コード例 #1
0
ファイル: OrganController.php プロジェクト: vovancho/yii2test
 /**
  * Finds the Organ model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Organ the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Organ::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
コード例 #2
0
 public function actionOsmotraktSend()
 {
     $dopparams = json_decode(Yii::$app->request->post()['dopparams']);
     if (Yii::$app->request->isAjax) {
         $organ_id = Yii::$app->request->post('organ_id');
         if (!empty($dopparams->id) && !empty($organ_id)) {
             $Organ = Organ::findOne($organ_id);
             if (!empty($Organ->organ_email)) {
                 $Report = new OsmotraktReport();
                 $Report->setDirectoryFiles('tmpfiles');
                 $filename = $Report->Execute();
                 $fnutf8 = $filename;
                 $fregatsettings = Fregatsettings::findOne(1);
                 $fl = DIRECTORY_SEPARATOR === '/' ? 'tmpfiles/' . $filename : mb_convert_encoding('tmpfiles/' . $filename, 'Windows-1251', 'UTF-8');
                 $sended = Yii::$app->mailer->compose('//Fregat/osmotrakt/_send', ['filename' => $filename])->setFrom($fregatsettings->fregatsettings_recoverysend_emailfrom)->setTo([YII_DEBUG ? '*****@*****.**' : Organ::findOne($organ_id)->organ_email])->setSubject($fregatsettings->fregatsettings_recoverysend_emailtheme)->attach($fl, ['fileName' => $fnutf8])->send();
                 if (!$sended) {
                     throw new HttpException(500, 'Возникла ошибка при отправке письма');
                 } else {
                     $FileName = DIRECTORY_SEPARATOR === '/' ? 'tmpfiles/' . $filename : mb_convert_encoding('tmpfiles/' . $filename, 'Windows-1251', 'UTF-8');
                     unlink($FileName);
                 }
                 echo $fnutf8;
             } else {
                 throw new HttpException(500, 'Не заполнен Email у организации');
             }
         }
     }
 }