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; }
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; }
/** * Returns child components recursively * * This method usually is very efficient and tries to create as less data objects as possible. * It is still a complex operation thus should not get called too often. * * @param Kwf_Component_Select|array what to search for * @param Kwf_Component_Select|array how deep to search * @return array(Kwf_Component_Data) */ public function getRecursiveChildComponents($select = array(), $childSelect = array('page' => false)) { if (is_array($select)) { $select = new Kwf_Component_Select($select); } else { $select = clone $select; } Kwf_Benchmark::count('getRecursiveChildComponents'); if (is_array($childSelect)) { $childSelect = new Kwf_Component_Select($childSelect); } $ret = $this->getChildComponents($select); if ($select->hasPart('limitCount') && $select->getPart('limitCount') <= count($ret)) { return $ret; } $genSelect = new Kwf_Component_Select(); $genSelect->copyParts(array(Kwf_Component_Select::WHERE_HOME, Kwf_Component_Select::WHERE_PAGE, Kwf_Component_Select::WHERE_PSEUDO_PAGE, Kwf_Component_Select::WHERE_FLAGS, Kwf_Component_Select::WHERE_BOX, Kwf_Component_Select::WHERE_MULTI_BOX, Kwf_Component_Select::WHERE_SHOW_IN_MENU, Kwf_Component_Select::WHERE_COMPONENT_CLASSES, Kwf_Component_Select::WHERE_PAGE_GENERATOR, Kwf_Component_Select::WHERE_GENERATOR, Kwf_Component_Select::WHERE_HAS_EDIT_COMPONENTS, Kwf_Component_Select::WHERE_INHERIT, Kwf_Component_Select::WHERE_UNIQUE, Kwf_Component_Select::WHERE_GENERATOR_CLASS, Kwf_Component_Select::WHERE_COMPONENT_KEY), $select); $selectHash = md5($genSelect->getHash() . $childSelect->getHash()); $cacheId = 'recCCGen-' . $selectHash . $this->componentClass . implode('__', $this->inheritClasses); $generators = Kwf_Cache_SimpleStatic::fetch($cacheId, $success); if (!$success) { //get (statically=fast and cached) all generators that could create the component we are looking for $generators = $this->_getRecursiveGenerators(Kwc_Abstract::getChildComponentClasses($this, $childSelect), $genSelect, $childSelect, $selectHash); Kwf_Cache_SimpleStatic::add($cacheId, $generators); } $noSubPages = $childSelect->hasPart('wherePage') && !$childSelect->getPart('wherePage') || $childSelect->hasPart('wherePseudoPage') && !$childSelect->getPart('wherePseudoPage'); if ($noSubPages) { $select->whereChildOf($this); } else { $select->whereSubroot($this); } foreach ($generators as $g) { if ($g['type'] == 'notStatic') { $gen = Kwf_Component_Generator_Abstract::getInstance($g['class'], $g['key']); $s = clone $select; if (!$noSubPages) { //unset limit as we may have filter away results $s->unsetPart('limitCount'); } foreach ($gen->getChildData(null, $s) as $d) { $add = true; if (!$noSubPages) { // sucht über unterseiten hinweg, wird hier erst im Nachhinein gehandelt, langsam $add = false; $c = $d; while (!$add && $c) { if ($c->componentId == $this->componentId) { $add = true; } $c = $c->parent; } } if ($add && !in_array($d, $ret, true)) { $ret[] = $d; if ($select->hasPart('limitCount') && $select->getPart('limitCount') <= count($ret)) { return $ret; } } } } } foreach ($generators as $k => $g) { if ($g['type'] == 'cards') { $lookingForDefault = true; if ($select->hasPart('whereComponentClasses')) { $gen = Kwf_Component_Generator_Abstract::getInstance($g['class'], $g['key'], array(), $g['pluginBaseComponentClass']); $classes = array_values($gen->getChildComponentClasses()); $defaultCardClass = $classes[0]; if (!in_array($defaultCardClass, $select->getPart('whereComponentClasses'))) { $lookingForDefault = false; } } if ($lookingForDefault) { //we have to look for it like for a static component because it's the default value that might not be in the table //this is not so efficient $generators[$k]['type'] = 'static'; //(kind of hackish to change the type here but works for now) } else { $gen = Kwf_Component_Generator_Abstract::getInstance($g['class'], $g['key'], array(), $g['pluginBaseComponentClass']); foreach ($gen->getChildData(null, clone $select) as $d) { $ret[] = $d; if ($select->hasPart('limitCount') && $select->getPart('limitCount') <= count($ret)) { return $ret; } } } } } $staticGeneratorComponentClasses = array(); foreach ($generators as $k => $g) { if ($g['type'] == 'static') { if ($g['pluginBaseComponentClass']) { $staticGeneratorComponentClasses[] = $g['pluginBaseComponentClass']; } else { $staticGeneratorComponentClasses[] = $g['class']; } } } if ($staticGeneratorComponentClasses) { $pdSelect = clone $childSelect; $pdSelect->whereComponentClasses($staticGeneratorComponentClasses); $pdSelect->copyParts(array('ignoreVisible'), $select); $pd = $this->getRecursiveChildComponents($pdSelect, $childSelect); foreach ($generators as $k => $g) { if ($g['type'] == 'static') { $parentDatas = array(); foreach ($pd as $d) { if ($d->componentClass == $g['class'] || $d->componentClass == $g['pluginBaseComponentClass']) { $parentDatas[] = $d; } } if ($parentDatas) { $gen = Kwf_Component_Generator_Abstract::getInstance($g['class'], $g['key'], array(), $g['pluginBaseComponentClass']); foreach ($gen->getChildData($parentDatas, $select) as $d) { if (!in_array($d, $ret, true)) { $ret[] = $d; if ($select->hasPart('limitCount') && $select->getPart('limitCount') <= count($ret)) { return $ret; } } } } } } } return $ret; }
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; }