src/FMT/Data/Model/BaseFilterOptions.php line 11

Open in your IDE?
  1. <?php
  2. namespace FMT\Data\Model;
  3. use FMT\Data\Entity\UserMajor;
  4. /**
  5.  * Class BaseFilterOptions
  6.  * @package FMT\Data\Model
  7.  */
  8. class BaseFilterOptions
  9. {
  10.     const SORT_DIRECTION = [
  11.         'DESC' => 'fmt.form.filter.sort_desc',
  12.         'ASC' => 'fmt.form.filter.sort_asc',
  13.     ];
  14.     const RECORDS_LIMIT = [
  15.         '20' => 20,
  16.         '50' => 50,
  17.         '100' => 100,
  18.         '500' => 500,
  19.         '1000' => 1000,
  20.         'all' => 'fmt.form.filter.all',
  21.     ];
  22.     const DEFAULT_ALL_RECORDS_PER_PAGE 99999999;
  23.     /**
  24.      * @var UserMajor
  25.      */
  26.     protected $major;
  27.     /**
  28.      * @var array
  29.      */
  30.     protected $sortBy;
  31.     /**
  32.      * @var string
  33.      */
  34.     protected $sortDirection;
  35.     /**
  36.      * @var integer
  37.      */
  38.     protected $limit;
  39.     /**
  40.      * @var string
  41.      */
  42.     protected $search;
  43.     /**
  44.      * @var string
  45.      */
  46.     protected $firstgen;
  47.     /**
  48.      * @return string
  49.      */
  50.     public function getFirstgen()
  51.     {
  52.         return $this->firstgen;
  53.     }
  54.     /**
  55.      * @param $firstgen
  56.      * @return $this
  57.      */
  58.     public function setFirstgen($firstgen)
  59.     {
  60.         $this->firstgen $firstgen;
  61.         return $this;
  62.     }
  63.     /**
  64.      * @return mixed
  65.      */
  66.     public function getMajor()
  67.     {
  68.         return $this->major;
  69.     }
  70.     /**
  71.      * @param $major
  72.      * @return $this
  73.      */
  74.     public function setMajor($major)
  75.     {
  76.         $this->major $major;
  77.         return $this;
  78.     }
  79.     /**
  80.      * @return array
  81.      */
  82.     public function getSortBy()
  83.     {
  84.         return $this->sortBy;
  85.     }
  86.     /**
  87.      * @param $sortBy
  88.      * @return $this
  89.      */
  90.     public function setSortBy($sortBy)
  91.     {
  92.         $this->sortBy explode(','$sortBy);
  93.         return $this;
  94.     }
  95.     /**
  96.      * @return mixed
  97.      */
  98.     public function getSortDirection()
  99.     {
  100.         return $this->sortDirection;
  101.     }
  102.     /**
  103.      * @param $sortDirection
  104.      * @return $this
  105.      */
  106.     public function setSortDirection($sortDirection)
  107.     {
  108.         $this->sortDirection $sortDirection;
  109.         return $this;
  110.     }
  111.     /**
  112.      * @return mixed
  113.      */
  114.     public function getLimit()
  115.     {
  116.         return $this->limit;
  117.     }
  118.     /**
  119.      * @param $limit
  120.      * @return $this
  121.      */
  122.     public function setLimit($limit)
  123.     {
  124.         $this->limit $limit;
  125.         return $this;
  126.     }
  127.     /**
  128.      * @return mixed
  129.      */
  130.     public function getSearch()
  131.     {
  132.         return $this->search;
  133.     }
  134.     /**
  135.      * @param $search
  136.      * @return $this
  137.      */
  138.     public function setSearch($search)
  139.     {
  140.         $this->search $search;
  141.         return $this;
  142.     }
  143.     /**
  144.      * @return int
  145.      */
  146.     public function getFilterLimit()
  147.     {
  148.         $limits self::RECORDS_LIMIT;
  149.         if (is_numeric($this->getLimit()) && in_array($this->getLimit(), $limits)) {
  150.             return $this->getLimit();
  151.         }
  152.         if (is_string($this->getLimit()) && $this->getLimit() == 'all') {
  153.             return self::DEFAULT_ALL_RECORDS_PER_PAGE;
  154.         }
  155.         return (int)array_shift($limits);
  156.     }
  157. }