本文整理汇总了PHP中Joomla\Utilities\ArrayHelper::sortObjects方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayHelper::sortObjects方法的具体用法?PHP ArrayHelper::sortObjects怎么用?PHP ArrayHelper::sortObjects使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Joomla\Utilities\ArrayHelper
的用法示例。
在下文中一共展示了ArrayHelper::sortObjects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: mapslist
/**
* Creates a list of maps.
*
* @return array An array containing the maps that can be selected.
*
* @since 2.5
*/
public static function mapslist()
{
$lang = JFactory::getLanguage();
// Load the finder types.
$db = JFactory::getDbo();
$query = $db->getQuery(true)->select($db->quoteName('title', 'text'))->select($db->quoteName('id', 'value'))->from($db->quoteName('#__finder_taxonomy'))->where($db->quoteName('parent_id') . ' = 1');
$db->setQuery($query);
try {
$branches = $db->loadObjectList();
} catch (RuntimeException $e) {
JError::raiseWarning(500, $db->getMessage());
}
// Translate.
foreach ($branches as $branch) {
$key = FinderHelperLanguage::branchPlural($branch->text);
$branch->translatedText = $lang->hasKey($key) ? JText::_($key) : $branch->text;
}
// Order by title.
$branches = ArrayHelper::sortObjects($branches, 'translatedText', 1, true, true);
// Compile the options.
$options = array();
$options[] = JHtml::_('select.option', '', JText::_('COM_FINDER_MAPS_SELECT_BRANCH'));
// Convert the values to options.
foreach ($branches as $branch) {
$options[] = JHtml::_('select.option', $branch->value, $branch->translatedText);
}
return $options;
}
示例2: getOptions
/**
* Method to get the field options.
*
* @return array The field option objects.
*
* @since 3.6.0
*/
public function getOptions()
{
$lang = JFactory::getLanguage();
$options = array();
$db = JFactory::getDbo();
$query = $db->getQuery(true)->select($db->quoteName('id', 'value'))->select($db->quoteName('title', 'text'))->from($db->quoteName('#__finder_types'));
// Get the options.
$db->setQuery($query);
try {
$contentTypes = $db->loadObjectList();
} catch (RuntimeException $e) {
JError::raiseWarning(500, $db->getMessage());
}
// Translate.
foreach ($contentTypes as $contentType) {
$key = FinderHelperLanguage::branchSingular($contentType->text);
$contentType->translatedText = $lang->hasKey($key) ? JText::_($key) : $contentType->text;
}
// Order by title.
$contentTypes = ArrayHelper::sortObjects($contentTypes, 'translatedText', 1, true, true);
// Convert the values to options.
foreach ($contentTypes as $contentType) {
$options[] = JHtml::_('select.option', $contentType->value, $contentType->translatedText);
}
// Merge any additional options in the XML definition.
$options = array_merge(parent::getOptions(), $options);
return $options;
}
示例3: _getList
/**
* Returns an object list
*
* @param string $query The query
* @param int $limitstart Offset
* @param int $limit The number of records
*
* @return array
*/
protected function _getList($query, $limitstart = 0, $limit = 0)
{
$listOrder = $this->getState('list.ordering', 'name');
$listDirn = $this->getState('list.direction', 'asc');
// Replace slashes so preg_match will work
$search = $this->getState('filter.search');
$search = str_replace('/', ' ', $search);
$db = $this->getDbo();
// Define which fields have to be processed in a custom way because of translation.
$customOrderFields = array('name', 'client_translated', 'type_translated', 'folder_translated');
// Process searching, ordering and pagination for fields that need to be translated.
if (in_array($listOrder, $customOrderFields) || !empty($search) && stripos($search, 'id:') !== 0) {
// Get results from database and translate them.
$db->setQuery($query);
$result = $db->loadObjectList();
$this->translate($result);
// Process searching.
if (!empty($search) && stripos($search, 'id:') !== 0) {
$escapedSearchString = $this->refineSearchStringToRegex($search, '/');
// By default search only the extension name field.
$searchFields = array('name');
// If in update sites view search also in the update site name field.
if ($this instanceof InstallerModelUpdatesites) {
$searchFields[] = 'update_site_name';
}
foreach ($result as $i => $item) {
// Check if search string exists in any of the fields to be searched.
$found = 0;
foreach ($searchFields as $key => $field) {
if (!$found && preg_match('/' . $escapedSearchString . '/i', $item->{$field})) {
$found = 1;
}
}
// If search string was not found in any of the fields searched remove it from results array.
if (!$found) {
unset($result[$i]);
}
}
}
// Process ordering.
// Sort array object by selected ordering and selected direction. Sort is case insensative and using locale sorting.
$result = ArrayHelper::sortObjects($result, $listOrder, strtolower($listDirn) == 'desc' ? -1 : 1, false, true);
// Process pagination.
$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);
}
// Process searching, ordering and pagination for regular database fields.
$query->order($db->quoteName($listOrder) . ' ' . $db->escape($listDirn));
$result = parent::_getList($query, $limitstart, $limit);
$this->translate($result);
return $result;
}
示例4: getComponents
/**
* Get a list of the components.
*
* @return array
*
* @since 1.6
*/
public static function getComponents()
{
// Initialise variable.
$db = JFactory::getDbo();
$query = $db->getQuery(true)->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 = JFactory::getLanguage();
foreach ($items as &$item) {
// Load language
$extension = $item->value;
$source = JPATH_ADMINISTRATOR . '/components/' . $extension;
$lang->load("{$extension}.sys", JPATH_ADMINISTRATOR, null, false, true) || $lang->load("{$extension}.sys", $source, null, false, true);
// Translate component name
$item->text = JText::_($item->text);
}
// Sort by component name
$items = ArrayHelper::sortObjects($items, 'text', 1, true, true);
}
return $items;
}
示例5: _getList
/**
* Returns an object list
*
* @param string $query The query
* @param int $limitstart Offset
* @param int $limit The number of records
*
* @return array
*/
protected function _getList($query, $limitstart = 0, $limit = 0)
{
$listOrder = $this->getState('list.ordering', 'name');
$listDirn = $this->getState('list.direction', 'asc');
// Replace slashes so preg_match will work
$search = $this->getState('filter.search');
$search = str_replace('/', ' ', $search);
$db = $this->getDbo();
// Process ordering and pagination.
if (in_array($listOrder, array('name', 'client_translated', 'type_translated', 'folder_translated')) || !empty($search) && stripos($search, 'id:') !== 0) {
$db->setQuery($query);
$result = $db->loadObjectList();
$this->translate($result);
// Search in the name.
if (!empty($search)) {
$escapedSearchString = $this->refineSearchStringToRegex($search, '/');
foreach ($result as $i => $item) {
if (!preg_match("/{$escapedSearchString}/i", $item->name)) {
unset($result[$i]);
}
}
}
// Sort array object by selected ordering and selected direction. Sort is case insensative and using locale sorting.
$result = ArrayHelper::sortObjects($result, $listOrder, strtolower($listDirn) == 'desc' ? -1 : 1, false, true);
$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);
}
$query->order($db->quoteName($listOrder) . ' ' . $db->escape($listDirn));
$result = parent::_getList($query, $limitstart, $limit);
$this->translate($result);
return $result;
}
示例6: getItems
/**
* 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();
$client = JApplicationHelper::getClientInfo($this->getState('client_id', 0));
$lang = JFactory::getLanguage();
// Loop through the results to add the XML metadata,
// and load language support.
foreach ($items as &$item) {
$path = JPath::clean($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', $client->path, null, false, true) || $lang->load($item->module . '.sys', $client->path . '/modules/' . $item->module, null, false, true);
$item->name = JText::_($item->name);
if (isset($item->xml) && ($text = trim($item->xml->description))) {
$item->desc = JText::_($text);
} else {
$item->desc = JText::_('COM_MODULES_NODESCRIPTION');
}
}
$items = ArrayHelper::sortObjects($items, 'name', 1, true, true);
// TODO: Use the cached XML from the extensions table?
return $items;
}
示例7: _getList
/**
* Returns an object list
*
* @param string $query The query
* @param int $limitstart Offset
* @param int $limit The number of records
*
* @return array
*/
protected function _getList($query, $limitstart = 0, $limit = 0)
{
$listOrder = $this->getState('list.ordering', 'a.position');
$listDirn = $this->getState('list.direction', 'asc');
// If ordering by fields that need translate we need to sort the array of objects after translating them.
if (in_array($listOrder, array('pages', 'name'))) {
// Fetch the results.
$this->_db->setQuery($query);
$result = $this->_db->loadObjectList();
// Translate the results.
$this->translate($result);
// Sort the array of translated objects.
$result = ArrayHelper::sortObjects($result, $listOrder, strtolower($listDirn) == 'desc' ? -1 : 1, true, true);
// Process pagination.
$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);
}
// If ordering by fields that doesn't need translate just order the query.
if ($listOrder === 'a.ordering') {
$query->order($this->_db->quoteName('a.position') . ' ASC')->order($this->_db->quoteName($listOrder) . ' ' . $this->_db->escape($listDirn));
} elseif ($listOrder === 'a.position') {
$query->order($this->_db->quoteName($listOrder) . ' ' . $this->_db->escape($listDirn))->order($this->_db->quoteName('a.ordering') . ' ASC');
} else {
$query->order($this->_db->quoteName($listOrder) . ' ' . $this->_db->escape($listDirn));
}
// Process pagination.
$result = parent::_getList($query, $limitstart, $limit);
// Translate the results.
$this->translate($result);
return $result;
}
示例8: getData
/**
* Method to get Languages item data.
*
* @return array
*
* @since 1.6
*/
public function getData()
{
// Fetch language data if not fetched yet.
if (is_null($this->data)) {
$this->data = array();
// Get information.
$db = $this->getDbo();
$query = $db->getQuery(true);
// Select languages installed from the extensions table.
$query->select($db->quoteName(array('a.element', 'a.client_id', 'a.extension_id')))->from($db->quoteName('#__extensions', 'a'))->where($db->quoteName('a.type') . ' = ' . $db->quote('language'))->where($db->quoteName('state') . ' = 0')->where($db->quoteName('enabled') . ' = 1');
// For client_id = 1 do we need to check language table also?
$db->setQuery($query);
$langlist = $db->loadObjectList();
// Compute all the languages.
foreach ($langlist as $lang) {
$client = JApplicationHelper::getClientInfo($lang->client_id);
$clientPath = $lang->client_id === 0 ? JPATH_SITE : JPATH_ADMINISTRATOR;
$info = JApplicationHelper::parseXMLLangMetaFile($clientPath . '/language/' . $lang->element . '/' . $lang->element . '.xml');
$row = new StdClass();
$row->language = $lang->element;
$row->client_id = (int) $lang->client_id;
$row->extension_id = (int) $lang->extension_id;
if (!is_array($info)) {
continue;
}
foreach ($info as $key => $value) {
$row->{$key} = $value;
}
// Fix wrongly set parentheses in RTL languages
if (JFactory::getLanguage()->isRtl()) {
$row->name = html_entity_decode($row->name . '‎', ENT_QUOTES, 'UTF-8');
}
// If current than set published.
$params = JComponentHelper::getParams('com_languages');
if ($params->get($client->name, 'en-GB') == $row->language) {
$row->published = 1;
} else {
$row->published = 0;
}
$row->checked_out = 0;
$this->data[] = $row;
}
}
$installedLanguages = array_merge($this->data);
// Process filters.
$clientId = (int) $this->getState('client_id');
$search = $this->getState('filter.search');
foreach ($installedLanguages as $key => $installedLanguage) {
// Filter by client id.
if (in_array($clientId, array(0, 1))) {
if ($installedLanguage->client_id !== $clientId) {
unset($installedLanguages[$key]);
continue;
}
}
// Filter by search term.
if (!empty($search)) {
if (stripos($installedLanguage->name, $search) === false && stripos($installedLanguage->language, $search) === false) {
unset($installedLanguages[$key]);
continue;
}
}
}
// Process ordering.
$listOrder = $this->getState('list.ordering', 'name');
$listDirn = $this->getState('list.direction', 'ASC');
$installedLanguages = ArrayHelper::sortObjects($installedLanguages, $listOrder, strtolower($listDirn) === 'desc' ? -1 : 1, true, true);
// Process pagination.
$limit = (int) $this->getState('list.limit', 25);
// Sets the total for pagination.
$this->total = count($installedLanguages);
if ($limit !== 0) {
$start = (int) $this->getState('list.start', 0);
return array_slice($installedLanguages, $start, $limit);
}
return $installedLanguages;
}
示例9: getData
/**
* Method to get cache data
*
* @return array
*/
public function getData()
{
if (empty($this->_data)) {
$cache = $this->getCache();
$data = $cache->getAll();
if ($data && count($data) > 0) {
// Process filter by search term.
if ($search = $this->getState('filter.search')) {
foreach ($data as $key => $cacheItem) {
if (stripos($cacheItem->group, $search) === false) {
unset($data[$key]);
continue;
}
}
}
// Process ordering.
$listOrder = $this->getState('list.ordering', 'group');
$listDirn = $this->getState('list.direction', 'ASC');
$this->_data = ArrayHelper::sortObjects($data, $listOrder, strtolower($listDirn) === 'desc' ? -1 : 1, true, true);
// Process pagination.
$limit = (int) $this->getState('list.limit', 25);
if ($limit !== 0) {
$start = (int) $this->getState('list.start', 0);
return array_slice($this->_data, $start, $limit);
}
} else {
$this->_data = array();
}
}
return $this->_data;
}
示例10: getModules
/**
* Get a list of the unique modules installed in the client application.
*
* @param int $clientId The client id.
*
* @return array Array of unique modules
*/
public static function getModules($clientId)
{
$db = JFactory::getDbo();
$query = $db->getQuery(true)->select('element AS value, name AS text')->from('#__extensions as e')->where('e.client_id = ' . (int) $clientId)->where('type = ' . $db->quote('module'))->join('LEFT', '#__modules as m ON m.module=e.element AND m.client_id=e.client_id')->where('m.module IS NOT NULL')->group('element,name');
$db->setQuery($query);
$modules = $db->loadObjectList();
$lang = JFactory::getLanguage();
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 = JText::_($module->text);
}
$modules = ArrayHelper::sortObjects($modules, 'text', 1, true, true);
return $modules;
}
示例11: sortObjects
/**
* Utility function to sort an array of objects on a given field
*
* @param array &$a An array of objects
* @param mixed $k The key (string) or a array of key to sort on
* @param mixed $direction Direction (integer) or an array of direction to sort in [1 = Ascending] [-1 = Descending]
* @param mixed $caseSensitive Boolean or array of booleans to let sort occur case sensitive or insensitive
* @param mixed $locale Boolean or array of booleans to let sort occur using the locale language or not
*
* @return array The sorted array of objects
*
* @since 11.1
* @deprecated 4.0 Use Joomla\Utilities\ArrayHelper::sortObjects instead
*/
public static function sortObjects(&$a, $k, $direction = 1, $caseSensitive = true, $locale = false)
{
if (is_array($a)) {
$a = ArrayHelper::sortObjects($a, $k, $direction, $caseSensitive, $locale);
} else {
JLog::add('This method is typehinted to be an array in \\Joomla\\Utilities\\ArrayHelper::sortObjects.', JLog::WARNING, 'deprecated');
}
return $a;
}
示例12: _getList
/**
* Returns an object list
*
* @param string $query The query
* @param int $limitstart Offset
* @param int $limit The number of records
*
* @return array
*
* @since 3.5
*/
protected function _getList($query, $limitstart = 0, $limit = 0)
{
$db = $this->getDbo();
$listOrder = $this->getState('list.ordering', 'u.name');
$listDirn = $this->getState('list.direction', 'asc');
// Process ordering.
if (in_array($listOrder, array('client_translated', 'folder_translated', 'type_translated'))) {
$db->setQuery($query);
$result = $db->loadObjectList();
$this->translate($result);
$result = ArrayHelper::sortObjects($result, $listOrder, strtolower($listDirn) === 'desc' ? -1 : 1, true, true);
$total = count($result);
if ($total < $limitstart) {
$limitstart = 0;
$this->setState('list.start', 0);
}
return array_slice($result, $limitstart, $limit ? $limit : null);
} else {
$query->order($db->quoteName($listOrder) . ' ' . $db->escape($listDirn));
$result = parent::_getList($query, $limitstart, $limit);
$this->translate($result);
return $result;
}
}
示例13: positions
/**
* Display a batch widget for the module position selector.
*
* @param integer $clientId The client ID.
* @param integer $state The state of the module (enabled, unenabled, trashed).
* @param string $selectedPosition The currently selected position for the module.
*
* @return string The necessary positions for the widget.
*
* @since 2.5
*/
public static function positions($clientId, $state = 1, $selectedPosition = '')
{
JLoader::register('TemplatesHelper', JPATH_ADMINISTRATOR . '/components/com_templates/helpers/templates.php');
$templates = array_keys(ModulesHelper::getTemplates($clientId, $state));
$templateGroups = array();
// Add an empty value to be able to deselect a module position
$option = ModulesHelper::createOption();
$templateGroups[''] = ModulesHelper::createOptionGroup('', array($option));
// Add positions from templates
$isTemplatePosition = false;
foreach ($templates as $template) {
$options = array();
$positions = TemplatesHelper::getPositions($clientId, $template);
if (is_array($positions)) {
foreach ($positions as $position) {
$text = ModulesHelper::getTranslatedModulePosition($clientId, $template, $position) . ' [' . $position . ']';
$options[] = ModulesHelper::createOption($position, $text);
if (!$isTemplatePosition && $selectedPosition === $position) {
$isTemplatePosition = true;
}
}
$options = ArrayHelper::sortObjects($options, 'text');
}
$templateGroups[$template] = ModulesHelper::createOptionGroup(ucfirst($template), $options);
}
// Add custom position to options
$customGroupText = JText::_('COM_MODULES_CUSTOM_POSITION');
$editPositions = true;
$customPositions = ModulesHelper::getPositions($clientId, $editPositions);
$templateGroups[$customGroupText] = ModulesHelper::createOptionGroup($customGroupText, $customPositions);
return $templateGroups;
}
示例14: _getList
/**
* Returns an object list
*
* @param string $query The query
* @param int $limitstart Offset
* @param int $limit The number of records
*
* @return array
*
* @since 3.4
*/
protected function _getList($query, $limitstart = 0, $limit = 0)
{
$ordering = $this->getState('list.ordering', 'name');
$direction = $this->getState('list.direction', 'asc');
$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();
$this->translate($result);
if (!empty($search) && stripos($search, 'id:') !== 0) {
foreach ($result as $i => $item) {
if (!preg_match("/{$search}/i", $item->name) && !preg_match("/{$search}/i", $item->update_site_name)) {
unset($result[$i]);
}
}
}
$result = ArrayHelper::sortObjects($result, $ordering, strtolower($direction) === 'desc' ? -1 : 1, true, true);
$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);
}
$query->order($db->quoteName($ordering) . ' ' . $direction);
$result = parent::_getList($query, $limitstart, $limit);
$this->translate($result);
return $result;
}
示例15: getComponents
/**
* 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
*
* @since 1.6
*/
public static function getComponents($authCheck = true)
{
$lang = JFactory::getLanguage();
$user = JFactory::getUser();
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$result = array();
// Prepare the query.
$query->select('m.id, m.title, m.alias, m.link, m.parent_id, m.img, e.element')->from('#__menu AS m');
// Filter on the enabled states.
$query->join('LEFT', '#__extensions AS e ON m.component_id = e.extension_id')->where('m.client_id = 1')->where('e.enabled = 1')->where('m.id > 1');
// Order by lft.
$query->order('m.lft');
$db->setQuery($query);
// Component list
try {
$components = $db->loadObjectList();
} catch (RuntimeException $e) {
$components = array();
JFactory::getApplication()->enqueueMessage(JText::_('JERROR_AN_ERROR_HAS_OCCURRED'), 'error');
}
// 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', JPATH_BASE, null, false, true) || $lang->load($component->element . '.sys', JPATH_ADMINISTRATOR . '/components/' . $component->element, null, false, true);
}
$component->text = $lang->hasKey($component->title) ? JText::_($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) ? JText::_($component->title) : $component->alias;
$result[$component->parent_id]->submenu[] =& $component;
}
}
}
}
return ArrayHelper::sortObjects($result, 'text', 1, false, true);
}