/** * Returns an object list * * @param string The query * @param int Offset * @param int The number of records * @return array */ protected function _getList($query, $limitstart = 0, $limit = 0) { $ordering = $this->getState('list.ordering'); $search = $this->getState('filter.search'); // Replace slashes so preg_match will work $search = str_replace('/', ' ', $search); $db = $this->getDbo(); if ($ordering == 'name' || !empty($search) && stripos($search, 'id:') !== 0) { $db->setQuery($query); $result = $db->loadObjectList(); $lang = Lang::getRoot(); $this->translate($result); if (!empty($search)) { foreach ($result as $i => $item) { if (!preg_match("/{$search}/i", $item->name)) { unset($result[$i]); } } } \Hubzero\Utility\Arr::sortObjects($result, $this->getState('list.ordering'), $this->getState('list.direction') == 'desc' ? -1 : 1, true, $lang->getLocale()); $total = count($result); $this->cache[$this->getStoreId('getTotal')] = $total; if ($total < $limitstart) { $limitstart = 0; $this->setState('list.start', 0); } return array_slice($result, $limitstart, $limit ? $limit : null); } else { $query->order($db->quoteName($ordering) . ' ' . $this->getState('list.direction')); $result = parent::_getList($query, $limitstart, $limit); $this->translate($result); return $result; } }
/** * Get a list of the components. * * @return array */ public static function getComponents() { // Initialise variable. $db = App::get('db'); $query = $db->getQuery(true); $query->select('name AS text, element AS value')->from('#__extensions')->where('enabled >= 1')->where('type =' . $db->Quote('component')); $items = $db->setQuery($query)->loadObjectList(); if (count($items)) { $lang = Lang::getRoot(); foreach ($items as &$item) { // Load language $extension = $item->value; $source = PATH_CORE . '/components/' . $extension . '/admin'; $lang->load("{$extension}.sys", PATH_APP, null, false, true) || $lang->load("{$extension}.sys", $source, null, false, true); // Translate component name $item->text = Lang::txt($item->text); } // Sort by component name \Hubzero\Utility\Arr::sortObjects($items, 'text', 1, true, $lang->getLocale()); } return $items; }
/** * Get a list of the authorised, non-special components to display in the components menu. * * @param boolean $authCheck An optional switch to turn off the auth check (to support custom layouts 'grey out' behaviour). * @return array A nest array of component objects and submenus */ public static function getComponents($authCheck = true) { // Initialise variables. $lang = App::get('language'); $user = User::getRoot(); $db = \App::get('db'); $query = $db->getQuery(true); $result = array(); $langs = array(); // Prepare the query. $query->select('m.id, m.title, m.alias, m.link, m.parent_id, m.img, e.element, e.protected'); $query->from('#__menu AS m'); // Filter on the enabled states. $query->leftJoin('#__extensions AS e ON m.component_id = e.extension_id'); $query->where('m.client_id = 1'); $query->where('e.enabled = 1'); $query->where('m.id > 1'); // Order by lft. $query->order('m.lft'); $db->setQuery($query); // Component list $components = $db->loadObjectList(); // Parse the list of extensions. foreach ($components as &$component) { // Trim the menu link. $component->link = trim($component->link); if ($component->parent_id == 1) { // Only add this top level if it is authorised and enabled. if ($authCheck == false || $authCheck && $user->authorise('core.manage', $component->element)) { // Root level. $result[$component->id] = $component; if (!isset($result[$component->id]->submenu)) { $result[$component->id]->submenu = array(); } // If the root menu link is empty, add it in. if (empty($component->link)) { $component->link = 'index.php?option=' . $component->element; } if (!empty($component->element)) { // Load the core file then // Load extension-local file. $lang->load($component->element . '.sys', PATH_APP . '/bootstrap/administrator', null, false, false) || $lang->load($component->element . '.sys', ($component->protected ? PATH_CORE : PATH_APP) . '/components/' . $component->element . '/admin', null, false, false) || $lang->load($component->element . '.sys', PATH_APP . '/bootstrap/administrator', $lang->getDefault(), false, false) || $lang->load($component->element . '.sys', ($component->protected ? PATH_CORE : PATH_APP) . '/components/' . $component->element . '/admin', $lang->getDefault(), false, false); } $component->text = $lang->hasKey($component->title) ? Lang::txt($component->title) : $component->alias; } } else { // Sub-menu level. if (isset($result[$component->parent_id])) { // Add the submenu link if it is defined. if (isset($result[$component->parent_id]->submenu) && !empty($component->link)) { $component->text = $lang->hasKey($component->title) ? Lang::txt($component->title) : $component->alias; $result[$component->parent_id]->submenu[] =& $component; } } } } $result = Arr::sortObjects($result, 'text', 1, true, $lang->getLocale()); return $result; }
/** * Get the child categories. * * @param int An optional category id. If not supplied, the model state 'category.id' will be used. * * @return mixed An array of categories or false if an error occurs. * @since 1.6 */ function &getChildren() { if (!is_object($this->_item)) { $this->getCategory(); } // Order subcategories if (sizeof($this->_children)) { $params = $this->getState()->get('params'); if ($params->get('orderby_pri') == 'alpha' || $params->get('orderby_pri') == 'ralpha') { jimport('joomla.utilities.arrayhelper'); \Hubzero\Utility\Arr::sortObjects($this->_children, 'title', $params->get('orderby_pri') == 'alpha' ? 1 : -1); } } return $this->_children; }
/** * Method to get cache data * * @return array */ public function data() { if (empty($this->data)) { $this->data = array(); $cache = $this->cache(); $data = $cache->all(); if ($data != false) { $this->data = $data; $this->total = count($data); if ($this->total) { // Apply custom ordering $ordering = $this->state('list.ordering'); $direction = $this->state('list.direction') == 'asc' ? 1 : -1; $this->data = \Hubzero\Utility\Arr::sortObjects($data, $ordering, $direction); // Apply custom pagination if ($this->total > $this->state('list.limit') && $this->state('list.limit')) { $this->data = array_slice($this->data, $this->state('list.start'), $this->state('list.limit')); } } } } return $this->data; }
/** * Method to get a list of items. * * @return mixed An array of objects on success, false on failure. */ public function getItems() { // Get the list of items from the database. $items = parent::getItems(); // Initialise variables. $client = \Hubzero\Base\ClientManager::client($this->getState('filter.client_id', 0)); $client->path = PATH_CORE; $lang = Lang::getRoot(); // Loop through the results to add the XML metadata, // and load language support. foreach ($items as &$item) { $path = \Hubzero\Filesystem\Util::normalizePath($client->path . '/modules/' . $item->module . '/' . $item->module . '.xml'); if (file_exists($path)) { $item->xml = simplexml_load_file($path); } else { $item->xml = null; } // 1.5 Format; Core files or language packs then // 1.6 3PD Extension Support $lang->load($item->module . '.sys', PATH_APP . DS . 'bootstrap' . DS . $client->name, null, false, true) || $lang->load($item->module . '.sys', PATH_APP . '/modules/' . $item->module, null, false, true) || $lang->load($item->module . '.sys', $client->path . '/modules/' . $item->module, null, false, true); $item->name = Lang::txt($item->name); if (isset($item->xml) && ($text = trim($item->xml->description))) { $item->desc = Lang::txt($text); } else { $item->desc = Lang::txt('COM_MODULES_NODESCRIPTION'); } } $items = \Hubzero\Utility\Arr::sortObjects($items, 'name', 1, true, $lang->getLocale()); // TODO: Use the cached XML from the extensions table? return $items; }
/** * Get a list of the unique modules installed in the client application. * * @param int The client id. * * @return array */ public static function getModules($clientId) { $db = App::get('db'); $query = $db->getQuery(true); $query->select('element AS value, name AS text'); $query->from('#__extensions as e'); $query->where('e.client_id = ' . (int) $clientId); $query->where('type = ' . $db->quote('module')); $query->leftJoin('#__modules as m ON m.module=e.element AND m.client_id=e.client_id'); $query->where('m.module IS NOT NULL'); $query->group('element,name'); $db->setQuery($query); $modules = $db->loadObjectList(); $lang = Lang::getRoot(); foreach ($modules as $i => $module) { $extension = $module->value; $path = $clientId ? JPATH_ADMINISTRATOR : JPATH_SITE; $source = $path . "/modules/{$extension}"; $lang->load("{$extension}.sys", $path, null, false, true) || $lang->load("{$extension}.sys", $source, null, false, true); $modules[$i]->text = Lang::txt($module->text); } \Hubzero\Utility\Arr::sortObjects($modules, 'text', 1, true, $lang->getLocale()); return $modules; }