| @@ 215-245 (lines=31) @@ | ||
| 212 | /** |
|
| 213 | * {@inheritdoc} |
|
| 214 | */ |
|
| 215 | public function saveWatch(array $data) |
|
| 216 | { |
|
| 217 | if (empty($data['name'])) { |
|
| 218 | return false; |
|
| 219 | } |
|
| 220 | ||
| 221 | if (!empty($data['removed']) && isset($data['_id'])) { |
|
| 222 | $this->_watches->remove( |
|
| 223 | array('_id' => new MongoId($data['_id'])), |
|
| 224 | array('w' => 1) |
|
| 225 | ); |
|
| 226 | return true; |
|
| 227 | } |
|
| 228 | ||
| 229 | if (empty($data['_id'])) { |
|
| 230 | $this->_watches->insert( |
|
| 231 | $data, |
|
| 232 | array('w' => 1) |
|
| 233 | ); |
|
| 234 | return true; |
|
| 235 | } |
|
| 236 | ||
| 237 | ||
| 238 | $data['_id'] = new MongoId($data['_id']); |
|
| 239 | $this->_watches->update( |
|
| 240 | array('_id' => $data['_id']), |
|
| 241 | $data, |
|
| 242 | array('w' => 1) |
|
| 243 | ); |
|
| 244 | return true; |
|
| 245 | } |
|
| 246 | ||
| 247 | /** |
|
| 248 | * {@inheritdoc} |
|
| @@ 20-50 (lines=31) @@ | ||
| 17 | * @param array $data The data to save. |
|
| 18 | * @return boolean |
|
| 19 | */ |
|
| 20 | public function save($data) |
|
| 21 | { |
|
| 22 | if (empty($data['name'])) { |
|
| 23 | return false; |
|
| 24 | } |
|
| 25 | ||
| 26 | if (!empty($data['removed']) && isset($data['_id'])) { |
|
| 27 | $this->_collection->remove( |
|
| 28 | array('_id' => new MongoId($data['_id'])), |
|
| 29 | array('w' => 1) |
|
| 30 | ); |
|
| 31 | return true; |
|
| 32 | } |
|
| 33 | ||
| 34 | if (empty($data['_id'])) { |
|
| 35 | $this->_collection->insert( |
|
| 36 | $data, |
|
| 37 | array('w' => 1) |
|
| 38 | ); |
|
| 39 | return true; |
|
| 40 | } |
|
| 41 | ||
| 42 | ||
| 43 | $data['_id'] = new MongoId($data['_id']); |
|
| 44 | $this->_collection->update( |
|
| 45 | array('_id' => $data['_id']), |
|
| 46 | $data, |
|
| 47 | array('w' => 1) |
|
| 48 | ); |
|
| 49 | return true; |
|
| 50 | } |
|
| 51 | ||
| 52 | /** |
|
| 53 | * Get all the known watch functions. |
|