Skip to content

Instantly share code, notes, and snippets.

@kinglozzer
Created March 24, 2015 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kinglozzer/1865d08ce500775c0cd1 to your computer and use it in GitHub Desktop.
Save kinglozzer/1865d08ce500775c0cd1 to your computer and use it in GitHub Desktop.
<?php
class Page extends SiteTree {
/**
* Return any event pages that are in this section.
* @param ArrayList|null $children
* @param ArrayList|null &$events
* @return ArrayList
*/
public function SectionEvents() {
$top = $this->Level(1);
$events = ArrayList::create();
$top->loadChildEventsInto($events);
return $events;
}
/**
* Recursively scans child pages looking for instances of 'EventPage' and adding
* them to the ArrayList passed by reference
* @param ArrayList &$arrayList
* @return void
*/
protected function loadChildEventsInto(ArrayList &$arrayList) {
if($children = $this->Children()) {
foreach($children as $child) {
if($child->ClassName === 'EventPage') {
$arrayList->push($child);
}
$child->loadChildEventsInto($arrayList);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment