You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
<?php
/** * Класс модели данных * * @copyright NetMonsters <team@netmonsters.ru> * @link http://netmonsters.ru * @package Majestic * @subpackage Model * @since 2011-11-15 */
abstract class MongoModel extends Model {
public function count($query = array(), $limit = 0, $skip = 0) { return $this->db->count($this->table(), $query, $limit, $skip); }
public function find($condition = array()) { return $this->db->find($this->table(), $condition); }
public function get($id) { return $this->db->get($this->table(), array('_id' => $id))->fetch(); }
public function delete($id) { return $this->db->delete($this->table(), array('_id' => $id)); }
/** * @TODO: test method */ public function deleteAll($query = array()) { $this->db->delete($this->table(), $query); } /** * @TODO: check for limits (if just one record needed) */ protected function fetchField($data, $params = array(), $field, $cache_key = null) { if (!$cache_key || !$result = $cache_key->get()) { $result = $this->db->find($this->table(), $data, array($field => 1))->fetchField($field); if ($cache_key) { $cache_key->set($result); } } return $result; }
/** * @TODO: check for limits (if just one record needed) */ protected function fetch($data, $params = array(), $cache_key = null) { if (!$cache_key || !$result = $cache_key->get()) { $result = $this->db->find($this->table(), $data)->fetch(); if ($cache_key) { $cache_key->set($result); } } return $result; }
protected function fetchAll($data, $params = array(), $cache_key = null) { if (!$cache_key || !$result = $cache_key->get()) { $result = $this->db->find($this->table(), $data)->fetchAll(); if ($cache_key) { $cache_key->set($result); } } return $result; } }
|