Example #1
0
 /**
  * Get a single instance of the class (Singleton)
  * @return GetRequest
  */
 public static function getInstance()
 {
     if (!self::$__instance instanceof self) {
         self::$__instance = new self();
     }
     return self::$__instance;
 }
Example #2
0
 public function processQuery()
 {
     $Request = GetRequest::getInstance();
     if ($paginate) {
         $this->_paginate = true;
         //Get a Grip of the whole thing
         $sql_without_conditions = str_replace('{conditions}', '', $sql);
         $count_sql = "SELECT count(*) FROM ({$sql_without_conditions}) AS count_table;";
         $total_rows = $DbConnection->getOneValue($count_sql);
         //Create some basic pattern variables
         $this->_page_number = empty($Request->__page_number) ? '0' : $Request->__page_number;
         $this->_page_size = empty($Request->__page_size) ? $this->_page_size : $Request->__page_size;
         $this->_pages = ceil($total_rows / $this->_page_size);
         if ($this->_page_number > $this->_pages) {
             $this->_page_number = $this->_pages - 1;
         }
         //Reformat the query to use MySQL Limit clause
         $page_start = $this->_page_number * $this->_page_size;
         $sql = "{$sql}\n            LIMIT {$page_start}, {$this->_page_size}";
         $this->setPatternVariable('paginate', $this->_paginate);
         $this->setPatternVariable('page_number', $this->_page_number);
         $this->setPatternVariable('page_size', $this->_page_size);
         $this->setPatternVariable('pages', $this->_pages);
     }
     $conditions = '';
     if (count($this->_filters)) {
         foreach ($this->_filters as $field => $filter) {
             $Filter = (object) $filter;
             if ($Filter->type == 'custom') {
                 //echo "Checking for filter on '$field'\n";
                 if (isset($Request->{$field})) {
                     $selected = stripslashes($Request->{$field});
                 } else {
                     $selected = $this->_filters[$field]['default'];
                 }
                 //echo "Selected:$selected\n";
                 foreach ($Filter->options as $option) {
                     //echo "Comparing value: {$option['value']}\n";
                     if ($option['value'] == $selected) {
                         //echo "Match!, condition added '{$option['condition']}'\n\n";
                         $conditions .= "\nAND ";
                         $conditions .= $option['condition'];
                         $this->_filters[$field]['selected'] = $selected;
                     }
                 }
             } else {
                 if ($Filter->type == 'hidden') {
                     $conditions .= "\nAND ";
                     $conditions .= $Filter->condition;
                 }
             }
         }
     }
     if (empty($conditions)) {
         $sql = str_replace('{conditions}', '', $sql);
     } else {
         $sql = str_replace('{conditions}', $conditions, $sql);
     }
     $this->_conditions = $conditions;
     $this->_sql = $sql;
 }