/**
  * Creates a new NotifyEmail model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new NotifyEmail();
     if ($model->load(Yii::$app->request->post())) {
         //recepients info
         $rcpt = Staff::findOne($model->staff_id);
         $mc = MedicalCertificate::findOne($model->mc_id);
         $student = Student::findOne($mc->student_id);
         //get student's program
         $program = Program::findOne($student->program_id);
         //get Clinic that produce the Medical Certificate
         $clinic = Clinic::findOne($mc->clinic_id);
         //get authorizer info
         $auth = Authorizer::findOne($mc->au_id);
         $staff = Staff::findOne($auth->staff_id);
         //upload the attachment
         $model->attachment = UploadedFile::getInstance($model, 'attachment');
         if ($model->attachment) {
             $time = time();
             $model->attachment->saveAs('attachments/' . $time . '.' . $model->attachment->extension);
             $model->attachment = 'attachments/' . $time . '.' . $model->attachment->extension;
         }
         if ($model->attachment) {
             //send email with attachment
             $value = Yii::$app->mail->compose()->setFrom(array('*****@*****.**' => 'imaprog'))->setTo('*****@*****.**')->setSubject('Medical Certificate')->setHtmlBody('
                 Dear ' . $rcpt->staff_name . '
                 Your Student Has a Medical Certificate,
                 Serial Number: ' . $mc->mc_serial . '
                 Student Name: ' . $student->student_name . '
                 Student Matrix: ' . $student->student_matrix . '
                 Student Faculty: ' . $program->program_name . '
                 Problem/Diesease: ' . $mc->mc_problem . '
                 Valid From: ' . $mc->mc_startdate . '
                 Till: ' . $mc->mc_enddate . '
                 Appointmet On: ' . $mc->mc_appdate . '
                 Produced By: ' . $clinic->clinic_name . '
                 Authorize By: ' . $staff->staff_name)->attach($model->attachment)->send();
         } else {
             //send email without attachment
             $value = Yii::$app->mail->compose()->setFrom(array('*****@*****.**' => 'imaprog'))->setTo('*****@*****.**')->setSubject('Medical Certificate')->setHtmlBody('
                 Dear ' . $rcpt->staff_name . '
                 Your Student Has a Medical Certificate,
                 Serial Number: ' . $mc->mc_serial . '
                 Student Name: ' . $student->student_name . '
                 Student Matrix: ' . $student->student_matrix . '
                 Student Faculty: ' . $program->program_name . '
                 Problem/Diesease: ' . $mc->mc_problem . '
                 Valid From: ' . $mc->mc_startdate . '
                 Till: ' . $mc->mc_enddate . '
                 Appointmet On: ' . $mc->mc_appdate . '
                 Produced By: ' . $clinic->clinic_name . '
                 Authorize By: ' . $staff->staff_name)->send();
         }
         $model->save();
         return $this->redirect(['view', 'id' => $model->ne_id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = MedicalCertificate::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $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->joinWith('student');
     $query->andFilterWhere(['mc_id' => $this->mc_id, 'mc_startdate' => $this->mc_startdate, 'mc_enddate' => $this->mc_enddate, 'mc_appdate' => $this->mc_appdate, 'clinic_id' => $this->clinic_id, 'au_id' => $this->au_id]);
     $query->andFilterWhere(['like', 'mc_serial', $this->mc_serial])->andFilterWhere(['like', 'mc_problem', $this->mc_problem])->andFilterWhere(['like', 'student.student_matrix', $this->student_id]);
     return $dataProvider;
 }
Example #3
0
 public function getMedicalCertificate()
 {
     return $this->hasOne(MedicalCertificate::className(), ['mc_id' => 'mc_id']);
 }
Example #4
0
 public function getMedicalCertificate()
 {
     return $this->hasMany(MedicalCertificate::className(), ['au_id' => 'au_id']);
 }
 /**
  * Finds the MedicalCertificate model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return MedicalCertificate the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = MedicalCertificate::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #6
0
 public function getMedicalCertificate()
 {
     //a student has many medical certificate
     return $this->hasMany(MedicalCertificate::className(), ['student_id' => 'student_id']);
 }