Esempio n. 1
0
 /**
  * @return LBoxConfigStructure
  * @throws Exception
  */
 public static function getInstance()
 {
     $className = __CLASS__;
     try {
         if (!self::$instance instanceof $className) {
             self::$instance = new $className();
         }
         return self::$instance;
     } catch (Exception $e) {
         throw $e;
     }
 }
 public function process()
 {
     try {
         $parent = NULL;
         if (strlen($this->fileNamesTemplatePagesTypesPattern) < 1) {
             throw new LBoxExceptionFormProcessor(LBoxExceptionFormProcessor::MSG_INSTANCE_VAR_STRING_NOTNULL, LBoxExceptionFormProcessor::CODE_BAD_INSTANCE_VAR);
         }
         if (strlen($this->form->getControlByName("id")->getValue()) > 0) {
             $configItem = LBoxConfigManagerStructure::getInstance()->getPageById($this->form->getControlByName("id")->getValue());
             // smazat cache pro existujici stranku na jeji puvodni URL jeste pred moznou zmenou!
             LBoxCacheManagerFront::getInstance()->cleanAllURLs(true);
             if ($parentID = $this->form->getControlByName("parent_id")->getValue()) {
                 $parent = LBoxConfigManagerStructure::getInstance()->getPageById($parentID);
             }
         } else {
             try {
                 if (LBoxConfigManagerStructure::getInstance()->getPageByUrl($this->form->getControlByName("url")->getValue())) {
                     throw new LBoxExceptionConfigStructure("URL: " . LBoxExceptionConfigStructure::MSG_ATTRIBUTE_UNIQUE_NOT_UNIQUE, LBoxExceptionConfigStructure::CODE_ATTRIBUTE_UNIQUE_NOT_UNIQUE);
                 }
             } catch (Exception $e) {
                 switch ($e->getCode()) {
                     case LBoxExceptionConfigStructure::CODE_NODE_BYURL_NOT_FOUND:
                         NULL;
                         break;
                     default:
                         throw $e;
                 }
             }
             if ($parentID = $this->form->getControlByName("parent_id")->getValue()) {
                 $parent = LBoxConfigManagerStructure::getInstance()->getPageById($parentID);
                 // zaridi parental vztah jen pri vytvareni (nutno kvuli odvozeni ID) - pro editaci je dodatecne prirazeni nize
                 $configItem = LBoxConfigStructure::getInstance()->getCreateChild($parent, $this->form->getControlByName("url")->getValue());
             } else {
                 $configItem = LBoxConfigStructure::getInstance()->getCreateItem($this->form->getControlByName("url")->getValue());
             }
         }
         foreach ($this->form->getControls() as $control) {
             if ($control instanceof LBoxFormControlMultiple) {
                 continue;
             }
             $name = $control->getName();
             switch ($name) {
                 case "id":
                 case "parent_id":
                 case "move_before":
                     NULL;
                     break;
                 case "type":
                     $configItem->template = str_replace("(.+)", $control->getValue(), $this->fileNamesTemplatePagesTypesPattern);
                     $configItem->template = preg_replace("/[^\\w_\\-\\.]/", "", $configItem->template);
                     break;
                 case "url":
                     if ($parent) {
                         $configItem->{$name} = "/" . $parent->url . "/" . $control->getValue() . "/";
                         $configItem->{$name} = preg_replace("/(\\/+)/", "/", $configItem->{$name});
                     } else {
                         $configItem->{$name} = "/" . $control->getValue() . "/";
                         $configItem->{$name} = preg_replace("/(\\/+)/", "/", $configItem->{$name});
                     }
                     break;
                 default:
                     $configItem->{$name} = $control->getValue();
             }
         }
         // move before a parent_id
         // - je treba dodatecne zajistit parental vztah, pri editaci horni logika to zajistuje pouze pri vytvareni, ale ne pri editaci
         switch (true) {
             // editace + parent puvodne nemel tohoto potomka
             case $this->form->getControlByName("id")->getValue() && $this->form->getControlByName("parent_id")->getValue() > 0 && !LBoxConfigManagerStructure::getInstance()->getPageById($this->form->getControlByName("parent_id")->getValue())->isParentOf($configItem):
                 LBoxConfigManagerStructure::getInstance()->getPageById($this->form->getControlByName("parent_id")->getValue())->appendChild($configItem);
                 break;
                 // parent neni nastaven, jde o editaci a predtim nastaven byl
             // parent neni nastaven, jde o editaci a predtim nastaven byl
             case !$this->form->getControlByName("parent_id")->getValue() && $configItem->hasParent():
                 // uprednostnit removeFromTree()
                 $configItem->removeFromTree();
                 break;
                 // editace + move before je nastaveno na jiny node nez bylo
             // editace + move before je nastaveno na jiny node nez bylo
             case $this->form->getControlByName("move_before")->getValue() && $this->form->getControlByName("id")->getValue() && (!$configItem->hasSiblingBefore() || $configItem->getSiblingBefore()->id != $this->form->getControlByName("move_before")->getValue()):
                 // vlozeni + moveBefore je nastaveno
             // vlozeni + moveBefore je nastaveno
             case $this->form->getControlByName("move_before")->getValue() && $this->form->getControlByName("id")->getValue():
                 // uprednostnit insertBefore()
                 LBoxConfigManagerStructure::getInstance()->getPageById($this->form->getControlByName("move_before")->getValue())->insertBefore($configItem);
                 break;
                 // parent je nastaven
             // parent je nastaven
             case $this->form->getControlByName("parent_id")->getValue():
                 // uprednostnit appendChild()
                 LBoxConfigManagerStructure::getInstance()->getPageById($this->form->getControlByName("parent_id")->getValue())->appendChild($configItem);
                 break;
             default:
                 $configItem->removeFromTree();
         }
         LBoxConfigStructure::getInstance()->store();
         // pro jistotu smazani front cache stranky na jeji potencialne zmenene URL (mohly by tam byt data z minulosti)
         LBoxCacheManagerFront::getInstance()->cleanAllURLs(true);
         //reload na nove ulozenou stranky
         LBoxFront::reload(LBoxConfigManagerStructure::getInstance()->getPageById($configItem->id)->url);
     } catch (Exception $e) {
         throw $e;
     }
 }
