Beispiel #1
0
 protected function _getNodeJson(Bubble_CmsTree_Model_Cms_Page $page)
 {
     $item = array();
     $selres = $this->getSelectedResources();
     $item['text'] = $page->getTitle();
     $item['sort_order'] = $page->getPosition();
     $item['id'] = $page->getId();
     if (in_array($item['id'], $selres)) {
         $item['checked'] = true;
     }
     $children = $page->getChildren();
     if (empty($children)) {
         return $item;
     }
     if ($children) {
         $item['children'] = array();
         foreach ($children as $child) {
             $item['children'][] = $this->_getNodeJson($child);
         }
         if (!empty($item['children'])) {
             usort($item['children'], array($this, '_sortTree'));
         }
     }
     return $item;
 }
$installer->run("\n    DROP TABLE IF EXISTS `{$tablePageTree}`;\n    CREATE TABLE `{$tablePageTree}` LIKE `{$tablePage}`;\n\n    ALTER TABLE `{$tablePageTree}`\n        ADD `store_id` SMALLINT( 5 ) UNSIGNED NOT NULL DEFAULT 0,\n        ADD `parent_id` SMALLINT( 6 ) NOT NULL DEFAULT 0,\n        ADD `path` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,\n        ADD `position` SMALLINT( 6 ) UNSIGNED NOT NULL DEFAULT 0,\n        ADD `level` TINYINT( 3 ) UNSIGNED NOT NULL DEFAULT 0,\n        ADD `include_in_menu` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '1',\n        ADD `children_count` TINYINT( 3 ) UNSIGNED NOT NULL DEFAULT 0;\n\n    ALTER TABLE `{$tablePageTree}` CHANGE `identifier` `identifier` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '';\n\n    ALTER TABLE `{$tablePageTree}` ADD INDEX ( `store_id` );\n\n    ALTER TABLE `{$tablePageTree}` ADD FOREIGN KEY ( `store_id` ) REFERENCES `{$tableStore}` (\n        `store_id`\n    ) ON DELETE CASCADE ON UPDATE CASCADE;\n\n    ALTER TABLE `{$tablePageTree}` ADD UNIQUE (\n        `identifier` ,\n        `store_id`\n    );\n\n    DROP TABLE IF EXISTS `{$tablePermission}`;\n    CREATE TABLE `{$tablePermission}` (\n        `permission_id` MEDIUMINT(8) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,\n        `store_id` SMALLINT(5) UNSIGNED NOT NULL,\n        `customer_group_id` SMALLINT(3) UNSIGNED NOT NULL,\n        `page_id` SMALLINT(6) NOT NULL\n    ) ENGINE = INNODB CHARACTER SET utf8 COLLATE utf8_general_ci;\n\n    ALTER TABLE `{$tablePermission}` ADD INDEX (`store_id`);\n    ALTER TABLE `{$tablePermission}` ADD INDEX (`customer_group_id`);\n    ALTER TABLE `{$tablePermission}` ADD INDEX (`page_id`);\n    ALTER TABLE `{$tablePermission}` ADD UNIQUE (`store_id`, `customer_group_id`, `page_id`);\n\n    ALTER TABLE `{$tablePermission}` ADD FOREIGN KEY (`store_id`) REFERENCES `{$tableStore}` (\n        `store_id`\n    ) ON DELETE CASCADE ON UPDATE CASCADE;\n\n    ALTER TABLE `{$tablePermission}` ADD FOREIGN KEY (`customer_group_id`) REFERENCES `{$tableCustomerGroup}` (\n        `customer_group_id`\n    ) ON DELETE CASCADE ON UPDATE CASCADE;\n\n    ALTER TABLE `{$tablePermission}` ADD FOREIGN KEY (`page_id`) REFERENCES `{$tablePageTree}` (\n        `page_id`\n    ) ON DELETE CASCADE ON UPDATE CASCADE;\n");
Mage::app()->reinitStores();
// needed to have store list
$isSingleStoreMode = Mage::app()->isSingleStoreMode();
$stores = Mage::app()->getStores(!$isSingleStoreMode);
// Create pages
foreach ($stores as $store) {
    $storeId = $store->getId();
    // Retrieve old store pages
    $select = $connection->select()->from(array('pages' => $tablePage))->join(array('stores' => $tablePageStore), 'pages.page_id = stores.page_id', '')->where('stores.store_id = ?', $storeId);
    if ($isSingleStoreMode) {
        $select->orWhere('stores.store_id = 0');
    }
    $pages = $connection->fetchAll($select);
    // Create default root page for this store
    $home = Bubble_CmsTree_Model_Cms_Page::createDefaultStoreRootPage($storeId);
    $homeId = $home->getId();
    if (count($pages) > 0) {
        $insertedPages = array();
        $childrenCount = 0;
        foreach ($pages as $page) {
            if (!isset($insertedPages[$page['identifier']])) {
                $insertedPages[$page['identifier']] = 0;
            } else {
                $insertedPages[$page['identifier']]++;
                $page['identifier'] = $page['identifier'] . '-' . $insertedPages[$page['identifier']];
            }
            unset($page['page_id']);
            $page['parent_id'] = $homeId;
            $page['store_id'] = $storeId;
            $connection->insert($tablePageTree, $page);
 public function addAllChildrenFilter(Bubble_CmsTree_Model_Cms_Page $page)
 {
     $this->addFieldToFilter('identifier', array('like' => ltrim($page->getIdentifier() . '/%', '/')))->addFieldToFilter('store_id', $page->getStoreId());
     return $this;
 }
 public function getRoot($parentNodePage = null, $recursionLevel = 3)
 {
     if (!is_null($parentNodePage) && $parentNodePage->getId()) {
         return $this->getNode($parentNodePage, $recursionLevel);
     }
     $root = Mage::registry('root');
     if (is_null($root)) {
         $storeId = (int) $this->getRequest()->getParam('store');
         $rootId = Mage::getResourceModel('cms/page')->getStoreRootId($storeId);
         if (!$rootId) {
             $newRoot = Bubble_CmsTree_Model_Cms_Page::createDefaultStoreRootPage($storeId);
             $rootId = $newRoot->getId();
         }
         $tree = Mage::getResourceSingleton('cms/page_tree')->load(null, $recursionLevel);
         if ($this->getPage()) {
             $tree->loadEnsuredNodes($this->getPage(), $tree->getNodeById($rootId));
         }
         $tree->addCollectionData($this->getPageCollection());
         $root = $tree->getNodeById($rootId);
         if (!$root) {
             Mage::throwException('Could not retrieve root page of store ' . $storeId);
         }
         $root->setIsVisible(true);
         $root->setName($root->getTitle());
         if ($this->_withChildrenCount) {
             $root->setName($root->getName() . ' (' . $root->getChildrenCount() . ')');
         }
         Mage::register('root', $root);
     }
     return $root;
 }