示例#1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = NoreplyEmail::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'created_at' => $this->created_at, 'start_sending_at' => $this->start_sending_at, 'last_sent_at' => $this->last_sent_at, 'status' => $this->status, 'is_active' => $this->is_active, 'total_emails_address' => $this->total_emails_address, 'total_emails_sent' => $this->total_emails_sent]);
     $query->andFilterWhere(['like', 'subject', $this->subject])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'created_by', $this->created_by])->andFilterWhere(['like', 'to_groups', $this->to_groups])->andFilterWhere(['like', 'to_items', $this->to_items])->andFilterWhere(['like', 'image_path', $this->image_path]);
     return $dataProvider;
 }
示例#2
0
 /**
  * function ::create ($data)
  */
 public static function create($data)
 {
     $now = strtotime('now');
     $username = Yii::$app->user->identity->username;
     $model = new NoreplyEmail();
     if ($model->load($data)) {
         if ($log = new UserLog()) {
             $log->username = $username;
             $log->action = 'Create';
             $log->object_class = 'NoreplyEmail';
             $log->created_at = $now;
             $log->is_success = 0;
             $log->save();
         }
         $model->created_at = $now;
         $model->created_by = $username;
         $model->start_sending_at = strtotime($model->start_sending_at);
         empty($model->last_sent_at) or $model->last_sent_at = strtotime($model->last_sent_at);
         do {
             $path = FileUtils::generatePath($now);
         } while (file_exists(Yii::$app->params['images_folder'] . $path));
         $model->image_path = $path;
         $targetFolder = Yii::$app->params['images_folder'] . $model->image_path;
         $targetUrl = Yii::$app->params['images_url'] . $model->image_path;
         $model->content = FileUtils::copyContentImages(['content' => $model->content, 'defaultFromFolder' => Yii::$app->params['uploads_folder'], 'toFolder' => $targetFolder, 'toUrl' => $targetUrl, 'removeInputImage' => true]);
         if ($model->save()) {
             if ($log) {
                 $log->object_pk = $model->id;
                 $log->is_success = 1;
                 $log->save();
             }
             return $model;
         }
         $model->getErrors();
         return $model;
     }
     return false;
 }
 /**
  * Finds the NoreplyEmail model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return NoreplyEmail the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = NoreplyEmail::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }