/** * Returns the alias for the root class in the EPQ_N_FROM node * (Also set the root class) * @return false|string * @throws epExceptionQueryBuilder */ private function _rootAlias() { // get from node if (!($from = $this->root->getChild('from'))) { throw new epExceptionQueryBuilder($this->_e("Cannot found 'from' clause")); return false; } // get from items if (!($items = $from->getChildren())) { throw new epExceptionQueryBuilder($this->_e("No from items specified")); return false; } // go through each item $isRoot = true; foreach ($items as &$item) { // get class name $class = $item->getParam('class'); // get class map if (!($cm = $this->em->getClassMap($class))) { throw new epExceptionQueryBuilder($this->_e("No class map for class [" . $class . "]")); continue; } // does it have param 'alias' set? if (!($alias = $item->getParam('alias'))) { $alias = $this->generateAlias($class); } // put it into aliases array $this->aliases[$alias] = $class; // set up root class if ($isRoot) { $isRoot = false; $this->root_alias = $alias; $this->root_class = $class; $this->root_cms[] = $cm; // get the db for the class if (!($this->db = $this->em->getDb($class, $cm))) { throw new epExceptionQueryBuilder($this->_e("Cannot found db for root class [" . $class . "]")); continue; } $this->root_classes[] = $cm->getName(); // combine all the children and the root class, so we can // get results for all children $rootClasses = $cm->getChildren(true); foreach ($rootClasses as $rootCm) { $this->root_classes[] = $rootCm->getName(); $this->root_cms[] = $rootCm; } } } // if not generate one return $this->root_alias; }