|
|
@@ -11,6 +11,7 @@ use common\helpers\Cache;
|
|
|
use common\helpers\Form;
|
|
|
use common\models\Article;
|
|
|
use common\models\ArticleCategory;
|
|
|
+use common\models\Countries;
|
|
|
use common\models\forms\ArticleCategoryForm;
|
|
|
use common\models\forms\ArticleForm;
|
|
|
use common\models\forms\UploadForm;
|
|
|
@@ -43,8 +44,9 @@ class ArticleController extends BaseController
|
|
|
* @return mixed
|
|
|
* @throws \yii\web\HttpException
|
|
|
*/
|
|
|
- public function actionCategoryAdd(){
|
|
|
- if(Yii::$app->request->isPost) {
|
|
|
+ public function actionCategoryAdd()
|
|
|
+ {
|
|
|
+ if (Yii::$app->request->isPost) {
|
|
|
return parent::edit(ArticleCategoryForm::class, Yii::t('ctx', 'successfully'));
|
|
|
}
|
|
|
}
|
|
|
@@ -82,13 +84,23 @@ class ArticleController extends BaseController
|
|
|
* @return mixed
|
|
|
* @throws \yii\web\HttpException
|
|
|
*/
|
|
|
- public function actionIndex(){
|
|
|
- $data = Article::lists('', [], [
|
|
|
- 'select' => 'ID,TITLE,CID,STATUS,SORT,CREATED_AT',
|
|
|
+ public function actionIndex()
|
|
|
+ {
|
|
|
+ $filter = $this->filterCondition([
|
|
|
+ 'TITLE' => 'TITLE',
|
|
|
+ 'COUNTRY_ID' => 'COUNTRY_ID',
|
|
|
+ ]);
|
|
|
+ $condition = $filter['condition'];
|
|
|
+ $params = $filter['params'];
|
|
|
+
|
|
|
+ $data = Article::lists($condition, $params, [
|
|
|
+ 'select' => 'ID,TITLE,CID,COUNTRY_ID,STATUS,SORT,CREATED_AT',
|
|
|
'orderBy' => 'SORT ASC,CREATED_AT DESC',
|
|
|
]);
|
|
|
+
|
|
|
// 全部分类
|
|
|
$data['allCategory'] = ArticleCategory::getAllCategory();
|
|
|
+
|
|
|
return static::notice($data);
|
|
|
}
|
|
|
|
|
|
@@ -97,12 +109,15 @@ class ArticleController extends BaseController
|
|
|
* @return mixed
|
|
|
* @throws \yii\web\HttpException
|
|
|
*/
|
|
|
- public function actionAdd(){
|
|
|
- if(Yii::$app->request->isPost) {
|
|
|
+ public function actionAdd()
|
|
|
+ {
|
|
|
+ if (Yii::$app->request->isPost) {
|
|
|
return parent::edit(ArticleForm::class, Yii::t('ctx', 'successfully'));
|
|
|
}
|
|
|
+
|
|
|
// 获取全部分类
|
|
|
$allCategory = ArticleCategory::find()->where('STATUS=1')->asArray()->all();
|
|
|
+
|
|
|
return static::notice(['allCategory'=>$allCategory]);
|
|
|
}
|
|
|
|
|
|
@@ -119,6 +134,8 @@ class ArticleController extends BaseController
|
|
|
}
|
|
|
$oneData = Article::findOneAsArray(['ID'=>$id]);
|
|
|
$oneData['CONTENT'] = is_resource($oneData['CONTENT']) ? stream_get_contents($oneData['CONTENT']) : '';
|
|
|
+ // 国家
|
|
|
+ $oneData['COUNTRY'] = Countries::getCountry($oneData['COUNTRY_ID']);
|
|
|
// 暂时先从文件中取内容
|
|
|
$path = \Yii::getAlias('@common/runtime/articleContent/').$oneData['ID'];
|
|
|
if(!file_exists($path)){
|
|
|
@@ -180,11 +197,13 @@ class ArticleController extends BaseController
|
|
|
$id = \Yii::$app->request->get('id');
|
|
|
$data = null;
|
|
|
if($id){
|
|
|
- $data = Article::findOneAsArray('ID=:ID AND STATUS=1', [':ID'=>$id], 'ID,TITLE,CID,SORT,CREATED_AT');
|
|
|
+ $data = Article::findOneAsArray('ID=:ID AND STATUS=1', [':ID'=>$id], 'ID,COUNTRY_ID,TITLE,CID,SORT,CREATED_AT');
|
|
|
+ // 国家
|
|
|
+ $data['COUNTRY'] = Countries::getCountry($data['COUNTRY_ID']);
|
|
|
}
|
|
|
if($data){
|
|
|
// 暂时先从文件中取内容
|
|
|
- $path = \Yii::getAlias('@common/runtime/articleContent/').$data['ID'];
|
|
|
+ $path = \Yii::getAlias('@common/runtime/articleContent/') . $data['ID'];
|
|
|
if(!file_exists($path)){
|
|
|
$data['CONTENT'] = '';
|
|
|
} else {
|