Esempio n. 1
0
 public function parseValue($value, Doctrine_Table $table = null, $field = null)
 {
     if (substr($value, 0, 1) == '(') {
         // trim brackets
         $trimmed = $this->_tokenizer->bracketTrim($value);
         if (substr($trimmed, 0, 4) == 'FROM' || substr($trimmed, 0, 6) == 'SELECT') {
             // subquery found
             $q = new Doctrine_Query();
             $value = '(' . $this->query->createSubquery()->parseQuery($trimmed, false)->getQuery() . ')';
         } elseif (substr($trimmed, 0, 4) == 'SQL:') {
             $value = '(' . substr($trimmed, 4) . ')';
         } else {
             // simple in expression found
             $e = $this->_tokenizer->sqlExplode($trimmed, ',');
             $value = array();
             $index = false;
             foreach ($e as $part) {
                 if (isset($table) && isset($field)) {
                     $index = $table->enumIndex($field, trim($part, "'"));
                 }
                 if ($index !== false) {
                     $value[] = $index;
                 } else {
                     $value[] = $this->parseLiteralValue($part);
                 }
             }
             $value = '(' . implode(', ', $value) . ')';
         }
     } else {
         if (substr($value, 0, 1) == ':' || $value === '?') {
             // placeholder found
             if (isset($table) && isset($field) && $table->getTypeOf($field) == 'enum') {
                 $this->query->addEnumParam($value, $table, $field);
             } else {
                 $this->query->addEnumParam($value, null, null);
             }
         } else {
             $enumIndex = false;
             if (isset($table) && isset($field)) {
                 // check if value is enumerated value
                 $enumIndex = $table->enumIndex($field, trim($value, "'"));
             }
             if ($enumIndex !== false) {
                 $value = $enumIndex;
             } else {
                 $value = $this->parseLiteralValue($value);
             }
         }
     }
     return $value;
 }