Skip to content

Commit

Permalink
ActiveDataProvider default sorting configuration for news article
Browse files Browse the repository at this point in the history
overview. closes #1115
  • Loading branch information
nadar committed Dec 20, 2016
1 parent 6eeac97 commit b8c5f0e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ The changelog contains informations about bug fixes, new features or bc breaking

### Added

- [#1115](https://github.com/luyadev/luya/issues/1115) ActiveDataProvider default sorting configuration for news article overview.
- [#1018](https://github.com/luyadev/luya/issues/1018) NgRest SelectModel Plugins where conditions, labelFields and labelTemplate properties added.
- [#1010](https://github.com/luyadev/luya/issues/1010) Ability to soft delete admin languages if its not the system default language.
- [#1110](https://github.com/luyadev/luya/issues/1110) Filemanager is sorting the directories alphabetically instead of chronologically.
Expand Down
7 changes: 7 additions & 0 deletions modules/news/src/frontend/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ class Module extends \luya\base\Module
*/
public $useAppViewPath = true;

/**
* @var array The default order for the article overview in the index action for the news.
*
* In order to read more about activeDataProvider defaultOrder: http://www.yiiframework.com/doc-2.0/yii-data-sort.html#$defaultOrder-detail
*/
public $articleDefaultOrder = ['timestamp_create' => SORT_DESC];

/**
* @var array
*/
Expand Down
3 changes: 3 additions & 0 deletions modules/news/src/frontend/controllers/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public function actionIndex()
{
$provider = new ActiveDataProvider([
'query' => Article::find()->andWhere(['is_deleted' => 0]),
'sort' => [
'defaultOrder' => $this->module->articleDefaultOrder,
]
]);

return $this->render('index', [
Expand Down
13 changes: 1 addition & 12 deletions modules/news/src/models/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,6 @@ public function eventBeforeInsert()
$this->timestamp_display_from = time();
}
}

/**
* @inheritdoc
*/
public function scenarios()
{
return [
'restcreate' => ['title', 'text', 'cat_id', 'image_id', 'image_list', 'timestamp_create', 'timestamp_display_from', 'timestamp_display_until', 'is_display_limit', 'file_list', 'teaser_text'],
'restupdate' => ['title', 'text', 'cat_id', 'image_id', 'image_list', 'timestamp_create', 'timestamp_display_from', 'timestamp_display_until', 'is_display_limit', 'file_list', 'teaser_text'],
];
}

/**
* @inheritdoc
Expand All @@ -97,7 +86,7 @@ public function rules()
[['title', 'text'], 'required'],
[['title', 'text', 'image_list', 'file_list', 'teaser_text'], 'string'],
[['cat_id', 'create_user_id', 'update_user_id', 'timestamp_create', 'timestamp_update', 'timestamp_display_from', 'timestamp_display_until', 'is_deleted', 'is_display_limit'], 'integer'],
[['image_id'], 'string', 'max' => 200],
[['image_id'], 'safe'],
];
}

Expand Down

0 comments on commit b8c5f0e

Please sign in to comment.