Ejemplo n.º 1
0
 public function getChildData($parentData, $select = array())
 {
     if (is_array($select)) {
         $select = new Kwf_Component_Select($select);
     }
     if (!$parentData && !$select->hasPart(Kwf_Component_Select::WHERE_CHILD_OF) && !$select->hasPart(Kwf_Component_Select::WHERE_ID)) {
         $e = new Kwf_Exception("Looking up components generated by List is slow, and must be avoided.");
         $e->logOrThrow();
     }
     return parent::getChildData($parentData, $select);
 }
Ejemplo n.º 2
0
 protected function _formatSelectId(Kwf_Component_Select $select)
 {
     if ($select->hasPart(Kwf_Model_Select::WHERE_ID)) {
         $id = $select->getPart(Kwf_Model_Select::WHERE_ID);
         $select->unsetPart(Kwf_Model_Select::WHERE_ID);
         if (substr($id, 0, 2) == '-l') {
             $select->whereEquals('component', 'link');
         } else {
             if (substr($id, 0, 2) == '-d') {
                 $select->whereEquals('component', 'download');
             } else {
                 if (substr($id, 0, 2) == '-i') {
                     $select->whereEquals('component', 'image');
                 } else {
                     return null;
                 }
             }
         }
         $select->whereEquals('nr', substr($id, 2));
     }
     if ($p = $select->getPart(Kwf_Component_Select::WHERE_CHILD_OF)) {
         $select->where(new Kwf_Model_Select_Expr_Or(array(new Kwf_Model_Select_Expr_StartsWith('component_id', $p->dbId . '-'), new Kwf_Model_Select_Expr_Equal('component_id', $p->dbId))));
     }
     return $select;
 }
Ejemplo n.º 3
0
 public function getChildData($parentData, $select = array())
 {
     if (is_array($select)) {
         $select = new Kwf_Component_Select($select);
     }
     if (($id = $select->getPart(Kwf_Component_Select::WHERE_ID)) && substr($id, 0, 1) == '_') {
         $select->whereId(substr($id, 1));
     }
     if ($parentData) {
         if ($parentData->generator != $this && $parentData->componentClass != $this->getClass()) {
             return array();
         }
     }
     $filename = null;
     $limit = null;
     $ignoreVisible = $select->hasPart(Kwf_Component_Select::IGNORE_VISIBLE) ? $select->getPart(Kwf_Component_Select::IGNORE_VISIBLE) : false;
     if (Kwf_Component_Data_Root::getShowInvisible()) {
         $ignoreVisible = true;
     }
     $select = clone $select;
     // Nach Filename selbst suchen, da ja andere Sprache
     if ($select->hasPart(Kwf_Component_Select::WHERE_FILENAME)) {
         $filename = $select->getPart(Kwf_Component_Select::WHERE_FILENAME);
         $select->unsetPart(Kwf_Component_Select::WHERE_FILENAME);
     }
     // Limit auch selbst beachten, da in slave eigenes visible gesetzt ist
     if ($select->hasPart(Kwf_Component_Select::LIMIT_COUNT)) {
         $limit = $select->getPart(Kwf_Component_Select::LIMIT_COUNT);
         $select->unsetPart(Kwf_Component_Select::LIMIT_COUNT);
     }
     $select->ignoreVisible();
     $ret = array();
     $components = parent::getChildData($parentData, $select);
     foreach ($components as $key => $c) {
         if (($ignoreVisible || $c->visible || $c->isHome) && (!$filename || $c->filename == $filename)) {
             $ret[$key] = $c;
         }
         if ($limit && count($ret) == $limit) {
             return $ret;
         }
     }
     if ($filename) {
         $componentIds = array();
         foreach ($components as $key => $c) {
             $componentIds[$c->dbId] = $key;
         }
         $model = $this->getHistoryModel();
         $select = $model->select()->whereEquals('component_id', array_keys($componentIds))->whereEquals('filename', $filename)->order('date', 'DESC');
         $rows = $model->export(Kwf_Model_Interface::FORMAT_ARRAY, $select, array('columns' => array('component_id')));
         foreach ($rows as $row) {
             $key = $componentIds[$row['component_id']];
             $ret[$key] = $components[$key];
             if ($limit && count($ret) == $limit) {
                 return $ret;
             }
         }
     }
     return $ret;
 }
