Bouncy Melons 0.2
declarative style orm
Filter.php
Go to the documentation of this file.
1 <?php
2 
3 namespace bm;
4 
5 abstract class Filter implements IFilter {
6 
7  const DEFAULT_PAGE = 0;
8  const DEFAULT_ITEMS_PER_PAGE = 50;
9 
15  const INFINITY = -1;
16 
17  protected $page;
18  protected $itemsPerPage;
19  protected $orderBy;
20  protected $groupBy;
21  private $bm;
22 
23 
24  public function __constcruct() {}
25 
26  public function setBm($bm) {
27  $this->bm = $bm;
28  }
29 
30  public function getBm() {
31  return $this->bm;
32  }
33 
34  public function setPage($page = null) {
35  $this->page = $page;
36  }
37 
38  public function getPage() {
39  if($this->page !== null) {
40  return $this->page;
41  }
42  return self::DEFAULT_PAGE;
43  }
44 
45  public function setItemsPerPage($itemsPerPage = null) {
46  $this->itemsPerPage = $itemsPerPage;
47  }
48 
49  public function getItemsPerPage() {
50  if($this->itemsPerPage !== null) {
51  return $this->itemsPerPage;
52  }
53  return $this->getDefaultItemsPerPage();
54  }
55 
59  public function setOrderBy($orderBy) {
60  $this->orderBy = $orderBy;
61  }
62 
63  public function setGroupBy($groupBy) {
64  $this->groupBy = $groupBy;
65  }
66 
70  public function getDefaultItemsPerPage() {
71  return $this->getBm()->getItemsPerPage();
72  }
73 
74  public function createLimit() {
75  $itemsperpage = $this->getItemsPerPage();
76  if($itemsperpage == self::INFINITY) {
77  return "";
78  }
79  $offset = $this->getPage()*$itemsperpage;
80  return $offset.','.$itemsperpage;
81  }
82 
83  public function createOrderBy($fields) {
84  return implode(",",$this->orderBy);
85  }
86 
87  public function createGroupBy() {
88  return implode(",",$this->groupBy);
89  }
90 }
getItemsPerPage()
Definition: Filter.php:49
setOrderBy($orderBy)
Definition: Filter.php:59
__constcruct()
Definition: Filter.php:24
createLimit()
Definition: Filter.php:74
setGroupBy($groupBy)
Definition: Filter.php:63
setBm($bm)
Definition: Filter.php:26
getDefaultItemsPerPage()
Definition: Filter.php:70
createGroupBy()
Definition: Filter.php:87
$itemsPerPage
Definition: Filter.php:18
getPage()
Definition: Filter.php:38
createOrderBy($fields)
Definition: Filter.php:83
setPage($page=null)
Definition: Filter.php:34
getBm()
Definition: Filter.php:30
setItemsPerPage($itemsPerPage=null)
Definition: Filter.php:45