Пример #1
0
 /**
  * Builds SQL statement from 'variable' node
  * 
  * The returning array is an associative array keyed by the primitive
  * variable in the form of '<alias>.<var_name>' and the value is the
  * condition for the relationship fields. 
  * 
  * @return false|array
  * @throws epExceptionQueryBuilder
  */
 protected function buildSqlVariable(epQueryNode &$node)
 {
     // check if path is set on variable node
     if (!($path = trim($node->getParam('path')))) {
         throw new epExceptionQueryBuilder($this->_e("no path for varialbe", $node));
         return false;
     }
     // the varialbe name is the last item
     $pieces = explode('.', $path);
     $var = $pieces[count($pieces) - 1];
     // array to hold SQL expressions for primitive vars
     $pvars = array();
     // if the path points to an object
     if ($this->pm->isObject($path)) {
         // force it to oid
         $var = 'oid';
     }
     // call path manager to get aliases
     if ($aliases = $this->pm->getAliases($path)) {
         foreach ($aliases as $alias) {
             $pvars[] = $this->pm->quoteId($alias) . '.' . $this->pm->quoteId($var);
         }
     }
     return $pvars;
 }
 /**
  * Builds SQL statement from 'variable' node
  * 
  * The returning array is an associative array keyed by the primitive
  * variable in the form of '<alias>.<var_name>' and the value is the
  * condition for the relationship fields. 
  * 
  * @return false|array
  * @throws epExceptionQueryBuilder
  */
 protected function buildSqlVariable(epQueryNode &$node)
 {
     // get all field maps
     if (!($fms = $node->getParam('fmaps'))) {
         throw new epExceptionQueryBuilder($this->_e("[Internal] Cannot find field maps", $node));
         return false;
     }
     // array to keep wheres for reltaionship field
     $wheres_r = array();
     $where_prim = false;
     // go through each field map
     foreach ($fms as $fm) {
         // is it a primary field?
         if ($fm instanceof epFieldMapPrimitive) {
             // if not, time to break
             $where_prim = $this->_buildSqlFieldMapPrimitive($fm);
             break;
         }
         // build sql from field map
         if (!($wheres = $this->_buildSqlFieldMapRelationship($fm))) {
             throw new epExceptionQueryBuilder($this->_e("[Internal] empty where expressions", $node));
             continue;
         }
         // is it an error message?
         if (is_string($wheres)) {
             throw new epExceptionQueryBuilder($this->_e($wheres, $node));
             continue;
         }
         // collect wheres
         $wheres_r[] = $wheres;
     }
     // compute Cartesian product for relationship field
     $wheres = array($node->getParam('alias') => '');
     foreach ($wheres_r as $wheres_) {
         $wheres = $this->_cartesianProduct($wheres, $wheres_);
     }
     // no primitive 'where' for?
     if (!$where_prim) {
         // return now if so
         return $wheres;
     }
     // finally put together with primitive var
     $results = array();
     foreach ($wheres as $alias => $where) {
         $where_prim = str_replace(self::DUMMY_ALIAS, $alias, $where_prim);
         $results[$where_prim] = $where;
     }
     return $results;
 }