Example #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Newsletter::find();
     $dataProvider = new ActiveDataProvider(['query' => $query->where(['status' => [Status::STATUS_ACTIVE, Status::STATUS_INACTIVE]])]);
     $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_date' => $this->created_date, 'last_modified_date' => $this->last_modified_date, 'status' => $this->status]);
     $query->andFilterWhere(['like', 'subject', $this->subject])->andFilterWhere(['like', 'message', $this->message])->andFilterWhere(['like', 'created_by', $this->created_by])->andFilterWhere(['like', 'last_modified_by', $this->last_modified_by]);
     return $dataProvider;
 }
Example #2
0
 /**
  * Creates data provider instance with search query applied
  * @param $params
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     /** @var ActiveQuery $query */
     $query = Newsletter::find();
     if (!isset($params['sort'])) {
         $query->orderBy(['updated_at' => SORT_DESC]);
     }
     $session = Yii::$app->session;
     if (!$session['language_id']) {
         $session['language_id'] = LanguageRecord::getMainLanguageId();
     }
     $query->andWhere(['language_id' => $session['language_id']]);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         return $dataProvider;
     }
     $query->andFilterWhere(['active' => $this->active]);
     $query->andFilterWhere(['like', 'title', $this->title]);
     $query->andFilterWhere(['like', 'CONCAT(DATE_FORMAT(content_date,\'%d.%m.%Y\'),\' \',DATE_FORMAT(content_time,\'%H:%i\'))', $this->sendDateTime]);
     $dataProvider->sort->attributes['sendDateTime'] = ['asc' => ['content_date' => SORT_ASC, 'content_time' => SORT_ASC], 'desc' => ['content_date' => SORT_DESC, 'content_time' => SORT_DESC]];
     return $dataProvider;
 }
 public function actionSend($id)
 {
     /** @var Newsletter $model */
     $model = Newsletter::findOne($id);
     if ($model) {
         $this->layout = '@backend/views/newsletter/layouts/' . $model->layout->filename;
         $viewMail = true;
         $htmlBody = $this->render('view', compact('model', 'viewMail'));
         $textBody = Yii::t('back', 'Dear user') . ",\n\n";
         $textBody .= Yii::t('back', 'we would send to you a pretty version of our newsletter. But your email client doesn\'t support it.') . "\n";
         $textBody .= Yii::t('back', 'Luckily you can see our newsletter at this link') . ": " . Url::to(['view', 'id' => $id], true) . "\n\n";
         $textBody .= Yii::t('back', 'Yours sincerely') . " " . Yii::$app->params['sendingEmailTitle'];
         $sendingEmail = Yii::$app->params['sendingEmail'];
         $targetEmailsChunks = array_chunk(EmailRecord::getActiveEmails(), Yii::$app->params['maxEmailsCount']);
         foreach ($targetEmailsChunks as $targetEmailsChunk) {
             Yii::$app->mailer->compose()->setTo(Yii::$app->params['sendingEmail'])->setBcc($targetEmailsChunk)->setFrom([$sendingEmail => Yii::$app->params['sendingEmailTitle']])->setSubject(Yii::$app->params['sendingEmailTitle'] . ' - ' . Yii::t('back', 'newsletter'))->setTextBody($textBody)->setHtmlBody($htmlBody)->send();
         }
         $model->content_date = new Expression('DATE(NOW())');
         $model->content_time = new Expression('TIME(NOW())');
         $model->save(false);
         $session = Yii::$app->session;
         $session->setFlash('info', Yii::t('back', 'Newsletter successfuly sent!'));
         return $this->redirect(['index']);
     } else {
         throw new NotFoundHttpException(Yii::t('back', 'The requested page does not exist.'));
     }
 }
 /**
  * Finds the Newsletter model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Newsletter the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Newsletter::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #5
0
 /**
  * Deletes Newsletter
  * @throws \Exception
  */
 public function deleteNewsletter()
 {
     /** @var $newsletter Newsletter */
     if ($newsletter = Newsletter::findOne($this->item_id)) {
         $newsletter->delete();
     }
 }