2019-12-23 16:28:30 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace dominion\cron\controllers;
|
|
|
|
|
2019-12-23 17:34:09 +03:00
|
|
|
use Yii;
|
2019-12-23 16:28:30 +03:00
|
|
|
use yii\web\Controller;
|
2019-12-23 17:34:09 +03:00
|
|
|
use dominion\cron\models\search\MoleTaskSearch;
|
2019-12-24 17:04:30 +03:00
|
|
|
use dominion\cron\models\MoleTask;
|
|
|
|
use yii\filters\VerbFilter;
|
|
|
|
use yii\web\NotFoundHttpException;
|
2019-12-23 16:28:30 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Default controller for the `cron` module
|
|
|
|
*/
|
|
|
|
class DefaultController extends Controller
|
|
|
|
{
|
2019-12-24 17:04:30 +03:00
|
|
|
public function behaviors()
|
|
|
|
{
|
|
|
|
if (!Yii::$app->user->getIsGuest() && in_array(Yii::$app->user->id, $this->module->admins))
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'verbs' => [
|
|
|
|
'class' => VerbFilter::className(),
|
|
|
|
'actions' => [
|
|
|
|
'delete' => ['POST'],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw new NotFoundHttpException(Yii::t('mole', 'access denied'));
|
|
|
|
}
|
|
|
|
}
|
2019-12-23 17:34:09 +03:00
|
|
|
|
2019-12-23 16:28:30 +03:00
|
|
|
/**
|
|
|
|
* Renders the index view for the module
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function actionIndex()
|
|
|
|
{
|
2019-12-23 17:34:09 +03:00
|
|
|
$searchModel = new MoleTaskSearch();
|
|
|
|
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
|
|
|
|
|
|
|
return $this->render('index', [
|
|
|
|
'searchModel' => $searchModel,
|
|
|
|
'dataProvider' => $dataProvider,
|
|
|
|
]);
|
2019-12-23 16:28:30 +03:00
|
|
|
}
|
2019-12-23 17:34:09 +03:00
|
|
|
|
2019-12-24 17:04:30 +03:00
|
|
|
/**
|
|
|
|
* Displays a single MoleTask model.
|
|
|
|
* @param integer $id
|
|
|
|
* @return mixed
|
|
|
|
* @throws NotFoundHttpException if the model cannot be found
|
|
|
|
*/
|
|
|
|
public function actionView($id)
|
|
|
|
{
|
|
|
|
$model = $this->findModel($id);
|
|
|
|
return $this->render('view', [
|
|
|
|
'model' => $model,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new MoleTask model.
|
|
|
|
* If creation is successful, the browser will be redirected to the 'view' page.
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function actionCreate()
|
|
|
|
{
|
|
|
|
$model = new MoleTask();
|
|
|
|
|
|
|
|
if ($model->load(Yii::$app->request->post()) && $model->save())
|
|
|
|
{
|
|
|
|
return $this->redirect(['view', 'id' => $model->id]);
|
|
|
|
}
|
|
|
|
return $this->render('create', [
|
|
|
|
'model' => $model,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates an existing MoleTask 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 MoleTask 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 MoleTask model based on its primary key value.
|
|
|
|
* If the model is not found, a 404 HTTP exception will be thrown.
|
|
|
|
* @param integer $id
|
|
|
|
* @return MoleTask the loaded model
|
|
|
|
* @throws NotFoundHttpException if the model cannot be found
|
|
|
|
*/
|
|
|
|
protected function findModel($id)
|
|
|
|
{
|
|
|
|
if (($model = MoleTask::findOne($id)) !== null)
|
|
|
|
{
|
|
|
|
return $model;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new NotFoundHttpException(Yii::t('mole', 'The requested page does not exist.'));
|
|
|
|
}
|
|
|
|
|
2019-12-23 16:28:30 +03:00
|
|
|
}
|