Commit cd8607fe authored by Shakarim Sapa's avatar Shakarim Sapa

- Добавили CRUD стоп слов

parent 5f44bcf5
<?php
namespace common\modules\users\controllers;
use common\components\AdminController;
use common\modules\analyticsSchool\models\UserStopWords;
use yii\data\ActiveDataProvider;
use yii\web\NotFoundHttpException;
class StopwordsAdminController extends AdminController {
/**
* @return array|void
*/
public static function actionsTitles(){
return [
'Manage' => 'Управление стоп словами',
'Create' => 'Добавление нового стоп-слова',
'View' => 'Просмотр стоп слова',
'Update' => 'Редактирование стоп-слова',
'Delete' => 'Удаление стоп слова',
];
}
/**
* @return string
*/
public function actionManage(){
$dataProvider = new ActiveDataProvider([
'query' => UserStopWords::find(),
]);
return $this->render(
'manage',
[
'dataProvider' => $dataProvider,
]
);
}
/**
* @return string|\yii\web\Response
*/
public function actionCreate(){
$model = new UserStopWords();
if ($model->load(\Yii::$app->request->post())) {
if ($model->validate() && $model->save())
return $this->redirect([
'manage'
]);
}
$form = new \common\components\BaseForm('/common/modules/users/forms/StopWordsForm', $model);
return $this->render(
'create',
[
'form' => $form
]
);
}
/**
* @param $id
* @return string
*/
public function actionView($id){
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
/**
* @param $id
* @return string|\yii\web\Response
*/
public function actionUpdate($id){
/** @var UserStopWords $model */
$model = $this->findModel($id);
if ($model->load(\Yii::$app->request->post())) {
if ($model->validate() && $model->save())
return $this->redirect([
'manage'
]);
}
$form = new \common\components\BaseForm('/common/modules/users/forms/StopWordsForm', $model);
return $this->render(
'update',
[
'form' => $form
]
);
}
/**
* @param $id
* @return UserStopWords|null
* @throws NotFoundHttpException
*/
public function findModel($id)
{
if (($model = UserStopWords::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
/**
* @param $id
* @return \yii\web\Response
*/
public function actionDelete($id){
$this->findModel($id)->delete();
return $this->redirect(['manage']);
}
}
\ No newline at end of file
<?php
use \yii\data\ActiveDataProvider;
return [
'activeForm' => [
'id' => 'trigger-form',
'options' => [
'enctype' => 'multipart/form-data'
]
],
'elements' => [
'active' => [
'type' => 'checkbox',
'class' => 'form-control'
],
'word' => [
'type' => 'text',
'class' => 'form-control'
],
],
'buttons' => [
'submit' => ['type' => 'submit', 'value' => 'Cохранить']
]
];
\ No newline at end of file
<?= $form->out;
\ No newline at end of file
<?php
use \yii\helpers\Html;
use yii\grid\GridView;
/**
* @var $this \common\modules\users\controllers\StopwordsAdminController
* @var $dataProvider yii\data\ActiveDataProvider
*/
?>
<div class="analytics-school-manage">
<h1><?= Html::encode($this->title); ?></h1>
<p>
<?= Html::a('Добавить стоп слово', ['create'], ['class' => 'btn btn-success']); ?>
</p>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id',
[
'attribute' => 'active',
'value' => function($model) {
return ($model->active==1) ? 'Активно' : 'Не активно';
}
],
'word',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
</div>
<?= $form->out;
\ No newline at end of file
<?php
use yii\widgets\DetailView;
use \common\modules\analyticsSchool\models\AnalyticsSchoolLesson;
use \yii\grid\GridView;
/** @var AnalyticsSchoolLesson $model */
/** @var \yii\data\ActiveDataProvider $files */
?>
<h1>Просмотр стоп слова #<?= $model->id; ?></h1>
<div class="analytics-school-view">
<?=
DetailView::widget([
'model' => $model,
'attributes' => [
'id',
[
'attribute' => 'active',
'value' => ($model->active==1) ? 'Активно' : 'Не активно'
],
'word'
],
]);
?>
</div>
<div class="analytics-school-files-view">
<?= GridView::widget([
'dataProvider' => $files,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'title',
'file',
],
]); ?>
</div>
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