Parses sort fields into an order by clause

@param   array   $sort
@return  string
541003
private function parseSort(array $sort)
    {
        $out = '';
        if (!empty($sort)) {
            $conditions = [];
            foreach ($sort as $field => $direction) {
                $direction = $direction ? 'DESC' : 'ASC';
                $conditions[] = sprintf('%s %s', $field, $direction);
            }
            $out = sprintf(' ORDER BY %s', implode(', ', $conditions));
        }
        return $out;
    }
56888
protected function getOrderBys($order)
    {
        $separatedOrders = [$order];

        if ($this->isMultiOrderQuery($order)) {
            $separatedOrders = explode(',', $order);
        }

        return $separatedOrders;
    }
809038
public function sort($sort, $data) {
		if (count($this->files) == 0) {
			return $this;
		}
		// defines fields list if it's need
		for ($i = 0; $i < count($sort); $i++) {
			$fieldname = $sort[$i]['name'];
			if (!isset($this->files[0][$fieldname])) {
				if (isset($data[$fieldname])) {
					$fieldname = $data[$fieldname]['db_name'];
					$sort[$i]['name'] = $fieldname;
				} else {
					$fieldname = false;
				}
			}
		}

		// for every sorting field will sort
		for ($i = 0; $i < count($sort); $i++) {
			// if field, setted in sort parameter doesn't exist, continue
			if ($sort[$i]['name'] == false) {
				continue;
			}
			// sorting by current field
			$flag = true;
			while ($flag == true) {
				$flag = false;
				// checks if previous sorting fields are equal
				for ($j = 0; $j < count($this->files) - 1; $j++) {
					$equal = true;
					for ($k = 0; $k < $i; $k++) {
						if ($this->files[$j][$sort[$k]['name']] != $this->files[$j + 1][$sort[$k]['name']]) {
							$equal = false;
						}
					}
					// compares two records in list under current sorting field and sorting direction
					if (((($this->files[$j][$sort[$i]['name']] > $this->files[$j + 1][$sort[$i]['name']])&&($sort[$i]['direction'] == 'ASC'))||(($this->files[$j][$sort[$i]['name']] < $this->files[$j + 1][$sort[$i]['name']])&&($sort[$i]['direction'] == 'DESC')))&&($equal == true)) {
						$c = $this->files[$j];
						$this->files[$j] = $this->files[$j+1];
						$this->files[$j+1] = $c;
						$flag = true;
					}
				}
			}
		}
		return $this;
	}
333162
public function actionAll($sort = '')
    {
        $order = ExtHelpers::getOrder($sort, [
            'group_id',
            'name',
            'is_system',
            'note',
            'status'
        ], [], 'group_id DESC');
        $list = DpAdminGroup::getAll($order);

        return [
            'total' => count($list),
            'list' => $list,
        ];
    }
304731
private static function handleSort($query, $sort = null)
    {
        $replace = '';

        if ($sort !== null) {
            $sort ->validate(static::class);

            $tableAttribute = (
                $sort->table === null
                ? $sort->attribute
                : $sort->table . '"."' .$sort->attribute
            );

            $replace = "\n" . sprintf(
                'ORDER BY "%s" %s',
                $tableAttribute,
                ($sort->ascending ? 'ASC' : 'DESC')
            );
        }

        $query = str_replace(
            '{{sort}}',
            $replace,
            $query
        );

        return $query;
    }
1282819
public function sortPrimaryKeys(array $order = null)
    {
        if (!$order) {
            ksort($this->values);

            return;
        }

        $orderedKeys = array_intersect_key(array_flip($order), $this->values);

        $this->values = array_replace($orderedKeys, $this->values);
    }
1332333
protected function parseSorts()
    {
        if ($this->query->has('sort')) {
            $sorts = explode(',', $this->query->getRaw('sort'));

            foreach($sorts as $sort) {
                $this->query->addSort($this->parseSort($sort));
            }
        }
    }
551352
public function getAllSortByQuery($sort, $order = 'DESC')
    {
        $qb = $this->createQueryBuilder('p');
        $qb2 = $this->getEntityManager()->getRepository(PageSnapshot::class)->createQueryBuilder('pp');
        $qb->select('p', 'ps')
            ->leftJoin('p.snapshots', 'ps')
            ->where($qb->expr()->eq(
                'ps.id',
                '('.$qb2->select('MAX(pp.id)')
                    ->where('p.id = pp.page')
                    ->getDQL().')'
            ))
            ->orWhere('ps.id IS NULL')
            ->orderBy('p.'.$sort,  $order);

        return $qb->getQuery();
    }
