@@ 130-144 (lines=15) @@ | ||
127 | * @return \Sokil\Mongo\Operator |
|
128 | * @throws \Sokil\Mongo\Exception |
|
129 | */ |
|
130 | public function pushEachSort($field, array $sort) |
|
131 | { |
|
132 | // add modifiers |
|
133 | if (empty($sort)) { |
|
134 | throw new Exception('Sort condition is empty'); |
|
135 | } |
|
136 | ||
137 | if (!isset($this->operators['$push'][$field]['$each'])) { |
|
138 | throw new Exception('Field ' . $field . ' must be pushed with $each modifier'); |
|
139 | } |
|
140 | ||
141 | $this->operators['$push'][$field]['$sort'] = $sort; |
|
142 | ||
143 | return $this; |
|
144 | } |
|
145 | ||
146 | /** |
|
147 | * The $position modifier specifies the location in the array at which |
|
@@ 158-174 (lines=17) @@ | ||
155 | * @return \Sokil\Mongo\Operator |
|
156 | * @throws \Sokil\Mongo\Exception |
|
157 | */ |
|
158 | public function pushEachPosition($field, $position) |
|
159 | { |
|
160 | $position = (int) $position; |
|
161 | ||
162 | // add modifiers |
|
163 | if ($position <= 0) { |
|
164 | throw new Exception('Position must be greater 0'); |
|
165 | } |
|
166 | ||
167 | if (!isset($this->operators['$push'][$field]['$each'])) { |
|
168 | throw new Exception('Field ' . $field . ' must be pushed with $each modifier'); |
|
169 | } |
|
170 | ||
171 | $this->operators['$push'][$field]['$position'] = $position; |
|
172 | ||
173 | return $this; |
|
174 | } |
|
175 | ||
176 | public function addToSet($field, $value) |
|
177 | { |