public function count($force = false) { if ($force || !isset($this->count)) { $this->count = $this->cursor->count(); } return $this->count; }
/** * Returns the total number of rows in the result set. * * @return int */ public function count() { if ($this->rowCount !== null) { return $this->rowCount; } $this->rowCount = $this->cursor->count($foundOnly = true); return $this->rowCount; }
public function testDrop() { $this->object->storeFile('tests/somefile'); $c = $this->object->chunks->count(); $this->assertGreaterThan(0, $c); $this->assertEquals($this->count(), 1); $this->object->drop(); $this->assertEquals($this->object->chunks->count(), 0); $this->assertEquals($this->object->count(), 0); }
/** * Count total number of items without limit and offset * @return mixed */ public function totalCount() { if (!$this->count) { $this->count = $this->cursor->count(false); } return $this->count; }
/** * Get affected rows * * @return int */ public function getAffectedRows() { if ($this->resource instanceof \MongoCursor) { return $this->resource->count(); } return $this->resource; }
/** * Construct by passing in the \MongoCursor and the object to populate * @param \MongoCursor $cursor */ public function __construct(\MongoCursor $cursor, Collection $collection) { $this->cursor = $cursor; $this->count = $cursor->count(true); $this->position = 0; $this->collection = $collection; }
/** * Count the results from the query * * + Count the results from the current query: pass false for "all" results (disregard limit/skip) * + Count results of a separate query: pass an array or JSON string of query parameters * * @since 0.3.0 * * See [\Countable::count] * * @link http://www.php.net/manual/en/mongocursor.count.php \MongoCursor::count * * @param boolean|array|string $query * * @return integer * * @throws \Exception * * @uses \JSON::encodeMongo * @uses \JSON::decode * @uses \Profiler::start * @uses \Profiler::stop */ public function count($query = true) { if (is_bool($query)) { // Profile count operation for cursor if ($this->getClientInstance()->profiling) { $this->benchmark = Profiler::start(get_class($this->getClientInstance()) . "::{$this->db}", $this->shellQuery() . ".count(" . JSON::encodeMongo($query) . ")"); } $this->cursor || $this->load(); $count = $this->cursor->count($query); } else { if (is_string($query) && $query[0] == "{") { $query = JSON::decode($query, true); } $query_trans = array(); foreach ($query as $field => $value) { $query_trans[$this->getFieldName($field)] = $value; } $query = $query_trans; // Profile count operation for collection if ($this->getClientInstance()->profiling) { $this->benchmark = Profiler::start(get_class($this->getClientInstance()) . "::{$this->db}", "db.{$this->name}.count(" . ($query ? JSON::encodeMongo($query) : '') . ")"); } $count = $this->getCollection()->count($query); } // End profiling count if ($this->benchmark) { // Stop the benchmark Profiler::stop($this->benchmark); // Clean benchmark token $this->benchmark = null; } return $count; }
/** * Performs proper skip and limit to get * data package that can be wraped in paginator * * @param int $perPage * @param int $page * @param mixed $options Options you want to pass */ public function getPaginator($perPage = 10, $page = 1, $options = null) { $this->_checkCursor(); $total = $this->_cursor->count(); $this->_cursor->skip(($page - 1) * $perPage)->limit($perPage); $result = $this->get(); return $this->_createPaginator($result, $total, $perPage, $page, $options); }
/** * @see CActiveDataProvider::calculateTotalItemCount() * @return int */ public function calculateTotalItemCount() { if (!$this->_cursor) { $criteria = $this->getCriteria(); $this->_cursor = $this->model->find(isset($criteria['condition']) && is_array($criteria['condition']) ? $criteria['condition'] : array()); } return $this->_cursor->count(); }
/** * @see CActiveDataProvider::calculateTotalItemCount() * @return int */ public function calculateTotalItemCount() { if (!$this->_builder) { $criteria = $this->getCriteria(); $this->_builder = new EMongoQueryBuilder($this->model, isset($criteria['condition']) && is_array($criteria['condition']) ? $criteria['condition'] : []); } return $this->_builder->count(); }
/** * Count the results * * @since v1.0.0 */ public function count($foundOnly = FALSE) { $count = array(); try { $count = $this->_cursor->count($foundOnly); } catch (MongoCursorException $exception) { show_error($exception->getMessage(), 500); } catch (MongoConnectionException $exception) { show_error($exception->getMessage(), 500); } catch (MongoCursorTimeoutException $exception) { show_error($exception->getMessage(), 500); } return $count; }
/** * count method on the cursor, allows to get result count * * @param bool $foundOnly * @return int */ public function count($foundOnly = false) { return $this->myResultCursor->count($foundOnly); }
/** * Returns the number of documents found * {@see http://www.php.net/manual/en/mongocursor.count.php} * @param boolean $foundOnly default TRUE * @return integer count of documents found * @since v1.3.4 */ public function count($foundOnly = true) { return $this->_cursor->count($foundOnly); }
/** * Constructor. * * @param \Iterator $iterator Iterator to paginate * @throws \Zend\Paginator\Adapter\Exception\InvalidArgumentException */ public function __construct(\MongoCursor $iterator) { $this->iterator = $iterator; $this->count = $iterator->count(); }
/** * @param \MongoCursor $resource * @param mixed $context * @return Result */ public function createResult($resource, $context = null) { $result = clone $this->resultPrototype; if ($resource instanceof \MongoCursor) { $rowCount = $resource->count($foundOnly = true); } elseif (is_array($resource) && isset($resource['n'])) { $rowCount = (int) $resource['n']; // $resource = $this -> connection -> getDB() -> selectCollection( $context ) -> find( ['_id' => $this -> connection -> getLastGeneratedValue( $context ) ] ); } else { $rowCount = (int) $resource; // $resource = $this -> connection -> getDB() -> selectCollection( $context ) -> find( ['_id' => $this -> connection -> getLastGeneratedValue( $context ) ] ); } $result->initialize($resource, $this->connection->getLastGeneratedValue($context), $rowCount); return $result; }
/** * Returns the total count of result irrevelent of the value of limit * * @return int */ public function totalCount() { return $this->cursor->count(); }
/** * count. */ public function count($foundOnly = false) { $this->time->start(); $return = parent::count($foundOnly); $time = $this->time->stop(); $info = $this->info(); $this->log(array('type' => 'count', 'query' => is_array($info['query']) ? $info['query'] : array(), 'limit' => $info['limit'], 'skip' => $info['skip'], 'foundOnly' => $foundOnly, 'time' => $time)); return $return; }
/** * {@inheritDoc} * * @api */ public function getItemCount() { return $this->cursor->count(); }
/** * Counts the number of results for this query * @link http://www.php.net/manual/en/mongocursor.count.php * @param bool $all Count records with limit and skip applied * @return int The number of documents returned by this cursor's query. */ public function count($all = false) { return $this->cursor->count($all); }
/** * * @param array | MongoCursor $content * If content is array, there should be keys url, avatar, name * @param unknown $max * @return multitype: */ public static function facePile($content, $max) { $count = $content instanceof MongoCursor ? $content->count() : count($content); $moreCount = $count - $max; $listSliced = $list = array(); if ($moreCount > 0) { $listSliced = $content instanceof MongoCursor ? $content->limit($max) : array_slice($content, 0, $max); } else { $listSliced = $content; } foreach ($listSliced as $listItem) { array_push($list, array('url' => '/page/' . $listItem['uname'], 'avatar' => $listItem['avatar'], 'name' => $listItem['name'])); } if ($moreCount > 0) { array_push($list, '<span class="count rounded-avatar">+' . self::megaCount(abs($moreCount)) . '</span>'); } return $list; }
public function count() { return parent::count(); }
/** * Countable: count * * Count the results from the current query: pass FALSE for "all" results (disregard limit/skip)<br/> * Count results of a separate query: pass an array or JSON string of query parameters * * @param mixed $query * @throws Exception * @return int */ public function count($query = TRUE) { if (is_bool($query)) { // Profile count operation for cursor if ($this->db()->profiling) { $bm = $this->db()->profiler_start("Mongo_Database::{$this->db}", $this->inspect() . ".count(" . JSON::str($query) . ")"); } $this->_cursor or $this->load(TRUE); $count = $this->_cursor->count($query); } else { if (is_string($query) && $query[0] == "{") { $query = JSON::arr($query); if ($query === NULL) { throw new Exception('Unable to parse query from JSON string.'); } } $query_trans = array(); foreach ($query as $field => $value) { $query_trans[$this->get_field_name($field)] = $value; } $query = $query_trans; // Profile count operation for collection if ($this->db()->profiling) { $bm = $this->db()->profiler_start("Mongo_Database::{$this->db}", "db.{$this->name}.count(" . ($query ? JSON::str($query) : '') . ")"); } $count = $this->collection()->count($query); } // End profiling count if (isset($bm)) { $this->db()->profiler_stop($bm); } if (is_array($count)) { throw new MongoException(json_encode($count)); } return $count; }
public function count($foundOnly = false) { return parent::count($foundOnly); }