'匹配(人才匹配)', self::TYPE_SEARCH => '查询(政策查询)', ]; } /** * {@inheritdoc} */ public static function tableName() { return '{{%policy}}'; } /** * {@inheritdoc} */ public function rules() { return [ [['content', 'title', 'summary', 'type', 'cengci', 'estate'], 'required'], [['sort'], 'integer'], [['content', 'filter', 'cengci'], 'string'], ['markdown', 'default', 'value' => $this->getIsMarkdown()], [['use_layout'], 'in', 'range' => [0, 1]], [['sort'], 'default', 'value' => 0], [['title'], 'string', 'max' => 50], [['author'], 'string', 'max' => 50], // ['content', 'filterHtml'] ]; } public function filterHtml($attribute) { $this->$attribute = HtmlPurifier::process($this->$attribute, function ($config) { $config->set('HTML.Allowed', 'p[style],a[href|title],img[src|title|alt|class],h3,ul,ol,li,span,b,strong,hr,code,table,tbody,tr,td'); // 清除空标签 $config->set('AutoFormat.RemoveEmpty', true); }); } /** * 没有指定markdown情况下默认编辑器是否为markdown * @return int */ public function getIsMarkdown() { return \Yii::$app->config->get('article_editor_type') == 'markdown' ? 1 : 0; } public function getProcessedContent() { return $this->markdown ? \yii\helpers\Markdown::process($this->content) : $this->content; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'use_layout' => '是否使用布局', 'summary' => '摘要', 'content' => '详情', 'title' => '标题', 'author' => '作者', 'type' => '类型',//类型:0 匹配,1 查询 'cengci' => '层次', 'estate' => '产业', 'created_at' => '发布时间', 'sort' => '排序', ]; } public function attributeHints() { return [ 'name' => '(影响url)' ]; } public function behaviors() { return [ TimestampBehavior::className(), [ 'class' => MetaBehavior::className(), ], [ 'class' => CommentBehavior::className() ], 'positionBehavior' => [ 'class' => PositionBehavior::className(), 'positionAttribute' => 'sort', 'groupAttributes' => [ 'estate' ], ], ]; } public function getMetaData() { $model = $this->getMetaModel(); $title = $model->title ?: $this->title; $author = $model->author ?: $this->author; $description = $model->description ?: StringHelper::truncate(strip_tags($this->content), 150); return [$title, $author, $description, $model->keywords]; } public function getTypeText() { if (!empty($this->type)) { $keys = explode(',', $this->type); $list = self::getTypeList(); if (count($keys) == 2) { return $list[$keys[0]] . ',' . $list[$keys[1]]; } return $list[$keys[0]]; } return ''; } }