| Current Path : /var/www/html/ebook/backend/modules/refdynawebv2/controllers/ |
| Current File : /var/www/html/ebook/backend/modules/refdynawebv2/controllers/RefController.php |
<?php
namespace backend\modules\refdynawebv2\controllers;
use Yii;
use backend\modules\refdynawebv2\models\Ref;
use backend\modules\refdynawebv2\models\RefSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;
use common\components\AccessRule;
/**
* RefController implements the CRUD actions for Ref model.
*/
class RefController extends Controller {
/**
* @inheritdoc
*/
public function behaviors() {
return [
'access' => [
'class' => AccessControl::className(),
'ruleConfig' => [
'class' => AccessRule::className(),
],
'rules' => [
[
'actions' => ['index', 'create', 'update', 'view', 'delete'],
'allow' => true,
'roles' => ['@'],
], [
'allow' => true,
'actions' => ['getreflist', 'getreflistmy'],
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
* Lists all Ref models.
* @return mixed
*/
public function actionIndex() {
$searchModel = new RefSearch();
$dataProvider = $searchModel->search4(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single Ref 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 Ref model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate() {
$model = new Ref();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['index']);
}
return $this->render('create', [
'model' => $model,
]);
}
/**
* Updates an existing Ref 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(['index']);
}
return $this->render('update', [
'model' => $model,
]);
}
/**
* Deletes an existing Ref 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 Ref model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Ref the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id) {
if (($model = Ref::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException(Yii::t('app', 'The requested page does not exist.'));
}
public function actionGetreflist($code, $cat) {
$output = '<option value="">-- Please choose --</option>';
if (($model2 = Ref::findOne(['code' => $code, 'cat' => $cat])) !== null) {
$model = Ref::find()->where(['param1' => $model2->id])->orderBy(['descr' => SORT_ASC])->all();
if (!empty($model)) {
foreach ($model as $row) {
$output .= '<option value="' . $row->code . '">' . $row->descr . '</option>';
}
}
}
return $output;
}
public function actionGetreflistmy($code, $cat) {
$output = '<option value="">-- Sila pilih --</option>';
if (($model2 = Ref::findOne(['code' => $code, 'cat' => $cat])) !== null) {
$model = Ref::find()->where(['param1' => $model2->id])->orderBy(['descr' => SORT_ASC])->all();
if (!empty($model)) {
foreach ($model as $row) {
$output .= '<option value="' . $row->code . '">' . $row->descr . '</option>';
}
}
}
return $output;
}
}