/**
  * 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);
 }
Exemple #2
0
 /**
  * Query for n random submit times if 'random' option is set indicting number of random
  * values to return (n)
  * @param $formName
  * @return array|null array of n submit_times or null if not applicable
  */
 protected function queryRandomSubmitTimes($formName)
 {
     $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;
                     return $submitTimes;
                 } else {
                     shuffle($allSubmitTimes);
                     // randomize
                     $submitTimes = array_slice($allSubmitTimes, 0, $numRandom);
                     return $submitTimes;
                 }
             }
             return $submitTimes;
         }
         return $submitTimes;
     }
     return $submitTimes;
 }
 public function test_post_vars()
 {
     $options = array();
     $exp = new ExportBase();
     $options['debug'] = 'true';
     $options['filter'] = 'your-name=$_POST(aname)&&your-subject=$_POST(subject)';
     $exp->setOptions($options);
     $exp->setCommonOptions(true);
     print_r($exp->rowFilter->tree);
     $this->assertEquals('your-name', $exp->rowFilter->tree[0][0][0]);
     $this->assertEquals('=', $exp->rowFilter->tree[0][0][1]);
     $this->assertEquals('', $exp->rowFilter->tree[0][0][2]);
     $this->assertEquals('your-subject', $exp->rowFilter->tree[0][1][0]);
     $this->assertEquals('=', $exp->rowFilter->tree[0][1][1]);
     $this->assertEquals('', $exp->rowFilter->tree[0][1][2]);
 }