| Current Path : /var/www/html/ebookingdbkl/backend/modules/serviceApplication/controllers/ |
| Current File : /var/www/html/ebookingdbkl/backend/modules/serviceApplication/controllers/ServiceImgController.php |
<?php
namespace backend\modules\serviceApplication\controllers;
use Yii;
use backend\modules\serviceApplication\models\ServiceImg;
use backend\modules\serviceApplication\models\ServiceImgSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\web\UploadedFile;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use backend\modules\serviceApplication\Modules as M;
/**
* ServiceImgController implements the CRUD actions for ServiceImg model.
*/
class ServiceImgController extends Controller {
/**
* {@inheritdoc}
*/
public function behaviors() {
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
* Lists all ServiceImg models.
* @return mixed
*/
public function actionIndex($service_id) {
$searchModel = new ServiceImgSearch();
$searchModel->service_id = $service_id;
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single ServiceImg 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 ServiceImg model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate($service_id) {
$model = new ServiceImg();
$model->created_at = date("Y-m-d H:i:s");
$model->created_by = Yii::$app->user->identity->id;
$model->created_user_type = 'backend_user';
$model->updated_at = date("Y-m-d H:i:s");
$model->updated_by = Yii::$app->user->identity->id;
$model->updated_user_type = 'backend_user';
$model->service_id = $service_id;
if ($model->load(Yii::$app->request->post())) {
$model->img_path = UploadedFile::getInstance($model, 'img_path');
if (!empty($model->img_path)) {
$img_path = 'uploads/service-img/' . 'serviceImg-backend-' . date('YmdHis') . '-' . round(microtime(true) * 1000) . '.' .$model->img_path->extension;
if ($model->img_path->saveAs('../' .$img_path))
$model->img_path = $img_path;
}
if ($model->save()) {
return $this->redirect(['index', 'service_id' => $model->service_id]);
}
}
return $this->render('create', [
'model' => $model,
]);
}
/**
* Updates an existing ServiceImg 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);
$model->updated_at = date("Y-m-d H:i:s");
$model->updated_by = Yii::$app->user->identity->id;
$model->updated_user_type = 'backend_user';
$original_file = $model->img_path;
if ($model->load(Yii::$app->request->post())) {
$model->img_path = UploadedFile::getInstance($model, 'img_path');
if (!empty($model->img_path)) {
$img_path = 'uploads/service-img/' . 'serviceImg-backend-' . date('YmdHis') . '-' . round(microtime(true) * 1000) . '.' .$model->img_path->extension;
if ($model->img_path->saveAs('../' .$img_path))
$model->img_path = $img_path;
} else
$model->img_path = $original_file;
if ($model->save()) {
return $this->redirect(['index', 'service_id' => $model->service_id]);
}
}
return $this->render('update', ['model' => $model,]);
}
/**
* Deletes an existing ServiceImg 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) {
$model = $this->findModel($id);
$service_id = $model->service_id;
$model->delete();
return $this->redirect(['index','service_id' => $service_id]);
}
/**
* Finds the ServiceImg model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return ServiceImg the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id) {
if (($model = ServiceImg::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException(M::t('app', 'PageNotExist'));
}
public function actionApprove($id) {
$model = $this->findModel($id);
$model->service_status = 'approve';
$model->updated_at = date("Y-m-d H:i:s");
$model->updated_by = Yii::$app->user->identity->id;
if ($model->save())
return $this->redirect(['index']);
}
public function actionReject($id) {
$model = $this->findModel($id);
$model->service_status = 'reject';
$model->updated_at = date("Y-m-d H:i:s");
$model->updated_by = Yii::$app->user->identity->id;
if ($model->save())
return $this->redirect(['index']);
}
}