/**
  * Fetch next row into variable
  * @return bool if next row exists
  */
 public function nextRow()
 {
     while (true) {
         if (!$this->onFirstRow) {
             $this->row = $this->fetchRow();
         }
         $this->onFirstRow = false;
         if (!$this->row) {
             $this->freeResult();
             return false;
         }
         // Format the date
         if (!isset($this->row['submit_time']) && isset($this->row['Submitted']) && is_numeric($this->row['Submitted'])) {
             $submitTime = $this->row['Submitted'];
             $this->row['submit_time'] = $submitTime;
             $this->row['Submitted'] = $this->plugin->formatDate($submitTime);
         }
         // Determine if row is filtered
         if ($this->rowFilter) {
             $match = $this->rowFilter->evaluate($this->row);
             if (!$match) {
                 continue;
             }
         }
         $this->idx += 1;
         if ($this->limitStart && $this->idx < $this->limitStart) {
             continue;
         }
         if ($this->limitEnd && $this->idx >= $this->limitEnd) {
             while ($this->row = $this->fetchRow()) {
             }
             $this->freeResult();
             $this->row = null;
             return false;
         }
         // Keep the unformatted submitTime if needed
         if (isset($submitTime) && $this->submitTimeKeyName) {
             $this->row[$this->submitTimeKeyName] = $submitTime;
         }
         break;
     }
     if (!$this->row) {
         $this->freeResult();
     }
     return $this->row ? true : false;
 }
