Пример #1
0
 /**
  * send a email to client with checklist attached
  * @return void
  */
 public function actionSendmail()
 {
     $post = Yii::$app->request->post('SendmailForm');
     Yii::$app->response->format = 'json';
     $sm_form = new SendmailForm();
     if ($sm_form->load(Yii::$app->request->post()) && $sm_form->validate()) {
         $checklistCow = ChecklistsCow::findOne($post['checklists_cow_id']);
         if ($checklistCow->belong_to == 1) {
             $cow = Client::findOne($checklistCow->clients_or_webs_id);
             $email = $cow->email;
         } elseif ($checklistCow->belong_to == 2) {
             $cow = Website::findOne($checklistCow->clients_or_webs_id);
             $email = $cow->client->email;
         }
         // save time sending
         // checking if time sending is exist then only update else create new one
         $timeSent = ChecklistsTimeSent::find()->where(['checklists_cow_id' => $post['checklists_cow_id']])->one();
         if (!isset($timeSent)) {
             $timeSent = new ChecklistsTimeSent();
         }
         $timeSent->checklists_cow_id = $post['checklists_cow_id'];
         $timeSent->time_sent = date('Y-m-d H:i:s');
         $timeSent->save();
         // if everything is ok, then send mail. go ahead!!!
         Yii::$app->mailer->compose()->setFrom('*****@*****.**')->setTo($email)->setSubject($post['subject'])->setTextBody($post['content'])->attach(Yii::$app->basePath . '/web/upload/pdf/' . $checklistCow->file_name)->send();
         return ['errors' => ''];
     } else {
         return ['errors' => 'Something is wrong.'];
     }
 }
Пример #2
0
 /**
  * get latest time sending of checklist for client or website
  * @param integer $belong_to 
  * @param integer $cowid
  * @return mix
  */
 public function getTimesent()
 {
     return $this->hasOne(ChecklistsTimeSent::className(), ['checklists_cow_id' => 'id']);
 }