public static function getListHtml(Kwf_Component_Renderer_Abstract $renderer, Kwf_Component_Data $c, $level, $levels, $className)
 {
     $ret = '';
     $level++;
     $select = new Kwf_Component_Select();
     $select->whereShowInMenu(true);
     $ret .= '<ul class="' . self::getBemClass($className, 'sitemapListLevel' . $level) . '">' . "\n";
     $count = 1;
     foreach ($c->getChildPages($select) as $child) {
         $ret .= '<li class="' . self::getBemClass($className, 'sitemapListItemLevel' . $level);
         if ($count % 3 === 0) {
             $ret .= ' ' . self::getBemClass($className, '--third');
         }
         if ($count % 2 === 0) {
             $ret .= ' ' . self::getBemClass($className, '--second');
         }
         if (!$child->getChildPages($select)) {
             $ret .= ' ' . self::getBemClass($className, '--noChild');
         }
         $ret .= '">';
         $helper = new Kwf_Component_View_Helper_ComponentLink();
         $helper->setRenderer($renderer);
         $ret .= $helper->componentLink($child);
         $ret .= "\n";
         if ($level < $levels) {
             $ret .= self::getListHtml($renderer, $child, $level, $levels, $className);
         }
         $ret .= "</li>\n";
         $count++;
     }
     $ret .= "</ul>\n";
     return $ret;
 }
Esempio n. 2
0
 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 _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;
 }
 public function getTemplateVars(Kwf_Component_Renderer_Abstract $renderer)
 {
     $ret = parent::getTemplateVars($renderer);
     $ret['product'] = $this->getData()->row;
     $ret['item'] = $ret['product']->getItem();
     $ret['similarProducts'] = array();
     if ($ret['item']->SimilarProducts) {
         foreach ($ret['item']->SimilarProducts as $p) {
             $p = $ret['product']->getModel()->getRow($p->ASIN);
             foreach ($p->getChildRows('ProductsToNodes') as $n) {
                 $s = new Kwf_Component_Select();
                 $s->whereEquals('node_id', $n->node_id);
                 $s->whereGenerator('detail');
                 if ($this->getData()->parent->parent->countChildComponents($s)) {
                     $ret['similarProducts'][] = $this->getData()->parent->getChildComponent('_' . $p->asin);
                     break;
                 }
             }
         }
     }
     $ret['nodes'] = array();
     $nodes = $ret['product']->getChildRows('ProductsToNodes');
     foreach ($nodes as $node) {
         $s = new Kwf_Component_Select();
         $s->whereEquals('node_id', $node->node_id);
         $s->whereGenerator('detail');
         $node = $this->getData()->parent->parent->getChildComponent($s);
         if ($node) {
             $ret['nodes'][] = $node;
         }
     }
     return $ret;
 }
 public static function getListHtml(Kwf_Component_Renderer_Abstract $renderer, Kwf_Component_Data $c, $level, $levels)
 {
     $ret = '';
     $level++;
     $select = new Kwf_Component_Select();
     $select->whereShowInMenu(true);
     $ret .= "<ul>\n";
     foreach ($c->getChildPages($select) as $child) {
         $noChild = '';
         if (!$child->getChildPages($select)) {
             $noChild = 'noChild';
         }
         $ret .= '<li class="' . $noChild . '">';
         $helper = new Kwf_Component_View_Helper_ComponentLink();
         $helper->setRenderer($renderer);
         $ret .= $helper->componentLink($child);
         $ret .= "\n";
         if ($level < $levels) {
             $ret .= self::getListHtml($renderer, $child, $level, $levels);
         }
         $ret .= "</li>\n";
     }
     $ret .= "</ul>\n";
     return $ret;
 }
 public function setComponentId($componentId)
 {
     $c = Kwf_Component_Data_Root::getInstance()->getComponentByDbId($componentId, array('ignoreVisible' => true));
     $s = new Kwf_Component_Select();
     $s->ignoreVisible();
     $s->whereGenerator('detail');
     foreach ($c->getChildComponents($s) as $c) {
         $this->_data[$c->componentId] = array('id' => $c->chained->row->id, 'component_id' => $componentId, 'original_name' => $c->chained->row->name, 'name' => $c->row->name, 'row' => $c->row, 'visible' => $c->row->visible);
     }
 }
 public function getPartialVars($partial, $nr, $info)
 {
     if (!$partial instanceof Kwf_Component_Partial_Random) {
         throw new Kwf_Exception('Only Kwf_Component_Partial_Random supported');
     }
     $select = new Kwf_Component_Select();
     $select->whereGenerator('child');
     $select->limit(1, $nr);
     return array('child' => $this->getData()->getChildComponent($select));
 }
 public function setComponentId($componentId)
 {
     $c = Kwf_Component_Data_Root::getInstance()->getComponentByDbId($componentId, array('ignoreVisible' => true));
     $s = new Kwf_Component_Select();
     $s->ignoreVisible();
     $s->whereGenerator('child');
     $i = 0;
     foreach ($c->getChildComponents($s) as $c) {
         $this->_data[$c->componentId] = array('id' => $c->chained->row->id, 'pos' => $i++, 'component_id' => $componentId, 'row' => $c->row, 'name' => $c->targetPage->name);
     }
 }
 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);
 }
Esempio n. 10
0
 public function setComponentId($componentId)
 {
     $c = Kwf_Component_Data_Root::getInstance()->getComponentByDbId($componentId, array('ignoreVisible' => true));
     $s = new Kwf_Component_Select();
     $s->ignoreVisible();
     $s->whereGenerator('child');
     foreach ($c->getChildComponents($s) as $c) {
         $row = $c->generator->getTrlRowByData($c);
         $this->_data[$c->componentId] = array('id' => $c->chained->row->id, 'component_id' => $componentId, 'row' => $row, 'pos' => isset($c->chained->row->pos) ? $c->chained->row->pos : null);
         foreach ($this->_translateFields as $tf) {
             $this->_data[$c->componentId][$tf] = $row->{$tf};
         }
     }
 }
Esempio n. 11
0
 public function setComponentId($componentId)
 {
     $c = Kwf_Component_Data_Root::getInstance()->getComponentByDbId($componentId, array('ignoreVisible' => true));
     $s = new Kwf_Component_Select();
     $s->ignoreVisible();
     $s->whereGenerator('paragraphs');
     $chainedModel = Kwc_Abstract::createChildModel($c->componentClass);
     foreach ($c->getChildComponents($s) as $c) {
         $chainedRow = $chainedModel->getRow($c->dbId);
         if (!$chainedRow) {
             $chainedRow = $chainedModel->createRow(array('component_id' => $c->dbId, 'visible' => false));
         }
         $this->_data[$c->componentId] = array('id' => $c->chained->row->id, 'component_id' => $componentId, 'component_class' => $c->componentClass, 'component_name' => Kwf_Trl::getInstance()->trlStaticExecute(Kwc_Abstract::getSetting($c->componentClass, 'componentName')), 'component_icon' => (string) new Kwf_Asset(Kwc_Abstract::getSetting($c->componentClass, 'componentIcon')), 'row' => $chainedRow, 'visible' => $chainedRow->visible, 'pos' => $c->chained->row->pos);
     }
 }
Esempio n. 12
0
 public function getSelect()
 {
     $select = parent::getSelect();
     if (!$select) {
         return null;
     }
     $s = new Kwf_Component_Select();
     $s->whereGenerator('categories');
     $tableName = Kwc_Abstract::getSetting($this->getItemDirectory()->getChildComponent($s)->componentClass, 'categoryToItemModelName');
     $refData = Kwc_Directories_Category_Detail_List_Component::getTableReferenceData($tableName, 'Item');
     $select->join($refData['tableName'], $refData['tableName'] . '.' . $refData['itemColumn'] . '=' . $refData['refTableName'] . '.' . $refData['refItemColumn'], array());
     $ids = $this->getCategoryIds();
     if (!$ids) {
         return null;
     }
     $select->where($refData['tableName'] . '.category_id IN (' . implode(',', $ids) . ')');
     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);
 }
Esempio n. 14
0
 public function getTemplateVars()
 {
     $ret = parent::getTemplateVars();
     $ret['title'] = $this->getData()->row->title;
     $ret['publish_date'] = $this->getData()->row->publish_date;
     $ret['author'] = $this->getData()->row->author_firstname . ' ' . $this->getData()->row->author_lastname;
     if ($this->_getPlaceholder('nextLink')) {
         $s = new Kwf_Component_Select();
         $s->whereGenerator('detail');
         $s->order('publish_date', 'ASC');
         $s->where(new Kwf_Model_Select_Expr_Higher('publish_date', new Kwf_Date($this->getData()->row->publish_date)));
         $ret['nextPost'] = $this->getData()->parent->getChildComponent($s);
     }
     if ($this->_getPlaceholder('previousLink')) {
         $s = new Kwf_Component_Select();
         $s->whereGenerator('detail');
         $s->order('publish_date', 'DESC');
         $s->where(new Kwf_Model_Select_Expr_Lower('publish_date', new Kwf_Date($this->getData()->row->publish_date)));
         $ret['previousPost'] = $this->getData()->parent->getChildComponent($s);
     }
     return $ret;
 }
