/**
  * 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;
 }
 /**
  * Renders the menu
  *  
  * @parameter  array - An array with two optional parameters: 
  * 											w3s_assigned_to     The tag which the class is assigned
  * 											w3s_assigned_class  The name of the class
  * 
  * @return     string - The rendered menu 
  * 
  */
 protected function renderMenu($params = array())
 {
     $result = '';
     // Retrieves the menu, the language name and the page name from the current content
     $menu = W3sMenuElementPeer::getContentMenu($this->content->getId());
     $language = $this->content->getW3sLanguage()->getLanguage();
     $classForPage = $this->content->getW3sPage()->getPageName();
     $assignedTo = array_key_exists('w3s_assigned_to', $params) ? $params['w3s_assigned_to'] : 'li';
     $className = array_key_exists('w3s_assigned_class', $params) ? $params['w3s_assigned_class'] : 'w3sNone';
     // Cycles the menu elements
     foreach ($menu as $menuRow) {
         $idPage = $menuRow->getPageId();
         // Checks if link is internal or external
         if ($idPage != 0) {
             // Checks if page exists
             $oPage = DbFinder::from('W3sPage')->findPK($idPage);
             if ($oPage != null) {
                 $pageName = $oPage->getPageName();
                 $class = $className != 'w3sNone' && $classForPage == $pageName ? sprintf(' class="%s"', $className) : '';
                 $link = sprintf('/%s/%s.html', $language, $pageName);
                 $onclickEvent = '';
             } else {
                 $class = '';
                 $link = '#';
                 $onclickEvent = ' onclick="alert(\'This page has been removed from the website\')"';
             }
         } else {
             $class = '';
             $onclickEvent = '';
             $link = $menuRow->getExternalLink();
         }
         // Link name or image
         if ($menuRow->getImage() != '') {
             $rollover = $menuRow->getRolloverImage() != '' ? sprintf(' onmouseover="this.src=\'/images/%s\'" onmouseout="this.src=\'/images/%s\'"', $menuRow->getRolloverImage(), $menuRow->getImage()) : '';
             $linkText = sprintf('<img src="/images/%s"%s/>', $menuRow->getImage(), $rollover);
         } else {
             $linkText = $menuRow->getLink();
         }
         $result .= sprintf('<li%s><a href="%s"%s%s>%s</a></li>', $assignedTo == 'li' ? $class : '', $link, $onclickEvent, $assignedTo == 'a' ? $class : '', $linkText);
     }
     $result = sprintf('<ul>%s</ul>', $result);
     return $result;
 }
Пример #3
0
 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();
 }