@@ -58,6 +58,9 @@ |
||
58 | 58 | ]); |
59 | 59 | } |
60 | 60 | |
61 | + /** |
|
62 | + * @return string |
|
63 | + */ |
|
61 | 64 | private function makeQuery() |
62 | 65 | { |
63 | 66 | return TagRecord::select([ |
@@ -10,12 +10,12 @@ discard block |
||
10 | 10 | |
11 | 11 | class Contenttag extends AbstractWidget |
12 | 12 | { |
13 | - use OopTools; |
|
13 | + use OopTools; |
|
14 | 14 | |
15 | - public $count; |
|
16 | - public $cache; |
|
15 | + public $count; |
|
16 | + public $cache; |
|
17 | 17 | |
18 | - public $tpl = 'widgets/contenttag/default'; |
|
18 | + public $tpl = 'widgets/contenttag/default'; |
|
19 | 19 | |
20 | 20 | public function init() |
21 | 21 | { |
@@ -33,39 +33,39 @@ discard block |
||
33 | 33 | public function display() |
34 | 34 | { |
35 | 35 | // get special properties hash |
36 | - $classHash = $this->createStringClassSnapshotHash(); |
|
36 | + $classHash = $this->createStringClassSnapshotHash(); |
|
37 | 37 | |
38 | - // get records rows from cache or directly from db |
|
39 | - $records = null; |
|
40 | - if ($this->cache === 0) { |
|
41 | - $records = $this->makeQuery(); |
|
42 | - } else { |
|
43 | - $records === App::$Cache->get('widget.contenttag.' . $classHash); |
|
44 | - if ($records === null) { |
|
45 | - $records = $this->makeQuery(); |
|
46 | - App::$Cache->set('widget.contenttag' . $classHash, $records, $this->cache); |
|
47 | - } |
|
48 | - } |
|
38 | + // get records rows from cache or directly from db |
|
39 | + $records = null; |
|
40 | + if ($this->cache === 0) { |
|
41 | + $records = $this->makeQuery(); |
|
42 | + } else { |
|
43 | + $records === App::$Cache->get('widget.contenttag.' . $classHash); |
|
44 | + if ($records === null) { |
|
45 | + $records = $this->makeQuery(); |
|
46 | + App::$Cache->set('widget.contenttag' . $classHash, $records, $this->cache); |
|
47 | + } |
|
48 | + } |
|
49 | 49 | |
50 | - // check if result is not empty |
|
50 | + // check if result is not empty |
|
51 | 51 | if ($records === null || $records->count() < 1) { |
52 | 52 | return __('Content tags is not found'); |
53 | 53 | } |
54 | 54 | |
55 | 55 | // render view |
56 | - return App::$View->render($this->tpl, [ |
|
57 | - 'records' => $records |
|
58 | - ]); |
|
56 | + return App::$View->render($this->tpl, [ |
|
57 | + 'records' => $records |
|
58 | + ]); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | private function makeQuery() |
62 | 62 | { |
63 | 63 | return TagRecord::select([ |
64 | - App::$Database->getConnection()->raw('SQL_CALC_FOUND_ROWS tag'), |
|
65 | - App::$Database->getConnection()->raw('COUNT(*) AS count') |
|
66 | - ])->groupBy('tag') |
|
67 | - ->orderBy('count', 'DESC') |
|
68 | - ->take($this->count) |
|
69 | - ->get(); |
|
64 | + App::$Database->getConnection()->raw('SQL_CALC_FOUND_ROWS tag'), |
|
65 | + App::$Database->getConnection()->raw('COUNT(*) AS count') |
|
66 | + ])->groupBy('tag') |
|
67 | + ->orderBy('count', 'DESC') |
|
68 | + ->take($this->count) |
|
69 | + ->get(); |
|
70 | 70 | } |
71 | 71 | } |
72 | 72 | \ No newline at end of file |
@@ -22,11 +22,11 @@ discard block |
||
22 | 22 | $cfg = $this->getConfigs(); |
23 | 23 | // check cache is defined |
24 | 24 | if ($this->cache === null || !Obj::isLikeInt($this->cache)) { |
25 | - $this->cache = (int)$cfg['cache']; |
|
25 | + $this->cache = (int) $cfg['cache']; |
|
26 | 26 | } |
27 | 27 | // check tag count is defined |
28 | 28 | if ($this->count === null || !Obj::isLikeInt($this->count)) { |
29 | - $this->count = (int)$cfg['count']; |
|
29 | + $this->count = (int) $cfg['count']; |
|
30 | 30 | } |
31 | 31 | } |
32 | 32 | |
@@ -40,10 +40,10 @@ discard block |
||
40 | 40 | if ($this->cache === 0) { |
41 | 41 | $records = $this->makeQuery(); |
42 | 42 | } else { |
43 | - $records === App::$Cache->get('widget.contenttag.' . $classHash); |
|
43 | + $records === App::$Cache->get('widget.contenttag.'.$classHash); |
|
44 | 44 | if ($records === null) { |
45 | 45 | $records = $this->makeQuery(); |
46 | - App::$Cache->set('widget.contenttag' . $classHash, $records, $this->cache); |
|
46 | + App::$Cache->set('widget.contenttag'.$classHash, $records, $this->cache); |
|
47 | 47 | } |
48 | 48 | } |
49 | 49 |
@@ -29,7 +29,7 @@ |
||
29 | 29 | |
30 | 30 | // render view output |
31 | 31 | return App::$View->render('index', [ |
32 | - 'model' => $model |
|
32 | + 'model' => $model |
|
33 | 33 | ]); |
34 | 34 | } |
35 | 35 | } |
36 | 36 | \ No newline at end of file |
@@ -5,5 +5,5 @@ |
||
5 | 5 | ?> |
6 | 6 | |
7 | 7 | <?php foreach ($records as $row) { |
8 | - echo Url::link(['content/tag', $row['tag']], $row['tag'], ['class' => 'label label-default']) . ' '; |
|
8 | + echo Url::link(['content/tag', $row['tag']], $row['tag'], ['class' => 'label label-default']).' '; |
|
9 | 9 | } |
10 | 10 | \ No newline at end of file |
@@ -22,8 +22,8 @@ discard block |
||
22 | 22 | } |
23 | 23 | |
24 | 24 | /** |
25 | - * Set default model properties from global configuration |
|
26 | - */ |
|
25 | + * Set default model properties from global configuration |
|
26 | + */ |
|
27 | 27 | public function before() |
28 | 28 | { |
29 | 29 | $this->count = (int)$this->_configs['count']; |
@@ -31,8 +31,8 @@ discard block |
||
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
34 | - * Form display labels |
|
35 | - */ |
|
34 | + * Form display labels |
|
35 | + */ |
|
36 | 36 | public function labels() |
37 | 37 | { |
38 | 38 | return [ |
@@ -42,8 +42,8 @@ discard block |
||
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
45 | - * Validation rules |
|
46 | - */ |
|
45 | + * Validation rules |
|
46 | + */ |
|
47 | 47 | public function rules() |
48 | 48 | { |
49 | 49 | return [ |
@@ -26,8 +26,8 @@ |
||
26 | 26 | */ |
27 | 27 | public function before() |
28 | 28 | { |
29 | - $this->count = (int)$this->_configs['count']; |
|
30 | - $this->cache = (int)$this->_configs['cache']; |
|
29 | + $this->count = (int) $this->_configs['count']; |
|
30 | + $this->cache = (int) $this->_configs['cache']; |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |