/** * Makes a copy of the current element and saves it attached to the given page. * This copy includes the records in the elements' foreign tables * * @param string $strNewPage * @param bool $bitChangeTitle * * @throws class_exception * @return class_module_pages_pageelement the new element or null in case of an error */ public function copyObject($strNewPage = "", $bitChangeTitle = true, $bitCopyChilds = true) { class_logger::getInstance()->addLogRow("copy pageelement " . $this->getSystemid(), class_logger::$levelInfo); $this->objDB->transactionBegin(); //fetch all values to insert after the general copy process - mainly the foreign table $objElement = $this->getConcreteAdminInstance(); $arrElementData = $objElement->loadElementData(); //duplicate the current elements - afterwards $this is the new element parent::copyObject($strNewPage, $bitChangeTitle, $bitCopyChilds); //copy the old contents into the new elements $objElement = $this->getConcreteAdminInstance(); $arrNewElementData = $objElement->loadElementData(); $arrElementData["content_id"] = $arrNewElementData["content_id"]; $arrElementData["page_element_id"] = $arrNewElementData["page_element_id"]; $arrElementData["system_id"] = $arrNewElementData["system_id"]; $objElement->setArrParamData($arrElementData); //try to find setters to inject the values $objAnnotation = new class_reflection($objElement); $arrMappedProperties = $objAnnotation->getPropertiesWithAnnotation(class_orm_base::STR_ANNOTATION_TABLECOLUMN); foreach ($arrElementData as $strColumn => $strValue) { foreach ($arrMappedProperties as $strPropertyname => $strAnnotation) { $strMappedColumn = uniSubstr($strAnnotation, uniStrpos($strAnnotation, ".") + 1); if ($strColumn == $strMappedColumn) { $objSetter = $objAnnotation->getSetter($strPropertyname); if ($objSetter != null) { call_user_func_array(array($objElement, $objSetter), array($strValue)); } } } } $objElement->doBeforeSaveToDb(); $objElement->updateForeignElement(); $objElement->doAfterSaveToDb(); $this->objDB->transactionCommit(); return $this; }
/** * @param string $strNewPrevid * @param bool $bitChangeTitle * * @return bool */ public function copyObject($strNewPrevid = "", $bitChangeTitle = true, $bitCopyChilds = true) { $strPrefix = $this->getStrName() . "_"; $intCount = 1; $strQuery = "SELECT COUNT(*) FROM " . _dbprefix_ . "tags_tag WHERE tags_tag_name = ?"; $arrRow = $this->objDB->getPRow($strQuery, array($strPrefix . $intCount)); while ($arrRow["COUNT(*)"] > 0) { $arrRow = $this->objDB->getPRow($strQuery, array($strPrefix . ++$intCount)); } $this->setStrName($strPrefix . $intCount); //save assigned records $arrRecords = $this->getListOfAssignments(); parent::copyObject($strNewPrevid, $bitChangeTitle, $bitCopyChilds); //copy the tag assignments foreach ($arrRecords as $arrOneRecord) { $this->assignToSystemrecord($arrOneRecord["tags_systemid"]); } return true; }
/** * Does a deep copy of the current page. * Inlcudes all page-elements created on the page * and all languages. * * @param string $strNewPrevid * @param bool $bitChangeTitle * * @return bool */ public function copyObject($strNewPrevid = "", $bitChangeTitle = true, $bitCopyChilds = true) { $this->objDB->transactionBegin(); //fetch data to be updated after the general copy process //page-properties, language dependant $arrBasicSourceProperties = $this->objDB->getPArray("SELECT * FROM " . _dbprefix_ . "page_properties WHERE pageproperties_id = ?", array($this->getSystemid())); //create a new page-name $this->setStrName($this->generateNonexistingPagename($this->getStrName(), false)); //copy the page-instance and all elements on the page parent::copyObject($strNewPrevid, $bitChangeTitle, $bitCopyChilds); //update the pages' properties in the table - manually foreach ($arrBasicSourceProperties as $arrOneProperty) { //insert or update - the properties for the current language should aready be in place $this->objDB->flushQueryCache(); $arrCount = $this->objDB->getPRow("SELECT COUNT(*) FROM " . _dbprefix_ . "page_properties WHERE pageproperties_id = ? AND pageproperties_language = ? ", array($this->getSystemid(), $arrOneProperty["pageproperties_language"])); if ($arrCount["COUNT(*)"] == 0) { $strQuery = "INSERT INTO " . _dbprefix_ . "page_properties\n (pageproperties_browsername,\n pageproperties_keywords,\n pageproperties_description,\n pageproperties_template,\n pageproperties_seostring,\n pageproperties_alias,\n pageproperties_path,\n pageproperties_target,\n pageproperties_language,\n pageproperties_id\n ) VALUES\n (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; } else { $strQuery = "UPDATE " . _dbprefix_ . "page_properties\n SET pageproperties_browsername = ?,\n pageproperties_keywords = ?,\n pageproperties_description = ?,\n pageproperties_template = ?,\n pageproperties_seostring = ?,\n pageproperties_alias = ?,\n pageproperties_path = ?,\n pageproperties_target = ?\n WHERE pageproperties_language = ?\n AND pageproperties_id = ?"; } $arrValues = array($arrOneProperty["pageproperties_browsername"], $arrOneProperty["pageproperties_keywords"], $arrOneProperty["pageproperties_description"], $arrOneProperty["pageproperties_template"], $arrOneProperty["pageproperties_seostring"], $arrOneProperty["pageproperties_alias"], $arrOneProperty["pageproperties_path"], $arrOneProperty["pageproperties_target"], $arrOneProperty["pageproperties_language"], $this->getSystemid()); if (!$this->objDB->_pQuery($strQuery, $arrValues, array(false, false, false, false, false, false, false, false))) { $this->objDB->transactionRollback(); class_logger::getInstance()->addLogRow("error while copying page properties", class_logger::$levelError); return false; } } $this->objDB->transactionCommit(); return $this; }