public function onAfterCreate() { parent::onAfterCreate(); $db = $this->criteria->getClassMap()->getDB(); $sql = $this->criteria->getSqlStatement(false); $countSQL = clone $sql; $countSQL->columns = array('count(*) as CNT'); $queryCNT = $db->getQuery($countSQL); $this->totalRecords = $queryCNT->fields('CNT'); $range = new MRange($this->pageNumber, $this->pageLength, $this->totalRecords); $sql->setRange($range); $query = $db->getQuery($sql); $cursor = new Cursor($query, $this->criteria->getClassMap(), false, $this->criteria->getManager()); $this->objArray = $cursor->getObjects(); $this->rowCount = count($this->objArray); }
/** * {@inheritdoc} */ public function read() { $this->documentManager->clear(); if (!$this->executed) { $this->executed = true; if (!is_object($this->channel)) { $this->channel = $this->channelManager->getChannelByCode($this->channel); } if ($this->missingCompleteness) { $this->completenessManager->generateMissingForChannel($this->channel); } $this->query = $this->repository->buildByChannelAndCompleteness($this->channel)->getQuery(); $this->products = $this->getQuery()->execute(); // MongoDB Cursor are not positioned on first element (whereas ArrayIterator is) // as long as getNext() hasn't be called $this->products->getNext(); } $result = $this->products->current(); if ($result) { $this->metricConverter->convert($result, $this->channel); $this->stepExecution->incrementSummaryInfo('read'); $this->products->next(); } return $result; }
public function testSetZoomable() { $this->cursor->setZoomable(true); $this->assertTrue($this->cursor->isZoomable()); $this->cursor->setZoomable(false); $this->assertFalse($this->cursor->isZoomable()); }
/** * Initialize the internal data by converting the Cursor to an array. */ public function initialize() { if ($this->initialized === false) { $this->data = $this->cursor->toArray(); } $this->initialized = true; }
/** * Output a line, erasing the line first * * @param string $str String to output * @param null|int $col The column to draw the current line * @param boolean $erase Clear the line before drawing the passed string */ static function line($str, $col = null, $erase = true) { if ($col !== null) { Cursor::rowcol($col, 1); } if ($erase) { Erase::line(); } fwrite(self::$stream, $str); }
/** * @param resource $stream * @param string $str * @param integer|null $row */ protected static function saveWriteRestore($stream, $str, $row) { if ($row) { Cursor::savepos(); Cursor::rowcol($row, Misc::cols()); } fwrite($stream, $str); if ($row) { Cursor::restore(); } }
/** * @{inheritdoc} */ public function read() { $product = null; if ($this->products->valid()) { $product = $this->products->current(); $this->stepExecution->incrementSummaryInfo('read'); $this->products->next(); } if (null !== $product) { $channel = $this->channelManager->getChannelByCode($this->channel); $this->metricConverter->convert($product, $channel); } return $product; }
/** * Initializer * @param Array $options Connection Options */ public function __construct($server = 'mongodb://localhost:27017', array $options = array()) { // Link timeouts Cursor::$timeout = \MongoCursor::$timeout; \MongoCursor::$timeout =& Cursor::$timeout; // Parse MongoDB Path Info if (!empty($options['db'])) { $db_name = $options['db']; } else { $uri = parse_url($server); $db_name = isset($uri['path']) ? substr($uri['path'], 1) : 'test'; } // Apply defaults if (!isset($options['connect'])) { $options['connect'] = true; } // Native connection $this->native = new \MongoClient($server, $options); // Select Database for default reference if ($db_name) { $this->selectDb($db_name); } }
/** * Render a statusbar stack * * @staticvar bool $lines A stack of previously added lines * @param string $str The status to add * @param null|int $height The height of the status menu to render * @param bool $last_line_to_opposing_stream Send the last line of the status to the oposite stream (STDERR/STDOUT) */ static function statusbar($str, $height = null, $last_line_to_opposing_stream = true) { if ($height < 0) { $height = Misc::rows() + $height + 1; } if (!$height) { if (defined('STATUSBAR_HEIGHT')) { $height = STATUSBAR_HEIGHT; //@todo: backwards compatibility with some of my older code, remove } else { $height = max(5, Misc::rows() - 5); } } static $lines = false; $i = 0; if (!$lines) { $lines = array_fill(0, $height - 1, array('str' => '')); } foreach (explode(PHP_EOL, $str) as $line) { $lines[] = array('str' => strtr(trim($line), "\r\n", " ")); array_shift($lines); } fwrite(self::$stream, "7[1;1f[2K"); foreach ($lines as $line) { $i++; $text = substr(str_pad($line['str'], Misc::cols()), 0, Misc::cols() - 1); Cursor::rowcol($i, 1); if ($i == $height - 1 && $last_line_to_opposing_stream) { fwrite(self::$altstream, $text); } else { fwrite(self::$stream, $text); } } fwrite(self::$stream, "[" . $height . ";1f"); fwrite(self::$stream, str_repeat('─', Misc::cols())); fwrite(self::$stream, "8"); }
public function testSetServerTimeoutInSetter() { $cursor = new Cursor($this->collection); $cursor->setServerTimeout(42); $this->assertEquals(42, $cursor->getOption('serverTimeout')); }
/** * {@inheritdoc} */ public function timeout($ms) { $this->cursor->timeout($ms); return $this; }
/** * Returns the document the cursor is currently pointing to * @return \Todo */ public function current() { $output = new Todo(); $output->document = parent::current(); return $output; }
/** @proxy */ public function sort($fields) { $this->log(array('sort' => true, 'sortFields' => $fields)); return parent::sort($fields); }
public function pivot($table, $id) { $cursor = new Cursor(self::instance($this->db, $table)); return $cursor->getRow($id); }
/** * @see Cursor::maxTimeMS() */ public function maxTimeMS($ms) { $this->log(array('maxTimeMS' => true, 'maxTimeMSNum' => $ms)); return parent::maxTimeMS($ms); }
public function disableEcho() { return $this->cursor->disableEcho(); }
public function snapshot() { $this->log(array('snapshot' => true)); return parent::snapshot(); }
/** * Returns the document the cursor is currently pointing to * @return array */ public function current() { // $output = new Todo(); // $output->document = parent::current(); return parent::current(); }
/** * Get the batch part identified by the array key (0...n) or its id (if it was set with nextBatchPartId($id) ) * * @throws ClientException * @return mixed $partId */ public function getProcessedResponse() { $response = $this->getResponse(); switch ($this->_type) { case 'getdocument': $json = $response->getJson(); $options = $this->getCursorOptions(); $options['isNew'] = false; $response = Document::createFromArray($json, $options); break; case 'document': $json = $response->getJson(); if ($json['error'] === false) { $id = $json[Document::ENTRY_ID]; $response = $id; } break; case 'getedge': $json = $response->getJson(); $options = $this->getCursorOptions(); $options['isNew'] = false; $response = Edge::createFromArray($json, $options); break; case 'edge': $json = $response->getJson(); if ($json['error'] === false) { $id = $json[Edge::ENTRY_ID]; $response = $id; } break; case 'getcollection': $json = $response->getJson(); $options = $this->getCursorOptions(); $options['isNew'] = false; $response = Collection::createFromArray($json, $options); break; case 'collection': $json = $response->getJson(); if ($json['error'] === false) { $id = $json[Collection::ENTRY_ID]; $response = $id; } break; case 'cursor': $options = $this->getCursorOptions(); $options['isNew'] = false; $response = new Cursor($this->_batch->getConnection(), $response->getJson(), $options); break; default: throw new ClientException('Could not determine response data type.'); break; } return $response; }
/** * EmptyCursor constructor. */ public function __construct() { parent::__construct([]); }