Beispiel #1
0
 /**
  *
  * @param unknown $navId
  * @param unknown $langId
  * @param unknown $title
  * @param unknown $alias
  * @param unknown $redirectType The type of redirect (1 = page, 2 = URL, 3 = Link to File)
  * @param unknown $redirectTypeValue Depending on the type (1 = cms_nav.id, 2 = http://luya.io)
  * @param unknown $description
  * @return boolean
  */
 public function createRedirectItem($navId, $langId, $title, $alias, $redirectType, $redirectTypeValue, $description)
 {
     $_errors = [];
     $navItem = new NavItem();
     $navItem->parent_nav_id = self::findOne($navId)->parent_nav_id;
     $navItemRedirect = new NavItemRedirect();
     $navItem->attributes = ['nav_id' => $navId, 'lang_id' => $langId, 'title' => $title, 'alias' => $alias, 'description' => $description, 'nav_item_type' => 3];
     $navItemRedirect->attributes = ['type' => $redirectType, 'value' => $redirectTypeValue];
     if (!$navItem->validate()) {
         $_errors = ArrayHelper::merge($navItem->getErrors(), $_errors);
     }
     if (!$navItemRedirect->validate()) {
         $_errors = ArrayHelper::merge($navItemRedirect->getErrors(), $_errors);
     }
     if (!empty($_errors)) {
         return $_errors;
     }
     $navItemRedirect->save();
     $navItem->nav_item_type_id = $navItemRedirect->id;
     $navItemId = $navItem->save();
     return $navItemId;
 }
Beispiel #2
0
 /**
  *
  * Copy content of type cms_nav_item_redirect to a target nav item. This will create a new entry in cms_nav_item_redirect.
  *
  * @param $targetNavItem
  * @return bool
  */
 public function copyRedirectItem($targetNavItem)
 {
     if ($this->nav_item_type !== 3) {
         return false;
     }
     $sourceRedirectItem = NavItemRedirect::findOne($this->nav_item_type_id);
     if (!$sourceRedirectItem) {
         return false;
     }
     $redirectItem = new NavItemRedirect();
     $redirectItem->attributes = $sourceRedirectItem->toArray();
     if (!$redirectItem->save()) {
         return false;
     }
     $targetNavItem->nav_item_type_id = $redirectItem->id;
     return $targetNavItem->save();
 }