task users, set priority at column and task, timer entity

This commit is contained in:
2023-05-23 02:11:44 +03:00
parent c50dc189a7
commit 5da6746cc4
12 changed files with 794 additions and 8 deletions

View File

@ -106,7 +106,9 @@ class Project extends \yii\db\ActiveRecord
*/
public function getColumns()
{
return $this->hasMany(ProjectColumn::class, ['project_id' => 'id'])->with('tasks')->where(['status' => ProjectColumn::STATUS_ACTIVE]);
return $this->hasMany(ProjectColumn::class, ['project_id' => 'id'])
->with('tasks')
->where(['status' => ProjectColumn::STATUS_ACTIVE])->orderBy('priority');
}
/**

View File

@ -126,6 +126,9 @@ class ProjectColumn extends \yii\db\ActiveRecord
*/
public function getTasks()
{
return $this->hasMany(ProjectTask::class, ['column_id' => 'id'])->with('taskUsers')->where(['status' => ProjectTask::STATUS_ACTIVE]);
return $this->hasMany(ProjectTask::class, ['column_id' => 'id'])
->with('taskUsers')
->where(['status' => ProjectTask::STATUS_ACTIVE])
->orderBy('priority');
}
}

View File

@ -116,7 +116,7 @@ class ProjectTask extends ActiveRecord
'executor_id',
'priority',
'executor' => function () {
if ($this->executor){
if ($this->executor) {
return [
"fio" => $this->executor->userCard->fio ?? $this->executor->username,
"avatar" => $this->executor->userCard->photo ?? '',
@ -125,10 +125,11 @@ class ProjectTask extends ActiveRecord
return null;
},
'comment_count' => function(){
'comment_count' => function () {
return Comment::find()->where(['entity_id' => $this->id, 'entity_type' => 2, 'status' => Comment::STATUS_ACTIVE])->count();
},
'taskUsers',
'timers',
];
}
@ -191,6 +192,11 @@ class ProjectTask extends ActiveRecord
return $this->hasMany(ProjectTaskUser::className(), ['task_id' => 'id']);
}
public function getTimers()
{
return $this->hasMany(Timer::class, ['entity_id' => 'id'])->where(['status' => Timer::STATUS_ACTIVE]);
}
public static function usersByTaskArr($task_id): array
{
return ArrayHelper::map(

117
common/models/Timer.php Normal file
View File

@ -0,0 +1,117 @@
<?php
namespace common\models;
use common\classes\Debug;
use Yii;
use yii\behaviors\TimestampBehavior;
use yii\db\Expression;
/**
* This is the model class for table "timer".
*
* @property int $id
* @property string $created_at
* @property string $stopped_at
* @property int $user_id
* @property int $entity_type
* @property int $entity_id
* @property int $status
*/
class Timer extends \yii\db\ActiveRecord
{
const STATUS_ACTIVE = 1;
const STATUS_DISABLE = 0;
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'timer';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['created_at', 'stopped_at'], 'safe'],
[['user_id', 'entity_type', 'entity_id'], 'required'],
[['user_id', 'entity_type', 'entity_id', 'status'], 'integer'],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'created_at' => 'Created At',
'stopped_at' => 'Stopped At',
'user_id' => 'User ID',
'entity_type' => 'Entity Type',
'entity_id' => 'Entity ID',
'status' => 'Status',
];
}
/**
* @return array
*/
public function fields(): array
{
return [
'id',
'user_id',
'created_at',
'stopped_at',
'entity_id',
'entity_type',
'delta' => function(){
return $this->getDelta();
},
'deltaSeconds' => function(){
return $this->getDeltaSeconds();
},
'status',
];
}
/**
* @return \DateInterval|false
*/
public function getDelta()
{
$create = date_create($this->created_at);
$stopped = date_create($this->stopped_at);
return date_diff($create, $stopped);
}
/**
* @return int
*/
public function getDeltaSeconds(): int
{
$create = date_create($this->created_at);
$stopped = date_create($this->stopped_at);
return $stopped->getTimestamp() - $create->getTimestamp();
}
/**
* @return string[]
*/
public static function getStatusList(): array
{
return [
self::STATUS_ACTIVE => "Активен",
self::STATUS_DISABLE => "Не активен",
];
}
}