rename task to project_task and task_user to project_task_user; create project_task_category, fix bug in create project method
This commit is contained in:
parent
8b2bb7468c
commit
9eba04cae2
@ -166,4 +166,25 @@ class ProjectUserController extends Controller
|
||||
|
||||
return $this->redirect(['index']);
|
||||
}
|
||||
|
||||
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 = ProjectUser::getUsersNotOnProject($project_id);
|
||||
|
||||
$formattedCatArr = array();
|
||||
foreach ($categories as $key => $value){
|
||||
$formattedCatArr[] = array('id' => $key, 'name' => $value);
|
||||
}
|
||||
|
||||
return ['output'=>$formattedCatArr, 'selected'=>''];
|
||||
}
|
||||
}
|
||||
return ['output'=>'', 'selected'=>''];
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,9 @@
|
||||
<?php
|
||||
|
||||
use backend\modules\card\models\UserCard;
|
||||
use backend\modules\project\models\Project;
|
||||
use common\models\User;
|
||||
use kartik\select2\Select2;
|
||||
use kartik\depdrop\DepDrop;
|
||||
use yii\helpers\Html;
|
||||
use yii\helpers\Url;
|
||||
use yii\widgets\ActiveForm;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
@ -16,26 +15,42 @@ use yii\widgets\ActiveForm;
|
||||
|
||||
<?php $form = ActiveForm::begin(); ?>
|
||||
|
||||
<?= $form->field($model, 'project_id')->widget(Select2::className(),
|
||||
<?= $form->field($model, 'project_id')->dropDownList(
|
||||
Project::find()->select(['name', 'id'])->indexBy('id')->column(),
|
||||
[
|
||||
'data' => Project::find()->select(['name', 'id'])->indexBy('id')->column(),
|
||||
'options' => ['placeholder' => '...','class' => 'form-control'],
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true
|
||||
],
|
||||
'id' => 'project-id',
|
||||
'prompt' => 'Выберите'
|
||||
]
|
||||
) ?>
|
||||
);
|
||||
?>
|
||||
|
||||
<?= $form->field($model, 'card_id')->widget(Select2::className(),
|
||||
<?= $form->field($model, 'card_id')->widget(DepDrop::className(),
|
||||
[
|
||||
'data' => UserCard::find()->select(['fio', 'id'])->indexBy('id')->column(),
|
||||
'options' => ['placeholder' => '...','class' => 'form-control'],
|
||||
'options' => ['id' => 'card_id'],
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true,
|
||||
'multiple' => true,
|
||||
'depends' => ['project-id'],
|
||||
'placeholder' => 'Выберите',
|
||||
'url' => Url::to(['/project/project-user/users-not-on-project'])
|
||||
,'initialize' => false,
|
||||
],
|
||||
|
||||
'type' => DepDrop::TYPE_SELECT2,
|
||||
'select2Options' => [
|
||||
'hideSearch' => false,
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true,
|
||||
'closeOnSelect' => false,
|
||||
'multiple' => true,
|
||||
'hideSearch' => false
|
||||
],
|
||||
'showToggleAll' => false,
|
||||
],
|
||||
]
|
||||
) ?>
|
||||
);
|
||||
echo "<p>
|
||||
* в списке отображаются только пользователи у которых присудствует запись в таблице user (в user_card есть id_user)
|
||||
</p>";
|
||||
?>
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton('Сохранить', ['class' => 'btn btn-success']) ?>
|
||||
|
@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
namespace backend\modules\task\controllers;
|
||||
|
||||
use Yii;
|
||||
use backend\modules\task\models\ProjectTaskCategory;
|
||||
use backend\modules\task\models\ProjectTaskCategorySearch;
|
||||
use yii\web\Controller;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\filters\VerbFilter;
|
||||
|
||||
/**
|
||||
* ProjectTaskCategoryController implements the CRUD actions for ProjectTaskCategory model.
|
||||
*/
|
||||
class ProjectTaskCategoryController extends Controller
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function behaviors()
|
||||
{
|
||||
return [
|
||||
'verbs' => [
|
||||
'class' => VerbFilter::className(),
|
||||
'actions' => [
|
||||
'delete' => ['POST'],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all ProjectTaskCategory models.
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionIndex()
|
||||
{
|
||||
$searchModel = new ProjectTaskCategorySearch();
|
||||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
||||
|
||||
return $this->render('index', [
|
||||
'searchModel' => $searchModel,
|
||||
'dataProvider' => $dataProvider,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a single ProjectTaskCategory 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 ProjectTaskCategory model.
|
||||
* If creation is successful, the browser will be redirected to the 'view' page.
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionCreate()
|
||||
{
|
||||
$model = new ProjectTaskCategory();
|
||||
|
||||
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 ProjectTaskCategory 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 ProjectTaskCategory 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 ProjectTaskCategory model based on its primary key value.
|
||||
* If the model is not found, a 404 HTTP exception will be thrown.
|
||||
* @param integer $id
|
||||
* @return ProjectTaskCategory the loaded model
|
||||
* @throws NotFoundHttpException if the model cannot be found
|
||||
*/
|
||||
protected function findModel($id)
|
||||
{
|
||||
if (($model = ProjectTaskCategory::findOne($id)) !== null) {
|
||||
return $model;
|
||||
}
|
||||
|
||||
throw new NotFoundHttpException('The requested page does not exist.');
|
||||
}
|
||||
}
|
9
backend/modules/task/models/ProjectTaskCategory.php
Normal file
9
backend/modules/task/models/ProjectTaskCategory.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace backend\modules\task\models;
|
||||
|
||||
|
||||
class ProjectTaskCategory extends \common\models\ProjectTaskCategory
|
||||
{
|
||||
|
||||
}
|
69
backend/modules/task/models/ProjectTaskCategorySearch.php
Normal file
69
backend/modules/task/models/ProjectTaskCategorySearch.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace backend\modules\task\models;
|
||||
|
||||
use yii\base\Model;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use backend\modules\task\models\ProjectTaskCategory;
|
||||
|
||||
/**
|
||||
* ProjectTaskCategorySearch represents the model behind the search form of `backend\modules\task\models\ProjectTaskCategory`.
|
||||
*/
|
||||
class ProjectTaskCategorySearch extends ProjectTaskCategory
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['id', 'project_id'], 'integer'],
|
||||
[['title'], 'safe'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@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 = ProjectTaskCategory::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,
|
||||
]);
|
||||
|
||||
$query->andFilterWhere(['like', 'title', $this->title]);
|
||||
|
||||
return $dataProvider;
|
||||
}
|
||||
}
|
32
backend/modules/task/views/project-task-category/_form.php
Normal file
32
backend/modules/task/views/project-task-category/_form.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use backend\modules\project\models\Project;
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\ActiveForm;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model backend\modules\task\models\ProjectTaskCategory */
|
||||
/* @var $form yii\widgets\ActiveForm */
|
||||
?>
|
||||
|
||||
<div class="project-task-category-form">
|
||||
|
||||
<?php $form = ActiveForm::begin(); ?>
|
||||
|
||||
<?= $form->field($model, 'title')->textInput(['maxlength' => true]) ?>
|
||||
|
||||
<?= $form->field($model, 'project_id')->dropDownList(
|
||||
Project::find()->select(['name', 'id'])->indexBy('id')->column(),
|
||||
[
|
||||
'id' => 'project_id',
|
||||
'prompt' => 'Выберите'
|
||||
]
|
||||
); ?>
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton('Сохранить', ['class' => 'btn btn-success']) ?>
|
||||
</div>
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
|
||||
</div>
|
31
backend/modules/task/views/project-task-category/_search.php
Normal file
31
backend/modules/task/views/project-task-category/_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\task\models\ProjectTaskCategorySearch */
|
||||
/* @var $form yii\widgets\ActiveForm */
|
||||
?>
|
||||
|
||||
<div class="project-task-category-search">
|
||||
|
||||
<?php $form = ActiveForm::begin([
|
||||
'action' => ['index'],
|
||||
'method' => 'get',
|
||||
]); ?>
|
||||
|
||||
<?= $form->field($model, 'id') ?>
|
||||
|
||||
<?= $form->field($model, 'title') ?>
|
||||
|
||||
<?= $form->field($model, 'project_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/task/views/project-task-category/create.php
Normal file
18
backend/modules/task/views/project-task-category/create.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model backend\modules\task\models\ProjectTaskCategory */
|
||||
|
||||
$this->title = 'Создание категории задач';
|
||||
$this->params['breadcrumbs'][] = ['label' => 'Project Task Categories', 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
?>
|
||||
<div class="project-task-category-create">
|
||||
|
||||
<?= $this->render('_form', [
|
||||
'model' => $model,
|
||||
]) ?>
|
||||
|
||||
</div>
|
51
backend/modules/task/views/project-task-category/index.php
Normal file
51
backend/modules/task/views/project-task-category/index.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
use backend\modules\project\models\Project;
|
||||
use kartik\select2\Select2;
|
||||
use yii\helpers\Html;
|
||||
use yii\grid\GridView;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $searchModel backend\modules\task\models\ProjectTaskCategorySearch */
|
||||
/* @var $dataProvider yii\data\ActiveDataProvider */
|
||||
|
||||
$this->title = 'Категории задач проекта';
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
?>
|
||||
<div class="project-task-category-index">
|
||||
|
||||
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
|
||||
|
||||
<p>
|
||||
<?= Html::a('Создать категорию задач', ['create'], ['class' => 'btn btn-success']) ?>
|
||||
</p>
|
||||
|
||||
<?= GridView::widget([
|
||||
'dataProvider' => $dataProvider,
|
||||
'filterModel' => $searchModel,
|
||||
'columns' => [
|
||||
['class' => 'yii\grid\SerialColumn'],
|
||||
|
||||
'title',
|
||||
[
|
||||
'attribute' => 'project_id',
|
||||
'value' => 'project.name',
|
||||
'filter' => Select2::widget([
|
||||
'model' => $searchModel,
|
||||
'attribute' => 'project_id',
|
||||
'data' => Project::find()->select(['project.name', 'project.id'])
|
||||
->indexBy('project.id')->column(),
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true,
|
||||
],
|
||||
'options' => [
|
||||
'class' => 'form-control',
|
||||
'placeholder' => 'Выберите значение'
|
||||
],
|
||||
])
|
||||
],
|
||||
|
||||
['class' => 'yii\grid\ActionColumn'],
|
||||
],
|
||||
]); ?>
|
||||
</div>
|
21
backend/modules/task/views/project-task-category/update.php
Normal file
21
backend/modules/task/views/project-task-category/update.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model backend\modules\task\models\ProjectTaskCategory */
|
||||
|
||||
$this->title = 'Update Project Task Category: ' . $model->title;
|
||||
$this->params['breadcrumbs'][] = ['label' => 'Project Task Categories', 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = ['label' => $model->title, 'url' => ['view', 'id' => $model->id]];
|
||||
$this->params['breadcrumbs'][] = 'Update';
|
||||
?>
|
||||
<div class="project-task-category-update">
|
||||
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
||||
<?= $this->render('_form', [
|
||||
'model' => $model,
|
||||
]) ?>
|
||||
|
||||
</div>
|
40
backend/modules/task/views/project-task-category/view.php
Normal file
40
backend/modules/task/views/project-task-category/view.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\ArrayHelper;
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\DetailView;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model backend\modules\task\models\ProjectTaskCategory */
|
||||
|
||||
$this->title = $model->title;
|
||||
$this->params['breadcrumbs'][] = ['label' => 'Project Task Categories', 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
\yii\web\YiiAsset::register($this);
|
||||
?>
|
||||
<div class="project-task-category-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' => [
|
||||
'title',
|
||||
[
|
||||
'attribute' => 'project_id',
|
||||
'value' => ArrayHelper::getValue($model, 'project.name'),
|
||||
],
|
||||
],
|
||||
]) ?>
|
||||
|
||||
</div>
|
@ -37,7 +37,7 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
'model' => $searchModel,
|
||||
'attribute' => 'task_id',
|
||||
'data' => ProjectTaskUser::find()->joinWith('task')
|
||||
->select(['task.title', 'task.id'])->indexBy('task.id')->column(),
|
||||
->select(['project_task.title', 'project_task.id'])->indexBy('project_task.id')->column(),
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true,
|
||||
'width' => '250px',
|
||||
@ -55,7 +55,7 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
'model' => $searchModel,
|
||||
'attribute' => 'project_user_id',
|
||||
'data' => ProjectTaskUser::find()->joinWith('projectUser.card')
|
||||
->select(['user_card.fio', 'task_user.id'])->column(),
|
||||
->select(['user_card.fio', 'project_task_user.id'])->column(),
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true,
|
||||
'width' => '250px',
|
||||
|
@ -68,6 +68,7 @@
|
||||
'items' => [
|
||||
['label' => 'Задачи', 'icon' => 'minus', 'url' => ['/task/task'], 'active' => \Yii::$app->controller->id == 'task'],
|
||||
['label' => 'Исполнители задачи', 'icon' => 'users', 'url' => ['/task/task-user'], 'active' => \Yii::$app->controller->id == 'task-user'],
|
||||
['label' => 'Категории задач', 'icon' => 'users', 'url' => ['/task/project-task-category'], 'active' => \Yii::$app->controller->id == 'project-task-category'],
|
||||
],
|
||||
'visible' => Yii::$app->user->can('task')
|
||||
],
|
||||
|
57
common/models/ProjectTaskCategory.php
Normal file
57
common/models/ProjectTaskCategory.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace common\models;
|
||||
|
||||
use Yii;
|
||||
|
||||
/**
|
||||
* This is the model class for table "project_task_category".
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $title
|
||||
* @property int $project_id
|
||||
*
|
||||
* @property Project $project
|
||||
*/
|
||||
class ProjectTaskCategory extends \yii\db\ActiveRecord
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return 'project_task_category';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['project_id'], 'integer'],
|
||||
[['title'], 'string', 'max' => 255],
|
||||
[['project_id'], 'exist', 'skipOnError' => true, 'targetClass' => Project::className(), 'targetAttribute' => ['project_id' => 'id']],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'id' => 'ID',
|
||||
'title' => 'Название',
|
||||
'project_id' => 'Проект',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
*/
|
||||
public function getProject()
|
||||
{
|
||||
return $this->hasOne(Project::className(), ['id' => 'project_id']);
|
||||
}
|
||||
}
|
@ -150,4 +150,15 @@ class ProjectUser extends \yii\db\ActiveRecord
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function getUsersNotOnProject($project_id): array
|
||||
{
|
||||
$usersIdList = ProjectUser::find()->where(['project_id' => $project_id])->select('card_id')->column();
|
||||
|
||||
$userCards = UserCard::find()
|
||||
->where(['not in', 'id', $usersIdList])
|
||||
->andWhere(['not', ['id_user' => null]])
|
||||
->all();
|
||||
return ArrayHelper::map($userCards, 'id', 'fio');
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user