Ejemplo n.º 1
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];
 }
Ejemplo n.º 2
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;
 }
Ejemplo n.º 3
0
 /**
  * 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;
 }