php - SilverStripe 3 Filtering / Filtering Out DataObjects in a Function -
i've found examples of filtering nothing clear enough answer question. have following function grand children pages. i'm trying count them if meet criteria. in case if not have x,y,z include them in count.
in other words add list / array of arguments function if true don't include them , filter them out. example if dealeronly = true
ignore.
i thought doing in template , using if / else count won't display haven't gone down route.
alternative methods welcome.
<% loop $grandchildren %>$count<% end_loop %>
possible help: http://www.silverstripe.org/community/forums/data-model-questions/show/23507
docs here: (not quite need though) https://docs.silverstripe.org/en/3.1/developer_guides/model/searchfilters/
my function returns grandchild pages.
public function getgrandchildren() { $ids = page::get()->filter(array('parentid' => $this->id))->getidlist(); $grandchildren = page::get()->filter(array( 'parentid' => $ids )); return $grandchildren; }
in template counts pages
$grandchildren.count
well, can manipulate datalist
want, e.g.
public function getgrandchildren() { $ids = page::get()->filter(array('parentid' => $this->id))->getidlist(); $grandchildren = page::get() ->filter(array( 'parentid' => $ids )) ->exclude(array('dealeronly' => true)); return $grandchildren; }
see api docs datalist::exclude
, docs
if want exclude if of more columns in database true, have use :not
searchfilter modifier unfortunately there no excludeany()
function.
->filter(array('dealeronly:not' => true)) ->filter(array('foo:not' => 'bar'))
Comments
Post a Comment