task priority, comments

This commit is contained in:
Kavalar 2023-05-12 02:12:43 +03:00
parent d6f5ffcd26
commit 7eab647ff7
25 changed files with 887 additions and 7 deletions

View File

@ -86,6 +86,9 @@ return [
'knowledgelevel' => [ 'knowledgelevel' => [
'class' => 'backend\modules\knowledgelevel\KnowledgeLevel', 'class' => 'backend\modules\knowledgelevel\KnowledgeLevel',
], ],
'comment' => [
'class' => 'backend\modules\comment\Comment',
],
], ],
'components' => [ 'components' => [
'request' => [ 'request' => [

View File

@ -0,0 +1,24 @@
<?php
namespace backend\modules\comment;
/**
* comment module definition class
*/
class Comment extends \yii\base\Module
{
/**
* {@inheritdoc}
*/
public $controllerNamespace = 'backend\modules\comment\controllers';
/**
* {@inheritdoc}
*/
public function init()
{
parent::init();
// custom initialization code goes here
}
}

View File

@ -0,0 +1,127 @@
<?php
namespace backend\modules\comment\controllers;
use backend\modules\comment\models\Comment;
use backend\modules\comment\models\CommentSearch;
use Yii;
use yii\filters\VerbFilter;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
/**
* CommentController implements the CRUD actions for Comment model.
*/
class CommentController extends Controller
{
/**
* {@inheritdoc}
*/
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
* Lists all Comment models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new CommentSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single Comment 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 Comment model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Comment();
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 Comment 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 Comment 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 Comment model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Comment the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Comment::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException('The requested page does not exist.');
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace backend\modules\comment\controllers;
use yii\web\Controller;
/**
* Default controller for the `comment` module
*/
class DefaultController extends Controller
{
/**
* Renders the index view for the module
* @return string
*/
public function actionIndex()
{
return $this->render('index');
}
}

View File

@ -0,0 +1,8 @@
<?php
namespace backend\modules\comment\models;
class Comment extends \common\models\Comment
{
}

View File

@ -0,0 +1,75 @@
<?php
namespace backend\modules\comment\models;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use backend\modules\comment\models\Comment;
/**
* CommentSearch represents the model behind the search form of `backend\modules\comment\models\Comment`.
*/
class CommentSearch extends Comment
{
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['id', 'user_id', 'parent_id', 'entity_type', 'entity_id', 'status'], 'integer'],
[['created_at', 'updated_at', 'text'], '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 = Comment::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,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
'user_id' => $this->user_id,
'parent_id' => $this->parent_id,
'entity_type' => $this->entity_type,
'entity_id' => $this->entity_id,
'status' => $this->status,
]);
$query->andFilterWhere(['like', 'text', $this->text]);
return $dataProvider;
}
}

View File

@ -0,0 +1,43 @@
<?php
use kartik\select2\Select2;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model backend\modules\comment\models\Comment */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="comment-form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'user_id')->widget(
Select2::class,
[
'data' => \common\models\UserCard::getListUserWithUserId(),
'options' => ['placeholder' => '...', 'class' => 'form-control'],
'pluginOptions' => [
'allowClear' => true
],
]
); ?>
<?= $form->field($model, 'parent_id')->textInput() ?>
<?= $form->field($model, 'entity_type')->dropDownList(\common\models\Comment::getEntityTypeList()) ?>
<?= $form->field($model, 'entity_id')->textInput() ?>
<?= $form->field($model, 'status')->dropDownList(\common\models\Comment::getStatusList()) ?>
<?= $form->field($model, 'text')->textarea(['rows' => 6]) ?>
<div class="form-group">
<?= Html::submitButton('Save', ['class' => 'btn btn-success']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

View File

@ -0,0 +1,43 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model backend\modules\comment\models\CommentSearch */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="comment-search">
<?php $form = ActiveForm::begin([
'action' => ['index'],
'method' => 'get',
]); ?>
<?= $form->field($model, 'id') ?>
<?= $form->field($model, 'created_at') ?>
<?= $form->field($model, 'updated_at') ?>
<?= $form->field($model, 'user_id') ?>
<?= $form->field($model, 'parent_id') ?>
<?php // echo $form->field($model, 'entity_type') ?>
<?php // echo $form->field($model, 'entity_id') ?>
<?php // echo $form->field($model, 'status') ?>
<?php // echo $form->field($model, 'text') ?>
<div class="form-group">
<?= Html::submitButton('Search', ['class' => 'btn btn-primary']) ?>
<?= Html::resetButton('Reset', ['class' => 'btn btn-default']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

View File

@ -0,0 +1,18 @@
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model backend\modules\comment\models\Comment */
$this->title = 'Добавление';
$this->params['breadcrumbs'][] = ['label' => 'Комментарии', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="comment-create">
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>

View File

@ -0,0 +1,37 @@
<?php
use yii\helpers\Html;
use yii\grid\GridView;
/* @var $this yii\web\View */
/* @var $searchModel backend\modules\comment\models\CommentSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = 'Комментарии';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="comment-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'],
'id',
'created_at',
'user_id',
'entity_type',
//'status',
'text:ntext',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
</div>

View File

@ -0,0 +1,21 @@
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model backend\modules\comment\models\Comment */
$this->title = 'Update Comment: ' . $model->id;
$this->params['breadcrumbs'][] = ['label' => 'Comments', 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]];
$this->params['breadcrumbs'][] = 'Update';
?>
<div class="comment-update">
<h1><?= Html::encode($this->title) ?></h1>
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>

View File

@ -0,0 +1,44 @@
<?php
use yii\helpers\Html;
use yii\widgets\DetailView;
/* @var $this yii\web\View */
/* @var $model backend\modules\comment\models\Comment */
$this->title = $model->id;
$this->params['breadcrumbs'][] = ['label' => 'Comments', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
\yii\web\YiiAsset::register($this);
?>
<div class="comment-view">
<h1><?= Html::encode($this->title) ?></h1>
<p>
<?= Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
<?= Html::a('Delete', ['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',
'created_at',
'updated_at',
'user_id',
'parent_id',
'entity_type',
'entity_id',
'status',
'text:ntext',
],
]) ?>
</div>

View File

@ -0,0 +1,12 @@
<div class="comment-default-index">
<h1><?= $this->context->action->uniqueId ?></h1>
<p>
This is the view content for action "<?= $this->context->action->id ?>".
The action belongs to the controller "<?= get_class($this->context) ?>"
in the "<?= $this->context->module->id ?>" module.
</p>
<p>
You may customize this page by editing the following file:<br>
<code><?= __FILE__ ?></code>
</p>
</div>

View File

@ -4,6 +4,7 @@ namespace backend\modules\task\controllers;
use backend\modules\project\models\ProjectUser; use backend\modules\project\models\ProjectUser;
use backend\modules\task\models\ProjectTaskUser; use backend\modules\task\models\ProjectTaskUser;
use common\classes\Debug;
use yii\data\ActiveDataProvider; use yii\data\ActiveDataProvider;
use yii\web\Response; use yii\web\Response;
use Yii; use Yii;
@ -61,7 +62,7 @@ class TaskController extends Controller
{ {
$model = $this->findModel($id); $model = $this->findModel($id);
$taskDataProvider = new ActiveDataProvider([ $taskDataProvider = new ActiveDataProvider([
'query' => $model->getTaskUsers()->with(['task', 'projectUser']), 'query' => \common\models\ProjectTaskUser::find()->where(['task_id' => $id])->with(['user']),
'pagination' => [ 'pagination' => [
'pageSize' => 20, 'pageSize' => 20,
], ],

View File

@ -57,6 +57,8 @@ use yii\widgets\ActiveForm;
<?= $form->field($model, 'description')->textarea(['rows' => '6']) ?> <?= $form->field($model, 'description')->textarea(['rows' => '6']) ?>
<?= $form->field($model, 'priority')->input('number') ?>
<div class="form-group"> <div class="form-group">
<?= Html::submitButton('Создать', ['class' => 'btn btn-success']) ?> <?= Html::submitButton('Создать', ['class' => 'btn btn-success']) ?>
</div> </div>

View File

@ -54,13 +54,18 @@ YiiAsset::register($this);
'attribute' => 'user_id', 'attribute' => 'user_id',
'value' => ArrayHelper::getValue($model, 'user.userCard.fio'), 'value' => ArrayHelper::getValue($model, 'user.userCard.fio'),
], ],
[
'attribute' => 'executor_id',
'value' => ArrayHelper::getValue($model, 'executor.userCard.fio'),
],
'description', 'description',
'priority',
], ],
]) ?> ]) ?>
<div> <div>
<h2> <h2>
<?= 'Исполнители' ?> <?= 'Участники' ?>
</h2> </h2>
</div> </div>
@ -71,7 +76,7 @@ YiiAsset::register($this);
[ [
'attribute' => 'project_user_id', 'attribute' => 'project_user_id',
'value' => 'projectUser.card.fio' 'value' => 'user.email'
], ],
[ [

104
common/models/Comment.php Normal file
View File

@ -0,0 +1,104 @@
<?php
namespace common\models;
use Yii;
use yii\behaviors\TimestampBehavior;
use yii\db\Expression;
/**
* This is the model class for table "comment".
*
* @property int $id
* @property string $created_at
* @property string $updated_at
* @property int $user_id
* @property int $parent_id
* @property int $entity_type
* @property int $entity_id
* @property int $status
* @property string $text
*/
class Comment extends \yii\db\ActiveRecord
{
const ENTITY_TYPE_PROJECT = 1;
const ENTITY_TYPE_TASK = 2;
const STATUS_ACTIVE = 1;
const STATUS_DISABLE = 0;
/**
* @return array[]
*/
public function behaviors()
{
return [
[
'class' => TimestampBehavior::class,
'createdAtAttribute' => 'created_at',
'updatedAtAttribute' => 'updated_at',
'value' => new Expression('NOW()'),
],
];
}
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'comment';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['created_at', 'updated_at'], 'safe'],
[['user_id', 'parent_id', 'entity_type', 'entity_id', 'status'], 'integer'],
[['text'], 'string'],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'created_at' => 'Дата создания',
'updated_at' => 'Дата редактирования',
'user_id' => 'Автор',
'parent_id' => 'Родительский',
'entity_type' => 'Сущность',
'entity_id' => 'Идентификатор сущности',
'status' => 'Статус',
'text' => 'Текст',
];
}
/**
* @return string[]
*/
public static function getEntityTypeList(): array
{
return [
self::ENTITY_TYPE_PROJECT => "Проект",
self::ENTITY_TYPE_TASK => "Задача",
];
}
/**
* @return string[]
*/
public static function getStatusList(): array
{
return [
self::STATUS_ACTIVE => "Активен",
self::STATUS_DISABLE => "Не активен",
];
}
}

