Beispiel #1
0
 /**
  * Returns rewritten sqloptions array.
  * @param array $sqloptions
  * @return array $sqloptions
  */
 protected function _processOptions($sqloptions)
 {
     // prepare sqloptions
     $sqloptions['pending'] = array();
     $sqloptions['history'] = array();
     if ($sqloptions) {
         $lexer = new PHPSQLParser\lexer\PHPSQLLexer();
         $fieldStringPending = $this->quoteIdentifier('qqueue_jobs');
         $fieldStringHistory = $this->quoteIdentifier('qqueue_history');
         if (isset($sqloptions['order'])) {
             $order = array();
             foreach ($sqloptions['order'] as $value) {
                 $split = $lexer->split(trim($value));
                 $tmp = explode('.', $split[0]);
                 $order[end($split)] = end($tmp);
             }
             if (count($order) != 1) {
                 throw new Expection('More than one col in ' . get_class($this) . '::' . __METHOD__);
             } else {
                 // revert column again
                 $orderField = array_search(reset($order), Query_Model_Resource_QQueueQuery::$_cols);
                 $sqloptions['order'] = $orderField . ' ' . key($order);
             }
         }
         if (isset($sqloptions['where'])) {
             $sqloptions['pending']['where'] = array();
             $sqloptions['history']['where'] = array();
             foreach ($sqloptions['where'] as $key => $value) {
                 if (is_int($key)) {
                     $split = $lexer->split(trim($value));
                 } else {
                     $split = $lexer->split(trim($key));
                 }
                 // replace field
                 $split[0] = str_replace(array_keys(Query_Model_Resource_QQueueQuery::$_cols), Query_Model_Resource_QQueueQuery::$_cols, $split[0]);
                 if (is_int($key)) {
                     if (strpos($split[0], 'qqueue_jobs') !== false) {
                         $sqloptions['pending']['where'][] = implode($split);
                     } else {
                         if (strpos($split[0], 'qqueue_history') !== false) {
                             $sqloptions['history']['where'][] = implode($split);
                         } else {
                             $sqloptions['pending']['where'][] = implode($split);
                             $sqloptions['history']['where'][] = implode($split);
                         }
                     }
                 } else {
                     if (strpos($split[0], 'qqueue_jobs') !== false) {
                         $sqloptions['pending']['where'][implode($split)] = $value;
                     } else {
                         if (strpos($split[0], 'qqueue_history') === 0) {
                             $sqloptions['history']['where'][implode($split)] = $value;
                         } else {
                             $sqloptions['pending']['where'][implode($split)] = $value;
                             $sqloptions['history']['where'][implode($split)] = $value;
                         }
                     }
                 }
             }
             unset($sqloptions['where']);
         }
         if (isset($sqloptions['orWhere'])) {
             $sqloptions['pending']['orWhere'] = array();
             $sqloptions['history']['orWhere'] = array();
             foreach ($sqloptions['orWhere'] as $key => $value) {
                 if (is_int($key)) {
                     $split = $lexer->split(trim($value));
                 } else {
                     $split = $lexer->split(trim($key));
                 }
                 // replace field
                 $split[0] = str_replace(array_keys(Query_Model_Resource_QQueueQuery::$_cols), Query_Model_Resource_QQueueQuery::$_cols, $split[0]);
                 if (is_int($key)) {
                     if (strpos($split[0], $fieldStringPending) === 0) {
                         $sqloptions['pending']['orWhere'][] = implode($split);
                     } else {
                         if (strpos($split[0], $fieldStringHistory) === 0) {
                             $sqloptions['history']['orWhere'][] = implode($split);
                         } else {
                             $sqloptions['pending']['orWhere'][] = implode($split);
                             $sqloptions['history']['orWhere'][] = implode($split);
                         }
                     }
                 } else {
                     if (strpos($split[0], $fieldStringPending) === 0) {
                         $sqloptions['pending']['orWhere'][implode($split)] = $value;
                     } else {
                         if (strpos($split[0], $fieldStringHistory) === 0) {
                             $sqloptions['history']['orWhere'][implode($split)] = $value;
                         } else {
                             $sqloptions['pending']['orWhere'][implode($split)] = $value;
                             $sqloptions['history']['orWhere'][implode($split)] = $value;
                         }
                     }
                 }
             }
             unset($sqloptions['orWhere']);
         }
     }
     return $sqloptions;
 }
Beispiel #2
0
 /**
  * Returns rewritten sqloptions array.
  * @param array $sqloptions
  * @return array $sqloptions
  */
 protected function _processWhere($sqloptions)
 {
     if ($sqloptions) {
         $lexer = new PHPSQLParser\lexer\PHPSQLLexer();
         if (isset($sqloptions['where'])) {
             $where = array();
             foreach ($sqloptions['where'] as $key => $value) {
                 if (is_int($key)) {
                     $split = $lexer->split(trim($value));
                 } else {
                     $split = $lexer->split(trim($key));
                 }
                 // replace field
                 $split[0] = str_replace(array_keys(Query_Model_Resource_DirectQuery::$_cols), Query_Model_Resource_DirectQuery::$_cols, $split[0]);
                 if (is_int($key)) {
                     $where[$key] = implode($split);
                 } else {
                     $where[implode($split)] = $value;
                 }
             }
             $sqloptions['where'] = $where;
         }
         if (isset($sqloptions['orWhere'])) {
             $orWhere = array();
             foreach ($sqloptions['orWhere'] as $key => $value) {
                 if (is_int($key)) {
                     $split = $lexer->split(trim($value));
                 } else {
                     $split = $lexer->split(trim($key));
                 }
                 // replace field
                 $split[0] = str_replace(array_keys(Query_Model_Resource_DirectQuery::$_cols), Query_Model_Resource_DirectQuery::$_cols, $split[0]);
                 if (is_int($key)) {
                     $orWhere[$key] = implode($split);
                 } else {
                     $orWhere[implode($split)] = $value;
                 }
             }
             $sqloptions['orWhere'] = $orWhere;
         }
     }
     return $sqloptions;
 }