/** * Get a theme object with all his attributes * * Loads the component data from component.yml file or creates one from info.xml * or a new one from static array * @param int $id the id of a theme, used for delete * @param string $themesname the display name of theme * @param string $foldername the physical folder name * @param int $expert * @param int $languageId language id * @return \Cx\Core\View\Model\Entity\Theme a theme object */ protected function getTheme($id, $themesname, $foldername, $expert, $languageId = null) { $theme = new \Cx\Core\View\Model\Entity\Theme($id, $themesname, $foldername, $expert); // select default theme of default language if no language id has been // provided $where = '`is_default` = "true"'; if ($languageId) { $where = '`id` = ' . intval($languageId); } $result = $this->db->SelectLimit('SELECT `themesid`, `pdf_themes_id`, `app_themes_id`, `mobile_themes_id`, `print_themes_id` FROM `' . DBPREFIX . 'languages` WHERE ' . $where, 1); if ($result !== false && !$result->EOF) { if ($result->fields['themesid'] == $id) { $theme->addDefault(\Cx\Core\View\Model\Entity\Theme::THEME_TYPE_WEB); } if ($result->fields['pdf_themes_id'] == $id) { $theme->addDefault(\Cx\Core\View\Model\Entity\Theme::THEME_TYPE_PDF); } if ($result->fields['app_themes_id'] == $id) { $theme->addDefault(\Cx\Core\View\Model\Entity\Theme::THEME_TYPE_APP); } if ($result->fields['mobile_themes_id'] == $id) { $theme->addDefault(\Cx\Core\View\Model\Entity\Theme::THEME_TYPE_MOBILE); } if ($result->fields['print_themes_id'] == $id) { $theme->addDefault(\Cx\Core\View\Model\Entity\Theme::THEME_TYPE_PRINT); } } $themePath = file_exists(\Env::get('cx')->getWebsiteThemesPath() . '/' . $foldername) ? \Env::get('cx')->getWebsiteThemesPath() . '/' . $foldername : \Env::get('cx')->getCodeBaseThemesPath() . '/' . $foldername; if (!file_exists($themePath)) { \DBG::log($foldername . ' :Theme folder not Exists'); return $theme; } $this->loadComponentData($theme); // create a new one if no component.yml exists if (!$theme->isComponent()) { try { $this->convertThemeToComponent($theme); } catch (\Exception $ex) { \DBG::log($ex->getMessage()); \DBG::log($theme->getThemesname() . ' : Unable to convert theme to component'); } $this->loadComponentData($theme); } return $theme; }
/** * Sorts the themes by default value. that means, * the themes which have been set as default for a theme type, * they are listed first. * @param Cx\Core\View\Model\Entity\Theme $a theme 1 * @param Cx\Core\View\Model\Entity\Theme $b theme 2 * @return int */ public function sortThemesByDefault($a, $b) { if ($a->isDefault() && $b->isDefault()) { return 0; } if ($a->isDefault() && !$b->isDefault()) { return -1; } return 1; }