protected function _formatConfig($parentData, $row) { $ret = parent::_formatConfig($parentData, $row); //im pages generator fangen die ids immer von vorne an $id = $this->_getIdFromRow($row); if (!is_numeric($id)) { throw new Kwf_Exception("Id must be numeric"); } $idParent = $parentData; while ($idParent->componentClass != $this->_class) { $idParent = $idParent->parent; } $id = $this->_getIdFromRow($row); $ret['componentId'] = $idParent->componentId . $this->getIdSeparator() . $id; $ret['dbId'] = $idParent->dbId . $this->getIdSeparator() . $id; //parent geradebiegen if (!$parentData || $parentData->componentClass == $this->_class && is_numeric($ret['chained']->parent->componentId)) { $c = new Kwf_Component_Select(); $c->ignoreVisible(true); $c->whereId('_' . $ret['chained']->parent->componentId); $parentData = $parentData->getChildComponent($c); } $ret['parent'] = $parentData; return $ret; }
/** * Searches for component datas by it's dbId * * @param string * @param array|Kwf_Component_Select * @return Kwf_Component_Data[] */ public function getComponentsByDbId($dbId, $select = array()) { if (is_array($select)) { $select = new Kwf_Component_Select($select); } $cacheId = $dbId . $select->getHash(); if (!isset($this->_componentsByDbIdCache[$cacheId])) { if (is_numeric(substr($dbId, 0, 1)) || substr($dbId, 0, 4) == 'root') { $data = $this->getComponentById($dbId, $select); if ($data) { return array($data); } else { return array(); } } if ($select->hasPart(Kwf_Component_Select::LIMIT_COUNT)) { $limitCount = $select->getPart(Kwf_Component_Select::LIMIT_COUNT); } $ret = array(); foreach (Kwc_Abstract::getComponentClasses() as $class) { foreach (Kwc_Abstract::getSetting($class, 'generators') as $key => $generator) { if (isset($generator['dbIdShortcut']) && substr($dbId, 0, strlen($generator['dbIdShortcut'])) == $generator['dbIdShortcut']) { $idParts = $this->_getIdParts(substr($dbId, strlen($generator['dbIdShortcut']) - 1)); $generator = Kwf_Component_Generator_Abstract::getInstance($class, $key); if (count($idParts) <= 1) { $generatorSelect = clone $select; } else { $generatorSelect = new Kwf_Component_Select(); // Select erst bei letzten Part if ($select->hasPart(Kwf_Component_Select::IGNORE_VISIBLE)) { $generatorSelect->ignoreVisible($select->getPart(Kwf_Component_Select::IGNORE_VISIBLE)); } if ($select->hasPart(Kwf_Component_Select::WHERE_SUBROOT)) { $generatorSelect->whereSubroot($select->getPart(Kwf_Component_Select::WHERE_SUBROOT)); } } if (isset($limitCount)) { $generatorSelect->limit($limitCount - count($ret)); } $generatorSelect->whereId($idParts[0]); $data = $generator->getChildData(null, $generatorSelect); unset($idParts[0]); foreach ($data as $d) { $componentId = $d->componentId . implode('', $idParts); $data = $this->getComponentById($componentId, $select); if ($data) { $ret[] = $data; } if (isset($limitCount) && $limitCount - count($ret) <= 0) { break 3; } } } } } $this->_componentsByDbIdCache[$cacheId] = $ret; } return $this->_componentsByDbIdCache[$cacheId]; }
public static function getAllChainedByMasterFromChainedStart($componentClass, $master, $chainedType, $parentDataSelect = array()) { if ($chainedType != 'Cc') { return array(); } if (is_array($parentDataSelect)) { $parentDataSelect = new Kwf_Component_Select($parentDataSelect); } static $targets = array(); static $targetIds = array(); if (!isset($targets[$componentClass])) { $targets[$componentClass] = array(); $targetIds[$componentClass] = array(); $s = clone $parentDataSelect; $s->whereSubroot($master); foreach (Kwf_Component_Data_Root::getInstance()->getComponentsBySameClass($componentClass, $s) as $c) { $target = $c->getComponent()->getTargetComponent(); if (!$target) { continue; } $targets[$componentClass][] = array('target' => $target, 'chainedStart' => $c); $targetIds[$componentClass][] = $target->componentId; } } $c = $master; while ($c) { if (in_array($c->componentId, $targetIds[$componentClass])) { break; } $c = $c->parent; } if (!$c) { return array(); } //shortcut: $master is not below $target $ret = array(); foreach ($targets[$componentClass] as $t) { $target = $t['target']; $chainedStart = $t['chainedStart']; $m = $master; $targetReached = false; $ids = array(); while ($m) { $pos = max(strrpos($m->componentId, '-'), strrpos($m->componentId, '_')); $id = substr($m->componentId, $pos); if ($m->componentId == $target->componentId) { $targetReached = true; break; } if ((int) $id > 0) { // nicht mit is_numeric wegen Bindestrich, das als minus interpretiert wird $id = '_' . $id; } $m = $m->parent; if ($m) { $ids[] = $id; } } if (!$targetReached) { continue; } $chainedTarget = $chainedStart->getChildComponent('-target'); if ($chainedTarget->chained == $target) { //targetComponent or child of targetComponent $chained = $chainedTarget; } else { //created by PagesGenerator (which is not child of target comopnent) $chained = $chainedStart; } foreach (array_reverse($ids) as $id) { $parentDataSelect->whereId($id); $chained = $chained->getChildComponent($parentDataSelect); if (!$chained) { break; } } if ($chained) { $ret[] = $chained; } } return $ret; }
public function getPartialVars($partial, $nr, $info) { $ret = $info; if ($partial instanceof Kwf_Component_Partial_Random) { $select = $this->_getSelect()->limit(1, $nr); $ret['item'] = array_shift($this->_getItems($select)); } else { if ($partial instanceof Kwf_Component_Partial_Paging) { if ($partial instanceof Kwf_Component_Partial_Id) { $select = new Kwf_Component_Select(); $select->whereId($nr); } else { if ($partial instanceof Kwf_Component_Partial_Paging) { $select = $this->_getSelect()->limit(1, $nr); } } $items = $this->_getItems($select); $ret['item'] = array_shift($items); } else { throw new Kwf_Exception('Unsupported partial type ' . get_class($partial)); } } $ret['placeholder'] = $this->_getPlaceholder(); $ret['bemClass'] = $this->_getBemClass(''); return $ret; }