Achievement model. Achievement CRUD pages. Achievements at sidebar
This commit is contained in:
24
backend/modules/achievements/Achievements.php
Executable file
24
backend/modules/achievements/Achievements.php
Executable file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace backend\modules\achievements;
|
||||
|
||||
/**
|
||||
* achievement module definition class
|
||||
*/
|
||||
class Achievements extends \yii\base\Module
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public $controllerNamespace = 'backend\modules\achievements\controllers';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
|
||||
// custom initialization code goes here
|
||||
}
|
||||
}
|
151
backend/modules/achievements/controllers/AchievementsController.php
Executable file
151
backend/modules/achievements/controllers/AchievementsController.php
Executable file
@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
namespace backend\modules\achievements\controllers;
|
||||
|
||||
use backend\modules\achievements\models\AchievementSearch;
|
||||
use common\models\Status;
|
||||
use Yii;
|
||||
use backend\modules\achievements\models\Achievement;
|
||||
use common\models\FieldsValueNew;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use yii\filters\AccessControl;
|
||||
use yii\filters\VerbFilter;
|
||||
use yii\web\Controller;
|
||||
use yii\web\NotFoundHttpException;
|
||||
|
||||
/**
|
||||
* Default controller for the `achievements` module
|
||||
*/
|
||||
class AchievementsController extends Controller
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function behaviors()
|
||||
{
|
||||
return [
|
||||
'verbs' => [
|
||||
'class' => VerbFilter::className(),
|
||||
'actions' => [
|
||||
'delete' => ['POST'],
|
||||
],
|
||||
],
|
||||
'access' => [
|
||||
'class' => AccessControl::className(),
|
||||
'rules' => [
|
||||
[
|
||||
'allow' => true,
|
||||
'roles' => ['admin'],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the index view for the module
|
||||
* @return string
|
||||
*/
|
||||
public function actionIndex()
|
||||
{
|
||||
$searchModel = new AchievementSearch();
|
||||
|
||||
$dataProvider = $searchModel->search();
|
||||
return $this->render('index', [
|
||||
'searchModel' => $searchModel,
|
||||
'dataProvider' => $dataProvider
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new note model.
|
||||
* If creation is successful, the browser will be redirected to the 'view' page.
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionCreate()
|
||||
{
|
||||
$model = new Achievement();
|
||||
|
||||
if ($model->load(\Yii::$app->request->post()) && $model->save()) {
|
||||
return $this->redirect(['view', 'id' => $model->id]);
|
||||
}
|
||||
|
||||
return $this->render('create', [
|
||||
'model' => $model
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a single note model.
|
||||
* @param integer $id
|
||||
* @return mixed
|
||||
* @throws NotFoundHttpException if the model cannot be found
|
||||
*/
|
||||
public function actionView($id)
|
||||
{
|
||||
$additionalDataProvider = new ActiveDataProvider([
|
||||
'query' => FieldsValueNew::find()
|
||||
->where(['item_id' => $id, 'item_type' => FieldsValueNew::TYPE_NOTE])
|
||||
->orderBy('order'),
|
||||
'pagination' => [
|
||||
'pageSize' => 200,
|
||||
],
|
||||
]);
|
||||
|
||||
$changeDataProvider = new ActiveDataProvider([
|
||||
'query' => \common\models\ChangeHistory::find()->where(['type_id' => $this->findModel($id)->id]),
|
||||
'pagination' => [
|
||||
'pageSize' => 200,
|
||||
]
|
||||
]);
|
||||
|
||||
return $this->render('view', [
|
||||
'model' => Achievement::findOne($id),
|
||||
'additionalDataProvider' => $additionalDataProvider,
|
||||
'changeDataProvider' => $changeDataProvider,
|
||||
]);
|
||||
}
|
||||
|
||||
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 Note 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 note model based on its primary key value.
|
||||
* If the model is not found, a 404 HTTP exception will be thrown.
|
||||
* @param integer $id
|
||||
* @return Achievement the loaded model
|
||||
* @throws NotFoundHttpException if the model cannot be found
|
||||
*/
|
||||
protected function findModel($id)
|
||||
{
|
||||
if (($model = Achievement::findOne($id)) !== null) {
|
||||
return $model;
|
||||
}
|
||||
|
||||
throw new NotFoundHttpException('The requested page does not exist.');
|
||||
}
|
||||
}
|
21
backend/modules/achievements/models/Achievement.php
Executable file
21
backend/modules/achievements/models/Achievement.php
Executable file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace backend\modules\achievements\models;
|
||||
|
||||
use Yii;
|
||||
use common\models\FieldsValueNew;
|
||||
|
||||
class Achievement extends \common\models\Achievement
|
||||
{
|
||||
|
||||
public $fields;
|
||||
|
||||
public function behaviors()
|
||||
{
|
||||
return [
|
||||
'log' => [
|
||||
'class' => \common\behaviors\LogBehavior::class,
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
58
backend/modules/achievements/models/AchievementSearch.php
Executable file
58
backend/modules/achievements/models/AchievementSearch.php
Executable file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace backend\modules\achievements\models;
|
||||
|
||||
use common\models\Achievement;
|
||||
use Yii;
|
||||
use yii\data\ActiveDataProvider;
|
||||
|
||||
class AchievementSearch extends Achievement
|
||||
{
|
||||
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['id', 'status'], 'integer'],
|
||||
[['name', 'description', 'slug', 'title','img'], 'safe'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates data provider instance with search query applied
|
||||
*
|
||||
* @param array $params
|
||||
*
|
||||
* @return ActiveDataProvider
|
||||
*/
|
||||
public function search()
|
||||
{
|
||||
$params = Yii::$app->request->queryParams;
|
||||
$query = Achievement::find();
|
||||
// add conditions that should always apply here
|
||||
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
'query' => $query,
|
||||
]);
|
||||
|
||||
$this->load($params);
|
||||
|
||||
if (!$this->validate()) {
|
||||
// uncomment the following line if you do not want to return any records when validation fails
|
||||
// $query->where('0=1');
|
||||
return $dataProvider;
|
||||
}
|
||||
|
||||
// grid filtering conditions
|
||||
$query->andFilterWhere([
|
||||
'id' => $this->id,
|
||||
'status' => $this->status
|
||||
]);
|
||||
|
||||
$query->andFilterWhere(['like', 'slug', $this->slug])
|
||||
->andFilterWhere(['like', 'description', $this->description])
|
||||
->andFilterWhere(['like', 'title', $this->title]);
|
||||
// $query->orderBy('created_at DESC');
|
||||
|
||||
return $dataProvider;
|
||||
}
|
||||
}
|
50
backend/modules/achievements/views/achievements/_form.php
Executable file
50
backend/modules/achievements/views/achievements/_form.php
Executable file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
use backend\modules\settings\models\AdditionalFields;
|
||||
use mihaildev\elfinder\InputFile;
|
||||
use unclead\multipleinput\MultipleInput;
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\ActiveForm;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model backend\modules\achievements\models\Achievement */
|
||||
/* @var $form yii\widgets\ActiveForm */
|
||||
/* @var $statuses array */
|
||||
?>
|
||||
|
||||
<div class="notes-form">
|
||||
|
||||
<?php $form = ActiveForm::begin(); ?>
|
||||
|
||||
<?= $form->field($model, 'title')->textInput(['maxlength' => true]) ?>
|
||||
<?= $form->field($model, 'slug')->textInput(['maxlength' => true]) ?>
|
||||
<?= $form->field($model, 'description')->textarea(['rows' => 6]) ?>
|
||||
<?= $form->field($model, 'status')->dropDownList(\common\models\Achievement::getStatusLabel()) ?>
|
||||
<div class="imgUpload form-group">
|
||||
<div class="media__upload_img"><img src="<?= $model->img; ?>" width="100px"/></div>
|
||||
<?php
|
||||
echo InputFile::widget([
|
||||
'language' => 'ru',
|
||||
'controller' => 'elfinder',
|
||||
// вставляем название контроллера, по умолчанию равен elfinder
|
||||
'filter' => 'image',
|
||||
// фильтр файлов, можно задать массив фильтров https://github.com/Studio-42/elFinder/wiki/Client-con..
|
||||
'name' => 'Achievement[img]',
|
||||
'id' => 'achievement-img',
|
||||
'template' => '<label>Изображение</label><div class="input-group">{input}<span class="span-btn">{button}</span></div>',
|
||||
'options' => ['class' => 'form-control itemImg', 'maxlength' => '255'],
|
||||
'buttonOptions' => ['class' => 'btn btn-primary'],
|
||||
'value' => $model->img,
|
||||
'buttonName' => 'Выбрать изображение',
|
||||
]);
|
||||
?>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton('Сохранить', ['class' => 'btn btn-success']) ?>
|
||||
</div>
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
|
||||
</div>
|
19
backend/modules/achievements/views/achievements/create.php
Executable file
19
backend/modules/achievements/views/achievements/create.php
Executable file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model backend\modules\achievements\models\Achievement */
|
||||
|
||||
$this->title = 'Создать достижение';
|
||||
$this->params['breadcrumbs'][] = ['label' => 'Достижения', 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
?>
|
||||
<div class="notes-create">
|
||||
|
||||
<?= $this->render('_form', [
|
||||
'model' => $model,
|
||||
]) ?>
|
||||
|
||||
</div>
|
49
backend/modules/achievements/views/achievements/index.php
Executable file
49
backend/modules/achievements/views/achievements/index.php
Executable file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
use yii\grid\GridView;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $searchModel backend\modules\achievements\models\AchievementSearch */
|
||||
/* @var $dataProvider yii\data\ActiveDataProvider */
|
||||
|
||||
$this->title = 'Достижения';
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
?>
|
||||
<div class="notes-index">
|
||||
|
||||
<p>
|
||||
<?= Html::a('Добавить', ['create'], ['class' => 'btn btn-success']) ?>
|
||||
</p>
|
||||
|
||||
<?= GridView::widget([
|
||||
'dataProvider' => $dataProvider,
|
||||
'filterModel' => $searchModel,
|
||||
'columns' => [
|
||||
['class' => 'yii\grid\SerialColumn'],
|
||||
// 'id',
|
||||
'title',
|
||||
'slug',
|
||||
'description',
|
||||
[
|
||||
'attribute' => 'status',
|
||||
'value' => function ($model) {
|
||||
return \common\models\Achievement::getStatusLabel()[$model->status ?? 0];
|
||||
},
|
||||
'filter' => kartik\select2\Select2::widget([
|
||||
'model' => $searchModel,
|
||||
'attribute' => 'status',
|
||||
'data' => \common\models\Achievement::getStatusLabel(),
|
||||
'options' => ['placeholder' => 'Начните вводить...', 'class' => 'form-control'],
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true
|
||||
],
|
||||
]),
|
||||
],
|
||||
// 'created_at',
|
||||
// 'updated_at',
|
||||
|
||||
['class' => 'yii\grid\ActionColumn'],
|
||||
],
|
||||
]); ?>
|
||||
</div>
|
17
backend/modules/achievements/views/achievements/update.php
Executable file
17
backend/modules/achievements/views/achievements/update.php
Executable file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model backend\modules\achievements\models\Achievement */
|
||||
|
||||
$this->title = 'Редактировать достижение: ' . $model->title;
|
||||
$this->params['breadcrumbs'][] = ['label' => 'Заметки', 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = ['label' => $model->title, 'url' => ['view', 'id' => $model->id]];
|
||||
$this->params['breadcrumbs'][] = 'Редактировать';
|
||||
?>
|
||||
<div class="notes-update">
|
||||
|
||||
<?= $this->render('_form', [
|
||||
'model' => $model,
|
||||
]) ?>
|
||||
|
||||
</div>
|
60
backend/modules/achievements/views/achievements/view.php
Executable file
60
backend/modules/achievements/views/achievements/view.php
Executable file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
use yii\grid\GridView;
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\DetailView;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $dataProviderF \yii\data\ActiveDataProvider */
|
||||
/* @var $model backend\modules\achievements\models\Achievement */
|
||||
|
||||
$this->title = $model->title;
|
||||
$this->params['breadcrumbs'][] = ['label' => 'Достижения', 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
?>
|
||||
<div class="notes-view">
|
||||
<p>
|
||||
<?= Html::a('Список', ['index'], ['class' => 'btn btn-primary']) ?>
|
||||
<?= Html::a('Редактировать', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
|
||||
<?= Html::a('Удалить', ['delete', 'id' => $model->id], [
|
||||
'class' => 'btn btn-danger',
|
||||
'data' => [
|
||||
'confirm' => 'Are you sure you want to delete this item?',
|
||||
'method' => 'post',
|
||||
],
|
||||
]) ?>
|
||||
</p>
|
||||
|
||||
<?= DetailView::widget([
|
||||
'model' => $model,
|
||||
'attributes' => [
|
||||
'id',
|
||||
'title',
|
||||
'slug',
|
||||
'description:ntext',
|
||||
[
|
||||
'attribute' => 'status',
|
||||
'value' => \common\models\Achievement::getStatusLabel()[$model->status ?? 0],
|
||||
],
|
||||
[
|
||||
'attribute' => 'img',
|
||||
'format' => 'raw',
|
||||
'value' => function ($model) {
|
||||
return Html::tag('img', null, ['src' => $model->img, 'width' => '100px']);
|
||||
}
|
||||
],
|
||||
],
|
||||
]) ?>
|
||||
|
||||
<h2>История изменений</h2>
|
||||
<?= GridView::widget([
|
||||
'dataProvider' => $changeDataProvider,
|
||||
'columns' => [
|
||||
'label',
|
||||
'old_value',
|
||||
'new_value',
|
||||
'created_at',
|
||||
],
|
||||
]); ?>
|
||||
|
||||
</div>
|
Reference in New Issue
Block a user