Bouncy Melons 0.1
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 
10  protected $page;
11  protected $itemsPerPage;
12  protected $orderBy;
13  protected $groupBy;
14 
15 
16  public function __constcruct() {}
17 
18  public function setPage($page = null) {
19  $this->page = $page;
20  }
21 
22  public function getPage() {
23  if($this->page !== null) {
24  return $this->page;
25  }
26  return self::DEFAULT_PAGE;
27  }
28 
29  public function setItemsPerPage($itemsPerPage = null) {
30  $this->itemsPerPage = $itemsPerPage;
31  }
32 
33  public function getItemsPerPage() {
34  if($this->itemsPerPage !== null) {
35  return $this->itemsPerPage;
36  }
37  return $this->getDefaultItemsPerPage();
38  }
39 
43  public function setOrderBy($orderBy) {
44  $this->orderBy = $orderBy;
45  }
46 
47  public function setGroupBy($groupBy) {
48  $this->groupBy = $groupBy;
49  }
50 
54  public function getDefaultItemsPerPage() {
55  return self::DEFAULT_ITEMS_PER_PAGE;
56  }
57 
58  public function createLimit() {
59  $itemsperpage = $this->getItemsPerPage();
60  $offset = $this->getPage()*$itemsperpage;
61  return $offset.','.$itemsperpage;
62  }
63 
64  public function createOrderBy($fields) {
65  return implode(",",$this->orderBy);
66  }
67 
68  public function createGroupBy() {
69  return implode(",",$this->groupBy);
70  }
71 }
getItemsPerPage()
Definition: Filter.php:33
setOrderBy($orderBy)
Definition: Filter.php:43
__constcruct()
Definition: Filter.php:16
createLimit()
Definition: Filter.php:58
setGroupBy($groupBy)
Definition: Filter.php:47
getDefaultItemsPerPage()
Definition: Filter.php:54
createGroupBy()
Definition: Filter.php:68
$itemsPerPage
Definition: Filter.php:11
getPage()
Definition: Filter.php:22
createOrderBy($fields)
Definition: Filter.php:64
setPage($page=null)
Definition: Filter.php:18
setItemsPerPage($itemsPerPage=null)
Definition: Filter.php:29