/** * Copies the menu links for the sourceContent to the targetContent * * @parameter int The id of the source content * @parameter int The id of the target content * * @return bool false - The save operation has failed * true - The save operation has correctly done */ public static function copyRelatedElements($sourceContent, $targetContent) { $bRollBack = false; $con = Propel::getConnection(); $con = w3sPropelWorkaround::beginTransaction($con); // Deletes all the target menus $targetMenus = W3sMenuElementPeer::getContentMenu($targetContent); foreach ($targetMenus as $targetMenu) { $targetMenu->delete(); } // Retrieves the menu rows related to source content $sourceMenus = DbFinder::from('W3sMenuElement')->where('contentId', $sourceContent)->orderBy('position')->find(); foreach ($sourceMenus as $sourceMenu) { $oTargetMenu = new W3sMenuElement(); $contentValues = array("ContentId" => $targetContent, "PageId" => $sourceMenu->getPageId(), "Link" => $sourceMenu->getLink(), "ExternalLink" => $sourceMenu->getExternalLink(), "Image" => $sourceMenu->getImage(), "RolloverImage" => $sourceMenu->getRolloverImage(), "Position" => $sourceMenu->getPosition()); $oTargetMenu->fromArray($contentValues); // Saves $result = $oTargetMenu->save(); if ($oTargetMenu->isModified() && $result == 0) { $bRollBack = true; break; } } if (!$bRollBack) { // Everything was fine so W3StudioCMS commits to database $con->commit(); $result = true; } else { // Something was wrong so W3StudioCMS aborts the operation and restores to previous status w3sPropelWorkaround::rollBack($con); $result = false; } return $result; }
/** * Inserts the menu links related to the inserted content, * into the w3sMenuElements table * * @return bool * */ protected function setDefaultRelatedElements() { $bRollBack = false; $con = Propel::getConnection(); $con = w3sPropelWorkaround::beginTransaction($con); for ($i = 1; $i < 4; $i++) { $newMenu = new W3sMenuElement(); $contentValues = array("ContentId" => $this->content->getId(), "PageId" => 0, "Link" => w3sCommonFunctions::toI18n('This is a link'), "ExternalLink" => '', "Image" => '', "RolloverImage" => '', "Position" => $i); $newMenu->fromArray($contentValues); $result = $newMenu->save(); if ($newMenu->isModified() && $result == 0) { $bRollBack = true; break; } } if (!$bRollBack) { // Everything was fine so W3StudioCMS commits to database $con->commit(); $result = true; } else { // Something was wrong so W3StudioCMS aborts the operation and restores to previous status w3sPropelWorkaround::rollBack($con); $result = false; } }
public function saveMenuLink($linkText) { $menu = new W3sMenuElement(); $menu->setContentId($this->content->getId()); $menu->setLink($linkText); $menu->setPosition(W3sMenuElementPeer::getMaxPosition($this->content->getId()) + 1); return $menu->save(); }