Merge pull request #70 from apuc/add_task

Add task
This commit is contained in:
2021-11-25 13:02:08 +03:00
committed by GitHub
76 changed files with 10938 additions and 48 deletions

View File

@ -64,6 +64,9 @@ class ScoreCalculatorHelper
case '3': // multi answer
$score += $response_question['question']['score'] / self::correctAnswersNum($response_question['question']['id']);
break;
case '4': // istina-loz
$score += $response_question['question']['score'];
break;
}
}
}

72
common/models/Manager.php Normal file
View File

@ -0,0 +1,72 @@
<?php
namespace common\models;
use Yii;
use yii\db\ActiveQuery;
/**
* This is the model class for table "manager".
*
* @property int $id
* @property int $user_id
*
* @property User $user
* @property ManagerEmployee[] $managerEmployees
*/
class Manager extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'manager';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['user_id'], 'integer'],
[['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'id']],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'user_id' => 'Пользователь',
];
}
public function beforeDelete()
{
foreach ($this->managerEmployees as $employee){
$employee->delete();
}
return parent::beforeDelete();
}
/**
* @return ActiveQuery
*/
public function getUser()
{
return $this->hasOne(User::className(), ['id' => 'user_id']);
}
/**
* @return ActiveQuery
*/
public function getManagerEmployees()
{
return $this->hasMany(ManagerEmployee::className(), ['manager_id' => 'id']);
}
}

View File

@ -0,0 +1,67 @@
<?php
namespace common\models;
use yii\db\ActiveQuery;
/**
* This is the model class for table "manager_employee".
*
* @property int $id
* @property int $manager_id
* @property int $employee_id
*
* @property User $user
* @property Manager $manager
*/
class ManagerEmployee extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'manager_employee';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['manager_id', 'employee_id'], 'required'],
[['manager_id', 'employee_id'], 'integer'],
[['employee_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['employee_id' => 'id']],
[['manager_id'], 'exist', 'skipOnError' => true, 'targetClass' => Manager::className(), 'targetAttribute' => ['manager_id' => 'id']],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'manager_id' => 'Менеджер',
'employee_id' => 'Работник',
];
}
/**
* @return ActiveQuery
*/
public function getUser()
{
return $this->hasOne(User::className(), ['id' => 'employee_id']);
}
/**
* @return ActiveQuery
*/
public function getManager()
{
return $this->hasOne(Manager::className(), ['id' => 'manager_id']);
}
}

67
common/models/ProjectUser.php Executable file → Normal file
View File

