コード例 #1
0
 /**
  * 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.');
     }
 }
コード例 #2
0
 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.'));
     }
 }
コード例 #3
0
ファイル: NewsletterForm.php プロジェクト: czechcamus/dasport
 /**
  * Deletes Newsletter
  * @throws \Exception
  */
 public function deleteNewsletter()
 {
     /** @var $newsletter Newsletter */
     if ($newsletter = Newsletter::findOne($this->item_id)) {
         $newsletter->delete();
     }
 }