Scandi_MenuManager - Version 0.1.0

Version Notes

Stable Release.

Download this release

Release Info

Developer Scandiweb
Extension Scandi_MenuManager
Version 0.1.0
Comparing to
See all releases


Version 0.1.0

Files changed (28) hide show
  1. app/code/local/Scandi/MenuManager/Block/Adminhtml/Menu.php +38 -0
  2. app/code/local/Scandi/MenuManager/Block/Adminhtml/Menu/Edit.php +107 -0
  3. app/code/local/Scandi/MenuManager/Block/Adminhtml/Menu/Edit/Form.php +34 -0
  4. app/code/local/Scandi/MenuManager/Block/Adminhtml/Menu/Edit/Tab/Items.php +121 -0
  5. app/code/local/Scandi/MenuManager/Block/Adminhtml/Menu/Edit/Tab/Main.php +154 -0
  6. app/code/local/Scandi/MenuManager/Block/Adminhtml/Menu/Edit/Tab/Renderer/Parent.php +35 -0
  7. app/code/local/Scandi/MenuManager/Block/Adminhtml/Menu/Edit/Tabs.php +60 -0
  8. app/code/local/Scandi/MenuManager/Block/Adminhtml/Menu/Grid.php +132 -0
  9. app/code/local/Scandi/MenuManager/Block/Adminhtml/Menu/Item/Edit.php +83 -0
  10. app/code/local/Scandi/MenuManager/Block/Adminhtml/Menu/Item/Edit/Form.php +128 -0
  11. app/code/local/Scandi/MenuManager/Block/Menu.php +358 -0
  12. app/code/local/Scandi/MenuManager/Helper/Data.php +20 -0
  13. app/code/local/Scandi/MenuManager/Model/Item.php +45 -0
  14. app/code/local/Scandi/MenuManager/Model/Menu.php +52 -0
  15. app/code/local/Scandi/MenuManager/Model/Resource/Item.php +74 -0
  16. app/code/local/Scandi/MenuManager/Model/Resource/Item/Collection.php +86 -0
  17. app/code/local/Scandi/MenuManager/Model/Resource/Menu.php +209 -0
  18. app/code/local/Scandi/MenuManager/Model/Resource/Menu/Collection.php +70 -0
  19. app/code/local/Scandi/MenuManager/controllers/Adminhtml/IndexController.php +332 -0
  20. app/code/local/Scandi/MenuManager/etc/adminhtml.xml +42 -0
  21. app/code/local/Scandi/MenuManager/etc/config.xml +88 -0
  22. app/code/local/Scandi/MenuManager/sql/scandi_menumanager_setup/install-0.1.0.php +172 -0
  23. app/design/adminhtml/default/default/layout/scandi_menumanager.xml +38 -0
  24. app/design/frontend/base/default/layout/scandi_menumanager.xml +19 -0
  25. app/design/frontend/base/default/template/scandi/menumanager/menu.phtml +21 -0
  26. app/etc/modules/Scandi_MenuManager.xml +24 -0
  27. package.xml +19 -0
  28. skin/frontend/base/default/scandi/menumanager/css/menumanager.css +37 -0
