Commit edcc089c authored by Shakarim Sapa's avatar Shakarim Sapa

Расписаны функции добавления, редактирования и удаления триггера, а так же...

Расписаны функции добавления, редактирования и удаления триггера, а так же формы для работы с триггером
parent f2000c91
...@@ -12,14 +12,24 @@ use Yii; ...@@ -12,14 +12,24 @@ use Yii;
use common\components\AdminController; use common\components\AdminController;
use common\modules\triggers\models\TriggerTrigger; use common\modules\triggers\models\TriggerTrigger;
use yii\data\ActiveDataProvider; use yii\data\ActiveDataProvider;
use yii\web\NotFoundHttpException;
class TriggerAdminController extends AdminController { class TriggerAdminController extends AdminController {
/**
* @return array|void
*/
public static function actionsTitles(){ public static function actionsTitles(){
return [ return [
'Manage' => 'Управление триггерами' 'Manage' => 'Управление триггерами',
'Create' => 'Добавление триггера',
'Update' => 'Редактирование триггера',
'Delete' => 'Удаление триггера'
]; ];
} }
/**
* @return string
*/
public function actionManage(){ public function actionManage(){
$dataProvider = new ActiveDataProvider([ $dataProvider = new ActiveDataProvider([
'query' => TriggerTrigger::find() 'query' => TriggerTrigger::find()
...@@ -33,16 +43,85 @@ class TriggerAdminController extends AdminController { ...@@ -33,16 +43,85 @@ class TriggerAdminController extends AdminController {
); );
} }
public function actionCreate(){ /**
* @return string|\yii\web\Response
*/
public function actionCreate() {
$model = new TriggerTrigger(); $model = new TriggerTrigger();
if ($model->load(Yii::$app->request->post()) && $model->save()) { if ($model->load(Yii::$app->request->post())) {
return $this->redirect(['view', 'id' => $model->id]); $datetime=new \DateTime();
$model->owner_id = Yii::$app->user->getId();
$model->date_create=$datetime->format('Y-m-d H:i:s');
if ($model->save())
return $this->redirect(
[
'manage'
]
);
} else { } else {
$form = new \common\components\BaseForm('/common/modules/triggers/forms/TriggerForm', $model); $form = new \common\components\BaseForm('/common/modules/triggers/forms/TriggerForm', $model);
return $this->render('create', [ return $this->render(
'model' => $model, 'create',
]); [
'model' => $model,
'form' => $form
]
);
} }
} }
}
\ No newline at end of file /**
* @param $id
* @return string|\yii\web\Response
*/
public function actionUpdate($id){
/** @var TriggerTrigger $model */
$model = TriggerTrigger::findOne($id);
if ($model->load(Yii::$app->request->post())) {
$datetime=new \DateTime();
$model->owner_id = Yii::$app->user->getId();
$model->date_create=$datetime->format('Y-m-d H:i:s');
if ($model->save())
return $this->redirect(
[
'manage'
]
);
} else {
$form = new \common\components\BaseForm('/common/modules/triggers/forms/TriggerForm', $model);
return $this->render(
'update',
[
'model' => $model,
'form' => $form
]
);
}
}
/**
* @param $id
* @return \yii\web\Response
*/
public function actionDelete($id){
$this->findModel($id)->delete();
return $this->redirect(['manage']);
}
/**
* @param $id
* @return null|TriggerTrigger
* @throws NotFoundHttpException
*/
protected function findModel($id)
{
if (($model = TriggerTrigger::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}
\ No newline at end of file
...@@ -4,7 +4,29 @@ return [ ...@@ -4,7 +4,29 @@ return [
'id' => 'trigger-form' 'id' => 'trigger-form'
], ],
'elements' => [ 'elements' => [
'active' => [
'type' => 'checkbox'
],
'owner_id' => [
'type' => 'hidden',
'value' => (string)Yii::$app->user->id
],
'name' => [
'type' => 'text',
'class' => 'form-control'
],
'description' => [
'type' => 'textarea',
'class' => 'form-control'
],
'message_template_id' => [
'type' => 'dropdownlist',
'items' => array('1' => 'first template', '2' => 'second template')
],
'timeout' => [
'type' => 'text',
'class' => 'form-control'
]
], ],
'buttons' => [ 'buttons' => [
'submit' => ['type' => 'submit', 'value' => 'Cохранить'] 'submit' => ['type' => 'submit', 'value' => 'Cохранить']
......
...@@ -58,8 +58,8 @@ class TriggerTrigger extends \yii\db\ActiveRecord ...@@ -58,8 +58,8 @@ class TriggerTrigger extends \yii\db\ActiveRecord
'description' => 'Описание триггера', 'description' => 'Описание триггера',
'owner_id' => 'Автор', 'owner_id' => 'Автор',
'date_create' => 'Дата создания', 'date_create' => 'Дата создания',
'timeout' => 'Задержка перед выполнением', 'timeout' => 'Задержка перед выполнением (секунд)',
'message_template_id' => 'Наблон письма', 'message_template_id' => 'Шаблон письма',
]; ];
} }
......
<?php
/**
* @var $form common\components\BaseForm
*/
echo $form->out;
\ No newline at end of file
...@@ -18,14 +18,28 @@ use yii\grid\GridView; ...@@ -18,14 +18,28 @@ use yii\grid\GridView;
['class' => 'yii\grid\SerialColumn'], ['class' => 'yii\grid\SerialColumn'],
'id', 'id',
'active', [
'attribute' => 'active',
'value' => function($model) {
return ($model->active==1) ? 'Активен' : 'Не активен';
}
],
'name', 'name',
'description:ntext', 'description:html',
'owner_id', [
'date_create', 'attribute' => 'owner_id',
'timeout:datetime', 'value' => function($model) {
/** @var $model common\modules\triggers\models\TriggerTrigger */
return $model->owner->fio;
}
],
'date_create:datetime',
'timeout',
'message_template_id', 'message_template_id',
['class' => 'yii\grid\ActionColumn'], [
'class' => 'yii\grid\ActionColumn',
'template' => '{update}{delete}',
],
], ],
]); ?> ]); ?>
</div> </div>
<?php
/**
* @var $form common\components\BaseForm
*/
echo $form->out;
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment