| Current Path : /var/www/html/chatbot/backend/controllers/ |
| Current File : /var/www/html/chatbot/backend/controllers/ChatLiveController.php |
<?php
namespace backend\controllers;
use Yii;
use backend\models\chat\ChatLive;
use backend\models\chat\ChatLiveSearch;
use backend\models\chat\ChatUser;
use backend\models\chat\ChatConfig;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* ChatLiveController implements the CRUD actions for ChatLive model.
*/
class ChatLiveController extends Controller
{
/**
* {@inheritdoc}
*/
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
* Lists all ChatLive models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new ChatLiveSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single ChatLive model.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionView($id)
{
$modelLatest = ChatLive::find()
->select('live_session')
->where(['=', 'user_id', Yii::$app->request->get('id')])
->orderBy('create_dttm DESC')
->one();
$condition = ['and',
['=', 'user_id', Yii::$app->request->get('id')]
];
ChatLive::updateAll(['live_read_status'=>1],$condition);
$model = ChatLive::find()
->where(['=', 'live_session', $modelLatest->live_session])
->orderBy(['create_dttm' => 'ASC'])
->all();
$modelUser = ChatUser::find()
->where(['=', 'user_id', Yii::$app->request->get('id')])
->one();
if(file_exists("/www/admin/images/profile_pic/" . Yii::$app->user->identity->staff->id . '.jpg')){
$img = "/www/admin/images/profile_pic/" . Yii::$app->user->identity->staff->id . '.jpg';
}
else
$img = "/www/admin/images/user_icon.png";
return $this->render('view', [
'model' => $model,
'model_user' => $modelUser,
'live_session' => $modelLatest->live_session,
'admin_id' => Yii::$app->user->identity->id,
'admin_fullname' => Yii::$app->user->identity->fullname,
'admin_icon' => $img
]);
}
/**
* Creates a new ChatLive model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new ChatLive();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->live_id]);
}
return $this->render('create', [
'model' => $model,
]);
}
/**
* Updates an existing ChatLive 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->live_id]);
}
return $this->render('update', [
'model' => $model,
]);
}
/**
* Updates an existing ChatLive 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 actionSetting()
{
$model = ChatConfig::find()->one();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['index']);
}
return $this->render('setting', [
'model' => $model,
]);
}
/**
* Deletes an existing ChatLive 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 ChatLive model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return ChatLive the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = ChatLive::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException(Yii::t('app', 'The requested page does not exist.'));
}
}