예제 #2
0
 public function setCommonOptions($htmlOptions = false)
 {
     if ($this->options && is_array($this->options)) {
         foreach (array('debug', 'permissionmsg', 'unbuffered', 'show', 'hide', 'class', 'style', 'id', 'orderby', 'limit', 'tlimit', 'header', 'headers', 'content', 'filter', 'tfilter', 'search', 'tsearch', 'trans') as $optionName) {
             $this->dereferenceOption($optionName);
         }
         if (isset($this->options['debug']) && $this->options['debug'] != 'false') {
             $this->debug = true;
         }
         $this->isFromShortCode = isset($this->options['fromshortcode']) && $this->options['fromshortcode'] === true;
         if (!isset($this->options['unbuffered'])) {
             //$this->options['unbuffered'] = $this->isFromShortCode ? 'false' : 'true'; // todo
             $this->options['unbuffered'] = 'false';
         } else {
             if ($this->options['unbuffered'] == 'checked') {
                 $this->options['unbuffered'] = 'true';
             }
         }
         if (isset($this->options['showColumns'])) {
             $this->showColumns = $this->options['showColumns'];
         } else {
             if (isset($this->options['show'])) {
                 $this->showColumns = preg_split('/,/', $this->options['show'], -1, PREG_SPLIT_NO_EMPTY);
             }
         }
         if (isset($this->options['hideColumns'])) {
             $this->hideColumns = $this->options['hideColumns'];
         } else {
             if (isset($this->options['hide'])) {
                 $this->hideColumns = preg_split('/,/', $this->options['hide'], -1, PREG_SPLIT_NO_EMPTY);
             }
         }
         if ($htmlOptions) {
             if (isset($this->options['class'])) {
                 $this->htmlTableClass = $this->options['class'];
             } else {
                 $this->htmlTableClass = $this->defaultTableClass;
             }
             if (isset($this->options['id'])) {
                 $this->htmlTableId = $this->options['id'];
             } else {
                 $this->htmlTableId = 'cftble_' . rand();
             }
             if (isset($this->options['style'])) {
                 $this->style = $this->options['style'];
             }
         }
         $permittedFunctions = null;
         if (isset($this->options['filter']) || isset($this->options['trans'])) {
             require_once 'CFDBPermittedFunctions.php';
             $permittedFunctions = CFDBPermittedFunctions::getInstance();
             $permitAll = $this->queryPermitAllFunctions();
             $permittedFunctions->setPermitAllFunctions($permitAll);
         }
         $filters = array();
         if (isset($this->options['filter'])) {
             require_once 'CFDBFilterParser.php';
             $aFilter = new CFDBFilterParser();
             $aFilter->setComparisonValuePreprocessor(new DereferenceShortcodeVars());
             $aFilter->setPermittedFilterFunctions($permittedFunctions);
             $aFilter->parse($this->options['filter']);
             if ($this->debug) {
                 echo '<pre>\'' . $this->options['filter'] . "'\n";
                 print_r($aFilter->tree);
                 echo '</pre>';
             }
             $filters[] = $aFilter;
         }
         $transformFilters = array();
         if (isset($this->options['tfilter'])) {
             require_once 'CFDBFilterParser.php';
             $aFilter = new CFDBFilterParser();
             $aFilter->setComparisonValuePreprocessor(new DereferenceShortcodeVars());
             $aFilter->setPermittedFilterFunctions($permittedFunctions);
             $aFilter->parse($this->options['tfilter']);
             if ($this->debug) {
                 echo '<pre>\'' . $this->options['tfilter'] . "'\n";
                 print_r($aFilter->tree);
                 echo '</pre>';
             }
             $transformFilters[] = $aFilter;
         }
         if (isset($this->options['search'])) {
             require_once 'CFDBSearchEvaluator.php';
             $aFilter = new CFDBSearchEvaluator();
             $aFilter->setSearch($this->options['search']);
             $filters[] = $aFilter;
         }
         if (isset($this->options['tsearch'])) {
             require_once 'CFDBSearchEvaluator.php';
             $aFilter = new CFDBSearchEvaluator();
             $aFilter->setSearch($this->options['tsearch']);
             $transformFilters[] = $aFilter;
         }
         $numFilters = count($filters);
         if ($numFilters == 1) {
             $this->rowFilter = $filters[0];
         } else {
             if ($numFilters > 1) {
                 require_once 'CFDBCompositeEvaluator.php';
                 $this->rowFilter = new CFDBCompositeEvaluator();
                 $this->rowFilter->setEvaluators($filters);
             }
         }
         $numTransformFilters = count($transformFilters);
         if ($numTransformFilters == 1) {
             $this->rowTransformFilter = $transformFilters[0];
         } else {
             if ($numTransformFilters > 1) {
                 require_once 'CFDBCompositeEvaluator.php';
                 $this->rowTransformFilter = new CFDBCompositeEvaluator();
                 $this->rowTransformFilter->setEvaluators($transformFilters);
             }
         }
         if (isset($this->options['trans'])) {
             require_once 'CFDBTransformParser.php';
             $this->transform = new CFDBTransformParser();
             $this->transform->setComparisonValuePreprocessor(new DereferenceShortcodeVars());
             $this->transform->setPermittedFilterFunctions($permittedFunctions);
             $transformOption = $this->options['trans'];
             // Set up "orderby" post-processing
             if (isset($this->options['orderby'])) {
                 $orderByStrings = explode(',', $this->options['orderby']);
                 foreach ($orderByStrings as $anOrderBy) {
                     $anOrderBy = trim($anOrderBy);
                     $ascOrDesc = null;
                     list($ascOrDesc, $anOrderBy) = $this->parseOrderBy($anOrderBy);
                     $ascOrDesc = trim($ascOrDesc);
                     if (empty($ascOrDesc)) {
                         $ascOrDesc = 'ASC';
                     }
                     // Append a Sort transform
                     $transformOption .= '&&NaturalSortByField(' . $anOrderBy . ',' . $ascOrDesc . ')';
                 }
             }
             $this->transform->parse($transformOption);
             if ($this->debug) {
                 echo '<pre>\'' . $transformOption . "'\n";
                 print_r($this->transform->tree);
                 echo '</pre>';
             }
             $this->transform->setupTransforms();
         }
         if (isset($this->options['headers'])) {
             // e.g. "col1=Column 1 Display Name,col2=Column2 Display Name"
             $headersList = preg_split('/,/', $this->options['headers'], -1, PREG_SPLIT_NO_EMPTY);
             if (is_array($headersList)) {
                 $this->headers = array();
                 foreach ($headersList as $nameEqualValue) {
                     $nameEqualsValueArray = explode('=', $nameEqualValue, 2);
                     // col1=Column 1 Display Name
                     if (count($nameEqualsValueArray) >= 2) {
                         $this->headers[$nameEqualsValueArray[0]] = $nameEqualsValueArray[1];
                     }
                 }
             }
         }
     }
 }