-
Notifications
You must be signed in to change notification settings - Fork 0
/
ArticleCategory.php
85 lines (76 loc) · 2.21 KB
/
ArticleCategory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
namespace common\models;
use himiklab\sitemap\behaviors\SitemapBehavior;
use Yii;
use yii\helpers\Url;
/**
* @inheritdoc
*
* @property Article[] $articles
* @property ArticleCategoryTranslation[] $translations
*/
class ArticleCategory extends \common\models\base\ArticleCategory implements \common\components\model\Translateable
{
use \backend\components\TranslateableTrait;
/**
* @return array
*/
public static function getTranslationAttributes()
{
return [
'label',
];
}
/**
* @inheritdoc
*/
public function behaviors()
{
return \yii\helpers\ArrayHelper::merge(parent::behaviors(), [
'translateable' => [
'class' => \creocoder\translateable\TranslateableBehavior::className(),
'translationAttributes' => static::getTranslationAttributes(),
],
'sitemap' => [
'class' => SitemapBehavior::className(),
'scope' => function ($model) {
/** @var \yii\db\ActiveQuery $model */
$model->andWhere(['published' => 1]);
},
'dataClosure' => function ($model) {
/** @var self $model */
return [
'loc' => Url::to($model->getIndexUrl(), true),
'lastmod' => time(),
'changefreq' => SitemapBehavior::CHANGEFREQ_WEEKLY,
'priority' => 0.8
];
}
],
]);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getArticles()
{
return $this->hasMany(Article::className(), ['category_id' => 'id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getTranslations()
{
return $this->hasMany(ArticleCategoryTranslation::className(), ['model_id' => 'id']);
}
/** @return string */
public static function getIndexRoute()
{
return '/article/default/category';
}
/** @return string */
public function getIndexUrl()
{
return $this->createUrl(static::getIndexRoute(), ['alias' => $this->alias]);
}
}