Merge branch 'master' into update_user_answers
# Conflicts: # frontend-access.log # frontend-error.log
This commit is contained in:
@ -110,13 +110,4 @@ class Document extends \yii\db\ActiveRecord
|
||||
{
|
||||
return $this->hasMany(DocumentFieldValue::className(), ['document_id' => 'id']);
|
||||
}
|
||||
|
||||
public static function getDocument($document_id)
|
||||
{
|
||||
return self::find()
|
||||
->joinWith(['documentFieldValues.field'])
|
||||
->where(['document.id' => $document_id])
|
||||
->asArray()
|
||||
->all();
|
||||
}
|
||||
}
|
||||
|
@ -123,4 +123,10 @@ class Template extends \yii\db\ActiveRecord
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
public function getFields()
|
||||
{
|
||||
return $this->hasMany(DocumentField::className(), ['id' => 'field_id'])
|
||||
->via('templateDocumentFields');
|
||||
}
|
||||
}
|
||||
|
75
common/models/TestTask.php
Normal file
75
common/models/TestTask.php
Normal file
@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace common\models;
|
||||
|
||||
use Yii;
|
||||
|
||||
/**
|
||||
* This is the model class for table "test_task".
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $description
|
||||
* @property string $link
|
||||
* @property int $level
|
||||
* @property int $status
|
||||
*/
|
||||
class TestTask extends \yii\db\ActiveRecord
|
||||
{
|
||||
const LEVEL_JUNIOR = 1;
|
||||
const LEVEL_MIDDLE = 2;
|
||||
const LEVEL_MIDDLE_PLUS = 3;
|
||||
const LEVEL_SENIOR = 4;
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public static function getLevelList(): array
|
||||
{
|
||||
return [
|
||||
self::LEVEL_JUNIOR => 'Junior',
|
||||
self::LEVEL_MIDDLE => 'Middle',
|
||||
self::LEVEL_MIDDLE_PLUS => 'Middle+',
|
||||
self::LEVEL_SENIOR => 'Senior',
|
||||
];
|
||||
}
|
||||
|
||||
public static function getLevelLabel(int $level): string
|
||||
{
|
||||
return self::getLevelList()[$level];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return 'test_task';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['level', 'status', 'description', 'link'], 'required'],
|
||||
[['level', 'status'], 'integer'],
|
||||
[['description'], 'string', 'max' => 500],
|
||||
[['link'], 'string', 'max' => 255],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'id' => 'ID',
|
||||
'description' => 'Описание',
|
||||
'link' => 'Ссылка',
|
||||
'level' => 'Уровень',
|
||||
'status' => 'Статус',
|
||||
];
|
||||
}
|
||||
}
|
@ -63,7 +63,7 @@ class UserQuestionnaire extends ActiveRecord
|
||||
[['questionnaire_id', 'user_id', 'status'], 'required'],
|
||||
[['questionnaire_id', 'user_id', 'score', 'status'], 'integer'],
|
||||
[['percent_correct_answers'], 'number'],
|
||||
[['created_at', 'updated_at'], 'safe'],
|
||||
[['created_at', 'updated_at', 'testing_date'], 'safe'],
|
||||
[['uuid'], 'string', 'max' => 36],
|
||||
[['uuid'], 'unique'],
|
||||
[['questionnaire_id'], 'exist', 'skipOnError' => true, 'targetClass' => Questionnaire::className(), 'targetAttribute' => ['questionnaire_id' => 'id']],
|
||||
@ -74,8 +74,7 @@ class UserQuestionnaire extends ActiveRecord
|
||||
public function beforeSave($insert)
|
||||
{
|
||||
if (parent::beforeSave($insert)) {
|
||||
if (empty($this->uuid))
|
||||
{
|
||||
if (empty($this->uuid)) {
|
||||
$this->uuid = UUIDHelper::v4();
|
||||
}
|
||||
return true;
|
||||
@ -98,6 +97,7 @@ class UserQuestionnaire extends ActiveRecord
|
||||
'status' => 'Статус',
|
||||
'created_at' => 'Дата создания',
|
||||
'updated_at' => 'Дата обновления',
|
||||
'testing_date' => 'Дата тестирования',
|
||||
'percent_correct_answers' => 'Процент правильных ответов',
|
||||
];
|
||||
}
|
||||
@ -178,8 +178,18 @@ class UserQuestionnaire extends ActiveRecord
|
||||
|
||||
public static function findActiveUserQuestionnaires($user_id): array
|
||||
{
|
||||
return self::find()->where(['user_id' => $user_id])
|
||||
->andWhere(['status' => '1'])
|
||||
$models = self::find()
|
||||
->where(['user_id' => $user_id])
|
||||
->andWhere(['user_questionnaire.status' => '1'])
|
||||
->all();
|
||||
|
||||
$modelsArr = array();
|
||||
foreach ($models as $model) {
|
||||
$modelsArr[] = array_merge($model->toArray(), [
|
||||
'questionnaire_title' => $model->getQuestionnaireTitle()
|
||||
]);
|
||||
}
|
||||
|
||||
return $modelsArr;
|
||||
}
|
||||
}
|
||||
|
74
common/services/DocumentFileService.php
Normal file
74
common/services/DocumentFileService.php
Normal file
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace common\services;
|
||||
|
||||
|
||||
use common\models\Document;
|
||||
use PhpOffice\PhpWord\Exception\CopyFileException;
|
||||
use PhpOffice\PhpWord\Exception\CreateTemporaryFileException;
|
||||
use PhpOffice\PhpWord\TemplateProcessor;
|
||||
use Yii;
|
||||
|
||||
class DocumentFileService
|
||||
{
|
||||
private $model;
|
||||
private $document;
|
||||
private $file_title;
|
||||
private $documentFieldValuesArr;
|
||||
|
||||
/**
|
||||
* @throws CopyFileException
|
||||
* @throws CreateTemporaryFileException
|
||||
*/
|
||||
public function __construct($modelID)
|
||||
{
|
||||
$this->model = Document::findOne($modelID);
|
||||
|
||||
$this->initDocument();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws CopyFileException
|
||||
* @throws CreateTemporaryFileException
|
||||
*/
|
||||
private function initDocument()
|
||||
{
|
||||
$this->file_title = $this->model->title . '.docx';
|
||||
|
||||
$template_title = $this->model->template->template_file_name;
|
||||
$this->document = new TemplateProcessor(
|
||||
Yii::getAlias('@templates') . "/$template_title");
|
||||
|
||||
$this->documentFieldValuesArr = $this->model->documentFieldValues;
|
||||
}
|
||||
|
||||
public function setFields()
|
||||
{
|
||||
foreach ($this->documentFieldValuesArr as $docFieldValue) {
|
||||
$this->document->setValue(
|
||||
$docFieldValue->field->field_template,
|
||||
$docFieldValue->value
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function downloadDocument()
|
||||
{
|
||||
$this->document->saveAs($this->file_title);
|
||||
|
||||
// Имя скачиваемого файла
|
||||
$downloadFile = $this->file_title;
|
||||
// Контент-тип означающий скачивание
|
||||
header("Content-Type: application/octet-stream");
|
||||
// Размер в байтах
|
||||
header("Accept-Ranges: bytes");
|
||||
// Размер файла
|
||||
header("Content-Length: ".filesize($downloadFile));
|
||||
// Расположение скачиваемого файла
|
||||
header("Content-Disposition: attachment; filename=".$downloadFile);
|
||||
|
||||
// Прочитать файл
|
||||
readfile($downloadFile);
|
||||
unlink($this->file_title);
|
||||
}
|
||||
}
|
@ -2,73 +2,27 @@
|
||||
|
||||
namespace common\services;
|
||||
|
||||
|
||||
use common\models\Document;
|
||||
use PhpOffice\PhpWord\Exception\CopyFileException;
|
||||
use PhpOffice\PhpWord\Exception\CreateTemporaryFileException;
|
||||
use PhpOffice\PhpWord\TemplateProcessor;
|
||||
use Yii;
|
||||
|
||||
class DocumentService
|
||||
{
|
||||
private $model;
|
||||
private $document;
|
||||
private $file_title;
|
||||
private $documentFieldValuesArr;
|
||||
|
||||
/**
|
||||
* @throws CopyFileException
|
||||
* @throws CreateTemporaryFileException
|
||||
*/
|
||||
public function __construct($modelID)
|
||||
public static function getDocumentList($document_type): array
|
||||
{
|
||||
$this->model = Document::findOne($modelID);
|
||||
|
||||
$this->initDocument();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws CopyFileException
|
||||
* @throws CreateTemporaryFileException
|
||||
*/
|
||||
private function initDocument()
|
||||
{
|
||||
$this->file_title = $this->model->title . '.docx';
|
||||
|
||||
$template_title = $this->model->template->template_file_name;
|
||||
$this->document = new TemplateProcessor(
|
||||
Yii::getAlias('@templates') . "/$template_title");
|
||||
|
||||
$this->documentFieldValuesArr = $this->model->documentFieldValues;
|
||||
}
|
||||
|
||||
public function setFields()
|
||||
{
|
||||
foreach ($this->documentFieldValuesArr as $docFieldValue) {
|
||||
$this->document->setValue(
|
||||
$docFieldValue->field->field_template,
|
||||
$docFieldValue->value
|
||||
);
|
||||
if (!empty($document_type)) {
|
||||
return Document::find()->joinWith('template')
|
||||
->where(['document_type' => $document_type])->asArray()->all();
|
||||
}
|
||||
else {
|
||||
return Document::find()->asArray()->all();
|
||||
}
|
||||
}
|
||||
|
||||
public function downloadDocument()
|
||||
public static function getDocument($document_id)
|
||||
{
|
||||
$this->document->saveAs($this->file_title);
|
||||
return Document::find()
|
||||
->joinWith(['documentFieldValues.field'])
|
||||
->where(['document.id' => $document_id])
|
||||
->asArray()->all();
|
||||
|
||||
// Имя скачиваемого файла
|
||||
$downloadFile = $this->file_title;
|
||||
// Контент-тип означающий скачивание
|
||||
header("Content-Type: application/octet-stream");
|
||||
// Размер в байтах
|
||||
header("Accept-Ranges: bytes");
|
||||
// Размер файла
|
||||
header("Content-Length: ".filesize($downloadFile));
|
||||
// Расположение скачиваемого файла
|
||||
header("Content-Disposition: attachment; filename=".$downloadFile);
|
||||
|
||||
// Прочитать файл
|
||||
readfile($downloadFile);
|
||||
unlink($this->file_title);
|
||||
}
|
||||
}
|
35
common/services/ManagerService.php
Normal file
35
common/services/ManagerService.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace common\services;
|
||||
|
||||
use common\models\UserCard;
|
||||
|
||||
class ManagerService
|
||||
{
|
||||
public static function getManagerList()
|
||||
{
|
||||
return UserCard::find()->select(['fio','manager.id' , 'email'])
|
||||
->joinWith('manager')->where(['NOT',['manager.user_card_id' => null]])->all();
|
||||
}
|
||||
|
||||
public static function getManager($manager_id)
|
||||
{
|
||||
return UserCard::find()
|
||||
->select(['manager.id', 'fio', 'email', 'photo', 'gender'])
|
||||
->joinWith([
|
||||
'manager' => function ($query) { $query->select(['id']); }
|
||||
])
|
||||
->where(['manager.id' => $manager_id])
|
||||
->asArray()
|
||||
->one();
|
||||
}
|
||||
|
||||
public static function getManagerEmployeesList($manager_id)
|
||||
{
|
||||
return UserCard::find()
|
||||
->select(['user_card.id', 'user_card.fio', 'user_card.email'])
|
||||
->joinWith('managerEmployee')
|
||||
->where(['manager_employee.manager_id' => $manager_id])
|
||||
->all();
|
||||
}
|
||||
}
|
46
common/services/TaskService.php
Normal file
46
common/services/TaskService.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace common\services;
|
||||
|
||||
use common\models\Task;
|
||||
|
||||
class TaskService
|
||||
{
|
||||
public static function createTask($taskParams)
|
||||
{
|
||||
$task = new Task();
|
||||
$task->load($taskParams, '');
|
||||
$task->save();
|
||||
return $task;
|
||||
}
|
||||
|
||||
public static function getTask($task_id): ?Task
|
||||
{
|
||||
return Task::findOne($task_id);
|
||||
}
|
||||
|
||||
public static function getTaskList($task_id): array
|
||||
{
|
||||
return Task::find()->asArray()->all();
|
||||
}
|
||||
|
||||
public static function getTaskListByProject($project_id): array
|
||||
{
|
||||
return Task::find()->where(['project_id' => $project_id])->asArray()->all();
|
||||
}
|
||||
|
||||
public static function updateTask($task_params): ?Task
|
||||
{
|
||||
$modelTask = Task::findOne($task_params['task_id']);
|
||||
|
||||
$modelTask->load($task_params, '');
|
||||
$modelTask->save();
|
||||
|
||||
return $modelTask;
|
||||
}
|
||||
|
||||
public static function taskExists($task_id): bool
|
||||
{
|
||||
return Task::find()->where(['id' => $task_id])->exists();
|
||||
}
|
||||
}
|
38
common/services/TemplateService.php
Normal file
38
common/services/TemplateService.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace common\services;
|
||||
|
||||
use common\models\Template;
|
||||
|
||||
class TemplateService
|
||||
{
|
||||
public static function getTemplateList($document_type = null): array
|
||||
{
|
||||
if (!empty($document_type)) {
|
||||
return Template::find()->where(['document_type' => $document_type])->asArray()->all();
|
||||
}
|
||||
else {
|
||||
return Template::find()->asArray()->all();
|
||||
}
|
||||
}
|
||||
|
||||
public static function getTemplateWithFields($template_id): array
|
||||
{
|
||||
return Template::find()
|
||||
// ->select('title')
|
||||
->joinWith('templateDocumentFields.field')
|
||||
// ->with([
|
||||
// 'fields' => function ($query) { $query->select(['id', 'title', 'field_template']); }
|
||||
// ])
|
||||
->where(['template.id' => $template_id])
|
||||
->asArray()
|
||||
->one();
|
||||
}
|
||||
|
||||
public static function getTemplate($template_id): array
|
||||
{
|
||||
return Template::find()->where(['template.id' => $template_id])
|
||||
->asArray()
|
||||
->one();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user