Ejemplo n.º 4
0
 protected function _formatSelectId(Kwf_Component_Select $select)
 {
     if ($select->hasPart(Kwf_Model_Select::WHERE_ID)) {
         $id = $select->getPart(Kwf_Model_Select::WHERE_ID);
         if (!preg_match('#^_([0-9]{4})$#', $id, $m)) {
             return null;
         }
         $dateColumn = Kwc_Abstract::getSetting($this->_class, 'dateColumn');
         $select->where("YEAR({$dateColumn}) = ?", $m[1]);
         $select->unsetPart(Kwf_Model_Select::WHERE_ID);
     }
     return $select;
 }
Ejemplo n.º 5
0
 protected function _getChainedChildComponents($parentData, Kwf_Component_Select $select)
 {
     $limitCount = $limitOffset = null;
     if ($select->hasPart(Kwf_Component_Select::LIMIT_COUNT) || $select->hasPart(Kwf_Component_Select::LIMIT_OFFSET)) {
         $limitCount = $select->getPart(Kwf_Component_Select::LIMIT_COUNT);
         $limitOffset = $select->getPart(Kwf_Component_Select::LIMIT_OFFSET);
         $select->unsetPart(Kwf_Component_Select::LIMIT_COUNT);
         $select->unsetPart(Kwf_Component_Select::LIMIT_OFFSET);
     }
     $m = $this->getModel();
     $ret = parent::_getChainedChildComponents($parentData, $select);
     if ($m && $select->getPart(Kwf_Component_Select::IGNORE_VISIBLE) !== true && $parentData) {
         //kann nur gemacht werden nur wenn parentData vorhanden
         $ids = array();
         foreach ($ret as $k => $c) {
             $ids[] = $parentData->dbId . $this->getIdSeparator() . $this->_getIdFromRow($c);
         }
         foreach ($this->_getRows($ids) as $r) {
             if ($r) {
                 $visible[$r->component_id] = $r->visible;
             }
         }
         foreach ($ret as $k => $c) {
             $id = $parentData->dbId . $this->getIdSeparator() . $this->_getIdFromRow($c);
             if (!isset($visible[$id]) || !$visible[$id]) {
                 unset($ret[$k]);
             }
         }
     }
     $ret = array_values($ret);
     if ($limitOffset) {
         $ret = array_slice($ret, $limitOffset);
     }
     if ($limitCount) {
         $ret = array_slice($ret, 0, $limitCount);
     }
     return $ret;
 }
Ejemplo n.º 6
0
 public function getChildData($parentData, $select = array())
 {
     if (is_array($select)) {
         $select = new Kwf_Component_Select($select);
     }
     if (($id = $select->getPart(Kwf_Component_Select::WHERE_ID)) && substr($id, 0, 1) == '_') {
         $select->whereId(substr($id, 1));
     }
     if ($parentData) {
         if ($parentData->generator != $this && $parentData->componentClass != $this->getClass()) {
             return array();
         }
     }
     $filename = null;
     $limit = null;
     $ignoreVisible = $select->hasPart(Kwf_Component_Select::IGNORE_VISIBLE) ? $select->getPart(Kwf_Component_Select::IGNORE_VISIBLE) : false;
     if (Kwf_Component_Data_Root::getShowInvisible()) {
         $ignoreVisible = true;
     }
     $select = clone $select;
     // Nach Filename selbst suchen, da ja andere Sprache
     if ($select->hasPart(Kwf_Component_Select::WHERE_FILENAME)) {
         $filename = $select->getPart(Kwf_Component_Select::WHERE_FILENAME);
         $select->unsetPart(Kwf_Component_Select::WHERE_FILENAME);
     }
     // Limit auch selbst beachten, da in slave eigenes visible gesetzt ist
     if ($select->hasPart(Kwf_Component_Select::LIMIT_COUNT)) {
         $limit = $select->getPart(Kwf_Component_Select::LIMIT_COUNT);
         $select->unsetPart(Kwf_Component_Select::LIMIT_COUNT);
     }
     $select->ignoreVisible();
     $ret = array();
     foreach (parent::getChildData($parentData, $select) as $key => $c) {
         if (($ignoreVisible || $c->visible || $c->isHome) && (!$filename || $c->filename == $filename)) {
             $ret[$key] = $c;
         }
         if ($limit && count($ret) == $limit) {
             return $ret;
         }
     }
     return $ret;
 }
