Filtering Page List Block with Multiple Filters
Permalink
I have a custom template to style a Page List Block in a slider. It works great.
Now, I'm trying to display "Event" page types (from the Calendar Events Add-on) that are:
* Featured (custom page attribute)
* Event End Date (page attribute from add-on) >= Today
* Public Date <= Today (page property)
I started by handling this in a custom template "view.php" file, then realized that doesn't work because the display count would be off, etc.
So, my question is,
1) How do I filter with multiple filters, and
2) do I do this in the /blocks/page_list/templates/TEMPLATE_NAME/controller.php file?
I've been racking my brain to headache mode for a few days on this.
Now, I'm trying to display "Event" page types (from the Calendar Events Add-on) that are:
* Featured (custom page attribute)
* Event End Date (page attribute from add-on) >= Today
* Public Date <= Today (page property)
I started by handling this in a custom template "view.php" file, then realized that doesn't work because the display count would be off, etc.
So, my question is,
1) How do I filter with multiple filters, and
2) do I do this in the /blocks/page_list/templates/TEMPLATE_NAME/controller.php file?
I've been racking my brain to headache mode for a few days on this.
Thanks rge, I will try this.
I'm having the hardest time. I am confusing myself big-time, and I think it's because there is no direct solutions talked about for filtering on the public date on the web.
I copied the getPageList() function to a copied over controller.php file in my page list template, but it's not filtering out future page lists.
I copied the getPageList() function to a copied over controller.php file in my page list template, but it's not filtering out future page lists.
<?php defined('C5_EXECUTE') or die("Access Denied."); class PageListBlockController extends Concrete5_Controller_Block_PageList { public function getPageList() { Loader::model('page_list'); $db = Loader::db(); $bID = $this->bID; if ($this->bID) { $q = "select num, cParentID, cThis, orderBy, ctID, displayAliases, rss from btPageList where bID = '$bID'"; $r = $db->query($q); if ($r) { $row = $r->fetchRow(); } } else { $row['num'] = $this->num;
Viewing 15 lines of 82 lines. View entire code block.
I am not sure but maybe this helps.
In this post they filter on date with the filter method.
http://www.concrete5.org/community/forums/customizing_c5/creating-a...
Documentation Advanced users:
Passes a fliter directly to the "WHERE" clause. The value of $column must be a valid database column that's referenced in the PageList query. Setting the value of $column to false will allow you to pass complex SQL into the $value field ex:
Filters by number of page children. $comparison can be any MySQL comparison operator. $pl->filterByAttribute($attributeKeyHandle, $value, $comparison)
In this post they filter on date with the filter method.
http://www.concrete5.org/community/forums/customizing_c5/creating-a...
$pl->filter($column, $value, $comparison)
Documentation Advanced users:
Passes a fliter directly to the "WHERE" clause. The value of $column must be a valid database column that's referenced in the PageList query. Setting the value of $column to false will allow you to pass complex SQL into the $value field ex:
$pl->filter(false, '(ak_age = 10 OR ak_age IN (13,17,25) OR ak_age > 23)'); where 'age' would be the handle of a numeric page attribute
Thanks for your reply again rge.
I tried all of that too and none of it is filtering out pages that are in the future (public date). I must either be putting something in the wrong place/file, or something else.
I tried all of that too and none of it is filtering out pages that are in the future (public date). I must either be putting something in the wrong place/file, or something else.
I did a quick test via a new page type template that I created. In this page type I instantiate the new pagelist ( $pl = new PageList() ). On the children pages I have set an attribute of is_featured.
For me the code above now only shows the pages that are:
1. featured
2. have a public date <= than the current date (today)
I don't have to calender addon. But I asume that when you know the page attribute It should be used in the same way as the public date.
Don't hardcode It in a page type like I did. It wil probably go wrong when you turn on caching in Concrete.
Full code of the page type
<?php $pl = new PageList(); $pl->filterByParentID($c->getCollectionID()); //get all children pages of the current page $pl->filterByIsFeatured(1); //only get featured pages $pl->filter('cvDatePublic', date('Y-m-d H:i:s'), '<='); $pages = $pl->getPage(); foreach ($pages as $page): $title = $page->getCollectionName(); ?>
For me the code above now only shows the pages that are:
1. featured
2. have a public date <= than the current date (today)
I don't have to calender addon. But I asume that when you know the page attribute It should be used in the same way as the public date.
$pl->filter('endDate', date('Y-m-d 23:59:59'), '>=');
Don't hardcode It in a page type like I did. It wil probably go wrong when you turn on caching in Concrete.
Full code of the page type
<?php defined('C5_EXECUTE') or die (_('Acccess denied.')); ?> <?php $this->inc('elements/header.php'); ?> <?php $c = Page::getCurrentPage(); ?> <div class="main-content main-content-full"> <h2>Filtering mutliple attributes</h2> <?php $pl = new PageList(); $pl->filterByParentID($c->getCollectionID()); $pl->filterByIsFeatured(1); $pl->filter('cvDatePublic', date('Y-m-d H:i:s'), '<='); $pages = $pl->getPage(); foreach ($pages as $page): $title = $page->getCollectionName(); ?> <h3><?php echo $title; ?></h3>
Viewing 15 lines of 18 lines. View entire code block.
Thanks so much for this. I must had tried all kinds of different ways, but I did get this to work for the Public Date and "Is Featured".
I'm still having issues with the "Event End Date", but am starting to wonder if it's the add-on itself... The page breaks when uncomment that filter (below).
I'm still having issues with the "Event End Date", but am starting to wonder if it's the add-on itself... The page breaks when uncomment that filter (below).
<div class="slider-tabs event flexslider"> <ul class="slides"> <?php $pl = new PageList(); $pl->filter('cvDatePublic', date('Y-m-d H:i:s'), '<='); //$pl->filter(date("Y-m-d H:i:s", strtotime('calendar_event_end_date_time')), date('Y-m-d H:i:s'), '>='); $pl->filterByIsFeatured(1); $pages = $pl->getPage(); foreach ($pages as $page): // Title $title = $th->entities($page->getCollectionName()); // URL $url = $nh->getLinkToCollection($page); ...
The filter methods is used in an incorrect way (for the end date).
This first param is the column in the database table of the page. I don't know if end date is included in this table as the publicDate. It might be that it is stored in a different way. Like a page attribute our in a different table.
Here is some more documentation regarding to listing:
http://www.concrete5.org/documentation/developers/5.6/pages/searchi...
Hopefully someone with some more experience regarding to the plugin can give some more insights?
$pl->filter($column, $value, $comparison)
This first param is the column in the database table of the page. I don't know if end date is included in this table as the publicDate. It might be that it is stored in a different way. Like a page attribute our in a different table.
Here is some more documentation regarding to listing:
http://www.concrete5.org/documentation/developers/5.6/pages/searchi...
Hopefully someone with some more experience regarding to the plugin can give some more insights?
My mistake. The Calendar Events add-on does add the "End Date" as a page attribute. It's my playing around with testing date/time formatting for comparison that ended up making the filter wrong, I'm sure.
As far as I know the filters are by default "AND" statements. So you can call the filter multiple times it will be an AND statement. Personally I would do it from the controller since I had some issues with caching when I hardcoded it in a page.
You can also use