Skip to content

Commit 6b1f76a

Browse files
author
Samuel Akopyan
committed
Redo array() to []
1 parent c66e398 commit 6b1f76a

39 files changed

+9594
-7937
lines changed

demos/simple-blog/protected/components/Bootstrap.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ class Bootstrap extends CComponent
2424
*/
2525
function __construct()
2626
{
27-
A::app()->attachEventHandler('_onBeginRequest', array($this, 'setTimeZone'));
28-
A::app()->attachEventHandler('_onBeginRequest', array($this, 'setSslMode'));
29-
A::app()->attachEventHandler('_onBeginRequest', array($this, 'setCron'));
30-
31-
A::app()->attachEventHandler('_onEndRequest', array($this, 'setLastVisitedPage'));
32-
}
33-
34-
/**
35-
* Returns the instance of object
27+
A::app()->attachEventHandler('_onBeginRequest', [$this, 'setTimeZone']);
28+
A::app()->attachEventHandler('_onBeginRequest', [$this, 'setSslMode']);
29+
A::app()->attachEventHandler('_onBeginRequest', [$this, 'setCron']);
30+
31+
A::app()->attachEventHandler('_onEndRequest', [$this, 'setLastVisitedPage']);
32+
}
33+
34+
/**
35+
* Returns the instance of object
3636
* @return current class
3737
*/
3838
public static function init()

demos/simple-blog/protected/controllers/CategoriesController.php

+46-35
Original file line numberDiff line numberDiff line change
@@ -52,34 +52,35 @@ public function viewAction($categoryId = 0)
5252

5353
//All posts from the selected category
5454
$postsModel = Posts::model();
55-
if (!$postsModel->count('category_id = :category_id', array(':category_id' => $categoryId))) {
56-
$msgType = 'warning';
55+
if ( ! $postsModel->count('category_id = :category_id', [':category_id' => $categoryId])) {
56+
$msgType = 'warning';
5757
$msg = (!empty($catName)) ? 'There are still no posts in category <b>' . $catName . '</b>.' : 'Wrong parameter passed, please try again later.';
5858
} else {
5959

6060
// prepare pagination vars
6161
$this->_view->targetPage = 'categories/view/id/' . $categoryId;
6262
$this->_view->currentPage = A::app()->getRequest()->getQuery('page', 'integer', 1);
6363
$this->_view->pageSize = '5';
64-
$this->_view->totalRecords = Posts::model()->count(array(
65-
'condition' => 'category_id = :category_id',
66-
),
67-
array(':category_id' => $categoryId)
68-
);
69-
70-
$msgType = 'info';
64+
$this->_view->totalRecords = Posts::model()->count(
65+
['condition' => 'category_id = :category_id',],
66+
[':category_id' => $categoryId]
67+
);
68+
69+
$msgType = 'info';
7170
$msg = 'Category: ' . $catName;
72-
73-
$this->_view->posts = $postsModel->findAll(array(
74-
'condition' => 'category_id = :category_id',
75-
'limit' => (($this->_view->currentPage - 1) * $this->_view->pageSize) . ', ' . $this->_view->pageSize,
76-
'order' => 'post_datetime DESC',
77-
),
78-
array(':category_id' => $categoryId)
79-
);
80-
}
81-
$this->_view->mainText = CWidget::create('CMessage', array($msgType, $msg, array('button' => false)));
82-
$this->_view->render('categories/view');
71+
72+
$this->_view->posts = $postsModel->findAll(
73+
[
74+
'condition' => 'category_id = :category_id',
75+
'limit' => (($this->_view->currentPage - 1) * $this->_view->pageSize).', '
76+
.$this->_view->pageSize,
77+
'order' => 'post_datetime DESC',
78+
],
79+
[':category_id' => $categoryId]
80+
);
81+
}
82+
$this->_view->mainText = CWidget::create('CMessage', [$msgType, $msg, ['button' => false]]);
83+
$this->_view->render('categories/view');
8384
}
8485

