/**
  * 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 = null;
     if (isset($this->options['random'])) {
         $numRandom = intval($this->options['random']);
         if ($numRandom > 0) {
             // Digression: query for n unique random submit_time values
             $justSubmitTimes = new ExportBase();
             $justSubmitTimes->setOptions($this->options);
             $justSubmitTimes->setCommonOptions();
             unset($justSubmitTimes->options['random']);
             $justSubmitTimes->showColumns = array('submit_time');
             $jstSql = $justSubmitTimes->getPivotQuery($formName);
             $justSubmitTimes->setDataIterator($formName, 'submit_time');
             $justSubmitTimes->dataIterator->query($jstSql, $justSubmitTimes->rowFilter);
             $allSubmitTimes = null;
             while ($justSubmitTimes->dataIterator->nextRow()) {
                 $allSubmitTimes[] = $justSubmitTimes->dataIterator->row['submit_time'];
             }
             if (!empty($allSubmitTimes)) {
                 if (count($allSubmitTimes) < $numRandom) {
                     $submitTimes = $allSubmitTimes;
                 } else {
                     shuffle($allSubmitTimes);
                     // randomize
                     $submitTimes = array_slice($allSubmitTimes, 0, $numRandom);
                 }
             }
         }
     }
     $sql = $this->getPivotQuery($formName, false, $submitTimes);
     $this->dataIterator = new CFDBQueryResultIterator();
     //        $this->dataIterator->fileColumns = $this->getFileMetaData($formName);
     $queryOptions = array();
     if ($submitTimeKeyName) {
         $queryOptions['submitTimeKeyName'] = $submitTimeKeyName;
     }
     if (!empty($this->rowFilter) && isset($this->options['limit'])) {
         // 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'];
     }
     if (isset($this->options['unbuffered'])) {
         $queryOptions['unbuffered'] = $this->options['unbuffered'];
     }
     $this->dataIterator->query($sql, $this->rowFilter, $queryOptions);
     $this->dataIterator->displayColumns = $this->getColumnsToDisplay($this->dataIterator->columns);
 }
예제 #2
0
 /**
  * @param string|array $formName (if array, must be array of string)
  * @param null|string $submitTimeKeyName
  * @return void
  */
 protected function setDataIterator($formName, $submitTimeKeyName = null)
 {
     $sql = $this->getPivotQuery($formName);
     $this->dataIterator = new CFDBQueryResultIterator();
     //        $this->dataIterator->fileColumns = $this->getFileMetaData($formName);
     $queryOptions = array();
     if ($submitTimeKeyName) {
         $queryOptions['submitTimeKeyName'] = $submitTimeKeyName;
     }
     if (!empty($this->rowFilter) && isset($this->options['limit'])) {
         // 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'];
     }
     if (isset($this->options['unbuffered'])) {
         $queryOptions['unbuffered'] = $this->options['unbuffered'];
     }
     $this->dataIterator->query($sql, $this->rowFilter, $queryOptions);
     $this->dataIterator->displayColumns = $this->getColumnsToDisplay($this->dataIterator->columns);
 }