231028
public function sort(Sorting $sorting)
	{
		if (is_callable($sorting->getSortCallback())) {
			call_user_func(
				$sorting->getSortCallback(),
				$this->criteria,
				$sorting->getSort()
			);

			return $this;
		}

		if ($sort = $sorting->getSort()) {
			$this->criteria->orderBy($sort);
			return $this;
		}

		$this->criteria->orderBy([$this->primary_key => 'ASC']);

		return $this;
	}
517520
public function getSortedFile($sort = true)
    {
        if (!$this->tokens->valid()) {
            $this->logger->info('File is empty.');
        }
        while ($this->tokens->valid()) {
            $this->logger->info('parsing next block');
            $this->parseNextBlock();
        }
        if ($sort) {
            ksort($this->var_blocks);
        }
        $this->var_blocks = array_values($this->var_blocks);
        $blocks = array_merge($this->empty_blocks, $this->var_blocks, $this->end_blocks);

        return implode('', $blocks);
    }
282808
private function appendSort($sort)
    {
        $column = $sort;
        $direction = 'asc';

        if ($sort[0] == '-') {
            $column = substr($sort, 1);
            $direction = 'desc';
        }

        $this->sort[] = [
            'column'    => $column,
            'direction' => $direction,
        ];
    }
1262226
protected static function convertSort($sort)
  {
    /** @var RSort $convertedSort */
    $convertedSort = null;
    if (!empty($sort)) {
      $convertedSort = new RSort();
      $convertedSort->setField($sort->getField());
      switch ($sort->getOrder()) {
        case MSort\Order::Ascending:
          $convertedSort->setOrder(RSort\Order::Ascending);
          break;
        case MSort\Order::Descending:
          $convertedSort->setOrder(RSort\Order::Descending);
          break;
      }
    }
    return $convertedSort;
  }
1288945
public function sort(array $sorts = array())
    {
        if (func_num_args() === 0) {
            return $this->sorts;
        }

        $this->sorts = array();

        foreach ($sorts as $key => $value) {
            if ($key[0] === '$') {
                $key[0] = '_';
            }

            $this->sorts[$key] = $value;
        }

        return $this;
    }
541907
public static function sort($sort) {

        if ( is_array($sort) ) return $sort;

        $__sort = array();
        if ( is_string($sort) && $sort != '' ) {
            $oarr = explode(',', $sort);
            foreach ($oarr as $value) {
                $value = preg_replace('/\s+/', ' ', $value);    //去除多余的空格
                $value = explode(' ', $value);
                if ( strtoupper($value[1]) == "DESC" ) {
                    $__sort[$value[0]] = -1;
                } else {
                    $__sort[$value[0]] = 1;
                }
            }
        }
        return $__sort;
    }
816399
public function orderBy($column = '', $sort = 'desc')
    {
        $column=self::sanitize($column);
        $sort=strtoupper(self::sanitize($sort));

        /*check if the sort method passed is valid */
        if (!(hash_equals('DESC',$sort) || hash_equals('ASC',$sort))){
            static::$response["status"] = "error";
            static::$response["response"] = "The sort order in order by clause is invalid";
            static::$response['code'] = 6050;
            return static::terminate(static::$response);
        }

        if ($this->order == null) {
            $this->order = " ORDER BY $column $sort";
        } else {
            $this->order .= ", $column $sort";
        }
        return $this;
    }
37876
public static function sortProperties(array $contents, $sort)
    {
        switch ($sort) {
            case self::SORT_VISIBILITY:
                /** @var array<array-key, BasicObject[]> Containers to quickly stable sort by type */
                $containers = array(
                    BasicObject::ACCESS_PUBLIC => array(),
                    BasicObject::ACCESS_PROTECTED => array(),
                    BasicObject::ACCESS_PRIVATE => array(),
                    BasicObject::ACCESS_NONE => array(),
                );

                foreach ($contents as $item) {
                    $containers[$item->access][] = $item;
                }

                return \call_user_func_array('array_merge', $containers);
            case self::SORT_FULL:
                \usort($contents, array('Kint\\Renderer\\Renderer', 'sortPropertiesFull'));
                // no break
            default:
                return $contents;
        }
    }
1103826
public function sortBy($array, $field, $order = 'ASC')
    {
        if ($array instanceof Collection) {
            $array = $array->toArray();
        }
        if (1 >= count($array)) {
            return $array;
        }

        usort(
            $array,
            function ($firstElement, $secondElement) use ($field, $order) {
                $accessor = PropertyAccess::createPropertyAccessor();

                $firstProperty = (string)$accessor->getValue($firstElement, $field);
                $secondProperty = (string)$accessor->getValue($secondElement, $field);

                $result = strcasecmp($firstProperty, $secondProperty);
                if ('DESC' === $order) {
                    $result *= -1;
                }

                return $result;
            }
        );

        return $array;
    }