-
-
Save kinglozzer/ed34bd961f185956b2cb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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