Ejemplo n.º 7
0
 protected function _formatSelectFilename(Kwf_Component_Select $select)
 {
     if ($select->hasPart(Kwf_Component_Select::WHERE_FILENAME)) {
         $filename = $select->getPart(Kwf_Component_Select::WHERE_FILENAME);
         if ($this->_settings['uniqueFilename']) {
             $select->whereEquals($this->_settings['filenameColumn'], $filename);
         } else {
             if ($this->_hasNumericIds) {
                 $pattern = '#^([0-9]+)-#';
             } else {
                 $pattern = '#^([^-]+)-#';
             }
             if (!preg_match($pattern, $filename, $m)) {
                 return null;
             }
             $select->whereEquals($this->_idColumn, $m[1]);
         }
     }
     return $select;
 }
 public function getChildData($parentData, $select = array())
 {
     if (is_array($select)) {
         $select = new Kwf_Component_Select($select);
     }
     if (!is_instance_of($this->_class, 'Kwc_Root_Component') && $select->hasPart(Kwf_Component_Select::WHERE_SUBROOT)) {
         //abkürzung wenn mehrere domains mit unterschiedlichen component-Klassen
         //im prinzip gleicher code wie in _GetParentDataByRow wenn return null gemacht wird, aber das hier wird früher gemacht
         $subroot = $select->getPart(Kwf_Component_Select::WHERE_SUBROOT);
         $component = $subroot[0];
         while (!Kwc_Abstract::getFlag($component->componentClass, 'subroot')) {
             $component = $component->parent;
         }
         if ($component->componentClass != $this->getClass()) {
             Kwf_Benchmark::count('GenTable::getChildData skipped');
             return array();
         }
     }
     return parent::getChildData($parentData, $select);
 }
Ejemplo n.º 9
0
 protected function _createData($parentData, $row, $select)
 {
     $id = $this->_getIdFromRow($row);
     if (is_array($select)) {
         $select = new Kwf_Component_Select($select);
     }
     if ($select && $select->hasPart('whereSubroot')) {
         foreach ($select->getPart('whereSubroot') as $subroot) {
             $subrootLevel = 0;
             $c = $subroot;
             while ($c) {
                 $subrootLevel++;
                 $c = $c->parent;
             }
             $parentLevel = 0;
             if (!is_object($parentData)) {
                 $parentData = Kwf_Component_Data_Root::getInstance()->getComponentById($parentData, array('ignoreVisible' => true));
             }
             $c = $parentData;
             while ($c) {
                 $parentLevel++;
                 $c = $c->parent;
             }
             if ($parentLevel >= $subrootLevel) {
                 $compareData = $parentData;
                 for ($x = 0; $x < $parentLevel - $subrootLevel; $x++) {
                     $compareData = $compareData->parent;
                 }
                 if ($compareData->componentId != $subroot->componentId) {
                     return null;
                 }
                 break;
             }
         }
     }
     $componentId = $this->_getComponentIdFromRow($parentData, $row);
     $ret = Kwf_Component_Data_Root::getInstance()->getFromDataCache($componentId);
     if (!$ret) {
         $config = $this->_formatConfig($parentData, $row);
         if (!$config) {
             return null;
         }
         if (!$config['componentClass'] || !is_string($config['componentClass'])) {
             throw new Kwf_Exception("no componentClass set (id {$parentData->componentId} {$id})");
         }
         $config['id'] = $id;
         if (isset($config['inherits'])) {
             throw new Kwf_Exception("You must set Generator::_inherits instead of magically modifying the config");
         }
         if ($this->_inherits) {
             $config['inherits'] = true;
         }
         $config['generator'] = $this;
         //wird benötigt für duplizieren
         $pageDataClass = $this->_getDataClass($config, $row);
         $ret = new $pageDataClass($config);
         Kwf_Component_Data_Root::getInstance()->addToDataCache($ret, $select->getPart(Kwf_Component_Select::IGNORE_VISIBLE));
     }
     return $ret;
 }
