Initial import
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\models;
|
||||
|
||||
/**
|
||||
* Class Positions
|
||||
* @package app\models
|
||||
* @property $id
|
||||
* @property $group_name
|
||||
* @property $class_name
|
||||
* @property $group_id
|
||||
* @property $position_article_key
|
||||
* @property $event_id
|
||||
* @property $campaign_id
|
||||
* @property Positions[] $positions
|
||||
* @property int $positionsCount
|
||||
* @property News $news;
|
||||
* @property Events $event
|
||||
* @property Campaigns $campaign
|
||||
* @property string $article
|
||||
* @property Articles $articleModel
|
||||
* @property int $order_index
|
||||
*/
|
||||
class Positions extends _Base
|
||||
{
|
||||
public static function getArticleTypeIds()
|
||||
{
|
||||
return ['news_id', 'event_id', 'campaign_id'];
|
||||
}
|
||||
|
||||
public function getPositions()
|
||||
{
|
||||
return $this->hasMany(Positions::class, ['group_id' => 'id'])->orderBy(['order_index' => SORT_ASC])->all();
|
||||
}
|
||||
|
||||
public function getPositionsCount()
|
||||
{
|
||||
return $this->hasMany(Positions::class, ['group_id' => 'id'])->count();
|
||||
}
|
||||
|
||||
public function getArticleModel()
|
||||
{
|
||||
return $this->hasOne(Articles::class, ['key' => 'position_article_key']);
|
||||
}
|
||||
|
||||
public function getArticle()
|
||||
{
|
||||
if ($this->position_article_key) {
|
||||
$articleModel = $this->articleModel;
|
||||
$table = explode('_', $this->position_article_key);
|
||||
|
||||
switch ($table[0]) {
|
||||
case 'news':
|
||||
$src = $articleModel->news->getSrcOfSingleImage('title_news_image', 'thumb');
|
||||
return $this->articleTableRowPreview(
|
||||
'Новина: (№ ' . $articleModel->news->id . ')',
|
||||
$articleModel->news->title,
|
||||
$src
|
||||
);
|
||||
case 'events':
|
||||
$src = $articleModel->events->getSrcOfSingleImage('title_event_image', 'thumb');
|
||||
return $this->articleTableRowPreview(
|
||||
'Събитие: (№ ' . $articleModel->events->id . ')',
|
||||
$articleModel->events->title,
|
||||
$src
|
||||
);
|
||||
case 'campaigns':
|
||||
$src = $articleModel->campaigns->getSrcOfSingleImage('title_campaigns_image', 'thumb');
|
||||
return $this->articleTableRowPreview(
|
||||
'Кампания: (№ ' . $articleModel->campaigns->id . ')',
|
||||
$articleModel->campaigns->title,
|
||||
$src
|
||||
);
|
||||
}
|
||||
}
|
||||
return '<span style="color: var(--base-background)">Няма закачен материал</span>';
|
||||
}
|
||||
|
||||
private function articleTableRowPreview($type, $title, $src_img)
|
||||
{
|
||||
$html = '<div class="flex">';
|
||||
if ($src_img) {
|
||||
$html .= '<img src="' . $src_img . '" style="height: 50px; display:block">';
|
||||
}
|
||||
$html .= '<div style="margin-left: 5px">';
|
||||
$html .= '<div style="font-weight: bold; color: var(--base-background-dark)">' . $type . '</div>';
|
||||
$html .= '<div>' . $title . '</div>';
|
||||
$html .= '</div>';
|
||||
$html .= '</div>';
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function getNextOrderIndex()
|
||||
{
|
||||
$size = sizeof($this->positions);
|
||||
$last = $this->positions[$size - 1];
|
||||
return $last->order_index + 1;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user