/** * save() * @param integer $intElementId * @param string $strType * @param string $strElementId * @param integet $intVersion * @author Thomas Schedler <*****@*****.**> * @version 1.0 */ public function save($intElementId, $strType, $strElementId = null, $intVersion = null) { try { $this->strType = $strType; $strParentUrl = ''; $this->getModel(); $this->getModelUrls(); $objItemData = $this->objModel->load($intElementId); if (count($objItemData) > 0) { $objItem = $objItemData->current(); if ($objItem->idParentTypes == $this->core->sysConfig->parent_types->folder) { $objParentFolderData = $this->objModel->loadParentUrl($intElementId, $this->objElement->Setup()->getIsStartElement(false)); if (count($objParentFolderData) > 0) { $objParentFolderUrl = $objParentFolderData->current(); $strParentUrl = $objParentFolderUrl->url; } } $objUrlData = $this->objModelUrls->loadUrl($objItem->relationId, $objItem->version, $this->core->sysConfig->url_types->{$strType}); if (count($objUrlData) > 0) { $objUrl = $objUrlData->current(); $this->strUrl = $objUrl->url; $strUrlNew = ''; // get the new url if (isset($_POST[$this->objElement->name . '_EditableUrl'])) { $strUrlNew = $_POST[$this->objElement->name . '_EditableUrl']; $strUrlNew = $this->makeUrlConform($strUrlNew); if ($this->objElement->Setup()->getIsStartElement(false) == true) { $strUrlNew .= '/'; } } // compare the new url with the url from the db and check if there is a new url if (strcmp($this->strUrl, $strParentUrl . $strUrlNew) !== 0 && $strUrlNew != '') { //urls are unequal $this->strUrl = $this->checkUrlUniqueness($strParentUrl . $strUrlNew); // set all page urls to isMain 0 $this->objModelUrls->resetIsMainUrl($objItem->relationId, $objItem->version, $this->core->sysConfig->url_types->{$strType}); $this->objModelUrls->insertUrl($this->strUrl, $objItem->relationId, $objItem->version, $this->core->sysConfig->url_types->{$strType}); //change child urls if ($this->objElement->Setup()->getIsStartElement(false) == true) { $arrChildData = $this->objModel->getChildUrls($this->objElement->Setup()->getParentId()); if (count($arrChildData) > 0) { foreach ($arrChildData as $objChild) { if ($objChild->relationId != $objItem->relationId) { $this->objModelUrls->resetIsMainUrl($objChild->relationId, $objChild->version, $this->core->sysConfig->url_types->{$strType}); $this->objModelUrls->insertUrl($this->checkUrlUniqueness(str_replace($objUrl->url, $this->strUrl, $objChild->url)), $objChild->relationId, $objChild->version, $this->core->sysConfig->url_types->{$strType}); } } } } } } else { $this->strUrl = $strParentUrl; if ($objItem->idParentTypes == $this->core->sysConfig->parent_types->folder || $this->objElement->Setup()->getIsStartElement(false) == false) { $objFieldData = $this->objElement->Setup()->getModelGenericForm()->loadFieldsWithPropery($this->core->sysConfig->fields->properties->url_field, $this->objElement->Setup()->getGenFormId()); if (count($objFieldData) > 0) { foreach ($objFieldData as $objField) { if ($this->objElement->Setup()->getRegion($objField->regionId)->getField($objField->name)->getValue() != '') { $this->strUrl .= $this->makeUrlConform($this->objElement->Setup()->getRegion($objField->regionId)->getField($objField->name)->getValue()); break; } } } if ($this->objElement->Setup()->getIsStartElement(false) == true) { $this->strUrl .= '/'; } } $this->strUrl = $this->checkUrlUniqueness($this->strUrl); $this->objModelUrls->insertUrl($this->strUrl, $objItem->relationId, $objItem->version, $this->core->sysConfig->url_types->{$strType}); } } $this->load($intElementId, $strType, $strElementId, $intVersion); } catch (Exception $exc) { $this->core->logger->err($exc); } }