. * * @author TechFuze * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License * * @link http://fuzeworks.techfuze.net * @since Version 0.0.1 * * @version Version 0.0.1 */ namespace Module\Admin; use FuzeWorks\Logger; class AdvertiseFetcher { /** * Create a pageList using the advertisements from the admin module. * * @param array $advertisements The advertisement repository * * @throws AdminException On fatal and/or missing data * * @return PageList An object oriented page list with details * * @todo Implement Unit Test */ public static function getPageList($advertisements) { // Prepare a pageList Logger::newLevel('Generating PageList'); $pageList = new PageList(); // First get the modules foreach ($advertisements as $module => $data) { // Apple regular data $identifier = (isset($data['identifier']) ? $data['identifier'] : null); $pages = (isset($data['pages']) ? $data['pages'] : null); // Check if everything is set, if not shout out in terror if (is_null($identifier) || is_null($pages)) { throw new AdminException("Incomplete data for module '".$module."'", 1); } // And then the pages foreach ($pages as $pageData) { // Create page variable and add module and identifier $page = new PageData(); $page->setModule($module); $page->setIdentifier($identifier); // First the required data for every page $page_path = (isset($pageData['page_path']) ? $pageData['page_path'] : null); $name = (isset($pageData['name']) ? $pageData['name'] : null); // And throw errors if non-existent if (is_null($page_path) || is_null($name)) { throw new AdminException("Incomplete data for module '".$module."'", 1); } // And set those values $page->setPagePath($page_path); $page->setName($name); $unique_identifier = $identifier.'/'.$page_path; Logger::log("Adding page '".$name."' on '".$unique_identifier."'"); // And at last for the optional values $page->setIcon((isset($pageData['icon']) ? $pageData['icon'] : '')); $page->setPermissionGroups((isset($pageData['permissionGroups']) ? $pageData['permissionGroups'] : array())); $page->setPriority((isset($pageData['priority']) ? $pageData['priority'] : 1)); // And finally add the page $pageList->addPage($page, $unique_identifier); } } // And finally return the pageList\ Logger::stopLevel(); return $pageList; } }