Scalr\UI\Utils::convertOrder PHP Method

convertOrder() public static method

Convert extjs-coded order value to AbstractEntity::find format
public static convertOrder ( JsonData $order, array $default = [], array $allowed = [] ) : array
$order Scalr\UI\Request\JsonData
$default array
$allowed array
return array
    public static function convertOrder(JsonData $order, array $default = [], array $allowed = [])
    {
        $result = [];
        foreach ($order as $param) {
            if (isset($param['property']) && isset($param['direction']) && $param['property'] && in_array($param['property'], $allowed)) {
                $direction = strtolower($param['direction']);
                $result[$param['property']] = $direction == 'asc';
            }
        }
        return empty($result) ? $default : $result;
    }

Usage Example

Example #1
0
 /**
  * @param string $query
  * @param string $platform
  * @param string $cloudLocation
  * @param JsonData $sort
  * @param int $start
  * @param int $limit
  * @throws Exception
  */
 public function xListAction($query = null, $platform = null, $cloudLocation = null, JsonData $sort, $start = 0, $limit = 20)
 {
     $this->request->restrictAccess(Acl::RESOURCE_FARMS_ROLES);
     $criteria = [];
     $criteria[] = ['envId' => $this->getEnvironmentId()];
     if ($query) {
         $querySql = '%' . $query . '%';
         $criteria[] = ['$or' => [['id' => ['$like' => $querySql]]]];
     }
     if ($platform) {
         $criteria[] = ['platform' => $platform];
     }
     if ($cloudLocation) {
         $criteria[] = ['cloudLocation' => $cloudLocation];
     }
     $result = Image::find($criteria, \Scalr\UI\Utils::convertOrder($sort, ['id' => 'ASC'], ['id', 'platform', 'cloudLocation', 'os', 'dtAdded', 'architecture', 'source']), $limit, $start, true);
     $data = [];
     foreach ($result as $image) {
         /* @var Image $image */
         $s = get_object_vars($image);
         $s['dtAdded'] = Scalr_Util_DateTime::convertTz($image->dtAdded);
         $s['status'] = $image->isUsed() ? 'In use' : 'Not used';
         $data[] = $s;
     }
     $this->response->data(['total' => $result->totalNumber, 'data' => $data]);
 }
All Usage Examples Of Scalr\UI\Utils::convertOrder