Source of file GameListingPage.php
Size: 3,165 Bytes - Last Modified: 2022-02-21T10:00:34+00:00
/var/www/docs.ssmods.com/process/src/code/pagetypes/GameListingPage.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 | <?php class GameListingPage extends Page { private static $icon = "gamesevent/images/gamelist.png"; /** * Modified version of Breadcrumbs, to cater for viewing data objects. */ public function Breadcrumbs($maxDepth = 20, $unlinked = false, $stopAtPageType = false, $showHidden = false) { $page = $this; $pages = array(); while( $page && (!$maxDepth || count($pages) < $maxDepth) && (!$stopAtPageType || $page->ClassName != $stopAtPageType) ) { if($showHidden || $page->ShowInMenus || ($page->ID == $this->ID)) { $pages[] = $page; } $page = $page->Parent; } // Add on the item we're currently showing. $controller = Controller::curr(); if ($controller) { $request = $controller->getRequest(); if ($request->param('Action') == 'show') { $id = $request->param('ID'); if ($id) { $object = DataObject::get_by_id($this->getDataClass(), $id); array_unshift($pages, $object); } } } $template = new SSViewer('BreadcrumbsTemplate'); return $template->process($this->customise(new ArrayData(array( 'Pages' => new ArrayList(array_reverse($pages)) )))); } public function getCurrentGames() { $siteConfig = SiteConfig::current_site_config(); // show all if in draft mode $mode = Versioned::get_reading_mode(); if($mode == 'Stage.Stage') { $items = Game::get()->filter(array( 'ParentID'=>$siteConfig->CurrentEventID )); } else { $items = Game::get()->filter(array( 'Status'=> true, 'ParentID'=>$siteConfig->CurrentEventID )); } return $items; } } class GameListingPage_Controller extends Page_Controller { private static $allowed_actions = array( 'show' ); public function FilteredGames($pageSize = 30){ $items = $this->getCurrentGames(); $items->sort('Title','ASC'); // Apply pagination $list = new AjaxPaginatedList($items, $this->request); $list->setPageLength($pageSize); return $list; } public function getAllTags($current = false) { if($current){ $games = $this->getCurrentGames(); } else { $games = Game::get(); } $list = array(); $result = new ArrayList(); foreach ($games as $game){ $tags = $game->getGenresArray(); for ($i = 0; $i < count($tags); $i++){ $list[$tags[$i]] = $tags[$i]; } } asort($list); foreach($list as $item) { $result->push(new ArrayData(array( 'Title' => $item ))); } return $result; } /** * Returns all modules, sorted by their title. * @return GroupedList */ public function getGroupedGames($sort = 'Session') { $items = $this->getCurrentGames(); return GroupedList::create($items->sort($sort)); } public function show($request) { $data = DataObject::get_by_id("Game", $request->param('ID')); if(!($data && $data->exists())) { return $this->httpError(404); } return $this->customise($data)->renderWith(array('GameListingPage_show', 'Page')); } // Strip underscores and spaces from a string public function NiceString($title, $sentenceCase = false) { $title = str_replace("_", " ", $title); if ($sentenceCase) { $title = ucfirst($title); } return str_replace("-", " ", $title); } } |