예제 #1
0
 /**
  * add
  * @param GenericSetup $objGenericSetup
  * @return stdClass Global
  * @author Thomas Schedler <*****@*****.**>
  * @version 1.0
  */
 public function add(GenericSetup &$objGenericSetup)
 {
     $this->core->logger->debug('global->models->Model_Globals->add()');
     $objGlobal = new stdClass();
     $objGlobal->globalId = uniqid();
     $objGlobal->version = 1;
     $objGlobal->sortPosition = GenericSetup::DEFAULT_SORT_POSITION;
     $intUserId = Zend_Auth::getInstance()->getIdentity()->id;
     if ($objGenericSetup->getRootLevelGroupId() == $this->core->sysConfig->root_level_groups->product) {
         $objGlobal->parentId = $this->core->sysConfig->product->rootLevels->list->id;
         $objGlobal->parentTypeId = $this->core->sysConfig->parent_types->rootlevel;
     } else {
         /**
          * check if parent element is rootlevel or folder and get sort position
          */
         if ($objGenericSetup->getParentId() != '' && $objGenericSetup->getParentId() > 0) {
             $objGlobal->parentId = $objGenericSetup->getParentId();
             $objGlobal->parentTypeId = $this->core->sysConfig->parent_types->folder;
             $objData = $this->getModelFolders()->countChilds($objGlobal->parentId);
         } else {
             if ($objGenericSetup->getRootLevelId() != '' && $objGenericSetup->getRootLevelId() > 0) {
                 $objGlobal->parentId = $objGenericSetup->getRootLevelId();
             } else {
                 $this->core->logger->err('zoolu->modules->global->models->Model_Globals->add(): intRootLevelId is empty!');
             }
             $objGlobal->parentTypeId = $this->core->sysConfig->parent_types->rootlevel;
             $objData = $this->getModelFolders()->countGlobalRootChilds($objGlobal->parentId);
         }
         if (count($objData) == 1) {
             $objGlobal->sortPosition = current($objData)->counter;
         }
     }
     /**
      * insert main data
      */
     $arrMainData = array('idParent' => $objGlobal->parentId, 'idParentTypes' => $objGlobal->parentTypeId, 'isStartGlobal' => $objGenericSetup->getIsStartElement(), 'idUsers' => $intUserId, 'sortPosition' => $objGlobal->sortPosition, 'sortTimestamp' => date('Y-m-d H:i:s'), 'globalId' => $objGlobal->globalId, 'version' => $objGlobal->version, 'creator' => $objGenericSetup->getCreatorId(), 'created' => date('Y-m-d H:i:s'));
     $objGlobal->id = $this->getGlobalTable()->insert($arrMainData);
     /**
      * insert language specific properties
      */
     $arrProperties = array('globalId' => $objGlobal->globalId, 'version' => $objGlobal->version, 'idLanguages' => $this->intLanguageId, 'idLanguageFallbacks' => $objGenericSetup->getLanguageFallbackId(), 'idGenericForms' => $objGenericSetup->getGenFormId(), 'idTemplates' => $objGenericSetup->getTemplateId(), 'idGlobalTypes' => $objGenericSetup->getElementTypeId(), 'showInNavigation' => $objGenericSetup->getShowInNavigation(), 'idUsers' => $intUserId, 'creator' => $objGenericSetup->getCreatorId(), 'publisher' => $intUserId, 'created' => date('Y-m-d H:i:s'), 'published' => $objGenericSetup->getPublishDate(), 'idStatus' => $objGenericSetup->getStatusId());
     $this->getGlobalPropertyTable()->insert($arrProperties);
     /**
      * if is tree add, make alis now
      */
     if ($objGenericSetup->getRootLevelId() == $this->core->sysConfig->product->rootLevels->tree->id) {
         $objGlobal->parentId = $objGenericSetup->getParentId();
         $objGlobal->rootLevelId = $objGenericSetup->getRootLevelId();
         $objGlobal->rootLevelGroupId = $objGenericSetup->getRootLevelGroupId();
         $objGlobal->isStartElement = $objGenericSetup->getIsStartElement();
         $this->addLink($objGlobal);
     }
     return $objGlobal;
 }