Process the ORDER BY clause

@param $arr
@return string
@throws GQL
776688
private function recordOrder($arr)
    {
        $arr_order_bys = explode(',', $arr['order']);
        foreach($arr_order_bys as $str_order_by) {
            $arr_matches = [];
            preg_match('/\s?(?<field>[^\s]*)\s*(?<dir>ASC|DESC)?/i', $str_order_by, $arr_matches);
            if(isset($arr_matches['field'])) {
                $str_direction = strtoupper(isset($arr_matches['dir']) ? $arr_matches['dir'] : 'ASC');
                if(isset($this->arr_directions[$str_direction])) {
                    $int_direction = $this->arr_directions[$str_direction];
                } else {
                    throw new GQL("Unsupported direction in ORDER BY: [{$arr_matches['dir']}] [{$str_order_by}]");
                }
                $this->arr_order_bys[] = [
                    'property' => $this->lookupToken($arr_matches['field']), // @todo @ lookup
                    'direction' => $int_direction
                ];
            }
        }
        return '';
    }
1006919
private function getSearchQueryOrderBy($query, $orderBy)
	{
		foreach ($orderBy as $key => $value) {
			$query->orderBy($key, $value);
		}

		return $query;
	}
419905
protected function prepare_config( $arr ) {
		$result = [];

		if ( ! is_array( $arr ) ) {
			return $result;
		}

		$arr = array_merge( $this->get_default_config(), $arr );

		foreach ( $arr as $key => $value ) {
			$res          = $this->config( $key );
			$result[$key] = is_null( $res ) ? $value : $res;
		}

		return apply_filters( 'digster/config', $result );
	}
329329
public function ordered($orderBy = 'orderby', $orderDir = 'orderdir')
	{
		// Look for our request vars of interest
		$this->orderBy  = \Request::getCmd($orderBy, $this->getState('orderby', $this->orderBy));
		$this->orderDir = \Request::getCmd($orderDir, $this->getState('orderdir', $this->orderDir));

		$qualifiedOrderBy = $this->orderBy;

		// If we have a '.' we'll assume the prefix is a relationship name
		if (strpos($this->orderBy, '.') !== false)
		{
			list($relationship, $field) = explode('.', $this->orderBy);

			// We have to join to apply the order by clause
			$relationship     = $this->$relationship()->join();
			$qualifiedOrderBy = $relationship->getQualifiedFieldName($field);
		}

		// Apply order clause
		$this->order($qualifiedOrderBy, $this->orderDir);

		// Set state for future use
		$this->setState('orderby', $this->orderBy);
		$this->setState('orderdir', $this->orderDir);

		return $this;
	}
253061
protected function processI(array $result) {
		$entity = df_ic($this->entityC(), O::class, $result); /** @var O $entity */
		$entity->validate();
		return $result;
	}
536773
protected static function get_instances($arr) {
        $result = array();
        foreach ($arr as $key => $sub) {
            $result[$key] = new rule($sub);
        }
        return $result;
    }
401391
public function processResult(array $result) {
        list($result, $isRaw) = array_values($result);

        if(!$isRaw && is_string($result)) {
            return $this->createClone($result);
        }

        return $result;
    }
593478
public function processListQueryOrderBy() {
		if (!empty($this->values['\Object\Form\Model\Dummy\Sort'])) {
			foreach ($this->values['\Object\Form\Model\Dummy\Sort'] as $k => $v) {
				if (!empty($v['__sort'])) {
					$name = $this->detail_fields['\Object\Form\Model\Dummy\Sort']['elements']['__sort']['options']['options'][$v['__sort']]['name'];
					$this->misc_settings['list']['sort'][$name] = $v['__order'];
					$this->query->orderby([$v['__sort'] => $v['__order']]);
				}
			}
		}
	}
1166516
public static function orderBy(): array
    {
        $args = \func_get_args();
        $data = array_shift($args);
        foreach ($args as $n => $field) {
            if (\is_string($field)) {
                $tmp = [];
                foreach ($data as $key => $row) {
                    $tmp[$key] = $row[$field];
                }
                $args[$n] = $tmp;
            }
        }
        $args[] = &$data;
        array_multisort($args);
        return array_pop($args);
    }
1047286
private function _prepareOrderBy(array $orderByArray)
	{
		if(count($orderByArray) === 1)
		{
			foreach($orderByArray as $orderMode => $column)
			{
				$this->orderBy = 'ORDER BY ' . $column->getColumnName() . ' ' . $orderMode . ' ';
			}
		}
	}
295967
public function execute($sql, $arr = [])
    {
        $this->sql = $sql;
        $sth       = $this->pdo->prepare($sql);
        try {
            $sth->execute($arr);
        } catch (\PDOException $e) {
            $this->errorInfo($sql, $e->getMessage());
            throw $e;
        }
        $count = $sth->rowCount();

        return $count;
    }
1129612
private function _formatOrder()
    {
        $orders = array();

        if (isset($this->_order[DbInterface::ORDER_RAND])) {
            $orders[] = 'RAND()';
        } else {
            foreach ($this->_order as $field => $order) {
                $orders[] = "`$field` $order";
            }
        }

        return ' ORDER BY ' . implode(', ', $orders);
    }
677465
public function fetchByNames(array $arr_names)
    {
        return $this->obj_gateway
            ->withSchema($this->obj_schema)
            ->withTransaction($this->str_transaction_id)
            ->fetchByNames($arr_names);
    }
986526
public function getOrderBy()
    {
        $orderby = $this->orderby;
        if (!$orderby) {
            $orderby = array();
        }

        if (!is_array($orderby)) {
            // spilt by any commas not within brackets
            $orderby = preg_split('/,(?![^()]*+\\))/', $orderby);
        }

        foreach ($orderby as $k => $v) {
            if (strpos($v, ' ') !== false) {
                unset($orderby[$k]);

                $rule = explode(' ', trim($v));
                $clause = $rule[0];
                $dir = (isset($rule[1])) ? $rule[1] : 'ASC';

                $orderby[$clause] = $dir;
            }
        }

        return $orderby;
    }
960503
final function Query($qry)
    {
        $GLOBALS['qry_count']++;
        $GLOBALS['qry'].=$GLOBALS['qry_count'].':'.$qry."\n";

        $this->last_query = $qry;

        $this->query_result = $this->ExecQuery($qry);

        if ($this->query_result) {
            $this->SetQuerySummary();
            return $this->query_result;
        }

        $this->SetErrCode();
        if (!$this->show_errors) {
            $this->WriteError($this->GetErr());
        }

        return false;
    }
598544
public function sortArrayByColumn(&$arr, $col)
    {
        $newArray = [];
        $sort_col = array();
        foreach ($arr as $key => $row) {
            $sort_col[$key] = strtoupper($row[$col]);
        }
        asort($sort_col, SORT_LOCALE_STRING);

        foreach ($sort_col as $key => $val) {
            $newArray[$key] = $arr[$key];
        }

        $arr = $newArray;
    }
1124080
public static function arrayKeyUpper($arr)
    {
        return array_map(function($item){
            if(is_array($item)) {
                $item = self::arrayKeyUpper($item);
            }
            return $item;
        },array_change_key_case($arr,CASE_UPPER));
    }