function TemplateList() { if (!$this->templateList) { $page = TemplateOverviewPage::get()->First(); if ($page) { $this->templateList = $page->ListOfAllClasses(); } } return $this->templateList; }
/** * returns a lis of all SiteTree Classes * @return Array(String) */ private function listOfAllClasses() { $pages = array(); $list = null; if (class_exists("TemplateOverviewPage")) { $templateOverviewPage = TemplateOverviewPage::get()->First(); if (!$templateOverviewPage) { $templateOverviewPage = singleton("TemplateOverviewPage"); } $list = $templateOverviewPage->ListOfAllClasses(); foreach ($list as $page) { $pages[] = $page->ClassName; } } if (!count($pages)) { $list = ClassInfo::subclassesFor("SiteTree"); foreach ($list as $page) { $pages[] = $page; } } return $pages; }
public function ListOfAllClasses($checkCurrentClass = true) { if (!self::$list_of_all_classes) { $ArrayOfAllClasses = array(); //$classes = ClassInfo::subclassesFor("SiteTree"); $classes = SiteTree::page_type_classes(); $classesToRemove = array(); foreach ($classes as $className) { if (!in_array($className, $this->config()->get("classes_to_exclude"))) { if ($this->showAll) { $objects = $className::get()->filter(array("ClassName" => $className))->sort("RAND() ASC")->limit(25); $count = 0; if ($objects->count()) { foreach ($objects as $obj) { if (!$count) { if ($ancestorToHide = $obj->stat('hide_ancestor')) { $classesToRemove[] = $ancestorToHide; } } $object = $this->createPageObject($obj, $count++); $ArrayOfAllClasses[$object->indexNumber] = clone $object; } } } else { $obj = null; $obj = $className::get()->filter(array("ClassName" => $className))->sort("RAND() ASC")->limit(1)->first(); if ($obj) { $count = SiteTree::get()->filter(array("ClassName" => $obj->ClassName))->count(); } else { $obj = $className::create(); $count = 0; } if ($ancestorToHide = $obj->stat('hide_ancestor')) { $classesToRemove[] = $ancestorToHide; } $object = $this->createPageObject($obj, $count); $object->TemplateOverviewDescription = $this->TemplateDetails($className); $ArrayOfAllClasses[$object->indexNumber] = clone $object; } } } //remove the hidden ancestors... if ($classesToRemove && count($classesToRemove)) { $classesToRemove = array_unique($classesToRemove); // unset from $classes foreach ($ArrayOfAllClasses as $tempKey => $tempClass) { if (in_array($tempClass->ClassName, $classesToRemove)) { unset($ArrayOfAllClasses[$tempKey]); } } } ksort($ArrayOfAllClasses); self::$list_of_all_classes = new ArrayList(); $currentClassname = ''; if ($checkCurrentClass) { if ($c = Controller::curr()) { if ($d = $c->dataRecord) { $currentClassname = $d->ClassName; } } } if (count($ArrayOfAllClasses)) { foreach ($ArrayOfAllClasses as $item) { if ($item->ClassName == $currentClassname) { $item->LinkingMode = "current"; } else { $item->LinkingMode = "link"; } self::$list_of_all_classes->push($item); } } } return self::$list_of_all_classes; }
function onBeforeWrite() { if (!$this->ParentID) { if ($page = TemplateOverviewPage::get()->First()) { $this->ParentID = $page->ID; } } parent::onBeforeWrite(); }