/** * Copies Properties, Extensions, Permissions, Tags, assigned and embedded Cblocks * from another Page into a new version of this Page * * @param object $sourcePage Source Page object * @return bool TRUE on success or FALSE in case of an error * @throws Exception */ public function copyFrom(&$sourcePage) { if ($this->permissions->checkInternal($this->_uid, $this->_id, "RWRITE")) { $sourceID = $sourcePage->getID(); $sourceSite = $sourcePage->getSite(); $sourceVersion = $sourcePage->getVersion(); $targetID = (int) $this->_id; $targetVersion = (int) $this->getVersion(); $sourceVersionID = (int) $sourcePage->getPropertyId(); $targetVersionID = (int) $this->getPropertyId(); $sourceInfo = $sourcePage->get(); $this->copyExtensionsFrom($sourcePage); if ($sourceSite == $this->_site) { $this->permissions->copyTo($sourceID, $targetID); $this->properties->copyTo($sourceVersionID, $targetVersionID); $this->tags->copyTo($sourceID, $sourceVersion, $targetID, $targetVersion); } else { // Permissions $sourcePermissions = $sourcePage->permissions->getPermissions(); $this->permissions->setPermissions($sourcePermissions); // Properties $pageMgr = new PageMgr($this->getSite()); $propstocopy = $pageMgr->properties->getList(); $p = new Page($sourceSite, $sourceID, $sourceVersion); for ($i = 0; $i < count($propstocopy); $i++) { $scpd = $p->getPropertyId(); $sourcevalue = $p->properties->getValueInternal($propstocopy[$i]["IDENTIFIER"]); $this->properties->setValue($propstocopy[$i]["IDENTIFIER"], $sourcevalue); } // Tags $sourceTags = $sourcePage->tags->getAssigned(); foreach ($sourceTags as $sourceTag) { $this->tags->assign($sourceTag['ID']); } } $this->setTemplate($sourceInfo['TEMPLATEID']); $this->setNavigation($sourceInfo['NAVIGATIONID']); $this->setActive($sourceInfo['ACTIVE']); $this->setHidden($sourceInfo['HIDDEN']); // Clear contentareas $pageInfo = $this->get(); $templateMgr = new Templates(); $contentareas = $templateMgr->getContentareas($pageInfo['TEMPLATEID']); for ($i = 0; $i < count($contentareas); $i++) { $cblockList = $this->getCblockList($contentareas[$i]['CODE']); for ($x = 0; $x < count($cblockList); $x++) { $this->removeCblock($cblockList[$x]['ID'], $contentareas[$i]['CODE']); } } $pageInfo = $sourcePage->get(); $contentareas = $templateMgr->getContentareas($pageInfo['TEMPLATEID']); $finalCblockListLinkOrder = array(); for ($i = 0; $i < count($contentareas); $i++) { $cblockList = $sourcePage->getCblockList($contentareas[$i]['CODE']); for ($x = 0; $x < count($cblockList); $x++) { $coid = $cblockList[$x]['OBJECTID']; // Check if we have a blind contentblock if ($cblockList[$x]['EMBEDDED'] == 1) { // Yes, we have to copy it to the blind folder // Check which entrymasks are contained $sourcecb = sCblockMgr()->getCblock($coid, $cblockList[$x]['VERSION']); if ($sourcecb) { $src_entrymasks = $sourcecb->getEntrymasks(); // Create blind contentblocks with these entrymasks foreach ($src_entrymasks as $src_entrymask_item) { // Add new contentblock to folder $contentblockID = $this->addCblockEmbedded($contentareas[$i]['CODE']); $newcb = sCblockMgr()->getCblock($contentblockID); $newcb->setPagePermissions($sourcePage); $newcb->properties->setValue("NAME", $src_entrymask_item['ENTRYMASKNAME']); // Get the Link Id of the newly created contentblock (and save it) $finalCblockListLinkOrder[] = $this->getEmbeddedCblockLinkId($contentblockID); // Add requested control to contentblock $new_control = $newcb->addEntrymask($src_entrymask_item['ENTRYMASKID']); // Loop through all formfields $controlFormfields = $sourcecb->getFormfieldsInternal($src_entrymask_item['LINKID']); $newControlFormfields = $newcb->getFormfieldsInternal($new_control); // Fill all formfield parameter values with content from the source formfield for ($c = 0; $c < count($newControlFormfields); $c++) { $newcb->setFormfield($newControlFormfields[$c]['ID'], $controlFormfields[$c]['VALUE01'], $controlFormfields[$c]['VALUE02'], $controlFormfields[$c]['VALUE03'], $controlFormfields[$c]['VALUE04'], $controlFormfields[$c]['VALUE05'], $controlFormfields[$c]['VALUE06'], $controlFormfields[$c]['VALUE07'], $controlFormfields[$c]['VALUE08']); } } } } else { // No, it's a normal one, just link it to the page (and save the Link Id) $finalCblockListLinkOrder[] = $this->addCblockLink($coid, $contentareas[$i]['CODE']); } } } $this->setCblockLinkOrder($finalCblockListLinkOrder); return true; } else { return false; } }