This formats the orderBy array to ignore case differences between the orderBy name and the actually selected name,
such as for sorting arrays.

@param $selected
@param $aliases
@return array
164758
protected function getFormattedOrderBy($selected, $aliases)
    {
        if (!empty($aliases) && !$this->isWildCardSelection()) {
            $orderBy = [];
            foreach ($this->orderBy as $attribute => $direction) {
                list($alias, $attr) = LdapUtilities::getAliasAndAttribute($attribute);
                $orderAttr = AttributeNameResolver::arraySearchGetValue($attr, $selected);
                $orderAttr = $alias ? "$alias.$orderAttr" : $orderAttr;
                $orderBy[$orderAttr] = $direction;
            }
        } else {
            $orderBy = $this->orderBy;
        }

        return $orderBy;
    }
999106
private function buildSelectColumns()
    {
        $columns = array();

        foreach ($this->query['select'] as $column => $as) {
            // Normal column select
            if (is_numeric($column)) {
                $columns[] = $this->columnName($as);
            }
            // Alias
            else {
                $columns[] = $this->columnName($column) . " AS `{$as}`";
            }
        }

        // Join columns and return
        return implode(', ', $columns);
    }
844966
public function hasJoin($aliasOrTable)
    {
        if ($this->join) {
            foreach ($this->join as $join) {
                $secondJoinParam = $join[1];
                if (is_array($secondJoinParam)) {
                    list($key, $val) = each($secondJoinParam);
                    if ($key == $aliasOrTable) {
                        return true;
                    }
                }
                if (is_string($secondJoinParam)) {
                    if ($secondJoinParam == $aliasOrTable) {
                        return true;
                    } else {
                        $pos = strrpos($secondJoinParam, ' ');
                        if ($pos) {
                            $alias = substr($secondJoinParam, $pos);
                            $alias = trim($alias, " \t`");
                            $table = substr($secondJoinParam, 0, $pos);
                            $table = trim($table);

                            if ($alias == $aliasOrTable || $table == $aliasOrTable) {
                                return true;
                            }
                        }
                    }
                }
            }
        }
        return false;
    }
514740
public function addAlias($aliases)
    {
        if (! is_array($aliases)) {
            $aliases = func_get_args();
        }

        foreach ($aliases as $alias) {
            $this->aliases[] = $alias;
        }

        return $this;
    }
153415
protected function getExpressionInSelect(Select $select, string $tableAlias) : Expr
    {
        return $this->loadExpressionWithNecessarySubselects($select, $tableAlias, function (Select $select, $tableAlias) {
            return $this->getSingleValueExpressionInSelect($select, $tableAlias);
        });
    }
1285511
protected function mergeOrderByAttributes(array $attributes, $alias = null)
    {
        if (!$this->isWildCardSelection() && !empty($this->orderBy)) {
            $orderBy = $this->getAttributesForAlias(array_keys($this->orderBy), $alias);
            $lcAttributes = array_map('strtolower', $attributes);
            foreach ($orderBy as $attribute) {
                if (!in_array(strtolower($attribute), $lcAttributes)) {
                    $attributes[] = $attribute;
                }
            }
        }

        return $attributes;
    }
841260
protected function get_component_select_sql($alias = '') {
        $component = $this->get_component();
        if ($alias) {
            $alias = $alias.'.';
        }
        if (empty($component)) {
            $componentwhere = "{$alias}component IS NULL";
            $component = null;
        } else {
            $componentwhere = "({$alias}component IS NULL OR {$alias}component = :component)";
        }
        return array($componentwhere, $component);
    }
631902
public function buildOrderBy(array $fields)
    {
        $this->parseSelectPath();
        foreach ($fields as $field) {
            if (!is_array($field)) {
                $field = [$field];
            }
            $property = array_shift($field);
            if (!in_array($property, $this->aliasMapping) && isset($this->aliasMapping[$property])) {
                $property = $this->aliasMapping[$property];
            }
            $direction = $field ? array_shift($field) : 'ASC';
            $function = $field ? array_shift($field) : null;
            if ($function) {
                $property = sprintf("%s(%s)", $function, $property);
            }
            $this->addOrderBy($property, $direction);
        }

        return $this;
    }
