@@ -21,8 +21,11 @@ discard block |
||
| 21 | 21 | foreach ($fields as $key => $val) { |
| 22 | 22 | $currentFieldResult = $this->getIfFieldMatches($key, $val, $data, $mode); |
| 23 | 23 | |
| 24 | - if (Maphper::FIND_OR & $mode && $currentFieldResult === true) return true; |
|
| 25 | - else if (!(Maphper::FIND_OR & $mode) && $currentFieldResult === false) return false; |
|
| 24 | + if (Maphper::FIND_OR & $mode && $currentFieldResult === true) { |
|
| 25 | + return true; |
|
| 26 | + } else if (!(Maphper::FIND_OR & $mode) && $currentFieldResult === false) { |
|
| 27 | + return false; |
|
| 28 | + } |
|
| 26 | 29 | } |
| 27 | 30 | return !(Maphper::FIND_OR & $mode); |
| 28 | 31 | }; |
@@ -31,22 +34,31 @@ discard block |
||
| 31 | 34 | private function getIfFieldMatches($key, $val, $data, $mode) { |
| 32 | 35 | if (is_numeric($key) && is_array($val)) { |
| 33 | 36 | return $this->getSearchFieldFunction($val, $key)($data); |
| 37 | + } else if (!isset($data->$key)) { |
|
| 38 | + return false; |
|
| 39 | + } else if (!(Maphper::FIND_BETWEEN & $mode) && !is_numeric($key) && is_array($val)) { |
|
| 40 | + return in_array($data->$key, $val); |
|
| 41 | + } else { |
|
| 42 | + return $this->processFilter($mode, $val, $data->$key); |
|
| 34 | 43 | } |
| 35 | - else if (!isset($data->$key)) return false; |
|
| 36 | - else if (!(Maphper::FIND_BETWEEN & $mode) && !is_numeric($key) && is_array($val)) |
|
| 37 | - return in_array($data->$key, $val); |
|
| 38 | - else |
|
| 39 | - return $this->processFilter($mode, $val, $data->$key); |
|
| 40 | 44 | } |
| 41 | 45 | |
| 42 | 46 | private function processFilter($mode, $expected, $actual) { |
| 43 | - if (Maphper::FIND_NOT & $mode) return $expected != $actual; |
|
| 44 | - else if (Maphper::FIND_GREATER & $mode && Maphper::FIND_EXACT & $mode) return $expected <= $actual; |
|
| 45 | - else if (Maphper::FIND_LESS & $mode && Maphper::FIND_EXACT & $mode) return $expected >= $actual; |
|
| 46 | - else if (Maphper::FIND_GREATER & $mode) return $expected < $actual; |
|
| 47 | - else if (Maphper::FIND_LESS & $mode) return $expected > $actual; |
|
| 48 | - else if (Maphper::FIND_BETWEEN & $mode) return $expected[0] <= $actual && $actual <= $expected[1]; |
|
| 49 | - else if (Maphper::FIND_NOCASE & $mode) return strtolower($expected) == strtolower($actual); |
|
| 47 | + if (Maphper::FIND_NOT & $mode) { |
|
| 48 | + return $expected != $actual; |
|
| 49 | + } else if (Maphper::FIND_GREATER & $mode && Maphper::FIND_EXACT & $mode) { |
|
| 50 | + return $expected <= $actual; |
|
| 51 | + } else if (Maphper::FIND_LESS & $mode && Maphper::FIND_EXACT & $mode) { |
|
| 52 | + return $expected >= $actual; |
|
| 53 | + } else if (Maphper::FIND_GREATER & $mode) { |
|
| 54 | + return $expected < $actual; |
|
| 55 | + } else if (Maphper::FIND_LESS & $mode) { |
|
| 56 | + return $expected > $actual; |
|
| 57 | + } else if (Maphper::FIND_BETWEEN & $mode) { |
|
| 58 | + return $expected[0] <= $actual && $actual <= $expected[1]; |
|
| 59 | + } else if (Maphper::FIND_NOCASE & $mode) { |
|
| 60 | + return strtolower($expected) == strtolower($actual); |
|
| 61 | + } |
|
| 50 | 62 | return $expected == $actual; |
| 51 | 63 | } |
| 52 | 64 | } |
@@ -25,8 +25,12 @@ discard block |
||
| 25 | 25 | list($columns, $order) = explode(' ', $options['order']); |
| 26 | 26 | usort($filteredArray, $this->getOrderFunction($order, $columns)); |
| 27 | 27 | } |
| 28 | - if (isset($options['offset'])) $filteredArray = array_slice($filteredArray, $options['offset']); |
|
| 29 | - if (isset($options['limit'])) $filteredArray = array_slice($filteredArray, 0, $options['limit']); |
|
| 28 | + if (isset($options['offset'])) { |
|
| 29 | + $filteredArray = array_slice($filteredArray, $options['offset']); |
|
| 30 | + } |
|
| 31 | + if (isset($options['limit'])) { |
|
| 32 | + $filteredArray = array_slice($filteredArray, 0, $options['limit']); |
|
| 33 | + } |
|
| 30 | 34 | return $filteredArray; |
| 31 | 35 | } |
| 32 | 36 | |
@@ -39,14 +43,15 @@ discard block |
||
| 39 | 43 | } |
| 40 | 44 | |
| 41 | 45 | public function deleteByField(array $fields, array $options) { |
| 42 | - foreach ($this->findByField($fields, $options) as $val) unset($this->data[$val->{$this->id[0]}]); |
|
| 46 | + foreach ($this->findByField($fields, $options) as $val) { |
|
| 47 | + unset($this->data[$val->{$this->id[0]}]); |
|
| 48 | + } |
|
| 43 | 49 | } |
| 44 | 50 | |
| 45 | 51 | public function save($data) { |
| 46 | 52 | if (isset($data->{$this->id[0]})) { |
| 47 | 53 | $id = $data->{$this->id[0]}; |
| 48 | - } |
|
| 49 | - else { |
|
| 54 | + } else { |
|
| 50 | 55 | $id = count($this->data); |
| 51 | 56 | $data->{$this->id[0]} = $id; |
| 52 | 57 | } |
@@ -66,12 +71,16 @@ discard block |
||
| 66 | 71 | if ($aColumn === $bColumn) { |
| 67 | 72 | $sortVal = 0; |
| 68 | 73 | continue; |
| 74 | + } else { |
|
| 75 | + $sortVal = ($aColumn < $bColumn) ? -1 : 1; |
|
| 69 | 76 | } |
| 70 | - else $sortVal = ($aColumn < $bColumn) ? -1 : 1; |
|
| 71 | 77 | break; |
| 72 | 78 | } |
| 73 | - if ($order === 'desc') return -$sortVal; |
|
| 74 | - else return $sortVal; |
|
| 79 | + if ($order === 'desc') { |
|
| 80 | + return -$sortVal; |
|
| 81 | + } else { |
|
| 82 | + return $sortVal; |
|
| 83 | + } |
|
| 75 | 84 | }; |
| 76 | 85 | } |
| 77 | 86 | } |