| @@ 33-59 (lines=27) @@ | ||
| 30 | } |
|
| 31 | } |
|
| 32 | ||
| 33 | public function display() |
|
| 34 | { |
|
| 35 | // get special properties hash |
|
| 36 | $classHash = $this->createStringClassSnapshotHash(); |
|
| 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 | } |
|
| 49 | ||
| 50 | // check if result is not empty |
|
| 51 | if ($records === null || $records->count() < 1) { |
|
| 52 | return __('Content tags is not found'); |
|
| 53 | } |
|
| 54 | ||
| 55 | // render view |
|
| 56 | return App::$View->render($this->tpl, [ |
|
| 57 | 'records' => $records |
|
| 58 | ]); |
|
| 59 | } |
|
| 60 | ||
| 61 | private function makeQuery() |
|
| 62 | { |
|
| @@ 48-77 (lines=30) @@ | ||
| 45 | * {@inheritDoc} |
|
| 46 | * @see \Ffcms\Core\Arch\Widget::display() |
|
| 47 | */ |
|
| 48 | public function display() |
|
| 49 | { |
|
| 50 | // get unique instance hash with current params |
|
| 51 | $cacheHash = $this->createStringClassSnapshotHash(); |
|
| 52 | ||
| 53 | $query = null; |
|
| 54 | // cache is disabled, get result directly |
|
| 55 | if ($this->cache === 0) { |
|
| 56 | $query = $this->makeQuery(); |
|
| 57 | } else { |
|
| 58 | // try get query result from cache |
|
| 59 | $query = App::$Cache->get('widget.newcontent.' . $cacheHash); |
|
| 60 | if ($query === null) { |
|
| 61 | // if query is not cached make it |
|
| 62 | $query = $this->makeQuery(); |
|
| 63 | // and save result to cache |
|
| 64 | App::$Cache->set('widget.newcontent.' . $cacheHash, $query, $this->cache); |
|
| 65 | } |
|
| 66 | } |
|
| 67 | ||
| 68 | // check if response is not empty |
|
| 69 | if ($query->count() < 1) { |
|
| 70 | return __('Content is not founded'); |
|
| 71 | } |
|
| 72 | ||
| 73 | // render view |
|
| 74 | return App::$View->render($this->tpl, [ |
|
| 75 | 'records' => $query |
|
| 76 | ]); |
|
| 77 | } |
|
| 78 | ||
| 79 | /** |
|
| 80 | * Make query to database |
|