View File

@ -20,6 +20,7 @@ use yii\helpers\ArrayHelper;
* @property int $column_id * @property int $column_id
* @property int $user_id * @property int $user_id
* @property int $executor_id * @property int $executor_id
* @property int $priority
* @property string $description * @property string $description
* *
* @property Project $project * @property Project $project
@ -59,7 +60,7 @@ class ProjectTask extends ActiveRecord
{ {
return [ return [
[['project_id', 'status', 'title', 'description',], 'required'], [['project_id', 'status', 'title', 'description',], 'required'],
[['project_id', 'status', 'column_id', 'user_id', 'executor_id'], 'integer'], [['project_id', 'status', 'column_id', 'user_id', 'executor_id', 'priority'], 'integer'],
[['created_at', 'updated_at'], 'safe'], [['created_at', 'updated_at'], 'safe'],
['title', 'unique', 'targetAttribute' => ['title', 'project_id'], 'message' => 'Такая задача уже создана'], ['title', 'unique', 'targetAttribute' => ['title', 'project_id'], 'message' => 'Такая задача уже создана'],
[['title'], 'string', 'max' => 255], [['title'], 'string', 'max' => 255],
@ -87,6 +88,7 @@ class ProjectTask extends ActiveRecord
'user_id' => 'Создатель задачи', 'user_id' => 'Создатель задачи',
'column_id' => 'Колонка', 'column_id' => 'Колонка',
'executor_id' => 'Исполнитель', 'executor_id' => 'Исполнитель',
'priority' => 'Приоритет',
]; ];
} }
@ -112,6 +114,7 @@ class ProjectTask extends ActiveRecord
]; ];
}, },
'executor_id', 'executor_id',
'priority',
'executor' => function () { 'executor' => function () {
if ($this->executor){ if ($this->executor){
return [ return [

View File

@ -20,7 +20,7 @@ class m211020_133147_create_user_questionnaire_table extends Migration
'created_at' => $this->dateTime(), 'created_at' => $this->dateTime(),
'updated_at' => $this->dateTime(), 'updated_at' => $this->dateTime(),
'score' => $this->integer(), 'score' => $this->integer(),
'status' => $this->integer(), 'status' => $this->integer()->defaultValue(1),
]); ]);

View File

@ -0,0 +1,40 @@
<?php
use yii\db\Migration;
/**
* Class m230511_201352_add_priority_column_at_project_task_table
*/
class m230511_201352_add_priority_column_at_project_task_table extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addColumn('project_task', 'priority', $this->integer(2)->defaultValue(1));
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropColumn('project_task', 'priority');
}
/*
// Use up()/down() to run migration code without a transaction.
public function up()
{
}
public function down()
{
echo "m230511_201352_add_priority_column_at_project_task_table cannot be reverted.\n";
return false;
}
*/
}

View File

@ -0,0 +1,35 @@
<?php
use yii\db\Migration;
/**
* Handles the creation of table `{{%comment}}`.
*/
class m230511_205501_create_comment_table extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->createTable('{{%comment}}', [
'id' => $this->primaryKey(),
'created_at' => $this->dateTime(),
'updated_at' => $this->dateTime(),
'user_id' => $this->integer(11),
'parent_id' => $this->integer(11),
'entity_type' => $this->integer(2),
'entity_id' => $this->integer(11),
'status' => $this->integer(1),
'text' => $this->text()
]);
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropTable('{{%comment}}');
}
}

View File

@ -0,0 +1,136 @@
<?php
namespace frontend\modules\api\controllers;
use frontend\modules\api\models\Comment;
use yii\web\BadRequestHttpException;
class CommentController extends ApiController
{
public function verbs(): array
{
return [
'get-entity-type-list' => ['get'],
'create' => ['post'],
];
}
/**
*
* @OA\Get(path="/comment/get-entity-type-list",
* summary="Список типов сущностей",
* description="Получить список всех возможных типов сущностей",
* tags={"Comment"},
* security={
* {"bearerAuth": {}}
* },
* @OA\Response(
* response=200,
* description="Возвращает массив",
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(
* type="array",
* @OA\Items(
* @OA\Property(
* property="id",
* type="integer",
* example="1",
* ),
* @OA\Property(
* property="name",
* type="string",
* example="Проект",
* ),
* )
* ),
* ),
*
* ),
* )
*
* @return array
*/
public function actionGetEntityTypeList(): array
{
$arr = [];
foreach (Comment::getEntityTypeList() as $key => $value) {
$arr[] = ["id" => $key, "name" => $value];
}
return $arr;
}
/**
*
* @OA\Post(path="/comment/create",
* summary="Добавить комментарий",
* description="Метод для создания комментария",
* security={
* {"bearerAuth": {}}
* },
* tags={"Comment"},
*
* @OA\RequestBody(
* @OA\MediaType(
* mediaType="multipart/form-data",
* @OA\Schema(
* required={"text"},
* @OA\Property(
* property="text",
* type="string",
* description="Текст комментария",
* ),
* @OA\Property(
* property="entity_type",
* type="integer",
* description="Тип сущности",
* ),
* @OA\Property(
* property="entity_id",
* type="integer",
* description="Идентификатор сущности",
* ),
* @OA\Property(
* property="status",
* type="integer",
* description="Статус комментария",
* ),
* ),
* ),
* ),
* @OA\Response(
* response=200,
* description="Возвращает объект комментария",
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(ref="#/components/schemas/Comment"),
* ),
* ),
* )
*
* @return array|Comment
* @throws BadRequestHttpException
*/
public function actionCreate()
{
$model = new Comment();
$request = \Yii::$app->request->post();
$user_id = \Yii::$app->user->id;
if (!$user_id) {
throw new BadRequestHttpException(json_encode(['User not found']));
}
$request['user_id'] = $user_id;
$model->load($request, '');
if (!$model->save()){
return $model->errors;
}
return $model;
}
}

