public function getChildData($parentData, $select = array()) { Kwf_Benchmark::count('GenStatic::getChildData'); if (is_array($select)) { $select = new Kwf_Component_Select($select); } $pData = $parentData; $ret = array(); if ($p = $select->getPart(Kwf_Component_Select::WHERE_ID)) { if (!$this->_idMatches($p)) { return $ret; } } if (!$parentData) { if ($p = $select->getPart(Kwf_Component_Select::WHERE_CHILD_OF)) { throw new Kwf_Exception("this must not happen"); $p = $p->getPageOrRoot(); $parentData = $p->getRecursiveChildComponents(array('componentClass' => $this->_class)); } else { $parentSelect = new Kwf_Component_Select(); $parentSelect->copyParts(array(Kwf_Component_Select::WHERE_SUBROOT, Kwf_Component_Select::IGNORE_VISIBLE, Kwf_Component_Select::WHERE_CHILD_OF), $select); $parentData = Kwf_Component_Data_Root::getInstance()->getComponentsBySameClass($this->_class, $parentSelect); } } $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; }
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; }
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; }
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; }
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; }
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; }
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(); } } return parent::getChildData($parentData, $select); }
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); }
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; }
public function getChildData($parentDatas, $select = array()) { Kwf_Benchmark::count('GenChained::getChildData'); $ret = array(); if (is_array($select)) { $select = new Kwf_Component_Select($select); } $chainedType = $this->getGeneratorFlag('chainedType'); $slaveData = $select->getPart(Kwf_Component_Select::WHERE_CHILD_OF); while ($slaveData) { if (Kwc_Abstract::getFlag($slaveData->componentClass, 'chainedType') == $chainedType) { break; } $slaveData = $slaveData->parent; } $parentDataSelect = new Kwf_Component_Select(); $parentDataSelect->copyParts(array('ignoreVisible'), $select); $parentDatas = is_array($parentDatas) ? $parentDatas : array($parentDatas); foreach ($parentDatas as $parentData) { foreach ($this->_getChainedChildComponents($parentData, $select) as $component) { $pData = array(); if (!$parentData) { if (!$slaveData) { $pData = Kwc_Chained_Abstract_Component::getAllChainedByMaster($component->parent, $chainedType, $parentDataSelect); } else { $chainedComponent = Kwc_Chained_Abstract_Component::getChainedByMaster($component->parent, $slaveData, $chainedType, $parentDataSelect); if ($chainedComponent) { $pData = array($chainedComponent); } } } else { $pData = array($parentData); } foreach ($pData as $d) { $data = $this->_createData($d, $component, $select); if ($data) { $ret[] = $data; } } } } return $ret; }
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; }
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; }
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; }