1 | <?php |
||
27 | class Post extends \yii\db\ActiveRecord |
||
28 | { |
||
29 | const STATUS_INACTIVE = 0; |
||
30 | const STATUS_ACTIVE = 1; |
||
31 | |||
32 | /** |
||
33 | * @inheritdoc |
||
34 | */ |
||
35 | 1 | public static function tableName() |
|
39 | |||
40 | /** |
||
41 | * @inheritdoc |
||
42 | */ |
||
43 | 1 | public function rules() |
|
44 | { |
||
45 | return [ |
||
46 | 1 | [['title', 'content', 'active'], 'required'], |
|
47 | 1 | [['content'], 'string'], |
|
48 | 1 | [['active', 'visits', 'created_at', 'updated_at', 'category_id'], 'integer'], |
|
49 | 1 | [['title', 'image', 'source', 'categories'], 'string', 'max' => 255], |
|
50 | 1 | ['tagValues', 'safe'], |
|
51 | 1 | ]; |
|
52 | } |
||
53 | |||
54 | /** |
||
55 | * @inheritdoc |
||
56 | */ |
||
57 | public function attributeLabels() |
||
58 | { |
||
59 | return [ |
||
60 | 'id' => Module::t('cms', 'ID'), |
||
61 | 'title' => Module::t('cms', 'Title'), |
||
62 | 'image' => Module::t('cms', 'Image'), |
||
63 | 'content' => Module::t('cms', 'Content'), |
||
64 | 'active' => Module::t('cms', 'Active'), |
||
65 | 'source' => Module::t('cms', 'Source'), |
||
66 | 'visits' => Module::t('cms', 'Visits'), |
||
67 | 'category_id' => Module::t('cms', 'Category Id'), |
||
68 | 'categories' => Module::t('cms', 'Categories'), |
||
69 | 'created_at' => Module::t('cms', 'Created At'), |
||
70 | 'updated_at' => Module::t('cms', 'Updated At'), |
||
71 | 'tagValues' => '标签', |
||
72 | ]; |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * @inheritdoc |
||
77 | */ |
||
78 | 1 | public function behaviors() |
|
79 | { |
||
80 | return [ |
||
81 | 'timestamp' => [ |
||
82 | 1 | 'class' => TimestampBehavior::className(), |
|
|
|||
83 | 1 | ], |
|
84 | 'fileBehavior' => [ |
||
85 | 1 | 'class' => \nemmo\attachments\behaviors\FileBehavior::className() |
|
86 | 1 | ], |
|
87 | 'taggable' => [ |
||
88 | 1 | 'class' => TaggableBehavior::className(), |
|
89 | // 'tagValuesAsArray' => false, |
||
90 | // 'tagRelation' => 'tags', |
||
91 | // 'tagValueAttribute' => 'name', |
||
92 | // 'tagFrequencyAttribute' => 'frequency', |
||
93 | 1 | ], |
|
94 | 1 | ]; |
|
95 | } |
||
96 | |||
97 | /** |
||
98 | * @return array |
||
99 | */ |
||
100 | public static function getStatusList() |
||
101 | { |
||
102 | return [ |
||
103 | self::STATUS_INACTIVE => Module::t('cms', 'InActive'), |
||
104 | self::STATUS_ACTIVE => Module::t('cms', 'Active'), |
||
105 | ]; |
||
106 | } |
||
107 | |||
108 | public function getTags() |
||
113 | |||
114 | 1 | public function transactions() |
|
115 | { |
||
116 | return [ |
||
117 | 1 | self::SCENARIO_DEFAULT => self::OP_ALL, |
|
118 | 1 | ]; |
|
119 | } |
||
120 | |||
121 | public static function find() |
||
125 | |||
126 | /** |
||
127 | * @return PostCategory |
||
128 | */ |
||
129 | public function getCategory() |
||
135 | |||
136 | /** |
||
137 | * @return array |
||
138 | */ |
||
139 | public function getCategories() |
||
140 | { |
||
141 | $ids = explode(',', $this->categories); |
||
142 | $res = []; |
||
143 | foreach ($ids as $id) { |
||
144 | $res[] = PostCategory::findOne($id); |
||
145 | } |
||
146 | return $res; |
||
147 | } |
||
148 | |||
149 | public function getCategoriesName() |
||
150 | { |
||
151 | $categories = $this->getCategories(); |
||
152 | $labels = []; |
||
153 | foreach ($categories as $category) { |
||
154 | $labels[] = $category->name; |
||
155 | } |
||
156 | return implode(',', $labels); |
||
157 | } |
||
158 | |||
159 | public function getUrl() |
||
163 | |||
164 | 1 | public function beforeSave($insert) |
|
169 | |||
170 | public function afterFind() |
||
175 | } |
||
176 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.