Esempio n. 3
0
 public function testInsertBefore()
 {
     $this->assertType("LBoxConfigItemStructure", $newItem = LBoxConfigStructure::getInstance()->getCreateItem("/unittest-new-item-30/"));
     LBoxConfigStructure::getInstance()->store();
     $this->assertType("LBoxConfigItemStructure", $newItem2 = LBoxConfigStructure::getInstance()->getCreateItem("/unittest-new-item-3001/"));
     LBoxConfigStructure::getInstance()->store();
     $this->assertType("LBoxConfigItemStructure", $newItem3 = LBoxConfigStructure::getInstance()->getCreateItem("/unittest-new-item-3002/"));
     $newItem = LBoxConfigManagerStructure::getInstance()->getPageByUrl("/unittest-new-item-30/");
     $newItem2 = LBoxConfigManagerStructure::getInstance()->getPageByUrl("/unittest-new-item-3001/");
     $this->assertNull($newItem->appendChild($newItem2));
     LBoxConfigStructure::getInstance()->store();
     $newItem = LBoxConfigManagerStructure::getInstance()->getPageByUrl("/unittest-new-item-30/");
     $newItem2 = LBoxConfigManagerStructure::getInstance()->getPageByUrl("/unittest-new-item-3001/");
     $this->assertSame($newItem2->id, $newItem->getChildNodesIterator()->current()->id);
     $newItem2 = LBoxConfigManagerStructure::getInstance()->getPageByUrl("/unittest-new-item-3001/");
     $newItem3 = LBoxConfigManagerStructure::getInstance()->getPageByUrl("/unittest-new-item-3002/");
     $this->assertNull($newItem2->insertBefore($newItem3));
     LBoxConfigStructure::getInstance()->store();
     $newItem2 = LBoxConfigManagerStructure::getInstance()->getPageByUrl("/unittest-new-item-3001/");
     $newItem3 = LBoxConfigManagerStructure::getInstance()->getPageByUrl("/unittest-new-item-3002/");
     $this->assertSame($newItem2->id, $newItem3->getSiblingAfter()->id);
     $this->assertSame($newItem3->id, $newItem2->getSiblingBefore()->id);
     $newItem = LBoxConfigManagerStructure::getInstance()->getPageByUrl("/unittest-new-item-30/");
     $newItem->delete();
     LBoxConfigStructure::getInstance()->store();
 }