@ -2,17 +2,20 @@
namespace common\models;
use Yii;
use yii\db\ActiveQuery;
use yii\helpers\ArrayHelper;
/**
* This is the model class for table "project_user".
*
* @property int $id
* @property int $card_id
* @property int $project_id
* @property int $user_id
*
* @property Project $project
* @property UserCard $card
* @property User $user
* @property Task[] $tasks
* @property TaskUser[] $taskUsers
*/
class ProjectUser extends \yii\db\ActiveRecord
{
@ -30,10 +33,10 @@ class ProjectUser extends \yii\db\ActiveRecord
public function rules()
{
return [
[['card_id', 'project_id'], 'required'],
[['card_id', 'project_id'], 'integer'],
[['project_id', 'user_id'], 'required'],
[['project_id', 'user_id'], 'integer'],
[['project_id'], 'exist', 'skipOnError' => true, 'targetClass' => Project::className(), 'targetAttribute' => ['project_id' => 'id']],
[['card_id'], 'exist', 'skipOnError' => true, 'targetClass' => UserCard::className(), 'targetAttribute' => ['card_id' => 'id']],
[['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'id']],
];
}
@ -44,24 +47,68 @@ class ProjectUser extends \yii\db\ActiveRecord
{
return [
'id' => 'ID',
'card_id' => 'Card ID',
'project_id' => 'Project ID',
'project_id' => 'Проект',
'user_id' => 'Сотрудник',
];
}
/**
* @return \yii\db\ActiveQuery
* @return ActiveQuery
*/
public function getProject()
{
return $this->hasOne(Project::className(), ['id' => 'project_id']);
}
/**
* @return ActiveQuery
*/
public function getUser()
{
return $this->hasOne(User::className(), ['id' => 'user_id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getCard()
{
return $this->hasOne(UserCard::className(), ['id' => 'card_id']);
return $this->hasOne(UserCard::className(), ['id_user' => 'user_id']);
}
/**
* @return ActiveQuery
*/
public function getTasks()
{
return $this->hasMany(Task::className(), ['project_user_id' => 'id']);
}
/**
* @return ActiveQuery
*/
public function getTasksByProject()
{
return $this->hasMany(Task::className(), ['project_id' => 'project_id']);
}
/**
* @return ActiveQuery
*/
public function getTaskUsers()
{
return $this->hasMany(TaskUser::className(), ['project_user_id' => 'id']);
}
public static function usersByProjectArr($project_id): array
{
return ArrayHelper::map(
self::find()->joinWith('user')->where(['project_id' => $project_id])->all(), 'id', 'user.username');
}
public static function usersByTaskArr($task_id): array
{
return ArrayHelper::map(
self::find()->joinWith(['tasksByProject', 'user'])->where(['task.id' => $task_id])->all(), 'id', 'user.username');
}
}

132
common/models/Task.php Normal file
View File

@ -0,0 +1,132 @@
<?php
namespace common\models;
use phpDocumentor\Reflection\Types\This;
use Yii;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveQuery;
use yii\db\Expression;
use yii\helpers\ArrayHelper;
/**
* This is the model class for table "task".
*
* @property int $id
* @property int $project_id
* @property string $title
* @property int $status
* @property string $created_at
* @property string $updated_at
* @property int $project_user_id
* @property int $user_id
* @property string $description
*
* @property Project $project
* @property ProjectUser $projectUser
* @property User $user
* @property TaskUser[] $taskUsers
*/
class Task extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'task';
}
public function behaviors()
{
return [
[
'class' => TimestampBehavior::class,
'createdAtAttribute' => 'created_at',
'updatedAtAttribute' => 'updated_at',
'value' => new Expression('NOW()'),
],
];
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['project_id', 'status', 'title', 'description', 'project_user_id'], 'required'],
[['project_id', 'status', 'project_user_id', 'user_id'], 'integer'],
[['created_at', 'updated_at'], 'safe'],
[['title'], 'string', 'max' => 255],
[['description'], 'string', 'max' => 500],
[['project_id'], 'exist', 'skipOnError' => true, 'targetClass' => Project::className(), 'targetAttribute' => ['project_id' => 'id']],
[['project_user_id'], 'exist', 'skipOnError' => true, 'targetClass' => ProjectUser::className(), 'targetAttribute' => ['project_user_id' => 'id']],
[['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'id']],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'project_id' => 'Проект',
'title' => 'Название задачи',
'status' => 'Статус',
'created_at' => 'Дата создания',
'updated_at' => 'Дата обновления',
'project_user_id' => 'Создатель',
'user_id' => 'Наблюдатель',
'description' => 'Описание',
];
}
public function beforeDelete()
{
foreach ($this->taskUsers as $taskUser){
$taskUser->delete();
}
return parent::beforeDelete();
}
/**
* @return ActiveQuery
*/
public function getProject()
{
return $this->hasOne(Project::className(), ['id' => 'project_id']);
}
/**
* @return ActiveQuery
*/
public function getProjectUser()
{
return $this->hasOne(ProjectUser::className(), ['id' => 'project_user_id']);
}
/**
* @return ActiveQuery
*/
public function getUser()
{
return $this->hasOne(User::className(), ['id' => 'user_id']);
}
/**
* @return ActiveQuery
*/
public function getTaskUsers()
{
return $this->hasMany(TaskUser::className(), ['task_id' => 'id']);
}
public static function usersByTaskArr($task_id): array
{
return ArrayHelper::map(
self::find()->joinWith(['user', 'project'])->where(['project_id' => $task_id])->all(), 'id', 'user.username');
}
}

View File

@ -0,0 +1,69 @@
<?php
namespace common\models;
use Yii;
use yii\db\ActiveQuery;
/**
* This is the model class for table "task_user".
*
* @property int $id
* @property int $task_id
* @property int $project_user_id
*
* @property ProjectUser $projectUser
* @property Task $task
*/
class TaskUser extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'task_user';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['task_id', 'project_user_id'], 'integer'],
[['project_user_id'], 'exist', 'skipOnError' => true, 'targetClass' => ProjectUser::className(), 'targetAttribute' => ['project_user_id' => 'id']],
[['task_id'], 'exist', 'skipOnError' => true, 'targetClass' => Task::className(), 'targetAttribute' => ['task_id' => 'id']],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'task_id' => 'Задача',
'project_user_id' => 'Сотрудник',
];
}
/**
* @return ActiveQuery
*/
public function getProjectUser()
{
return $this->hasOne(ProjectUser::className(), ['id' => 'project_user_id']);
}
/**
* @return ActiveQuery
*/
public function getTask()
{
return $this->hasOne(Task::className(), ['id' => 'task_id']);
}
}

View File

@ -57,6 +57,17 @@ class User extends ActiveRecord implements IdentityInterface
];
}
public function beforeSave($insert)
{
if (parent::beforeSave($insert)) {
if ($this->isNewRecord) {
$this->auth_key = Yii::$app->security->generateRandomString();
}
return true;
}
return false;
}
/**
* {@inheritdoc}
*/
@ -205,20 +216,18 @@ class User extends ActiveRecord implements IdentityInterface
$this->password_reset_token = null;
}
public function beforeSave($insert)
{
if (parent::beforeSave($insert)) {
if ($this->isNewRecord) {
$this->auth_key = Yii::$app->security->generateRandomString();
}
return true;
}
return false;
}
public function getUserCard()
{
return $this->hasOne(UserCard::class, ['id_user' => 'id']);
}
public function getManager()
{
return $this->hasOne(Manager::class, ['user_id' => 'id']);
}
public function getManagerEmployee()
{
return $this->hasMany(ManagerEmployee::className(), ['employee_id' => 'id']);
}
}