1 | <?php |
||
22 | class News extends \yii\db\ActiveRecord |
||
23 | { |
||
24 | const STATUS_BLOCKED = 0; |
||
25 | const STATUS_ACTIVE = 1; |
||
26 | |||
27 | /** |
||
28 | * @var array |
||
29 | */ |
||
30 | public $gallery; |
||
31 | /** |
||
32 | * @var array |
||
33 | */ |
||
34 | public $galleryTitles; |
||
35 | |||
36 | 4 | public function __construct($config = []) |
|
41 | |||
42 | /** |
||
43 | * @inheritdoc |
||
44 | */ |
||
45 | 4 | public static function tableName() |
|
49 | |||
50 | /** |
||
51 | * @inheritdoc |
||
52 | */ |
||
53 | 2 | public function rules() |
|
54 | { |
||
55 | return [ |
||
56 | [ |
||
57 | 2 | ['title', 'text', 'date_pub'], 'required' |
|
58 | ], |
||
59 | [ |
||
60 | [ |
||
61 | 'title', 'text', 'date_pub', 'preview', |
||
62 | 'gallery', 'galleryTitles', 'status' |
||
63 | ], 'safe' |
||
64 | ], |
||
65 | |||
66 | ['title', 'string', 'max' => 255], |
||
67 | ['text', 'string'], |
||
68 | |||
69 | ['date_pub', 'date', 'format' => 'php:Y-m-d H:i:s', |
||
70 | 'timestampAttribute' => 'date_pub', |
||
71 | 'timestampAttributeFormat' => 'php:Y-m-d H:i:s' |
||
72 | ], |
||
73 | |||
74 | ['status', 'integer'], |
||
75 | 2 | ['status', 'in', 'range' => array_keys(News::getStatuses())], |
|
76 | ]; |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * @inheritdoc |
||
81 | */ |
||
82 | 4 | public function attributeLabels() |
|
96 | |||
97 | /** |
||
98 | * @inheritdoc |
||
99 | */ |
||
100 | 2 | public function attributeHints() |
|
101 | { |
||
102 | return [ |
||
103 | |||
104 | 2 | ]; |
|
105 | } |
||
106 | |||
107 | /** |
||
108 | * @inheritdoc |
||
109 | */ |
||
110 | 4 | public function behaviors() |
|
121 | |||
122 | public function transactions() |
||
130 | |||
131 | /** |
||
132 | * @inheritdoc |
||
133 | * @return NewsQuery |
||
134 | */ |
||
135 | 4 | public static function find() |
|
139 | |||
140 | /** |
||
141 | * Get all statuses |
||
142 | * |
||
143 | * @return string[] |
||
144 | */ |
||
145 | 4 | public static function getStatuses(): array |
|
152 | |||
153 | /** |
||
154 | * Get statuse name |
||
155 | * |
||
156 | * @return string |
||
157 | */ |
||
158 | 4 | public function getStatusName(): string |
|
163 | |||
164 | /** |
||
165 | * Is it blocked? |
||
166 | * |
||
167 | * @param bool |
||
168 | */ |
||
169 | public function isBlocked(): bool |
||
173 | |||
174 | /** |
||
175 | * Is it active? |
||
176 | * |
||
177 | * @param bool |
||
178 | */ |
||
179 | public function isActive(): bool |
||
183 | |||
184 | 2 | public function getFiles($callable = null) |
|
185 | { |
||
190 | } |
||
191 |