count() public method

Counts the number of results for this query
public count ( boolean $foundOnly = false ) : integer
$foundOnly boolean Send cursor limit and skip information to the count function, if applicable.
return integer The number of documents returned by this cursor's query.
Ejemplo n.º 1
0
 public function count($force = false)
 {
     if ($force || !isset($this->count)) {
         $this->count = $this->cursor->count();
     }
     return $this->count;
 }
Ejemplo n.º 2
0
 /**
  * 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);
 }
Ejemplo n.º 4
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;
 }
Ejemplo n.º 5
0
 /**
  * Get affected rows
  *
  * @return int
  */
 public function getAffectedRows()
 {
     if ($this->resource instanceof \MongoCursor) {
         return $this->resource->count();
     }
     return $this->resource;
 }
Ejemplo n.º 6
0
 /**
  * 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;
 }
Ejemplo n.º 7
0
 /**
  * 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;
 }
Ejemplo n.º 8
0
 /**
  * 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);
 }
Ejemplo n.º 9
0
 /**
  * @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();
 }
Ejemplo n.º 10
0
 /**
  * @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();
 }
Ejemplo n.º 11
0
 /**
  * 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;
 }
Ejemplo n.º 12
0
 /**
  * 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);
 }
Ejemplo n.º 13
0
 /**
  * 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);
 }
Ejemplo n.º 14
0
 /**
  * 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();
 }
Ejemplo n.º 15
0
 /**
  * @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;
 }
Ejemplo n.º 16
0
 /**
  * Returns the total count of result irrevelent of the value of limit
  *
  * @return int
  */
 public function totalCount()
 {
     return $this->cursor->count();
 }
Ejemplo n.º 17
0
 /**
  * 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;
 }
Ejemplo n.º 18
0
 /**
  * {@inheritDoc}
  *
  * @api
  */
 public function getItemCount()
 {
     return $this->cursor->count();
 }
Ejemplo n.º 19
0
 /**
  * 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);
 }
Ejemplo n.º 20
0
 /**
  *
  * @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;
 }
Ejemplo n.º 21
0
 public function count()
 {
     return parent::count();
 }
Ejemplo n.º 22
0
 /**
  * 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;
 }
Ejemplo n.º 23
0
 public function count($foundOnly = false)
 {
     return parent::count($foundOnly);
 }