reports fix

This commit is contained in:
Kavalar 2024-02-01 00:57:42 +03:00
parent 1279d5ac17
commit 1bcc7834c2
8 changed files with 355 additions and 233 deletions

View File

@ -14,6 +14,7 @@ use Yii;
* @property string $difficulties * @property string $difficulties
* @property string $tomorrow * @property string $tomorrow
* @property int $user_card_id * @property int $user_card_id
* @property int $user_id
* @property int $project_id * @property int $project_id
* @property int $company_id * @property int $company_id
* @property int $status * @property int $status
@ -38,11 +39,12 @@ class Reports extends \yii\db\ActiveRecord
public function rules() public function rules()
{ {
return [ return [
[['user_card_id', 'status', 'company_id', 'project_id'], 'integer'], [['user_card_id', 'user_id', 'status', 'company_id', 'project_id'], 'integer'],
[['_task'], 'checkIsArray'], [['_task'], 'checkIsArray'],
[['user_card_id', 'created_at'], 'required'], [['created_at'], 'required'],
[['today', 'difficulties', 'tomorrow', 'created_at'], 'string', 'max' => 255], [['today', 'difficulties', 'tomorrow', 'created_at'], 'string', 'max' => 255],
[['user_card_id'], 'exist', 'skipOnError' => true, 'targetClass' => UserCard::class, 'targetAttribute' => ['user_card_id' => 'id']], [['user_card_id'], 'exist', 'skipOnError' => true, 'targetClass' => UserCard::class, 'targetAttribute' => ['user_card_id' => 'id']],
[['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::class, 'targetAttribute' => ['user_id' => 'id']],
[['project_id'], 'exist', 'skipOnEmpty' => true, 'targetClass' => Project::class, 'targetAttribute' => ['project_id' => 'id']], [['project_id'], 'exist', 'skipOnEmpty' => true, 'targetClass' => Project::class, 'targetAttribute' => ['project_id' => 'id']],
[['company_id'], 'exist', 'skipOnEmpty' => true, 'targetClass' => Company::class, 'targetAttribute' => ['company_id' => 'id']], [['company_id'], 'exist', 'skipOnEmpty' => true, 'targetClass' => Company::class, 'targetAttribute' => ['company_id' => 'id']],
]; ];
@ -59,7 +61,8 @@ class Reports extends \yii\db\ActiveRecord
'today' => 'Что было сделано сегодня?', 'today' => 'Что было сделано сегодня?',
'difficulties' => 'Какие сложности возникли?', 'difficulties' => 'Какие сложности возникли?',
'tomorrow' => 'Что планируется сделать завтра?', 'tomorrow' => 'Что планируется сделать завтра?',
'user_card_id' => 'Пользователь', 'user_card_id' => 'Профиль пользователя',
'user_id' => 'Пользователь',
'status' => 'Статус', 'status' => 'Статус',
'project_id' => 'ID проекта', 'project_id' => 'ID проекта',
'company_id' => 'ID компании' 'company_id' => 'ID компании'
@ -95,6 +98,14 @@ class Reports extends \yii\db\ActiveRecord
return $this->hasOne(UserCard::className(), ['id' => 'user_card_id']); return $this->hasOne(UserCard::className(), ['id' => 'user_card_id']);
} }
/**
* @return \yii\db\ActiveQuery
*/
private function getUser(): \yii\db\ActiveQuery
{
return $this->hasOne(User::class, ['id' => 'user_id']);
}
public function getTask() public function getTask()
{ {
return $this->hasMany(ReportsTask::class, ['report_id' => 'id']); return $this->hasMany(ReportsTask::class, ['report_id' => 'id']);

View File

@ -19,14 +19,14 @@ use Yii;
*/ */
class ReportsTask extends \yii\db\ActiveRecord class ReportsTask extends \yii\db\ActiveRecord
{ {
const SCENARIO_WITHOUT_REPORT_ID = 'withoutReportID'; // const SCENARIO_WITHOUT_REPORT_ID = 'withoutReportID';
//
public function scenarios() // public function scenarios()
{ // {
$scenarios = parent::scenarios(); // $scenarios = parent::scenarios();
$scenarios[self::SCENARIO_WITHOUT_REPORT_ID] = self::attributes(); // $scenarios[self::SCENARIO_WITHOUT_REPORT_ID] = self::attributes();
return $scenarios; // return $scenarios;
} // }
/** /**
* {@inheritdoc} * {@inheritdoc}
@ -42,7 +42,7 @@ class ReportsTask extends \yii\db\ActiveRecord
public function rules() public function rules()
{ {
return [ return [
[['report_id'], 'required', 'on' => self::SCENARIO_DEFAULT], //[['report_id'], 'required', 'on' => self::SCENARIO_DEFAULT],
[['report_id', 'created_at', 'status', 'minutes_spent'], 'integer'], [['report_id', 'created_at', 'status', 'minutes_spent'], 'integer'],
[['hours_spent'], 'number'], [['hours_spent'], 'number'],
['minutes_spent', 'compare', 'compareValue' => 60, 'operator' => '<'], ['minutes_spent', 'compare', 'compareValue' => 60, 'operator' => '<'],

View File

@ -4,6 +4,7 @@
namespace console\controllers; namespace console\controllers;
use common\models\Reports;
use common\models\UserCard; use common\models\UserCard;
use Yii; use Yii;
use yii\console\Controller; use yii\console\Controller;
@ -24,8 +25,7 @@ class SqlController extends Controller
if (!$item->photo) { if (!$item->photo) {
if ($item->gender === 1) { if ($item->gender === 1) {
$item->photo = '/profileava/f' . random_int(1, 6) . '.png'; $item->photo = '/profileava/f' . random_int(1, 6) . '.png';
} } else {
else {
$item->photo = '/profileava/m' . random_int(1, 10) . '.png'; $item->photo = '/profileava/m' . random_int(1, 10) . '.png';
} }
$item->save(); $item->save();
@ -38,4 +38,16 @@ class SqlController extends Controller
{ {
echo UserCard::generateUserForUserCard() . "\n"; echo UserCard::generateUserForUserCard() . "\n";
} }
public function actionAddUserIdToReports()
{
$reports = Reports::find()->all();
foreach ($reports as $report) {
$report->user_id = $report->userCard->id_user;
$report->save();
echo "user $report->user_id changed\n";
}
echo "script completed successfully\n";
}
} }

View File

@ -0,0 +1,45 @@
<?php
use yii\db\Migration;
/**
* Class m240131_080048_add_user_id_column_at_reports_table
*/
class m240131_080048_add_user_id_column_at_reports_table extends Migration
{
private const TABLE_NAME = "reports";
private const COLUMN_NAME = "user_id";
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addColumn(self::TABLE_NAME, self::COLUMN_NAME, $this->integer(11)->after("status"));
$this->addForeignKey('fk_reports_user', self::TABLE_NAME, self::COLUMN_NAME, 'user', 'id');
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropForeignKey('fk_reports_user', self::TABLE_NAME);
$this->dropColumn(self::TABLE_NAME, self::COLUMN_NAME);
}
/*
// Use up()/down() to run migration code without a transaction.
public function up()
{
}
public function down()
{
echo "m240131_080048_add_user_id_column_at_reports_table cannot be reverted.\n";
return false;
}
*/
}

View File

@ -0,0 +1,28 @@
<?php
use yii\db\Migration;
/**
* Handles the dropping of table `{{%fk_reports_user_card_id_at_reports}}`.
*/
class m240131_132201_drop_fk_reports_user_card_id_at_reports_table extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->dropForeignKey("fk-reports-user_card_id", "reports");
$this->dropIndex("idx-reports-user_card_id", "reports");
$this->alterColumn("reports", "user_card_id", $this->integer(11));
$this->alterColumn("reports", "status", $this->integer(1)->defaultValue(1));
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
}
}

View File

@ -2,6 +2,7 @@
namespace frontend\modules\api\controllers; namespace frontend\modules\api\controllers;
use common\classes\Debug;
use common\models\Reports; use common\models\Reports;
use common\models\ReportsTask; use common\models\ReportsTask;
use common\models\UserCard; use common\models\UserCard;
@ -14,39 +15,48 @@ use yii\web\NotFoundHttpException;
class ReportsController extends ApiController class ReportsController extends ApiController
{ {
public function verbs(): array
{
return [
'index' => ['get'],
'attach' => ['post'],
'delete' => ['delete'],
'update' => ['put', 'patch'],
];
}
/** /**
* @OA\Get(path="/user-response/index", * @OA\Get(path="/reports/index",
* summary="Поиск отчётов по промежутку дат", * summary="Поиск отчётов по промежутку дат",
* description="Осуществляет поиск отчётов пользователя по промежутку дат", * description="Осуществляет поиск отчётов пользователя по промежутку дат",
* security={ * security={
* {"bearerAuth": {}} * {"bearerAuth": {}}
* }, * },
* tags={"Reports"}, * tags={"Reports"},
* @OA\RequestBody( * @OA\Parameter(
* @OA\MediaType( * name="user_id",
* mediaType="application/x-www-form-urlencoded", * description="Идентификатор пользователя",
* in="query",
* required=true,
* @OA\Schema( * @OA\Schema(
* required={"user_card_id"},
* @OA\Property(
* property="user_card_id",
* type="integer", * type="integer",
* description="Идентификатор карты(профиля) пользователя", * )
* nullable=false,
* ), * ),
* @OA\Property( * @OA\Parameter(
* property="fromDate", * name="fromDate",
* type="DateTime",
* description="Дата начала поиска", * description="Дата начала поиска",
* nullable=false, * in="query",
* ), * @OA\Schema(
* @OA\Property(
* property="toDate",
* type="DateTime", * type="DateTime",
* )
* ),
* @OA\Parameter(
* name="toDate",
* description="Дата конца периода поиска", * description="Дата конца периода поиска",
* nullable=false, * in="query",
* ), * @OA\Schema(
* ), * type="DateTime",
* ), * )
* ), * ),
* *
* @OA\Response( * @OA\Response(
@ -61,10 +71,9 @@ class ReportsController extends ApiController
* *
* ) * )
* *
* @param $user_card_id
* @return array * @return array
*/ */
public function actionIndex($user_card_id): array public function actionIndex(): array
{ {
$reportsModel = new ReportSearchForm(); $reportsModel = new ReportSearchForm();
@ -82,32 +91,30 @@ class ReportsController extends ApiController
} }
/** /**
* @OA\Get(path="/user-response/find-by-date", * @OA\Get(path="/reports/find-by-date",
* summary="Поиск отчётов по дате", * summary="Поиск отчётов по дате",
* description="Осуществляет поиск отчётов пользователя по дате", * description="Осуществляет поиск отчётов пользователя по дате",
* security={ * security={
* {"bearerAuth": {}} * {"bearerAuth": {}}
* }, * },
* tags={"Reports"}, * tags={"Reports"},
* @OA\RequestBody( * @OA\Parameter(
* @OA\MediaType( * name="user_id",
* mediaType="application/x-www-form-urlencoded", * description="Идентификатор пользователя",
* in="query",
* required=true,
* @OA\Schema( * @OA\Schema(
* required={"user_card_id"},
* @OA\Property(
* property="user_card_id",
* type="integer", * type="integer",
* description="Идентификатор карты(профиля) пользователя", * )
* nullable=false,
* ), * ),
* @OA\Property( * @OA\Parameter(
* property="date", * name="date",
* type="DateTime",
* description="Дата поиска", * description="Дата поиска",
* nullable=false, * in="query",
* ), * required=true,
* ), * @OA\Schema(
* ), * type="DateTime",
* )
* ), * ),
* *
* @OA\Response( * @OA\Response(
@ -131,7 +138,7 @@ class ReportsController extends ApiController
$reportsModel = new ReportSearchForm(); $reportsModel = new ReportSearchForm();
$params = Yii::$app->request->get(); $params = Yii::$app->request->get();
if(!isset($params['user_card_id']) or !isset($params['date'])){ if(!isset($params['user_id']) or !isset($params['date'])){
throw new NotFoundHttpException('Required parameter are missing!'); throw new NotFoundHttpException('Required parameter are missing!');
} }
@ -157,76 +164,51 @@ class ReportsController extends ApiController
* {"bearerAuth": {}} * {"bearerAuth": {}}
* }, * },
* tags={"Reports"}, * tags={"Reports"},
* @OA\Parameter( *
* name="difficulties", * @OA\RequestBody(
* in="query", * @OA\MediaType(
* required=false, * mediaType="multipart/form-data",
* @OA\Schema(
* required={"tasks"},
* @OA\Property(
* property="user_id",
* type="integer",
* description="Идентификатор пользователя",
* ),
* @OA\Property(
* property="created_at",
* type="Date",
* description="Идентификатор пользователя",
* ),
* @OA\Property(
* property="difficulties",
* type="string",
* description="Описание сложностей возникших при выполнении задач", * description="Описание сложностей возникших при выполнении задач",
* @OA\Schema(
* type="string",
* )
* ), * ),
* @OA\Parameter( * @OA\Property(
* name="tomorrow", * property="tomorrow",
* in="query", * type="string",
* required=false,
* description="Описание планов на завтра", * description="Описание планов на завтра",
* @OA\Schema(
* type="string",
* )
* ), * ),
* @OA\Parameter( * @OA\Property(
* name="created_at", * property="Статус",
* in="query", * type="integer",
* required=false,
* description="Дата создания",
* @OA\Schema(
* type="string",
* )
* ),
* @OA\Parameter(
* name="status",
* in="query",
* required=false,
* description="Статус", * description="Статус",
* @OA\Schema(
* type="integer",
* )
* ), * ),
* @OA\Parameter( * @OA\Property(
* name="user_card_id", * property="project_id",
* in="query",
* required=false,
* description="ID карты(профиля) пользователя",
* @OA\Schema(
* type="integer", * type="integer",
* ) * description="Идентификатор проекта",
* ), * ),
* @OA\Parameter( * @OA\Property(
* name="project_id", * property="company_id",
* in="query",
* required=false,
* description="ID проекта",
* @OA\Schema(
* type="integer", * type="integer",
* ) * description="Идентификатор компании",
* ), * ),
* @OA\Parameter( * @OA\Property(
* name="company_id", * property="tasks[]",
* in="query",
* required=false,
* description="ID компании",
* @OA\Schema(
* type="integer",
* )
* ),
* @OA\Parameter(
* name="tasks[]",
* in="query",
* required=false,
* description="Масив задач. ",
* @OA\Schema(
* type="array", * type="array",
* description="Массив выполненых задач",
* @OA\Items( * @OA\Items(
* type="object", * type="object",
* @OA\Property( * @OA\Property(
@ -245,8 +227,12 @@ class ReportsController extends ApiController
* type="string", * type="string",
* ) * )
* ) * )
* ) *
* ), * ),
* ),
* ),
* ),
*
* @OA\Response( * @OA\Response(
* response=200, * response=200,
* description="Возвращает объект Запроса", * description="Возвращает объект Запроса",
@ -267,11 +253,12 @@ class ReportsController extends ApiController
throw new BadRequestHttpException('Нет параметра tasks'); throw new BadRequestHttpException('Нет параметра tasks');
} }
if(!isset($params['user_card_id'])){ if(!isset($params['user_id'])){
$userCard = UserCard::find()->where(['id_user' => Yii::$app->user->id])->one(); $params['user_id'] = Yii::$app->user->id;
if($userCard){
$params['user_card_id'] = $userCard->id;
} }
if (!isset($params['created_at'])){
$params['created_at'] = date("Y-m-d");
} }
$reportsModel = new Reports(); $reportsModel = new Reports();
@ -283,7 +270,7 @@ class ReportsController extends ApiController
$tasks = $params['tasks']; $tasks = $params['tasks'];
foreach ($tasks as $task) { foreach ($tasks as $task) {
$reportsTask = new ReportsTask(); $reportsTask = new ReportsTask();
$reportsTask->attributes = $task; $reportsTask->load($task, '');
$reportsTask->report_id = $reportsModel->id; $reportsTask->report_id = $reportsModel->id;
$reportsTask->created_at = $reportsTask->created_at ?? strtotime($reportsModel->created_at); $reportsTask->created_at = $reportsTask->created_at ?? strtotime($reportsModel->created_at);
$reportsTask->status = $reportsTask->status ?? 1; $reportsTask->status = $reportsTask->status ?? 1;
@ -298,26 +285,21 @@ class ReportsController extends ApiController
/** /**
* @OA\Get(path="/user-response/delete", * @OA\Delete (path="/reports/delete",
* summary="Удаление отчёта", * summary="Удаление отчёта",
* description="Осуществляет удаление отчёта", * description="Осуществляет удаление отчёта",
* security={ * security={
* {"bearerAuth": {}} * {"bearerAuth": {}}
* }, * },
* tags={"Reports"}, * tags={"Reports"},
* @OA\RequestBody( * @OA\Parameter(
* @OA\MediaType( * name="id",
* mediaType="application/x-www-form-urlencoded", * description="Идентификатор отчета",
* in="query",
* required=true,
* @OA\Schema( * @OA\Schema(
* required={"id"},
* @OA\Property(
* property="id",
* type="integer", * type="integer",
* description="Идентификатор отчётая", * )
* nullable=false,
* ),
* ),
* ),
* ), * ),
* *
* @OA\Response( * @OA\Response(
@ -331,10 +313,8 @@ class ReportsController extends ApiController
* @throws \Throwable * @throws \Throwable
* @throws \yii\db\StaleObjectException * @throws \yii\db\StaleObjectException
*/ */
public function actionDelete() public function actionDelete($id): bool
{ {
$id = Yii::$app->request->get('id');
$report = Reports::findOne($id); $report = Reports::findOne($id);
if(null === $report) { if(null === $report) {
@ -349,7 +329,7 @@ class ReportsController extends ApiController
} }
/** /**
* @OA\Get(path="/reports/update", * @OA\Put (path="/reports/update",
* summary="Обновление отчёта", * summary="Обновление отчёта",
* description="Метод для Обновления отчёта", * description="Метод для Обновления отчёта",
* security={ * security={
@ -365,50 +345,61 @@ class ReportsController extends ApiController
* type="integer", * type="integer",
* ) * )
* ), * ),
* @OA\Parameter( * @OA\RequestBody(
* name="created_at", * @OA\MediaType(
* in="query", * mediaType="application/x-www-form-urlencoded",
* required=false,
* description="Дата создания (yyyy-mm-dd)",
* @OA\Schema( * @OA\Schema(
* required={},
* @OA\Property(
* property="created_at",
* type="DateTime", * type="DateTime",
* ) * description="Дата создания (yyyy-mm-dd)",
* ), * ),
* @OA\Parameter( * @OA\Property(
* name="today", * property="today",
* in="query", * type="string",
* required=false,
* description="Сделанное сегодня", * description="Сделанное сегодня",
* @OA\Schema(
* type="string",
* )
* ), * ),
* @OA\Parameter( * @OA\Property(
* name="difficulties", * property="difficulties",
* in="query", * type="string",
* required=false,
* description="Описание сложностей возникших при выполнении задач", * description="Описание сложностей возникших при выполнении задач",
* @OA\Schema(
* type="string",
* )
* ), * ),
* @OA\Parameter( * @OA\Property(
* name="tomorrow", * property="tomorrow",
* in="query", * type="string",
* required=false,
* description="Описание планов на завтра", * description="Описание планов на завтра",
* @OA\Schema(
* type="string",
* )
* ), * ),
* @OA\Parameter( * @OA\Property(
* name="status", * property="status",
* in="query",
* required=false,
* description="Статус",
* @OA\Schema(
* type="integer", * type="integer",
* ) * description="Статус",
* ),
* @OA\Property(
* property="tasks[]",
* type="array",
* description="Массив выполненых задач",
* @OA\Items(
* type="object",
* @OA\Property(
* property="task",
* description="Название задачи",
* type="string",
* ),
* @OA\Property(
* property="hours_spent",
* description="Затраченное количество часов",
* type="string",
* ),
* @OA\Property(
* property="minutes_spent",
* description="Затраченное количество минут",
* type="string",
* ),
* ),
* ),
* ),
* ),
* ), * ),
* @OA\Response( * @OA\Response(
* response=200, * response=200,
@ -418,26 +409,30 @@ class ReportsController extends ApiController
* @OA\Schema(ref="#/components/schemas/ReportsResponseCreateExample"), * @OA\Schema(ref="#/components/schemas/ReportsResponseCreateExample"),
* ), * ),
* ), * ),
* ) * ),
* *
* @return array * @return array
* @throws BadRequestHttpException * @throws BadRequestHttpException
* @throws NotFoundHttpException * @throws NotFoundHttpException
*/ */
public function actionUpdate(): array public function actionUpdate($id): array
{ {
$params = Yii::$app->request->get(); $params = Yii::$app->getRequest()->getBodyParams();
$reportsModel = Reports::findone($id);
$reportsModel = Reports::findone($params['id']);
if(!isset($reportsModel)) { if(!isset($reportsModel)) {
throw new NotFoundHttpException('report not found'); throw new NotFoundHttpException('report not found');
} }
if(isset($params['user_card_id'])) { if (!isset($params['tasks'])){
throw new BadRequestHttpException('Нет параметра tasks');
}
if(isset($params['user_id'])) {
throw new \RuntimeException('constraint by user_card_id'); throw new \RuntimeException('constraint by user_card_id');
} }
$reportsModel->attributes = $params; $reportsModel->load($params, '');
if(!$reportsModel->validate()){ if(!$reportsModel->validate()){
throw new BadRequestHttpException(json_encode($reportsModel->errors)); throw new BadRequestHttpException(json_encode($reportsModel->errors));
@ -445,6 +440,20 @@ class ReportsController extends ApiController
$reportsModel->save(); $reportsModel->save();
ReportsTask::deleteAll(['report_id' => $reportsModel->id]);
foreach ($params['tasks'] as $task) {
$reportsTask = new ReportsTask();
$reportsTask->load($task, '');
$reportsTask->report_id = $reportsModel->id;
$reportsTask->created_at = $reportsTask->created_at ?? strtotime($reportsModel->created_at);
$reportsTask->status = $reportsTask->status ?? 1;
if(!$reportsTask->validate() ){
throw new BadRequestHttpException(json_encode($reportsTask->errors));
}
$reportsTask->save();
}
return $reportsModel->toArray(); return $reportsModel->toArray();
} }

View File

@ -3,6 +3,7 @@
namespace frontend\modules\api\models; namespace frontend\modules\api\models;
use common\classes\Debug;
use common\models\Reports; use common\models\Reports;
use yii\base\Model; use yii\base\Model;
@ -10,6 +11,7 @@ use yii\base\Model;
class ReportSearchForm extends Model class ReportSearchForm extends Model
{ {
public $user_card_id; public $user_card_id;
public $user_id;
public $limit; public $limit;
public $offset; public $offset;
/** @var string */ /** @var string */
@ -22,6 +24,7 @@ class ReportSearchForm extends Model
$this->limit = 10; $this->limit = 10;
$this->offset = 0; $this->offset = 0;
$this->user_card_id = null; $this->user_card_id = null;
$this->user_id = null;
$this->toDate = date('Y-m-d'); $this->toDate = date('Y-m-d');
$this->fromDate = date('Y-m-d'); $this->fromDate = date('Y-m-d');
@ -36,7 +39,7 @@ class ReportSearchForm extends Model
[['byDate'], 'safe'], [['byDate'], 'safe'],
[['fromDate', 'toDate', 'date'], 'string'], [['fromDate', 'toDate', 'date'], 'string'],
// [['fromDate', 'toDate', 'date'], 'date', 'format' => 'php:Y-m-d'], // [['fromDate', 'toDate', 'date'], 'date', 'format' => 'php:Y-m-d'],
[[ 'user_card_id'], 'integer', 'min' => 0], [[ 'user_card_id', 'user_id'], 'integer', 'min' => 0],
]; ];
} }
@ -48,8 +51,8 @@ class ReportSearchForm extends Model
$queryBuilder->andWhere(['between', 'reports.created_at', $this->fromDate, $this->toDate]); $queryBuilder->andWhere(['between', 'reports.created_at', $this->fromDate, $this->toDate]);
} }
if (isset($this->user_card_id)) { if (isset($this->user_id)) {
$queryBuilder->andWhere(['reports.user_card_id' => $this->user_card_id]); $queryBuilder->andWhere(['reports.user_id' => $this->user_id]);
} }
$queryBuilder->limit($this->limit) $queryBuilder->limit($this->limit)
@ -61,7 +64,7 @@ class ReportSearchForm extends Model
public function findByDate() public function findByDate()
{ {
return Reports::find()->with('task') return Reports::find()->with('task')
->where(['reports.user_card_id' => $this->user_card_id]) ->where(['reports.user_id' => $this->user_id])
->andWhere(['reports.created_at' => $this->date]) ->andWhere(['reports.created_at' => $this->date])
->asArray()->all(); ->asArray()->all();
} }
@ -69,7 +72,7 @@ class ReportSearchForm extends Model
public function reportsByDate() public function reportsByDate()
{ {
return Reports::find()->with('task') return Reports::find()->with('task')
->where(['reports.user_card_id' => $this->user_card_id]) ->where(['reports.user_id' => $this->user_id])
->andWhere(['between', 'reports.created_at', $this->fromDate, $this->toDate]) ->andWhere(['between', 'reports.created_at', $this->fromDate, $this->toDate])
->asArray()->all(); ->asArray()->all();
} }

View File

@ -35,6 +35,12 @@ namespace frontend\modules\api\models;
* description="ID карты(профиля) пользователя" * description="ID карты(профиля) пользователя"
* ), * ),
* @OA\Property( * @OA\Property(
* property="user_id",
* type="integer",
* example=23,
* description="ID пользователя"
* ),
* @OA\Property(
* property="project_id", * property="project_id",
* type="integer", * type="integer",
* example=1, * example=1,
@ -75,6 +81,10 @@ namespace frontend\modules\api\models;
* type="integer", * type="integer",
* ), * ),
* @OA\Property( * @OA\Property(
* property="user_id",
* type="integer",
* ),
* @OA\Property(
* property="project_id", * property="project_id",
* type="integer", * type="integer",
* ), * ),
@ -111,6 +121,10 @@ namespace frontend\modules\api\models;
* type="integer", * type="integer",
* ), * ),
* @OA\Property( * @OA\Property(
* property="user_id",
* type="integer",
* ),
* @OA\Property(
* property="project_id", * property="project_id",
* type="integer", * type="integer",
* ), * ),