@@ -6,9 +6,9 @@ discard block |
||
| 6 | 6 | protected $collection; |
| 7 | 7 | protected $namespace; |
| 8 | 8 | |
| 9 | - public function __construct($collection, $collection_name=false) |
|
| 9 | + public function __construct($collection, $collection_name = false) |
|
| 10 | 10 | { |
| 11 | - if($collection_name !== false) |
|
| 11 | + if ($collection_name !== false) |
|
| 12 | 12 | { |
| 13 | 13 | $this->namespace = $collection.'.'.$collection_name; |
| 14 | 14 | } |
@@ -18,12 +18,12 @@ discard block |
||
| 18 | 18 | } |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | - public function count($filter=false) |
|
| 21 | + public function count($filter = false) |
|
| 22 | 22 | { |
| 23 | 23 | $criteria = array(); |
| 24 | - if($filter !== false) |
|
| 24 | + if ($filter !== false) |
|
| 25 | 25 | { |
| 26 | - if($filter instanceof \Data\Filter) |
|
| 26 | + if ($filter instanceof \Data\Filter) |
|
| 27 | 27 | { |
| 28 | 28 | $criteria = $filter->to_mongo_filter(); |
| 29 | 29 | } |
@@ -37,44 +37,44 @@ discard block |
||
| 37 | 37 | |
| 38 | 38 | private function getCriteriaFromFilter($filter) |
| 39 | 39 | { |
| 40 | - if($filter === false) |
|
| 40 | + if ($filter === false) |
|
| 41 | 41 | { |
| 42 | 42 | return array(); |
| 43 | 43 | } |
| 44 | - if(is_array($filter)) |
|
| 44 | + if (is_array($filter)) |
|
| 45 | 45 | { |
| 46 | 46 | return $filter; |
| 47 | 47 | } |
| 48 | 48 | return $filter->to_mongo_filter(); |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - public function search($filter=false, $select=false, $count=false, $skip=false, $sort=false, $params=false) |
|
| 51 | + public function search($filter = false, $select = false, $count = false, $skip = false, $sort = false, $params = false) |
|
| 52 | 52 | { |
| 53 | 53 | $fields = array(); |
| 54 | 54 | $criteria = $this->getCriteriaFromFilter($filter); |
| 55 | - if($select !== false) |
|
| 55 | + if ($select !== false) |
|
| 56 | 56 | { |
| 57 | 57 | $fields = array_fill_keys($select, 1); |
| 58 | 58 | } |
| 59 | - $cursor = $this->collection->find($criteria, $fields); |
|
| 60 | - if($params !== false && isset($params['fields'])) |
|
| 59 | + $cursor = $this->collection->find($criteria, $fields); |
|
| 60 | + if ($params !== false && isset($params['fields'])) |
|
| 61 | 61 | { |
| 62 | 62 | $cursor->fields($params['fields']); |
| 63 | 63 | } |
| 64 | - if($sort !== false) |
|
| 64 | + if ($sort !== false) |
|
| 65 | 65 | { |
| 66 | 66 | $cursor->sort($sort); |
| 67 | 67 | } |
| 68 | - if($skip !== false) |
|
| 68 | + if ($skip !== false) |
|
| 69 | 69 | { |
| 70 | 70 | $cursor->skip($skip); |
| 71 | 71 | } |
| 72 | - if($count !== false) |
|
| 72 | + if ($count !== false) |
|
| 73 | 73 | { |
| 74 | 74 | $cursor->limit($count); |
| 75 | 75 | } |
| 76 | - $ret = array(); |
|
| 77 | - foreach($cursor as $doc) |
|
| 76 | + $ret = array(); |
|
| 77 | + foreach ($cursor as $doc) |
|
| 78 | 78 | { |
| 79 | 79 | array_push($ret, $doc); |
| 80 | 80 | } |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | public function create($data) |
| 85 | 85 | { |
| 86 | 86 | $res = $this->collection->insert($data); |
| 87 | - if($res === false || $res['err'] !== null) |
|
| 87 | + if ($res === false || $res['err'] !== null) |
|
| 88 | 88 | { |
| 89 | 89 | return false; |
| 90 | 90 | } |
@@ -94,12 +94,12 @@ discard block |
||
| 94 | 94 | public function update($filter, $data) |
| 95 | 95 | { |
| 96 | 96 | $criteria = $this->getCriteriaFromFilter($filter); |
| 97 | - if(isset($data['_id'])) |
|
| 97 | + if (isset($data['_id'])) |
|
| 98 | 98 | { |
| 99 | 99 | unset($data['_id']); |
| 100 | 100 | } |
| 101 | 101 | $res = $this->collection->update($criteria, array('$set' => $data)); |
| 102 | - if($res === false || $res['err'] !== null) |
|
| 102 | + if ($res === false || $res['err'] !== null) |
|
| 103 | 103 | { |
| 104 | 104 | return false; |
| 105 | 105 | } |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | { |
| 111 | 111 | $criteria = $this->getCriteriaFromFilter($filter); |
| 112 | 112 | $res = $this->collection->remove($criteria); |
| 113 | - if($res === false || $res['err'] !== null) |
|
| 113 | + if ($res === false || $res['err'] !== null) |
|
| 114 | 114 | { |
| 115 | 115 | return false; |
| 116 | 116 | } |
@@ -11,8 +11,7 @@ discard block |
||
| 11 | 11 | if($collection_name !== false) |
| 12 | 12 | { |
| 13 | 13 | $this->namespace = $collection.'.'.$collection_name; |
| 14 | - } |
|
| 15 | - else |
|
| 14 | + } else |
|
| 16 | 15 | { |
| 17 | 16 | $this->collection = $collection; |
| 18 | 17 | } |
@@ -26,8 +25,7 @@ discard block |
||
| 26 | 25 | if($filter instanceof \Data\Filter) |
| 27 | 26 | { |
| 28 | 27 | $criteria = $filter->to_mongo_filter(); |
| 29 | - } |
|
| 30 | - else |
|
| 28 | + } else |
|
| 31 | 29 | { |
| 32 | 30 | $criteria = $filter; |
| 33 | 31 | } |