Initial import
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace app\models;
|
||||
|
||||
use app\services\Formatter;
|
||||
|
||||
/**
|
||||
* Class Articles
|
||||
* @package app\models
|
||||
* @property $id
|
||||
* @property $key
|
||||
* @property $art_table
|
||||
* @property News $news;
|
||||
* @property Events $events;
|
||||
* @property Campaigns $campaigns;
|
||||
* @property $title
|
||||
* @property $title_en
|
||||
* @property $is_active
|
||||
* @property $publish_date
|
||||
* @property \app\models\parsed\ArticleParsedInterface $article
|
||||
* @property $label
|
||||
* @property $partner_id
|
||||
* @property $partner_page_selected
|
||||
*/
|
||||
class Articles extends _Base
|
||||
{
|
||||
public function getNews()
|
||||
{
|
||||
return $this->hasOne(News::class, ['article_key' => 'key']);
|
||||
}
|
||||
|
||||
public function getEvents()
|
||||
{
|
||||
return $this->hasOne(Events::class, ['article_key' => 'key']);
|
||||
}
|
||||
|
||||
public function getCampaigns()
|
||||
{
|
||||
return $this->hasOne(Campaigns::class, ['article_key' => 'key']);
|
||||
}
|
||||
|
||||
public function getArticle() {
|
||||
switch ($this->art_table) {
|
||||
case 'news':
|
||||
return $this->news;
|
||||
case 'events':
|
||||
return $this->events;
|
||||
case 'campaigns':
|
||||
return $this->campaigns;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function getLabel() {
|
||||
switch ($this->art_table) {
|
||||
case 'news':
|
||||
return Ts::get(12);
|
||||
case 'events':
|
||||
return Ts::get(13);
|
||||
case 'campaigns':
|
||||
return Ts::get(14);
|
||||
}
|
||||
}
|
||||
|
||||
public static function getArticleBySlug($slug) {
|
||||
$slugArr = explode('-', $slug);
|
||||
if(!empty($slugArr[0])) {
|
||||
$id = Formatter::decodeId($slugArr[0]);
|
||||
$article = Articles::findOne($id);
|
||||
if($article) return $article;
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function getSingleArticleLabel() {
|
||||
switch ($this->art_table) {
|
||||
case 'news':
|
||||
return Ts::get(185);
|
||||
case 'events':
|
||||
return Ts::get(186);
|
||||
case 'campaigns':
|
||||
return Ts::get(187);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user