Esempio n. 1
0
 /**
  * Convert the query to record set and set the summary data if available
  * @param array $params parameters to the qurery
  * @param array $summary summary option
  * @param boolean excel
  * @return recordset object
  */
 protected function _rs($params = null, $summary = null, $excel = false)
 {
     if ($this->ExportCommand && strlen($this->ExportCommand) > 0) {
         $sqlId = $this->ExportCommand;
     } else {
         $sqlId = $this->_setSQL();
     }
     if (!$sqlId) {
         return false;
     }
     $sidx = $this->GridParams['sort'];
     $sidx = jqGridUtils::GetParam($sidx, '');
     // get index row - i.e. user click to sort
     $sord = $this->GridParams['order'];
     $sord = jqGridUtils::GetParam($sord, '');
     // get the direction
     $search = $this->GridParams['search'];
     $search = jqGridUtils::GetParam($search, 'false');
     // get the direction
     $sord = preg_replace("/[^a-zA-Z0-9]/", "", $sord);
     $sidx = preg_replace("/[^a-zA-Z0-9. _,]/", "", $sidx);
     if ($search == 'true') {
         if ($this->dbtype == 'mongodb') {
             $params = jqGridDB::_mongoSearch($params, $this->GridParams, $this->encoding, $this->datearray, $this->mongointegers);
         } else {
             $sGrid = $this->_buildSearch($params);
             if ($this->dbtype == 'array') {
                 $whr = "";
                 if ($sGrid[0]) {
                     if (preg_match("/WHERE/i", $sqlId)) {
                         // to be refined
                         $whr = " AND " . $sGrid[0];
                     } else {
                         $whr = " WHERE " . $sGrid[0];
                     }
                 }
                 $sqlId .= $whr;
             } else {
                 $whr = $sGrid[0] ? " WHERE " . $sGrid[0] : "";
                 $sqlId = "SELECT * FROM (" . $sqlId . ") gridsearch" . $whr;
             }
             $params = $sGrid[1];
         }
     }
     if ($this->dbtype !== 'mongodb') {
         if ($sidx) {
             $sqlId .= " ORDER BY " . $sidx . " " . $sord;
         }
     }
     if (!$excel && is_array($summary)) {
         if ($this->dbtype == 'mongodb') {
             $qryData = jqGridDB::_mongocount($sqlId, $params, $summary);
         } else {
             $qryData = $this->_getcount($sqlId, $params, $summary);
         }
         unset($qryData->COUNT, $qryData->count);
         foreach ($qryData as $k => $v) {
             if ($v == null) {
                 $v = 0;
             }
             $this->tmpvar[$k] = $v;
         }
     }
     if ($this->userdata) {
         if (!$this->tmpvar) {
             $this->tmpvar = array();
         }
         $this->tmpvar = jqGridUtils::array_extend($this->tmpvar, $this->userdata);
     }
     if ($this->debug) {
         $this->logQuery($sqlId, $params);
         $this->debugout();
     }
     $ret = $this->execute($sqlId, $params, $sql, true, $this->gSQLMaxRows, 0, $sidx, $sord);
     return $sql;
 }