Ejemplo n.º 1
0
 public function testGeneratorInstancesByChildComponentClass()
 {
     $s = array('componentClass' => 'Kwf_Component_Generator_GetRecursiveChildComponentsWithAlternativeComponent_TestComponent2_Component');
     $g = Kwf_Component_Generator_Abstract::getInstances('Kwf_Component_Generator_GetRecursiveChildComponentsWithAlternativeComponent_Root', $s);
     $this->assertEquals(1, count($g));
     $g = array_values($g);
     $this->assertEquals('Kwf_Component_Generator_GetRecursiveChildComponentsWithAlternativeComponent_Root', $g[0]->getClass());
     $this->assertEquals('test1', $g[0]->getGeneratorKey());
 }
 private function _assertGeneratorsCount($select, $count, $component = 'Kwf_Component_Generator_Components_Multiple')
 {
     $select = new Kwf_Component_Select($select);
     $initailSelect = clone $select;
     $generators = Kwf_Component_Generator_Abstract::getInstances($component, $select);
     $this->assertEquals($count, count($generators));
     $this->assertEquals($initailSelect, $select);
     //check if select was modified
 }
Ejemplo n.º 3
0
 public function testInheritedGenerators()
 {
     $page = $this->_root->getComponentById('1');
     $this->assertNotNull($page);
     $gen = Kwf_Component_Generator_Abstract::getInstances($page);
     $this->assertEquals(count($gen), 2);
     $page = $this->_root->getChildComponent('_static');
     $this->assertNotNull($page);
     $gen = Kwf_Component_Generator_Abstract::getInstances($page);
     $this->assertEquals(count($gen), 1);
     //aus performancegründen hier nur einer, page generator wird durch spezial-code in Generator::getInstances nicht zurückgegeben
 }
Ejemplo n.º 4
0
 public function testPlugin()
 {
     $components = $this->_root->getChildComponents(array('componentClasses' => array('Kwf_Component_Generator_Plugin_Static')));
     $this->assertEquals(1, count($components));
     $components = $this->_root->getRecursiveChildComponents(array('componentClasses' => array('Kwf_Component_Generator_Plugin_Static')));
     $this->assertEquals(1, count($components));
     $generators = Kwf_Component_Generator_Abstract::getInstances('Kwf_Component_Generator_Plugin_Static', array('componentClasses' => array('Kwf_Component_Plugin_Password_LoginForm_Component')));
     $this->assertEquals(1, count($generators));
     $components = $this->_root->getRecursiveChildComponents(array('componentClasses' => array('Kwf_Component_Plugin_Password_LoginForm_Component')));
     $this->assertEquals(1, count($components));
     $components = $this->_root->getRecursiveChildComponents(array('page' => false, 'flags' => array('processInput' => true)));
     $this->assertEquals(1, count($components));
 }
Ejemplo n.º 5
0
 private static function _getAllPossiblePageComponentClasses()
 {
     $ret = array();
     foreach (Kwc_Abstract::getComponentClasses() as $class) {
         foreach (Kwf_Component_Generator_Abstract::getInstances($class, array('pseudoPage' => true)) as $g) {
             foreach ($g->getChildComponentClasses() as $c) {
                 if (!in_array($c, $ret)) {
                     $ret[] = $c;
                 }
             }
         }
     }
     return $ret;
 }
Ejemplo n.º 6
0
 public function testStatic()
 {
     $c = $this->_root->getComponentById('root-child');
     $this->assertNotNull($c);
     $this->assertEquals('root-child', $c->componentId);
     $generators = Kwf_Component_Generator_Abstract::getInstances($this->_root->componentClass);
     $this->assertEquals(count($generators), 1);
     $generators = Kwf_Component_Generator_Abstract::getInstances($this->_root->componentClass, array('ignoreVisible' => false));
     $this->assertEquals(count($generators), 1);
     $generators = Kwf_Component_Generator_Abstract::getInstances($this->_root->componentClass, array('ignoreVisible' => true));
     $this->assertEquals(count($generators), 1);
     $c = $this->_root->getComponentById('root-child', array('ignoreVisible' => false));
     $this->assertNotNull($c);
     $c = $this->_root->getComponentById('root-child', array('ignoreVisible' => true));
     $this->assertNotNull($c);
 }
