* @copyright (c), Thread */ class Article extends ActiveRecord { public static $commonQuery = query\ActiveQuery::class; /** * @return null|object|string */ public static function getDb() { return ParentModule::getDb(); } /** * @return string */ public static function tableName() { return '{{%calendar_article}}'; } /** * @return array */ public function rules() { $getFormatDate = Yii::$app->getModule('news')->getFormatDate(); return [ [['alias', 'published_time'], 'required'], [['create_time', 'update_time'], 'integer'], [ ['published_time'], 'date', 'format' => 'php:' . $getFormatDate, 'timestampAttribute' => 'published_time' ], [['published', 'deleted'], 'in', 'range' => array_keys(static::statusKeyRange())], [['alias', 'image_link', 'default_title'], 'string', 'max' => 255], [['alias'], 'unique'] ]; } /** * @return array */ public function scenarios() { return [ 'published' => ['published'], 'deleted' => ['deleted'], 'backend' => ['alias', 'image_link', 'published', 'deleted', 'published_time', 'default_title'], ]; } /** * @return array */ public function attributeLabels() { return [ 'id' => Yii::t('app', 'ID'), 'alias' => Yii::t('app', 'Alias'), 'image_link' => Yii::t('app', 'Image link'), 'published_time' => Yii::t('app', 'Published time'), 'created_at' => Yii::t('app', 'Create time'), 'updated_at' => Yii::t('app', 'Update time'), 'published' => Yii::t('app', 'Published'), 'deleted' => Yii::t('app', 'Deleted'), 'date_from' => Yii::t('news', 'Date from'), 'date_to' => Yii::t('news', 'Date to'), 'title' => Yii::t('app', 'Title'), 'default_title' => Yii::t('app', 'Default Title'), ]; } /** * @return \yii\db\ActiveQuery */ public function getLang() { return $this->hasOne(ArticleLang::class, ['rid' => 'id']); } /** * @return string */ public function getTitle() { return (isset($this->lang->title)) ? $this->lang->title : "{{$this->default_title}}"; } /** * @return string */ public function getPublishedTime() { $getFormatDate = Yii::$app->getModule('news')->getFormatDate(); return $this->published_time == 0 ? date($getFormatDate) : date($getFormatDate, $this->published_time); } /** * ISO8601 = "Y-m-d\TH:i:sO" * @return string */ public function getPublishedTimeISO() { return date('Y-m-d\TH:i:sO', $this->published_time); } /** * ISO8601 = "Y-m-d\TH:i:sO" * @return string */ public function getModifiedTimeISO() { return date('Y-m-d\TH:i:sO', $this->updated_at); } /** * @return mixed */ public function getBaseUploadPath() { return Yii::$app->getModule('news')->getBaseUploadPath('article', $this); } /** * @return mixed */ public function getBaseUploadUrl() { return Yii::$app->getModule('news')->getBaseUploadUrl('article', $this); } /** * @return null|string */ public function getImageLink() { $image = null; if (!empty($this->image_link) && is_file($this->getBaseUploadPath() . '/' . $this->image_link)) { $image = $this->getBaseUploadUrl() . '/' . $this->image_link; } return $image; } /** * @return null|string */ public function getImagePath() { $image = null; if (!empty($this->image_link) && is_file($this->getBaseUploadPath() . '/' . $this->image_link)) { $image = $this->getBaseUploadPath() . '/' . $this->image_link; } return $image; } /** * @param $id */ public static function getById($id) { return self::find()->byID($id)->one(); } }