| Current Path : /var/www/html/drsa/backend/modules/emailLog/controllers/ |
| Current File : /var/www/html/drsa/backend/modules/emailLog/controllers/EmailLogController.php |
<?php
namespace backend\modules\emailLog\controllers;
use Yii;
use backend\modules\emailLog\models\EmailLog;
use backend\modules\emailLog\models\EmailLogSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\web\UploadedFile;
use yii\helpers\Url;
use backend\modules\appCompetency\models\ModuleAppCompetencyPreregistration;
/**
* EmailLogController implements the CRUD actions for EmailLog model.
*/
class EmailLogController extends Controller {
/**
* {@inheritdoc}
*/
public function behaviors() {
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
* Lists all EmailLog models.
* @return mixed
*/
public function actionIndex() {
$searchModel = new EmailLogSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single EmailLog model.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionView($id) {
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
/**
* Creates a new EmailLog model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate($id) {
$model = new EmailLog();
$model->created_at = date("Y-m-d H:i:s");
$model->created_by = Yii::$app->user->identity->id;
$id_competency = 0;
if (($model2 = ModuleAppCompetencyPreregistration::findOne($id)) !== null) {
$model->email_address = $model2->email;
$id_competency = $model2->id_competency;
}
if ($model->load(Yii::$app->request->post())) {
if ($model->save()) {
$sendEmail = Yii::$app->emailModule->sendemail($model->email_address, $model->subject, $model->content);
$this->getView()->registerJs("swal.fire({
title:'Email Send',
icon: 'success',
text: 'Email have been successfully send',
}).then(function(result){
window.location = '" . Url::toRoute(['/appCompetency/module-app-competency-preregistration/index', 'id' => $id_competency]) . "';
});");
}
}
return $this->render('create', ['model' => $model, 'id_competency' => $id_competency]);
}
/**
* Updates an existing EmailLog model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionUpdate($id) {
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('update', [
'model' => $model,
]);
}
/**
* Deletes an existing EmailLog model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionDelete($id) {
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
/**
* Finds the EmailLog model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return EmailLog the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id) {
if (($model = EmailLog::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException('The requested page does not exist.');
}
}