Adding lazy-load version of feed component to load data using AJAX after page content has been rendered.
This commit is contained in:
41
www/plugins/jasonwilliams/feed/components/ChannelList.php
Normal file
41
www/plugins/jasonwilliams/feed/components/ChannelList.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php namespace JasonWilliams\Feed\Components;
|
||||
|
||||
use Cms\Classes\ComponentBase;
|
||||
use JasonWilliams\Feed\Models\Channels;
|
||||
|
||||
class ChannelList extends ComponentBase
|
||||
{
|
||||
public function componentDetails()
|
||||
{
|
||||
return [
|
||||
'name' => 'Channel List',
|
||||
'description' => 'Displays a list of feed channels.'
|
||||
];
|
||||
}
|
||||
|
||||
public function defineProperties()
|
||||
{
|
||||
return [
|
||||
'includeEmpty' => [
|
||||
'title' => 'Include Empty?',
|
||||
'description' => 'Include channels with no posts?',
|
||||
'type' => 'checkbox',
|
||||
'default' => true
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function onRun()
|
||||
{
|
||||
$this->page['channels'] = Channels::orderBy('id')->withCount('feeditems')->get();
|
||||
|
||||
// If applicable, remove empty channels
|
||||
if (!$this->property('includeEmpty'))
|
||||
{
|
||||
foreach($this->page['channels'] as $key => $value)
|
||||
{
|
||||
if (!$value->feeditems_count) unset($this->page['channels'][$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user