8586
public function indexAction($msg = '')
@@ -107,25 +108,35 @@ public function indexAction($msg = '')
107108
$msgType = 'Wrong parameter passed! Check category ID.';
108109
$msgType = 'error';
109110
}
110-
if (!empty($msgType)) $this->_view->actionMessage = CWidget::create('CMessage', array($msgType, $msgType, array('button' => true)));
111-
}
112-
113-
// prepare pagination vars
111+
if ( ! empty($msgType)) {
112+
$this->_view->actionMessage = CWidget::create('CMessage', [$msgType, $msgType, ['button' => true]]);
113+
}
114+
}
115+
116+
// prepare pagination vars
114117
$this->_view->targetPage = 'categories/index';
115118
$this->_view->currentPage = A::app()->getRequest()->getQuery('page', 'integer', 1);
116119
$this->_view->pageSize = '15';
117120
$this->_view->totalRecords = Categories::model()->count();
118-
119-
if (!$this->_view->currentPage) {
120-
$this->_view->actionMessage = CWidget::create('CMessage', array('error', 'Wrong parameter passed! Please try again later.', array('button' => true)));
121-
} else {
122-
$this->_view->categories = Categories::model()->findAll(array(
123-
'limit' => (($this->_view->currentPage - 1) * $this->_view->pageSize) . ', ' . $this->_view->pageSize,
124-
'order' => 'id ASC',
125-
));
126-
}
127-
128-
$this->_view->render('categories/index');
121+
122+
if ( ! $this->_view->currentPage) {
123+
$this->_view->actionMessage = CWidget::create('CMessage',
124+
[
125+
'error',
126+
'Wrong parameter passed! Please try again later.',
127+
['button' => true]
128+
]
129+
);
130+
} else {
131+
$this->_view->categories = Categories::model()->findAll(
132+
[
133+
'limit' => (($this->_view->currentPage - 1) * $this->_view->pageSize).', '.$this->_view->pageSize,
134+
'order' => 'id ASC',
135+
]
136+
);
137+
}
138+
139+
$this->_view->render('categories/index');
129140
}
130141

131142
public function addAction()