1307996
public function selectJoin(
        $first = 0,
        $max = 20,
        array $filters = [],
        array $joins = [],
        array $orderBy = [],
        array $groupBy = []
    ) {
        $selection = $this->getEntityManager()->createQueryBuilder();
        $aliases = [];
        $aliases[] = $this->entityAlias;
        foreach ($joins as $table => $attributes) {
            $aliases[] = $attributes['alias'];
        }
        $selection->select($aliases)
            ->from($this->entityClass, $this->entityAlias);
        foreach ($joins as $table => $attributes) {
            $selection->Join(
                $table,
                $attributes['alias'],
                \Doctrine\ORM\Query\Expr\Join::WITH,
                "{$attributes['main_table_field']} = {$attributes['alias']}.{$attributes['join_table_field']}"
            );
        }
        return $this->filterFurther($filters, $orderBy, $groupBy, $selection, 0, 0);
    }
573697
public function registerAliases(array $aliases)
    {

        foreach ($aliases as $alias => $className)
            $this->registerAlias($alias, $className);

        return $this;
    }
244137
public function alias($alias)
    {
        if (is_array($alias)) {
            foreach ($alias as $key => $val) {
                $this->options['alias'][$key] = $val;
            }
        } else {
            if (isset($this->options['table'])) {
                $table = is_array($this->options['table']) ? key($this->options['table']) : $this->options['table'];
                if (false !== strpos($table, '__')) {
                    $table = $this->parseSqlTable($table);
                }
            } else {
                $table = $this->getTable();
            }

            $this->options['alias'][$table] = $alias;
        }
        return $this;
    }
489023
public function selectConcat(array $columns, string $delimiter = '', ?string $alias = null)
    {
        $instance = $this->selectQueryInstance();

        $instance->selectQuery()->columnConcat($columns, $delimiter, $alias);

        return $instance;
    }
281914
public static function setAliases(array $aliases)
    {
        foreach ($aliases as $name => $path) {
            self::setAlias($name, $path);
        }
    }
236821
protected function addOrderBy(QueryBuilder $queryBuilder, $alias, array $sortBy = [])
    {
        foreach ($sortBy as $field => $order) {
            // if no relation is defined add alias by default
            if (false === strpos($field, '.')) {
                $field = $alias . '.' . $field;
            }

            $queryBuilder->addOrderBy($field, $order);
        }
    }
926970
public function orderBy($columns, $order = 'ASC', $nulls = null)
    {
        return $this->buildSelect()->orderBy($columns, $order, $nulls);
    }
1150454
public function prioritylist($selected = null)
    {
        $html = $this->_template->getHelper('html');

        if (!$selected) {
            $selected = ComTodosDomainEntityTodo::PRIORITY_NORMAL;
        }

        $options = array(
            array(ComTodosDomainEntityTodo::PRIORITY_HIGHEST,    AnTranslator::_('COM-TODOS-TODO-PRIORITY-HIGHEST')),
            array(ComTodosDomainEntityTodo::PRIORITY_HIGH,        AnTranslator::_('COM-TODOS-TODO-PRIORITY-HIGH')),
            array(ComTodosDomainEntityTodo::PRIORITY_NORMAL,    AnTranslator::_('COM-TODOS-TODO-PRIORITY-NORMAL')),
            array(ComTodosDomainEntityTodo::PRIORITY_LOW,        AnTranslator::_('COM-TODOS-TODO-PRIORITY-LOW')),
            array(ComTodosDomainEntityTodo::PRIORITY_LOWEST,    AnTranslator::_('COM-TODOS-TODO-PRIORITY-LOWEST')),
        );

        return $html->select('priority', array('options' => $options, 'selected' => $selected))->class('input-medium')->id('todo-priority');
    }
510260
protected function getChoiceBySelection($selection)
    {
        preg_match('/^[^(]+\(([^\)]+)\)$/', $selection, $matches);
        if (count($matches) < 2) {
            return;
        }
        $username = $matches[1];
        foreach ($this->choices as $item) {
            if ($item->getUsername() === $username) {
                return $item;
            }
        }

        return;
    }