Exemplo n.º 1
0
 protected function __sql_conditions()
 {
     $first = true;
     foreach ($this->conditions as $kv) {
         if ($first) {
             $this->sql .= " WHERE ";
         } else {
             $this->sql .= " AND ";
         }
         if ($kv["type"] == self::CONDITION_MATCH_AGAINST) {
             $this->__sql_field_match_against($kv);
         } else {
             $this->sql .= "`" . $kv["field"] . "`";
             if ($kv["inner_statement"]) {
                 $this->sql .= " IN ";
             } else {
                 if ($kv["type"] == self::CONDITION_CONTAINS || $kv["type"] == self::CONDITION_BEGIN_WITH || $kv["type"] == self::CONDITION_END_WITH) {
                     if ($kv["not"]) {
                         $this->sql .= " NOT";
                     }
                     $this->sql .= " LIKE ";
                 }
                 if ($kv["type"] == self::CONDITION_REGEXP) {
                     if ($kv["not"]) {
                         $this->sql .= " NOT";
                     }
                     $this->sql .= " REGEXP ";
                     if ($kv["binary"]) {
                         $this->sql .= "BINARY ";
                     }
                 }
                 if ($kv["type"] == self::CONDITION_TYPE_EQUALS) {
                     $this->sql .= " = ";
                 }
                 if ($kv["type"] == self::CONDITION_TYPE_NOT_EQUALS) {
                     $this->sql .= " != ";
                 }
                 if ($kv["type"] == self::CONDITION_TYPE_GREATER_THAN) {
                     $this->sql .= " > ";
                 }
                 if ($kv["type"] == self::CONDITION_TYPE_GREATER_THAN_OR_EQUAL) {
                     $this->sql .= " >= ";
                 }
                 if ($kv["type"] == self::CONDITION_TYPE_LESS_THAN) {
                     $this->sql .= " < ";
                 }
                 if ($kv["type"] == self::CONDITION_TYPE_LESS_THAN_OR_EQUAL) {
                     $this->sql .= " <= ";
                 }
                 if ($kv["type"] == self::CONDITION_TYPE_IN) {
                     $this->sql .= " IN ";
                 }
                 if ($kv["type"] == self::CONDITION_TYPE_NOT_IN) {
                     $this->sql .= " NOT IN ";
                 }
             }
             if ($kv["inner_statement"]) {
                 $this->sql .= "(";
             }
             if ($kv["quote"]) {
                 $this->sql .= "'";
             }
             if ($kv["type"] == self::CONDITION_TYPE_IN || $kv["type"] == self::CONDITION_TYPE_NOT_IN) {
                 $this->sql .= " (" . ArrayUtils::join($kv["values"], ",") . ")";
             } else {
                 if ($kv["type"] == self::CONDITION_BEGIN_WITH || $kv["type"] == self::CONDITION_CONTAINS) {
                     $this->sql .= "%";
                 }
                 $this->sql .= $kv["value"];
                 if ($kv["type"] == self::CONDITION_CONTAINS || $kv["type"] == self::CONDITION_END_WITH) {
                     $this->sql .= "%";
                 }
             }
             if ($kv["quote"]) {
                 $this->sql .= "'";
             }
             if ($kv["inner_statement"]) {
                 $this->sql .= ")";
             }
         }
         $first = false;
     }
 }