diff --git a/frontend/modules/api/models/ReportSearchForm.php b/frontend/modules/api/models/ReportSearchForm.php index cb83a4a..60e1832 100755 --- a/frontend/modules/api/models/ReportSearchForm.php +++ b/frontend/modules/api/models/ReportSearchForm.php @@ -69,6 +69,8 @@ class ReportSearchForm extends Model public function findByDate(): array { return Reports::find() +// ->joinWith('task') + ->with('task') ->where(['user_card_id' => $this->user_card_id]) ->andWhere(['created_at' => $this->date]) ->all(); diff --git a/frontend/modules/api/models/Reports.php b/frontend/modules/api/models/Reports.php new file mode 100644 index 0000000..f289fac --- /dev/null +++ b/frontend/modules/api/models/Reports.php @@ -0,0 +1,83 @@ + function () { + return (int)$this->getCommentsCount(); + }, + 'photo' => function () { + return $this->getPhotoLink(); + }, + 'news_body', + 'like' => function () { + return (int)$this->getLikesCount(); + }, + 'category' => function () { + return $this->category; + }, + ]; + } + + public function getPhotoLink() + { + if (empty($this->photo)) { + return 'N/A'; + } + return '/uploads/news-image/' . $this->photo; + } + + public function getTags(): ActiveQuery + { + return $this->hasMany(Tag::className(), ['id' => 'tag_id']) + ->via('newsTags'); + } + + public function getCategory() + { + return $this->hasMany(Category::className(), ['id' => 'category_id']) + ->via('categoryNews'); + } + + public function getComments(): ActiveQuery + { + return $this->hasMany(Comment::className(), ['news_id' => 'id']); + } + + public function getLinks(): array + { + $string = str_replace('+', ',', Url::to(['news/news', 'expand' => 'tags comments photo news_body like', 'news_id' => $this->id], true)); + + return [ + 'self' => $string, + ]; + } + + public function getEvent() + { + return $this->hasOne(EventType::class, ['id' => 'event_type_id']); + } +}