/** * Execute the query and set up the results iterator * @param string|array $formName (if array, must be array of string) * @param null|string $submitTimeKeyName * @return void */ protected function setDataIterator($formName, $submitTimeKeyName = null) { $submitTimes = $this->queryRandomSubmitTimes($formName); $sql = $this->getPivotQuery($formName, false, $submitTimes); $queryOptions = array(); if ($submitTimeKeyName) { $queryOptions['submitTimeKeyName'] = $submitTimeKeyName; } if (isset($this->options['limit']) && $this->hasFilterOrTransform()) { // have data iterator apply the limit if it is not already // being applied in SQL directly, which we do when there are // no filter constraints. $queryOptions['limit'] = $this->options['limit']; } $unbuffered = false; if (isset($this->options['unbuffered'])) { $queryOptions['unbuffered'] = $this->options['unbuffered']; $unbuffered = $queryOptions['unbuffered'] == 'true'; } if ($this->debug) { $queryOptions['debug'] = 'true'; } $this->dataIterator = CFDBQueryResultIteratorFactory::getInstance()->newQueryIterator($unbuffered); if ($this->transform && !empty($this->transform->transformIterators)) { $postProcessOptions = $queryOptions; // make a copy // If we have a transform, then alternatively-named options like 'tlimit' are used // in the actual query (CFDBQueryResultIterator) whereas the normally named // ones are handled by the CFDBTransformEndpoint post-processor unset($queryOptions['limit']); if (isset($this->options['tlimit'])) { $queryOptions['limit'] = $this->options['tlimit']; } unset($queryOptions['orderby']); if (isset($this->options['torderby'])) { $queryOptions['orderby'] = $this->options['torderby']; } // These aren't really needed b/c we have already setup $this->rowTransformFilter unset($queryOptions['filter']); if (isset($this->options['tfilter'])) { $queryOptions['filter'] = $this->options['tfilter']; } unset($queryOptions['search']); if (isset($this->options['tsearch'])) { $queryOptions['search'] = $this->options['tsearch']; } $this->dataIterator->query($sql, $this->rowTransformFilter, $queryOptions); $queryDisplayColumns = $this->getColumnsToDisplay($this->dataIterator->columns); $this->transform->setTimezone(); // Hookup query iterator as first transform, hookup last iterator as $this->dataIterator $this->transform->setDataSource($this->dataIterator); $this->dataIterator = $this->transform->getIterator(); // $this->dataIterator is a CFDBTransformEndpoint $this->dataIterator->getPostProcessor()->query($sql, $this->rowFilter, $postProcessOptions); $displayColumns = $this->getColumnsToDisplay($this->dataIterator->getDisplayColumns()); // Not sure why I need to do this to make show/hide work in some cases $this->dataIterator->displayColumns = empty($displayColumns) ? $queryDisplayColumns : $displayColumns; } else { // No transform, just query $this->dataIterator->query($sql, $this->rowFilter, $queryOptions); $this->dataIterator->displayColumns = $this->getColumnsToDisplay($this->dataIterator->columns); } }
public function test_eval_class_chain_mixed_2() { $t = new CFDBTransformParser(); $t->parse('SortByField(fname)&&upperall'); $t->setupTransforms(); $data = array(array('fname' => 'zzzz', 'lname' => 'AAAAA'), array('fname' => 'yyyy', 'lname' => 'CCCCC'), array('fname' => 'xxxx', 'lname' => 'BBBBB')); $source = new ArrayDataIterator($data); $t->setDataSource($source); $iter = $t->getIterator(); $iter->nextRow(); $this->assertEquals('XXXX', $iter->row['fname']); $this->assertEquals('BBBBB', $iter->row['lname']); $iter->nextRow(); $this->assertEquals('YYYY', $iter->row['fname']); $this->assertEquals('CCCCC', $iter->row['lname']); $iter->nextRow(); $this->assertEquals('ZZZZ', $iter->row['fname']); $this->assertEquals('AAAAA', $iter->row['lname']); }