Exemplo n.º 1
0
 protected function _formatSelect($parentData, $select)
 {
     $select = parent::_formatSelect($parentData, $select);
     if (is_null($select)) {
         return null;
     }
     if ($this->_getUseComponentId()) {
         if ($parentData) {
             $select->whereEquals('component_id', $parentData->dbId);
         } else {
             if ($p = $select->getPart(Kwf_Component_Select::WHERE_CHILD_OF)) {
                 $ors = array(new Kwf_Model_Select_Expr_StartsWith('component_id', $p->dbId . '-'), new Kwf_Model_Select_Expr_Equal('component_id', $p->dbId));
                 foreach ($this->_getPossibleIndirectDbIdShortcuts($p->componentClass) as $dbIdShortcut) {
                     $ors[] = new Kwf_Model_Select_Expr_StartsWith('component_id', $dbIdShortcut);
                 }
                 $select->where(new Kwf_Model_Select_Expr_Or($ors));
             }
         }
     }
     $select = $this->_formatSelectId($select);
     if (is_null($select)) {
         return null;
     }
     if (in_array('pos', $this->_getModel()->getOwnColumns()) && !$select->hasPart(Kwf_Component_Select::ORDER)) {
         $select->order("pos");
     }
     $showInvisible = Kwf_Component_Data_Root::getShowInvisible();
     if (!$select->getPart(Kwf_Component_Select::IGNORE_VISIBLE) && $this->_getModel()->hasColumn('visible') && !$showInvisible) {
         $select->whereEquals("visible", 1);
     }
     if ($select->hasPart(Kwf_Component_Select::WHERE_COMPONENT_CLASSES)) {
         $selectClasses = $select->getPart(Kwf_Component_Select::WHERE_COMPONENT_CLASSES);
         if (!$selectClasses) {
             return null;
         }
         $childClasses = $this->_settings['component'];
         $keys = array();
         foreach ($selectClasses as $selectClass) {
             $keys = array_merge($keys, array_keys($childClasses, $selectClass));
         }
         if (!$keys) {
             return null;
         }
         if (count($childClasses) == 1) {
             if (!in_array(key($childClasses), $keys)) {
                 return null;
             }
         } else {
             if (!$this->_getModel()->hasColumn('component')) {
                 throw new Kwf_Exception("Column component does not exist for a generator '{$this->getGeneratorKey()}' in '{$this->_class}'");
             }
             $select->whereEquals('component', $keys);
         }
     }
     return $select;
 }