Skip to content
Browse files

Added ability to filterany

  • Loading branch information...
1 parent f5c48c2 commit b87b2334e48e76d78dba9393d41ef67747b9fd9e @arambalakjian committed Feb 25, 2014
Showing with 11 additions and 1 deletion.
  1. +11 −1 code/Pages/DataObjectAsPageHolder.php
12 code/Pages/DataObjectAsPageHolder.php
@@ -37,7 +37,17 @@ public function FetchItems($itemClass, $filter = null, $sort = Null, $limit = Nu
- $results = $results->filter($filter);
+ if(is_array($filter))
+ {
+ foreach($filter as $type => $value)
+ {
+ $results = $results->$type($value);
+ }
+ }
+ else
+ {
+ $results = $results->filter($filter);
+ }

1 comment on commit b87b233


Hi Aram

For those struggling with the new syntax updates for filtering DOAP Holding Pages I've put a basic example syntax below for each version (tested in SS 3.1.3 with the above latest version of DOAP installed and flushed).

If you get an SS error of: [User Error] Uncaught Exception: Object->__call(): the method 'embargodate:lessthan' does not exist on 'DataList'. Read below for how to update your filters.

Place each of the examples below inside the getItemsWhere() function on your DataObjectAsPageHolder sub class.

    public function getItemsWhere()
        //Use this function to return a custom filter to the Items() function
        // place code examples HERE

Old SSv2 style filter - depreciated method:

return "Category LIKE '$this->Category'";

New SSv3 DataList filtering (now also depreciated by above DOAP update causing the "User Error"):

return array (
    'Category:PartialMatch' => $this->Category

Update of above to work with the new SS3.1.3 and DOAP update (the critical part is to add filter and then add another array with what you want to filter with):

return array('filter' => array('Category:PartialMatch' => $this->Category));

You can also now use all the Search Filter Modifiers listed here as of SS3.1.3:

For example :GreaterThanOrEqual and :LessThanOrEqual are newly added as of SS3.1.3.

A more complex example with multiple items in the filter array:

$dateToday = date("Y-m-d");

return array('filter' => array (
    'EmbargoDate:LessThanOrEqual' => $dateToday,
    'ExpiryDate:GreaterThan' => $dateToday

I hope this comment helps anyone else who has struggled with the new filtering syntax updates.

Thanks to Aram for making DOAP and keeping it bang up to date.


Please sign in to comment.
Something went wrong with that request. Please try again.