Ejemplo n.º 7
0
 public static function useAlternativeComponent($componentClass, $parentData, $generator)
 {
     $c = $parentData;
     while (!$c->inherits) {
         $c = $c->parent;
     }
     $c = $c->parent;
     if (!$c) {
         return false;
     }
     while (!$c->inherits) {
         $c = $c->parent;
     }
     $instances = Kwf_Component_Generator_Abstract::getInstances($c, array('inherit' => true));
     if (in_array($generator, $instances, true)) {
         //wir wurden geerbt weils über uns ein parentData mit dem gleichen generator gibt
         return 'inherit';
     } else {
         return false;
     }
 }
Ejemplo n.º 8
0
 private static function _getSubscribersFromComponent($componentClass)
 {
     $subscribers = array();
     $eventsClass = Kwc_Admin::getComponentClass($componentClass, 'Events');
     $subscribers[] = Kwf_Component_Abstract_Events::getInstance($eventsClass, array('componentClass' => $componentClass));
     foreach (Kwc_Abstract::getSetting($componentClass, 'generators') as $generatorKey => $null) {
         $generator = current(Kwf_Component_Generator_Abstract::getInstances($componentClass, array('generator' => $generatorKey)));
         $eventsClass = $generator->getEventsClass();
         if ($eventsClass) {
             $subscribers[] = Kwf_Component_Generator_Events::getInstance($eventsClass, array('componentClass' => $componentClass, 'generatorKey' => $generatorKey));
         }
     }
     if (Kwc_Abstract::hasSetting($componentClass, 'menuConfig')) {
         $mc = Kwf_Component_Abstract_MenuConfig_Abstract::getInstance($componentClass);
         $eventsClass = $mc->getEventsClass();
         if ($eventsClass) {
             $subscribers[] = Kwf_Component_Abstract_MenuConfig_Events::getInstance($eventsClass, array('componentClass' => $componentClass));
         }
     }
     return $subscribers;
 }
Ejemplo n.º 9
0
 public function getListeners()
 {
     $ret = parent::getListeners();
     foreach (Kwc_Abstract::getComponentClasses() as $componentClass) {
         $generators = Kwf_Component_Generator_Abstract::getInstances($componentClass, array('box' => true));
         foreach ($generators as $g) {
             foreach ($g->getChildComponentClasses() as $c) {
                 //TODO: only listen to boxes that use if (hasContent(..)) in master template
                 //      (once this is implemented (Recursive)MasterContentChanged must be fired on (Recursive)ContentWidthChanged)
                 if ($g->hasSetting('unique') && $g->getSetting('unique')) {
                     $ret[] = array('class' => $c, 'event' => 'Kwf_Component_Event_Component_HasContentChanged', 'callback' => 'onUniqueBoxHasContentChanged');
                 } else {
                     $ret[] = array('class' => $c, 'event' => 'Kwf_Component_Event_Component_HasContentChanged', 'callback' => 'onBoxHasContentChanged');
                 }
                 $ret[] = array('class' => $c, 'event' => 'Kwf_Component_Event_Component_RecursiveHasContentChanged', 'callback' => 'onBoxRecursiveHasContentChanged');
             }
         }
     }
     $ret[] = array('event' => 'Kwf_Component_Event_Component_RecursiveAdded', 'callback' => 'onRecursiveAdded');
     return $ret;
 }
