public function createRedirectItem($navId, $langId, $title, $alias, $redirectType, $redirectTypeValue, $description, $redirectTypeTarget)
    {
        $_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, 'target' => $redirectTypeTarget];

        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(false); // as validation is done already

        $navItem->nav_item_type_id = $navItemRedirect->id;
        $navItemId = $navItem->save(false); // as validation is done already

        return $navItem->id;
    }
public function createRedirectItem($navId, $langId, $title, $alias, $redirectType, $redirectTypeValue, $description, $redirectTypeTarget)
    {
        $_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, 'target' => $redirectTypeTarget];

        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(false); // as validation is done already

        $navItem->nav_item_type_id = $navItemRedirect->id;
        $navItemId = $navItem->save(false); // as validation is done already

        return $navItem->id;
    }
public function createRedirectItem ( $ navId , $ langId , $ title , $ alias , $ redirectType , $ redirectTypeValue , $ description , $ redirectTypeTarget ) { $ _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 , 'target' => $ redirectTypeTarget ] ; 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 ( false ) ; // as validation is done already $ navItem -> nav_item_type_id = $ navItemRedirect -> id ; $ navItemId = $ navItem -> save ( false ) ; // as validation is done already return $ navItem -> id ; }
Create a redirecte for a given Nav Model.
@param integer $navId
@param integer $langId
@param string $title
@param string $alias
@param integer $redirectType The type of redirect (1 = page, 2 = URL, 3 = Link to File)
@param string $redirectTypeValue Depending on the type (1 = cms_nav.id, 2 = http://luya.io)
@param string $description
@param string $redirectTypeTarget redirect target (_blank, self) (since 2.0)
@return array|integer If an array is returned the validationed failed, the array contains the error messages. If sucess the navItem ID is returned.
Create a redirecte for a given Nav Model .