Esempio n. 15
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})([0-9]{2})$#', $id, $m)) {
             return null;
         }
         $dateColumn = Kwc_Abstract::getSetting($this->_class, 'dateColumn');
         $select->where("YEAR({$dateColumn}) = ?", $m[1]);
         $select->where("MONTH({$dateColumn}) = ?", $m[2]);
         $select->unsetPart(Kwf_Model_Select::WHERE_ID);
     }
     return $select;
 }
Esempio n. 16
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;
 }
Esempio n. 17
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;
 }
Esempio n. 18
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;
 }
Esempio n. 19
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;
 }
Esempio n. 20
0
 protected function _getMenuPages($parentData, $select)
 {
     if (is_array($select)) {
         $select = new Kwf_Component_Select($select);
     }
     $select->whereShowInMenu(true);
     $ret = array();
     if ($parentData) {
         $pageComponent = $parentData;
     } else {
         $pageComponent = $this->getData();
         while ($pageComponent = $pageComponent->parent) {
             if ($pageComponent->isPage) {
                 break;
             }
             if (Kwc_Abstract::getFlag($pageComponent->componentClass, 'menuCategory')) {
                 break;
             }
         }
     }
     if ($pageComponent) {
         $ret = $pageComponent->getChildPages($select);
     }
     return $ret;
 }
Esempio n. 21
0
 protected function _getSelect()
 {
     $select = new Kwf_Component_Select();
     $select->whereGenerator('child');
     return $select;
 }
Esempio n. 22
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;
 }
Esempio n. 23
0
 /**
  * Returns all components matching a component class (including classes inheriting that class)
  *
  * Use with care, this is only efficient if a few components exist.
  *
  * @see getComponentsBySameClass
  * @param string|array component class
  * @param array|Kwf_Component_Select
  * @return Kwf_Component_Data[]
  */
 public function getComponentsByClass($class, $select = array())
 {
     if (is_array($select)) {
         $select = new Kwf_Component_Select($select);
     }
     $cacheId = (is_array($class) ? implode(',', $class) : $class) . $select->getHash();
     if (!isset($this->_componentsByClassCache[$cacheId])) {
         $lookingForChildClasses = Kwc_Abstract::getComponentClassesByParentClass($class);
         $ret = $this->getComponentsBySameClass($lookingForChildClasses, $select);
         $this->_componentsByClassCache[$cacheId] = $ret;
     }
     return $this->_componentsByClassCache[$cacheId];
 }
Esempio n. 24
0
 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;
 }
Esempio n. 25
0
 /**
  * Returns a single child pseudo page
  *
  * @see getChildPseudoPages
  * @return Kwf_Component_Data
  */
 public function getChildPseudoPage($select = array())
 {
     if (is_array($select)) {
         $select = new Kwf_Component_Select($select);
     }
     $select->limit(1);
     $ret = $this->getChildPseudoPages($select);
     if (!$ret) {
         return null;
     }
     return current($ret);
 }
Esempio n. 26
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;
 }
Esempio n. 27
0
 /**
  * Returns indirect child component classes of a componentclass or a componentData
  *
  * @param string|Kwf_Component_Data if data inherited generators are returned as well
  * @param array Optional filtering (string to get for one generator)
  */
 public static function getIndirectChildComponentClasses($class, $select = array())
 {
     if (is_array($select)) {
         $select = new Kwf_Component_Select($select);
     }
     $cacheId = $select->getHash();
     $ret = self::_getIndirectChildComponentClasses($class, $select, $cacheId);
     return $ret;
 }
Esempio n. 28
0
 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;
 }
Esempio n. 29
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;
 }
 public static function getMediaOutput($id, $type, $className)
 {
     $s = new Kwf_Component_Select();
     $s->ignoreVisible(true);
     $component = Kwf_Component_Data_Root::getInstance()->getComponentByDbId($id, $s);
     $row = $component->getComponent()->getRow();
     if ($type == 'webm') {
         $uploadRow = $row->getParentRow('FileWebm');
         $mimeType = 'video/webm';
     } else {
         if ($type == 'mp4') {
             $uploadRow = $row->getParentRow('FileMp4');
             $mimeType = 'video/mp4';
         } else {
             if ($type == 'ogg') {
                 $uploadRow = $row->getParentRow('FileOgg');
                 $mimeType = 'video/ogg';
             }
         }
     }
     if (!$uploadRow) {
         return null;
     }
     return array('file' => $uploadRow->getFileSource(), 'mimeType' => $mimeType);
 }