示例#1
0
 /**
  * applyInheritance
  * applies column aggregation inheritance to DQL / SQL query
  *
  * @return string
  */
 public function applyInheritance()
 {
     // get the inheritance maps
     $array = array();
     foreach ($this->_aliasMap as $componentAlias => $data) {
         $tableAlias = $this->getTableAlias($componentAlias);
         $array[$tableAlias][] = $data['table']->inheritanceMap;
     }
     // apply inheritance maps
     $str = '';
     $c = array();
     $index = 0;
     foreach ($array as $tableAlias => $maps) {
         $a = array();
         // don't use table aliases if the query isn't a select query
         if ($this->type !== Doctrine_Query::SELECT) {
             $tableAlias = '';
         } else {
             $tableAlias .= '.';
         }
         foreach ($maps as $map) {
             $b = array();
             foreach ($map as $field => $value) {
                 $identifier = $this->_conn->quoteIdentifier($tableAlias . $field);
                 if ($index > 0) {
                     $b[] = '(' . $identifier . ' = ' . $value . ' OR ' . $identifier . ' IS NULL)';
                 } else {
                     $b[] = $identifier . ' = ' . $value;
                 }
             }
             if (!empty($b)) {
                 $a[] = implode(' AND ', $b);
             }
         }
         if (!empty($a)) {
             $c[] = implode(' AND ', $a);
         }
         $index++;
     }
     $str .= implode(' AND ', $c);
     return $str;
 }