add mark to project
This commit is contained in:
165
backend/modules/project/controllers/ProjectMarkController.php
Normal file
165
backend/modules/project/controllers/ProjectMarkController.php
Normal file
@ -0,0 +1,165 @@
|
||||
<?php
|
||||
|
||||
namespace backend\modules\project\controllers;
|
||||
|
||||
use backend\modules\project\models\ProjectMark;
|
||||
use backend\modules\project\models\ProjectMarkSearch;
|
||||
use Yii;
|
||||
use yii\filters\VerbFilter;
|
||||
use yii\helpers\ArrayHelper;
|
||||
use yii\web\Controller;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\web\Response;
|
||||
|
||||
/**
|
||||
* ProjectMarkController implements the CRUD actions for ProjectMark model.
|
||||
*/
|
||||
class ProjectMarkController extends Controller
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function behaviors()
|
||||
{
|
||||
return [
|
||||
'verbs' => [
|
||||
'class' => VerbFilter::className(),
|
||||
'actions' => [
|
||||
'delete' => ['POST'],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all ProjectMark models.
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionIndex()
|
||||
{
|
||||
$searchModel = new ProjectMarkSearch();
|
||||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
||||
|
||||
return $this->render('index', [
|
||||
'searchModel' => $searchModel,
|
||||
'dataProvider' => $dataProvider,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a single ProjectMark 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 ProjectMark model.
|
||||
* If creation is successful, the browser will be redirected to the 'view' page.
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionCreate()
|
||||
{
|
||||
$marks = \Yii::$app->request->post('ProjectMark');
|
||||
|
||||
if (!empty($marks)) {
|
||||
$mark_id_arr = ArrayHelper::getValue($marks, 'mark_id');
|
||||
$project_id = $marks['project_id'];
|
||||
|
||||
foreach ($mark_id_arr as $mark_id) {
|
||||
$emtModel = new ProjectMark();
|
||||
$emtModel->project_id = $project_id;
|
||||
$emtModel->mark_id = $mark_id;
|
||||
|
||||
if (!$emtModel->save()) {
|
||||
return $this->render('create', [
|
||||
'model' => $emtModel,
|
||||
]);
|
||||
}
|
||||
}
|
||||
return $this->redirect(['index']);
|
||||
}
|
||||
|
||||
$model = new ProjectMark();
|
||||
return $this->render('create', [
|
||||
'model' => $model,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates an existing ProjectMark 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 ProjectMark 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 ProjectMark model based on its primary key value.
|
||||
* If the model is not found, a 404 HTTP exception will be thrown.
|
||||
* @param integer $id
|
||||
* @return ProjectMark the loaded model
|
||||
* @throws NotFoundHttpException if the model cannot be found
|
||||
*/
|
||||
protected function findModel($id)
|
||||
{
|
||||
if (($model = ProjectMark::findOne($id)) !== null) {
|
||||
return $model;
|
||||
}
|
||||
|
||||
throw new NotFoundHttpException('The requested page does not exist.');
|
||||
}
|
||||
|
||||
public function actionUsersNotOnProject(): array
|
||||
{
|
||||
Yii::$app->response->format = Response::FORMAT_JSON;
|
||||
|
||||
if (isset($_POST['depdrop_parents'])) {
|
||||
$parents = $_POST['depdrop_parents'];
|
||||
if ($parents != null) {
|
||||
$project_id = $parents[0];
|
||||
$categories = ProjectMark::getMarkNotAtProject($project_id);
|
||||
|
||||
$formattedCatArr = array();
|
||||
foreach ($categories as $key => $value){
|
||||
$formattedCatArr[] = array('id' => $key, 'name' => $value);
|
||||
}
|
||||
|
||||
return ['output'=>$formattedCatArr, 'selected'=>''];
|
||||
}
|
||||
}
|
||||
return ['output'=>'', 'selected'=>''];
|
||||
}
|
||||
}
|
8
backend/modules/project/models/ProjectMark.php
Normal file
8
backend/modules/project/models/ProjectMark.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace backend\modules\project\models;
|
||||
|
||||
class ProjectMark extends \common\models\ProjectMark
|
||||
{
|
||||
|
||||
}
|
67
backend/modules/project/models/ProjectMarkSearch.php
Normal file
67
backend/modules/project/models/ProjectMarkSearch.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace backend\modules\project\models;
|
||||
|
||||
use yii\base\Model;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use backend\modules\project\models\ProjectMark;
|
||||
|
||||
/**
|
||||
* ProjectMarkSearch represents the model behind the search form of `backend\modules\project\models\ProjectMark`.
|
||||
*/
|
||||
class ProjectMarkSearch extends ProjectMark
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['id', 'project_id', 'mark_id'], 'integer'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function scenarios()
|
||||
{
|
||||
// bypass scenarios() implementation in the parent class
|
||||
return Model::scenarios();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates data provider instance with search query applied
|
||||
*
|
||||
* @param array $params
|
||||
*
|
||||
* @return ActiveDataProvider
|
||||
*/
|
||||
public function search($params)
|
||||
{
|
||||
$query = ProjectMark::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,
|
||||
'project_id' => $this->project_id,
|
||||
'mark_id' => $this->mark_id,
|
||||
]);
|
||||
|
||||
return $dataProvider;
|
||||
}
|
||||
}
|
58
backend/modules/project/views/project-mark/_form.php
Normal file
58
backend/modules/project/views/project-mark/_form.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
use backend\modules\project\models\Project;
|
||||
use yii\helpers\Url;
|
||||
use kartik\depdrop\DepDrop;
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\ActiveForm;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model backend\modules\project\models\ProjectMark */
|
||||
/* @var $form yii\widgets\ActiveForm */
|
||||
?>
|
||||
|
||||
<div class="project-mark-form">
|
||||
|
||||
<?php $form = ActiveForm::begin(); ?>
|
||||
|
||||
<?= $form->field($model, 'project_id')->dropDownList(
|
||||
Project::find()->select(['name', 'id'])->indexBy('id')->column(),
|
||||
[
|
||||
'id' => 'project-id',
|
||||
'placeholder' => 'Выберите',
|
||||
'prompt' => 'Выберите'
|
||||
]
|
||||
) ?>
|
||||
|
||||
<?= $form->field($model, 'mark_id')->widget(DepDrop::className(),
|
||||
[
|
||||
'options' => ['id' => 'mark_id'],
|
||||
'pluginOptions' => [
|
||||
'depends' => ['project-id'],
|
||||
'url' => Url::to(['/project/project-mark/users-not-on-project'])
|
||||
,'initialize' => false,
|
||||
],
|
||||
|
||||
'type' => DepDrop::TYPE_SELECT2,
|
||||
'select2Options' => [
|
||||
'hideSearch' => false,
|
||||
'pluginOptions' => [
|
||||
'placeholder' => 'Вводите название метки',
|
||||
'allowClear' => true,
|
||||
'closeOnSelect' => false,
|
||||
'multiple' => true,
|
||||
'hideSearch' => false
|
||||
],
|
||||
'showToggleAll' => true,
|
||||
],
|
||||
]
|
||||
);
|
||||
?>
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton('Save', ['class' => 'btn btn-success']) ?>
|
||||
</div>
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
|
||||
</div>
|
41
backend/modules/project/views/project-mark/_form_update.php
Normal file
41
backend/modules/project/views/project-mark/_form_update.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
use backend\modules\project\models\Project;
|
||||
use backend\modules\settings\models\Mark;
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\ActiveForm;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model backend\modules\project\models\ProjectMark */
|
||||
/* @var $form yii\widgets\ActiveForm */
|
||||
?>
|
||||
|
||||
<div class="project-mark-form">
|
||||
|
||||
<?php $form = ActiveForm::begin(); ?>
|
||||
|
||||
<?= $form->field($model, 'project_id')->dropDownList(
|
||||
Project::find()->select(['name', 'id'])->indexBy('id')->column(),
|
||||
[
|
||||
'id' => 'project-id',
|
||||
'placeholder' => 'Выберите',
|
||||
'prompt' => 'Выберите'
|
||||
]
|
||||
) ?>
|
||||
|
||||
<?= $form->field($model, 'mark_id')->dropDownList(
|
||||
Mark::find()->select(['title', 'id'])
|
||||
->indexBy('id')
|
||||
->column(),
|
||||
[
|
||||
'placeholder' => 'Выберите',
|
||||
]
|
||||
) ?>
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton('Save', ['class' => 'btn btn-success']) ?>
|
||||
</div>
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
|
||||
</div>
|
31
backend/modules/project/views/project-mark/_search.php
Normal file
31
backend/modules/project/views/project-mark/_search.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\ActiveForm;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model backend\modules\project\models\ProjectMarkSearch */
|
||||
/* @var $form yii\widgets\ActiveForm */
|
||||
?>
|
||||
|
||||
<div class="project-mark-search">
|
||||
|
||||
<?php $form = ActiveForm::begin([
|
||||
'action' => ['index'],
|
||||
'method' => 'get',
|
||||
]); ?>
|
||||
|
||||
<?= $form->field($model, 'id') ?>
|
||||
|
||||
<?= $form->field($model, 'project_id') ?>
|
||||
|
||||
<?= $form->field($model, 'mark_id') ?>
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton('Search', ['class' => 'btn btn-primary']) ?>
|
||||
<?= Html::resetButton('Reset', ['class' => 'btn btn-default']) ?>
|
||||
</div>
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
|
||||
</div>
|
18
backend/modules/project/views/project-mark/create.php
Normal file
18
backend/modules/project/views/project-mark/create.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model backend\modules\project\models\ProjectMark */
|
||||
|
||||
$this->title = 'Добавление проекту метки';
|
||||
$this->params['breadcrumbs'][] = ['label' => 'Project Marks', 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
?>
|
||||
<div class="project-mark-create">
|
||||
|
||||
<?= $this->render('_form', [
|
||||
'model' => $model,
|
||||
]) ?>
|
||||
|
||||
</div>
|
61
backend/modules/project/views/project-mark/index.php
Normal file
61
backend/modules/project/views/project-mark/index.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
use backend\modules\project\models\Project;
|
||||
use backend\modules\settings\models\Mark;
|
||||
use yii\helpers\Html;
|
||||
use yii\grid\GridView;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $searchModel backend\modules\project\models\ProjectMarkSearch */
|
||||
/* @var $dataProvider yii\data\ActiveDataProvider */
|
||||
|
||||
$this->title = 'Метки проектов';
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
?>
|
||||
<div class="project-mark-index">
|
||||
|
||||
<p>
|
||||
<?= Html::a('Добавить проекту метку', ['create'], ['class' => 'btn btn-success']) ?>
|
||||
</p>
|
||||
|
||||
<?= GridView::widget([
|
||||
'dataProvider' => $dataProvider,
|
||||
'filterModel' => $searchModel,
|
||||
'columns' => [
|
||||
['class' => 'yii\grid\SerialColumn'],
|
||||
|
||||
[
|
||||
'attribute' => 'project_id',
|
||||
'value' => function($model){
|
||||
return $model->project->name;
|
||||
},
|
||||
'filter' => kartik\select2\Select2::widget([
|
||||
'model' => $searchModel,
|
||||
'attribute' => 'project_id',
|
||||
'data' => Project::find()->select(['name', 'id'])->indexBy('id')->column(),
|
||||
'options' => ['placeholder' => 'Начните вводить...','class' => 'form-control'],
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true
|
||||
],
|
||||
]),
|
||||
],
|
||||
[
|
||||
'attribute' => 'mark_id',
|
||||
'value' => function($model){
|
||||
return $model->mark->title;
|
||||
},
|
||||
'filter' => kartik\select2\Select2::widget([
|
||||
'model' => $searchModel,
|
||||
'attribute' => 'mark_id',
|
||||
'data' => Mark::find()->select(['title', 'id'])->indexBy('id')->column(),
|
||||
'options' => ['placeholder' => 'Начните вводить...','class' => 'form-control'],
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true
|
||||
],
|
||||
]),
|
||||
],
|
||||
|
||||
['class' => 'yii\grid\ActionColumn'],
|
||||
],
|
||||
]); ?>
|
||||
</div>
|
19
backend/modules/project/views/project-mark/update.php
Normal file
19
backend/modules/project/views/project-mark/update.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model backend\modules\project\models\ProjectMark */
|
||||
|
||||
$this->title = 'Изменение метки для проекта: ' . $model->project->name;
|
||||
$this->params['breadcrumbs'][] = ['label' => 'Project Marks', 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]];
|
||||
$this->params['breadcrumbs'][] = 'Update';
|
||||
?>
|
||||
<div class="project-mark-update">
|
||||
|
||||
<?= $this->render('_form_update', [
|
||||
'model' => $model,
|
||||
]) ?>
|
||||
|
||||
</div>
|
44
backend/modules/project/views/project-mark/view.php
Normal file
44
backend/modules/project/views/project-mark/view.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\ArrayHelper;
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\DetailView;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model backend\modules\project\models\ProjectMark */
|
||||
|
||||
$this->title = 'Проект: ' . $model->project->name . '; Метка: ' . $model->mark->title;
|
||||
$this->params['breadcrumbs'][] = ['label' => 'Project Marks', 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
\yii\web\YiiAsset::register($this);
|
||||
?>
|
||||
<div class="project-mark-view">
|
||||
|
||||
<p>
|
||||
<?= Html::a('Список', ['index', 'id' => $model->id], ['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',
|
||||
[
|
||||
'attribute' => 'project_id',
|
||||
'value' => ArrayHelper::getValue($model, 'project.name' ),
|
||||
],
|
||||
[
|
||||
'attribute' => 'mark_id',
|
||||
'value' => ArrayHelper::getValue($model, 'mark.title' ),
|
||||
]
|
||||
],
|
||||
]) ?>
|
||||
|
||||
</div>
|
@ -16,7 +16,7 @@ use yii\widgets\ActiveForm;
|
||||
<?php $form = ActiveForm::begin(); ?>
|
||||
|
||||
<?= $form->field($model, 'project_id')->dropDownList(
|
||||
Project::find()->select(['name', 'id'])->indexBy('id')->column(),
|
||||
Project::find()->select(['name', 'id'])->indexBy('id')->column(),
|
||||
[
|
||||
'id' => 'project-id',
|
||||
'prompt' => 'Выберите'
|
||||
@ -29,21 +29,19 @@ use yii\widgets\ActiveForm;
|
||||
'options' => ['id' => 'card_id'],
|
||||
'pluginOptions' => [
|
||||
'depends' => ['project-id'],
|
||||
'placeholder' => 'Выберите',
|
||||
'url' => Url::to(['/project/project-user/users-not-on-project'])
|
||||
,'initialize' => false,
|
||||
],
|
||||
|
||||
'type' => DepDrop::TYPE_SELECT2,
|
||||
'select2Options' => [
|
||||
'hideSearch' => false,
|
||||
'pluginOptions' => [
|
||||
'placeholder' => 'Вводите фио',
|
||||
'allowClear' => true,
|
||||
'closeOnSelect' => false,
|
||||
'multiple' => true,
|
||||
'hideSearch' => false
|
||||
],
|
||||
'showToggleAll' => false,
|
||||
'showToggleAll' => true,
|
||||
],
|
||||
]
|
||||
);
|
||||
|
Reference in New Issue
Block a user