|
|
@@ -16,6 +16,7 @@ class ArticleForm extends Model
|
|
|
public $id;
|
|
|
public $title;
|
|
|
public $cid;
|
|
|
+ public $sort;
|
|
|
public $content;
|
|
|
|
|
|
/**
|
|
|
@@ -36,9 +37,10 @@ class ArticleForm extends Model
|
|
|
{
|
|
|
return [
|
|
|
'id' => 'ID',
|
|
|
- 'title' => '标题',
|
|
|
- 'cid' => '分类',
|
|
|
- 'content' => '内容',
|
|
|
+ 'title' => 'Title',//标题
|
|
|
+ 'cid' => 'Type', // 分类
|
|
|
+ 'content' => 'Content', // 内容
|
|
|
+ 'sort' => 'Sort', // 排序
|
|
|
];
|
|
|
}
|
|
|
|
|
|
@@ -50,8 +52,9 @@ class ArticleForm extends Model
|
|
|
{
|
|
|
$parentScenarios = parent::scenarios();
|
|
|
$customScenarios = [
|
|
|
- 'add' => ['title', 'cid', 'content'],
|
|
|
- 'edit' => ['id','title', 'cid', 'content'],
|
|
|
+ 'add' => ['title', 'cid', 'content', 'sort'],
|
|
|
+ 'edit' => ['id','title', 'cid', 'content', 'sort'],
|
|
|
+ 'sort' => ['id', 'sort'],
|
|
|
];
|
|
|
return array_merge($parentScenarios, $customScenarios);
|
|
|
}
|
|
|
@@ -73,6 +76,8 @@ class ArticleForm extends Model
|
|
|
$model->CREATED_AT = Date::nowTime();
|
|
|
} elseif($this->scenario == 'edit') {
|
|
|
$model = Article::findOne(['ID'=>$this->id]);
|
|
|
+ } elseif($this->scenario == 'sort') {
|
|
|
+ $model = Article::findOne(['ID'=>$this->id]);
|
|
|
} else {
|
|
|
$this->addError('edit', 'Scenario not exists');// 提交场景不存在
|
|
|
return null;
|
|
|
@@ -81,6 +86,7 @@ class ArticleForm extends Model
|
|
|
$model->CID = $this->cid;
|
|
|
$model->CONTENT = '';
|
|
|
$model->STATUS = 1;
|
|
|
+ $model->SORT = $this->sort;
|
|
|
if(!$model->save()){
|
|
|
throw new Exception(Form::formatErrorsForApi($model->getErrors()));
|
|
|
}
|
|
|
@@ -96,5 +102,22 @@ class ArticleForm extends Model
|
|
|
return $model;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 排序
|
|
|
+ * @return Article
|
|
|
+ */
|
|
|
+ public function sortTo(): ?Article
|
|
|
+ {
|
|
|
+ if (!$this->validate()) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
|
|
|
+ $model = Article::findOne(['ID' => $this->id]);
|
|
|
+ $model->SORT = $this->sort;
|
|
|
+ if (!$model->save()) {
|
|
|
+ $this->addError('sortTo', Form::formatErrorsForApi($model->getErrors()));
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return $model;
|
|
|
+ }
|
|
|
}
|