demos/simple-blog/protected/controllers/PostsController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public function indexAction($msg = '')
147147
));
148148
}else{
149149
$posts = null;
150-
Posts::model()->chunk($conditions, [], -2, function ($records) use(&$posts){
150+
Posts::model()->chunk($conditions, [], 2, function ($records) use(&$posts){
151151
foreach ($records as $key => $record) {
152152
$posts[] = $record;
153153
}

demos/simple-blog/protected/models/Posts.php

+28-14
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ class Posts extends CActiveRecord
1919
public $categoryOldId;
2020

2121
/** @var */
22-
protected $_fillable = array();
23-
/** @var */
24-
protected $_guarded = array('post_datetime');
22+
protected $_fillable = [];
23+
/** @var */
24+
protected $_guarded = ['post_datetime'];
2525

26-
27-
public function __construct()
26+
27+
public function __construct()
2828
{
2929
parent::__construct();
3030
}
@@ -42,13 +42,27 @@ public static function model()
4242
*/
4343
protected function _relations()
4444
{
45-
return array(
46-
'author_id' => array(self::HAS_ONE, 'authors', 'id', 'condition' => '', 'joinType' => self::LEFT_OUTER_JOIN, 'fields' => array('login' => '')),
47-
'category_id' => array(self::BELONGS_TO, 'categories', 'id', 'condition' => '', 'joinType' => self::LEFT_OUTER_JOIN, 'fields' => array('name' => 'category_name')),
48-
);
49-
}
50-
51-
protected function _afterSave($pk = '')
45+
return [
46+
'author_id' => [
47+
self::HAS_ONE,
48+
'authors',
49+
'id',
50+
'condition' => '',
51+
'joinType' => self::LEFT_OUTER_JOIN,
52+
'fields' => ['login' => '']
53+
],
54+
'category_id' => [
55+
self::BELONGS_TO,
56+
'categories',
57+
'id',
58+
'condition' => '',
59+
'joinType' => self::LEFT_OUTER_JOIN,
60+
'fields' => ['name' => 'category_name']
61+
],
62+
];
63+
}
64+
65+
protected function _afterSave($pk = '')
5266
{
5367
if ($this->categoryOldId != $this->category_id) {
5468
$this->_updatePostsCount($this->categoryOldId);
@@ -65,7 +79,7 @@ protected function _afterDelete($pk = '')
6579
private function _updatePostsCount($pKey)
6680
{
6781
// update total count of posts in categories table
68-
$totalPosts = self::model()->count('category_id = :category_id', array(':category_id' => $pKey));
69-
$this->_db->update('categories', array('posts_count' => $totalPosts), 'id = ' . (int)$pKey);
82+
$totalPosts = self::model()->count('category_id = :category_id', [':category_id' => $pKey]);
83+
$this->_db->update('categories', array('posts_count' => $totalPosts), 'id = ' . (int)$pKey);
7084
}
7185
}

demos/simple-blog/protected/modules/setup/templates/default.php

+18-14
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,25 @@
2727
</div>
2828

2929
<?php
30-
CWidget::create('CMenu', array(
31-
'type'=>'vertical',
32-
'items'=>array(
33-
array('label'=>'1. Server Requirements', 'url'=>'setup/index', 'readonly'=>true),
34-
array('label'=>'2. Database Settings', 'url'=>'setup/database', 'readonly'=>true),
35-
array('label'=>'3. Administrator Account', 'url'=>'setup/administrator', 'readonly'=>true),
36-
array('label'=>'4. Ready to Install', 'url'=>'setup/ready', 'readonly'=>true),
37-
array('label'=>'5. Completed', 'url'=>'setup/completed', 'readonly'=>true),
38-
),
39-
'selected'=>$this->_activeMenu,
40-
'return'=>false
41-
));
30+
31+
CWidget::create(
32+
'CMenu',
33+
[
34+
'type' => 'vertical',
35+
'items' => [
36+
['label' => '1. Server Requirements', 'url' => 'setup/index', 'readonly' => true],
37+
['label' => '2. Database Settings', 'url' => 'setup/database', 'readonly' => true],
38+
['label' => '3. Administrator Account', 'url' => 'setup/administrator', 'readonly' => true],
39+
['label' => '4. Ready to Install', 'url' => 'setup/ready', 'readonly' => true],
40+
['label' => '5. Completed', 'url' => 'setup/completed', 'readonly' => true],
41+
],
42+
'selected' => $this->_activeMenu,
43+
'return' => false
44+
]
45+
);
4246
?>
43-
</aside>
44-
<article>
47+
</aside>
48+
<article>
4549
<?php echo A::app()->view->getContent(); ?>
4650
</article>
4751
</section>

demos/simple-blog/protected/modules/setup/views/setup/index.php

+16-12
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,21 @@
1010
<?= $actionMessage; ?>
1111
<br>
1212
<?php
13-
echo CWidget::create('CFormView', array(
14-
'action' => 'setup/index',
15-
'method' => 'post',
16-
'htmlOptions' => array(
17-
'name' => 'frmSetup',
18-
),
19-
'fields' => $formFields,
20-
'buttons' => array(
21-
'submit' => array('type' => 'submit', 'value' => A::t('setup', 'Next'), 'htmlOptions' => array('name' => '')),
22-
),
23-
'return' => true,
24-
));
13+
14+
echo CWidget::create(
15+
'CFormView',
16+
[
17+
'action' => 'setup/index',
18+
'method' => 'post',
19+
'htmlOptions' => [
20+
'name' => 'frmSetup',
21+
],
22+
'fields' => $formFields,
23+
'buttons' => [
24+
'submit' => ['type' => 'submit', 'value' => A::t('setup', 'Next'), 'htmlOptions' => ['name' => '']],
25+
],
26+
'return' => true,
27+
]
28+
);
2529
?>
2630
<br>

demos/simple-blog/protected/views/categories/index.php

+14-11
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,19 @@
3131
}
3232
echo '</tbody>';
3333
echo '</table>';
34-
35-
echo CWidget::create('CPagination', array(
36-
'actionPath' => 'categories/index',
37-
'currentPage' => $currentPage,
38-
'pageSize' => $pageSize,
39-
'totalRecords' => $totalRecords,
40-
'linkType' => 1,
41-
'paginationType' => 'fullNumbers',
42-
));
43-
}
44-
?>
34+
35+
echo CWidget::create(
36+
'CPagination',
37+
[
38+
'actionPath' => 'categories/index',
39+
'currentPage' => $currentPage,
40+
'pageSize' => $pageSize,
41+
'totalRecords' => $totalRecords,
42+
'linkType' => 1,
43+
'paginationType' => 'fullNumbers',
44+
]
45+
);
46+
}
47+
?>
4548
</p>
4649
</article>

demos/simple-blog/protected/views/categories/view.php

+12-10
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,19 @@
4747
}
4848

4949
if (count($posts) > 1) {
50-
echo CWidget::create('CPagination', array(
51-
'actionPath' => 'posts/view',
52-
'currentPage' => $currentPage,
53-
'pageSize' => $pageSize,
54-
'totalRecords' => $totalRecords,
55-
'showResultsOfTotal' => false,
56-
'linkType' => 0,
57-
'paginationType' => 'prevNext',
58-
));
50+
echo CWidget::create(
51+
'CPagination',
52+
[
53+
'actionPath' => 'posts/view',
54+
'currentPage' => $currentPage,
55+
'pageSize' => $pageSize,
56+
'totalRecords' => $totalRecords,
57+
'showResultsOfTotal' => false,
58+
'linkType' => 0,
59+
'paginationType' => 'prevNext',
60+
]
61+
);
5962
}
60-
6163
}
6264
?>
6365

0 commit comments

Comments
 (0)