add import tasks to xlsx
This commit is contained in:
@ -11,6 +11,8 @@ use Yii;
|
||||
* @property int $mark_id
|
||||
* @property int $entity_type
|
||||
* @property int $entity_id
|
||||
*
|
||||
* @property Mark $mark
|
||||
*/
|
||||
class MarkEntity extends \yii\db\ActiveRecord
|
||||
{
|
||||
|
@ -29,6 +29,9 @@ use yii\helpers\ArrayHelper;
|
||||
* @property User $user
|
||||
* @property UserCard $card
|
||||
* @property UserCard $cardIdCreator
|
||||
* @property Company $company
|
||||
* @property ProjectColumn $column
|
||||
* @property User $executor
|
||||
* @property Mark[] $mark
|
||||
* @property MarkEntity[] $markEntity
|
||||
* @property ProjectTaskUser[] $taskUsers
|
||||
@ -42,6 +45,8 @@ class ProjectTask extends ActiveRecord
|
||||
const PRIORITY_MEDIUM = 1;
|
||||
const PRIORITY_HIGH = 2;
|
||||
|
||||
const DAY_IN_UNIX_TIME = 86340; // 23:59:59
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
@ -147,7 +152,7 @@ class ProjectTask extends ActiveRecord
|
||||
'user_id',
|
||||
'user' => function () {
|
||||
return [
|
||||
"fio" => $this->user->userCard->fio ?? $this->user->id,
|
||||
"fio" => $this->user->userCard->fio ?? ($this->user->id ?? ''),
|
||||
"avatar" => $this->user->userCard->photo ?? '',
|
||||
];
|
||||
},
|
||||
@ -164,7 +169,7 @@ class ProjectTask extends ActiveRecord
|
||||
return null;
|
||||
},
|
||||
'comment_count' => function () {
|
||||
return Comment::find()->where(['entity_id' => $this->id, 'entity_type' => 2, 'status' => Comment::STATUS_ACTIVE])->count();
|
||||
return $this->getCommentCount();
|
||||
},
|
||||
'taskUsers',
|
||||
'mark',
|
||||
@ -172,6 +177,14 @@ class ProjectTask extends ActiveRecord
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool|int|string|null
|
||||
*/
|
||||
public function getCommentCount()
|
||||
{
|
||||
return Comment::find()->where(['entity_id' => $this->id, 'entity_type' => 2, 'status' => Comment::STATUS_ACTIVE])->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
@ -215,6 +228,15 @@ class ProjectTask extends ActiveRecord
|
||||
return $this->hasOne(Project::className(), ['id' => 'project_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ActiveQuery
|
||||
*/
|
||||
public function getCompany(): ActiveQuery
|
||||
{
|
||||
return $this->hasOne(Company::class,['id' => 'company_id'])
|
||||
->via('project');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ActiveQuery
|
||||
*/
|
||||
@ -275,4 +297,71 @@ class ProjectTask extends ActiveRecord
|
||||
return ArrayHelper::map(
|
||||
self::find()->joinWith(['user', 'project'])->where(['project_id' => $task_id])->all(), 'id', 'user.username');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTaskUsersToStr(): string
|
||||
{
|
||||
$participants = '';
|
||||
foreach ($this->taskUsers as $taskUser) {
|
||||
$participants .= $taskUser->user->userCard->fio ?? $taskUser->user->username;
|
||||
$participants .= ', ';
|
||||
}
|
||||
return $participants;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getMarkTitleToStr(): string
|
||||
{
|
||||
$tags = '';
|
||||
foreach ($this->markEntity as $markEntity) {
|
||||
$tags .= $markEntity->mark->title . ', ';
|
||||
}
|
||||
return $tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|null $companyId
|
||||
* @param int|null $userId
|
||||
* @param int|null $projectId
|
||||
* @param int|null $fromDate
|
||||
* @param int|null $toDate
|
||||
* @return ActiveQuery
|
||||
*/
|
||||
public static function genQueryToImport(
|
||||
int $companyId = null,
|
||||
int $userId = null,
|
||||
int $projectId = null,
|
||||
int $fromDate = null,
|
||||
int $toDate = null
|
||||
): ActiveQuery
|
||||
{
|
||||
$query = ProjectTask::find();
|
||||
|
||||
if ($companyId) {
|
||||
$query->joinWith('company')
|
||||
->andWhere(['company.id' => $companyId]);
|
||||
}
|
||||
|
||||
if ($userId) {
|
||||
$query->andWhere(['project_task.user_id' => $userId]);
|
||||
}
|
||||
|
||||
if ($projectId) {
|
||||
$query->andWhere(['project_task.project_id' => $projectId]);
|
||||
}
|
||||
|
||||
if ($fromDate) {
|
||||
$query->andFilterWhere(['>=', 'project_task.created_at', date("Y-m-d H:i:s", $fromDate)]);
|
||||
}
|
||||
|
||||
if ($toDate) {
|
||||
$query->andFilterWhere(['<=', 'project_task.created_at', date("Y-m-d H:i:s", ($toDate + self::DAY_IN_UNIX_TIME))]);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
|
@ -11,8 +11,8 @@ use yii\db\ActiveQuery;
|
||||
* @property int $task_id
|
||||
* @property int $user_id
|
||||
*
|
||||
* @property ProjectUser $projectUser
|
||||
* @property ProjectTask $task
|
||||
* @property User $user
|
||||
*/
|
||||
class ProjectTaskUser extends \yii\db\ActiveRecord
|
||||
{
|
||||
|
44
common/models/forms/TasksImportForm.php
Normal file
44
common/models/forms/TasksImportForm.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace common\models\forms;
|
||||
use yii\base\Model;
|
||||
|
||||
class TasksImportForm extends Model
|
||||
{
|
||||
public $companyId;
|
||||
public $userId;
|
||||
public $projectId;
|
||||
public $fromDate;
|
||||
public $toDate;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['companyId', 'userId', 'projectId'], 'integer'],
|
||||
['fromDate', 'date', 'format' => 'php:Y-m-d', 'timestampAttribute' => 'fromDate'],
|
||||
['toDate', 'date', 'format' => 'php:Y-m-d', 'timestampAttribute' => 'toDate'],
|
||||
];
|
||||
}
|
||||
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'companyId' => 'ID компании',
|
||||
'userId' => 'ID пользователя',
|
||||
'projectId' => 'ID проекта',
|
||||
'fromDate' => 'Дата начала поиска',
|
||||
'toDate' => 'Дата конца поиска',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function formName(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user