/** * Constructor * * @param class_module_pages_pageelement $objElementData */ public function __construct($objElementData) { parent::__construct(); $this->setSystemid($objElementData->getSystemid()); //merge the attributes of $objElementData to the array $this->arrElementData["page_element_ph_placeholder"] = $objElementData->getStrPlaceholder(); $this->arrElementData["page_element_ph_name"] = $objElementData->getStrName(); $this->arrElementData["page_element_ph_element"] = $objElementData->getStrElement(); $this->arrElementData["page_element_ph_title"] = $objElementData->getStrTitle(false); $this->objElementData = $objElementData; }
private function processSinglePage($arrPage, $bitReplaceExisting, $strTopFolderId) { $strReturn = ""; $arrMetadata = $arrPage["metadata"][0]; $arrElements = $arrPage["elements"][0]["element"]; //create page itself $strPagename = $arrMetadata["pagename"][0]["value"]; $strPrevId = ""; //check if the exported prev-values may be used $strImportPrevName = $arrMetadata["prevname"][0]["value"]; if ($strImportPrevName != "") { $objPage = class_module_pages_page::getPageByName($strImportPrevName); if ($objPage !== null) { $strPrevId = $objPage->getSystemid(); } } elseif (validateSystemid($arrMetadata["previd"][0]["value"])) { $objRoot = class_objectfactory::getInstance()->getObject($arrMetadata["previd"][0]["value"]); if ($objRoot !== null) { $strPrevId = $arrMetadata["previd"][0]["value"]; } } if ($strPrevId == "") { $strPrevId = $strTopFolderId; } //check if an existing page should be replaced if ($bitReplaceExisting) { $objPage = class_module_pages_page::getPageByName($strPagename); if ($objPage !== null) { $strPrevId = $objPage->getPrevId(); $objPage->deleteObject(); } class_carrier::getInstance()->getObjDB()->flushQueryCache(); } $objPage = new class_module_pages_page(); $objPage->setStrName($strPagename); $objPage->updateObjectToDb($strPrevId); $strPageId = $objPage->getSystemid(); $strReturn .= "created page " . $objPage->getStrName() . "\n"; //save propertysets $objLanguages = new class_module_languages_language(); $strCurrentLanguage = $objLanguages->getStrAdminLanguageToWorkOn(); $arrPropertysets = $arrMetadata["pageproperties"][0]["propertyset"]; foreach ($arrPropertysets as $arrOnePropSet) { class_carrier::getInstance()->getObjDB()->flushQueryCache(); $objLanguages->setStrAdminLanguageToWorkOn($arrOnePropSet["attributes"]["language"]); //reload page to save correct prop-sets $objPage = new class_module_pages_page($strPageId); $objPage->setStrLanguage($arrOnePropSet["language"][0]["value"]); $objPage->setStrBrowsername($arrOnePropSet["browsername"][0]["value"]); $objPage->setStrDesc($arrOnePropSet["description"][0]["value"]); $objPage->setStrKeywords($arrOnePropSet["keywords"][0]["value"]); $objPage->setStrTemplate($arrOnePropSet["template"][0]["value"]); $objPage->setStrSeostring($arrOnePropSet["seostring"][0]["value"]); $objPage->setStrLanguage($arrOnePropSet["language"][0]["value"]); $objPage->setStrAlias($arrOnePropSet["alias"][0]["value"]); $objPage->setStrTarget($arrOnePropSet["target"][0]["value"]); $objPage->setStrPath($arrOnePropSet["path"][0]["value"]); $objPage->updateObjectToDb(); $strReturn .= "saved propertyset for language " . $objPage->getStrLanguage() . "\n"; } $objLanguages->setStrAdminLanguageToWorkOn($strCurrentLanguage); //and import each element foreach ($arrElements as $arrSingleElement) { //validate if element exists $strElementName = $arrSingleElement["metadata"][0]["element"][0]["value"]; if (class_module_pages_element::getElement($strElementName) !== null) { $objElement = new class_module_pages_pageelement(); $objElement->setStrPlaceholder($arrSingleElement["metadata"][0]["placeholder"][0]["value"]); $objElement->setStrName($arrSingleElement["metadata"][0]["name"][0]["value"]); $objElement->setStrElement($arrSingleElement["metadata"][0]["element"][0]["value"]); $objElement->setStrTitle($arrSingleElement["metadata"][0]["title"][0]["value"]); $objElement->setStrLanguage($arrSingleElement["metadata"][0]["language"][0]["value"]); $objElement->updateObjectToDb($strPageId); //and the foreign table $strTable = $arrSingleElement["foreignTable"][0]["attributes"]["table"]; $arrValues = array(); foreach ($arrSingleElement["foreignTable"][0]["column"] as $arrColumn) { $arrValues[$arrColumn["attributes"]["name"]] = isset($arrColumn["value"]) ? $arrColumn["value"] : ""; } unset($arrValues["content_id"]); //and build the query itself $strQuery = "UPDATE " . class_carrier::getInstance()->getObjDB()->encloseTableName(_dbprefix_ . $strTable) . " SET "; $arrInsertValues = array(); $arrEscapes = array(); $arrColumns = class_carrier::getInstance()->getObjDB()->getColumnsOfTable(_dbprefix_ . $strTable); $arrColumns = array_map(function ($arrColumn) { return $arrColumn["columnName"]; }, $arrColumns); foreach ($arrValues as $strColumn => $strValue) { if (!in_array($strColumn, $arrColumns)) { continue; } $strQuery .= class_carrier::getInstance()->getObjDB()->encloseColumnName($strColumn) . " = ? ,"; $arrInsertValues[] = $strValue; $arrEscapes[] = false; } $strQuery = uniSubstr($strQuery, 0, -1); $strQuery .= " WHERE content_id = ?"; $arrInsertValues[] = $objElement->getSystemid(); class_carrier::getInstance()->getObjDB()->_pQuery($strQuery, $arrInsertValues, $arrEscapes); $strReturn .= "created element " . $objElement->getStrName() . "\n"; } else { $strReturn .= "error: element " . $strElementName . " not existing"; } } return $this->objToolkit->getPreformatted(array($strReturn)); }
/** * Provides a form to set up the params needed to copy a single element from one placeholder to another. * Collects the target language, the target page and the target placeholder, invokes the copy-procedure. * * @throws class_exception * @return string , "" in case of success * @permissions edit */ protected function actionCopyElement() { $strReturn = ""; $this->setArrModuleEntry("template", "/folderview.tpl"); $objSourceElement = new class_module_pages_pageelement($this->getSystemid()); if ($objSourceElement->rightEdit($this->getSystemid())) { $objLang = null; if ($this->getParam("copyElement_language") != "") { $objLang = new class_module_languages_language($this->getParam("copyElement_language")); } else { $objLang = class_module_languages_language::getLanguageByName($this->getLanguageToWorkOn()); } $objPage = null; if ($this->getParam("copyElement_page") != "") { $objPage = class_module_pages_page::getPageByName($this->getParam("copyElement_page")); if ($objPage == null) { throw new class_exception("failed to load page " . $this->getParam("copyElement_page"), class_exception::$level_ERROR); } $objPage->setStrLanguage($objLang->getStrName()); $objPage->initObject(); } else { $objPage = new class_module_pages_page($objSourceElement->getPrevId()); } //form header $strReturn .= $this->objToolkit->formHeader(class_link::getLinkAdminHref("pages_content", "copyElement"), "formCopyElement"); $strReturn .= $this->objToolkit->formInputHidden("copyElement_doCopy", 1); $strReturn .= $this->objToolkit->formInputHidden("systemid", $this->getSystemid()); $strReturn .= $this->objToolkit->formHeadline($this->getLang("copyElement_element") . " " . $objSourceElement->getStrName() . "_" . $objSourceElement->getStrElement() . " (" . $objSourceElement->getStrTitle() . ")"); //step one: language selection $arrLanguages = class_module_languages_language::getObjectList(true); $arrLanguageDD = array(); foreach ($arrLanguages as $objSingleLanguage) { $arrLanguageDD[$objSingleLanguage->getSystemid()] = $this->getLang("lang_" . $objSingleLanguage->getStrName(), "languages"); } $strReturn .= $this->objToolkit->formInputDropdown("copyElement_language", $arrLanguageDD, $this->getLang("copyElement_language"), $objLang->getSystemid()); //step two: page selection $strReturn .= $this->objToolkit->formInputPageSelector("copyElement_page", $this->getLang("copyElement_page"), $objPage->getStrName(), "inputText", false); //step three: placeholder-selection //here comes the tricky part. load the template, analyze the placeholders and validate all those against things like repeatable and more... $strTemplate = $objPage->getStrTemplate(); //load the placeholders $strTemplateId = $this->objTemplate->readTemplate("/module_pages/" . $strTemplate); $arrPlaceholders = $this->objTemplate->getElements($strTemplateId); $arrPlaceholdersDD = array(); foreach ($arrPlaceholders as $arrSinglePlaceholder) { foreach ($arrSinglePlaceholder["elementlist"] as $arrSinglePlaceholderlist) { if ($objSourceElement->getStrElement() == $arrSinglePlaceholderlist["element"]) { if ($objSourceElement->getIntRepeat() == 1) { //repeatable, ok in every case $arrPlaceholdersDD[$arrSinglePlaceholder["placeholder"]] = $arrSinglePlaceholder["placeholder"]; } else { //not repeatable - element already existing at placeholder? $arrElementsOnPage = class_module_pages_pageelement::getElementsOnPage($objPage->getSystemid(), false, $objLang->getStrName()); //loop in order to find same element-types - other elements may be possible due to piped placeholders, too $bitAdd = true; //var_dump($arrElementsOnPage); foreach ($arrElementsOnPage as $objSingleElementOnPage) { if ($objSingleElementOnPage->getStrElement() == $objSourceElement->getStrElement()) { $bitAdd = false; } } if ($bitAdd) { $arrPlaceholdersDD[$arrSinglePlaceholder["placeholder"]] = $arrSinglePlaceholder["placeholder"]; } } } } } $bitCopyingAllowed = true; if (count($arrPlaceholdersDD) == 0) { $strReturn .= $this->objToolkit->formTextRow($this->getLang("copyElement_err_placeholder")); $bitCopyingAllowed = false; } else { $strReturn .= $this->objToolkit->formInputDropdown("copyElement_placeholder", $arrPlaceholdersDD, $this->getLang("copyElement_placeholder")); } $strReturn .= $this->objToolkit->formTextRow($this->getLang("copyElement_template") . " " . $strTemplate); $strReturn .= $this->objToolkit->divider(); $strReturn .= $this->objToolkit->formInputSubmit($this->getLang("copyElement_submit"), "Submit", "", "inputSubmit", $bitCopyingAllowed); $strReturn .= $this->objToolkit->formClose(); $strReturn .= "\n <script type=\"text/javascript\">\n\n \$(function() {\n var reloadForm = function() {\n setTimeout( function() {\n document.getElementById('copyElement_doCopy').value = 0;\n var formElement = document.getElementById('formCopyElement');\n formElement.submit();\n }, 100);\n\n };\n\n\t KAJONA.admin.copyElement_page.bind('autocompleteselect', reloadForm);\n\n\t var languageField = document.getElementById('copyElement_language');\n\t languageField.onchange = reloadForm;\n\n var pageField = document.getElementById('copyElement_page');\n\t pageField.onchange = reloadForm;\n\t });\n\n </script>"; //any actions to take? if ($this->getParam("copyElement_doCopy") == 1) { $objNewElement = $objSourceElement->copyObject($objPage->getSystemid()); $objNewElement->setStrLanguage($objLang->getStrName()); $objNewElement->setStrPlaceholder($this->getParam("copyElement_placeholder")); if ($objNewElement->updateObjectToDb()) { $this->setSystemid($objNewElement->getSystemid()); $strReturn = ""; $this->adminReload(class_link::getLinkAdminHref("pages_content", "list", "systemid=" . $objNewElement->getPrevId() . "&blockAction=1&peClose=1")); } else { throw new class_exception("Error copying the pageelement " . $objSourceElement->getSystemid(), class_exception::$level_ERROR); } } } else { $strReturn = $this->getLang("commons_error_permissions"); } return $strReturn; }