-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
see #111
- Loading branch information
Showing
3 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
plugins/Content/src/Template/Element/Widget/recent_content_render.ctp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
/** | ||
* Licensed under The GPL-3.0 License | ||
* For full copyright and license information, please see the LICENSE.txt | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @since 2.0.0 | ||
* @author Christopher Castro <[email protected]> | ||
* @link http://www.quickappscms.org | ||
* @license http://opensource.org/licenses/gpl-3.0.html GPL-3.0 License | ||
*/ | ||
?> | ||
|
||
<h2><?= $block->title; ?></h2> | ||
<ul class="qa-recent-content"> | ||
<?php foreach ($contents as $content): ?> | ||
<li> | ||
<?= $this->Html->link($content->title, $content->url, ['title' => $content->description]); ?> | ||
</li> | ||
<?php endforeach; ?> | ||
</ul> |
27 changes: 27 additions & 0 deletions
27
plugins/Content/src/Template/Element/Widget/recent_content_settings.ctp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
/** | ||
* Licensed under The GPL-3.0 License | ||
* For full copyright and license information, please see the LICENSE.txt | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @since 2.0.0 | ||
* @author Christopher Castro <[email protected]> | ||
* @link http://www.quickappscms.org | ||
* @license http://opensource.org/licenses/gpl-3.0.html GPL-3.0 License | ||
*/ | ||
?> | ||
|
||
<?= | ||
$this->Form->input('filter_criteria', [ | ||
'type' => 'text', | ||
'label' => __d('contents', 'Filter criteria') | ||
]); | ||
?> | ||
<em class="help-block"><?= __d('contents', 'Search criteria which determinates Contents that will be present in the list. e.g. "type:articles" if you want to list latest Articles.'); ?></em> | ||
|
||
<?= | ||
$this->Form->input('limit', [ | ||
'type' => 'number', | ||
'label' => __d('taxonomy', 'Size of the list') | ||
]); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
/** | ||
* Licensed under The GPL-3.0 License | ||
* For full copyright and license information, please see the LICENSE.txt | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @since 2.0.0 | ||
* @author Christopher Castro <[email protected]> | ||
* @link http://www.quickappscms.org | ||
* @license http://opensource.org/licenses/gpl-3.0.html GPL-3.0 License | ||
*/ | ||
namespace Content\Widget; | ||
|
||
use Block\Model\Entity\Block; | ||
use Block\Widget; | ||
use Cake\ORM\TableRegistry; | ||
use CMS\View\View; | ||
|
||
/** | ||
* Used to render a list of latest content publiched on the site. | ||
* | ||
* Aimed to be used in frontend themes. | ||
*/ | ||
class RecentContentWidget extends Widget | ||
{ | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function render(Block $block, View $view) | ||
{ | ||
$contentsTable = TableRegistry::get('Content.Contents'); | ||
$query = $contentsTable->find('all', ['fieldable' => false]); | ||
|
||
if (!empty($block->settings['filter_criteria'])) { | ||
$query = $contentsTable->search($block->settings['filter_criteria'], $query); | ||
} | ||
|
||
$contents = $query | ||
->order(['created' => 'DESC']) | ||
->where(['Contents.status' => true]) | ||
->limit($block->settings['limit']) | ||
->all(); | ||
|
||
return $view->element('Content.Widget/recent_content_render', compact('block', 'contents')); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function settings(Block $block, View $view) | ||
{ | ||
return $view->element('Content.Widget/recent_content_settings', compact('block')); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function defaultSettings(Block $block) | ||
{ | ||
return [ | ||
'filter_criteria' => '', | ||
'limit' => 10, | ||
]; | ||
} | ||
} |