app/code/local/Scandi/MenuManager/Block/Adminhtml/Menu.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Scandi_MenuManager
4
+ *
5
+ * @category Scandi
6
+ * @package Scandi_MenuManager
7
+ * @author Scandiweb <info@scandiweb.com>
8
+ * @copyright Copyright (c) 2013 Scandiweb, Ltd (http://scandiweb.com)
9
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
10
+ */
11
+
12
+ /**
13
+ * MenuManager menu grid container
14
+ *
15
+ * @category Scandi
16
+ * @package Scandi_MenuManager
17
+ */
18
+ class Scandi_MenuManager_Block_Adminhtml_Menu extends Mage_Adminhtml_Block_Widget_Grid_Container
19
+ {
20
+ public function __construct()
21
+ {
22
+ $this->_controller = 'adminhtml_menu';
23
+ $this->_blockGroup = 'scandi_menumanager';
24
+ $this->_headerText = Mage::helper('scandi_menumanager')->__('Manage Menus');
25
+
26
+ parent::__construct();
27
+ }
28
+
29
+ /**
30
+ * Get header css class
31
+ *
32
+ * @return string
33
+ */
34
+ public function getHeaderCssClass()
35
+ {
36
+ return 'icon-head head-cms-block ' . parent::getHeaderCssClass();
37
+ }
38
+ }
app/code/local/Scandi/MenuManager/Block/Adminhtml/Menu/Edit.php ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Scandi_MenuManager
4
+ *
5
+ * @category Scandi
6
+ * @package Scandi_MenuManager
7
+ * @author Scandiweb <info@scandiweb.com>
8
+ * @copyright Copyright (c) 2013 Scandiweb, Ltd (http://scandiweb.com)
9
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
10
+ */
11
+
12
+ /**
13
+ * MenuManager menu edit form container
14
+ *
15
+ * @category Scandi
16
+ * @package Scandi_MenuManager
17
+ */
18
+ class Scandi_MenuManager_Block_Adminhtml_Menu_Edit
19
+ extends Mage_Adminhtml_Block_Widget_Form_Container
20
+ {
21
+ public function __construct()
22
+ {
23
+ $this->_objectId = 'menu_id';
24
+ $this->_controller = 'adminhtml_menu';
25
+ $this->_blockGroup = 'scandi_menumanager';
26
+
27
+ parent::__construct();
28
+
29
+ $this->_addButton('saveandcontinue', array(
30
+ 'label' => Mage::helper('adminhtml')->__('Save and Continue Edit'),
31
+ 'onclick' => 'saveAndContinueEdit(\'' . $this->_getSaveAndContinueUrl() . '\')',
32
+ 'class' => 'save',
33
+ ), -100);
34
+
35
+ if (Mage::registry('menumanager_menu')->getId()) {
36
+ $this->_addButton('addmenuitem', array(
37
+ 'label' => Mage::helper('scandi_menumanager')->__('Add Menu Item'),
38
+ 'onclick' => 'setLocation(\'' . $this->_getAddMenuItemUrl() . '\')',
39
+ 'class' => 'add'
40
+ ), 0);
41
+ }
42
+
43
+ $this->_formScripts[] = "
44
+ function saveAndContinueEdit(urlTemplate) {
45
+ var template = new Template(urlTemplate, /(^|.|\\r|\\n)({{(\w+)}})/),
46
+ tabsIdValue = menu_page_tabsJsTabs.activeTab.id,
47
+ url = template.evaluate({tab_id:tabsIdValue});
48
+
49
+ editForm.submit(url);
50
+ }
51
+ ";
52
+ }
53
+
54
+ /**
55
+ * Retrieve text for header element depending on loaded page
56
+ *
57
+ * @return string
58
+ */
59
+ public function getHeaderText()
60
+ {
61
+ if (Mage::registry('menumanager_menu')->getId()) {
62
+ return Mage::helper('scandi_menumanager')->__("Edit Menu '%s'",
63
+ $this->escapeHtml(Mage::registry('menumanager_menu')->getTitle()));
64
+ } else {
65
+ return Mage::helper('scandi_menumanager')->__('New Menu');
66
+ }
67
+ }
68
+
69
+ /**
70
+ * Get header css class
71
+ *
72
+ * @return string
73
+ */
74
+ public function getHeaderCssClass()
75
+ {
76
+ return 'icon-head head-cms-block ' . strtr($this->_controller, '_', '-');
77
+ }
78
+
79
+ /**
80
+ * Getter of url for "Save and Continue" button
81
+ *
82
+ * @return string
83
+ */
84
+ protected function _getSaveAndContinueUrl()
85
+ {
86
+ return $this->getUrl('*/*/save', array(
87
+ '_current' => true,
88
+ 'back' => 'edit',
89
+ 'active_tab' => '{{tab_id}}'
90
+ ));
91
+ }
92
+
93
+ /**
94
+ * Getter of url for "Add Menu Item" button
95
+ *
96
+ * @return string
97
+ */
98
+ protected function _getAddMenuItemUrl()
99
+ {
100
+ $request = $this->getRequest();
101
+
102
+ return $this->getUrl('*/*/new_item', array(
103
+ 'menu_id' => $request->getParam('menu_id'),
104
+ 'active_tab' => $request->getParam('active_tab'),
105
+ ));
106
+ }
107
+ }
app/code/local/Scandi/MenuManager/Block/Adminhtml/Menu/Edit/Form.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Scandi_MenuManager
4
+ *
5
+ * @category Scandi
6
+ * @package Scandi_MenuManager
7
+ * @author Scandiweb <info@scandiweb.com>
8
+ * @copyright Copyright (c) 2013 Scandiweb, Ltd (http://scandiweb.com)
9
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
10
+ */
11
+
12
+ /**
13
+ * MenuManager menu edit form block
14
+ *
15
+ * @category Scandi
16
+ * @package Scandi_MenuManager
17
+ */
18
+ class Scandi_MenuManager_Block_Adminhtml_Menu_Edit_Form
19
+ extends Mage_Adminhtml_Block_Widget_Form
20
+ {
21
+ protected function _prepareForm()
22
+ {
23
+ $form = new Varien_Data_Form(array(
24
+ 'method' => 'post',
25
+ 'id' => 'edit_form',
26
+ 'action' => $this->getUrl('*/*/save')
27
+ ));
28
+
29
+ $form->setUseContainer(true);
30
+ $this->setForm($form);
31
+
32
+ return parent::_prepareForm();
33
+ }
34
+ }
app/code/local/Scandi/MenuManager/Block/Adminhtml/Menu/Edit/Tab/Items.php ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Scandi_MenuManager
4
+ *
5
+ * @category Scandi
6
+ * @package Scandi_MenuManager
7
+ * @author Scandiweb <info@scandiweb.com>
8
+ * @copyright Copyright (c) 2013 Scandiweb, Ltd (http://scandiweb.com)
9
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
10
+ */
11
+
12
+ /**
13
+ * MenuManager menu items grid
14
+ *
15
+ * @category Scandi
16
+ * @package Scandi_MenuManager
17
+ */
18
+ class Scandi_MenuManager_Block_Adminhtml_Menu_Edit_Tab_Items
19
+ extends Mage_Adminhtml_Block_Widget_Grid
20
+ {
21
+ public function __construct()
22
+ {
23
+ parent::__construct();
24
+
25
+ $this->setId('cmsMenuItemsGrid');
26
+ $this->setSaveParametersInSession(true);
27
+ }
28
+
29
+ /**
30
+ * Prepare collection for grid
31
+ *
32
+ * @return Scandi_MenuManager_Block_Adminhtml_Menu_Edit_Tab_Items
33
+ */
34
+ protected function _prepareCollection()
35
+ {
36
+ /* @var $collection Scandi_MenuManager_Model_Resource_Item_Collection */
37
+ $collection = Mage::getModel('scandi_menumanager/item')->getResourceCollection()
38
+ ->addMenuFilter(Mage::registry('menumanager_menu'))
39
+ ->setPositionOrder();
40
+
41
+ $this->setCollection($collection);
42
+ return parent::_prepareCollection();
43
+ }
44
+
45
+ /**
46
+ * Prepare grid columns
47
+ *
48
+ * @return Scandi_MenuManager_Block_Adminhtml_Menu_Edit_Tab_Items
49
+ */
50
+ protected function _prepareColumns()
51
+ {
52
+ /* @var $model Scandi_MenuManager_Model_Menu*/
53
+ $menuModel = Mage::registry('menumanager_menu');
54
+
55
+ /* @var $model Scandi_MenuManager_Model_Item*/
56
+ $ItemModel = Mage::getModel('scandi_menumanager/item');
57
+
58
+ $this->addColumn('item_title', array(
59
+ 'header' => Mage::helper('scandi_menumanager')->__('Title'),
60
+ 'index' => 'title',
61
+ ));
62
+
63
+ $this->addColumn('item_parent_id', array(
64
+ 'header' => Mage::helper('scandi_menumanager')->__('Parent'),
65
+ 'index' => 'parent_id',
66
+ 'type' => 'options',
67
+ 'renderer' => 'Scandi_MenuManager_Block_Adminhtml_Menu_Edit_Tab_Renderer_Parent',
68
+ 'options' => $ItemModel->getCollection()
69
+ ->addMenuFilter($menuModel)
70
+ ->toItemOptionArray(),
71
+ ));
72
+
73
+ $this->addColumn('item_url', array(
74
+ 'header' => Mage::helper('scandi_menumanager')->__('Url'),
75
+ 'index' => 'url',
76
+ ));
77
+
78
+ $this->addColumn('item_type', array(
79
+ 'header' => Mage::helper('scandi_menumanager')->__('Type'),
80
+ 'index' => 'type',
81
+ 'type' => 'options',
82
+ 'options' => $ItemModel->getAvailableTypes(),
83
+ ));
84
+
85
+ $this->addColumn('item_css_class', array(
86
+ 'header' => Mage::helper('scandi_menumanager')->__('CSS Class'),
87
+ 'index' => 'css_class',
88
+ ));
89
+
90
+ $this->addColumn('item_position', array(
91
+ 'header' => Mage::helper('scandi_menumanager')->__('Position'),
92
+ 'index' => 'position',
93
+ ));
94
+
95
+ $this->addColumn('item_is_active', array(
96
+ 'header' => Mage::helper('scandi_menumanager')->__('Status'),
97
+ 'index' => 'is_active',
98
+ 'type' => 'options',
99
+ 'options' => array(
100
+ 0 => Mage::helper('scandi_menumanager')->__('Disabled'),
101
+ 1 => Mage::helper('scandi_menumanager')->__('Enabled')
102
+ ),
103
+ ));
104
+
105
+ return parent::_prepareColumns();
106
+ }
107
+
108
+ /**
109
+ * Return row url
110
+ *
111
+ * @return string
112
+ */
113
+ public function getRowUrl($row)
114
+ {
115
+ return $this->getUrl('*/*/edit_item', array(
116
+ 'item_id' => $row->getId(),
117
+ 'active_tab' => 'menu_page_tabs_items_section',
118
+ 'menu_id' => $this->getRequest()->getParam('menu_id'),
119
+ ));
120
+ }
121
+ }
app/code/local/Scandi/MenuManager/Block/Adminhtml/Menu/Edit/Tab/Main.php ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Scandi_MenuManager
4
+ *
5
+ * @category Scandi
6
+ * @package Scandi_MenuManager
7
+ * @author Scandiweb <info@scandiweb.com>
8
+ * @copyright Copyright (c) 2013 Scandiweb, Ltd (http://scandiweb.com)
9
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
10
+ */
11
+
12
+ /**
13
+ * MenuManager menu edit page main tab
14
+ *
15
+ * @category Scandi
16
+ * @package Scandi_MenuManager
17
+ */
18
+ class Scandi_MenuManager_Block_Adminhtml_Menu_Edit_Tab_Main
19
+ extends Mage_Adminhtml_Block_Widget_Form
20
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface
21
+ {
22
+ protected function _prepareForm()
23
+ {
24
+ /* @var $model Scandi_MenuManager_Model_Menu */
25
+ $model = Mage::registry('menumanager_menu');
26
+
27
+ $form = new Varien_Data_Form();
28
+ $form->setHtmlIdPrefix('menu_');
29
+
30
+ $fieldset = $form->addFieldset('base_fieldset', array(
31
+ 'legend' => Mage::helper('scandi_menumanager')->__('General Information'))
32
+ );
33
+
34
+ if ($model->getMenuId()) {
35
+ $fieldset->addField('menu_id', 'hidden', array(
36
+ 'name' => 'menu_id',
37
+ ));
38
+ }
39
+
40
+ $fieldset->addField('title', 'text', array(
41
+ 'name' => 'title',
42
+ 'label' => Mage::helper('scandi_menumanager')->__('Title'),
43
+ 'title' => Mage::helper('scandi_menumanager')->__('Title'),
44
+ 'required' => true
45
+ ));
46
+
47
+ $fieldset->addField('identifier', 'text', array(
48
+ 'name' => 'identifier',
49
+ 'label' => Mage::helper('scandi_menumanager')->__('Identifier'),
50
+ 'title' => Mage::helper('scandi_menumanager')->__('Identifier'),
51
+ 'required' => true,
52
+ 'class' => 'validate-xml-identifier',
53
+ 'note' => Mage::helper('cms')->__('Must Be Unique Identifier Per Store View')
54
+ ));
55
+
56
+ $fieldset->addField('type', 'select', array(
57
+ 'name' => 'type',
58
+ 'label' => Mage::helper('scandi_menumanager')->__('Type'),
59
+ 'title' => Mage::helper('scandi_menumanager')->__('Type'),
60
+ 'options' => $model->getAvailableTypes(),
61
+ 'required' => true
62
+ ));
63
+
64
+ $fieldset->addField('css_class', 'text', array(
65
+ 'name' => 'css_class',
66
+ 'label' => Mage::helper('scandi_menumanager')->__('CSS Class'),
67
+ 'title' => Mage::helper('scandi_menumanager')->__('CSS Class'),
68
+ 'note' => Mage::helper('cms')->__('Space Separated Class Names')
69
+ ));
70
+
71
+ if (!Mage::app()->isSingleStoreMode()) {
72
+ $fieldset->addField('store_id', 'multiselect', array(
73
+ 'name' => 'stores[]',
74
+ 'label' => Mage::helper('scandi_menumanager')->__('Store View'),
75
+ 'title' => Mage::helper('scandi_menumanager')->__('Store View'),
76
+ 'required' => true,
77
+ 'values' => Mage::getSingleton('adminhtml/system_store')
78
+ ->getStoreValuesForForm(false, true)
79
+ ));
80
+ } else {
81
+ $fieldset->addField('store_id', 'hidden', array(
82
+ 'name' => 'stores[]',
83
+ 'value' => Mage::app()->getStore(true)->getId()
84
+ ));
85
+
86
+ $model->setStoreId(Mage::app()->getStore(true)->getId());
87
+ }
88
+
89
+ $fieldset->addField('is_active', 'select', array(
90
+ 'label' => Mage::helper('scandi_menumanager')->__('Status'),
91
+ 'title' => Mage::helper('scandi_menumanager')->__('Menu Status'),
92
+ 'name' => 'is_active',
93
+ 'required' => true,
94
+ 'options' => array(
95
+ '1' => Mage::helper('scandi_menumanager')->__('Enabled'),
96
+ '0' => Mage::helper('scandi_menumanager')->__('Disabled'),
97
+ ),
98
+ ));
99
+
100
+ if (!$model->getId()) {
101
+ $model->setData('is_active', '1');
102
+ }
103
+
104
+ Mage::dispatchEvent(
105
+ 'adminhtml_cms_menu_edit_tab_main_prepare_form',
106
+ array('form' => $form)
107
+ );
108
+
109
+ $form->setValues($model->getData());
110
+ $this->setForm($form);
111
+
112
+ return parent::_prepareForm();
113
+ }
114
+
115
+ /**
116
+ * Prepare label for tab
117
+ *
118
+ * @return string
119
+ */
120
+ public function getTabLabel()
121
+ {
122
+ return Mage::helper('scandi_menumanager')->__('General Information');
123
+ }
124
+
125
+ /**
126
+ * Prepare title for tab
127
+ *
128
+ * @return string
129
+ */
130
+ public function getTabTitle()
131
+ {
132
+ return Mage::helper('scandi_menumanager')->__('General Information');
133
+ }
134
+
135
+ /**
136
+ * Returns tab's status flag - can be shown or not
137
+ *
138
+ * @return boolean
139
+ */
140
+ public function canShowTab()
141
+ {
142
+ return true;
143
+ }
144
+
145
+ /**
146
+ * Returns tab's status flag - hidden or not
147
+ *
148
+ * @return boolean
149
+ */
150
+ public function isHidden()
151
+ {
152
+ return false;
153
+ }
154
+ }
app/code/local/Scandi/MenuManager/Block/Adminhtml/Menu/Edit/Tab/Renderer/Parent.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Scandi_MenuManager
4
+ *
5
+ * @category Scandi
6
+ * @package Scandi_MenuManager
7
+ * @author Scandiweb <info@scandiweb.com>
8
+ * @copyright Copyright (c) 2013 Scandiweb, Ltd (http://scandiweb.com)
9
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
10
+ */
11
+
12
+ /**
13
+ * MenuManager menu item parent title renderer
14
+ *
15
+ * @category Scandi
16
+ * @package Scandi_MenuManager
17
+ */
18
+ class Scandi_MenuManager_Block_Adminhtml_Menu_Edit_Tab_Renderer_Parent
19
+ extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
20
+ {
21
+ /**
22
+ * Returns item title by id or 'Root' if no parent specified
23
+ *
24
+ * @param Varien_Object $row
25
+ * @return string
26
+ */
27
+ public function render(Varien_Object $row)
28
+ {
29
+ if ($value = $row->getData($this->getColumn()->getIndex())) {
30
+ return Mage::getModel('scandi_menumanager/item')->load($value)->getTitle();
31
+ }
32
+
33
+ return Mage::helper('scandi_menumanager')->__('Root');
34
+ }
35
+ }
app/code/local/Scandi/MenuManager/Block/Adminhtml/Menu/Edit/Tabs.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Scandi_MenuManager
4
+ *
5
+ * @category Scandi
6
+ * @package Scandi_MenuManager
7
+ * @author Scandiweb <info@scandiweb.com>
8
+ * @copyright Copyright (c) 2013 Scandiweb, Ltd (http://scandiweb.com)
9
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
10
+ */
11
+
12
+ /**
13
+ * MenuManager menu edit page left menu
14
+ *
15
+ * @category Scandi
16
+ * @package Scandi_MenuManager
17
+ */
18
+ class Scandi_MenuManager_Block_Adminhtml_Menu_Edit_Tabs
19
+ extends Mage_Adminhtml_Block_Widget_Tabs
20
+ {
21
+ public function __construct()
22
+ {
23
+ parent::__construct();
24
+
25
+ $this->setId('menu_page_tabs');
26
+ $this->setDestElementId('edit_form');
27
+ $this->setTitle(Mage::helper('scandi_menumanager')->__('Menu Information'));
28
+ }
29
+
30
+ /**
31
+ * Add "Menu Items" tab and its content
32
+ *
33
+ * @return Mage_Core_Block_Abstract
34
+ */
35
+ protected function _beforeToHtml()
36
+ {
37
+ if ($this->getRequest()->getParam('menu_id')) {
38
+ $itemsTabContent = $this->getLayout()
39
+ ->createBlock('scandi_menumanager/adminhtml_menu_edit_tab_items')
40
+ ->toHtml();
41
+ } else {
42
+ $itemsTabContent = Mage::helper('scandi_menumanager')->__(
43
+ '<ul class="messages"><li class="notice-msg"><ul><li><span>%s</span></li></ul></li></ul>',
44
+ Mage::helper('scandi_menumanager')->__('You will be able to manage items after saving this menu.')
45
+ );
46
+ }
47
+
48
+ $itemSectionStatus = $this->getRequest()
49
+ ->getParam('active_tab') == 'menu_page_tabs_items_section' ? true : false;
50
+
51
+ $this->addTab('items_section', array(
52
+ 'label' => $this->__('Menu Items'),
53
+ 'title' => $this->__('Menu Items'),
54
+ 'active' => $itemSectionStatus,
55
+ 'content' => $itemsTabContent,
56
+ ));
57
+
58
+ return parent::_beforeToHtml();
59
+ }
60
+ }
app/code/local/Scandi/MenuManager/Block/Adminhtml/Menu/Grid.php ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Scandi_MenuManager
4
+ *
5
+ * @category Scandi
6
+ * @package Scandi_MenuManager
7
+ * @author Scandiweb <info@scandiweb.com>
8
+ * @copyright Copyright (c) 2013 Scandiweb, Ltd (http://scandiweb.com)
9
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
10
+ */
11
+
12
+ /**
13
+ * MenuManager menu grid
14
+ *
15
+ * @category Scandi
16
+ * @package Scandi_MenuManager
17
+ */
18
+ class Scandi_MenuManager_Block_Adminhtml_Menu_Grid extends Mage_Adminhtml_Block_Widget_Grid
19
+ {
20
+ public function __construct()
21
+ {
22
+ parent::__construct();
23
+
24
+ $this->setId('cmsMenuGrid');
25
+ $this->setSaveParametersInSession(true);
26
+ }
27
+
28
+ /**
29
+ * Prepare collection for grid
30
+ *
31
+ * @return Scandi_MenuManager_Block_Adminhtml_Menu_Grid
32
+ */
33
+ protected function _prepareCollection()
34
+ {
35
+ /* @var $collection Scandi_MenuManager_Model_Resource_Menu_Collection */
36
+ $collection = Mage::getModel('scandi_menumanager/menu')
37
+ ->getResourceCollection();
38
+
39
+ $this->setCollection($collection);
40
+ return parent::_prepareCollection();
41
+ }
42
+
43
+ /**
44
+ * Prepare grid columns
45
+ *
46
+ * @return Scandi_MenuManager_Block_Adminhtml_Menu_Grid
47
+ */
48
+ protected function _prepareColumns()
49
+ {
50
+ $this->addColumn('title', array(
51
+ 'header' => Mage::helper('scandi_menumanager')->__('Title'),
52
+ 'index' => 'title',
53
+ ));
54
+
55
+ $this->addColumn('identifier', array(
56
+ 'header' => Mage::helper('scandi_menumanager')->__('Identifier'),
57
+ 'index' => 'identifier',
58
+ ));
59
+
60
+ $this->addColumn('type', array(
61
+ 'header' => Mage::helper('scandi_menumanager')->__('Type'),
62
+ 'index' => 'type',
63
+ 'type' => 'options',
64
+ 'options' => Mage::getSingleton('scandi_menumanager/menu')->getAvailableTypes(),
65
+ ));
66
+
67
+ $this->addColumn('css_class', array(
68
+ 'header' => Mage::helper('scandi_menumanager')->__('CSS Class'),
69
+ 'index' => 'css_class',
70
+ ));
71
+
72
+ if (!Mage::app()->isSingleStoreMode()) {
73
+ $this->addColumn('store_id', array(
74
+ 'header' => Mage::helper('scandi_menumanager')->__('Store View'),
75
+ 'index' => 'store_id',
76
+ 'type' => 'store',
77
+ 'store_all' => true,
78
+ 'store_view' => true,
79
+ 'sortable' => false,
80
+ 'filter_condition_callback' => array($this, '_filterStoreCondition'),
81
+ ));
82
+ }
83
+
84
+ $this->addColumn('is_active', array(
85
+ 'header' => Mage::helper('scandi_menumanager')->__('Status'),
86
+ 'index' => 'is_active',
87
+ 'type' => 'options',
88
+ 'options' => array(
89
+ 0 => Mage::helper('scandi_menumanager')->__('Disabled'),
90
+ 1 => Mage::helper('scandi_menumanager')->__('Enabled')
91
+ ),
92
+ ));
93
+
94
+ return parent::_prepareColumns();
95
+ }
96
+
97
+ /**
98
+ * After collection load operations - load to add store data
99
+ *
100
+ * @return Mage_Adminhtml_Block_Widget_Grid | void
101
+ */
102
+ protected function _afterLoadCollection()
103
+ {
104
+ $this->getCollection()->walk('afterLoad');
105
+ parent::_afterLoadCollection();
106
+ }
107
+
108
+ /**
109
+ * Store filter condition callback - add store filter when needed
110
+ *
111
+ * @param $collection Scandi_MenuManager_Model_Resource_Menu_Collection
112
+ * @param $column Mage_Adminhtml_Block_Widget_Grid_Column
113
+ */
114
+ protected function _filterStoreCondition($collection, $column)
115
+ {
116
+ if (!$value = $column->getFilter()->getValue()) {
117
+ return;
118
+ }
119
+
120
+ $this->getCollection()->addStoreFilter($value);
121
+ }
122
+
123
+ /**
124
+ * Return row url
125
+ *
126
+ * @return string
127
+ */
128
+ public function getRowUrl($row)
129
+ {
130
+ return $this->getUrl('*/*/edit', array('menu_id' => $row->getId()));
131
+ }
132
+ }
app/code/local/Scandi/MenuManager/Block/Adminhtml/Menu/Item/Edit.php ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Scandi_MenuManager
4
+ *
5
+ * @category Scandi
6
+ * @package Scandi_MenuManager
7
+ * @author Scandiweb <info@scandiweb.com>
8
+ * @copyright Copyright (c) 2013 Scandiweb, Ltd (http://scandiweb.com)
9
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
10
+ */
11
+
12
+ /**
13
+ * MenuManager menu item edit form container
14
+ *
15
+ * @category Scandi
16
+ * @package Scandi_MenuManager
17
+ */
18
+ class Scandi_MenuManager_Block_Adminhtml_Menu_Item_Edit
19
+ extends Mage_Adminhtml_Block_Widget_Form_Container
20
+ {
21
+ public function __construct()
22
+ {
23
+ $this->_objectId = 'item_id';
24
+ $this->_blockGroup = 'scandi_menumanager';
25
+ $this->_controller = 'adminhtml_menu_item';
26
+
27
+ parent::__construct();
28
+
29
+ $this->_updateButton('back', 'onclick', 'setLocation(\'' . $this->_getBackUrl() . '\')');
30
+ $this->_updateButton('delete', 'onclick', 'setLocation(\'' . $this->_getDeleteUrl() . '\')');
31
+ }
32
+
33
+ /**
34
+ * Retrieve text for header element depending on loaded page
35
+ *
36
+ * @return string
37
+ */
38
+ public function getHeaderText()
39
+ {
40
+ if (Mage::registry('menumanager_menu_item')->getId()) {
41
+ return Mage::helper('scandi_menumanager')->__("Edit Menu Item '%s'",
42
+ $this->escapeHtml(Mage::registry('menumanager_menu_item')->getTitle()));
43
+ } else {
44
+ return Mage::helper('scandi_menumanager')->__('New Menu Item');
45
+ }
46
+ }
47
+
48
+ /**
49
+ * get header css class
50
+ *
51
+ * @return string
52
+ */
53
+ public function getHeaderCssClass()
54
+ {
55
+ return 'icon-head head-cms-block ' . strtr($this->_controller, '_', '-');
56
+ }
57
+
58
+ /**
59
+ * Getter of url for "Back" button
60
+ *
61
+ * @return string
62
+ */
63
+ protected function _getBackUrl()
64
+ {
65
+ return $this->getUrl('*/*/edit', array(
66
+ 'menu_id' => $this->getRequest()->getParam('menu_id'),
67
+ '_current' => true
68
+ ));
69
+ }
70
+
71
+ /**
72
+ * Getter of url for "Delete" button
73
+ *
74
+ * @return string
75
+ */
76
+ protected function _getDeleteUrl()
77
+ {
78
+ return $this->getUrl('*/*/delete_item', array(
79
+ 'menu_id' => $this->getRequest()->getParam('menu_id'),
80
+ 'item_id' => $this->getRequest()->getParam('item_id')
81
+ ));
82
+ }
83
+ }
app/code/local/Scandi/MenuManager/Block/Adminhtml/Menu/Item/Edit/Form.php ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Scandi_MenuManager
4
+ *
5
+ * @category Scandi
6
+ * @package Scandi_MenuManager
7
+ * @author Scandiweb <info@scandiweb.com>
8
+ * @copyright Copyright (c) 2013 Scandiweb, Ltd (http://scandiweb.com)
9
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
10
+ */
11
+
12
+ /**
13
+ * MenuManager menu item edit form
14
+ *
15
+ * @category Scandi
16
+ * @package Scandi_MenuManager
17
+ */
18
+ class Scandi_MenuManager_Block_Adminhtml_Menu_Item_Edit_Form
19
+ extends Mage_Adminhtml_Block_Widget_Form
20
+ {
21
+ protected function _prepareForm()
22
+ {
23
+ /* @var $model Scandi_MenuManager_Model_Item*/
24
+ $model = Mage::registry('menumanager_menu_item');
25
+ $menuId = $this->getRequest()->getParam('menu_id');
26
+
27
+ $form = new Varien_Data_Form(array(
28
+ 'method' => 'post',
29
+ 'id' => 'edit_form',
30
+ 'action' => $this->getUrl('*/*/save_item', array('menu_id' => $menuId)),
31
+ ));
32
+
33
+ $fieldset = $form->addFieldset('base_fieldset', array(
34
+ 'legend' => Mage::helper('scandi_menumanager')->__('General Information'))
35
+ );
36
+
37
+ if ($model->getItemId()) {
38
+ $fieldset->addField('item_id', 'hidden', array(
39
+ 'name' => 'item_id',
40
+ ));
41
+ }
42
+
43
+ if ($model->getMenuId()) {
44
+ $fieldset->addField('menu_id', 'hidden', array(
45
+ 'name' => 'menu_id',
46
+ ));
47
+ }
48
+
49
+ if ($model->getIdentifier()) {
50
+ $fieldset->addField('identifier', 'hidden', array(
51
+ 'name' => 'identifier',
52
+ ));
53
+ }
54
+
55
+ $fieldset->addField('title', 'text', array(
56
+ 'name' => 'title',
57
+ 'label' => Mage::helper('scandi_menumanager')->__('Title'),
58
+ 'title' => Mage::helper('scandi_menumanager')->__('Title'),
59
+ 'required' => true,
60
+ ));
61
+
62
+ $fieldset->addField('parent_id', 'select', array(
63
+ 'name' => 'parent_id',
64
+ 'label' => Mage::helper('scandi_menumanager')->__('Parent'),
65
+ 'title' => Mage::helper('scandi_menumanager')->__('Parent'),
66
+ 'options' => $model->getCollection()
67
+ ->addMenuFilter($menuId)
68
+ ->toItemOptionArray(),
69
+ 'required' => true,
70
+ ));
71
+
72
+ $fieldset->addField('url', 'text', array(
73
+ 'name' => 'url',
74
+ 'label' => Mage::helper('scandi_menumanager')->__('Url'),
75
+ 'title' => Mage::helper('scandi_menumanager')->__('Url'),
76
+ 'note' => Mage::helper('cms')->__('Use " / " For Item With Base Url.')
77
+ ));
78
+
79
+ $fieldset->addField('type', 'select', array(
80
+ 'name' => 'type',
81
+ 'label' => Mage::helper('scandi_menumanager')->__('Url Window Type'),
82
+ 'title' => Mage::helper('scandi_menumanager')->__('Url Window Type'),
83
+ 'options' => $model->getAvailableTypes(),
84
+ 'required' => true
85
+ ));
86
+
87
+ $fieldset->addField('css_class', 'text', array(
88
+ 'name' => 'css_class',
89
+ 'label' => Mage::helper('scandi_menumanager')->__('CSS Class'),
90
+ 'title' => Mage::helper('scandi_menumanager')->__('CSS Class'),
91
+ 'note' => Mage::helper('cms')->__('Space Separated Class Names')
92
+ ));
93
+
94
+ $fieldset->addField('position', 'text', array(
95
+ 'name' => 'position',
96
+ 'label' => Mage::helper('scandi_menumanager')->__('Position'),
97
+ 'title' => Mage::helper('scandi_menumanager')->__('Position'),
98
+ 'class' => 'validate-number',
99
+ 'required' => true
100
+ ));
101
+
102
+ $fieldset->addField('is_active', 'select', array(
103
+ 'label' => Mage::helper('scandi_menumanager')->__('Status'),
104
+ 'title' => Mage::helper('scandi_menumanager')->__('Menu Item Status'),
105
+ 'name' => 'is_active',
106
+ 'required' => true,
107
+ 'options' => array(
108
+ '1' => Mage::helper('scandi_menumanager')->__('Enabled'),
109
+ '0' => Mage::helper('scandi_menumanager')->__('Disabled'),
110
+ ),
111
+ ));
112
+
113
+ if (!$model->getId()) {
114
+ $model->setData('is_active', '1');
115
+ }
116
+
117
+ Mage::dispatchEvent(
118
+ 'adminhtml_cms_menu_item_edit_prepare_form',
119
+ array('form' => $form)
120
+ );
121
+
122
+ $form->setValues($model->getData());
123
+ $form->setUseContainer(true);
124
+ $this->setForm($form);
125
+
126
+ return parent::_prepareForm();
127
+ }
128
+ }
app/code/local/Scandi/MenuManager/Block/Menu.php ADDED
@@ -0,0 +1,358 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Scandi_MenuManager
4
+ *
5
+ * @category Scandi
6
+ * @package Scandi_MenuManager
7
+ * @author Scandiweb <info@scandiweb.com>
8
+ * @copyright Copyright (c) 2013 Scandiweb, Ltd (http://scandiweb.com)
9
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
10
+ */
11
+
12
+ /**
13
+ * MenuManager menu block
14
+ *
15
+ * @category Scandi
16
+ * @package Scandi_MenuManager
17
+ */
18
+ class Scandi_MenuManager_Block_Menu extends Mage_Core_Block_Template
19
+ {
20
+ /**
21
+ * Menu data tree
22
+ *
23
+ * @var Varien_Data_Tree_Node
24
+ */
25
+ protected $_menu;
26
+
27
+ /**
28
+ * Menu model
29
+ *
30
+ * @var Scandi_MenuManager_Model_Menu
31
+ */
32
+ protected $_menuModel;
33
+
34
+ /**
35
+ * Current url path
36
+ *
37
+ * @var string
38
+ */
39
+ protected $_currentUrlPath;
40
+
41
+ /**
42
+ * Current category url path
43
+ *
44
+ * @var string
45
+ */
46
+ protected $_currentCategoryUrlPath;
47
+
48
+ /**
49
+ * Base url path
50
+ *
51
+ * @var string
52
+ */
53
+ protected $_baseUrlPath;
54
+
55
+ /**
56
+ * Init menu tree structure and retrieve url paths
57
+ */
58
+ public function _construct()
59
+ {
60
+ $this->_currentUrlPath = $this->_getTrimmedPath(Mage::helper('core/url')->getCurrentUrl());
61
+ $this->_menu = new Varien_Data_Tree_Node(array(), 'root', new Varien_Data_Tree());
62
+ $this->_baseUrlPath = $this->_getTrimmedPath(Mage::getBaseUrl());
63
+
64
+ if ($currentCategory = Mage::registry('current_category')) {
65
+ $this->_currentCategoryUrlPath = $this->_getTrimmedPath($currentCategory->getUrl());
66
+ }
67
+ }
68
+
69
+ /**
70
+ * Prepare default template for menu
71
+ *
72
+ * @return Scandi_MenuManager_Block_Menu
73
+ */
74
+ protected function _prepareLayout()
75
+ {
76
+ $this->setTemplate('scandi/menumanager/menu.phtml');
77
+ }
78
+
79
+ /**
80
+ * Return loaded menu
81
+ *
82
+ * @return bool | Scandi_MenuManager_Model_Menu
83
+ */
84
+ public function getMenu()
85
+ {
86
+ if ($this->_menuModel) {
87
+ return $this->_menuModel;
88
+ }
89
+
90
+ if ($menuId = $this->getData('menu_id')) {
91
+ $menu = Mage::getModel('scandi_menumanager/menu')
92
+ ->setStoreId(Mage::app()->getStore()->getId())
93
+ ->load($menuId);
94
+
95
+ if ($menu->getIsActive()) {
96
+ if ($this->getData('custom_type')) {
97
+ $menu->setData('type', $this->getData('custom_type'));
98
+ }
99
+
100
+ $this->_menuModel = $menu;
101
+
102
+ return $menu;
103
+ }
104
+ }
105
+
106
+ return false;
107
+ }
108
+
109
+ /**
110
+ * Return menu html
111
+ *
112
+ * @return string | bool
113
+ */
114
+ public function getMenuHtml()
115
+ {
116
+ if ($this->getMenu() && $this->_fillMenuTree()) {
117
+ return '<ul class="menu-manager-menu menu-type-' . $this->_menuModel->getType() . ' '
118
+ . $this->_menuModel->getCssClass() . '">' . $this->_getMenuHtml($this->_menu) . '</ul>';
119
+ }
120
+
121
+ return false;
122
+ }
123
+
124
+ /**
125
+ * Return recursively generated menu html
126
+ *
127
+ * @param Varien_Data_Tree_Node $menuTree
128
+ * @return string
129
+ */
130
+ protected function _getMenuHtml(Varien_Data_Tree_Node $menuTree)
131
+ {
132
+ $html = '';
133
+ $counter = 1;
134
+ $children = $menuTree->getChildren();
135
+ $childrenCount = $children->count();
136
+ $parentLevel = $menuTree->getLevel();
137
+ $childLevel = is_null($parentLevel) ? 0 : $parentLevel + 1;
138
+
139
+ foreach ($children as $child) {
140
+ $this->_formatItemUrl($child);
141
+ $child->setLevel($childLevel);
142
+ $child->setIsFirst($counter == 1);
143
+ $child->setIsLast($counter == $childrenCount);
144
+ $child->setIsActive($this->_hasCurrentUrl($child));
145
+ $child->setType($child->getType() == 'new_window' ? 'target="_blank"' : '');
146
+
147
+ $html .= '<li class="' . $this->_getMenuItemClasses($child) . '">';
148
+
149
+ if ($child->getFullUrl()) {
150
+ $html .= '<a href="' . $child->getFullUrl() . '" ' . $child->getType() . '>';
151
+ } else {
152
+ $html .= '<span>';
153
+ }
154
+
155
+ $html .= '<span>' . $this->escapeHtml($child->getTitle()) . '</span>';
156
+
157
+ if ($child->getFullUrl()) {
158
+ $html .= '</a>';
159
+ } else {
160
+ $html .= '</span>';
161
+ }
162
+
163
+ if ($child->hasChildren()) {
164
+ $html .= '<ul class="level' . $childLevel . '">';
165
+ $html .= $this->_getMenuHtml($child);
166
+ $html .= '</ul>';
167
+ }
168
+
169
+ $html .= '</li>';
170
+ $counter++;
171
+ }
172
+
173
+ return $html;
174
+ }
175
+
176
+ /**
177
+ * Returns string of menu item's classes
178
+ *
179
+ * @param Varien_Data_Tree_Node $item
180
+ * @return string
181
+ */
182
+ protected function _getMenuItemClasses(Varien_Data_Tree_Node $item)
183
+ {
184
+ $classes = 'level' . $item->getLevel() . ' ';
185
+
186
+ if ($item->getIsFirst()) {
187
+ $classes .= 'first ';
188
+ }
189
+
190
+ if ($item->getIsActive()) {
191
+ $classes .= 'active ';
192
+ }
193
+
194
+ if ($item->getIsLast()) {
195
+ $classes .= 'last ';
196
+ }
197
+
198
+ if (!$item->getFullUrl()) {
199
+ $classes .= 'title ';
200
+ }
201
+
202
+ if ($item->getCssClass()) {
203
+ $classes .= $item->getCssClass();
204
+ }
205
+
206
+ if ($item->hasChildren()) {
207
+ $classes .= ' parent';
208
+ }
209
+
210
+ return $classes;
211
+ }
212
+
213
+ /**
214
+ * Checks if menu item's or child's url is same as current url
215
+ *
216
+ * @param Varien_Data_Tree_Node $item
217
+ * @return bool
218
+ */
219
+ protected function _hasCurrentUrl(Varien_Data_Tree_Node $item)
220
+ {
221
+ $this->_formatItemUrl($item);
222
+ $homeFlag = $item->getUrl() == '/' ? true : false;
223
+ $itemUrl = $this->_getTrimmedPath($item->getFullUrl());
224
+
225
+ if ($this->_baseUrlPath == $this->_currentUrlPath && $homeFlag) {
226
+ return true;
227
+ }
228
+
229
+ if ($itemUrl) {
230
+ if ($this->_currentUrlPath == $itemUrl && !$homeFlag) {
231
+ return true;
232
+ }
233
+
234
+ if ($this->_currentCategoryUrlPath == $itemUrl) {
235
+ return true;
236
+ }
237
+ }
238
+
239
+ if ($item->hasChildren()) {
240
+ foreach ($item->getChildren() as $child) {
241
+ if ($this->_hasCurrentUrl($child)) {
242
+ return true;
243
+ }
244
+ }
245
+ }
246
+
247
+ return false;
248
+ }
249
+
250
+ /**
251
+ * Format item url
252
+ *
253
+ * @param Varien_Data_Tree_Node $item
254
+ */
255
+ protected function _formatItemUrl(Varien_Data_Tree_Node $item)
256
+ {
257
+ if (!($itemFullUrl = $item->getFullUrl()) && ($itemUrl = $item->getUrl())) {
258
+ if (strpos($itemUrl, '://') === false) {
259
+ $itemUrl = $this->_getUrlModel()->getDirectUrl($itemUrl != '/' ? $itemUrl : '');
260
+ }
261
+
262
+ $item->setFullUrl($itemUrl);
263
+ };
264
+ }
265
+
266
+ /**
267
+ * Retrieve parsed and trimmed url path
268
+ *
269
+ * @param $url
270
+ * @return string
271
+ */
272
+ protected function _getTrimmedPath($url)
273
+ {
274
+ $url = parse_url($url);
275
+ return rtrim($url['path'], '/');
276
+ }
277
+
278
+ /**
279
+ * Fill menu data tree
280
+ *
281
+ * @return bool
282
+ */
283
+ protected function _fillMenuTree()
284
+ {
285
+ $collection = $this->_getMenuItemCollection();
286
+
287
+ if (!$collection->count()) {
288
+ return false;
289
+ }
290
+
291
+ $nodes = array();
292
+ $nodes['0'] = $this->_menu;
293
+
294
+ foreach ($collection as $item) {
295
+ if (!isset($nodes[$item->getParentId()])) {
296
+ continue;
297
+ }
298
+
299
+ $parentItemNode = $nodes[$item->getParentId()];
300
+
301
+ $itemNode = new Varien_Data_Tree_Node(
302
+ $item->getData(), 'item_id', $parentItemNode->getTree(), $parentItemNode
303
+ );
304
+
305
+ $nodes[$item->getId()] = $itemNode;
306
+ $parentItemNode->addChild($itemNode);
307
+ }
308
+
309
+ return true;
310
+ }
311
+
312
+ /**
313
+ * Return filtered menu item collection
314
+ *
315
+ * @return Scandi_MenuManager_Model_Resource_Item_Collection
316
+ */
317
+ protected function _getMenuItemCollection()
318
+ {
319
+ return Mage::getModel('scandi_menumanager/item')->getCollection()
320
+ ->addMenuFilter($this->_menuModel)
321
+ ->setPositionOrder()
322
+ ->addStatusFilter();
323
+ }
324
+
325
+ /**
326
+ * Get tags array for saving cache
327
+ *
328
+ * @return array
329
+ */
330
+ public function getCacheTags()
331
+ {
332
+ return array(Scandi_MenuManager_Model_Menu::CACHE_TAG);
333
+ }
334
+
335
+ /**
336
+ * Get block cache life time
337
+ *
338
+ * @return int
339
+ */
340
+ public function getCacheLifetime()
341
+ {
342
+ return null;
343
+ }
344
+
345
+ /**
346
+ * Get cache key informative items
347
+ *
348
+ * @return array
349
+ */
350
+ public function getCacheKeyInfo()
351
+ {
352
+ return array(
353
+ 'tag' => Scandi_MenuManager_Model_Menu::CACHE_TAG,
354
+ 'url' => base64_encode($this->_currentUrlPath),
355
+ 'mid' => $this->getMenu()->getId(),
356
+ );
357
+ }
358
+ }
app/code/local/Scandi/MenuManager/Helper/Data.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Scandi_MenuManager
4
+ *
5
+ * @category Scandi
6
+ * @package Scandi_MenuManager
7
+ * @author Scandiweb <info@scandiweb.com>
8
+ * @copyright Copyright (c) 2013 Scandiweb, Ltd (http://scandiweb.com)
9
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
10
+ */
11
+
12
+ /**
13
+ * MenuManager data helper
14
+ *
15
+ * @category Scandi
16
+ * @package Scandi_MenuManager
17
+ */
18
+ class Scandi_MenuManager_Helper_Data extends Mage_Core_Helper_Abstract
19
+ {
20
+ }
app/code/local/Scandi/MenuManager/Model/Item.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Scandi_MenuManager
4
+ *
5
+ * @category Scandi
6
+ * @package Scandi_MenuManager
7
+ * @author Scandiweb <info@scandiweb.com>
8
+ * @copyright Copyright (c) 2013 Scandiweb, Ltd (http://scandiweb.com)
9
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
10
+ */
11
+
12
+ /**
13
+ * MenuManager menu item model
14
+ *
15
+ * @category Scandi
16
+ * @package Scandi_MenuManager
17
+ */
18
+ class Scandi_MenuManager_Model_Item extends Mage_Core_Model_Abstract
19
+ {
20
+ /**
21
+ * Menu item url open window types
22
+ */
23
+ const TYPE_NEW_WINDOW = 'new_window';
24
+ const TYPE_SAME_WINDOW = 'same_window';
25
+
26
+ protected function _construct()
27
+ {
28
+ $this->_init('scandi_menumanager/item');
29
+ }
30
+
31
+ /**
32
+ * Prepare menu item url open window types
33
+ *
34
+ * @return array
35
+ */
36
+ public function getAvailableTypes()
37
+ {
38
+ $types = array(
39
+ self::TYPE_SAME_WINDOW => Mage::helper('scandi_menumanager')->__('Same Window'),
40
+ self::TYPE_NEW_WINDOW => Mage::helper('scandi_menumanager')->__('New Window'),
41
+ );
42
+
43
+ return $types;
44
+ }
45
+ }
app/code/local/Scandi/MenuManager/Model/Menu.php ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Scandi_MenuManager
4
+ *
5
+ * @category Scandi
6
+ * @package Scandi_MenuManager
7
+ * @author Scandiweb <info@scandiweb.com>
8
+ * @copyright Copyright (c) 2013 Scandiweb, Ltd (http://scandiweb.com)
9
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
10
+ */
11
+
12
+ /**
13
+ * MenuManager menu model
14
+ *
15
+ * @category Scandi
16
+ * @package Scandi_MenuManager
17
+ */
18
+ class Scandi_MenuManager_Model_Menu extends Mage_Core_Model_Abstract
19
+ {
20
+ /**
21
+ * Menu types
22
+ */
23
+ const TYPE_HORIZONTAL = 'horizontal';
24
+ const TYPE_VERTICAL = 'vertical';
25
+ const TYPE_NONE = 'none';
26
+
27
+ /**
28
+ * Cache tag
29
+ */
30
+ const CACHE_TAG = 'menumanager_menu';
31
+
32
+ protected function _construct()
33
+ {
34
+ $this->_init('scandi_menumanager/menu');
35
+ }
36
+
37
+ /**
38
+ * Prepare menu types
39
+ *
40
+ * @return array
41
+ */
42
+ public function getAvailableTypes()
43
+ {
44
+ $types = array(
45
+ self::TYPE_NONE => Mage::helper('scandi_menumanager')->__('None'),
46
+ self::TYPE_VERTICAL => Mage::helper('scandi_menumanager')->__('Vertical'),
47
+ self::TYPE_HORIZONTAL => Mage::helper('scandi_menumanager')->__('Horizontal'),
48
+ );
49
+
50
+ return $types;
51
+ }
52
+ }
app/code/local/Scandi/MenuManager/Model/Resource/Item.php ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Scandiweb - creating a better future
4
+ *
5
+ * Scandi_MenuManager
6
+ *
7
+ * @category Scandi
8
+ * @package Scandi_MenuManager
9
+ * @author Scandiweb.com <info@scandiweb.com>
10
+ * @copyright Copyright (c) 2013 Scandiweb.com (http://www.scandiweb.com)
11
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
12
+ */
13
+
14
+ /**
15
+ * MenuManager menu item model
16
+ *
17
+ * @category Scandi
18
+ * @package Scandi_MenuManager
19
+ */
20
+ class Scandi_MenuManager_Model_Resource_Item extends Mage_Core_Model_Resource_Db_Abstract
21
+ {
22
+ protected function _construct()
23
+ {
24
+ $this->_init('scandi_menumanager/menu_item', 'item_id');
25
+ }
26
+
27
+ /**
28
+ * Load an object using 'identifier' field
29
+ *
30
+ * @param Mage_Core_Model_Abstract $object
31
+ * @param mixed $value
32
+ * @param string $field
33
+ * @return Scandi_MenuManager_Model_Resource_Item
34
+ */
35
+ public function load(Mage_Core_Model_Abstract $object, $value, $field = null)
36
+ {
37
+ if (!is_numeric($value) && is_null($field)) {
38
+ $field = 'identifier';
39
+ }
40
+
41
+ return parent::load($object, $value, $field);
42
+ }
43
+
44
+ /**
45
+ * Perform operations before object save - add unique 'identifier' and check item parent
46
+ *
47
+ * @param Scandi_MenuManager_Model_Item $object
48
+ * @return Scandi_MenuManager_Model_Resource_Item
49
+ */
50
+ protected function _beforeSave(Mage_Core_Model_Abstract $object)
51
+ {
52
+ if ($object->getId() && $object->getId() == $object->getParentId()) {
53
+ Mage::throwException(Mage::helper('scandi_menumanager')
54
+ ->__('Menu item can not be parent to itself.'));
55
+
56
+ return $this;
57
+ }
58
+
59
+ if (!$object->getMenuId()) {
60
+ Mage::throwException(Mage::helper('scandi_menumanager')
61
+ ->__('Menu item parent menu must be specified.'));
62
+
63
+ return $this;
64
+ }
65
+
66
+ if (!$object->getIdentifier()) {
67
+ $object->setIdentifier('menu_' . $object->getMenuId() . '_item_' . date('Y_m_d_H_i_s'));
68
+ }
69
+
70
+ Mage::app()->cleanCache(Scandi_MenuManager_Model_Menu::CACHE_TAG);
71
+
72
+ return $this;
73
+ }
74
+ }
app/code/local/Scandi/MenuManager/Model/Resource/Item/Collection.php ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Scandiweb - creating a better future
4
+ *
5
+ * Scandi_MenuManager
6
+ *
7
+ * @category Scandi
8
+ * @package Scandi_MenuManager
9
+ * @author Scandiweb.com <info@scandiweb.com>
10
+ * @copyright Copyright (c) 2013 Scandiweb.com (http://www.scandiweb.com)
11
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
12
+ */
13
+
14
+ /**
15
+ * MenuManager menu item collection
16
+ *
17
+ * @category Scandi
18
+ * @package Scandi_MenuManager
19
+ */
20
+ class Scandi_MenuManager_Model_Resource_Item_Collection
21
+ extends Mage_Core_Model_Resource_Db_Collection_Abstract
22
+ {
23
+ protected function _construct()
24
+ {
25
+ $this->_init('scandi_menumanager/item');
26
+ }
27
+
28
+ /**
29
+ * Add menu filter to item collection
30
+ *
31
+ * @param int | Scandi_MenuManager_Model_Menu $menu
32
+ * @return Scandi_MenuManager_Model_Resource_Item_Collection
33
+ */
34
+ public function addMenuFilter($menu)
35
+ {
36
+ if ($menu instanceof Scandi_MenuManager_Model_Menu) {
37
+ $menu = $menu->getId();
38
+ }
39
+
40
+ $this->addFilter('menu_id', $menu);
41
+
42
+ return $this;
43
+ }
44
+
45
+ /**
46
+ * Add status filter to item collection
47
+ *
48
+ * @return Scandi_MenuManager_Model_Resource_Item_Collection
49
+ */
50
+ public function addStatusFilter()
51
+ {
52
+ $this->addFilter('is_active', 1);
53
+
54
+ return $this;
55
+ }
56
+
57
+ /**
58
+ * Set order to item collection
59
+ *
60
+ * @return Scandi_MenuManager_Model_Resource_Item_Collection
61
+ */
62
+ public function setPositionOrder()
63
+ {
64
+ $this->setOrder('parent_id', 'asc');
65
+ $this->setOrder('position', 'asc');
66
+
67
+ return $this;
68
+ }
69
+
70
+ /**
71
+ * Collection to option array method
72
+ *
73
+ * @return array
74
+ */
75
+ public function toItemOptionArray()
76
+ {
77
+ $result = array();
78
+ $result['0'] = Mage::helper('scandi_menumanager')->__('Root');
79
+
80
+ foreach ($this as $item) {
81
+ $result[$item->getData('item_id')] = $item->getData('title');
82
+ }
83
+
84
+ return $result;
85
+ }
86
+ }
app/code/local/Scandi/MenuManager/Model/Resource/Menu.php ADDED
@@ -0,0 +1,209 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Scandiweb - creating a better future
4
+ *
5
+ * Scandi_MenuManager
6
+ *
7
+ * @category Scandi
8
+ * @package Scandi_MenuManager
9
+ * @author Scandiweb.com <info@scandiweb.com>
10
+ * @copyright Copyright (c) 2013 Scandiweb.com (http://www.scandiweb.com)
11
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
12
+ */
13
+
14
+ /**
15
+ * MenuManager menu model
16
+ *
17
+ * @category Scandi
18
+ * @package Scandi_MenuManager
19
+ */
20
+ class Scandi_MenuManager_Model_Resource_Menu extends Mage_Core_Model_Resource_Db_Abstract
21
+ {
22
+ protected function _construct()
23
+ {
24
+ $this->_init('scandi_menumanager/menu', 'menu_id');
25
+ }
26
+
27
+ /**
28
+ * Load an object using 'identifier' field
29
+ *
30
+ * @param Mage_Core_Model_Abstract $object
31
+ * @param mixed $value
32
+ * @param string $field
33
+ * @return Scandi_MenuManager_Model_Resource_Menu
34
+ */
35
+ public function load(Mage_Core_Model_Abstract $object, $value, $field = null)
36
+ {
37
+ if (!is_numeric($value) && is_null($field)) {
38
+ $field = 'identifier';
39
+ }
40
+
41
+ return parent::load($object, $value, $field);
42
+ }
43
+
44
+ /**
45
+ * Perform operations before object save - check for unique 'identifier'
46
+ *
47
+ * @param Scandi_MenuManager_Model_Menu $object
48
+ * @return Scandi_MenuManager_Model_Resource_Menu
49
+ */
50
+ protected function _beforeSave(Mage_Core_Model_Abstract $object)
51
+ {
52
+ if (!$this->getIsUniqueMenuToStores($object)) {
53
+ Mage::throwException(Mage::helper('scandi_menumanager')
54
+ ->__('A menu identifier with the same properties already exists in the selected store.'));
55
+ }
56
+
57
+ Mage::app()->cleanCache(Scandi_MenuManager_Model_Menu::CACHE_TAG);
58
+
59
+ return $this;
60
+ }
61
+
62
+ /**
63
+ * Perform operations after object load - add stores data
64
+ *
65
+ * @param Mage_Core_Model_Abstract $object
66
+ * @return Scandi_MenuManager_Model_Resource_Menu
67
+ */
68
+ protected function _afterLoad(Mage_Core_Model_Abstract $object)
69
+ {
70
+ if ($object->getId()) {
71
+ $stores = $this->lookupStoreIds($object->getId());
72
+
73
+ $object->setData('store_id', $stores);
74
+ $object->setData('stores', $stores);
75
+ }
76
+
77
+ return parent::_afterLoad($object);
78
+ }
79
+
80
+ /**
81
+ * Perform operations after object save - update menu stores data
82
+ *
83
+ * @param Mage_Core_Model_Abstract $object
84
+ * @return Scandi_MenuManager_Model_Resource_Menu
85
+ */
86
+ protected function _afterSave(Mage_Core_Model_Abstract $object)
87
+ {
88
+ $oldStores = $this->lookupStoreIds($object->getId());
89
+ $newStores = (array)$object->getStores();
90
+
91
+ $table = $this->getTable('scandi_menumanager/menu_store');
92
+
93
+ $insert = array_diff($newStores, $oldStores);
94
+ $delete = array_diff($oldStores, $newStores);
95
+
96
+ if ($delete) {
97
+ $where = array(
98
+ 'menu_id = ?' => (int) $object->getId(),
99
+ 'store_id IN (?)' => $delete
100
+ );
101
+
102
+ $this->_getWriteAdapter()->delete($table, $where);
103
+ }
104
+
105
+ if ($insert) {
106
+ $data = array();
107
+
108
+ foreach ($insert as $storeId) {
109
+ $data[] = array(
110
+ 'menu_id' => (int) $object->getId(),
111
+ 'store_id' => (int) $storeId
112
+ );
113
+ }
114
+
115
+ $this->_getWriteAdapter()->insertMultiple($table, $data);
116
+ }
117
+
118
+ return parent::_afterSave($object);
119
+ }
120
+
121
+ /**
122
+ * Check if menu identifier is unique in store(s).
123
+ *
124
+ * @param Mage_Core_Model_Abstract $object
125
+ * @return bool
126
+ */
127
+ public function getIsUniqueMenuToStores(Mage_Core_Model_Abstract $object)
128
+ {
129
+ if (Mage::app()->isSingleStoreMode()) {
130
+ $stores = array(Mage_Core_Model_App::ADMIN_STORE_ID);
131
+ } else {
132
+ $stores = (array)$object->getData('stores');
133
+ }
134
+
135
+ $select = $this->_getReadAdapter()->select()
136
+ ->from(
137
+ array('menu' => $this->getMainTable())
138
+ )
139
+ ->join(
140
+ array('menu_stores' => $this->getTable('scandi_menumanager/menu_store')),
141
+ 'menu.menu_id = menu_stores.menu_id', array()
142
+ )
143
+ ->where('menu.identifier = ?', $object->getData('identifier'))
144
+ ->where('menu_stores.store_id IN (?)', $stores);
145
+
146
+ if ($object->getId()) {
147
+ $select->where('menu.menu_id <> ?', $object->getId());
148
+ }
149
+
150
+ if ($this->_getReadAdapter()->fetchRow($select)) {
151
+ return false;
152
+ }
153
+
154
+ return true;
155
+ }
156
+
157
+ /**
158
+ * Get store IDs to which menu is assigned
159
+ *
160
+ * @param int $id
161
+ * @return array
162
+ */
163
+ public function lookupStoreIds($id)
164
+ {
165
+ $adapter = $this->_getReadAdapter();
166
+
167
+ $select = $adapter->select()
168
+ ->from($this->getTable('scandi_menumanager/menu_store'), 'store_id')
169
+ ->where('menu_id = :menu_id');
170
+
171
+ $binds = array(
172
+ ':menu_id' => (int) $id
173
+ );
174
+
175
+ return $adapter->fetchCol($select, $binds);
176
+ }
177
+
178
+ /**
179
+ * Load only appropriate menu to specified store
180
+ *
181
+ * @param string $field
182
+ * @param mixed $value
183
+ * @param Scandi_MenuManager_Model_Menu $object
184
+ * @return Zend_Db_Select
185
+ */
186
+ protected function _getLoadSelect($field, $value, $object)
187
+ {
188
+ $select = parent::_getLoadSelect($field, $value, $object);
189
+
190
+ if ($object->getStoreId()) {
191
+ $stores = array(
192
+ (int) $object->getStoreId(),
193
+ Mage_Core_Model_App::ADMIN_STORE_ID
194
+ );
195
+
196
+ $select->join(
197
+ array('menu_store' => $this->getTable('scandi_menumanager/menu_store')),
198
+ $this->getMainTable() . '.menu_id = menu_store.menu_id',
199
+ array('store_id')
200
+ )
201
+ ->where('menu_store.store_id in (?) ', $stores)
202
+ ->where('is_active = ?', 1)
203
+ ->order('store_id DESC')
204
+ ->limit(1);
205
+ }
206
+
207
+ return $select;
208
+ }
209
+ }
app/code/local/Scandi/MenuManager/Model/Resource/Menu/Collection.php ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Scandiweb - creating a better future
4
+ *
5
+ * Scandi_MenuManager
6
+ *
7
+ * @category Scandi
8
+ * @package Scandi_MenuManager
9
+ * @author Scandiweb.com <info@scandiweb.com>
10
+ * @copyright Copyright (c) 2013 Scandiweb.com (http://www.scandiweb.com)
11
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
12
+ */
13
+
14
+ /**
15
+ * MenuManager menu collection
16
+ *
17
+ * @category Scandi
18
+ * @package Scandi_MenuManager
19
+ */
20
+ class Scandi_MenuManager_Model_Resource_Menu_Collection
21
+ extends Mage_Core_Model_Resource_Db_Collection_Abstract
22
+ {
23
+ protected function _construct()
24
+ {
25
+ $this->_init('scandi_menumanager/menu');
26
+ }
27
+
28
+ /**
29
+ * Add store filter to menu collection
30
+ *
31
+ * @param int | Mage_Core_Model_Store $store
32
+ * @param bool $withAdmin
33
+ * @return Scandi_MenuManager_Model_Resource_Menu_Collection
34
+ */
35
+ public function addStoreFilter($store, $withAdmin = true)
36
+ {
37
+ if ($store instanceof Mage_Core_Model_Store) {
38
+ $store = array($store->getId());
39
+ }
40
+
41
+ if (!is_array($store)) {
42
+ $store = array($store);
43
+ }
44
+
45
+ if ($withAdmin) {
46
+ $store[] = Mage_Core_Model_App::ADMIN_STORE_ID;
47
+ }
48
+
49
+ $this->addFilter('store_id', array('in' => $store), 'public');
50
+
51
+ return $this;
52
+ }
53
+
54
+ /**
55
+ * Join store relation table data if store filter is used
56
+ *
57
+ * @return Scandi_MenuManager_Model_Resource_Menu_Collection
58
+ */
59
+ protected function _renderFiltersBefore()
60
+ {
61
+ if ($this->getFilter('store_id')) {
62
+ $this->getSelect()->join(
63
+ array('store_table' => $this->getTable('scandi_menumanager/menu_store')),
64
+ 'main_table.menu_id = store_table.menu_id',array()
65
+ )->group('main_table.menu_id');
66
+ }
67
+
68
+ return parent::_renderFiltersBefore();
69
+ }
70
+ }
app/code/local/Scandi/MenuManager/controllers/Adminhtml/IndexController.php ADDED
@@ -0,0 +1,332 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Scandi_MenuManager
4
+ *
5
+ * @category Scandi
6
+ * @package Scandi_MenuManager
7
+ * @author Scandiweb <info@scandiweb.com>
8
+ * @copyright Copyright (c) 2013 Scandiweb, Ltd (http://scandiweb.com)
9
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
10
+ */
11
+
12
+ /**
13
+ * MenuManager admin index controller
14
+ *
15
+ * @category Scandi
16
+ * @package Scandi_MenuManager
17
+ */
18
+ class Scandi_MenuManager_Adminhtml_IndexController extends Mage_Adminhtml_Controller_Action
19
+ {
20
+ /**
21
+ * Init actions
22
+ *
23
+ * @return Scandi_MenuManager_Adminhtml_IndexController
24
+ */
25
+ protected function _initAction()
26
+ {
27
+ $this->loadLayout()
28
+ ->_setActiveMenu('cms/scandi_menumanager')
29
+ ->_addBreadcrumb(
30
+ Mage::helper('scandi_menumanager')->__('CMS'),
31
+ Mage::helper('scandi_menumanager')->__('CMS')
32
+ )
33
+ ->_addBreadcrumb(
34
+ Mage::helper('scandi_menumanager')->__('Menus'),
35
+ Mage::helper('scandi_menumanager')->__('Menus')
36
+ );
37
+
38
+ $this->_title($this->__('CMS'))
39
+ ->_title($this->__('Menus'));
40
+
41
+ return $this;
42
+ }
43
+
44
+ /**
45
+ * Index action - menu grid display
46
+ */
47
+ public function indexAction()
48
+ {
49
+ $this->_initAction();
50
+ $this->renderLayout();
51
+ }
52
+
53
+ /**
54
+ * Menu create action
55
+ */
56
+ public function newAction()
57
+ {
58
+ $this->_forward('edit');
59
+ }
60
+
61
+ /**
62
+ * Menu edit action
63
+ */
64
+ public function editAction()
65
+ {
66
+ $id = $this->getRequest()->getParam('menu_id');
67
+ $model = Mage::getModel('scandi_menumanager/menu');
68
+
69
+ if ($id) {
70
+ $model->load($id);
71
+ if (!$model->getId()) {
72
+ Mage::getSingleton('adminhtml/session')->addError(
73
+ Mage::helper('scandi_menumanager')->__('This menu no longer exists.'));
74
+
75
+ $this->_redirect('*/*/');
76
+ return;
77
+ }
78
+ }
79
+
80
+ $this->_title($model->getId() ? $model->getTitle() : $this->__('New Menu'));
81
+ $data = Mage::getSingleton('adminhtml/session')->getFormData(true);
82
+
83
+ if (!empty($data)) {
84
+ $model->setData($data);
85
+ }
86
+
87
+ Mage::register('menumanager_menu', $model);
88
+
89
+ $editMenu = Mage::helper('scandi_menumanager')->__('Edit Menu');
90
+ $newMenu = Mage::helper('scandi_menumanager')->__('New Menu');
91
+
92
+ $this->_initAction()->_addBreadcrumb(
93
+ $id ? $editMenu : $newMenu,
94
+ $id ? $editMenu : $newMenu
95
+ );
96
+
97
+ $this->renderLayout();
98
+ }
99
+
100
+ /**
101
+ * Menu save action
102
+ */
103
+ public function saveAction()
104
+ {
105
+ if ($data = $this->getRequest()->getPost()) {
106
+ /* @var $model Scandi_MenuManager_Model_Menu */
107
+ $id = $this->getRequest()->getParam('menu_id');
108
+ $model = Mage::getModel('scandi_menumanager/menu')->load($id);
109
+
110
+ if (!$model->getId() && $id) {
111
+ Mage::getSingleton('adminhtml/session')
112
+ ->addError(Mage::helper('scandi_menumanager')->__('This menu no longer exists.'));
113
+
114
+ $this->_redirect('*/*/');
115
+ return;
116
+ }
117
+
118
+ $model->setData($data);
119
+
120
+ try {
121
+ $model->save();
122
+ Mage::getSingleton('adminhtml/session')
123
+ ->addSuccess(Mage::helper('scandi_menumanager')->__('The menu has been saved.'));
124
+
125
+ Mage::getSingleton('adminhtml/session')->setFormData(false);
126
+
127
+ if ($this->getRequest()->getParam('back')) {
128
+ $this->_redirect('*/*/edit', array('menu_id' => $model->getId(), '_current' => true));
129
+
130
+ return;
131
+ }
132
+
133
+ $this->_redirect('*/*/');
134
+ return;
135
+
136
+ } catch (Exception $e) {
137
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
138
+ Mage::getSingleton('adminhtml/session')->setFormData($data);
139
+
140
+ $this->_redirect('*/*/edit', array('menu_id' => $id));
141
+ return;
142
+ }
143
+ }
144
+
145
+ $this->_redirect('*/*/');
146
+ }
147
+
148
+ /**
149
+ * Menu delete action
150
+ */
151
+ public function deleteAction()
152
+ {
153
+ if ($id = $this->getRequest()->getParam('menu_id')) {
154
+ try {
155
+ /* @var $model Scandi_MenuManager_Model_Menu */
156
+ $model = Mage::getModel('scandi_menumanager/menu')->load($id);
157
+ $model->delete();
158
+
159
+ Mage::getSingleton('adminhtml/session')
160
+ ->addSuccess(Mage::helper('scandi_menumanager')->__('The menu has been deleted.'));
161
+
162
+ $this->_redirect('*/*/');
163
+ return;
164
+
165
+ } catch (Exception $e) {
166
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
167
+
168
+ $this->_redirect('*/*/edit', array('menu_id' => $id));
169
+ return;
170
+ }
171
+ }
172
+
173
+ Mage::getSingleton('adminhtml/session')
174
+ ->addError(Mage::helper('scandi_menumanager')->__('Unable to find a menu to delete.'));
175
+
176
+ $this->_redirect('*/*/');
177
+ }
178
+
179
+ /**
180
+ * Create new menu item
181
+ */
182
+ public function new_itemAction()
183
+ {
184
+ $this->_forward('edit_item');
185
+ }
186
+
187
+ /**
188
+ * Menu item edit action
189
+ */
190
+ public function edit_itemAction()
191
+ {
192
+ /* @var $model Scandi_MenuManager_Model_Item */
193
+ $id = $this->getRequest()->getParam('item_id');
194
+ $model = Mage::getModel('scandi_menumanager/item');
195
+
196
+ if ($id) {
197
+ $model->load($id);
198
+ if (!$model->getId()) {
199
+ Mage::getSingleton('adminhtml/session')->addError(
200
+ Mage::helper('scandi_menumanager')->__('This menu item does not exist.')
201
+ );
202
+
203
+ $this->_redirectToMenuPage();
204
+ return;
205
+ }
206
+ }
207
+
208
+ $this->_title($model->getId() ? $model->getTitle() : $this->__('New Menu'));
209
+ $data = Mage::getSingleton('adminhtml/session')->getFormData(true);
210
+
211
+ if (!empty($data)) {
212
+ $model->setData($data);
213
+ }
214
+
215
+ Mage::register('menumanager_menu_item', $model);
216
+
217
+ $editMenuItem = Mage::helper('scandi_menumanager')->__('Edit Menu Item');
218
+ $newMenuItem = Mage::helper('scandi_menumanager')->__('New Menu Item');
219
+
220
+ $this->_initAction()->_addBreadcrumb(
221
+ $id ? $editMenuItem : $newMenuItem,
222
+ $id ? $editMenuItem : $newMenuItem
223
+ );
224
+
225
+ $this->renderLayout();
226
+ }
227
+
228
+ /**
229
+ * Menu item save action
230
+ */
231
+ public function save_itemAction()
232
+ {
233
+ if ($data = $this->getRequest()->getPost()) {
234
+ /* @var $model Scandi_MenuManager_Model_Item */
235
+ $id = $this->getRequest()->getParam('item_id');
236
+ $menuId = $this->getRequest()->getParam('menu_id');
237
+ $model = Mage::getModel('scandi_menumanager/item')->load($id);
238
+
239
+ if (!$model->getId() && $id) {
240
+ Mage::getSingleton('adminhtml/session')
241
+ ->addError(Mage::helper('scandi_menumanager')->__('This menu item no longer exists.'));
242
+
243
+ $this->_redirectToMenuPage();
244
+ return;
245
+ }
246
+
247
+ if (!$menuId) {
248
+ Mage::getSingleton('adminhtml/session')
249
+ ->addError(Mage::helper('scandi_menumanager')->__('Parent menu could not be found.'));
250
+
251
+ $this->_redirectToMenuPage();
252
+ return;
253
+ }
254
+
255
+ $data['menu_id'] = $menuId;
256
+ $model->setData($data);
257
+
258
+ try {
259
+ $model->save();
260
+ Mage::getSingleton('adminhtml/session')
261
+ ->addSuccess(Mage::helper('scandi_menumanager')->__('The menu item has been saved.'));
262
+
263
+ Mage::getSingleton('adminhtml/session')->setFormData(false);
264
+
265
+ $this->_redirectToMenuPage();
266
+ return;
267
+
268
+ } catch (Exception $e) {
269
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
270
+ Mage::getSingleton('adminhtml/session')->setFormData($data);
271
+
272
+ $this->_redirectToItemPage();
273
+ return;
274
+ }
275
+ }
276
+
277
+ $this->_redirect('*/*/');
278
+ }
279
+
280
+ /**
281
+ * Menu item delete action
282
+ */
283
+ public function delete_itemAction()
284
+ {
285
+ if ($id = $this->getRequest()->getParam('item_id')) {
286
+ try {
287
+ /* @var $model Scandi_MenuManager_Model_Item */
288
+ $model = Mage::getModel('scandi_menumanager/item')->load($id);
289
+ $model->delete();
290
+
291
+ Mage::getSingleton('adminhtml/session')
292
+ ->addSuccess(Mage::helper('scandi_menumanager')->__('The menu item has been deleted.'));
293
+
294
+ $this->_redirectToMenuPage();
295
+ return;
296
+
297
+ } catch (Exception $e) {
298
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
299
+
300
+ $this->_redirectToItemPage();
301
+ return;
302
+ }
303
+ }
304
+
305
+ Mage::getSingleton('adminhtml/session')
306
+ ->addError(Mage::helper('scandi_menumanager')->__('Unable to find a menu item to delete.'));
307
+
308
+ $this->_redirectToMenuPage();
309
+ }
310
+
311
+ /**
312
+ * Redirects to parent menu edit page
313
+ */
314
+ protected function _redirectToMenuPage()
315
+ {
316
+ $this->_redirect('*/*/edit', array(
317
+ 'menu_id' => $this->getRequest()->getParam('menu_id'),
318
+ 'active_tab' => 'menu_page_tabs_items_section',
319
+ ));
320
+ }
321
+
322
+ /**
323
+ * Redirects to item edit page
324
+ */
325
+ protected function _redirectToItemPage()
326
+ {
327
+ $this->_redirect('*/*/edit_item', array(
328
+ 'item_id' => $this->getRequest()->getParam('item_id'),
329
+ 'menu_id' => $this->getRequest()->getParam('menu_id'),
330
+ ));
331
+ }
332
+ }
app/code/local/Scandi/MenuManager/etc/adminhtml.xml ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Scandi_MenuManager
5
+ *
6
+ * @category Scandi
7
+ * @package Scandi_MenuManager
8
+ * @author Scandiweb <info@scandiweb.com>
9
+ * @copyright Copyright (c) 2013 Scandiweb, Ltd (http://scandiweb.com)
10
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
11
+ */
12
+ -->
13
+ <config>
14
+ <menu>
15
+ <cms>
16
+ <children>
17
+ <scandi_menumanager translate="title" module="scandi_menumanager">
18
+ <title>Menus</title>
19
+ <action>menumanager/adminhtml_index/index</action>
20
+ <sort_order>25</sort_order>
21
+ </scandi_menumanager>
22
+ </children>
23
+ </cms>
24
+ </menu>
25
+ <acl>
26
+ <resources>
27
+ <admin>
28
+ <children>
29
+ <cms>
30
+ <children>
31
+ <scandi_menumanager translate="title" module="scandi_menumanager">
32
+ <title>Menus</title>
33
+ <sort_order>25</sort_order>
34
+ </scandi_menumanager>
35
+ </children>
36
+ </cms>
37
+ </children>
38
+ </admin>
39
+ </resources>
40
+ </acl>
41
+ </config>
42
+
app/code/local/Scandi/MenuManager/etc/config.xml ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Scandi_MenuManager
5
+ *
6
+ * @category Scandi
7
+ * @package Scandi_MenuManager
8
+ * @author Scandiweb <info@scandiweb.com>
9
+ * @copyright Copyright (c) 2013 Scandiweb, Ltd (http://scandiweb.com)
10
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
11
+ */
12
+ -->
13
+ <config>
14
+ <modules>
15
+ <Scandi_MenuManager>
16
+ <version>0.1.0</version>
17
+ </Scandi_MenuManager>
18
+ </modules>
19
+ <global>
20
+ <models>
21
+ <scandi_menumanager>
22
+ <class>Scandi_MenuManager_Model</class>
23
+ <resourceModel>scandi_menumanager_resource</resourceModel>
24
+ </scandi_menumanager>
25
+ <scandi_menumanager_resource>
26
+ <class>Scandi_MenuManager_Model_Resource</class>
27
+ <entities>
28
+ <menu>
29
+ <table>scandi_menumanager_menu</table>
30
+ </menu>
31
+ <menu_item>
32
+ <table>scandi_menumanager_menu_item</table>
33
+ </menu_item>
34
+ <menu_store>
35
+ <table>scandi_menumanager_menu_store</table>
36
+ </menu_store>
37
+ </entities>
38
+ </scandi_menumanager_resource>
39
+ </models>
40
+ <helpers>
41
+ <scandi_menumanager>
42
+ <class>Scandi_MenuManager_Helper</class>
43
+ </scandi_menumanager>
44
+ </helpers>
45
+ <blocks>
46
+ <scandi_menumanager>
47
+ <class>Scandi_MenuManager_Block</class>
48
+ </scandi_menumanager>
49
+ </blocks>
50
+ <resources>
51
+ <scandi_menumanager_setup>
52
+ <setup>
53
+ <module>Scandi_MenuManager</module>
54
+ <class>Mage_Core_Model_Resource_Setup</class>
55
+ </setup>
56
+ </scandi_menumanager_setup>
57
+ </resources>
58
+ </global>
59
+ <admin>
60
+ <routers>
61
+ <scandi_menumanager_admin>
62
+ <use>admin</use>
63
+ <args>
64
+ <module>Scandi_MenuManager</module>
65
+ <frontName>menumanager</frontName>
66
+ </args>
67
+ </scandi_menumanager_admin>
68
+ </routers>
69
+ </admin>
70
+ <adminhtml>
71
+ <layout>
72
+ <updates>
73
+ <scandi_menumanager>
74
+ <file>scandi_menumanager.xml</file>
75
+ </scandi_menumanager>
76
+ </updates>
77
+ </layout>
78
+ </adminhtml>
79
+ <frontend>
80
+ <layout>
81
+ <updates>
82
+ <scandi_menumanager>
83
+ <file>scandi_menumanager.xml</file>
84
+ </scandi_menumanager>
85
+ </updates>
86
+ </layout>
87
+ </frontend>
88
+ </config>
app/code/local/Scandi/MenuManager/sql/scandi_menumanager_setup/install-0.1.0.php ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Scandi_MenuManager
4
+ *
5
+ * @category Scandi
6
+ * @package Scandi_MenuManager
7
+ * @author Scandiweb <info@scandiweb.com>
8
+ * @copyright Copyright (c) 2013 Scandiweb, Ltd (http://scandiweb.com)
9
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
10
+ */
11
+
12
+ /* @var $installer Mage_Core_Model_Resource_Setup */
13
+ $installer = $this;
14
+
15
+ /* Create table "scandi_menumanager/menu" */
16
+ $table = $installer->getConnection()
17
+ ->newTable(
18
+ $installer->getTable('scandi_menumanager/menu')
19
+ )
20
+ ->addColumn(
21
+ 'menu_id', Varien_Db_Ddl_Table::TYPE_TINYINT, null, array(
22
+ 'identity' => true,
23
+ 'nullable' => false,
24
+ 'primary' => true,
25
+ ), 'Menu ID'
26
+ )
27
+ ->addColumn(
28
+ 'title', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
29
+ 'nullable' => false,
30
+ ), 'Menu Title'
31
+ )
32
+ ->addColumn(
33
+ 'identifier', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
34
+ 'nullable' => false,
35
+ ), 'Menu String Identifier'
36
+ )
37
+ ->addColumn(
38
+ 'type', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
39
+ 'nullable' => false,
40
+ 'default' => 'none',
41
+ ), 'Menu Type'
42
+ )
43
+ ->addColumn(
44
+ 'css_class', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
45
+ 'nullable' => true,
46
+ 'default' => null,
47
+ ), 'Menu CSS Class'
48
+ )
49
+ ->addColumn(
50
+ 'is_active', Varien_Db_Ddl_Table::TYPE_TINYINT, null, array(
51
+ 'nullable' => false,
52
+ 'default' => '1',
53
+ ), 'Is Menu Active'
54
+ )
55
+ ->setComment('MenuManager Menu Table');
56
+
57
+ $installer->getConnection()->createTable($table);
58
+
59
+ /* Create table "scandi_menumanager/menu_store" */
60
+ $table = $installer->getConnection()
61
+ ->newTable(
62
+ $installer->getTable('scandi_menumanager/menu_store')
63
+ )
64
+ ->addColumn(
65
+ 'menu_id', Varien_Db_Ddl_Table::TYPE_TINYINT, null, array(
66
+ 'nullable' => false,
67
+ 'primary' => true,
68
+ ), 'Menu ID'
69
+ )
70
+ ->addColumn(
71
+ 'store_id', Varien_Db_Ddl_Table::TYPE_TINYINT, null, array(
72
+ 'unsigned' => true,
73
+ 'nullable' => false,
74
+ 'primary' => true,
75
+ ), 'Store ID'
76
+ )
77
+ ->addIndex(
78
+ $installer->getIdxName('scandi_menumanager/menu_store', array('store_id')), array('store_id')
79
+ )
80
+ ->addForeignKey(
81
+ $installer->getFkName(
82
+ 'scandi_menumanager/menu_store', 'menu_id', 'scandi_menumanager/menu', 'menu_id'
83
+ ),
84
+ 'menu_id', $installer->getTable('scandi_menumanager/menu'), 'menu_id',
85
+ Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE
86
+ )
87
+ ->addForeignKey(
88
+ $installer->getFkName(
89
+ 'scandi_menumanager/menu_store', 'store_id', 'core/store', 'store_id'
90
+ ),
91
+ 'store_id', $installer->getTable('core/store'), 'store_id',
92
+ Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE
93
+ )
94
+ ->setComment('MenuManager Menu To Store Linkage Table');
95
+
96
+ $installer->getConnection()->createTable($table);
97
+
98
+ /* Create table "scandi_menumanager/menu_item" */
99
+ $table = $installer->getConnection()
100
+ ->newTable(
101
+ $installer->getTable('scandi_menumanager/menu_item')
102
+ )
103
+ ->addColumn(
104
+ 'item_id', Varien_Db_Ddl_Table::TYPE_TINYINT, null, array(
105
+ 'identity' => true,
106
+ 'nullable' => false,
107
+ 'primary' => true,
108
+ ), 'Item ID'
109
+ )
110
+ ->addColumn(
111
+ 'menu_id', Varien_Db_Ddl_Table::TYPE_TINYINT, null, array(
112
+ 'nullable' => false,
113
+ ), 'Menu ID'
114
+ )
115
+ ->addColumn(
116
+ 'parent_id', Varien_Db_Ddl_Table::TYPE_TINYINT, null, array(
117
+ 'nullable' => false,
118
+ ), 'Parent ID'
119
+ )
120
+ ->addColumn(
121
+ 'title', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
122
+ 'nullable' => false,
123
+ ), 'Item Title'
124
+ )
125
+ ->addColumn(
126
+ 'identifier', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
127
+ 'nullable' => false,
128
+ ), 'Item String Identifier'
129
+ )
130
+ ->addColumn(
131
+ 'url', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
132
+ 'nullable' => true,
133
+ 'default' => null,
134
+ ), 'Item Url'
135
+ )
136
+ ->addColumn(
137
+ 'type', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
138
+ 'nullable' => false,
139
+ 'default' => 'same_window',
140
+ ), 'Item Open Type'
141
+ )
142
+ ->addColumn(
143
+ 'css_class', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
144
+ 'nullable' => true,
145
+ 'default' => null,
146
+ ), 'Item CSS Class'
147
+ )
148
+ ->addColumn(
149
+ 'position', Varien_Db_Ddl_Table::TYPE_TINYINT, null, array(
150
+ 'nullable' => false,
151
+ 'default' => '0',
152
+ ), 'Item Position'
153
+ )
154
+ ->addColumn(
155
+ 'is_active', Varien_Db_Ddl_Table::TYPE_TINYINT, null, array(
156
+ 'nullable' => false,
157
+ 'default' => '1',
158
+ ), 'Is Item Active'
159
+ )
160
+ ->addIndex(
161
+ $installer->getIdxName('scandi_menumanager/menu_item', array('identifier')), array('identifier')
162
+ )
163
+ ->addForeignKey(
164
+ $installer->getFkName(
165
+ 'scandi_menumanager/menu_item', 'menu_id', 'scandi_menumanager/menu', 'menu_id'
166
+ ),
167
+ 'menu_id', $installer->getTable('scandi_menumanager/menu'), 'menu_id',
168
+ Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE
169
+ )
170
+ ->setComment('MenuManager Menu Item Table');
171
+
172
+ $installer->getConnection()->createTable($table);
app/design/adminhtml/default/default/layout/scandi_menumanager.xml ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Scandi_MenuManager
5
+ *
6
+ * @category Scandi
7
+ * @package Scandi_MenuManager
8
+ * @author Scandiweb <info@scandiweb.com>
9
+ * @copyright Copyright (c) 2013 Scandiweb, Ltd (http://scandiweb.com)
10
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
11
+ */
12
+ -->
13
+ <layout>
14
+ <scandi_menumanager_admin_adminhtml_index_index>
15
+ <reference name="content">
16
+ <block type="scandi_menumanager/adminhtml_menu" name="menumanager_menu_grid" />
17
+ </reference>
18
+ </scandi_menumanager_admin_adminhtml_index_index>
19
+
20
+ <scandi_menumanager_admin_adminhtml_index_edit>
21
+ <reference name="content">
22
+ <block type="scandi_menumanager/adminhtml_menu_edit" name="menumanager_menu_edit" />
23
+ </reference>
24
+
25
+ <reference name="left">
26
+ <block type="scandi_menumanager/adminhtml_menu_edit_tabs" name="menumanager_menu_edit_tabs">
27
+ <block type="scandi_menumanager/adminhtml_menu_edit_tab_main" name="menumanager_menu_edit_tab_main" />
28
+ <action method="addTab"><name>main_section</name><block>menumanager_menu_edit_tab_main</block></action>
29
+ </block>
30
+ </reference>
31
+ </scandi_menumanager_admin_adminhtml_index_edit>
32
+
33
+ <scandi_menumanager_admin_adminhtml_index_edit_item>
34
+ <reference name="content">
35
+ <block type="scandi_menumanager/adminhtml_menu_item_edit" name="menumanager_menu_item_edit" />
36
+ </reference>
37
+ </scandi_menumanager_admin_adminhtml_index_edit_item>
38
+ </layout>
app/design/frontend/base/default/layout/scandi_menumanager.xml ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Scandi_MenuManager
5
+ *
6
+ * @category Scandi
7
+ * @package Scandi_MenuManager
8
+ * @author Scandiweb <info@scandiweb.com>
9
+ * @copyright Copyright (c) 2013 Scandiweb, Ltd (http://scandiweb.com)
10
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
11
+ */
12
+ -->
13
+ <layout>
14
+ <default>
15
+ <reference name="head">
16
+ <action method="addItem"><type>skin_css</type><name>scandi/menumanager/css/menumanager.css</name></action>
17
+ </reference>
18
+ </default>
19
+ </layout>
app/design/frontend/base/default/template/scandi/menumanager/menu.phtml ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Scandi_MenuManager
4
+ *
5
+ * @category Scandi
6
+ * @package Scandi_MenuManager
7
+ * @author Scandiweb <info@scandiweb.com>
8
+ * @copyright Copyright (c) 2013 Scandiweb, Ltd (http://scandiweb.com)
9
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
10
+ */
11
+
12
+ /**
13
+ * @var $this Scandi_MenuManager_Block_Menu
14
+ * $this->getMenu() to get menu model, data
15
+ */
16
+ ?>
17
+
18
+ <?php if ($menu = $this->getMenuHtml()): ?>
19
+ <?php echo $menu; ?>
20
+ <?php endif; ?>
21
+
app/etc/modules/Scandi_MenuManager.xml ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Scandi_MenuManager
5
+ *
6
+ * @category Scandi
7
+ * @package Scandi_MenuManager
8
+ * @author Scandiweb <info@scandiweb.com>
9
+ * @copyright Copyright (c) 2013 Scandiweb, Ltd (http://scandiweb.com)
10
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
11
+ */
12
+ -->
13
+ <config>
14
+ <modules>
15
+ <Scandi_MenuManager>
16
+ <active>true</active>
17
+ <codePool>local</codePool>
18
+ <depends>
19
+ <Mage_Cms />
20
+ <Mage_Adminhtml />
21
+ </depends>
22
+ </Scandi_MenuManager>
23
+ </modules>
24
+ </config>
package.xml ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Scandi_MenuManager</name>
4
+ <version>0.1.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/afl-3.0.php">Academic Free License (AFL 3.0)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Allows user to create multiple menus and add them to site.</summary>
10
+ <description>Allows user to create multiple menus and add them to site. Supports active menu item feature, multiple stores. Easy to use.&#xD;
11
+ 3 default menu types are available - vertical, horizontal and plain output - no style. Developer friendly.</description>
12
+ <notes>Stable Release.</notes>
13
+ <authors><author><name>Scandiweb</name><user>Scandiweb</user><email>info@scandiweb.com</email></author></authors>
14
+ <date>2013-09-17</date>
15
+ <time>09:07:28</time>
16
+ <contents><target name="mage"><dir name="skin"><dir name="frontend"><dir name="base"><dir name="default"><dir name="scandi"><dir><dir name="menumanager"><dir name="css"><file name="menumanager.css" hash="44affbd65601808da200dd6153c3200c"/></dir></dir></dir></dir></dir></dir></dir></dir><dir name="app"><dir name="etc"><dir name="modules"><file name="Scandi_MenuManager.xml" hash="a186239a5e97428580a1ff7d4bd55347"/></dir></dir><dir name="design"><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="scandi"><dir><dir name="menumanager"><file name="menu.phtml" hash="397b516c94996932fcb448c3a02cbc47"/></dir></dir></dir></dir><dir name="layout"><file name="scandi_menumanager.xml" hash="0af5ffc03e959aad16c43496a83f5b9e"/></dir></dir></dir></dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="scandi_menumanager.xml" hash="3ce4c1a20ad3d8873ce6ddd2a70aa23a"/></dir></dir></dir></dir></dir><dir name="code"><dir name="local"><dir><dir name="Scandi"><dir name="MenuManager"><dir name="Block"><dir name="Adminhtml"><dir name="Menu"><dir name="Edit"><file name="Form.php" hash="e636f7cd2f5acf6eccee885c0e5198d1"/><dir name="Tab"><file name="Items.php" hash="fba7c1cd90302ff9afc2e0216238845f"/><file name="Main.php" hash="cd5863cbc331ed42a6c4c0d175f5de2a"/><dir name="Renderer"><file name="Parent.php" hash="708f8220d75472a8822bfe18f0aea12f"/></dir></dir><file name="Tabs.php" hash="c092cee92941ee3211da0602b4402fdc"/></dir><file name="Edit.php" hash="61b153e11b36ece02a9024dbf7708e03"/><file name="Grid.php" hash="4a94cc2bd56e0b0d5a66bc5138ce4c18"/><dir name="Item"><dir name="Edit"><file name="Form.php" hash="a846d6cbaa6541cd8decfc15264c9331"/></dir><file name="Edit.php" hash="6af548772ba70e066944923ab421d8b0"/></dir></dir><file name="Menu.php" hash="0cd7f413dc74de864096e5a5769ed8c2"/></dir><file name="Menu.php" hash="f975f0e84bb173c17b8d24a902a4eebc"/></dir><dir name="Helper"><file name="Data.php" hash="1ca5e904a2c6bcbef6a6b5bd80c804a3"/></dir><dir name="Model"><file name="Item.php" hash="f4b340d5a7e9f975f36ff0cb2d932369"/><file name="Menu.php" hash="c88023d40c0ba534204ea315d0783abd"/><dir name="Resource"><dir name="Item"><file name="Collection.php" hash="7f2c88a86016638c4d26d83c372ccf54"/></dir><file name="Item.php" hash="7b6b389019f487b7a577e8a0b5e3a417"/><dir name="Menu"><file name="Collection.php" hash="9840901b8205cef9ef114109c85a232d"/></dir><file name="Menu.php" hash="48f29025fe6023e8dfc418b9600bc173"/></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="IndexController.php" hash="d712864c83d5b13ad42706c06605b91e"/></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="7a7bbe9d68c584ea7a5786cbdfdb688f"/><file name="config.xml" hash="b3fa658fccf9af1969de7973ca8574fa"/></dir><dir name="sql"><dir name="scandi_menumanager_setup"><file name="install-0.1.0.php" hash="4b41c4ce2e404b3ca645a4796ee3313a"/></dir></dir></dir></dir></dir></dir></dir></dir></target></contents>
17
+ <compatible/>
18
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
19
+ </package>
skin/frontend/base/default/scandi/menumanager/css/menumanager.css ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Scandi_MenuManager
3
+ *
4
+ * @category Scandi
5
+ * @package Scandi_MenuManager
6
+ * @author Scandiweb <info@scandiweb.com>
7
+ * @copyright Copyright (c) 2013 Scandiweb, Ltd (http://scandiweb.com)
8
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
9
+ */
10
+
11
+ /* Global Style */
12
+ .menu-manager-menu { margin-bottom:15px; }
13
+ .menu-manager-menu li.active > a { text-decoration:none; }
14
+
15
+ /* Type : None */
16
+ .menu-type-none,
17
+ .menu-type-none ul,
18
+ .menu-type-none li { display:inline; }
19
+ .menu-type-none li a span,
20
+ .menu-type-none li span span { padding-right:5px; }
21
+
22
+ /* Type : Vertical */
23
+ .menu-type-vertical ul { padding-left:15px; }
24
+
25
+ /* Type : Horizontal */
26
+ .menu-type-horizontal { position:relative; z-index:100; }
27
+ .menu-type-horizontal li.level0 { display:inline; }
28
+ .menu-type-horizontal li.level0.last { border-right:1px solid #ccc; }
29
+ .menu-type-horizontal li { display:block; position:relative; padding:5px 10px; border:1px solid #ccc; border-right:none; background:#fff; }
30
+
31
+ .menu-type-horizontal li.title { cursor:default; }
32
+
33
+ .menu-type-horizontal ul { position:absolute; left:0; top:100%; margin-left:-1px; border:1px solid #ccc; background:#fff; width:14em; display:none; }
34
+ .menu-type-horizontal ul li { border:none; border-bottom:1px solid #ccc; }
35
+ .menu-type-horizontal ul li.last { border-bottom:none; }
36
+ .menu-type-horizontal li.level1 ul { left:50%; top:70%; }
37
+ .menu-type-horizontal li:hover > ul { display:block; }