View File

@ -59,6 +59,11 @@ class TaskController extends ApiController
* description="статус", * description="статус",
* ), * ),
* @OA\Property( * @OA\Property(
* property="priority",
* type="integer",
* description="Приоритет задачи",
* ),
* @OA\Property(
* property="column_id", * property="column_id",
* type="integer", * type="integer",
* description="Колонка к которой относится задача", * description="Колонка к которой относится задача",
@ -275,9 +280,14 @@ class TaskController extends ApiController
* description="Идентификатор колонки", * description="Идентификатор колонки",
* ), * ),
* @OA\Property( * @OA\Property(
* property="priority",
* type="integer",
* description="Приоритет задачи",
* ),
* @OA\Property(
* property="status", * property="status",
* type="integer", * type="integer",
* description="Статус запроса", * description="Статус задачи",
* ), * ),
* @OA\Property( * @OA\Property(
* property="description", * property="description",

View File

@ -0,0 +1,63 @@
<?php
namespace frontend\modules\api\models;
/**
*
* @OA\Schema(
* schema="Comment",
* @OA\Property(
* property="id",
* type="int",
* example=12,
* description="Идентификатор комментария"
* ),
* @OA\Property(
* property="text",
* type="string",
* example="Очень хорошая задача",
* description="Текст комментария"
* ),
* @OA\Property(
* property="created_at",
* type="datetime",
* example="2023-04-07 02:09:42",
* description="Дата и время создания"
* ),
* @OA\Property(
* property="updated_at",
* type="datetime",
* example="2023-04-10 16:20:48",
* description="Дата и время обновления"
* ),
* @OA\Property(
* property="user_id",
* type="integer",
* example=19,
* description="Идентификатор пользователя"
* ),
* @OA\Property(
* property="entity_type",
* type="int",
* example=2,
* description="Идентификатор типа сущности комментария"
* ),
* @OA\Property(
* property="entity_id",
* type="int",
* example=2,
* description="Идентификатор сущности комментария"
* ),
* @OA\Property(
* property="status",
* type="integer",
* example="1",
* description="Статус"
* ),
*)
*
*/
class Comment extends \common\models\Comment
{
}

View File

@ -59,10 +59,16 @@ namespace frontend\modules\api\models;
* description="Описание задачи" * description="Описание задачи"
* ), * ),
* @OA\Property( * @OA\Property(
* property="priority",
* type="int",
* example="1",
* description="Приоритет задачи"
* ),
* @OA\Property(
* property="status", * property="status",
* type="int", * type="int",
* example="1", * example="1",
* description="Статус колонки" * description="Статус задачи"
* ), * ),
* @OA\Property( * @OA\Property(
* property="taskUsers", * property="taskUsers",