Ejemplo n.º 10
0
 private function _getPossibleIndirectDbIdShortcutsImpl($class)
 {
     if (isset($this->_getPossibleIndirectDbIdShortcutsCache[$class])) {
         return $this->_getPossibleIndirectDbIdShortcutsCache[$class];
     }
     $ret = array();
     $gens = Kwf_Component_Generator_Abstract::getInstances($class);
     foreach ($gens as $g) {
         // Do not return page generators
         // For Page generators the dbIdShortcut is only used for components below the current
         // page in models
         if (!$g->getGeneratorFlag('page') && $g->hasSetting('dbIdShortcut') && Kwc_Abstract::getIndirectChildComponentClasses($class, array('componentClass' => $this->_class))) {
             $ret[] = $g->getSetting('dbIdShortcut');
         }
     }
     $this->_getPossibleIndirectDbIdShortcutsCache[$class] = $ret;
     foreach (Kwc_Abstract::getChildComponentClasses($class, array('page' => false)) as $c) {
         $ret = array_merge($ret, $this->_getPossibleIndirectDbIdShortcutsImpl($c));
     }
     $this->_getPossibleIndirectDbIdShortcutsCache[$class] = $ret;
     return $ret;
 }
Ejemplo n.º 11
0
 /**
  * Returns 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 getChildComponentClasses($class, $select = array())
 {
     $selectType = gettype($select);
     if ($selectType == 'string' && is_string($class)) {
         //simple case no. 1: get from specific generator
         $g = Kwc_Abstract::getSetting($class, 'generators');
         if (!isset($g[$select])) {
             return array();
         }
         return $g[$select]['component'];
     } else {
         if (!$select && is_string($class)) {
             //simple case no. 2: get 'em all
             $ret = array();
             foreach (Kwc_Abstract::getSetting($class, 'generators') as $g) {
                 $ret = array_merge($ret, $g['component']);
             }
             return array_unique($ret);
         } else {
             if ($selectType == 'array' && is_string($class) && count($select) == 1 && isset($select['componentClass']) && count($select['componentClass']) == 1) {
                 //simple case no 3: looking for a single comopnentClass
                 foreach (Kwc_Abstract::getSetting($class, 'generators') as $g) {
                     foreach ($g['component'] as $c) {
                         if ($c == $select['componentClass']) {
                             return array($c);
                         }
                     }
                 }
                 return array();
             } else {
                 if ($selectType == 'array' && is_string($class) && count($select) == 1 && isset($select['generatorFlags']) && $select['generatorFlags'] == array('static' => true)) {
                     //simple case no 4: looking for a generator by flag
                     $ret = array();
                     foreach (Kwc_Abstract::getSetting($class, 'generators') as $key => $gSettings) {
                         $g = Kwf_Component_Generator_Abstract::getInstance($class, $key, $gSettings);
                         if ($g->getGeneratorFlag('static')) {
                             foreach ($gSettings['component'] as $c) {
                                 $ret[] = $c;
                             }
                         }
                     }
                     return array_unique($ret);
                 } else {
                     if ($selectType == 'array' && is_string($class) && count($select) == 2 && isset($select['generator']) && isset($select['componentKey'])) {
                         //simple case no 5: looking for a generator plus componentKey
                         $ret = array();
                         $generators = Kwc_Abstract::getSetting($class, 'generators');
                         if (isset($generators[$select['generator']]['component'][$select['componentKey']])) {
                             $ret[] = $generators[$select['generator']]['component'][$select['componentKey']];
                         }
                         return $ret;
                     } else {
                         if ($selectType == 'array') {
                             $select = new Kwf_Component_Select($select);
                         }
                     }
                 }
             }
         }
     }
     //not so simple, else we ask Generator_Abstract::getInstances for help
     $ret = array();
     $generators = Kwf_Component_Generator_Abstract::getInstances($class, $select);
     if (!$generators) {
         return $ret;
     }
     foreach ($generators as $generator) {
         $c = $generator->getChildComponentClasses($select);
         if (!$select->hasPart(Kwf_Component_Select::WHERE_GENERATOR)) {
             $c = array_values($c);
         }
         $ret = array_merge($ret, $c);
     }
     if (!$select->hasPart(Kwf_Component_Select::WHERE_GENERATOR)) {
         $ret = array_unique($ret);
     }
     return $ret;
 }
 protected function _hasPermissions($row, $action)
 {
     $user = Zend_Registry::get('userModel')->getAuthedUser();
     if ($row instanceof Kwf_Component_Model_Row) {
         $component = $row->getData();
     } else {
         $component = Kwf_Component_Data_Root::getInstance()->getComponentById($row->id, array('ignoreVisible' => true));
     }
     // darf man die action?
     $config = $component->generator->getPagesControllerConfig($component);
     $actions = isset($config['actions']) ? $config['actions'] : array();
     $actions['move'] = $config['allowDrag'];
     $data['moveTo'] = !!Kwf_Component_Generator_Abstract::getInstances($component, array('pageGenerator' => true));
     if (in_array($action, array_keys($actions)) && !$actions[$action]) {
         return false;
     }
     // wenn ja, darf man die Komponente bearbeiten?
     $acl = Kwf_Registry::get('acl')->getComponentAcl();
     return $acl->isAllowed($user, $component);
 }
Ejemplo n.º 13
0
 public function duplicateChild($source, $parentTarget, Zend_ProgressBar $progressBar = null)
 {
     if ($source->generator !== $this) {
         throw new Kwf_Exception("you must call this only with the correct source");
     }
     if (!Kwf_Component_Generator_Abstract::getInstances($parentTarget, array('whereGeneratorClass' => get_class($this)))) {
         throw new Kwf_Exception("you must call this only with the correct target");
     }
     $sourceId = $source->id;
     $parentSourceId = $source->parent->componentId;
     $parentTargetId = $parentTarget->componentId;
     unset($source);
     unset($parentTarget);
     $targetId = $this->_duplicatePageRecursive($parentSourceId, $parentTargetId, $sourceId, $progressBar);
     return Kwf_Component_Data_Root::getInstance()->getComponentById($targetId, array('ignoreVisible' => true));
 }
Ejemplo n.º 14
0
 public static function getEditConfigs($componentClass, Kwf_Component_Generator_Abstract $gen, $idTemplate = null, $componentIdSuffix = '')
 {
     $ret = array('componentConfigs' => array(), 'contentEditComponents' => array());
     if (is_null($idTemplate)) {
         if ($gen->hasSetting('dbIdShortcut')) {
             $idTemplate = $gen->getSetting('dbIdShortcut') . '{0}';
         } else {
             $idTemplate = '{componentId}' . $gen->getIdSeparator() . '{0}';
         }
     }
     $cfg = Kwc_Admin::getInstance($componentClass)->getExtConfig();
     foreach ($cfg as $k => $c) {
         $suffix = $componentIdSuffix;
         if (isset($c['componentIdSuffix'])) {
             $suffix .= $c['componentIdSuffix'];
             unset($c['componentIdSuffix']);
         }
         $ret['componentConfigs'][$componentClass . '-' . $k] = $c;
         $ret['contentEditComponents'][] = array('componentClass' => $componentClass, 'type' => $k, 'idTemplate' => $idTemplate, 'idSeparator' => $gen->getIdSeparator(), 'componentIdSuffix' => $suffix, 'title' => $c['title'], 'icon' => $c['icon']);
     }
     foreach ($gen->getGeneratorPlugins() as $plugin) {
         $cls = get_class($plugin);
         $cfg = Kwc_Admin::getInstance($cls)->getExtConfig();
         foreach ($cfg as $k => $c) {
             $suffix = $componentIdSuffix;
             if (isset($c['componentIdSuffix'])) {
                 $suffix .= $c['componentIdSuffix'];
                 unset($c['componentIdSuffix']);
             }
             $ret['componentConfigs'][$cls . '-' . $k] = $c;
             $ret['contentEditComponents'][] = array('componentClass' => $cls, 'type' => $k, 'idTemplate' => $idTemplate, 'componentIdSuffix' => $suffix);
         }
     }
     if (Kwc_Abstract::hasSetting($componentClass, 'editComponents')) {
         $editComponents = Kwc_Abstract::getSetting($componentClass, 'editComponents');
         foreach ($editComponents as $c) {
             $childGen = Kwf_Component_Generator_Abstract::getInstances($componentClass, array('componentKey' => $c));
             if (!$childGen) {
                 throw new Kwf_Exception("editComponents '{$c}' doesn't exist in '{$componentClass}'");
             }
             $childGen = $childGen[0];
             $cls = Kwc_Abstract::getChildComponentClass($componentClass, null, $c);
             $edit = self::getEditConfigs($cls, $childGen, $idTemplate, $componentIdSuffix . $childGen->getIdSeparator() . $c);
             $ret['componentConfigs'] = array_merge($ret['componentConfigs'], $edit['componentConfigs']);
             $ret['contentEditComponents'] = array_merge($ret['contentEditComponents'], $edit['contentEditComponents']);
         }
     }
     return $ret;
 }
Ejemplo n.º 15
0
 /**
  * Returns child ids for a single generator
  *
  * Only works for a single generator - you have to specify the required generator.
  *
  * This is much more efficient than getChildComponents as no rows or data objects will be created.
  *
  * @param array|Kwf_Component_Select
  * @return int[]
  */
 public function getChildIds($select = array())
 {
     $select = $this->_formatSelect($select);
     if (!$select->hasPart(Kwf_Component_Select::WHERE_GENERATOR)) {
         throw new Kwf_Exception('Only one generator supported, please restrict select to a generator');
     }
     $generator = current(Kwf_Component_Generator_Abstract::getInstances($this, $select));
     return $generator->getChildIds($this, $select);
 }
 protected function _initFields()
 {
     //--- main generator form (if Category_Generator this contains Pagename and Pagetype)
     $componentOrParent = Kwf_Component_Data_Root::getInstance()->getComponentById($this->_getComponentOrParentId(), array('ignoreVisible' => true));
     if (!$componentOrParent || !Kwf_Registry::get('acl')->getComponentAcl()->isAllowed($this->_getAuthData(), $componentOrParent)) {
         throw new Kwf_Exception_AccessDenied();
     }
     if ($this->_getParam('id')) {
         if ($componentOrParent->componentId == 'root') {
             $this->_form = null;
         } else {
             $this->_form = $componentOrParent->generator->getPagePropertiesForm($componentOrParent);
         }
     } else {
         $gens = Kwf_Component_Generator_Abstract::getInstances($componentOrParent, array('pageGenerator' => true));
         if (count($gens) != 1) {
             throw new Kwf_Exception('pageGenerator not found');
         }
         $gen = array_shift($gens);
         $this->_form = $gen->getPagePropertiesForm($componentOrParent);
     }
     if (!$this->_form) {
         $this->_form = new Kwf_Form();
         $this->_form->setModel(Kwf_Model_Abstract::getInstance('Kwf_Component_Model'));
         $this->_form->add(new Kwf_Form_Field_ShowField('name', trlKwf('Name')));
     }
     //--- and now add the more complicated additional forms
     $fields = $this->_form->fields;
     $componentField = $this->_form->getComponentField();
     if ($componentField) {
         $possibleComponentClasses = $componentField->getPossibleComponentClasses();
         $this->_componentField = $componentField;
     } else {
         if (!$this->_getParam('id')) {
             throw new Kwf_Exception("not supported for adding");
         }
         $possibleComponentClasses = array($componentOrParent->componentClass);
     }
     $component = Kwf_Component_Data_Root::getInstance()->getComponentById($this->_getComponentOrParentId(), array('ignoreVisible' => true));
     if ($this->_getParam('id')) {
         //$component is the component, just get inheritClasses
         $inheritClasses = $component->inheritClasses;
     } else {
         //$component is the parent component (we are adding)
         //this code is very similar to Kwf_Component_Data::__get inheritClasses
         $inheritClasses = array();
         $page = $component;
         while ($page) {
             foreach (Kwc_Abstract::getSetting($page->componentClass, 'generators') as $gKey => $g) {
                 if (isset($g['inherit']) && $g['inherit']) {
                     if (isset($g['unique']) && $g['unique']) {
                         continue;
                     }
                     //ignore, not edited
                     if (!in_array($page->componentClass, $inheritClasses)) {
                         $inheritClasses[] = $page->componentClass;
                     }
                 }
             }
             if ($page->inherits) {
                 //wenn page selbst erbt einfach von da übernehmen (rekursiver aufruf)
                 $inheritClasses = array_merge($inheritClasses, $page->inheritClasses);
                 break;
                 //aufhören, rest kommt durch rekursion daher
             }
             $page = $page->parent;
         }
     }
     unset($component);
     $generatorForms = array();
     $componentForms = array();
     $formsForComponent = array();
     $componentValues = array();
     if ($componentField) {
         $componentValues = $componentField->getValues();
     }
     foreach ($possibleComponentClasses as $key => $componentClass) {
         $ev = new Kwf_Component_Event_Component_FilterAddComponentClass($componentClass, $componentOrParent);
         Kwf_Events_Dispatcher::fireEvent($ev);
         if ($ev->deny) {
             if ($this->_getParam('id') && $componentOrParent->componentClass == $componentClass) {
                 //in edit-mode allow already used componentClass
             } else {
                 unset($componentValues[$key]);
                 continue;
             }
         }
         $component = array('componentClass' => $componentClass, 'inheritClasses' => $inheritClasses);
         $formsForComponent[$key] = array();
         $classesToCheckForPagePropertiesForm = array('__pageComponent' => $componentClass);
         foreach (Kwf_Component_Generator_Abstract::getInstances($component) as $g) {
             if ($g->getGeneratorFlag('page')) {
                 continue;
             }
             if (!array_key_exists($g->getClass() . '.' . $g->getGeneratorKey(), $generatorForms)) {
                 $f = $g->getPagePropertiesForm($componentOrParent);
                 if ($f) {
                     $f->setName('gen_' . $g->getClass() . '_' . $g->getGeneratorKey());
                     $f->setIdTemplate('{0}-' . $g->getGeneratorKey());
                     $f->setCreateMissingRow(true);
                     $f->setShowDependingOnComponent(true);
                     $this->_dynamicForms[] = $f;
                     $fields->add($f);
                 }
                 $generatorForms[$g->getClass() . '.' . $g->getGeneratorKey()] = $f;
             }
             if ($generatorForms[$g->getClass() . '.' . $g->getGeneratorKey()]) {
                 $formsForComponent[$key][] = 'gen_' . $g->getClass() . '_' . $g->getGeneratorKey();
             }
             if ($g->getGeneratorFlag('static')) {
                 $classesToCheckForPagePropertiesForm = array_merge($classesToCheckForPagePropertiesForm, $g->getChildComponentClasses());
             }
         }
         foreach ($classesToCheckForPagePropertiesForm as $childComponentKey => $childComponentClass) {
             if (!array_key_exists($key . '_' . $childComponentKey, $componentForms)) {
                 $config = array();
                 $config['component'] = $componentOrParent;
                 if ($this->_getParam('id')) {
                     $config['mode'] = 'edit';
                 } else {
                     $config['mode'] = 'add';
                 }
                 $f = Kwc_Admin::getInstance($childComponentClass)->getPagePropertiesForm($config);
                 if ($f) {
                     $f->setName('cmp_' . $key . '_' . $childComponentKey);
                     if ($childComponentKey == '__pageComponent') {
                         $f->setIdTemplate('{0}');
                     } else {
                         $f->setIdTemplate('{0}-' . $childComponentKey);
                     }
                     $f->setShowDependingOnComponent(true);
                     $this->_dynamicForms[] = $f;
                     $fields->add($f);
                 }
                 $componentForms[$key . '_' . $childComponentKey] = $f;
             }
             if ($componentForms[$key . '_' . $childComponentKey]) {
                 $formsForComponent[$key][] = 'cmp_' . $key . '_' . $childComponentKey;
             }
         }
     }
     if ($componentField) {
         $componentField->setValues($componentValues);
         $componentField->setFormsForComponent($formsForComponent);
     }
     $this->_form->setId($this->_getParam('id'));
 }