public static function copyBlocks($fromPageId, $toPageId)
    {
        $pageBlocks = NavItemPageBlockItem::find()->where(['nav_item_page_id' => $fromPageId])->asArray(true)->all();
        
        $idLink = [];
        foreach ($pageBlocks as $block) {
            $blockItem = new NavItemPageBlockItem();
            $blockItem->attributes = $block;
            $blockItem->nav_item_page_id = $toPageId;
            if ($blockItem->insert()) {
                $idLink[$block['id']] = $blockItem->id;
            }
        }
        
        // as blocks with subblocks have the previous block id stored in prev_id those values must be replaced from the old prev_id
        // with the new prev_id
        $newPageBlocks = NavItemPageBlockItem::find()->where(['nav_item_page_id' => $toPageId])->asArray(true)->all();
        foreach ($newPageBlocks as $block) {
            if ($block['prev_id'] && isset($idLink[$block['prev_id']])) {
                // update the given blocks' prev_id
                NavItemPageBlockItem::updateAll(['prev_id' => $idLink[$block['prev_id']]], ['id' => $block['id']]);
            }
        }
        
        return true;
    }
public static function copyBlocks($fromPageId, $toPageId)
    {
        $pageBlocks = NavItemPageBlockItem::find()->where(['nav_item_page_id' => $fromPageId])->asArray(true)->all();
        
        $idLink = [];
        foreach ($pageBlocks as $block) {
            $blockItem = new NavItemPageBlockItem();
            $blockItem->attributes = $block;
            $blockItem->nav_item_page_id = $toPageId;
            if ($blockItem->insert()) {
                $idLink[$block['id']] = $blockItem->id;
            }
        }
        
        // as blocks with subblocks have the previous block id stored in prev_id those values must be replaced from the old prev_id
        // with the new prev_id
        $newPageBlocks = NavItemPageBlockItem::find()->where(['nav_item_page_id' => $toPageId])->asArray(true)->all();
        foreach ($newPageBlocks as $block) {
            if ($block['prev_id'] && isset($idLink[$block['prev_id']])) {
                // update the given blocks' prev_id
                NavItemPageBlockItem::updateAll(['prev_id' => $idLink[$block['prev_id']]], ['id' => $block['id']]);
            }
        }
        
        return true;
    }
public static function copyBlocks ( $ fromPageId , $ toPageId ) { $ pageBlocks = NavItemPageBlockItem :: find ( ) -> where ( [ 'nav_item_page_id' => $ fromPageId ] ) -> asArray ( true ) -> all ( ) ; $ idLink = [ ] ; foreach ( $ pageBlocks as $ block ) { $ blockItem = new NavItemPageBlockItem ( ) ; $ blockItem -> attributes = $ block ; $ blockItem -> nav_item_page_id = $ toPageId ; if ( $ blockItem -> insert ( ) ) { $ idLink [ $ block [ 'id' ] ] = $ blockItem -> id ; } } // as blocks with subblocks have the previous block id stored in prev_id those values must be replaced from the old prev_id // with the new prev_id $ newPageBlocks = NavItemPageBlockItem :: find ( ) -> where ( [ 'nav_item_page_id' => $ toPageId ] ) -> asArray ( true ) -> all ( ) ; foreach ( $ newPageBlocks as $ block ) { if ( $ block [ 'prev_id' ] && isset ( $ idLink [ $ block [ 'prev_id' ] ] ) ) { // update the given blocks' prev_id NavItemPageBlockItem :: updateAll ( [ 'prev_id' => $ idLink [ $ block [ 'prev_id' ] ] ] , [ 'id' => $ block [ 'id' ] ] ) ; } } return true ; }
Copy blocks from one page to another.

@param integer $fromPageId
@param integer $toPageId
@return boolean
Copy blocks from one page to another .