Maslosoft Mangan API
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
<?php
/**
* This software package is licensed under AGPL or Commercial license.
*
* @package maslosoft/mangan
* @licence AGPL or Commercial
* @copyright Copyright (c) Piotr Masełkowski <pmaselkowski@gmail.com>
* @copyright Copyright (c) Maslosoft
* @copyright Copyright (c) Others as mentioned in code
* @link https://maslosoft.com/mangan/
*/
namespace Maslosoft\Mangan\Interfaces\Criteria;
use Maslosoft\Mangan\Criteria;
use Maslosoft\Mangan\Interfaces\CriteriaInterface;
use Maslosoft\Mangan\Interfaces\SortInterface;
/**
*
* @author Piotr Maselkowski <pmaselkowski at gmail.com>
*/
interface SortableInterface
{
/**
* Add sorting, avaliabe orders are: Criteria::SortAsc and Criteria::SortDesc
* Each call will be groupped with previous calls
* @param string $fieldName
* @param integer $order
* @return Criteria
* @since v1.0
*/
public function sort($fieldName, $order = SortInterface::SortAsc);
/**
* @since v1.0
*/
public function getSort();
/**
* Set sorting of results. Use model field names as keys and Criteria's sort consntants.
*
* Afields will be automatically decorated according to model.
* For instance, when sorting on i18n field simply use field name, without language prefix.
*
* Sort by title example:
* ```php
* $criteria = new Criteria();
* $sort = [
* 'title' => Criteria::SortAsc
* ];
* $criteria->setSort($sort);
* ```
* If title is declared as i18n and language is set to `en`, it will sort by `title.en` ascending in this case.
*
* Subsequent calls to setSort will override existing sort field and add new ones.
*
* Sort by title and then reverse order and add another field example:
* ```php
* $criteria = new Criteria();
* $sort = [
* 'title' => Criteria::SortAsc
* ];
* $criteria->setSort($sort);
* // Override order and add second sort field
* $sort = [
* 'title' => Criteria::SortDesc,
* 'active' => Critera::SortAsc
* ];
* $criteria->setSort($sort);
* ```
* Will sort by title descending, then active ascending
*
* When using `Sort` object as param, it will replace entire sorting
* information with that provided by `Sort` instance.
*
* Sort by title and then replace with `Sort` instance example:
* ```php
* $criteria = new Criteria();
* $sort = [
* 'title' => Criteria::SortAsc
* 'active' => Critera::SortAsc
* ];
* $criteria->setSort($sort);
*
* // Override order completely with new Sort instance
* $sort = new Sort([
* 'title' => Criteria::SortDesc,
* ];
* $criteria->setSort($sort);
* ```
* Will sort by title descending
*
*
* @param mixed[]|SortInterface
* @return CriteriaInterface
*/
public function setSort($sort);
}
API documentation generated by ApiGen