Source of file CatalogueCategoryController.php
Size: 2,730 Bytes - Last Modified: 2021-12-24T05:16:22+00:00
/var/www/docs.ssmods.com/process/src/code/controller/CatalogueCategoryController.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 | <?php /** * Controller used to render pages in the catalogue (either categories or pages) * * @author i-lateral (http://www.i-lateral.com) * @package catalogue */ class CatalogueCategoryController extends CatalogueController { /** * Get a paginated list of products contained in this category * * @return PaginatedList */ public function PaginatedProducts($limit = 10) { return PaginatedList::create( $this->SortedProducts(), $this->request )->setPageLength($limit); } /** * Get a paginated list of all products at this level and below * * @return PaginatedList */ public function PaginatedAllProducts($limit = 10) { return PaginatedList::create( $this->AllProducts(), $this->request )->setPageLength($limit); } /** * The Controller will take the URLSegment parameter from the URL * and use that to look up a record. */ public function __construct($dataRecord = null) { if (!$dataRecord) { $dataRecord = new CatalogueCategory(); if ($this->hasMethod("Title")) { $dataRecord->Title = $this->Title(); } $dataRecord->URLSegment = get_class($this); $dataRecord->ID = -1; } $this->dataRecord = $dataRecord; $this->failover = $this->dataRecord; parent::__construct(); } /** * Get a list of templates to call and return a default render with */ public function index() { $this->extend("onBeforeIndex"); $classes = CatalogueHelper::get_templates_for_class($this->dataRecord->class); return $this->renderWith($classes); } /** * Returns a fixed navigation menu of the given level. * @return SS_List */ public function CategoryMenu($level = 1) { if ($level == 1) { $result = CatalogueCategory::get()->filter(array( "ParentID" => 0 )); } else { $parent = $this->data(); $stack = array($parent); if ($parent) { while ($parent = $parent->Parent) { array_unshift($stack, $parent); } } if (isset($stack[$level-2])) { $result = $stack[$level-2]->Children(); } } $visible = array(); if (isset($result)) { foreach ($result as $item) { if ($item->canView()) { $visible[] = $item; } } } return new ArrayList($visible); } } |