addBehavior( new SoftDelete([ 'field' => 'deleted', 'value' => 1, ]) ); } public function beforeCreate() { $this->create_time = time(); } public function beforeUpdate() { if (time() - $this->update_time > 3 * 3600) { $sync = new ArticleIndexSync(); $sync->addItem($this->id); $sync = new ArticleScoreSync(); $sync->addItem($this->id); } $this->update_time = time(); } public function beforeSave() { if (is_array($this->tags) || is_object($this->tags)) { $this->tags = kg_json_encode($this->tags); } } public function afterCreate() { $cache = new MaxArticleIdCache(); $cache->rebuild(); } public function afterFetch() { if (is_string($this->tags)) { $this->tags = json_decode($this->tags, true); } } public static function sourceTypes() { return [ self::SOURCE_ORIGIN => '原创', self::SOURCE_REPRINT => '转载', self::SOURCE_TRANSLATE => '翻译', ]; } public static function publishTypes() { return [ self::PUBLISH_PENDING => '审核中', self::PUBLISH_APPROVED => '已发布', self::PUBLISH_REJECTED => '未通过', ]; } public static function sortTypes() { return [ 'latest' => '最新', 'popular' => '最热', 'featured' => '推荐', ]; } }