Ejemplo n.º 10
0
 public function getChildData($parentData, $select = array())
 {
     Kwf_Benchmark::count('GenStaticSelect::getChildData');
     if (is_array($select)) {
         $select = new Kwf_Component_Select($select);
     }
     if ($select->hasPart(Kwf_Component_Select::WHERE_COMPONENT_CLASSES)) {
         $continue = false;
         foreach ($select->getPart(Kwf_Component_Select::WHERE_COMPONENT_CLASSES) as $componentClass) {
             if (in_array($componentClass, $this->getChildComponentClasses())) {
                 $continue = true;
             }
         }
         if (!$continue) {
             return array();
         }
     }
     if (!$parentData) {
         if (!$select->hasPart(Kwf_Component_Select::WHERE_COMPONENT_CLASSES)) {
             throw new Kwf_Exception_NotYetImplemented();
         }
         $selectClasses = $select->getPart(Kwf_Component_Select::WHERE_COMPONENT_CLASSES);
         $possibleClasses = $this->getChildComponentClasses();
         if (in_array(array_shift($possibleClasses), $selectClasses)) {
             throw new Kwf_Exception("You can't search for component which is first (=default) in StaticSelect");
         }
         $searchFor = array();
         foreach ($selectClasses as $c) {
             $searchFor[] = array_search($c, $possibleClasses);
         }
         $s = new Kwf_Model_Select();
         $s->whereEquals('component', $searchFor);
         $s->where(new Kwf_Model_Select_Expr_Like('component_id', '%-' . $this->getGeneratorKey()));
         $rows = $this->_getModel()->export(Kwf_Model_Abstract::FORMAT_ARRAY, $s, array('columns' => array('component_id')));
         $parentDatas = array();
         foreach ($rows as $row) {
             $id = substr($row['component_id'], 0, -(strlen($this->getGeneratorKey()) + 1));
             $s = new Kwf_Component_Select();
             $s->copyParts(array(Kwf_Component_Select::IGNORE_VISIBLE, Kwf_Component_Select::WHERE_SUBROOT), $select);
             $d = Kwf_Component_Data_Root::getInstance()->getComponentByDbId($id, $s);
             if ($d) {
                 $parentDatas[] = $d;
             }
         }
     } else {
         $parentDatas = array($parentData);
     }
     $ret = array();
     foreach ($parentDatas as $parentData) {
         $data = $this->_createData($parentData, $this->getGeneratorKey(), $select);
         if (!$data) {
             continue;
         }
         if ($select->hasPart('whereId')) {
             if ('-' . $data->id != $select->getPart('whereId')) {
                 continue;
             }
         }
         $ret[] = $data;
     }
     return $ret;
 }
