1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Licensed under The GPL-3.0 License |
4
|
|
|
* For full copyright and license information, please see the LICENSE.txt |
5
|
|
|
* Redistributions of files must retain the above copyright notice. |
6
|
|
|
* |
7
|
|
|
* @since 2.0.0 |
8
|
|
|
* @author Christopher Castro <[email protected]> |
9
|
|
|
* @link http://www.quickappscms.org |
10
|
|
|
* @license http://opensource.org/licenses/gpl-3.0.html GPL-3.0 License |
11
|
|
|
*/ |
12
|
|
|
namespace Content\Widget; |
13
|
|
|
|
14
|
|
|
use Block\Model\Entity\Block; |
15
|
|
|
use Block\Widget; |
16
|
|
|
use Cake\ORM\TableRegistry; |
17
|
|
|
use CMS\View\View; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Used to render a list of latest content publiched on the site. |
21
|
|
|
* |
22
|
|
|
* Aimed to be used in frontend themes. |
23
|
|
|
*/ |
24
|
|
|
class RecentContentWidget extends Widget |
25
|
|
|
{ |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* {@inheritDoc} |
29
|
|
|
*/ |
30
|
|
|
public function render(Block $block, View $view) |
31
|
|
|
{ |
32
|
|
|
$contentsTable = TableRegistry::get('Content.Contents'); |
33
|
|
|
$query = $contentsTable->find('all', ['fieldable' => false]); |
34
|
|
|
|
35
|
|
|
if (!empty($block->settings['filter_criteria'])) { |
36
|
|
|
$query = $contentsTable->search($block->settings['filter_criteria'], $query); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
$contents = $query |
40
|
|
|
->order(['created' => 'DESC']) |
41
|
|
|
->where(['Contents.status' => true]) |
42
|
|
|
->limit($block->settings['limit']) |
43
|
|
|
->all(); |
44
|
|
|
|
45
|
|
|
return $view->element('Content.Widget/recent_content_render', compact('block', 'contents')); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* {@inheritDoc} |
50
|
|
|
*/ |
51
|
|
|
public function settings(Block $block, View $view) |
52
|
|
|
{ |
53
|
|
|
return $view->element('Content.Widget/recent_content_settings', compact('block')); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* {@inheritDoc} |
58
|
|
|
*/ |
59
|
|
|
public function defaultSettings(Block $block) |
60
|
|
|
{ |
61
|
|
|
return [ |
62
|
|
|
'filter_criteria' => '', |
63
|
|
|
'limit' => 10, |
64
|
|
|
]; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|