tmp commit

This commit is contained in:
iIronside 2023-01-19 14:50:55 +03:00
parent 097ecfe087
commit b5a9d4be40
2 changed files with 85 additions and 0 deletions

View File

@ -69,6 +69,8 @@ class ReportSearchForm extends Model
public function findByDate(): array public function findByDate(): array
{ {
return Reports::find() return Reports::find()
// ->joinWith('task')
->with('task')
->where(['user_card_id' => $this->user_card_id]) ->where(['user_card_id' => $this->user_card_id])
->andWhere(['created_at' => $this->date]) ->andWhere(['created_at' => $this->date])
->all(); ->all();

View File

@ -0,0 +1,83 @@
<?php
namespace frontend\modules\api\models;
use yii\db\ActiveQuery;
use yii\helpers\Url;
use yii\web\Linkable;
class News extends \common\models\Reports implements Linkable
{
public function fields()
{
return [
'id',
'created_at',
'today',
'difficulties',
'tomorrow',
'status',
'user_card_id'
];
}
public function extraFields()
{
return [
'tags',
'comments',
'comments_count' => 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']);
}
}