Ejemplo n.º 11
0
 protected function _formatSelectId(Kwf_Component_Select $select)
 {
     if ($select->hasPart(Kwf_Model_Select::WHERE_ID)) {
         $id = $select->getPart(Kwf_Model_Select::WHERE_ID);
         $separator = substr($id, 0, 1);
         if (in_array($separator, array('_', '-'))) {
             $id = substr($id, 1);
             if ($separator != $this->_idSeparator || $this->_hasNumericIds && !is_numeric($id)) {
                 return null;
             }
             $select->whereEquals($this->_idColumn, $id);
             $select->unsetPart(Kwf_Model_Select::WHERE_ID);
         }
     }
     return $select;
 }
Ejemplo n.º 12
0
 public function getChildData($parentData, $select = array())
 {
     Kwf_Benchmark::count('GenCards::getChildData');
     if (is_array($select)) {
         $select = new Kwf_Component_Select($select);
     }
     //es gibt exakt eine unterkomponente mit der id 'child'
     if ($select->hasPart(Kwf_Component_Select::WHERE_ID)) {
         if ($select->getPart(Kwf_Component_Select::WHERE_ID) != '-child') {
             return array();
         }
     }
     $ret = array();
     if (!$parentData) {
         if ($select->hasPart(Kwf_Component_Select::WHERE_COMPONENT_CLASSES)) {
             $cc = $select->getPart(Kwf_Component_Select::WHERE_COMPONENT_CLASSES);
             $componentValues = array_keys(array_intersect($this->_settings['component'], $cc));
             if (!$componentValues) {
                 throw new Kwf_Exception("no component classes found in this generator, should not have been clled");
             }
             reset($this->_settings['component']);
             if (in_array(current($this->_settings['component']), $cc)) {
                 throw new Kwf_Exception("can't get the first=default component without parentData as it might be not in the database");
             }
             $s = new Kwf_Model_Select();
             $s->whereEquals('component', $componentValues);
             if ($p = $select->getPart(Kwf_Component_Select::WHERE_CHILD_OF)) {
                 $ors = array(new Kwf_Model_Select_Expr_And(array(new Kwf_Model_Select_Expr_Like('component_id', $p->dbId . '%'), new Kwf_Model_Select_Expr_RegExp('component_id', '^' . $p->dbId . '[-_][^_]+$'))));
                 foreach ($this->_getPossibleIndirectDbIdShortcuts($p->componentClass) as $dbIdShortcut) {
                     $ors[] = new Kwf_Model_Select_Expr_StartsWith('component_id', $dbIdShortcut);
                 }
                 $s->where(new Kwf_Model_Select_Expr_Or($ors));
             }
             if ($subRoots = $select->getPart(Kwf_Component_Select::WHERE_SUBROOT)) {
                 foreach ($subRoots as $subRoot) {
                     $s->where(new Kwf_Model_Select_Expr_Like('component_id', $subRoot->dbId . '%'));
                 }
             }
             $data = $this->_getModel()->export(Kwf_Model_Abstract::FORMAT_ARRAY, $s, array('columns' => array('component_id')));
             $parentData = array();
             $s = new Kwf_Component_Select();
             $s->copyParts(array(Kwf_Component_Select::IGNORE_VISIBLE), $select);
             foreach ($data as $i) {
                 foreach (Kwf_Component_Data_Root::getInstance()->getComponentsByDbId($i['component_id'] . '-child', $s) as $d) {
                     if ($d->parent->componentClass == $this->_class) {
                         $ret[] = $d;
                     }
                 }
             }
         } else {
             throw new Kwf_Exception_NotYetImplemented();
         }
         return $ret;
     }
     $pData = $parentData;
     $parentDatas = is_array($parentData) ? $parentData : array($parentData);
     foreach ($this->_fetchKeys($pData, $select) as $key) {
         foreach ($parentDatas as $parentData) {
             $data = $this->_createData($parentData, $key, $select);
             if ($data) {
                 $ret[] = $data;
             }
         }
     }
     return $ret;
 }