Пример #1
0
 /**
  * @param SortField $sortField
  * @param SortOrder|null $sortOrder
  * @return SearchOptions
  */
 public function withSorting(SortField $sortField, SortOrder $sortOrder = null)
 {
     if (is_null($sortOrder)) {
         $sortOrder = SortOrder::ASC();
     }
     $c = clone $this;
     $c->sortField = $sortField;
     $c->sortOrder = $sortOrder;
     return $c;
 }
 /**
  * @return array
  */
 public function searchOptionsDataProvider()
 {
     return [[(new SearchOptions())->withPage(new Integer(2)), ['page' => 2]], [(new SearchOptions())->withLimit(new Integer(50)), ['perpage' => 50]], [(new SearchOptions())->withQuery(new Query('Vindicator')), ['query' => 'Vindicator']], [(new SearchOptions())->withSorting(SortField::VALUE(), SortOrder::DESC()), ['sortorder' => 'value_desc']], [(new SearchOptions())->withDetails(), ['moredetailed' => true]], [(new SearchOptions())->withPage(new Integer(2))->withLimit(new Integer(50))->withQuery(new Query('Vindicator'))->withSorting(SortField::DISPLAY_NAME(), SortOrder::DESC())->withDetails(), ['page' => 2, 'perpage' => 50, 'query' => 'Vindicator', 'sortorder' => 'display_name_desc', 'moredetailed' => true]]];
 }
Пример #3
0
         $errors[] = 'Please enter (part of) an item name.';
     } else {
         $query = new Query($value);
         $searchOptions = $searchOptions->withQuery($query);
     }
     break;
 case 'sortField':
     try {
         $sortField = SortField::fromNative($value);
     } catch (\InvalidArgumentException $e) {
         $errors[] = 'Please select a valid sort field.';
     }
     break;
 case 'sortOrder':
     try {
         $sortOrder = SortOrder::fromNative($value);
     } catch (\InvalidArgumentException $e) {
         $errors[] = 'Please select a valid sort order.';
     }
     break;
 case 'limit':
     $value = (int) $value;
     if ($value < 1 || $value > 30) {
         $errors[] = 'Please select an amount of items between 1 and 30.';
     } else {
         $limit = new Integer($value);
         $searchOptions = $searchOptions->withLimit($limit);
     }
     break;
 case 'page':
     $value = (int) $value;