Ejemplo n.º 1
0
 /**
  * Builds SQL statement from 'contains' or alias assignment node
  * @param epQueryNode &$node either a 'contains' node or an assignment node
  * @param epFieldMap $fm the starting field map
  * @param array $var_exprs expressions for var
  * @param array|epObject $arg the argument|value for the operation
  * @return false|string
  * @throws epExceptionQueryBuilder
  */
 protected function _buildSqlRelationship(epQueryNode &$node, $fm, $var_exprs, $arg)
 {
     // is arg a string
     if (is_string($arg)) {
         // go through each where (notice &)
         foreach ($var_exprs as $alias => &$expr) {
             // remove last alias
             $expr = str_replace($alias, $arg, $expr);
             // remove this alias (important)
             unset($this->aliases[$alias]);
         }
         return implode(' OR ', $var_exprs);
     } else {
         if (is_array($arg) || $arg instanceof epObject) {
             // convert array to an object
             $o = $arg;
             if (is_array($arg)) {
                 // false: no event dispatching, true: null vars if no value
                 $o =& $this->em->createFromArray($fm->getClass(), $arg, false, true);
                 // object and children not to be committed
                 $o->epSetCommittable(false, true);
             }
             // array to keep all expressions
             $exprs = array();
             // go through each var exprs
             foreach ($var_exprs as $var_alias => $var_expr) {
                 // build sql for array or object
                 $obj_exprs = $this->_buildSqlObject($o, $fm, $var_alias);
                 // go through each returned expr from the array or object
                 foreach ($obj_exprs as $obj_expr) {
                     $exprs[] = $obj_expr . ' AND ' . $var_expr;
                 }
             }
             return implode(' OR ', $exprs);
         }
     }
     // unrecognized
     throw new epExceptionQueryBuilder($this->_e("Unrecognized argument in 'contains()'", $node));
     return false;
 }