Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

3.1 #46

Merged
merged 3 commits into from

2 participants

@arambalakjian

No description provided.

@arambalakjian arambalakjian merged commit ddd904b into from
@aledbrown

Hi Aram

Happy New Year :)

I applied this latest DOAP update to a SS 3.1.2 implementation. My filters stopped working. However, I caveat that by saying I don't understand what the "new Filter Module" is.

For example in SS3.1.2/DOAP before 5b17acb was merged this subclass override used to work:

public function getItemsWhere()
{
    //Use this function to return a custom filter to the Items() function
    return "EmbargoDate <= CURDATE() AND EmbargoDate <= ExpiryDate";
}

But now it throws add item array errors.

It doesn't matter if I simplify the return it still doesn't work. Only commenting getItemsWhere() out completely lets the page work again (desired filters are then off, of course).

Could you post a quick example of the new Filter Module syntax and how to override it from List Holder pages? Or is something else going on?

Many thanks
Aled

@arambalakjian

Hi Aled,

Yea this change wa4s to bring it inline with the new DataList->filter() in SS3, instead of the where syntax that was used in DataObject::get() of 2.4

Essentially you now pass in an array to insert into filter(), take a look at the way the filter module does it here:

https://github.com/arambalakjian/DataObject-as-Page-Filter/blob/master/code/Pages/FilteredListingPage.php#L134

Shouldn't be too hard to work in your where in this format.

Essentially try to get it working on it's own as a YourClass::get()->filter(array($Var => $Value));

Then take the bit inside the filter() and return that from your getItemWhere() function.

Hope that helps!

Aram

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 21, 2013
Commits on Dec 30, 2013
This page is out of date. Refresh to see the latest.
Showing with 10 additions and 17 deletions.
  1. +7 −14 code/Pages/DataObjectAsPageHolder.php
  2. +3 −3 composer.json
View
21 code/Pages/DataObjectAsPageHolder.php
@@ -31,19 +31,13 @@ public function getSettingsFields()
/*
* Get Items which are to be displayed on this listing page
*/
- public function FetchItems($itemClass, $filter = '', $sort = Null, $joins = Null, $limit = Null)
+ public function FetchItems($itemClass, $filter = null, $sort = Null, $limit = Null)
{
- $results = $itemClass::get()->where($filter);
+ $results = $itemClass::get();
- if($joins)
+ if($filter)
{
- foreach($joins as $type => $join)
- {
- if($results->hasMethod($type))
- {
- $results = $results->$type($table, $join);
- }
- }
+ $results = $results->filter($filter);
}
if($sort)
@@ -101,7 +95,7 @@ class DataObjectAsPageHolder_Controller extends Page_Controller
private static $item_class = 'DataObjectAsPage';
private static $item_sort = 'Created DESC';
- public static $allowed_actions = array(
+ private static $allowed_actions = array(
'show'
);
@@ -112,13 +106,12 @@ public function Items($limit = null)
{
//Set custom filter
$where = ($this->hasMethod('getItemsWhere')) ? $this->getItemsWhere() : Null;
+
//Set custom sort
$sort = ($this->hasMethod('getItemsSort')) ? $this->getItemsSort() : $this->stat('item_sort');
- //Set custom join
- $join = ($this->hasMethod('getItemsJoin')) ? $this->getItemsJoin() : Null;
//QUERY
- $items = $this->FetchItems($this->Stat('item_class'), $where, $sort, $join, $limit);
+ $items = $this->FetchItems($this->Stat('item_class'), $where, $sort, $limit);
//Paginate the list
if(!$limit && $this->Paginate)
View
6 composer.json
@@ -7,12 +7,12 @@
"authors": [
{
"name": "Aram Balakjian",
- "email": "aram@aabweb.co.uk"
+ "email": "aram@carboncrayon.com"
}
],
"require":
{
- "silverstripe/framework": "3.*",
- "silverstripe/cms": "3.*"
+ "silverstripe/framework": "3.1.*",
+ "silverstripe/cms": "3.1.*"
}
}
Something went wrong with that request. Please try again.