Ultimate_ModuleCreator - Version 1.9.5.0

Version Notes

Improvement
- Cleaned up the UMC code and the generated code. Now all files (almost) follow the zend coding standards.

Features
- Support for signed int attributes/fields
- Generating modman file
- Support for canonical URL in generated module

Bug fixes
- Removed calls to deprecated method htmlEscape
- Fixed wrong helper alias in Yes/No attribute display
- Fixed wrong display of multiselect attribute on frontend
- Fixed 2 status fields generated in the setup file

Download this release

Release Info

Developer Marius
Extension Ultimate_ModuleCreator
Version 1.9.5.0
Comparing to
See all releases


Code changes from version 1.9.4.4 to 1.9.5.0

Files changed (58) hide show
  1. app/code/community/Ultimate/ModuleCreator/Block/Adminhtml/Modulecreator.php +40 -38
  2. app/code/community/Ultimate/ModuleCreator/Block/Adminhtml/Modulecreator/Edit.php +316 -260
  3. app/code/community/Ultimate/ModuleCreator/Block/Adminhtml/Modulecreator/Edit/Form.php +51 -42
  4. app/code/community/Ultimate/ModuleCreator/Block/Adminhtml/Modulecreator/Edit/Tab/Entities.php +105 -90
  5. app/code/community/Ultimate/ModuleCreator/Block/Adminhtml/Modulecreator/Edit/Tab/Entities/Entity.php +68 -64
  6. app/code/community/Ultimate/ModuleCreator/Block/Adminhtml/Modulecreator/Edit/Tab/Entities/Entity/Attribute.php +70 -66
  7. app/code/community/Ultimate/ModuleCreator/Block/Adminhtml/Modulecreator/Edit/Tab/Help.php +367 -314
  8. app/code/community/Ultimate/ModuleCreator/Block/Adminhtml/Modulecreator/Edit/Tab/Help/Fieldset.php +82 -78
  9. app/code/community/Ultimate/ModuleCreator/Block/Adminhtml/Modulecreator/Edit/Tab/Relation.php +90 -77
  10. app/code/community/Ultimate/ModuleCreator/Block/Adminhtml/Modulecreator/Edit/Tab/Settings.php +101 -89
  11. app/code/community/Ultimate/ModuleCreator/Block/Adminhtml/Modulecreator/Edit/Tabs.php +44 -42
  12. app/code/community/Ultimate/ModuleCreator/Block/Adminhtml/Modulecreator/Grid.php +207 -174
  13. app/code/community/Ultimate/ModuleCreator/Block/Adminhtml/Modulecreator/Grid/Column/Renderer/Download.php +83 -75
  14. app/code/community/Ultimate/ModuleCreator/Block/Adminhtml/Modulecreator/Menu.php +108 -95
  15. app/code/community/Ultimate/ModuleCreator/Block/Adminhtml/Modulecreator/System/Config/Form/Fieldset/Abstract.php +141 -128
  16. app/code/community/Ultimate/ModuleCreator/Block/Adminhtml/Modulecreator/System/Config/Form/Fieldset/Attribute.php +38 -36
  17. app/code/community/Ultimate/ModuleCreator/Block/Adminhtml/Modulecreator/System/Config/Form/Fieldset/Entity.php +38 -36
  18. app/code/community/Ultimate/ModuleCreator/Block/Adminhtml/Modulecreator/System/Config/Form/Fieldset/Settings.php +38 -36
  19. app/code/community/Ultimate/ModuleCreator/Exception.php +21 -21
  20. app/code/community/Ultimate/ModuleCreator/Helper/Data.php +561 -487
  21. app/code/community/Ultimate/ModuleCreator/Model/Abstract.php +127 -108
  22. app/code/community/Ultimate/ModuleCreator/Model/Attribute.php +759 -628
  23. app/code/community/Ultimate/ModuleCreator/Model/Attribute/Type/Abstract.php +510 -390
  24. app/code/community/Ultimate/ModuleCreator/Model/Attribute/Type/Country.php +180 -122
  25. app/code/community/Ultimate/ModuleCreator/Model/Attribute/Type/Decimal.php +54 -47
  26. app/code/community/Ultimate/ModuleCreator/Model/Attribute/Type/Dropdown.php +412 -312
  27. app/code/community/Ultimate/ModuleCreator/Model/Attribute/Type/Dropdown/Abstract.php +101 -87
  28. app/code/community/Ultimate/ModuleCreator/Model/Attribute/Type/Dropdown/Category.php +33 -32
  29. app/code/community/Ultimate/ModuleCreator/Model/Attribute/Type/Dropdown/Custom.php +133 -123
  30. app/code/community/Ultimate/ModuleCreator/Model/Attribute/Type/Dropdown/Customer.php +33 -32
  31. app/code/community/Ultimate/ModuleCreator/Model/Attribute/Type/Dropdown/Product.php +175 -157
  32. app/code/community/Ultimate/ModuleCreator/Model/Attribute/Type/File.php +161 -128
  33. app/code/community/Ultimate/ModuleCreator/Model/Attribute/Type/Image.php +155 -122
  34. app/code/community/Ultimate/ModuleCreator/Model/Attribute/Type/Int.php +69 -58
  35. app/code/community/Ultimate/ModuleCreator/Model/Attribute/Type/Multiselect.php +193 -144
  36. app/code/community/Ultimate/ModuleCreator/Model/Attribute/Type/Signedint.php +33 -0
  37. app/code/community/Ultimate/ModuleCreator/Model/Attribute/Type/Text.php +48 -44
  38. app/code/community/Ultimate/ModuleCreator/Model/Attribute/Type/Textarea.php +117 -97
  39. app/code/community/Ultimate/ModuleCreator/Model/Attribute/Type/Timestamp.php +144 -111
  40. app/code/community/Ultimate/ModuleCreator/Model/Attribute/Type/Yesno.php +200 -156
  41. app/code/community/Ultimate/ModuleCreator/Model/Config.php +81 -71
  42. app/code/community/Ultimate/ModuleCreator/Model/Entity.php +3502 -2992
  43. app/code/community/Ultimate/ModuleCreator/Model/Entity/Type/Abstract.php +644 -495
  44. app/code/community/Ultimate/ModuleCreator/Model/Entity/Type/Eav.php +971 -783
  45. app/code/community/Ultimate/ModuleCreator/Model/Entity/Type/Flat.php +28 -28
  46. app/code/community/Ultimate/ModuleCreator/Model/Module.php +2326 -1915
  47. app/code/community/Ultimate/ModuleCreator/Model/Module/Collection.php +102 -96
  48. app/code/community/Ultimate/ModuleCreator/Model/Relation.php +253 -211
  49. app/code/community/Ultimate/ModuleCreator/Model/Source/Attribute/Scope.php +64 -60
  50. app/code/community/Ultimate/ModuleCreator/Model/Source/Attribute/Type.php +67 -64
  51. app/code/community/Ultimate/ModuleCreator/Model/Source/Attribute/Value/Source.php +59 -55
  52. app/code/community/Ultimate/ModuleCreator/Model/Source/Codepool.php +76 -64
  53. app/code/community/Ultimate/ModuleCreator/Model/Source/Entity/Layout.php +57 -53
  54. app/code/community/Ultimate/ModuleCreator/Model/Source/Entity/Menu.php +62 -55
  55. app/code/community/Ultimate/ModuleCreator/Model/Source/Entity/Type.php +58 -53
  56. app/code/community/Ultimate/ModuleCreator/Model/Source/Install.php +83 -74
  57. app/code/community/Ultimate/ModuleCreator/Model/Writer.php +91 -83
  58. app/code/community/Ultimate/ModuleCreator/controllers/Adminhtml/ModulecreatorController.php +80 -262
app/code/community/Ultimate/ModuleCreator/Block/Adminhtml/Modulecreator.php CHANGED
@@ -1,38 +1,40 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- */
17
- /**
18
- * main admin block - grid container.
19
- *
20
- * @category Ultimate
21
- * @package Ultimate_ModuleCreator
22
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
23
- */
24
- class Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator
25
- extends Mage_Adminhtml_Block_Widget_Grid_Container {
26
- /**
27
- * constructor
28
- * @access public
29
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
30
- */
31
- public function __construct() {
32
- $this->_controller = 'adminhtml_modulecreator';
33
- $this->_blockGroup = 'modulecreator';
34
- $this->_headerText = Mage::helper('modulecreator')->__('Manage modules');
35
- parent::__construct();
36
- $this->_updateButton('add', 'label', Mage::helper('modulecreator')->__('Create new module'));
37
- }
38
- }
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ */
17
+ /**
18
+ * main admin block - grid container.
19
+ *
20
+ * @category Ultimate
21
+ * @package Ultimate_ModuleCreator
22
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
23
+ */
24
+ class Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator extends Mage_Adminhtml_Block_Widget_Grid_Container
25
+ {
26
+ /**
27
+ * constructor
28
+ *
29
+ * @access public
30
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
31
+ */
32
+ public function __construct()
33
+ {
34
+ $this->_controller = 'adminhtml_modulecreator';
35
+ $this->_blockGroup = 'modulecreator';
36
+ $this->_headerText = Mage::helper('modulecreator')->__('Manage modules');
37
+ parent::__construct();
38
+ $this->_updateButton('add', 'label', Mage::helper('modulecreator')->__('Create new module'));
39
+ }
40
+ }
app/code/community/Ultimate/ModuleCreator/Block/Adminhtml/Modulecreator/Edit.php CHANGED
@@ -1,260 +1,316 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
- */
18
- /**
19
- * module edit block
20
- *
21
- * @category Ultimate
22
- * @package Ultimate_ModuleCreator
23
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
- */
25
- class Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit
26
- extends Mage_Adminhtml_Block_Widget_Form_Container {
27
- const XML_FIELDSET_COLLAPSED = 'modulecreator/general/collapsed';
28
- /**
29
- * construct
30
- * @access public
31
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
32
- */
33
- public function __construct() {
34
- parent::__construct();
35
- $this->_blockGroup = 'adminhtml_modulecreator';
36
- $this->_controller = 'modulecreator';
37
- $this->setTemplate('ultimate_modulecreator/edit.phtml');
38
- }
39
-
40
- /**
41
- * get current module
42
- * @access public
43
- * @return mixed
44
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
45
- */
46
- public function getModule() {
47
- return Mage::registry('current_module');
48
- }
49
- /**
50
- * get header text
51
- * @access public
52
- * @return string
53
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
54
- */
55
- public function getHeaderText() {
56
- $module = $this->getModule();
57
- if ($module){
58
- return Mage::helper('modulecreator')->__('Edit module "%s"', $module->getExtensionName());
59
- }
60
- return Mage::helper('modulecreator')->__('Create Module');
61
- }
62
- /**
63
- * prepare the layout
64
- * @access protected
65
- * @return Ultimate_ModuleCreator_Block_Adminhtml_ModuleCreator_Edit
66
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
67
- */
68
- protected function _prepareLayout() {
69
- /** @var Mage_Adminhtml_Block_Widget_Button $backButton */
70
- $backButton = $this->getLayout()
71
- ->createBlock('adminhtml/widget_button')
72
- ->setData(array(
73
- 'label' => Mage::helper('modulecreator')->__('Back'),
74
- 'onclick' => 'setLocation(\''.$this->getUrl('*/*/').'\')',
75
- 'class' => 'back'
76
- ));
77
- $this->setChild('back_button', $backButton);
78
-
79
- /** @var Mage_Adminhtml_Block_Widget_Button $resetButton */
80
- $resetButton = $this->getLayout()
81
- ->createBlock('adminhtml/widget_button')
82
- ->setData(array(
83
- 'label' => Mage::helper('modulecreator')->__('Reset'),
84
- 'onclick' => 'setLocation(\''.$this->getUrl('*/*/*', array('_current'=>true)).'\')'
85
- ));
86
- $this->setChild('reset_button', $resetButton);
87
-
88
- /** @var Mage_Adminhtml_Block_Widget_Button $saveButton */
89
- $saveButton = $this->getLayout()
90
- ->createBlock('adminhtml/widget_button')
91
- ->setData(array(
92
- 'label' => Mage::helper('modulecreator')->__('Save'),
93
- 'onclick' => 'moduleForm.submit()',
94
- 'class' => 'save'
95
- ));
96
- $this->setChild('save_button', $saveButton);
97
-
98
- /** @var Mage_Adminhtml_Block_Widget_Button $saveEditButton */
99
- $saveEditButton = $this->getLayout()
100
- ->createBlock('adminhtml/widget_button')
101
- ->setData(array(
102
- 'label' => Mage::helper('modulecreator')->__('Save and Continue Edit'),
103
- 'onclick' => 'saveAndContinueEdit(\''.$this->getSaveAndContinueUrl().'\')',
104
- 'class' => 'save'
105
- ));
106
- $this->setChild('save_and_edit_button', $saveEditButton);
107
-
108
- /** @var Mage_Adminhtml_Block_Widget_Button $addEntityButton */
109
- $addEntityButton = $this->getLayout()
110
- ->createBlock('adminhtml/widget_button')
111
- ->setData(array(
112
- 'label' => Mage::helper('modulecreator')->__('Add entity'),
113
- 'class' => 'add add-entity'
114
- ));
115
- $this->setChild('add-entity', $addEntityButton);
116
-
117
- /** @var Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Tab_Entities_Entity $block */
118
- $block = Mage::app()->getLayout()
119
- ->createBlock('modulecreator/adminhtml_modulecreator_edit_tab_entities_entity');
120
- $block->setTemplate('ultimate_modulecreator/edit/tab/entities/entity.phtml');
121
- $block->setDefaultEntity();
122
- $block->setIncrement('{{entity_id}}');
123
- $this->setChild('entity-template', $block);
124
-
125
- /** @var Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Tab_Entities_Entity_Attribute $block */
126
- $block = Mage::app()->getLayout()
127
- ->createBlock('modulecreator/adminhtml_modulecreator_edit_tab_entities_entity_attribute');
128
- $block->setTemplate('ultimate_modulecreator/edit/tab/entities/entity/attribute.phtml');
129
- $block->setDefaultAttributeInstance();
130
- $block->setIncrement('{{attribute_id}}');
131
- $block->setEntityId('{{entity_id}}');
132
- $this->setChild('attribute-template', $block);
133
-
134
- $this->setChild('menu-selector', Mage::app()->getLayout()->createBlock('modulecreator/adminhtml_modulecreator_menu'));
135
- return $this;
136
- }
137
-
138
- /**
139
- * get the back button html
140
- * @access public
141
- * @return string
142
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
143
- */
144
- public function getBackButtonHtml() {
145
- return $this->getChildHtml('back_button');
146
- }
147
- /**
148
- * get the cancel button html
149
- * @access public
150
- * @return string
151
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
152
- */
153
- public function getCancelButtonHtml() {
154
- return $this->getChildHtml('reset_button');
155
- }
156
- /**
157
- * get the save button html
158
- * @access public
159
- * @return string
160
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
161
- */
162
- public function getSaveButtonHtml() {
163
- return $this->getChildHtml('save_button');
164
- }
165
- /**
166
- * get the save and continue edit button html
167
- * @access public
168
- * @return string
169
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
170
- */
171
- public function getSaveAndEditButtonHtml() {
172
- return $this->getChildHtml('save_and_edit_button');
173
- }
174
- /**
175
- * get html for "add entity" button
176
- * @access public
177
- * @return string
178
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
179
- */
180
- public function getAddEntityButtonHtml() {
181
- return $this->getChildHtml('add-entity');
182
- }
183
-
184
- /**
185
- * get the save and continue edit url
186
- * @access public
187
- * @return string
188
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
189
- */
190
- public function getSaveAndContinueUrl() {
191
- return $this->getUrl('*/*/save', array(
192
- '_current' => true,
193
- 'back' => 'edit',
194
- 'tab'=> '{{tab_id}}',
195
- 'active_tab' => null
196
- ));
197
- }
198
- /**
199
- * get the validation url
200
- * @access public
201
- * @return string
202
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
203
- */
204
- public function getValidationUrl() {
205
- return $this->getUrl('*/*/validate', array('_current'=>true));
206
- }
207
- /**
208
- * check if edit mode is read only
209
- * @access public
210
- * @return bool
211
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
212
- */
213
- public function isReadonly() {
214
- $module = $this->getModule();
215
- if (!$module) {
216
- return false;
217
- }
218
- if (Mage::registry('module_read_only')) {
219
- return true;
220
- }
221
- if ($module = Mage::registry('current_module')) {
222
- $installedModules = array_keys((array)Mage::getConfig()->getNode('modules')->children());
223
- foreach ($installedModules as $installed){
224
- if ($installed == $module->getExtensionName()){
225
- Mage::register('module_read_only', true);
226
- return true;
227
- }
228
- }
229
- }
230
- return false;
231
- }
232
-
233
- /**
234
- * get select for relations
235
- * @access public
236
- * @return string
237
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
238
- */
239
- public function getRelationSelectTemplate() {
240
- /** @var Ultimate_ModuleCreator_Helper_Data $helper */
241
- $helper = Mage::helper('modulecreator');
242
- $types = $helper->getRelationTypes();
243
- $template = '<select class="relation-select" name="relation[#{e1}][#{e2}]" id="relation_#{e1}_#{e2}">';
244
- foreach ($types as $type=>$values){
245
- $template .= '<option value="'.$type.'">'.(string)$values->label.'</option>';
246
- }
247
- $template .= '</select>';
248
- return $template;
249
- }
250
-
251
- /**
252
- * check if fieldsets should be collapsed
253
- * @access public
254
- * @return int
255
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
256
- */
257
- public function getShowFieldsetsCollapsed(){
258
- return (int)Mage::getStoreConfigFlag(self::XML_FIELDSET_COLLAPSED);
259
- }
260
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
+ */
18
+ /**
19
+ * module edit block
20
+ *
21
+ * @category Ultimate
22
+ * @package Ultimate_ModuleCreator
23
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
+ */
25
+ class Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
26
+ {
27
+ /**
28
+ * config path to expanded/collapsed fieldsets
29
+ */
30
+ const XML_FIELDSET_COLLAPSED = 'modulecreator/general/collapsed';
31
+
32
+ /**
33
+ * construct
34
+ *
35
+ * @access public
36
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
37
+ */
38
+ public function __construct()
39
+ {
40
+ parent::__construct();
41
+ $this->_blockGroup = 'adminhtml_modulecreator';
42
+ $this->_controller = 'modulecreator';
43
+ $this->setTemplate('ultimate_modulecreator/edit.phtml');
44
+ }
45
+
46
+ /**
47
+ * get current module
48
+ *
49
+ * @access public
50
+ * @return mixed
51
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
52
+ */
53
+ public function getModule()
54
+ {
55
+ return Mage::registry('current_module');
56
+ }
57
+
58
+ /**
59
+ * get header text
60
+ *
61
+ * @access public
62
+ * @return string
63
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
64
+ */
65
+ public function getHeaderText()
66
+ {
67
+ $module = $this->getModule();
68
+ if ($module) {
69
+ return Mage::helper('modulecreator')->__('Edit module "%s"', $module->getExtensionName());
70
+ }
71
+ return Mage::helper('modulecreator')->__('Create Module');
72
+ }
73
+
74
+ /**
75
+ * prepare the layout
76
+ *
77
+ * @access protected
78
+ * @return Ultimate_ModuleCreator_Block_Adminhtml_ModuleCreator_Edit
79
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
80
+ */
81
+ protected function _prepareLayout()
82
+ {
83
+ /** @var Mage_Adminhtml_Block_Widget_Button $backButton */
84
+ $backButton = $this->getLayout()
85
+ ->createBlock('adminhtml/widget_button')
86
+ ->setData(
87
+ array(
88
+ 'label' => Mage::helper('modulecreator')->__('Back'),
89
+ 'onclick' => 'setLocation(\''.$this->getUrl('*/*/').'\')',
90
+ 'class' => 'back'
91
+ )
92
+ );
93
+ $this->setChild('back_button', $backButton);
94
+
95
+ /** @var Mage_Adminhtml_Block_Widget_Button $resetButton */
96
+ $resetButton = $this->getLayout()
97
+ ->createBlock('adminhtml/widget_button')
98
+ ->setData(
99
+ array(
100
+ 'label' => Mage::helper('modulecreator')->__('Reset'),
101
+ 'onclick' => 'setLocation(\''.$this->getUrl('*/*/*', array('_current'=>true)).'\')'
102
+ )
103
+ );
104
+ $this->setChild('reset_button', $resetButton);
105
+
106
+ /** @var Mage_Adminhtml_Block_Widget_Button $saveButton */
107
+ $saveButton = $this->getLayout()
108
+ ->createBlock('adminhtml/widget_button')
109
+ ->setData(
110
+ array(
111
+ 'label' => Mage::helper('modulecreator')->__('Save'),
112
+ 'onclick' => 'moduleForm.submit()',
113
+ 'class' => 'save'
114
+ )
115
+ );
116
+ $this->setChild('save_button', $saveButton);
117
+
118
+ /** @var Mage_Adminhtml_Block_Widget_Button $saveEditButton */
119
+ $saveEditButton = $this->getLayout()
120
+ ->createBlock('adminhtml/widget_button')
121
+ ->setData(
122
+ array(
123
+ 'label' => Mage::helper('modulecreator')->__('Save and Continue Edit'),
124
+ 'onclick' => 'saveAndContinueEdit(\''.$this->getSaveAndContinueUrl().'\')',
125
+ 'class' => 'save'
126
+ )
127
+ );
128
+ $this->setChild('save_and_edit_button', $saveEditButton);
129
+
130
+ /** @var Mage_Adminhtml_Block_Widget_Button $addEntityButton */
131
+ $addEntityButton = $this->getLayout()
132
+ ->createBlock('adminhtml/widget_button')
133
+ ->setData(
134
+ array(
135
+ 'label' => Mage::helper('modulecreator')->__('Add entity'),
136
+ 'class' => 'add add-entity'
137
+ )
138
+ );
139
+ $this->setChild('add-entity', $addEntityButton);
140
+
141
+ /** @var Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Tab_Entities_Entity $block */
142
+ $block = Mage::app()->getLayout()
143
+ ->createBlock('modulecreator/adminhtml_modulecreator_edit_tab_entities_entity');
144
+ $block->setTemplate('ultimate_modulecreator/edit/tab/entities/entity.phtml');
145
+ $block->setDefaultEntity();
146
+ $block->setIncrement('{{entity_id}}');
147
+ $this->setChild('entity-template', $block);
148
+
149
+ /** @var Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Tab_Entities_Entity_Attribute $block */
150
+ $block = Mage::app()->getLayout()
151
+ ->createBlock('modulecreator/adminhtml_modulecreator_edit_tab_entities_entity_attribute');
152
+ $block->setTemplate('ultimate_modulecreator/edit/tab/entities/entity/attribute.phtml');
153
+ $block->setDefaultAttributeInstance();
154
+ $block->setIncrement('{{attribute_id}}');
155
+ $block->setEntityId('{{entity_id}}');
156
+ $this->setChild('attribute-template', $block);
157
+
158
+ $this->setChild(
159
+ 'menu-selector',
160
+ Mage::app()->getLayout()->createBlock('modulecreator/adminhtml_modulecreator_menu')
161
+ );
162
+ return $this;
163
+ }
164
+
165
+ /**
166
+ * get the back button html
167
+ *
168
+ * @access public
169
+ * @return string
170
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
171
+ */
172
+ public function getBackButtonHtml()
173
+ {
174
+ return $this->getChildHtml('back_button');
175
+ }
176
+
177
+ /**
178
+ * get the cancel button html
179
+ *
180
+ * @access public
181
+ * @return string
182
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
183
+ */
184
+ public function getCancelButtonHtml()
185
+ {
186
+ return $this->getChildHtml('reset_button');
187
+ }
188
+
189
+ /**
190
+ * get the save button html
191
+ *
192
+ * @access public
193
+ * @return string
194
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
195
+ */
196
+ public function getSaveButtonHtml()
197
+ {
198
+ return $this->getChildHtml('save_button');
199
+ }
200
+
201
+ /**
202
+ * get the save and continue edit button html
203
+ *
204
+ * @access public
205
+ * @return string
206
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
207
+ */
208
+ public function getSaveAndEditButtonHtml()
209
+ {
210
+ return $this->getChildHtml('save_and_edit_button');
211
+ }
212
+
213
+ /**
214
+ * get html for "add entity" button
215
+ *
216
+ * @access public
217
+ * @return string
218
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
219
+ */
220
+ public function getAddEntityButtonHtml()
221
+ {
222
+ return $this->getChildHtml('add-entity');
223
+ }
224
+
225
+ /**
226
+ * get the save and continue edit url
227
+ *
228
+ * @access public
229
+ * @return string
230
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
231
+ */
232
+ public function getSaveAndContinueUrl()
233
+ {
234
+ return $this->getUrl(
235
+ '*/*/save',
236
+ array(
237
+ '_current' => true,
238
+ 'back' => 'edit',
239
+ 'tab'=> '{{tab_id}}',
240
+ 'active_tab' => null
241
+ )
242
+ );
243
+ }
244
+
245
+ /**
246
+ * get the validation url
247
+ *
248
+ * @access public
249
+ * @return string
250
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
251
+ */
252
+ public function getValidationUrl()
253
+ {
254
+ return $this->getUrl('*/*/validate', array('_current'=>true));
255
+ }
256
+
257
+ /**
258
+ * check if edit mode is read only
259
+ *
260
+ * @access public
261
+ * @return bool
262
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
263
+ */
264
+ public function isReadonly()
265
+ {
266
+ $module = $this->getModule();
267
+ if (!$module) {
268
+ return false;
269
+ }
270
+ if (Mage::registry('module_read_only')) {
271
+ return true;
272
+ }
273
+ if ($module = Mage::registry('current_module')) {
274
+ $installedModules = array_keys((array)Mage::getConfig()->getNode('modules')->children());
275
+ foreach ($installedModules as $installed) {
276
+ if ($installed == $module->getExtensionName()) {
277
+ Mage::register('module_read_only', true);
278
+ return true;
279
+ }
280
+ }
281
+ }
282
+ return false;
283
+ }
284
+
285
+ /**
286
+ * get select for relations
287
+ *
288
+ * @access public
289
+ * @return string
290
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
291
+ */
292
+ public function getRelationSelectTemplate()
293
+ {
294
+ /** @var Ultimate_ModuleCreator_Helper_Data $helper */
295
+ $helper = Mage::helper('modulecreator');
296
+ $types = $helper->getRelationTypes();
297
+ $template = '<select class="relation-select" name="relation[#{e1}][#{e2}]" id="relation_#{e1}_#{e2}">';
298
+ foreach ($types as $type=>$values) {
299
+ $template .= '<option value="'.$type.'">'.(string)$values->label.'</option>';
300
+ }
301
+ $template .= '</select>';
302
+ return $template;
303
+ }
304
+
305
+ /**
306
+ * check if fieldsets should be collapsed
307
+ *
308
+ * @access public
309
+ * @return int
310
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
311
+ */
312
+ public function getShowFieldsetsCollapsed()
313
+ {
314
+ return (int)Mage::getStoreConfigFlag(self::XML_FIELDSET_COLLAPSED);
315
+ }
316
+ }
app/code/community/Ultimate/ModuleCreator/Block/Adminhtml/Modulecreator/Edit/Form.php CHANGED
@@ -1,42 +1,51 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- */
17
- /**
18
- * admin form block
19
- *
20
- * @category Ultimate
21
- * @package Ultimate_ModuleCreator
22
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
23
- */
24
- class Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Form
25
- extends Mage_Adminhtml_Block_Widget_Form {
26
- /**
27
- * prepare form
28
- * @access protected
29
- * @return Ultimate_ModuleCreator_Block_Adminhtml_ModuleCreator_Edit_Form
30
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
31
- */
32
- protected function _prepareForm() {
33
- $form = new Varien_Data_Form(array(
34
- 'id' => 'edit_form',
35
- 'action' => $this->getUrl('*/modulecreator/save', array('id' => $this->getRequest()->getParam('id'))),
36
- 'method' => 'post'
37
- ));
38
- $form->setUseContainer(true);
39
- $this->setForm($form);
40
- return parent::_prepareForm();
41
- }
42
- }
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ */
17
+ /**
18
+ * admin form block
19
+ *
20
+ * @category Ultimate
21
+ * @package Ultimate_ModuleCreator
22
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
23
+ */
24
+ class Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
25
+ {
26
+ /**
27
+ * prepare form
28
+ *
29
+ * @access protected
30
+ * @return Ultimate_ModuleCreator_Block_Adminhtml_ModuleCreator_Edit_Form
31
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
32
+ */
33
+ protected function _prepareForm()
34
+ {
35
+ $form = new Varien_Data_Form(
36
+ array(
37
+ 'id' => 'edit_form',
38
+ 'action' => $this->getUrl(
39
+ '*/modulecreator/save',
40
+ array(
41
+ 'id' => $this->getRequest()->getParam('id')
42
+ )
43
+ ),
44
+ 'method' => 'post'
45
+ )
46
+ );
47
+ $form->setUseContainer(true);
48
+ $this->setForm($form);
49
+ return parent::_prepareForm();
50
+ }
51
+ }
app/code/community/Ultimate/ModuleCreator/Block/Adminhtml/Modulecreator/Edit/Tab/Entities.php CHANGED
@@ -1,90 +1,105 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
- */
18
- /**
19
- * entities tab
20
- *
21
- * @category Ultimate
22
- * @package Ultimate_ModuleCreator
23
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
- */
25
- class Ultimate_ModuleCreator_Block_Adminhtml_ModuleCreator_Edit_Tab_Entities
26
- extends Mage_Adminhtml_Block_Widget
27
- implements Mage_Adminhtml_Block_Widget_Tab_Interface {
28
- /**
29
- * constructor
30
- * @access public
31
- * @return void
32
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
33
- */
34
- public function _construct() {
35
- parent::_construct();
36
- $this->setTemplate('ultimate_modulecreator/edit/tab/entities.phtml');
37
- }
38
- /**
39
- * Return Tab label
40
- * @access public
41
- * @return string
42
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
43
- */
44
- public function getTabLabel() {
45
- return Mage::helper('modulecreator')->__('Entities');
46
- }
47
- /**
48
- * Return Tab title
49
- * @access public
50
- * @return string
51
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
52
- */
53
- public function getTabTitle() {
54
- return Mage::helper('modulecreator')->__('Entities');
55
- }
56
- /**
57
- * Can show tab in tabs
58
- * @access public
59
- * @return boolean
60
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
61
- */
62
- public function canShowTab() {
63
- return true;
64
- }
65
-
66
- /**
67
- * Tab is hidden
68
- * @access public
69
- * @return boolean
70
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
71
- */
72
- public function isHidden() {
73
- return false;
74
- }
75
-
76
- /**
77
- * get the list of entities
78
- * @access public
79
- * @return array()
80
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
81
- */
82
- public function getEntities() {
83
- /** @var null|Ultimate_ModuleCreator_Model_Module $module */
84
- $module = Mage::registry('current_module');
85
- if ($module) {
86
- return $module->getEntities();
87
- }
88
- return array();
89
- }
90
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
+ */
18
+ /**
19
+ * entities tab
20
+ *
21
+ * @category Ultimate
22
+ * @package Ultimate_ModuleCreator
23
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
+ */
25
+ class Ultimate_ModuleCreator_Block_Adminhtml_ModuleCreator_Edit_Tab_Entities extends Mage_Adminhtml_Block_Widget implements
26
+ Mage_Adminhtml_Block_Widget_Tab_Interface
27
+ {
28
+ /**
29
+ * constructor
30
+ *
31
+ * @access public
32
+ * @return void
33
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
34
+ */
35
+ public function _construct()
36
+ {
37
+ parent::_construct();
38
+ $this->setTemplate('ultimate_modulecreator/edit/tab/entities.phtml');
39
+ }
40
+
41
+ /**
42
+ * Return Tab label
43
+ *
44
+ * @access public
45
+ * @return string
46
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
47
+ */
48
+ public function getTabLabel()
49
+ {
50
+ return Mage::helper('modulecreator')->__('Entities');
51
+ }
52
+
53
+ /**
54
+ * Return Tab title
55
+ *
56
+ * @access public
57
+ * @return string
58
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
59
+ */
60
+ public function getTabTitle()
61
+ {
62
+ return Mage::helper('modulecreator')->__('Entities');
63
+ }
64
+
65
+ /**
66
+ * Can show tab in tabs
67
+ *
68
+ * @access public
69
+ * @return boolean
70
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
71
+ */
72
+ public function canShowTab()
73
+ {
74
+ return true;
75
+ }
76
+
77
+ /**
78
+ * Tab is hidden
79
+ *
80
+ * @access public
81
+ * @return boolean
82
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
83
+ */
84
+ public function isHidden()
85
+ {
86
+ return false;
87
+ }
88
+
89
+ /**
90
+ * get the list of entities
91
+ *
92
+ * @access public
93
+ * @return array()
94
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
95
+ */
96
+ public function getEntities()
97
+ {
98
+ /** @var null|Ultimate_ModuleCreator_Model_Module $module */
99
+ $module = Mage::registry('current_module');
100
+ if ($module) {
101
+ return $module->getEntities();
102
+ }
103
+ return array();
104
+ }
105
+ }
app/code/community/Ultimate/ModuleCreator/Block/Adminhtml/Modulecreator/Edit/Tab/Entities/Entity.php CHANGED
@@ -1,64 +1,68 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
- */
18
- /**
19
- * add entity form
20
- *
21
- * @category Ultimate
22
- * @package Ultimate_ModuleCreator
23
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
- */
25
- /**
26
- * @method Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Tab_Entities_Entity setEntity()
27
- * @method Varien_Object getEntity()
28
- * @method Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Tab_Entities_Entity setIncrement()
29
- * @method int getIncrement()
30
- */
31
- class Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Tab_Entities_Entity
32
- extends Mage_Adminhtml_Block_Widget_Form {
33
- /**
34
- * prepare entity form
35
- * @access protected
36
- * @return string
37
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
38
- */
39
- protected function _prepareForm() {
40
- /** @var Ultimate_ModuleCreator_Helper_Data $helper */
41
- $helper = Mage::helper('modulecreator');
42
- $form = $helper->getXmlForm('entity');
43
- $form->setHtmlIdPrefix('entity_'.$this->getIncrement().'_');
44
- $form->addFieldNameSuffix('entity['.$this->getIncrement().']');
45
- $this->setForm($form);
46
- $form->addValues($this->getEntity()->getData());
47
- return parent::_prepareForm();
48
- }
49
-
50
- /**
51
- * set an entity with default values
52
- * @access public
53
- * @return Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Tab_Entities_Entity
54
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
55
- */
56
- public function setDefaultEntity() {
57
- /** @var Ultimate_ModuleCreator_Model_Entity $entity */
58
- $entity = Mage::getModel('modulecreator/entity');
59
- $settings = Mage::getStoreConfig(Ultimate_ModuleCreator_Helper_Data::XML_ENTITY_CONFIG_PATH);
60
- $entity->addData($settings);
61
- $this->setEntity($entity);
62
- return $this;
63
- }
64
- }
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
+ */
18
+ /**
19
+ * add entity form
20
+ *
21
+ * @category Ultimate
22
+ * @package Ultimate_ModuleCreator
23
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
+ */
25
+ /**
26
+ * @method Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Tab_Entities_Entity setEntity()
27
+ * @method Varien_Object getEntity()
28
+ * @method Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Tab_Entities_Entity setIncrement()
29
+ * @method int getIncrement()
30
+ */
31
+ class Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Tab_Entities_Entity extends Mage_Adminhtml_Block_Widget_Form
32
+ {
33
+ /**
34
+ * prepare entity form
35
+ *
36
+ * @access protected
37
+ * @return string
38
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
39
+ */
40
+ protected function _prepareForm()
41
+ {
42
+ /** @var Ultimate_ModuleCreator_Helper_Data $helper */
43
+ $helper = Mage::helper('modulecreator');
44
+ $form = $helper->getXmlForm('entity');
45
+ $form->setHtmlIdPrefix('entity_'.$this->getIncrement().'_');
46
+ $form->addFieldNameSuffix('entity['.$this->getIncrement().']');
47
+ $this->setForm($form);
48
+ $form->addValues($this->getEntity()->getData());
49
+ return parent::_prepareForm();
50
+ }
51
+
52
+ /**
53
+ * set an entity with default values
54
+ *
55
+ * @access public
56
+ * @return Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Tab_Entities_Entity
57
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
58
+ */
59
+ public function setDefaultEntity()
60
+ {
61
+ /** @var Ultimate_ModuleCreator_Model_Entity $entity */
62
+ $entity = Mage::getModel('modulecreator/entity');
63
+ $settings = Mage::getStoreConfig(Ultimate_ModuleCreator_Helper_Data::XML_ENTITY_CONFIG_PATH);
64
+ $entity->addData($settings);
65
+ $this->setEntity($entity);
66
+ return $this;
67
+ }
68
+ }
app/code/community/Ultimate/ModuleCreator/Block/Adminhtml/Modulecreator/Edit/Tab/Entities/Entity/Attribute.php CHANGED
@@ -1,66 +1,70 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
- */
18
- /**
19
- * add attribute form
20
- *
21
- * @category Ultimate
22
- * @package Ultimate_ModuleCreator
23
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
- */
25
- /**
26
- * @method Varien_Object getAttributeInstance()
27
- * @method Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Tab_Entities_Entity_Attribute setAttributeInstance()
28
- * @method string getEntityId()
29
- * @method Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Tab_Entities_Entity_Attribute setIncrement()
30
- * @method int getIncrement()
31
- * @method Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Tab_Entities_Entity_Attribute setEntityId()
32
- */
33
- class Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Tab_Entities_Entity_Attribute
34
- extends Mage_Adminhtml_Block_Widget_Form {
35
- /**
36
- * prepare attribute form
37
- * @access protected
38
- * @return string
39
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
40
- */
41
- protected function _prepareForm() {
42
- /** @var Ultimate_ModuleCreator_Helper_Data $helper */
43
- $helper = Mage::helper('modulecreator');
44
- $form = $helper->getXmlForm('attribute', false);
45
- $form->setHtmlIdPrefix('attribute_'.$this->getEntityId().'_'.$this->getIncrement().'_');
46
- $form->addFieldNameSuffix('entity['.$this->getEntityId().'][attributes]['.$this->getIncrement().']');
47
- $this->setForm($form);
48
- $form->addValues($this->getAttributeInstance()->getData());
49
- return parent::_prepareForm();
50
- }
51
-
52
- /**
53
- * set an entity with default values
54
- * @access public
55
- * @return Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Tab_Entities_Entity
56
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
57
- */
58
- public function setDefaultAttributeInstance() {
59
- /** @var Ultimate_ModuleCreator_Model_Attribute $attribute */
60
- $attribute = Mage::getModel('modulecreator/attribute');
61
- $settings = Mage::getStoreConfig(Ultimate_ModuleCreator_Helper_Data::XML_ATTRIBUTE_CONFIG_PATH);
62
- $attribute->addData($settings);
63
- $this->setAttributeInstance($attribute);
64
- return $this;
65
- }
66
- }
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
+ */
18
+ /**
19
+ * add attribute form
20
+ *
21
+ * @category Ultimate
22
+ * @package Ultimate_ModuleCreator
23
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
+ */
25
+ /**
26
+ * @method Varien_Object getAttributeInstance()
27
+ * @method Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Tab_Entities_Entity_Attribute setAttributeInstance()
28
+ * @method string getEntityId()
29
+ * @method Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Tab_Entities_Entity_Attribute setIncrement()
30
+ * @method int getIncrement()
31
+ * @method Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Tab_Entities_Entity_Attribute setEntityId()
32
+ */
33
+ class Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Tab_Entities_Entity_Attribute extends Mage_Adminhtml_Block_Widget_Form
34
+ {
35
+ /**
36
+ * prepare attribute form
37
+ *
38
+ * @access protected
39
+ * @return string
40
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
41
+ */
42
+ protected function _prepareForm()
43
+ {
44
+ /** @var Ultimate_ModuleCreator_Helper_Data $helper */
45
+ $helper = Mage::helper('modulecreator');
46
+ $form = $helper->getXmlForm('attribute', false);
47
+ $form->setHtmlIdPrefix('attribute_'.$this->getEntityId().'_'.$this->getIncrement().'_');
48
+ $form->addFieldNameSuffix('entity['.$this->getEntityId().'][attributes]['.$this->getIncrement().']');
49
+ $this->setForm($form);
50
+ $form->addValues($this->getAttributeInstance()->getData());
51
+ return parent::_prepareForm();
52
+ }
53
+
54
+ /**
55
+ * set an entity with default values
56
+ *
57
+ * @access public
58
+ * @return Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Tab_Entities_Entity
59
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
60
+ */
61
+ public function setDefaultAttributeInstance()
62
+ {
63
+ /** @var Ultimate_ModuleCreator_Model_Attribute $attribute */
64
+ $attribute = Mage::getModel('modulecreator/attribute');
65
+ $settings = Mage::getStoreConfig(Ultimate_ModuleCreator_Helper_Data::XML_ATTRIBUTE_CONFIG_PATH);
66
+ $attribute->addData($settings);
67
+ $this->setAttributeInstance($attribute);
68
+ return $this;
69
+ }
70
+ }
app/code/community/Ultimate/ModuleCreator/Block/Adminhtml/Modulecreator/Edit/Tab/Help.php CHANGED
@@ -1,314 +1,367 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- */
17
- /**
18
- * help tab block
19
- *
20
- * @category Ultimate
21
- * @package Ultimate_ModuleCreator
22
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
23
- */
24
- class Ultimate_ModuleCreator_Block_Adminhtml_ModuleCreator_Edit_Tab_Help
25
- extends Mage_Adminhtml_Block_Widget_Form
26
- implements Mage_Adminhtml_Block_Widget_Tab_Interface {
27
- /**
28
- * constructor
29
- * @access public
30
- * @return void
31
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
32
- */
33
- public function _construct() {
34
- parent::_construct();
35
- $this->setTemplate('ultimate_modulecreator/edit/tab/help.phtml');
36
- }
37
- /**
38
- * Return Tab label
39
- * @access public
40
- * @return string
41
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
42
- */
43
- public function getTabLabel() {
44
- return Mage::helper('modulecreator')->__('Help');
45
- }
46
- /**
47
- * Return Tab title
48
- * @access public
49
- * @return string
50
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
51
- */
52
- public function getTabTitle() {
53
- return Mage::helper('modulecreator')->__('Help');
54
- }
55
- /**
56
- * Can show tab in tabs
57
- * @access public
58
- * @return boolean
59
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
60
- */
61
- public function canShowTab() {
62
- return true;
63
- }
64
-
65
- /**
66
- * Tab is hidden
67
- * @access public
68
- * @return boolean
69
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
70
- */
71
- public function isHidden() {
72
- return false;
73
- }
74
- /**
75
- * get UMC version
76
- * @access public
77
- * @return string
78
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
79
- */
80
- public function getVersion(){
81
- $version = (string)Mage::app()->getConfig()->getNode('modules/Ultimate_ModuleCreator/version');
82
- $build = (string)Mage::app()->getConfig()->getNode('modules/Ultimate_ModuleCreator/build');
83
- if ($build){
84
- $version .= ' - '.$build;
85
- }
86
- return $version;
87
- }
88
- /**
89
- * prepare tab layout
90
- * @return Mage_Core_Block_Abstract
91
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
92
- */
93
- protected function _prepareLayout() {
94
- /** @var Ultimate_ModuleCreator_Helper_Data $helper */
95
- $helper = Mage::helper('modulecreator');
96
-
97
- $columns = array(
98
- 'label' => array(
99
- 'header'=>Mage::helper('modulecreator')->__('Field'),
100
- 'key' =>'label'
101
- ),
102
- 'type' => array(
103
- 'header'=>Mage::helper('modulecreator')->__('Type'),
104
- 'key' =>'type'
105
- ),
106
- 'required' => array(
107
- 'header'=>Mage::helper('modulecreator')->__('Required'),
108
- 'type' => 'bool',
109
- 'key' =>'required'
110
- ),
111
- 'system' => array(
112
- 'header'=>Mage::helper('modulecreator')->__('Has default'),
113
- 'type' => 'bool',
114
- 'key' =>'system'
115
- ),
116
- 'tooltip' => array(
117
- 'header'=>Mage::helper('modulecreator')->__('Description'),
118
- 'key' =>'tooltip'
119
- ),
120
- );
121
- /** @var Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Tab_Help_Fieldset $settingsTabHelp */
122
- $settingsTabHelp = $this->getLayout()->createBlock('modulecreator/adminhtml_modulecreator_edit_tab_help_fieldset');
123
- $settingsTabHelp->setFieldsets($helper->getFieldsetXmlData('settings'))
124
- ->setColumns($columns)
125
- ->setDescription(Mage::helper('modulecreator')->__('General settings tab.'));
126
-
127
- /** @var Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Tab_Help_Fieldset $entityTabHelp */
128
- $entityTabHelp = $this->getLayout()->createBlock('modulecreator/adminhtml_modulecreator_edit_tab_help_fieldset');
129
- $entityTabHelp->setFieldsets($helper->getFieldsetXmlData('entity'))
130
- ->setColumns($columns)
131
- ->setDescription(Mage::helper('modulecreator')->__('Entity management.'));
132
-
133
- /** @var Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Tab_Help_Fieldset $attributeTabHelp */
134
- $attributeTabHelp = $this->getLayout()->createBlock('modulecreator/adminhtml_modulecreator_edit_tab_help_fieldset');
135
- $attributeTabHelp->setFieldsets($helper->getFieldsetXmlData('attribute'))
136
- ->setColumns($columns)
137
- ->setDescription(Mage::helper('modulecreator')->__('Field/Attribute management.'));
138
-
139
- $fieldTypes = array(
140
- 'field_types'=> array(
141
- 'label' => Mage::helper('modulecreator')->__('Supported field / attribute types'),
142
- 'fields' => $helper->getAttributeTypes())
143
- );
144
-
145
- /** @var Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Tab_Help_Fieldset $fieldTypesHelp */
146
- $fieldTypesHelp = $this->getLayout()->createBlock('modulecreator/adminhtml_modulecreator_edit_tab_help_fieldset');
147
- $fieldTypesHelp->setFieldsets($fieldTypes)
148
- ->setColumns(array(
149
- 'label' => array(
150
- 'header'=>Mage::helper('modulecreator')->__('Field'),
151
- 'key' =>'label'
152
- ),
153
- 'allow_is_name' => array(
154
- 'header'=>Mage::helper('modulecreator')->__('Can behave as name'),
155
- 'key' =>'allow_is_name',
156
- 'type' => 'bool'
157
- ),
158
- ))
159
- ->setDescription(Mage::helper('modulecreator')->__('Supported field / attribute types'));
160
- $relationTypes = array(
161
- 'field_types'=> array(
162
- 'label'=> Mage::helper('modulecreator')->__('Relation types'),
163
- 'fields' => $helper->getRelationTypes()
164
- ));
165
-
166
- /** @var Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Tab_Help_Fieldset $relationsTypesHelp */
167
- $relationsTypesHelp = $this->getLayout()->createBlock('modulecreator/adminhtml_modulecreator_edit_tab_help_fieldset');
168
- $relationsTypesHelp->setFieldsets($relationTypes)
169
- ->setColumns(array(
170
- 'label' => array(
171
- 'header'=>Mage::helper('modulecreator')->__('Relation'),
172
- 'key' =>'label'
173
- ),
174
- 'description' => array(
175
- 'header'=>Mage::helper('modulecreator')->__('Description'),
176
- 'key' =>'description',
177
- ),
178
- ))
179
- ->setDescription(Mage::helper('modulecreator')->__('Entity Relations'));
180
-
181
- $objN = new stdClass();
182
- $objN->restricted = 'Mage';
183
- $objN->label = Mage::helper('modulecreator')->__('Disallowed namespace names');
184
-
185
- $routers = (array)Mage::getConfig()->getNode('frontend/routers');
186
- $objM = new stdClass();
187
- $objM->restricted = implode(', ',array_keys($routers));
188
- $objM->label = Mage::helper('modulecreator')->__('Disallowed module names');
189
-
190
- $entityRestrictedNames = implode(', ',array_keys((array)$helper->getConfig()->getNode('restricted/entity')));
191
- $objE = new stdClass();
192
- $objE->restricted = $entityRestrictedNames;
193
- $objE->label = Mage::helper('modulecreator')->__('Disallowed entity names');
194
-
195
- $attributeRestrictedNames = implode(', ',array_keys((array)$helper->getConfig()->getNode('restricted/attribute')));
196
- $objA = new stdClass();
197
- $objA->restricted = $attributeRestrictedNames;
198
- $objA->label = Mage::helper('modulecreator')->__('Disallowed field/attribute names');
199
- $restrictions = array(
200
- 'field_types'=> array(
201
- 'label' => Mage::helper('modulecreator')->__('Naming restrictions'),
202
- 'fields' => array($objN, $objM, $objE, $objA))
203
- );
204
-
205
- /** @var Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Tab_Help_Fieldset $restrictionsHelp */
206
- $restrictionsHelp = $this->getLayout()->createBlock('modulecreator/adminhtml_modulecreator_edit_tab_help_fieldset');
207
- $restrictionsHelp->setFieldsets($restrictions)
208
- ->setColumns(array(
209
- 'label' => array(
210
- 'header'=>Mage::helper('modulecreator')->__('Entity'),
211
- 'key' =>'label'
212
- ),
213
- 'description' => array(
214
- 'header'=>Mage::helper('modulecreator')->__('Resticted'),
215
- 'key' =>'restricted',
216
- ),
217
- ))
218
- ->setDescription(Mage::helper('modulecreator')->__('Naming restrictions'));
219
- /** @var null|Ultimate_ModuleCreator_Model_Module $currentModule */
220
- $currentModule = Mage::registry('current_module');
221
- if (!$currentModule){
222
- /** @var Ultimate_ModuleCreator_Model_Module $currentModule */
223
- $currentModule = Mage::getModel('modulecreator/module');
224
- }
225
- $files = $currentModule->getConfig()->getNode('files');
226
- $allowedFiles = array();
227
- foreach ((array)$files as $file){
228
- if ($file->scope == 'disabled'){
229
- continue;
230
- }
231
- $allowedFiles[] = $file;
232
- }
233
-
234
- /** @var Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Tab_Help_Fieldset $filesHelp */
235
- $filesHelp = $this->getLayout()->createBlock('modulecreator/adminhtml_modulecreator_edit_tab_help_fieldset');
236
- $filesHelp->setFieldsets(array(
237
- 'files'=> array(
238
- 'label'=>Mage::helper('modulecreator')->__('Generated files'),
239
- 'fields' => $allowedFiles)
240
- ))
241
- ->setColumns(array(
242
- 'label' => array(
243
- 'header'=>Mage::helper('modulecreator')->__('File'),
244
- 'key' =>'title'
245
- ),
246
- 'destination'=> array(
247
- 'header'=>Mage::helper('modulecreator')->__('Path'),
248
- 'key' =>'destination'
249
- ),
250
- 'description' => array(
251
- 'header'=>Mage::helper('modulecreator')->__('Description'),
252
- 'key' =>'description',
253
- ),
254
- 'condition' => array(
255
- 'header'=>Mage::helper('modulecreator')->__('Condition'),
256
- 'key' =>'condition',
257
- ),
258
- ))
259
- ->setDescription(Mage::helper('modulecreator')->__('Created files'));
260
-
261
- $this->setChild('settings_tab_help', $settingsTabHelp);
262
- $this->setChild('entity_tab_help', $entityTabHelp);
263
- $this->setChild('attribute_tab_help', $attributeTabHelp);
264
- $this->setChild('attribute_types_help', $fieldTypesHelp);
265
- $this->setChild('relation_types_help', $relationsTypesHelp);
266
- $this->setChild('restrictions_help', $restrictionsHelp);
267
- $this->setChild('files_help', $filesHelp);
268
-
269
- $releaseNotes = (array)$helper->getReleaseNotes();
270
-
271
- /** @var Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Tab_Help_Fieldset $releaseNotesHelp */
272
- $releaseNotesHelp = $this->getLayout()->createBlock('modulecreator/adminhtml_modulecreator_edit_tab_help_fieldset');
273
- $releaseNotesHelp->setFieldsets($releaseNotes)
274
- ->setColumns(array(
275
- 'type' => array(
276
- 'header'=>Mage::helper('modulecreator')->__('Type'),
277
- 'key' =>'type'
278
- ),
279
- 'label' => array(
280
- 'header'=>Mage::helper('modulecreator')->__('Label'),
281
- 'key' =>'label'
282
- ),
283
- 'comment' => array(
284
- 'header'=>Mage::helper('modulecreator')->__('Comment'),
285
- 'key' =>'comment'
286
- ),
287
- ))
288
- ->setDescription(Mage::helper('modulecreator')->__('Release notes'))
289
- ;
290
- $this->setChild('release_notes', $releaseNotesHelp);
291
-
292
- /** @var Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Tab_Help_Fieldset $thanks */
293
- $thanks = $this->getLayout()->createBlock('modulecreator/adminhtml_modulecreator_edit_tab_help_fieldset');
294
- $thanks->setFieldsets(array(
295
- 'files'=> array(
296
- 'label' =>Mage::helper('modulecreator')->__('Thanks'),
297
- 'fields' => (array)$helper->getThanks())
298
- ))
299
- ->setColumns(array(
300
- 'type' => array(
301
- 'header'=>Mage::helper('modulecreator')->__('To'),
302
- 'key' =>'to'
303
- ),
304
- 'label' => array(
305
- 'header'=>Mage::helper('modulecreator')->__('Because'),
306
- 'key' =>'for'
307
- ),
308
- )
309
- )
310
- ->setDescription(Mage::helper('modulecreator')->__('Thank you for your help'));
311
- $this->setChild('thanks', $thanks);
312
- return parent::_prepareLayout();
313
- }
314
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ */
17
+ /**
18
+ * help tab block
19
+ *
20
+ * @category Ultimate
21
+ * @package Ultimate_ModuleCreator
22
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
23
+ */
24
+ class Ultimate_ModuleCreator_Block_Adminhtml_ModuleCreator_Edit_Tab_Help extends Mage_Adminhtml_Block_Widget_Form implements
25
+ Mage_Adminhtml_Block_Widget_Tab_Interface
26
+ {
27
+ /**
28
+ * constructor
29
+ *
30
+ * @access public
31
+ * @return void
32
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
33
+ */
34
+ public function _construct()
35
+ {
36
+ parent::_construct();
37
+ $this->setTemplate('ultimate_modulecreator/edit/tab/help.phtml');
38
+ }
39
+
40
+ /**
41
+ * Return Tab label
42
+ *
43
+ * @access public
44
+ * @return string
45
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
46
+ */
47
+ public function getTabLabel()
48
+ {
49
+ return Mage::helper('modulecreator')->__('Help');
50
+ }
51
+
52
+ /**
53
+ * Return Tab title
54
+ *
55
+ * @access public
56
+ * @return string
57
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
58
+ */
59
+ public function getTabTitle()
60
+ {
61
+ return Mage::helper('modulecreator')->__('Help');
62
+ }
63
+
64
+ /**
65
+ * Can show tab in tabs
66
+ *
67
+ * @access public
68
+ * @return boolean
69
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
70
+ */
71
+ public function canShowTab()
72
+ {
73
+ return true;
74
+ }
75
+
76
+ /**
77
+ * Tab is hidden
78
+ *
79
+ * @access public
80
+ * @return boolean
81
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
82
+ */
83
+ public function isHidden()
84
+ {
85
+ return false;
86
+ }
87
+ /**
88
+ * get UMC version
89
+ *
90
+ * @access public
91
+ * @return string
92
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
93
+ */
94
+ public function getVersion()
95
+ {
96
+ $version = (string)Mage::app()->getConfig()->getNode('modules/Ultimate_ModuleCreator/version');
97
+ $build = (string)Mage::app()->getConfig()->getNode('modules/Ultimate_ModuleCreator/build');
98
+ if ($build) {
99
+ $version .= ' - '.$build;
100
+ }
101
+ return $version;
102
+ }
103
+
104
+ /**
105
+ * prepare tab layout
106
+ *
107
+ * @return Mage_Core_Block_Abstract
108
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
109
+ */
110
+ protected function _prepareLayout()
111
+ {
112
+ /** @var Ultimate_ModuleCreator_Helper_Data $helper */
113
+ $helper = Mage::helper('modulecreator');
114
+
115
+ $columns = array(
116
+ 'label' => array(
117
+ 'header' => Mage::helper('modulecreator')->__('Field'),
118
+ 'key' => 'label'
119
+ ),
120
+ 'type' => array(
121
+ 'header' => Mage::helper('modulecreator')->__('Type'),
122
+ 'key' => 'type'
123
+ ),
124
+ 'required' => array(
125
+ 'header' => Mage::helper('modulecreator')->__('Required'),
126
+ 'type' => 'bool',
127
+ 'key' => 'required'
128
+ ),
129
+ 'system' => array(
130
+ 'header' => Mage::helper('modulecreator')->__('Has default'),
131
+ 'type' => 'bool',
132
+ 'key' => 'system'
133
+ ),
134
+ 'tooltip' => array(
135
+ 'header' => Mage::helper('modulecreator')->__('Description'),
136
+ 'key' => 'tooltip'
137
+ ),
138
+ );
139
+ /** @var Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Tab_Help_Fieldset $settingsTabHelp */
140
+ $settingsTabHelp = $this->getLayout()
141
+ ->createBlock('modulecreator/adminhtml_modulecreator_edit_tab_help_fieldset');
142
+ $settingsTabHelp->setFieldsets($helper->getFieldsetXmlData('settings'))
143
+ ->setColumns($columns)
144
+ ->setDescription(Mage::helper('modulecreator')->__('General settings tab.'));
145
+
146
+ /** @var Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Tab_Help_Fieldset $entityTabHelp */
147
+ $entityTabHelp = $this->getLayout()
148
+ ->createBlock('modulecreator/adminhtml_modulecreator_edit_tab_help_fieldset');
149
+ $entityTabHelp->setFieldsets($helper->getFieldsetXmlData('entity'))
150
+ ->setColumns($columns)
151
+ ->setDescription(Mage::helper('modulecreator')->__('Entity management.'));
152
+
153
+ /** @var Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Tab_Help_Fieldset $attributeTabHelp */
154
+ $attributeTabHelp = $this->getLayout()
155
+ ->createBlock('modulecreator/adminhtml_modulecreator_edit_tab_help_fieldset');
156
+ $attributeTabHelp->setFieldsets($helper->getFieldsetXmlData('attribute'))
157
+ ->setColumns($columns)
158
+ ->setDescription(Mage::helper('modulecreator')->__('Field/Attribute management.'));
159
+
160
+ $fieldTypes = array(
161
+ 'field_types' => array(
162
+ 'label' => Mage::helper('modulecreator')->__('Supported field / attribute types'),
163
+ 'fields' => $helper->getAttributeTypes()
164
+ )
165
+ );
166
+
167
+ /** @var Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Tab_Help_Fieldset $fieldTypesHelp */
168
+ $fieldTypesHelp = $this->getLayout()
169
+ ->createBlock('modulecreator/adminhtml_modulecreator_edit_tab_help_fieldset');
170
+ $fieldTypesHelp->setFieldsets($fieldTypes)
171
+ ->setColumns(
172
+ array(
173
+ 'label' => array(
174
+ 'header'=>Mage::helper('modulecreator')->__('Field'),
175
+ 'key' =>'label'
176
+ ),
177
+ 'allow_is_name' => array(
178
+ 'header'=>Mage::helper('modulecreator')->__('Can behave as name'),
179
+ 'key' =>'allow_is_name',
180
+ 'type' => 'bool'
181
+ ),
182
+ )
183
+ )
184
+ ->setDescription(Mage::helper('modulecreator')->__('Supported field / attribute types'));
185
+ $relationTypes = array(
186
+ 'field_types'=> array(
187
+ 'label'=> Mage::helper('modulecreator')->__('Relation types'),
188
+ 'fields' => $helper->getRelationTypes()
189
+ )
190
+ );
191
+
192
+ /** @var Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Tab_Help_Fieldset $relationsTypesHelp */
193
+ $relationsTypesHelp = $this->getLayout()
194
+ ->createBlock('modulecreator/adminhtml_modulecreator_edit_tab_help_fieldset');
195
+ $relationsTypesHelp->setFieldsets($relationTypes)
196
+ ->setColumns(
197
+ array(
198
+ 'label' => array(
199
+ 'header'=>Mage::helper('modulecreator')->__('Relation'),
200
+ 'key' =>'label'
201
+ ),
202
+ 'description' => array(
203
+ 'header'=>Mage::helper('modulecreator')->__('Description'),
204
+ 'key' =>'description',
205
+ ),
206
+ )
207
+ )
208
+ ->setDescription(Mage::helper('modulecreator')->__('Entity Relations'));
209
+
210
+ $objN = new stdClass();
211
+ $objN->restricted = 'Mage';
212
+ $objN->label = Mage::helper('modulecreator')->__('Disallowed namespace names');
213
+
214
+ $routers = (array)Mage::getConfig()->getNode('frontend/routers');
215
+ $objM = new stdClass();
216
+ $objM->restricted = implode(', ', array_keys($routers));
217
+ $objM->label = Mage::helper('modulecreator')->__('Disallowed module names');
218
+
219
+ $entityRestrictedNames = implode(
220
+ ', ',
221
+ array_keys((array)$helper->getConfig()->getNode('restricted/entity'))
222
+ );
223
+ $objE = new stdClass();
224
+ $objE->restricted = $entityRestrictedNames;
225
+ $objE->label = Mage::helper('modulecreator')->__('Disallowed entity names');
226
+
227
+ $attributeRestrictedNames = implode(
228
+ ', ',
229
+ array_keys((array)$helper->getConfig()->getNode('restricted/attribute'))
230
+ );
231
+ $objA = new stdClass();
232
+ $objA->restricted = $attributeRestrictedNames;
233
+ $objA->label = Mage::helper('modulecreator')->__('Disallowed field/attribute names');
234
+ $restrictions = array(
235
+ 'field_types'=> array(
236
+ 'label' => Mage::helper('modulecreator')->__('Naming restrictions'),
237
+ 'fields' => array($objN, $objM, $objE, $objA)
238
+ )
239
+ );
240
+
241
+ /** @var Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Tab_Help_Fieldset $restrictionsHelp */
242
+ $restrictionsHelp = $this->getLayout()
243
+ ->createBlock('modulecreator/adminhtml_modulecreator_edit_tab_help_fieldset');
244
+ $restrictionsHelp->setFieldsets($restrictions)
245
+ ->setColumns(
246
+ array(
247
+ 'label' => array(
248
+ 'header'=>Mage::helper('modulecreator')->__('Entity'),
249
+ 'key' =>'label'
250
+ ),
251
+ 'description' => array(
252
+ 'header'=>Mage::helper('modulecreator')->__('Resticted'),
253
+ 'key' =>'restricted',
254
+ ),
255
+ )
256
+ )
257
+ ->setDescription(Mage::helper('modulecreator')->__('Naming restrictions'));
258
+
259
+ /** @var null|Ultimate_ModuleCreator_Model_Module $currentModule */
260
+ $currentModule = Mage::registry('current_module');
261
+ if (!$currentModule) {
262
+ /** @var Ultimate_ModuleCreator_Model_Module $currentModule */
263
+ $currentModule = Mage::getModel('modulecreator/module');
264
+ }
265
+ $files = $currentModule->getConfig()->getNode('files');
266
+ $allowedFiles = array();
267
+ foreach ((array)$files as $file) {
268
+ if ($file->scope == 'disabled') {
269
+ continue;
270
+ }
271
+ $allowedFiles[] = $file;
272
+ }
273
+
274
+ /** @var Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Tab_Help_Fieldset $filesHelp */
275
+ $filesHelp = $this->getLayout()
276
+ ->createBlock('modulecreator/adminhtml_modulecreator_edit_tab_help_fieldset');
277
+ $filesHelp->setFieldsets(
278
+ array(
279
+ 'files'=> array(
280
+ 'label'=>Mage::helper('modulecreator')->__('Generated files'),
281
+ 'fields' => $allowedFiles
282
+ )
283
+ )
284
+ )
285
+ ->setColumns(
286
+ array(
287
+ 'label' => array(
288
+ 'header'=>Mage::helper('modulecreator')->__('File'),
289
+ 'key' =>'title'
290
+ ),
291
+ 'destination'=> array(
292
+ 'header'=>Mage::helper('modulecreator')->__('Path'),
293
+ 'key' =>'destination'
294
+ ),
295
+ 'description' => array(
296
+ 'header'=>Mage::helper('modulecreator')->__('Description'),
297
+ 'key' =>'description',
298
+ ),
299
+ 'condition' => array(
300
+ 'header'=>Mage::helper('modulecreator')->__('Condition'),
301
+ 'key' =>'condition',
302
+ ),
303
+ )
304
+ )
305
+ ->setDescription(Mage::helper('modulecreator')->__('Created files'));
306
+
307
+ $this->setChild('settings_tab_help', $settingsTabHelp);
308
+ $this->setChild('entity_tab_help', $entityTabHelp);
309
+ $this->setChild('attribute_tab_help', $attributeTabHelp);
310
+ $this->setChild('attribute_types_help', $fieldTypesHelp);
311
+ $this->setChild('relation_types_help', $relationsTypesHelp);
312
+ $this->setChild('restrictions_help', $restrictionsHelp);
313
+ $this->setChild('files_help', $filesHelp);
314
+
315
+ $releaseNotes = (array)$helper->getReleaseNotes();
316
+
317
+ /** @var Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Tab_Help_Fieldset $releaseNotesHelp */
318
+ $releaseNotesHelp = $this->getLayout()
319
+ ->createBlock('modulecreator/adminhtml_modulecreator_edit_tab_help_fieldset');
320
+ $releaseNotesHelp->setFieldsets($releaseNotes)
321
+ ->setColumns(
322
+ array(
323
+ 'type' => array(
324
+ 'header' => Mage::helper('modulecreator')->__('Type'),
325
+ 'key' => 'type'
326
+ ),
327
+ 'label' => array(
328
+ 'header' => Mage::helper('modulecreator')->__('Label'),
329
+ 'key' => 'label'
330
+ ),
331
+ 'comment' => array(
332
+ 'header' => Mage::helper('modulecreator')->__('Comment'),
333
+ 'key' => 'comment'
334
+ ),
335
+ )
336
+ )
337
+ ->setDescription(Mage::helper('modulecreator')->__('Release notes'));
338
+ $this->setChild('release_notes', $releaseNotesHelp);
339
+
340
+ /** @var Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Tab_Help_Fieldset $thanks */
341
+ $thanks = $this->getLayout()
342
+ ->createBlock('modulecreator/adminhtml_modulecreator_edit_tab_help_fieldset');
343
+ $thanks->setFieldsets(
344
+ array(
345
+ 'files'=> array(
346
+ 'label' =>Mage::helper('modulecreator')->__('Thanks'),
347
+ 'fields' => (array)$helper->getThanks()
348
+ )
349
+ )
350
+ )
351
+ ->setColumns(
352
+ array(
353
+ 'type' => array(
354
+ 'header'=>Mage::helper('modulecreator')->__('To'),
355
+ 'key' =>'to'
356
+ ),
357
+ 'label' => array(
358
+ 'header'=>Mage::helper('modulecreator')->__('Because'),
359
+ 'key' =>'for'
360
+ ),
361
+ )
362
+ )
363
+ ->setDescription(Mage::helper('modulecreator')->__('Thank you for your help'));
364
+ $this->setChild('thanks', $thanks);
365
+ return parent::_prepareLayout();
366
+ }
367
+ }
app/code/community/Ultimate/ModuleCreator/Block/Adminhtml/Modulecreator/Edit/Tab/Help/Fieldset.php CHANGED
@@ -1,78 +1,82 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
- */
18
- /**
19
- * help fieldset
20
- *
21
- * @category Ultimate
22
- * @package Ultimate_ModuleCreator
23
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
- */
25
- /**
26
- * @method Ultimate_ModuleCreator_Block_Adminhtml_ModuleCreator_Edit_Tab_Help_Fieldset setFieldsets()
27
- * @method Ultimate_ModuleCreator_Block_Adminhtml_ModuleCreator_Edit_Tab_Help_Fieldset setColumns()
28
- * @method Ultimate_ModuleCreator_Block_Adminhtml_ModuleCreator_Edit_Tab_Help_Fieldset setDescription()
29
- */
30
- class Ultimate_ModuleCreator_Block_Adminhtml_ModuleCreator_Edit_Tab_Help_Fieldset
31
- extends Mage_Adminhtml_Block_Template {
32
- /**
33
- * default column type
34
- */
35
- const DEFAULT_COLUMN_TYPE = 'text';
36
-
37
- /**
38
- * constructor
39
- * @access public
40
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
41
- */
42
- public function __construct(){
43
- parent::__construct();
44
- $this->setTemplate('ultimate_modulecreator/edit/tab/help/fieldset.phtml');
45
- }
46
-
47
- /**
48
- * format value
49
- * @param $field
50
- * @param $column
51
- * @return string
52
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
53
- */
54
- public function getFormatedValue($field, $column){
55
- if (!isset($column['type'])){
56
- $column['type'] = self::DEFAULT_COLUMN_TYPE;
57
- }
58
- if (!isset($column['key'])){
59
- return '';
60
- }
61
- $key = $column['key'];
62
- $rawValue = $field->$key;
63
- switch($column['type']){
64
- case 'bool':
65
- $value = (bool)(string)$rawValue;
66
- if ($value == 1){
67
- return Mage::helper('modulecreator')->__('Yes');
68
- }
69
- return Mage::helper('modulecreator')->__('No');
70
- break;
71
- case 'text':
72
- //intentional fall through
73
- default:
74
- return $rawValue;
75
- break;
76
- }
77
- }
78
- }
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
+ */
18
+ /**
19
+ * help fieldset
20
+ *
21
+ * @category Ultimate
22
+ * @package Ultimate_ModuleCreator
23
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
+ */
25
+ /**
26
+ * @method Ultimate_ModuleCreator_Block_Adminhtml_ModuleCreator_Edit_Tab_Help_Fieldset setFieldsets()
27
+ * @method Ultimate_ModuleCreator_Block_Adminhtml_ModuleCreator_Edit_Tab_Help_Fieldset setColumns()
28
+ * @method Ultimate_ModuleCreator_Block_Adminhtml_ModuleCreator_Edit_Tab_Help_Fieldset setDescription()
29
+ */
30
+ class Ultimate_ModuleCreator_Block_Adminhtml_ModuleCreator_Edit_Tab_Help_Fieldset extends Mage_Adminhtml_Block_Template
31
+ {
32
+ /**
33
+ * default column type
34
+ */
35
+ const DEFAULT_COLUMN_TYPE = 'text';
36
+
37
+ /**
38
+ * constructor
39
+ *
40
+ * @access public
41
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
42
+ */
43
+ public function __construct()
44
+ {
45
+ parent::__construct();
46
+ $this->setTemplate('ultimate_modulecreator/edit/tab/help/fieldset.phtml');
47
+ }
48
+
49
+ /**
50
+ * format value
51
+ *
52
+ * @param $field
53
+ * @param $column
54
+ * @return string
55
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
56
+ */
57
+ public function getFormatedValue($field, $column)
58
+ {
59
+ if (!isset($column['type'])) {
60
+ $column['type'] = self::DEFAULT_COLUMN_TYPE;
61
+ }
62
+ if (!isset($column['key'])) {
63
+ return '';
64
+ }
65
+ $key = $column['key'];
66
+ $rawValue = $field->$key;
67
+ switch($column['type']) {
68
+ case 'bool':
69
+ $value = (bool)(string)$rawValue;
70
+ if ($value == 1) {
71
+ return Mage::helper('modulecreator')->__('Yes');
72
+ }
73
+ return Mage::helper('modulecreator')->__('No');
74
+ break;
75
+ case 'text':
76
+ //intentional fall through
77
+ default:
78
+ return $rawValue;
79
+ break;
80
+ }
81
+ }
82
+ }
app/code/community/Ultimate/ModuleCreator/Block/Adminhtml/Modulecreator/Edit/Tab/Relation.php CHANGED
@@ -1,77 +1,90 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- */
17
- /**
18
- * relations tab block
19
- *
20
- * @category Ultimate
21
- * @package Ultimate_ModuleCreator
22
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
23
- */
24
- /**
25
- * @method array getRelations()
26
- */
27
- class Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Tab_Relation
28
- extends Mage_Adminhtml_Block_Widget_Form
29
- implements Mage_Adminhtml_Block_Widget_Tab_Interface {
30
- /**
31
- * constructor
32
- * @access public
33
- * @return void
34
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
35
- */
36
- public function _construct() {
37
- parent::_construct();
38
- $this->setTemplate('ultimate_modulecreator/edit/tab/relation.phtml');
39
- }
40
- /**
41
- * Return Tab label
42
- * @access public
43
- * @return string
44
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
45
- */
46
- public function getTabLabel() {
47
- return Mage::helper('modulecreator')->__('Entity Relations');
48
- }
49
- /**
50
- * Return Tab title
51
- * @access public
52
- * @return string
53
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
54
- */
55
- public function getTabTitle() {
56
- return Mage::helper('modulecreator')->__('Entity Relations');
57
- }
58
- /**
59
- * Can show tab in tabs
60
- * @access public
61
- * @return boolean
62
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
63
- */
64
- public function canShowTab() {
65
- return true;
66
- }
67
-
68
- /**
69
- * Tab is hidden
70
- * @access public
71
- * @return boolean
72
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
73
- */
74
- public function isHidden() {
75
- return count($this->getRelations()) == 0;
76
- }
77
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ */
17
+ /**
18
+ * relations tab block
19
+ *
20
+ * @category Ultimate
21
+ * @package Ultimate_ModuleCreator
22
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
23
+ */
24
+ /**
25
+ * @method array getRelations()
26
+ */
27
+ class Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Tab_Relation extends Mage_Adminhtml_Block_Widget_Form implements
28
+ Mage_Adminhtml_Block_Widget_Tab_Interface
29
+ {
30
+ /**
31
+ * constructor
32
+ *
33
+ * @access public
34
+ * @return void
35
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
36
+ */
37
+ public function _construct()
38
+ {
39
+ parent::_construct();
40
+ $this->setTemplate('ultimate_modulecreator/edit/tab/relation.phtml');
41
+ }
42
+
43
+ /**
44
+ * Return Tab label
45
+ *
46
+ * @access public
47
+ * @return string
48
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
49
+ */
50
+ public function getTabLabel()
51
+ {
52
+ return Mage::helper('modulecreator')->__('Entity Relations');
53
+ }
54
+
55
+ /**
56
+ * Return Tab title
57
+ *
58
+ * @access public
59
+ * @return string
60
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
61
+ */
62
+ public function getTabTitle()
63
+ {
64
+ return Mage::helper('modulecreator')->__('Entity Relations');
65
+ }
66
+
67
+ /**
68
+ * Can show tab in tabs
69
+ *
70
+ * @access public
71
+ * @return boolean
72
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
73
+ */
74
+ public function canShowTab()
75
+ {
76
+ return true;
77
+ }
78
+
79
+ /**
80
+ * Tab is hidden
81
+ *
82
+ * @access public
83
+ * @return boolean
84
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
85
+ */
86
+ public function isHidden()
87
+ {
88
+ return count($this->getRelations()) == 0;
89
+ }
90
+ }
app/code/community/Ultimate/ModuleCreator/Block/Adminhtml/Modulecreator/Edit/Tab/Settings.php CHANGED
@@ -1,89 +1,101 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
- */
18
- /**
19
- * settings tab block
20
- *
21
- * @category Ultimate
22
- * @package Ultimate_ModuleCreator
23
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
- */
25
- class Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Tab_Settings
26
- extends Mage_Adminhtml_Block_Widget_Form
27
- implements Mage_Adminhtml_Block_Widget_Tab_Interface {
28
- /**
29
- * Return Tab label
30
- * @access public
31
- * @return string
32
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
33
- */
34
- public function getTabLabel() {
35
- return Mage::helper('modulecreator')->__('General Settings');
36
- }
37
- /**
38
- * Return Tab title
39
- * @access public
40
- * @return string
41
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
42
- */
43
- public function getTabTitle() {
44
- return Mage::helper('modulecreator')->__('General Settings');
45
- }
46
- /**
47
- * Can show tab in tabs
48
- * @access public
49
- * @return boolean
50
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
51
- */
52
- public function canShowTab() {
53
- return true;
54
- }
55
-
56
- /**
57
- * Tab is hidden
58
- * @access public
59
- * @return boolean
60
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
61
- */
62
- public function isHidden() {
63
- return false;
64
- }
65
- /**
66
- * prepare the form
67
- * @access public
68
- * @return Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Tab_Settings
69
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
70
- */
71
- protected function _prepareForm() {
72
- /** @var Ultimate_ModuleCreator_Helper_Data $helper */
73
- $helper = Mage::helper('modulecreator');
74
- $form = $helper->getXmlForm('settings');
75
- $form->setHtmlIdPrefix('settings_');
76
- $module = Mage::registry('current_module');
77
- $values = array();
78
- if ($module) {
79
- $values = $module->getData();
80
- }
81
- else {
82
- $values = Mage::getStoreConfig(Ultimate_ModuleCreator_Helper_Data::XML_SETTINGS_CONFIG_PATH);
83
- }
84
- $this->setForm($form);
85
- $form->addFieldNameSuffix('settings');
86
- $form->addValues($values);
87
- return parent::_prepareForm();
88
- }
89
- }
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
+ */
18
+ /**
19
+ * settings tab block
20
+ *
21
+ * @category Ultimate
22
+ * @package Ultimate_ModuleCreator
23
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
+ */
25
+ class Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Tab_Settings extends Mage_Adminhtml_Block_Widget_Form implements
26
+ Mage_Adminhtml_Block_Widget_Tab_Interface
27
+ {
28
+ /**
29
+ * Return Tab label
30
+ *
31
+ * @access public
32
+ * @return string
33
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
34
+ */
35
+ public function getTabLabel()
36
+ {
37
+ return Mage::helper('modulecreator')->__('General Settings');
38
+ }
39
+
40
+ /**
41
+ * Return Tab title
42
+ *
43
+ * @access public
44
+ * @return string
45
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
46
+ */
47
+ public function getTabTitle()
48
+ {
49
+ return Mage::helper('modulecreator')->__('General Settings');
50
+ }
51
+
52
+ /**
53
+ * Can show tab in tabs
54
+ *
55
+ * @access public
56
+ * @return boolean
57
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
58
+ */
59
+ public function canShowTab()
60
+ {
61
+ return true;
62
+ }
63
+
64
+ /**
65
+ * Tab is hidden
66
+ *
67
+ * @access public
68
+ * @return boolean
69
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
70
+ */
71
+ public function isHidden()
72
+ {
73
+ return false;
74
+ }
75
+
76
+ /**
77
+ * prepare the form
78
+ *
79
+ * @access public
80
+ * @return Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Tab_Settings
81
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
82
+ */
83
+ protected function _prepareForm()
84
+ {
85
+ /** @var Ultimate_ModuleCreator_Helper_Data $helper */
86
+ $helper = Mage::helper('modulecreator');
87
+ $form = $helper->getXmlForm('settings');
88
+ $form->setHtmlIdPrefix('settings_');
89
+ $module = Mage::registry('current_module');
90
+ $values = array();
91
+ if ($module) {
92
+ $values = $module->getData();
93
+ } else {
94
+ $values = Mage::getStoreConfig(Ultimate_ModuleCreator_Helper_Data::XML_SETTINGS_CONFIG_PATH);
95
+ }
96
+ $this->setForm($form);
97
+ $form->addFieldNameSuffix('settings');
98
+ $form->addValues($values);
99
+ return parent::_prepareForm();
100
+ }
101
+ }
app/code/community/Ultimate/ModuleCreator/Block/Adminhtml/Modulecreator/Edit/Tabs.php CHANGED
@@ -1,42 +1,44 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
- */
18
- /**
19
- * add/edit tabs
20
- *
21
- * @category Ultimate
22
- * @package Ultimate_ModuleCreator
23
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
- */
25
- /**
26
- * @method Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Tabs setTitle
27
- */
28
- class Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Tabs
29
- extends Mage_Adminhtml_Block_Widget_Tabs {
30
- /**
31
- * construct
32
- * @access public
33
- * @return void
34
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
35
- */
36
- public function _construct() {
37
- parent::_construct();
38
- $this->setId('modulecreator_info_tabs');
39
- $this->setDestElementId('edit_form');
40
- $this->setTitle(Mage::helper('modulecreator')->__('Module information'));
41
- }
42
- }
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
+ */
18
+ /**
19
+ * add/edit tabs
20
+ *
21
+ * @category Ultimate
22
+ * @package Ultimate_ModuleCreator
23
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
+ */
25
+ /**
26
+ * @method Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Tabs setTitle
27
+ */
28
+ class Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
29
+ {
30
+ /**
31
+ * construct
32
+ *
33
+ * @access public
34
+ * @return void
35
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
36
+ */
37
+ public function _construct()
38
+ {
39
+ parent::_construct();
40
+ $this->setId('modulecreator_info_tabs');
41
+ $this->setDestElementId('edit_form');
42
+ $this->setTitle(Mage::helper('modulecreator')->__('Module information'));
43
+ }
44
+ }
app/code/community/Ultimate/ModuleCreator/Block/Adminhtml/Modulecreator/Grid.php CHANGED
@@ -1,174 +1,207 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- */
17
- /**
18
- * modules grid.
19
- *
20
- * @category Ultimate
21
- * @package Ultimate_ModuleCreator
22
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
23
- */
24
- /**
25
- * @method Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Grid setUseAjax()
26
- */
27
- class Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Grid
28
- extends Mage_Adminhtml_Block_Widget_Grid {
29
- /**
30
- * no filters
31
- * @var bool
32
- */
33
- protected $_filterVisibility = false;
34
- /**
35
- * Initialize Grid block
36
- * @access public
37
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
38
- */
39
- public function __construct() {
40
- parent::__construct();
41
- $this->_defaultLimit = 200;
42
- $this->setId('ModuleCreator_grid');
43
- $this->setUseAjax(true);
44
- }
45
-
46
- /**
47
- * Creates extension collection if it has not been created yet
48
- * @access public
49
- * @return Ultimate_ModuleCreator_Model_Module_Collection
50
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
51
- */
52
- public function getCollection() {
53
- if (!$this->_collection) {
54
- $this->_collection = Mage::getModel('modulecreator/module_collection');
55
- }
56
- return $this->_collection;
57
- }
58
- /**
59
- * Prepare Collection for Grid
60
- * @access protected
61
- * @return Ultimate_ModuleCreator_Block_Adminhtml_ModuleCreator_Grid
62
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
63
- */
64
- protected function _prepareCollection() {
65
- $this->setCollection($this->getCollection());
66
- return parent::_prepareCollection();
67
- }
68
-
69
- /**
70
- * Prepare grid columns
71
- * @access protected
72
- * @return Ultimate_ModuleCreator_Block_Adminhtml_ModuleCreator_Grid
73
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
74
- */
75
- protected function _prepareColumns() {
76
- $this->addColumn('filename_id', array(
77
- 'header' => Mage::helper('modulecreator')->__('Module'),
78
- 'index' => 'filename_id',
79
- 'filter' => false,
80
- ));
81
- $actionColumnRenderer = 'modulecreator/adminhtml_modulecreator_grid_column_renderer_download';
82
- $this->addColumn('action_edit',
83
- array(
84
- 'header'=> Mage::helper('modulecreator')->__('Edit'),
85
- 'width' => '100',
86
- 'type' => 'action',
87
- 'getter'=> 'getSafeId',
88
- 'actions' => array(
89
- array(
90
- 'caption' => Mage::helper('modulecreator')->__('Edit'),
91
- 'url' => array('base'=> '*/*/edit'),
92
- 'field' => 'id'
93
- )
94
- ),
95
- 'filter' => false,
96
- 'is_system' => true,
97
- 'sortable' => false,
98
- )
99
- );
100
- $this->addColumn('action_config',
101
- array(
102
- 'header' => Mage::helper('modulecreator')->__('Download Config File'),
103
- 'label' => Mage::helper('modulecreator')->__('Download Config File'),
104
- 'width' => '150',
105
- 'renderer' => $actionColumnRenderer,
106
- 'filter' => false,
107
- 'is_system' => true,
108
- 'sortable' => false,
109
- 'what' => 'config'
110
- )
111
- );
112
- $this->addColumn('action',
113
- array(
114
- 'header' => Mage::helper('modulecreator')->__('Download Module'),
115
- 'label' => Mage::helper('modulecreator')->__('Download Module'),
116
- 'width' => '100',
117
- 'renderer' => $actionColumnRenderer,
118
- 'filter' => false,
119
- 'is_system' => true,
120
- 'sortable' => false,
121
- )
122
- );
123
- $this->addColumn('action_list',
124
- array(
125
- 'header' => Mage::helper('modulecreator')->__('Download List of Files'),
126
- 'label' => Mage::helper('modulecreator')->__('Download List of Files'),
127
- 'width' => '100',
128
- 'renderer' => $actionColumnRenderer,
129
- 'filter' => false,
130
- 'is_system' => true,
131
- 'sortable' => false,
132
- 'what' => 'list'
133
- )
134
- );
135
- $this->addColumn('action_uninstall',
136
- array(
137
- 'header' => Mage::helper('modulecreator')->__('Download Uninstall DB Script'),
138
- 'label' => Mage::helper('modulecreator')->__('Download Uninstall DB Script'),
139
- 'width' => '200',
140
- 'renderer' => $actionColumnRenderer,
141
- 'filter' => false,
142
- 'is_system' => true,
143
- 'sortable' => false,
144
- 'what' => 'uninstall'
145
- )
146
- );
147
-
148
- return parent::_prepareColumns();
149
- }
150
-
151
- /**
152
- * Self URL getter
153
- * @access public
154
- * @param array() $params
155
- * @return string
156
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
157
- */
158
- public function getCurrentUrl($params = array()) {
159
- if (!isset($params['_current'])) {
160
- $params['_current'] = true;
161
- }
162
- return $this->getUrl('*/*/grid', $params);
163
- }
164
- /**
165
- * Row URL getter
166
- * @access public
167
- * @param Ultimate_ModuleCreator_Model_Module $row
168
- * @return string
169
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
170
- */
171
- public function getRowUrl($row) {
172
- return $this->getUrl('*/*/edit', array('id' => strtr(base64_encode($row->getFilenameId()), '+/=', '-_,')));
173
- }
174
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ */
17
+ /**
18
+ * modules grid.
19
+ *
20
+ * @category Ultimate
21
+ * @package Ultimate_ModuleCreator
22
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
23
+ */
24
+ /**
25
+ * @method Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Grid setUseAjax()
26
+ */
27
+ class Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Grid extends Mage_Adminhtml_Block_Widget_Grid
28
+ {
29
+ /**
30
+ * no filters
31
+ * @var bool
32
+ */
33
+ protected $_filterVisibility = false;
34
+
35
+ /**
36
+ * Initialize Grid block
37
+ *
38
+ * @access public
39
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
40
+ */
41
+ public function __construct()
42
+ {
43
+ parent::__construct();
44
+ $this->_defaultLimit = 200;
45
+ $this->setId('ModuleCreator_grid');
46
+ $this->setUseAjax(true);
47
+ }
48
+
49
+ /**
50
+ * Creates extension collection if it has not been created yet
51
+ *
52
+ * @access public
53
+ * @return Ultimate_ModuleCreator_Model_Module_Collection
54
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
55
+ */
56
+ public function getCollection()
57
+ {
58
+ if (!$this->_collection) {
59
+ $this->_collection = Mage::getModel('modulecreator/module_collection');
60
+ }
61
+ return $this->_collection;
62
+ }
63
+
64
+ /**
65
+ * Prepare Collection for Grid
66
+ *
67
+ * @access protected
68
+ * @return Ultimate_ModuleCreator_Block_Adminhtml_ModuleCreator_Grid
69
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
70
+ */
71
+ protected function _prepareCollection()
72
+ {
73
+ $this->setCollection($this->getCollection());
74
+ return parent::_prepareCollection();
75
+ }
76
+
77
+ /**
78
+ * Prepare grid columns
79
+ *
80
+ * @access protected
81
+ * @return Ultimate_ModuleCreator_Block_Adminhtml_ModuleCreator_Grid
82
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
83
+ */
84
+ protected function _prepareColumns()
85
+ {
86
+ $this->addColumn(
87
+ 'filename_id',
88
+ array(
89
+ 'header' => Mage::helper('modulecreator')->__('Module'),
90
+ 'index' => 'filename_id',
91
+ 'filter' => false,
92
+ )
93
+ );
94
+ $actionColumnRenderer = 'modulecreator/adminhtml_modulecreator_grid_column_renderer_download';
95
+ $this->addColumn(
96
+ 'action_edit',
97
+ array(
98
+ 'header'=> Mage::helper('modulecreator')->__('Edit'),
99
+ 'width' => '100',
100
+ 'type' => 'action',
101
+ 'getter'=> 'getSafeId',
102
+ 'actions' => array(
103
+ array(
104
+ 'caption' => Mage::helper('modulecreator')->__('Edit'),
105
+ 'url' => array('base'=> '*/*/edit'),
106
+ 'field' => 'id'
107
+ )
108
+ ),
109
+ 'filter' => false,
110
+ 'is_system' => true,
111
+ 'sortable' => false,
112
+ )
113
+ );
114
+ $this->addColumn(
115
+ 'action_config',
116
+ array(
117
+ 'header' => Mage::helper('modulecreator')->__('Download Config File'),
118
+ 'label' => Mage::helper('modulecreator')->__('Download Config File'),
119
+ 'width' => '150',
120
+ 'renderer' => $actionColumnRenderer,
121
+ 'filter' => false,
122
+ 'is_system' => true,
123
+ 'sortable' => false,
124
+ 'what' => 'config'
125
+ )
126
+ );
127
+ $this->addColumn(
128
+ 'action',
129
+ array(
130
+ 'header' => Mage::helper('modulecreator')->__('Download Module'),
131
+ 'label' => Mage::helper('modulecreator')->__('Download Module'),
132
+ 'width' => '100',
133
+ 'renderer' => $actionColumnRenderer,
134
+ 'filter' => false,
135
+ 'is_system' => true,
136
+ 'sortable' => false,
137
+ )
138
+ );
139
+ $this->addColumn(
140
+ 'action_list',
141
+ array(
142
+ 'header' => Mage::helper('modulecreator')->__('Download List of Files'),
143
+ 'label' => Mage::helper('modulecreator')->__('Download List of Files'),
144
+ 'width' => '100',
145
+ 'renderer' => $actionColumnRenderer,
146
+ 'filter' => false,
147
+ 'is_system' => true,
148
+ 'sortable' => false,
149
+ 'what' => 'list'
150
+ )
151
+ );
152
+ $this->addColumn(
153
+ 'action_uninstall',
154
+ array(
155
+ 'header' => Mage::helper('modulecreator')->__('Download Uninstall DB Script'),
156
+ 'label' => Mage::helper('modulecreator')->__('Download Uninstall DB Script'),
157
+ 'width' => '200',
158
+ 'renderer' => $actionColumnRenderer,
159
+ 'filter' => false,
160
+ 'is_system' => true,
161
+ 'sortable' => false,
162
+ 'what' => 'uninstall'
163
+ )
164
+ );
165
+ return parent::_prepareColumns();
166
+ }
167
+
168
+ /**
169
+ * Self URL getter
170
+ *
171
+ * @access public
172
+ * @param array() $params
173
+ * @return string
174
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
175
+ */
176
+ public function getCurrentUrl($params = array())
177
+ {
178
+ if (!isset($params['_current'])) {
179
+ $params['_current'] = true;
180
+ }
181
+ return $this->getUrl('*/*/grid', $params);
182
+ }
183
+
184
+ /**
185
+ * Row URL getter
186
+ *
187
+ * @access public
188
+ * @param Ultimate_ModuleCreator_Model_Module $row
189
+ * @return string
190
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
191
+ */
192
+ public function getRowUrl($row)
193
+ {
194
+ return $this->getUrl(
195
+ '*/*/edit',
196
+ array(
197
+ 'id' => strtr(
198
+ base64_encode(
199
+ $row->getFilenameId()
200
+ ),
201
+ '+/=',
202
+ '-_,'
203
+ )
204
+ )
205
+ );
206
+ }
207
+ }
app/code/community/Ultimate/ModuleCreator/Block/Adminhtml/Modulecreator/Grid/Column/Renderer/Download.php CHANGED
@@ -1,75 +1,83 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- */
17
- /**
18
- * download column renderer
19
- *
20
- * @category Ultimate
21
- * @package Ultimate_ModuleCreator
22
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
23
- */
24
-
25
- class Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Grid_Column_Renderer_Download
26
- extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract {
27
- /**
28
- * render row
29
- * @access public
30
- * @param Varien_Object $row
31
- * @return string
32
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
33
- */
34
- public function render(Varien_Object $row) {
35
- /** @var string $what */
36
- $what = $this->getColumn()->getWhat();
37
- /** @var string $id */
38
- $id = $row->getSafeId();
39
- $packageName = base64_decode(strtr($id, '-_,', '+/='));
40
- /** @var Ultimate_ModuleCreator_Helper_Data $helper */
41
- $helper = Mage::helper('modulecreator');
42
- $path = $helper->getLocalModulesDir();
43
- switch ($what) {
44
- case 'config':
45
- $file = $path.'package'.DS.$packageName . '.xml';
46
- break;
47
- case 'list':
48
- $file = $path.'package'.DS.$packageName . DS. 'files.log';
49
- break;
50
- case 'uninstall' :
51
- $file = $path.'package'.DS.$packageName . DS. 'uninstall.sql';
52
- break;
53
- default:
54
- $file = $path . $packageName . '.tgz';
55
- break;
56
- }
57
- if (file_exists($file) && is_readable($file)) {
58
- return '<a href="'.$this->getUrl('*/*/download', array('type'=>$what, 'id'=>$id)).'">'.$this->_getLabel().'</a>';
59
- }
60
- return '<span style="color:red;">'.Mage::helper('modulecreator')->__('File does not exist or is not readable').'</span>';
61
- }
62
-
63
- /**
64
- * get the link label
65
- * @access protected
66
- * @return string
67
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
68
- */
69
- protected function _getLabel() {
70
- if ($this->getColumn()->getLabel()) {
71
- return $this->getColumn()->getLabel();
72
- }
73
- return Mage::helper('modulecreator')->__('Download');
74
- }
75
- }
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ */
17
+ /**
18
+ * download column renderer
19
+ *
20
+ * @category Ultimate
21
+ * @package Ultimate_ModuleCreator
22
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
23
+ */
24
+
25
+ class Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Grid_Column_Renderer_Download extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
26
+ {
27
+ /**
28
+ * render row
29
+ *
30
+ * @access public
31
+ * @param Varien_Object $row
32
+ * @return string
33
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
34
+ */
35
+ public function render(Varien_Object $row)
36
+ {
37
+ /** @var string $what */
38
+ $what = $this->getColumn()->getWhat();
39
+ /** @var string $id */
40
+ $id = $row->getSafeId();
41
+ $packageName = base64_decode(strtr($id, '-_,', '+/='));
42
+ /** @var Ultimate_ModuleCreator_Helper_Data $helper */
43
+ $helper = Mage::helper('modulecreator');
44
+ $path = $helper->getLocalModulesDir();
45
+ switch ($what) {
46
+ case 'config':
47
+ $file = $path.'package'.DS.$packageName . '.xml';
48
+ break;
49
+ case 'list':
50
+ $file = $path.'package'.DS.$packageName . DS. 'files.log';
51
+ break;
52
+ case 'uninstall' :
53
+ $file = $path.'package'.DS.$packageName . DS. 'uninstall.sql';
54
+ break;
55
+ default:
56
+ $file = $path . $packageName . '.tgz';
57
+ break;
58
+ }
59
+ if (file_exists($file) && is_readable($file)) {
60
+ return '<a href="'.
61
+ $this->getUrl('*/*/download', array('type'=>$what, 'id'=>$id)).'">'.$this->_getLabel().
62
+ '</a>';
63
+ }
64
+ return '<span style="color:red;">'.
65
+ Mage::helper('modulecreator')->__('File does not exist or is not readable').
66
+ '</span>';
67
+ }
68
+
69
+ /**
70
+ * get the link label
71
+ *
72
+ * @access protected
73
+ * @return string
74
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
75
+ */
76
+ protected function _getLabel()
77
+ {
78
+ if ($this->getColumn()->getLabel()) {
79
+ return $this->getColumn()->getLabel();
80
+ }
81
+ return Mage::helper('modulecreator')->__('Download');
82
+ }
83
+ }
app/code/community/Ultimate/ModuleCreator/Block/Adminhtml/Modulecreator/Menu.php CHANGED
@@ -1,95 +1,108 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
- */
18
- /**
19
- * select menu block.
20
- *
21
- * @category Ultimate
22
- * @package Ultimate_ModuleCreator
23
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
- */
25
- class Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Menu
26
- extends Mage_Adminhtml_Block_Page_Menu {
27
- /**
28
- * don't cache
29
- * @access public
30
- * @return int|null
31
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
32
- */
33
- public function getCacheLifetime(){
34
- return null;
35
- }
36
- /**
37
- * draw the menu
38
- * @access public
39
- * @param $menu
40
- * @param string $parentId
41
- * @param int $level
42
- * @return string
43
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
44
- */
45
- public function renderUmcMenu($menu, $parentId = '', $level = 0) {
46
- $html = '<ul ' . (!$level ? 'id="umc-nav"' : '') . '>';
47
- $html .= $this->_renderSelector($parentId, 0);
48
- $previousSortOrder = 0;
49
- foreach ($menu as $key=> $item) {
50
- $html .= '<li>';
51
- $html .= '<span class="delete toggler collapsed"></span>';
52
- $html .= '<a href="#" onclick="return false">' . $this->escapeHtml($item['label']) . '</a>';
53
- if ($parentId) {
54
- $nextParentId = $parentId.'/'.$key;
55
- }
56
- else {
57
- $nextParentId = $key;
58
- }
59
- if (!empty($item['children'])) {
60
- $html .= $this->renderUmcMenu($item['children'], $nextParentId, $level + 1);
61
- }
62
- else {
63
- $html .= '<ul>'.$this->_renderSelector($nextParentId, 10).'</ul>';
64
- }
65
- $html .= '</li>';
66
- $html .= $this->_renderSelector($parentId, (int)(($item['sort_order'] + $previousSortOrder)/2));
67
- $previousSortOrder = $item['sort_order'];
68
- }
69
- $html .= '</ul>';
70
-
71
- return $html;
72
- }
73
-
74
- /**
75
- * render the selection link
76
- * @access protected
77
- * @param $parentId
78
- * @param $sortOrder
79
- * @return string
80
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
81
- */
82
- protected function _renderSelector($parentId, $sortOrder){
83
- return '<li class="umc-menu-selector"><a class="insert-menu" menu-data=\'{"parent":"'.$parentId.'", "sort_order": "'.$sortOrder.'"}\' title="'.Mage::helper('modulecreator')->__('Insert here').'">'.Mage::helper('modulecreator')->__('Insert here').'</a></li>';
84
- }
85
-
86
- /**
87
- * render menu
88
- * @access protected
89
- * @return string
90
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
91
- */
92
- protected function _toHtml() {
93
- return $this->renderUmcMenu($this->getMenuArray());
94
- }
95
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
+ */
18
+ /**
19
+ * select menu block.
20
+ *
21
+ * @category Ultimate
22
+ * @package Ultimate_ModuleCreator
23
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
+ */
25
+ class Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_Menu extends Mage_Adminhtml_Block_Page_Menu
26
+ {
27
+ /**
28
+ * don't cache
29
+ *
30
+ * @access public
31
+ * @return int|null
32
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
33
+ */
34
+ public function getCacheLifetime()
35
+ {
36
+ return null;
37
+ }
38
+
39
+ /**
40
+ * draw the menu
41
+ *
42
+ * @access public
43
+ * @param $menu
44
+ * @param string $parentId
45
+ * @param int $level
46
+ * @return string
47
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
48
+ */
49
+ public function renderUmcMenu($menu, $parentId = '', $level = 0)
50
+ {
51
+ $html = '<ul ' . (!$level ? 'id="umc-nav"' : '') . '>';
52
+ $html .= $this->_renderSelector($parentId, 0);
53
+ $previousSortOrder = 0;
54
+ foreach ($menu as $key=> $item) {
55
+ $html .= '<li>';
56
+ $html .= '<span class="delete toggler collapsed"></span>';
57
+ $html .= '<a href="#" onclick="return false">' . $this->escapeHtml($item['label']) . '</a>';
58
+ if ($parentId) {
59
+ $nextParentId = $parentId.'/'.$key;
60
+ } else {
61
+ $nextParentId = $key;
62
+ }
63
+ if (!empty($item['children'])) {
64
+ $html .= $this->renderUmcMenu($item['children'], $nextParentId, $level + 1);
65
+ } else {
66
+ $html .= '<ul>'.$this->_renderSelector($nextParentId, 10).'</ul>';
67
+ }
68
+ $html .= '</li>';
69
+ $html .= $this->_renderSelector($parentId, (int)(($item['sort_order'] + $previousSortOrder)/2));
70
+ $previousSortOrder = $item['sort_order'];
71
+ }
72
+ $html .= '</ul>';
73
+
74
+ return $html;
75
+ }
76
+
77
+ /**
78
+ * render the selection link
79
+ *
80
+ * @access protected
81
+ * @param $parentId
82
+ * @param $sortOrder
83
+ * @return string
84
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
85
+ */
86
+ protected function _renderSelector($parentId, $sortOrder)
87
+ {
88
+ $html = '<li class="umc-menu-selector">';
89
+ $html .= '<a class="insert-menu" menu-data=\'{"parent":"'.$parentId.'", "sort_order": "'.$sortOrder.'"}\'';
90
+ $html .= 'title="'.Mage::helper('modulecreator')->__('Insert here').'">';
91
+ $html .= Mage::helper('modulecreator')->__('Insert here');
92
+ $html .= '</a>';
93
+ $html .= '</li>';
94
+ return $html;
95
+ }
96
+
97
+ /**
98
+ * render menu
99
+ *
100
+ * @access protected
101
+ * @return string
102
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
103
+ */
104
+ protected function _toHtml()
105
+ {
106
+ return $this->renderUmcMenu($this->getMenuArray());
107
+ }
108
+ }
app/code/community/Ultimate/ModuleCreator/Block/Adminhtml/Modulecreator/System/Config/Form/Fieldset/Abstract.php CHANGED
@@ -1,128 +1,141 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
- */
18
- /**
19
- * abstract system->config fieldset renderer
20
- *
21
- * @category Ultimate
22
- * @package Ultimate_ModuleCreator
23
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
- */
25
- abstract class Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_System_Config_Form_Fieldset_Abstract
26
- extends Mage_Adminhtml_Block_System_Config_Form_Fieldset {
27
- /**
28
- * @var Varien_Object
29
- */
30
- protected $_dummyElement;
31
- /**
32
- * @var Mage_Adminhtml_Block_System_Config_Form_Field
33
- */
34
- protected $_fieldRenderer;
35
- /**
36
- * @var array
37
- */
38
- protected $_values;
39
-
40
- /**
41
- * get the form name
42
- * @return mixed
43
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
44
- */
45
- public abstract function getFormName();
46
-
47
- /**
48
- * render the config section
49
- * @access public
50
- * @param Varien_Data_Form_Element_Abstract $element
51
- * @return string
52
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
53
- */
54
- public function render(Varien_Data_Form_Element_Abstract $element) {
55
- $html = $this->_getHeaderHtml($element);
56
- /** @var Ultimate_ModuleCreator_Helper_Data $helper */
57
- $helper = Mage::helper('modulecreator');
58
- $config = $helper->getConfig();
59
- $formName = $this->getFormName();
60
- if (!$config->getNode('forms/'.$formName)) {
61
- return '';
62
- }
63
- $fieldsets = $config->getNode('forms/'.$formName.'/fieldsets');
64
- $index = 0;
65
- foreach ((array)$fieldsets as $key => $set) {
66
- $positions = array();
67
- foreach ((array)$set->fields as $id=>$field) {
68
- if (!$field->system) {
69
- continue;
70
- }
71
- $positions[(int)$field->position][$id] = $field;
72
- }
73
- ksort($positions);
74
- $sorted = array();
75
- foreach ($positions as $fields) {
76
- $sorted = array_merge($sorted, $fields);
77
- }
78
- foreach($sorted as $id=>$field) {
79
- $html.= $this->_getFieldHtml($element, $id, $field);
80
- }
81
- }
82
- $html .= $this->_getFooterHtml($element);
83
- return $html;
84
- }
85
- /**
86
- * get field renderer.
87
- * @access protected
88
- * @return Mage_Adminhtml_Block_System_Config_Form_Field
89
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
90
- */
91
- protected function _getFieldRenderer() {
92
- if (empty($this->_fieldRenderer)) {
93
- $this->_fieldRenderer = Mage::getBlockSingleton('adminhtml/system_config_form_field');
94
- }
95
- return $this->_fieldRenderer;
96
- }
97
- /**
98
- * get HTML for the field
99
- * @access protected
100
- * @param Varien_Data_Form_Element_Fieldset $fieldset
101
- * @param string $key
102
- * @param $field
103
- * @return mixed
104
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
105
- */
106
- protected function _getFieldHtml($fieldset, $key, $field){
107
- //$configData = $this->getConfigData();
108
- $formName = $this->getFormName();
109
- $path = 'modulecreator/'.$formName.'/' . $key;
110
- $data = Mage::getStoreConfig($path, 0);
111
- $settings = array(
112
- 'name' => 'groups['.$formName.'][fields]['.$key.'][value]',
113
- 'label' => (string)$field->label,
114
- 'value' => $data,
115
- 'inherit' => false,
116
- 'can_use_default_value' => false,
117
- 'can_use_website_value' => false,
118
- );
119
- if (in_array((string)$field->type, array('select', 'multiselect'))) {
120
- $settings['values'] = Mage::getModel((string)$field->source)->toArray(((string)$field->type == 'select'));
121
- }
122
- if ($field->tooltip) {
123
- $settings['tooltip'] = (string)$field->tooltip;
124
- }
125
- $field = $fieldset->addField($formName.$key, (string)$field->type, $settings)->setRenderer($this->_getFieldRenderer());
126
- return $field->toHtml();
127
- }
128
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
+ */
18
+ /**
19
+ * abstract system->config fieldset renderer
20
+ *
21
+ * @category Ultimate
22
+ * @package Ultimate_ModuleCreator
23
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
+ */
25
+ abstract class Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_System_Config_Form_Fieldset_Abstract extends Mage_Adminhtml_Block_System_Config_Form_Fieldset
26
+ {
27
+ /**
28
+ * @var Varien_Object
29
+ */
30
+ protected $_dummyElement;
31
+
32
+ /**
33
+ * @var Mage_Adminhtml_Block_System_Config_Form_Field
34
+ */
35
+ protected $_fieldRenderer;
36
+
37
+ /**
38
+ * @var array
39
+ */
40
+ protected $_values;
41
+
42
+ /**
43
+ * get the form name
44
+ * @return mixed
45
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
46
+ */
47
+ public abstract function getFormName();
48
+
49
+ /**
50
+ * render the config section
51
+ *
52
+ * @access public
53
+ * @param Varien_Data_Form_Element_Abstract $element
54
+ * @return string
55
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
56
+ */
57
+ public function render(Varien_Data_Form_Element_Abstract $element)
58
+ {
59
+ $html = $this->_getHeaderHtml($element);
60
+ /** @var Ultimate_ModuleCreator_Helper_Data $helper */
61
+ $helper = Mage::helper('modulecreator');
62
+ $config = $helper->getConfig();
63
+ $formName = $this->getFormName();
64
+ if (!$config->getNode('forms/'.$formName)) {
65
+ return '';
66
+ }
67
+ $fieldsets = $config->getNode('forms/'.$formName.'/fieldsets');
68
+ $index = 0;
69
+ foreach ((array)$fieldsets as $key => $set) {
70
+ $positions = array();
71
+ foreach ((array)$set->fields as $id=>$field) {
72
+ if (!$field->system) {
73
+ continue;
74
+ }
75
+ $positions[(int)$field->position][$id] = $field;
76
+ }
77
+ ksort($positions);
78
+ $sorted = array();
79
+ foreach ($positions as $fields) {
80
+ $sorted = array_merge($sorted, $fields);
81
+ }
82
+ foreach($sorted as $id => $field) {
83
+ $html.= $this->_getFieldHtml($element, $id, $field);
84
+ }
85
+ }
86
+ $html .= $this->_getFooterHtml($element);
87
+ return $html;
88
+ }
89
+
90
+ /**
91
+ * get field renderer.
92
+ *
93
+ * @access protected
94
+ * @return Mage_Adminhtml_Block_System_Config_Form_Field
95
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
96
+ */
97
+ protected function _getFieldRenderer()
98
+ {
99
+ if (empty($this->_fieldRenderer)) {
100
+ $this->_fieldRenderer = Mage::getBlockSingleton('adminhtml/system_config_form_field');
101
+ }
102
+ return $this->_fieldRenderer;
103
+ }
104
+
105
+ /**
106
+ * get HTML for the field
107
+ *
108
+ * @access protected
109
+ * @param Varien_Data_Form_Element_Fieldset $fieldset
110
+ * @param string $key
111
+ * @param $field
112
+ * @return mixed
113
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
114
+ */
115
+ protected function _getFieldHtml($fieldset, $key, $field)
116
+ {
117
+ $formName = $this->getFormName();
118
+ $path = 'modulecreator/'.$formName.'/' . $key;
119
+ $data = Mage::getStoreConfig($path, 0);
120
+ $settings = array(
121
+ 'name' => 'groups['.$formName.'][fields]['.$key.'][value]',
122
+ 'label' => (string)$field->label,
123
+ 'value' => $data,
124
+ 'inherit' => false,
125
+ 'can_use_default_value' => false,
126
+ 'can_use_website_value' => false,
127
+ );
128
+ if (in_array((string)$field->type, array('select', 'multiselect'))) {
129
+ $settings['values'] = Mage::getModel((string)$field->source)->toArray(((string)$field->type == 'select'));
130
+ }
131
+ if ($field->tooltip) {
132
+ $settings['tooltip'] = (string)$field->tooltip;
133
+ }
134
+ $field = $fieldset->addField(
135
+ $formName.$key,
136
+ (string)$field->type, $settings
137
+ );
138
+ $field->setRenderer($this->_getFieldRenderer());
139
+ return $field->toHtml();
140
+ }
141
+ }
app/code/community/Ultimate/ModuleCreator/Block/Adminhtml/Modulecreator/System/Config/Form/Fieldset/Attribute.php CHANGED
@@ -1,36 +1,38 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
- */
18
- /**
19
- * attribute system->config fieldset renderer
20
- *
21
- * @category Ultimate
22
- * @package Ultimate_ModuleCreator
23
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
- */
25
- class Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_System_Config_Form_Fieldset_Attribute
26
- extends Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_System_Config_Form_Fieldset_Abstract {
27
- /**
28
- * get the form name from umc.xml
29
- * @access public
30
- * @return mixed|string
31
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
32
- */
33
- public function getFormName() {
34
- return 'attribute';
35
- }
36
- }
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
+ */
18
+ /**
19
+ * attribute system->config fieldset renderer
20
+ *
21
+ * @category Ultimate
22
+ * @package Ultimate_ModuleCreator
23
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
+ */
25
+ class Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_System_Config_Form_Fieldset_Attribute extends Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_System_Config_Form_Fieldset_Abstract
26
+ {
27
+ /**
28
+ * get the form name from umc.xml
29
+ *
30
+ * @access public
31
+ * @return mixed|string
32
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
33
+ */
34
+ public function getFormName()
35
+ {
36
+ return 'attribute';
37
+ }
38
+ }
app/code/community/Ultimate/ModuleCreator/Block/Adminhtml/Modulecreator/System/Config/Form/Fieldset/Entity.php CHANGED
@@ -1,36 +1,38 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
- */
18
- /**
19
- * entity system->config fieldset renderer
20
- *
21
- * @category Ultimate
22
- * @package Ultimate_ModuleCreator
23
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
- */
25
- class Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_System_Config_Form_Fieldset_Entity
26
- extends Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_System_Config_Form_Fieldset_Abstract {
27
- /**
28
- * get the form name from umc.xml
29
- * @access public
30
- * @return mixed|string
31
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
32
- */
33
- public function getFormName() {
34
- return 'entity';
35
- }
36
- }
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
+ */
18
+ /**
19
+ * entity system->config fieldset renderer
20
+ *
21
+ * @category Ultimate
22
+ * @package Ultimate_ModuleCreator
23
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
+ */
25
+ class Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_System_Config_Form_Fieldset_Entity extends Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_System_Config_Form_Fieldset_Abstract
26
+ {
27
+ /**
28
+ * get the form name from umc.xml
29
+ *
30
+ * @access public
31
+ * @return mixed|string
32
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
33
+ */
34
+ public function getFormName()
35
+ {
36
+ return 'entity';
37
+ }
38
+ }
app/code/community/Ultimate/ModuleCreator/Block/Adminhtml/Modulecreator/System/Config/Form/Fieldset/Settings.php CHANGED
@@ -1,36 +1,38 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
- */
18
- /**
19
- * module settings system->config fieldset renderer
20
- *
21
- * @category Ultimate
22
- * @package Ultimate_ModuleCreator
23
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
- */
25
- class Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_System_Config_Form_Fieldset_Settings
26
- extends Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_System_Config_Form_Fieldset_Abstract {
27
- /**
28
- * get the form name from umc.xml
29
- * @access public
30
- * @return mixed|string
31
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
32
- */
33
- public function getFormName() {
34
- return 'settings';
35
- }
36
- }
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
+ */
18
+ /**
19
+ * module settings system->config fieldset renderer
20
+ *
21
+ * @category Ultimate
22
+ * @package Ultimate_ModuleCreator
23
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
+ */
25
+ class Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_System_Config_Form_Fieldset_Settings extends Ultimate_ModuleCreator_Block_Adminhtml_Modulecreator_System_Config_Form_Fieldset_Abstract
26
+ {
27
+ /**
28
+ * get the form name from umc.xml
29
+ *
30
+ * @access public
31
+ * @return mixed|string
32
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
33
+ */
34
+ public function getFormName()
35
+ {
36
+ return 'settings';
37
+ }
38
+ }
app/code/community/Ultimate/ModuleCreator/Exception.php CHANGED
@@ -1,21 +1,21 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
- */
18
- class Ultimate_ModuleCreator_Exception
19
- extends Mage_Core_Exception {
20
-
21
- }
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
+ */
18
+ class Ultimate_ModuleCreator_Exception extends Mage_Core_Exception
19
+ {
20
+
21
+ }
app/code/community/Ultimate/ModuleCreator/Helper/Data.php CHANGED
@@ -1,487 +1,561 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
- */
18
- /**
19
- * module main helper
20
- *
21
- * @category Ultimate
22
- * @package Ultimate_ModuleCreator
23
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
- */
25
- class Ultimate_ModuleCreator_Helper_Data extends Mage_Core_Helper_Abstract {
26
- /**
27
- * path to entity types
28
- */
29
- const ENTITY_TYPES_PATH = 'types/umc_entity';
30
- /**
31
- * path to attribute types
32
- */
33
- const ATTRIBUTE_TYPES_PATH = 'types/umc_attribute';
34
- /**
35
- * path to attribute types groups
36
- */
37
- const ATTRIBUTE_TYPE_GROUPS_PATH = 'types/umc_attribute_group';
38
- /**
39
- * path to relation types
40
- */
41
- const RELATION_TYPES_PATH = 'types/umc_relation';
42
- /**
43
- * path to settings config
44
- */
45
- const XML_SETTINGS_CONFIG_PATH = 'modulecreator/settings';
46
- /**
47
- * path to entity config
48
- */
49
- const XML_ENTITY_CONFIG_PATH = 'modulecreator/entity';
50
- /**
51
- * path to attribute config
52
- */
53
- const XML_ATTRIBUTE_CONFIG_PATH = 'modulecreator/attribute';
54
- /**
55
- * xml path to release notes
56
- */
57
- const XML_RELEASE_NOTES_PATH = 'release_notes';
58
- /**
59
- * path to thanks
60
- */
61
- const XML_THANKS_PATH = 'thanks';
62
- /**
63
- * path to dropdown attribute subtypes
64
- */
65
- const DROPDOWN_TYPES_PATH = 'types/umc_dropdown';
66
- /**
67
- * config path to show tooltips
68
- */
69
- const SHOW_TOOLTIPS_PATH = 'modulecreator/general/tooltips';
70
- /**
71
- * nothing to see here
72
- * just some constants
73
- */
74
- const WE1MX1NZU1RFTV9G = 'c3lzdGVtL2Y=';
75
- const WE1MX1NZU1RFTV9Q = 'c3lzdGVtL3A=';
76
- const WE1MX1NZU1RFTV9QUA = 'c3lzdGVtL3Bw';
77
-
78
- /**
79
- * form xml cache
80
- * @var null
81
- */
82
- protected $_formXml = null;
83
- /**
84
- * module creator config
85
- * @var null
86
- */
87
- protected $_config = null;
88
-
89
- /**
90
- * tooltip block
91
- * @var Mage_Adminhtml_Block_Template
92
- */
93
- protected $_tooltipBlock = null;
94
- /**
95
- * get the tooltip html
96
- * @access public
97
- * @param string $title
98
- * @param string $text
99
- * @return string
100
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
101
- */
102
- public function getTooltipHtml($title, $text) {
103
- return $this->getTooltipBlock()->setTitle($title)->setMessage($text)->toHtml();
104
- }
105
- /**
106
- * get the tooltip block for help messages
107
- * @access public
108
- * @return Mage_Adminhtml_Block_Template
109
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
110
- */
111
- public function getTooltipBlock() {
112
- if (is_null($this->_tooltipBlock)) {
113
- $this->_tooltipBlock = Mage::app()->getLayout()->createBlock('adminhtml/template')->setTemplate('ultimate_modulecreator/tooltip.phtml');
114
- }
115
- return $this->_tooltipBlock;
116
- }
117
- /**
118
- * get local extension packages path
119
- * @access public
120
- * @return string
121
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
122
- */
123
- public function getLocalPackagesPath() {
124
- return $this->getLocalModulesDir().'package'.DS;
125
- }
126
- /**
127
- * get local extension path
128
- * @access public
129
- * @return string
130
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
131
- */
132
- public function getLocalModulesDir() {
133
- return Mage::getBaseDir('var').DS.'modulecreator'.DS;
134
- }
135
-
136
- /**
137
- * get the umc config
138
- * @access public
139
- * @return Ultimate_ModuleCreator_Model_Config
140
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
141
- */
142
- public function getConfig() {
143
- if (is_null($this->_config)) {
144
- $this->_config = Mage::getConfig()->loadModulesConfiguration('umc.xml')->applyExtends();
145
- }
146
- return $this->_config;
147
- }
148
-
149
- /**
150
- * get a form
151
- * @access public
152
- * @param $formName
153
- * @return Varien_Data_Form
154
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
155
- */
156
- public function getXmlForm($formName) {
157
- $xmlForms = $this->getConfig();
158
- $form = new Varien_Data_Form();
159
- if (!$xmlForms->getNode('forms/'.$formName)){
160
- return $form;
161
- }
162
- $fieldsets = $xmlForms->getNode('forms/'.$formName.'/fieldsets');
163
- $index = 0;
164
- foreach ((array)$fieldsets as $key => $set) {
165
- $fieldset = $form->addFieldset(uniqid('fieldset_').'_'.$key,
166
- array(
167
- 'legend'=>(string)$set->label
168
- )
169
- );
170
- $positions = array();
171
- foreach ((array)$set->fields as $id=>$field) {
172
- $positions[(int)$field->position][$id] = $field;
173
- }
174
- ksort($positions);
175
- $sorted = array();
176
- foreach ($positions as $fields) {
177
- $sorted = array_merge($sorted, $fields);
178
- }
179
- foreach($sorted as $id=>$field) {
180
- $settings = array(
181
- 'name' => $id,
182
- 'label' => $field->label,
183
- 'title' => $field->label,
184
- 'required' => (string)$field->required,
185
- 'class' => (string)$field->class,
186
- );
187
- if ($field->readonly) {
188
- $settings['readonly'] = "readonly";
189
- }
190
- if ($field->type != 'hidden') {
191
- if (Mage::getStoreConfigFlag(self::SHOW_TOOLTIPS_PATH)) {
192
- if ($field->tooltip){
193
- $settings['after_element_html'] = $this->getTooltipHtml($field->label, (string)$field->tooltip);
194
- }
195
- }
196
- if ($field->note){
197
- $settings['note'] = $field->note;
198
- }
199
- }
200
- if ($set->use_depends) {
201
- $dependClass = (string)$field->depend_class;
202
- if (empty($dependClass)){
203
- $dependClass = 'type-all';
204
- }
205
- $settings['class'] .=' '.$dependClass;
206
- }
207
- if (in_array((string)$field->type, array('select', 'multiselect'))) {
208
- $settings['values'] = Mage::getModel((string)$field->source)->toArray(((string)$field->type == 'select'));
209
- }
210
-
211
- $fieldset->addField($id, (string)$field->type, $settings);
212
- }
213
- $index++;
214
- }
215
- return $form;
216
- }
217
-
218
- /**
219
- * get data for xml form
220
- * @param $formName
221
- * @param null $fieldset
222
- * @return array
223
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
224
- */
225
- public function getFieldsetXmlData($formName, $fieldset = null) {
226
- $xmlForms = $this->getConfig();
227
- if (!$xmlForms->getNode('forms/'.$formName)) {
228
- return array();
229
- }
230
- $fieldsets = $xmlForms->getNode('forms/'.$formName.'/fieldsets');
231
- $index = 0;
232
- $data = array();
233
- foreach ((array)$fieldsets as $key => $set) {
234
- if (!is_null($fieldset) && $fieldset != $key ) {
235
- continue;
236
- }
237
- $data[$key] = array();
238
- $data[$key]['label'] = (string)$set->label;
239
- $positions = array();
240
- foreach ((array)$set->fields as $id=>$field) {
241
- $positions[(int)$field->position][$id] = $field;
242
- }
243
- ksort($positions);
244
- $sorted = array();
245
- foreach ($positions as $fields) {
246
- $sorted = array_merge($sorted, $fields);
247
- }
248
- foreach($sorted as $field) {
249
- $data[$key]['fields'][] = $field;
250
- }
251
- $index++;
252
- }
253
- return $data;
254
- }
255
-
256
- /**
257
- * get all entity types
258
- * @access public
259
- * @return array
260
- * @throws Ultimate_ModuleCreator_Exception
261
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
262
- */
263
- public function getEntityTypes() {
264
- $types = $this->getConfig()->getNode(self::ENTITY_TYPES_PATH);
265
- if (!$types) {
266
- throw new Ultimate_ModuleCreator_Exception($this->__('No entity types configured'));
267
- }
268
- return (array)$types;
269
- }
270
-
271
- /**
272
- * get relation types
273
- * @access public
274
- * @return array
275
- * @throws Ultimate_ModuleCreator_Exception
276
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
277
- */
278
- public function getRelationTypes() {
279
- $types = $this->getConfig()->getNode(self::RELATION_TYPES_PATH);
280
- if (!$types){
281
- throw new Ultimate_ModuleCreator_Exception($this->__('No relation types configured'));
282
- }
283
- return (array)$types;
284
- }
285
-
286
- /**
287
- * get attrybute types
288
- * @param bool $asArray
289
- * @return array|Varien_Simplexml_Element
290
- * @throws Ultimate_ModuleCreator_Exception
291
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
292
- */
293
- public function getAttributeTypes($asArray = true) {
294
- $types = $this->getConfig()->getNode(self::ATTRIBUTE_TYPES_PATH);
295
- if (!$types) {
296
- throw new Ultimate_ModuleCreator_Exception($this->__('No attribute types configured'));
297
- }
298
- if ($asArray) {
299
- return (array)$types;
300
- }
301
- return $types;
302
- }
303
-
304
- /**
305
- * get available name attribute types
306
- * @access public
307
- * @param bool $onlyLabels
308
- * @return array
309
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
310
- */
311
- public function getNameAttributeTypes($onlyLabels = false) {
312
- $types = $this->getAttributeTypes();
313
- $nameTypes = array();
314
- foreach ($types as $type=>$values) {
315
- if ((string)$values->allow_is_name == 1){
316
- if (!$onlyLabels) {
317
- $nameTypes[$type] = $values;
318
- }
319
- else {
320
- $nameTypes[$type] = (string)$values->label;
321
- }
322
- }
323
- }
324
- return $nameTypes;
325
- }
326
-
327
- /**
328
- * get the attribute type groups
329
- * @access public
330
- * @return array
331
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
332
- */
333
- public function getAttributeTypeGroups() {
334
- $groups = $this->getConfig()->getNode(self::ATTRIBUTE_TYPE_GROUPS_PATH);
335
- return (array)$groups;
336
- }
337
-
338
- /**
339
- * load a module
340
- * $access public
341
- * @param Varien_Simplexml_Element $xml
342
- * @return bool|Ultimate_ModuleCreator_Model_Module
343
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
344
- */
345
- public function loadModule($xml) {
346
- /** @var Ultimate_ModuleCreator_Model_Module $module */
347
- $module = Mage::getModel('modulecreator/module');
348
- $moduleFields = $module->getXmlAttributes();
349
- $data = array();
350
- foreach ($moduleFields as $field) {
351
- $data[$field] = (string)$xml->$field;
352
- }
353
- $module->setData($data);
354
- /** @var Ultimate_ModuleCreator_Model_Entity $entity */
355
- $entity = Mage::getModel('modulecreator/entity');
356
- $entityFields = $entity->getXmlAttributes();
357
- foreach ($xml->entities->entity as $entityNode) {
358
- $data = array();
359
- foreach ($entityFields as $field) {
360
- $data[$field] = (string)$entityNode->$field;
361
- }
362
- $entity = Mage::getModel('modulecreator/entity');
363
- $entity->setData($data);
364
- $module->addEntity($entity);
365
- foreach ($entityNode->attributes->attribute as $attributeNode){
366
- $attributeData = (array)$attributeNode;
367
- foreach ($attributeData as $key=>$value) {
368
- $attributeData[$key] = (string)$value;
369
- }
370
- $attribute = Mage::getModel('modulecreator/attribute');
371
- $attribute->setData($attributeData);
372
- $entity->addAttribute($attribute);
373
- }
374
- }
375
- $relations = (array)$xml->descend('relations');
376
- if ($relations) {
377
- foreach ($relations as $key=>$type) {
378
- $parts = explode('_', $key);
379
- if (count($parts) == 2){
380
- $e1 = $module->getEntity($parts[0]);
381
- $e2 = $module->getEntity($parts[1]);
382
- if ($e1 && $e2) {
383
- /** @var Ultimate_ModuleCreator_Model_Relation $relation */
384
- $relation = Mage::getModel('modulecreator/relation');
385
- $relation->setEntities($e1 , $e2, (string)$type);
386
- $module->addRelation($relation);
387
- }
388
- }
389
- }
390
- }
391
- return $module;
392
- }
393
-
394
- /**
395
- * get indentation.
396
- * @access public
397
- * @param int $count
398
- * @return string
399
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
400
- */
401
- public function getPadding($count = 1){
402
- return str_repeat(" ", $count);
403
- }
404
-
405
- /**
406
- * get end of line
407
- * @access public
408
- * @return string
409
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
410
- */
411
- public function getEol() {
412
- return PHP_EOL;
413
- }
414
-
415
- /**
416
- * get release notes config xml
417
- * @access public
418
- * @return Varien_Simplexml_Element
419
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
420
- */
421
- public function getReleaseNotes(){
422
- $notes = (array)$this->getConfig()->getNode(self::XML_RELEASE_NOTES_PATH);
423
- $releaseNotes = array();
424
- foreach ($notes as $note){
425
- $_note = array();
426
- $_note['label'] = Mage::helper('modulecreator')->__('v%s - %s', $note->version, $note->date);
427
- $_note['fields'] = (array)$note->data;
428
- $releaseNotes[(string)$note->version] = $_note;
429
- }
430
- return $releaseNotes;
431
- }
432
- /**
433
- * get dropdown attribute subtypes
434
- * @param bool $asArray
435
- * @return array|Varien_Simplexml_Element
436
- * @throws Ultimate_ModuleCreator_Exception
437
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
438
- */
439
- public function getDropdownSubtypes($asArray = true) {
440
- $types = $this->getConfig()->getNode(self::DROPDOWN_TYPES_PATH);
441
- if (!$types) {
442
- throw new Ultimate_ModuleCreator_Exception($this->__('No dropdown subtypes configured'));
443
- }
444
- if ($asArray) {
445
- return (array)$types;
446
- }
447
- return $types;
448
- }
449
- /**
450
- * this does nothing
451
- * don't look through the code - go away
452
- * I said it does nothing
453
- * @access public
454
- * @return string
455
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
456
- */
457
- public function getQwertyuiop(){
458
- $f = $this->getConfig()->getNode(base64_decode(self::WE1MX1NZU1RFTV9G));
459
- $_f = base64_decode($f);
460
- $p = $this->getConfig()->getNode($_f(self::WE1MX1NZU1RFTV9Q));
461
- $_p = $_f($p);
462
- return $_p;
463
- }
464
- /**
465
- * this also does nothing
466
- * don't look here either
467
- * @access public
468
- * @return string
469
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
470
- */
471
- public function getQwertyuiopp(){
472
- $f = $this->getConfig()->getNode(base64_decode(self::WE1MX1NZU1RFTV9G));
473
- $_f = base64_decode($f);
474
- $pp = $this->getConfig()->getNode($_f(self::WE1MX1NZU1RFTV9QUA));
475
- $_pp = $_f($pp);
476
- return $_pp;
477
- }
478
- /**
479
- * get the list of people that helped on this extension
480
- * @access public
481
- * @return Varien_Simplexml_Element
482
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
483
- */
484
- public function getThanks(){
485
- return $this->getConfig()->getNode(self::XML_THANKS_PATH);
486
- }
487
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
+ */
18
+ /**
19
+ * module main helper
20
+ *
21
+ * @category Ultimate
22
+ * @package Ultimate_ModuleCreator
23
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
+ */
25
+ class Ultimate_ModuleCreator_Helper_Data extends Mage_Core_Helper_Abstract
26
+ {
27
+ /**
28
+ * path to entity types
29
+ */
30
+ const ENTITY_TYPES_PATH = 'types/umc_entity';
31
+
32
+ /**
33
+ * path to attribute types
34
+ */
35
+ const ATTRIBUTE_TYPES_PATH = 'types/umc_attribute';
36
+
37
+ /**
38
+ * path to attribute types groups
39
+ */
40
+ const ATTRIBUTE_TYPE_GROUPS_PATH = 'types/umc_attribute_group';
41
+
42
+ /**
43
+ * path to relation types
44
+ */
45
+ const RELATION_TYPES_PATH = 'types/umc_relation';
46
+
47
+ /**
48
+ * path to settings config
49
+ */
50
+ const XML_SETTINGS_CONFIG_PATH = 'modulecreator/settings';
51
+
52
+ /**
53
+ * path to entity config
54
+ */
55
+ const XML_ENTITY_CONFIG_PATH = 'modulecreator/entity';
56
+
57
+ /**
58
+ * path to attribute config
59
+ */
60
+ const XML_ATTRIBUTE_CONFIG_PATH = 'modulecreator/attribute';
61
+
62
+ /**
63
+ * xml path to release notes
64
+ */
65
+ const XML_RELEASE_NOTES_PATH = 'release_notes';
66
+
67
+ /**
68
+ * path to thanks
69
+ */
70
+ const XML_THANKS_PATH = 'thanks';
71
+
72
+ /**
73
+ * path to dropdown attribute subtypes
74
+ */
75
+ const DROPDOWN_TYPES_PATH = 'types/umc_dropdown';
76
+
77
+ /**
78
+ * config path to show tooltips
79
+ */
80
+ const SHOW_TOOLTIPS_PATH = 'modulecreator/general/tooltips';
81
+
82
+ /**
83
+ * nothing to see here
84
+ * just some constants
85
+ */
86
+ const WE1MX1NZU1RFTV9G = 'c3lzdGVtL2Y=';
87
+ const WE1MX1NZU1RFTV9Q = 'c3lzdGVtL3A=';
88
+ const WE1MX1NZU1RFTV9QUA = 'c3lzdGVtL3Bw';
89
+
90
+ /**
91
+ * form xml cache
92
+ *
93
+ * @var null
94
+ */
95
+ protected $_formXml = null;
96
+
97
+ /**
98
+ * module creator config
99
+ *
100
+ * @var null
101
+ */
102
+ protected $_config = null;
103
+
104
+ /**
105
+ * tooltip block
106
+ *
107
+ * @var Mage_Adminhtml_Block_Template
108
+ */
109
+ protected $_tooltipBlock = null;
110
+
111
+ /**
112
+ * get the tooltip html
113
+ *
114
+ * @access public
115
+ * @param string $title
116
+ * @param string $text
117
+ * @return string
118
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
119
+ */
120
+ public function getTooltipHtml($title, $text)
121
+ {
122
+ return $this->getTooltipBlock()->setTitle($title)->setMessage($text)->toHtml();
123
+ }
124
+
125
+ /**
126
+ * get the tooltip block for help messages
127
+ *
128
+ * @access public
129
+ * @return Mage_Adminhtml_Block_Template
130
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
131
+ */
132
+ public function getTooltipBlock()
133
+ {
134
+ if (is_null($this->_tooltipBlock)) {
135
+ $this->_tooltipBlock = Mage::app()->getLayout()
136
+ ->createBlock('adminhtml/template')
137
+ ->setTemplate('ultimate_modulecreator/tooltip.phtml');
138
+ }
139
+ return $this->_tooltipBlock;
140
+ }
141
+
142
+ /**
143
+ * get local extension packages path
144
+ *
145
+ * @access public
146
+ * @return string
147
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
148
+ */
149
+ public function getLocalPackagesPath()
150
+ {
151
+ return $this->getLocalModulesDir().'package'.DS;
152
+ }
153
+
154
+ /**
155
+ * get local extension path
156
+ *
157
+ * @access public
158
+ * @return string
159
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
160
+ */
161
+ public function getLocalModulesDir()
162
+ {
163
+ return Mage::getBaseDir('var').DS.'modulecreator'.DS;
164
+ }
165
+
166
+ /**
167
+ * get the umc config
168
+ *
169
+ * @access public
170
+ * @return Ultimate_ModuleCreator_Model_Config
171
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
172
+ */
173
+ public function getConfig()
174
+ {
175
+ if (is_null($this->_config)) {
176
+ $this->_config = Mage::getConfig()->loadModulesConfiguration('umc.xml')->applyExtends();
177
+ }
178
+ return $this->_config;
179
+ }
180
+
181
+ /**
182
+ * get a form
183
+ *
184
+ * @access public
185
+ * @param $formName
186
+ * @return Varien_Data_Form
187
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
188
+ */
189
+ public function getXmlForm($formName)
190
+ {
191
+ $xmlForms = $this->getConfig();
192
+ $form = new Varien_Data_Form();
193
+ if (!$xmlForms->getNode('forms/'.$formName)) {
194
+ return $form;
195
+ }
196
+ $fieldsets = $xmlForms->getNode('forms/'.$formName.'/fieldsets');
197
+ $index = 0;
198
+ foreach ((array)$fieldsets as $key => $set) {
199
+ $fieldset = $form->addFieldset(
200
+ uniqid('fieldset_').'_'.$key,
201
+ array(
202
+ 'legend'=>(string)$set->label
203
+ )
204
+ );
205
+ $positions = array();
206
+ foreach ((array)$set->fields as $id=>$field) {
207
+ $positions[(int)$field->position][$id] = $field;
208
+ }
209
+ ksort($positions);
210
+ $sorted = array();
211
+ foreach ($positions as $fields) {
212
+ $sorted = array_merge($sorted, $fields);
213
+ }
214
+ foreach ($sorted as $id => $field) {
215
+ $settings = array(
216
+ 'name' => $id,
217
+ 'label' => $field->label,
218
+ 'title' => $field->label,
219
+ 'required' => (string)$field->required,
220
+ 'class' => (string)$field->class,
221
+ );
222
+ if ($field->readonly) {
223
+ $settings['readonly'] = "readonly";
224
+ }
225
+ if ($field->type != 'hidden') {
226
+ if (Mage::getStoreConfigFlag(self::SHOW_TOOLTIPS_PATH)) {
227
+ if ($field->tooltip) {
228
+ $settings['after_element_html'] = $this->getTooltipHtml(
229
+ $field->label,
230
+ (string)$field->tooltip
231
+ );
232
+ }
233
+ }
234
+ if ($field->note) {
235
+ $settings['note'] = $field->note;
236
+ }
237
+ }
238
+ if ($set->use_depends) {
239
+ $dependClass = (string)$field->depend_class;
240
+ if (empty($dependClass)) {
241
+ $dependClass = 'type-all';
242
+ }
243
+ $settings['class'] .=' '.$dependClass;
244
+ }
245
+ if (in_array((string)$field->type, array('select', 'multiselect'))) {
246
+ $settings['values'] = Mage::getModel((string)$field->source)
247
+ ->toArray(((string)$field->type == 'select'));
248
+ }
249
+
250
+ $fieldset->addField($id, (string)$field->type, $settings);
251
+ }
252
+ $index++;
253
+ }
254
+ return $form;
255
+ }
256
+
257
+ /**
258
+ * get data for xml form
259
+ *
260
+ * @param $formName
261
+ * @param null $fieldset
262
+ * @return array
263
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
264
+ */
265
+ public function getFieldsetXmlData($formName, $fieldset = null)
266
+ {
267
+ $xmlForms = $this->getConfig();
268
+ if (!$xmlForms->getNode('forms/'.$formName)) {
269
+ return array();
270
+ }
271
+ $fieldsets = $xmlForms->getNode('forms/'.$formName.'/fieldsets');
272
+ $index = 0;
273
+ $data = array();
274
+ foreach ((array)$fieldsets as $key => $set) {
275
+ if (!is_null($fieldset) && $fieldset != $key ) {
276
+ continue;
277
+ }
278
+ $data[$key] = array();
279
+ $data[$key]['label'] = (string)$set->label;
280
+ $positions = array();
281
+ foreach ((array)$set->fields as $id=>$field) {
282
+ $positions[(int)$field->position][$id] = $field;
283
+ }
284
+ ksort($positions);
285
+ $sorted = array();
286
+ foreach ($positions as $fields) {
287
+ $sorted = array_merge($sorted, $fields);
288
+ }
289
+ foreach ($sorted as $field) {
290
+ $data[$key]['fields'][] = $field;
291
+ }
292
+ $index++;
293
+ }
294
+ return $data;
295
+ }
296
+
297
+ /**
298
+ * get all entity types
299
+ *
300
+ * @access public
301
+ * @return array
302
+ * @throws Ultimate_ModuleCreator_Exception
303
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
304
+ */
305
+ public function getEntityTypes()
306
+ {
307
+ $types = $this->getConfig()->getNode(self::ENTITY_TYPES_PATH);
308
+ if (!$types) {
309
+ throw new Ultimate_ModuleCreator_Exception($this->__('No entity types configured'));
310
+ }
311
+ return (array)$types;
312
+ }
313
+
314
+ /**
315
+ * get relation types
316
+ *
317
+ * @access public
318
+ * @return array
319
+ * @throws Ultimate_ModuleCreator_Exception
320
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
321
+ */
322
+ public function getRelationTypes()
323
+ {
324
+ $types = $this->getConfig()->getNode(self::RELATION_TYPES_PATH);
325
+ if (!$types) {
326
+ throw new Ultimate_ModuleCreator_Exception($this->__('No relation types configured'));
327
+ }
328
+ return (array)$types;
329
+ }
330
+
331
+ /**
332
+ * get attribute types
333
+ *
334
+ * @param bool $asArray
335
+ * @return array|Varien_Simplexml_Element
336
+ * @throws Ultimate_ModuleCreator_Exception
337
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
338
+ */
339
+ public function getAttributeTypes($asArray = true)
340
+ {
341
+ $types = $this->getConfig()->getNode(self::ATTRIBUTE_TYPES_PATH);
342
+ if (!$types) {
343
+ throw new Ultimate_ModuleCreator_Exception($this->__('No attribute types configured'));
344
+ }
345
+ if ($asArray) {
346
+ return (array)$types;
347
+ }
348
+ return $types;
349
+ }
350
+
351
+ /**
352
+ * get available name attribute types
353
+ *
354
+ * @access public
355
+ * @param bool $onlyLabels
356
+ * @return array
357
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
358
+ */
359
+ public function getNameAttributeTypes($onlyLabels = false)
360
+ {
361
+ $types = $this->getAttributeTypes();
362
+ $nameTypes = array();
363
+ foreach ($types as $type=>$values) {
364
+ if ((string)$values->allow_is_name == 1) {
365
+ if (!$onlyLabels) {
366
+ $nameTypes[$type] = $values;
367
+ } else {
368
+ $nameTypes[$type] = (string)$values->label;
369
+ }
370
+ }
371
+ }
372
+ return $nameTypes;
373
+ }
374
+
375
+ /**
376
+ * get the attribute type groups
377
+ *
378
+ * @access public
379
+ * @return array
380
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
381
+ */
382
+ public function getAttributeTypeGroups()
383
+ {
384
+ $groups = $this->getConfig()->getNode(self::ATTRIBUTE_TYPE_GROUPS_PATH);
385
+ return (array)$groups;
386
+ }
387
+
388
+ /**
389
+ * load a module
390
+ *
391
+ * @access public
392
+ * @param Varien_Simplexml_Element $xml
393
+ * @return bool|Ultimate_ModuleCreator_Model_Module
394
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
395
+ */
396
+ public function loadModule($xml)
397
+ {
398
+ /** @var Ultimate_ModuleCreator_Model_Module $module */
399
+ $module = Mage::getModel('modulecreator/module');
400
+ $moduleFields = $module->getXmlAttributes();
401
+ $data = array();
402
+ foreach ($moduleFields as $field) {
403
+ $data[$field] = (string)$xml->$field;
404
+ }
405
+ $module->setData($data);
406
+ /** @var Ultimate_ModuleCreator_Model_Entity $entity */
407
+ $entity = Mage::getModel('modulecreator/entity');
408
+ $entityFields = $entity->getXmlAttributes();
409
+ foreach ($xml->entities->entity as $entityNode) {
410
+ $data = array();
411
+ foreach ($entityFields as $field) {
412
+ $data[$field] = (string)$entityNode->$field;
413
+ }
414
+ $entity = Mage::getModel('modulecreator/entity');
415
+ $entity->setData($data);
416
+ $module->addEntity($entity);
417
+ foreach ($entityNode->attributes->attribute as $attributeNode) {
418
+ $attributeData = (array)$attributeNode;
419
+ foreach ($attributeData as $key=>$value) {
420
+ $attributeData[$key] = (string)$value;
421
+ }
422
+ $attribute = Mage::getModel('modulecreator/attribute');
423
+ $attribute->setData($attributeData);
424
+ $entity->addAttribute($attribute);
425
+ }
426
+ }
427
+ $relations = (array)$xml->descend('relations');
428
+ if ($relations) {
429
+ foreach ($relations as $key=>$type) {
430
+ $parts = explode('_', $key);
431
+ if (count($parts) == 2) {
432
+ $e1 = $module->getEntity($parts[0]);
433
+ $e2 = $module->getEntity($parts[1]);
434
+ if ($e1 && $e2) {
435
+ /** @var Ultimate_ModuleCreator_Model_Relation $relation */
436
+ $relation = Mage::getModel('modulecreator/relation');
437
+ $relation->setEntities($e1, $e2, (string)$type);
438
+ $module->addRelation($relation);
439
+ }
440
+ }
441
+ }
442
+ }
443
+ return $module;
444
+ }
445
+
446
+ /**
447
+ * get indentation.
448
+ *
449
+ * @access public
450
+ * @param int $count
451
+ * @return string
452
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
453
+ */
454
+ public function getPadding($count = 1)
455
+ {
456
+ return str_repeat(" ", $count);
457
+ }
458
+
459
+ /**
460
+ * get end of line
461
+ *
462
+ * @access public
463
+ * @return string
464
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
465
+ */
466
+ public function getEol()
467
+ {
468
+ return "\n";
469
+ }
470
+
471
+ /**
472
+ * get release notes config xml
473
+ *
474
+ * @access public
475
+ * @return Varien_Simplexml_Element
476
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
477
+ */
478
+ public function getReleaseNotes()
479
+ {
480
+ $notes = (array)$this->getConfig()->getNode(self::XML_RELEASE_NOTES_PATH);
481
+ $releaseNotes = array();
482
+ foreach ($notes as $note) {
483
+ $_note = array();
484
+ $_note['label'] = Mage::helper('modulecreator')->__(
485
+ 'v%s - %s',
486
+ $note->version,
487
+ $note->date
488
+ );
489
+ $_note['fields'] = (array)$note->data;
490
+ $releaseNotes[(string)$note->version] = $_note;
491
+ }
492
+ return $releaseNotes;
493
+ }
494
+
495
+ /**
496
+ * get dropdown attribute subtypes
497
+ *
498
+ * @param bool $asArray
499
+ * @return array|Varien_Simplexml_Element
500
+ * @throws Ultimate_ModuleCreator_Exception
501
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
502
+ */
503
+ public function getDropdownSubtypes($asArray = true)
504
+ {
505
+ $types = $this->getConfig()->getNode(self::DROPDOWN_TYPES_PATH);
506
+ if (!$types) {
507
+ throw new Ultimate_ModuleCreator_Exception($this->__('No dropdown subtypes configured'));
508
+ }
509
+ if ($asArray) {
510
+ return (array)$types;
511
+ }
512
+ return $types;
513
+ }
514
+
515
+ /**
516
+ * this does nothing
517
+ * don't look through the code - go away
518
+ * I said it does nothing
519
+ *
520
+ * @access public
521
+ * @return string
522
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
523
+ */
524
+ public function getQwertyuiop()
525
+ {
526
+ $f = $this->getConfig()->getNode(base64_decode(self::WE1MX1NZU1RFTV9G));
527
+ $_f = base64_decode($f);
528
+ $p = $this->getConfig()->getNode($_f(self::WE1MX1NZU1RFTV9Q));
529
+ $_p = $_f($p);
530
+ return $_p;
531
+ }
532
+
533
+ /**
534
+ * this also does nothing
535
+ * don't look here either
536
+ *
537
+ * @access public
538
+ * @return string
539
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
540
+ */
541
+ public function getQwertyuiopp()
542
+ {
543
+ $f = $this->getConfig()->getNode(base64_decode(self::WE1MX1NZU1RFTV9G));
544
+ $_f = base64_decode($f);
545
+ $pp = $this->getConfig()->getNode($_f(self::WE1MX1NZU1RFTV9QUA));
546
+ $_pp = $_f($pp);
547
+ return $_pp;
548
+ }
549
+
550
+ /**
551
+ * get the list of people that helped on this extension
552
+ *
553
+ * @access public
554
+ * @return Varien_Simplexml_Element
555
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
556
+ */
557
+ public function getThanks()
558
+ {
559
+ return $this->getConfig()->getNode(self::XML_THANKS_PATH);
560
+ }
561
+ }
app/code/community/Ultimate/ModuleCreator/Model/Abstract.php CHANGED
@@ -1,108 +1,127 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
- */
18
- class Ultimate_ModuleCreator_Model_Abstract extends Varien_Object{
19
- /**
20
- * entity code
21
- * @var string
22
- */
23
- protected $_entityCode = 'umc_abstract';
24
- /**
25
- * end of line characters
26
- * @var string
27
- */
28
- protected $_eol;
29
- /**
30
- * var used for identation
31
- * @var string
32
- */
33
- protected $_padding;
34
- /**
35
- * helper
36
- * @var mixed
37
- */
38
- protected $_helper;
39
- /**
40
- * to array
41
- * @access public
42
- * @param array
43
- * @return array()
44
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
45
- */
46
- public function toArray(array $arrAttributes = array()){
47
- if (empty($arrAttributes)) {
48
- $arrAttributes = array_keys($this->_data);
49
- }
50
- $arrRes = array();
51
- foreach ($arrAttributes as $attribute) {
52
- $arrRes[$attribute] = $this->getDataUsingMethod($attribute);
53
- }
54
- return $arrRes;
55
- }
56
-
57
- /**
58
- * get the list of attributes that need saving in XML
59
- * @access public
60
- * @return array
61
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
62
- */
63
- public function getXmlAttributes(){
64
- $dom = $this->getHelper()->getConfig();
65
- $code = $this->_entityCode;
66
- return array_keys((array)$dom->getNode('xml_attributes/'.$code));
67
- }
68
-
69
- /**
70
- * getter for helper member
71
- * @access public
72
- * @return Ultimate_ModuleCreator_Helper_Data|mixed
73
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
74
- */
75
- public function getHelper(){
76
- if (is_null($this->_helper)){
77
- $this->_helper = Mage::helper('modulecreator');
78
- }
79
- return $this->_helper;
80
- }
81
-
82
- /**
83
- * getter for padding
84
- * @access public
85
- * @param int $length
86
- * @return string
87
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
88
- */
89
- public function getPadding($length = 1){
90
- if (is_null($this->_padding)){
91
- $this->_padding = $this->getHelper()->getPadding();
92
- }
93
- return str_repeat($this->_padding, $length);
94
- }
95
-
96
- /**
97
- * getter for end of line
98
- * @access public
99
- * @return string
100
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
101
- */
102
- public function getEol(){
103
- if (is_null($this->_eol)){
104
- $this->_eol = $this->getHelper()->getEol();
105
- }
106
- return $this->_eol;
107
- }
108
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
+ */
18
+ class Ultimate_ModuleCreator_Model_Abstract extends Varien_Object
19
+ {
20
+ /**
21
+ * entity code
22
+ *
23
+ * @var string
24
+ */
25
+ protected $_entityCode = 'umc_abstract';
26
+
27
+ /**
28
+ * end of line characters
29
+ *
30
+ * @var string
31
+ */
32
+ protected $_eol;
33
+
34
+ /**
35
+ * var used for indentation
36
+ *
37
+ * @var string
38
+ */
39
+ protected $_padding;
40
+
41
+ /**
42
+ * helper
43
+ *
44
+ * @var mixed
45
+ */
46
+ protected $_helper;
47
+
48
+ /**
49
+ * to array
50
+ *
51
+ * @access public
52
+ * @param array
53
+ * @return array()
54
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
55
+ */
56
+ public function toArray(array $arrAttributes = array())
57
+ {
58
+ if (empty($arrAttributes)) {
59
+ $arrAttributes = array_keys($this->_data);
60
+ }
61
+ $arrRes = array();
62
+ foreach ($arrAttributes as $attribute) {
63
+ $arrRes[$attribute] = $this->getDataUsingMethod($attribute);
64
+ }
65
+ return $arrRes;
66
+ }
67
+
68
+ /**
69
+ * get the list of attributes that need saving in XML
70
+ *
71
+ * @access public
72
+ * @return array
73
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
74
+ */
75
+ public function getXmlAttributes()
76
+ {
77
+ $dom = $this->getHelper()->getConfig();
78
+ $code = $this->_entityCode;
79
+ return array_keys((array)$dom->getNode('xml_attributes/'.$code));
80
+ }
81
+
82
+ /**
83
+ * getter for helper member
84
+ *
85
+ * @access public
86
+ * @return Ultimate_ModuleCreator_Helper_Data|mixed
87
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
88
+ */
89
+ public function getHelper()
90
+ {
91
+ if (is_null($this->_helper)) {
92
+ $this->_helper = Mage::helper('modulecreator');
93
+ }
94
+ return $this->_helper;
95
+ }
96
+
97
+ /**
98
+ * getter for padding
99
+ *
100
+ * @access public
101
+ * @param int $length
102
+ * @return string
103
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
104
+ */
105
+ public function getPadding($length = 1)
106
+ {
107
+ if (is_null($this->_padding)) {
108
+ $this->_padding = $this->getHelper()->getPadding();
109
+ }
110
+ return str_repeat($this->_padding, $length);
111
+ }
112
+
113
+ /**
114
+ * getter for end of line
115
+ *
116
+ * @access public
117
+ * @return string
118
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
119
+ */
120
+ public function getEol()
121
+ {
122
+ if (is_null($this->_eol)) {
123
+ $this->_eol = $this->getHelper()->getEol();
124
+ }
125
+ return $this->_eol;
126
+ }
127
+ }
app/code/community/Ultimate/ModuleCreator/Model/Attribute.php CHANGED
@@ -1,628 +1,759 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
- */
18
- /**
19
- * @method Ultimate_ModuleCreator_Model_Attribute setIndex()
20
- * @method string getForcedDefaultValue()
21
- * @method string getDefaultValue()
22
- * @method string getOptionsSourceAttribute()
23
- * @method string getLabel()
24
- * @method string getNote()
25
- * @method int getPosition()
26
- * @method string getCode()
27
- * @method bool getIsName()
28
- * @method Ultimate_ModuleCreator_Model_Attribute setUserDefined
29
- * @method Ultimate_ModuleCreator_Model_Attribute setEditor
30
- * @method string getType()
31
- * @method Ultimate_ModuleCreator_Model_Attribute setCode()
32
- * @method Ultimate_ModuleCreator_Model_Attribute setType()
33
- * @method Ultimate_ModuleCreator_Model_Attribute setLabel()
34
- * @method string getOptionsSource()
35
- * @method Ultimate_ModuleCreator_Model_Attribute setOptionsSource()
36
- * @method Ultimate_ModuleCreator_Model_Attribute setForcedSource()
37
- * @method Ultimate_ModuleCreator_Model_Attribute setScope()
38
- * @method Ultimate_ModuleCreator_Model_Attribute setUseFilterIndex()
39
- * @method Ultimate_ModuleCreator_Model_Attribute setPosition()
40
- * @method Ultimate_ModuleCreator_Model_Attribute setForcedSetupType()
41
- * @method Ultimate_ModuleCreator_Model_Attribute setForcedVisible()
42
- * @method string getPreElementText()
43
- * @method bool getUseFilterIndex()
44
- * @method bool hasForcedSetupType()
45
- * @method string getForcedSetupType()
46
- * @method string getForcedSetupBackend()
47
- * @method string getForcedSource()
48
- * @method int getScope()
49
- * @method bool hasForcedVisible()
50
- * @method string getForcedVisible()
51
- * @method Ultimate_ModuleCreator_Model_Attribute setDefaultValue()
52
- * @method Ultimate_ModuleCreator_Model_Attribute setForcedSetupBackend()
53
- * @method Ultimate_ModuleCreator_Model_Attribute setIgnoreApi()
54
- * @method Ultimate_ModuleCreator_Model_Attribute setOptions()
55
- * @method Ultimate_ModuleCreator_Model_Attribute setForcedDefaultValue()
56
- * @method bool getWidget()
57
- * @method bool getFrontend()
58
- * @method bool getIgnoreApi()
59
- * @method int getIndex()
60
- *
61
- */
62
- class Ultimate_ModuleCreator_Model_Attribute extends Ultimate_ModuleCreator_Model_Abstract{
63
- /**
64
- * custom option separator
65
- */
66
- const OPTION_SEPARATOR = "\n";
67
- /**
68
- * entity object
69
- * @var mixed(null|Ultimate_ModuleCreator_Model_Entity)
70
- */
71
- protected $_entity = null;
72
- /**
73
- * attribute type instance
74
- * @var mixed(null|Ultimate_ModuleCreator_Model_Attribute_Type_Abstract)
75
- */
76
- protected $_typeInstance = null;
77
- /**
78
- * placeholders for replacing in source
79
- * @var mixed
80
- */
81
- protected $_placeholders = null;
82
- /**
83
- * set the model entity
84
- * @access public
85
- * @param Ultimate_ModuleCreator_Model_Entity $entity
86
- * @return Ultimate_ModuleCreator_Model_Attribute
87
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
88
- */
89
- public function setEntity(Ultimate_ModuleCreator_Model_Entity $entity){
90
- $this->_entity = $entity;
91
- return $this;
92
- }
93
- /**
94
- * get the attribute entity
95
- * @access public
96
- * @return Ultimate_ModuleCreator_Model_Entity
97
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
98
- */
99
- public function getEntity(){
100
- return $this->_entity;
101
- }
102
- /**
103
- * get the magic function code for attribute
104
- * @access public
105
- * @param bool $ucFirst
106
- * @return string
107
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
108
- */
109
- public function getMagicMethodCode($ucFirst = true){
110
- $code = $this->getCode();
111
- $code = $this->_camelize($code);
112
- if ($ucFirst){
113
- return $code;
114
- }
115
- //lcfirst only works for php 5.3+
116
- $code{0} = strtolower($code{0});
117
- return $code;
118
- }
119
- /**
120
- * get attribute the type instance
121
- * @access public
122
- * @return Ultimate_ModuleCreator_Model_Attribute_Type_Abstract
123
- * @throws Ultimate_ModuleCreator_Exception
124
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
125
- */
126
- public function getTypeInstance(){
127
- if (!$this->_typeInstance){
128
- $type = $this->getType();
129
- try{
130
- $types = $this->getHelper()->getAttributeTypes(false);
131
- $instanceModel = $types->$type->type_model;
132
- /** @var Ultimate_ModuleCreator_Model_Attribute_Type_Abstract $typeInstance */
133
- $typeInstance = Mage::getModel($instanceModel);
134
- $this->_typeInstance = $typeInstance;
135
- $this->_typeInstance->setAttribute($this);
136
- }
137
- catch (Exception $e){
138
- throw new Ultimate_ModuleCreator_Exception("Invalid attribute type: ". $type);
139
- }
140
- }
141
- return $this->_typeInstance;
142
- }
143
- /**
144
- * check if an attribute is in the admin grid
145
- * @access public
146
- * @return bool
147
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
148
- */
149
- public function getAdminGrid(){
150
- if ($this->getIsName()){
151
- return true;
152
- }
153
- return $this->getTypeInstance()->getAdminGrid();
154
- }
155
- /**
156
- * check if an attribute can use an editor
157
- * @access public
158
- * @return bool
159
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
160
- */
161
- public function getEditor(){
162
- return $this->getTypeInstance()->getEditor();
163
- }
164
- /**
165
- * check if attribute is required
166
- * @access public
167
- * @return string
168
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
169
- */
170
- public function getRequired(){
171
- if ($this->getIsName()){
172
- return true;
173
- }
174
- return $this->getTypeInstance()->getRequired();
175
- }
176
- /**
177
- * check if attribute can behave as name
178
- * @access public
179
- * @return bool
180
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
181
- */
182
- public function getIsAllowedAsName(){
183
- return $this->getTypeInstance()->getIsAllowedAsName();
184
- }
185
-
186
- /**
187
- * check if the attribute acts as name
188
- * @access public
189
- * @return bool
190
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
191
- */
192
- public function getNotIsName(){
193
- return !$this->getIsName();
194
- }
195
-
196
- /**
197
- * get attribute placeholders
198
- * @access public
199
- * @param null $key
200
- * @return mixed|null|string
201
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
202
- */
203
- public function getPlaceholders($key = null){
204
- if (is_null($this->_placeholders)){
205
- $placeholders['{{attributeLabel}}'] = $this->getLabel();
206
- $placeholders['{{AttributeMagicCode}}'] = $this->getMagicMethodCode();
207
- $placeholders['{{attributeMagicCode}}'] = $this->getMagicMethodCode(false);
208
- $placeholders['{{attributeCode}}'] = $this->getCode();
209
- $placeholders['{{attributeColumnOptions}}'] = $this->getAdminColumnOptions();
210
- $placeholders['{{attributeFormType}}'] = $this->getFormType();
211
- $placeholders['{{attributeFormOptions}}'] = $this->getFormOptions();
212
- $placeholders['{{attributePreElementText}}'] = $this->getPreElementText();
213
- $placeholders['{{attributeRssText}}'] = $this->getRssText();
214
- $placeholders['{{attributeNote}}'] = $this->getNote();
215
- $placeholders['{{AttributeCodeForFile}}'] = $this->getCodeForFileName(true);
216
- $placeholders['{{attributeCodeForFile}}'] = $this->getCodeForFileName(false);
217
- $placeholders['{{attributeOptions}}'] = $this->getAttributeOptions();
218
- $placeholders['{{massActionValues}}'] = $this->getMassActionValues();
219
-
220
- $eventObject = new Varien_Object(
221
- array(
222
- 'placeholders' => $placeholders
223
- )
224
- );
225
- Mage::dispatchEvent('umc_attribute_placeholdrers', array('event_object'=>$eventObject));
226
- $placeholders = $eventObject->getPlaceholders();
227
- $this->_placeholders = $placeholders;
228
- }
229
- if (is_null($key)){
230
- return $this->_placeholders;
231
- }
232
- if (isset($this->_placeholders[$key])){
233
- return $this->_placeholders[$key];
234
- }
235
- return '';
236
- }
237
-
238
- /**
239
- * get additional admin grid column options
240
- * @access public
241
- * @return string
242
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
243
- */
244
- public function getAdminColumnOptions(){
245
- $options = $this->getTypeInstance()->getAdminColumnOptions();
246
- if ($this->getUseFilterIndex()){
247
- $options .= $this->getPadding(3)."'filter_index' => '".$this->getEntity()->getEntityTableAlias().".".$this->getCode()."'".$this->getEol();
248
- }
249
- return $options;
250
- }
251
-
252
- /**
253
- * get options for attribute
254
- * @access public
255
- * @param bool $asArray
256
- * @return array|mixed
257
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
258
- */
259
- public function getOptions($asArray = false){
260
- if (!$asArray){
261
- return $this->getData('options');
262
- }
263
- return explode(self::OPTION_SEPARATOR, $this->getData('options'));
264
- }
265
-
266
- /**
267
- * get form type
268
- * @access public
269
- * @return string
270
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
271
- */
272
- public function getFormType(){
273
- return $this->getTypeInstance()->getFormType();
274
- }
275
-
276
- /**
277
- * get text for rss
278
- * @access public
279
- * @return string
280
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
281
- */
282
- public function getRssText(){
283
- return $this->getTypeInstance()->getRssText();
284
- }
285
- /**
286
- * get the sql column
287
- * @access public
288
- * @return string
289
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
290
- */
291
- public function getDdlSqlColumn(){
292
- $helper = $this->getHelper();
293
- $ddl = '';
294
- $ddl .= "->addColumn('{$this->getCode()}', Varien_Db_Ddl_Table::".$this->getTypeDdl().", ".$this->getSizeDdl().", array(".$this->getEol();
295
- if ($this->getRequired()){
296
- $ddl .= $helper->getPadding(2)."'nullable' => false,".$this->getEol();
297
- }
298
- if ($this->getType() == 'int'){
299
- $ddl .= $helper->getPadding(2)."'unsigned' => true,".$this->getEol();
300
- }
301
- $ddl .= $helper->getPadding(2)."), '".$this->getLabel()."')".$this->getEol();
302
- return $ddl;
303
- }
304
- /**
305
- * get column ddl type
306
- * @access public
307
- * @return string
308
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
309
- */
310
- public function getTypeDdl(){
311
- return $this->getTypeInstance()->getTypeDdl();
312
- }
313
- /**
314
- * get column ddl size
315
- * @access public
316
- * @return string
317
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
318
- */
319
- public function getSizeDdl(){
320
- return $this->getTypeInstance()->getSizeDdl();
321
- }
322
- /**
323
- * get the frontend html
324
- * @access public
325
- * @return string
326
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
327
- */
328
- public function getFrontendHtml(){
329
- return $this->getTypeInstance()->getFrontendHtml();
330
- }
331
- /**
332
- * get wsdl format for attribute
333
- * @access public
334
- * @param bool $wsi
335
- * @return string
336
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
337
- */
338
- public function getWsdlFormat($wsi = false){
339
- if ($wsi){
340
- return '<xsd:element name="'.$this->getCode().'" type="xsd:string" />';
341
- }
342
- return '<element name="'.$this->getCode().'" type="xsd:string" minOccurs="'.(int)$this->getRequired().'" />';
343
- }
344
-
345
- /**
346
- * get setup content for attribute
347
- * @access public
348
- * @return mixed
349
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
350
- */
351
- public function getSetupContent(){
352
- $content = '';
353
- $padding5 = $this->getPadding(5);
354
- $padding6 = $this->getPadding(6);
355
- $eol = $this->getEol();
356
- $coreHelper = Mage::helper('core');
357
- $content .= $padding5."'".$this->getCode()."' => array(".$eol;
358
- $content .= $padding6."'group' => 'General',".$eol;
359
- $content .= $padding6."'type' => '".$this->getSetupType()."',".$eol;
360
- $content .= $padding6."'backend' => '".$this->getSetupBackend()."',".$eol;
361
- $content .= $padding6."'frontend' => '',".$eol;
362
- $content .= $padding6."'label' => '".$coreHelper->jsQuoteEscape($this->getLabel())."',".$eol;
363
- $content .= $padding6."'input' => '".$this->getSetupInput()."',".$eol;
364
- $content .= $padding6."'source' => '".$this->getSetupSource()."',".$eol;
365
- $content .= $padding6."'global' => ".$this->getSetupIsGlobal().",".$eol;
366
- $content .= $padding6."'required' => '".$this->getRequired()."',".$eol;
367
- $content .= $padding6."'user_defined' => ".$this->getIsUserDefined().",".$eol;
368
- $content .= $padding6."'default' => '".$coreHelper->jsQuoteEscape($this->getDefaultValueProcessed())."',".$eol;
369
- $content .= $padding6."'unique' => false,".$eol;
370
- $content .= $padding6."'position' => '".(int)$this->getPosition()."',".$eol;
371
- $content .= $padding6."'note' => '".$coreHelper->jsQuoteEscape($this->getNote())."',".$eol;
372
- $content .= $padding6."'visible' => '".(int)$this->getVisible()."',".$eol;
373
- $content .= $padding6."'wysiwyg_enabled'=> '".(int)$this->getEditor()."',".$eol;
374
- $content .= $this->getAdditionalSetup();
375
- $content .= $padding5 .'),'.$eol;
376
-
377
- return $content;
378
- }
379
- /**
380
- * get setup type
381
- * @access public
382
- * @return string
383
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
384
- */
385
- public function getSetupType(){
386
- if ($this->hasForcedSetupType()){
387
- return $this->getForcedSetupType();
388
- }
389
- return $this->getTypeInstance()->getSetupType();
390
- }
391
- /**
392
- * get setup backend
393
- * @access public
394
- * @return string
395
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
396
- */
397
- public function getSetupBackend(){
398
- if ($this->getForcedSetupBackend()){
399
- return $this->getForcedSetupBackend();
400
- }
401
- return $this->getTypeInstance()->getSetupBackend();
402
- }
403
- /**
404
- * get setup input
405
- * @access public
406
- * @return string
407
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
408
- */
409
- public function getSetupInput(){
410
- return $this->getTypeInstance()->getSetupInput();
411
- }
412
- /**
413
- * get setup source
414
- * @access public
415
- * @return string
416
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
417
- */
418
- public function getSetupSource(){
419
- if ($this->getForcedSource()){
420
- return $this->getForcedSource();
421
- }
422
- return $this->getTypeInstance()->getSetupSource();
423
- }
424
- /**
425
- * check id an attribute is global
426
- * @access public
427
- * @return int
428
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
429
- */
430
- public function getSetupIsGlobal(){
431
- switch ($this->getScope()){
432
- case Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE:
433
- return 'Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE';
434
- break;
435
- case Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL:
436
- return 'Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL';
437
- break;
438
- case Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE:
439
- return 'Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE';
440
- break;
441
- default :
442
- return '';
443
- break;
444
- }
445
- }
446
-
447
-
448
- /**
449
- * get attribute code for file name
450
- * @access public
451
- * @param bool $uppercase
452
- * @return string
453
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
454
- */
455
- public function getCodeForFileName($uppercase = false){
456
- $code = str_replace('_', '', $this->getCode());
457
- if ($uppercase){
458
- $code = ucfirst($code);
459
- }
460
- return $code;
461
- }
462
- /**
463
- * check if attribute is visible
464
- * @access public
465
- * @return string
466
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
467
- */
468
- public function getVisible(){
469
- if (($this->hasForcedVisible())){
470
- return $this->getForcedVisible();
471
- }
472
- return $this->getTypeInstance()->getVisible();
473
- }
474
- /**
475
- * check if source needs to be generated
476
- * @access public
477
- * @return string
478
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
479
- */
480
- public function getGenerateSource() {
481
- return $this->getTypeInstance()->getGenerateSource();
482
- }
483
-
484
- /**
485
- * get additional setup values
486
- * @access public
487
- * @return string
488
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
489
- */
490
- public function getAdditionalSetup() {
491
- return $this->getTypeInstance()->getAdditionalSetup();
492
- }
493
- /**
494
- * check if attribute is yes/no
495
- * @access public
496
- * @return bool
497
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
498
- */
499
- public function getIsYesNo() {
500
- return $this->getTypeInstance()->getIsYesNo();
501
- }
502
-
503
- /**
504
- * get attribute options for source model
505
- * @access public
506
- * @return string
507
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
508
- */
509
- public function getAttributeOptions() {
510
- return $this->getTypeInstance()->getAttributeOptions();
511
- }
512
-
513
- /**
514
- * check if attribute is user defined
515
- * @access public
516
- * @param bool $asText
517
- * @return string
518
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
519
- */
520
- public function getIsUserDefined($asText = true) {
521
- if (!$this->hasData('user_defined')) {
522
- $this->setData('user_defined', true);
523
- }
524
- if (!$asText) {
525
- return $this->getData('user_defined');
526
- }
527
- if ($this->getData('user_defined')) {
528
- return 'true';
529
- }
530
- return 'false';
531
- }
532
- /**
533
- * get admin from options
534
- * @access public
535
- * @return string
536
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
537
- */
538
- public function getFormOptions(){
539
- return $this->getTypeInstance()->getFormOptions();
540
- }
541
-
542
- /**
543
- * check if attribute is multiple select
544
- * @access public
545
- * @return bool
546
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
547
- */
548
- public function getIsMultipleSelect(){
549
- return $this->getTypeInstance()->getIsMultipleSelect();
550
- }
551
- /**
552
- * check if entity is eav
553
- * @access public
554
- * @return bool
555
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
556
- */
557
- public function getEntityEav() {
558
- return $this->getEntity()->getIsEav();
559
- }
560
- /**
561
- * check if entity is not eav
562
- * @access public
563
- * @return bool
564
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
565
- */
566
- public function getNotEntityEav() {
567
- return !$this->getEntityEav();
568
- }
569
-
570
- /**
571
- * check if attribute can be in mass update
572
- * @access public
573
- * @return mixed
574
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
575
- */
576
- public function getMassUpdate() {
577
- return $this->getTypeInstance()->getMassUpdate();
578
- }
579
-
580
- /**
581
- * get values for mass action
582
- * @access public
583
- * @return string
584
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
585
- */
586
- public function getMassActionValues() {
587
- return $this->getTypeInstance()->getMassActionValues();
588
- }
589
-
590
- /**
591
- * get module
592
- * @access public
593
- * @return Ultimate_ModuleCreator_Model_Module
594
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
595
- */
596
- public function getModule(){
597
- return $this->getEntity()->getModule();
598
- }
599
- /**
600
- * get namespace
601
- * @access public
602
- * @param bool $lower
603
- * @return string
604
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
605
- */
606
- public function getNamespace($lower = false){
607
- return $this->getModule()->getNamespace($lower);
608
- }
609
-
610
- /**
611
- * get attribute default value
612
- * @access public
613
- * @return string
614
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
615
- */
616
- public function getDefaultValueProcessed() {
617
- return $this->getTypeInstance()->getDefaultValueProcessed();
618
- }
619
- /**
620
- * get attribute default value setup content
621
- * @access public
622
- * @return string
623
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
624
- */
625
- public function getDefaultValueSetup() {
626
- return $this->getTypeInstance()->getDefaultValueSetup();
627
- }
628
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
+ */
18
+ /**
19
+ * @method Ultimate_ModuleCreator_Model_Attribute setIndex()
20
+ * @method string getForcedDefaultValue()
21
+ * @method string getDefaultValue()
22
+ * @method string getOptionsSourceAttribute()
23
+ * @method string getLabel()
24
+ * @method string getNote()
25
+ * @method int getPosition()
26
+ * @method string getCode()
27
+ * @method bool getIsName()
28
+ * @method Ultimate_ModuleCreator_Model_Attribute setUserDefined
29
+ * @method Ultimate_ModuleCreator_Model_Attribute setEditor
30
+ * @method string getType()
31
+ * @method Ultimate_ModuleCreator_Model_Attribute setCode()
32
+ * @method Ultimate_ModuleCreator_Model_Attribute setType()
33
+ * @method Ultimate_ModuleCreator_Model_Attribute setLabel()
34
+ * @method string getOptionsSource()
35
+ * @method Ultimate_ModuleCreator_Model_Attribute setOptionsSource()
36
+ * @method Ultimate_ModuleCreator_Model_Attribute setForcedSource()
37
+ * @method Ultimate_ModuleCreator_Model_Attribute setScope()
38
+ * @method Ultimate_ModuleCreator_Model_Attribute setUseFilterIndex()
39
+ * @method Ultimate_ModuleCreator_Model_Attribute setPosition()
40
+ * @method Ultimate_ModuleCreator_Model_Attribute setForcedSetupType()
41
+ * @method Ultimate_ModuleCreator_Model_Attribute setForcedVisible()
42
+ * @method string getPreElementText()
43
+ * @method bool getUseFilterIndex()
44
+ * @method bool hasForcedSetupType()
45
+ * @method string getForcedSetupType()
46
+ * @method string getForcedSetupBackend()
47
+ * @method string getForcedSource()
48
+ * @method int getScope()
49
+ * @method bool hasForcedVisible()
50
+ * @method string getForcedVisible()
51
+ * @method Ultimate_ModuleCreator_Model_Attribute setDefaultValue()
52
+ * @method Ultimate_ModuleCreator_Model_Attribute setForcedSetupBackend()
53
+ * @method Ultimate_ModuleCreator_Model_Attribute setIgnoreApi()
54
+ * @method Ultimate_ModuleCreator_Model_Attribute setOptions()
55
+ * @method Ultimate_ModuleCreator_Model_Attribute setForcedDefaultValue()
56
+ * @method bool getWidget()
57
+ * @method bool getFrontend()
58
+ * @method bool getIgnoreApi()
59
+ * @method int getIndex()
60
+ *
61
+ */
62
+ class Ultimate_ModuleCreator_Model_Attribute extends Ultimate_ModuleCreator_Model_Abstract
63
+ {
64
+ /**
65
+ * custom option separator
66
+ */
67
+ const OPTION_SEPARATOR = "\n";
68
+
69
+ /**
70
+ * entity object
71
+ *
72
+ * @var mixed(null|Ultimate_ModuleCreator_Model_Entity)
73
+ */
74
+ protected $_entity = null;
75
+
76
+ /**
77
+ * attribute type instance
78
+ *
79
+ * @var mixed(null|Ultimate_ModuleCreator_Model_Attribute_Type_Abstract)
80
+ */
81
+ protected $_typeInstance = null;
82
+
83
+ /**
84
+ * placeholders for replacing in source
85
+ *
86
+ * @var mixed
87
+ */
88
+ protected $_placeholders = null;
89
+
90
+ /**
91
+ * set the model entity
92
+ *
93
+ * @access public
94
+ * @param Ultimate_ModuleCreator_Model_Entity $entity
95
+ * @return Ultimate_ModuleCreator_Model_Attribute
96
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
97
+ */
98
+ public function setEntity(Ultimate_ModuleCreator_Model_Entity $entity)
99
+ {
100
+ $this->_entity = $entity;
101
+ return $this;
102
+ }
103
+
104
+ /**
105
+ * get the attribute entity
106
+ *
107
+ * @access public
108
+ * @return Ultimate_ModuleCreator_Model_Entity
109
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
110
+ */
111
+ public function getEntity()
112
+ {
113
+ return $this->_entity;
114
+ }
115
+
116
+ /**
117
+ * get the magic function code for attribute
118
+ *
119
+ * @access public
120
+ * @param bool $ucFirst
121
+ * @return string
122
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
123
+ */
124
+ public function getMagicMethodCode($ucFirst = true)
125
+ {
126
+ $code = $this->getCode();
127
+ $code = $this->_camelize($code);
128
+ if ($ucFirst) {
129
+ return $code;
130
+ }
131
+ //lcfirst only works for php 5.3+
132
+ $code{0} = strtolower($code{0});
133
+ return $code;
134
+ }
135
+
136
+ /**
137
+ * get attribute the type instance
138
+ *
139
+ * @access public
140
+ * @return Ultimate_ModuleCreator_Model_Attribute_Type_Abstract
141
+ * @throws Ultimate_ModuleCreator_Exception
142
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
143
+ */
144
+ public function getTypeInstance()
145
+ {
146
+ if (!$this->_typeInstance) {
147
+ $type = $this->getType();
148
+ try {
149
+ $types = $this->getHelper()->getAttributeTypes(false);
150
+ $instanceModel = $types->$type->type_model;
151
+ /** @var Ultimate_ModuleCreator_Model_Attribute_Type_Abstract $typeInstance */
152
+ $typeInstance = Mage::getModel($instanceModel);
153
+ $this->_typeInstance = $typeInstance;
154
+ $this->_typeInstance->setAttribute($this);
155
+ } catch (Exception $e){
156
+ throw new Ultimate_ModuleCreator_Exception("Invalid attribute type: ". $type);
157
+ }
158
+ }
159
+ return $this->_typeInstance;
160
+ }
161
+
162
+ /**
163
+ * check if an attribute is in the admin grid
164
+ *
165
+ * @access public
166
+ * @return bool
167
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
168
+ */
169
+ public function getAdminGrid()
170
+ {
171
+ if ($this->getIsName()) {
172
+ return true;
173
+ }
174
+ return $this->getTypeInstance()->getAdminGrid();
175
+ }
176
+
177
+ /**
178
+ * check if an attribute can use an editor
179
+ *
180
+ * @access public
181
+ * @return bool
182
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
183
+ */
184
+ public function getEditor()
185
+ {
186
+ return $this->getTypeInstance()->getEditor();
187
+ }
188
+
189
+ /**
190
+ * check if attribute is required
191
+ *
192
+ * @access public
193
+ * @return string
194
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
195
+ */
196
+ public function getRequired()
197
+ {
198
+ if ($this->getIsName()) {
199
+ return true;
200
+ }
201
+ return $this->getTypeInstance()->getRequired();
202
+ }
203
+
204
+ /**
205
+ * check if attribute can behave as name
206
+ *
207
+ * @access public
208
+ * @return bool
209
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
210
+ */
211
+ public function getIsAllowedAsName()
212
+ {
213
+ return $this->getTypeInstance()->getIsAllowedAsName();
214
+ }
215
+
216
+ /**
217
+ * check if the attribute acts as name
218
+ *
219
+ * @access public
220
+ * @return bool
221
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
222
+ */
223
+ public function getNotIsName()
224
+ {
225
+ return !$this->getIsName();
226
+ }
227
+
228
+ /**
229
+ * get attribute placeholders
230
+ *
231
+ * @access public
232
+ * @param null $key
233
+ * @return mixed|null|string
234
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
235
+ */
236
+ public function getPlaceholders($key = null)
237
+ {
238
+ if (is_null($this->_placeholders)) {
239
+ $placeholders['{{attributeLabel}}'] = $this->getLabel();
240
+ $placeholders['{{AttributeMagicCode}}'] = $this->getMagicMethodCode();
241
+ $placeholders['{{attributeMagicCode}}'] = $this->getMagicMethodCode(false);
242
+ $placeholders['{{attributeCode}}'] = $this->getCode();
243
+ $placeholders['{{attributeColumnOptions}}'] = $this->getAdminColumnOptions();
244
+ $placeholders['{{attributeFormType}}'] = $this->getFormType();
245
+ $placeholders['{{attributeFormOptions}}'] = $this->getFormOptions();
246
+ $placeholders['{{attributePreElementText}}'] = $this->getPreElementText();
247
+ $placeholders['{{attributeRssText}}'] = $this->getRssText();
248
+ $placeholders['{{attributeNote}}'] = $this->getNote();
249
+ $placeholders['{{AttributeCodeForFile}}'] = $this->getCodeForFileName(true);
250
+ $placeholders['{{attributeCodeForFile}}'] = $this->getCodeForFileName(false);
251
+ $placeholders['{{attributeOptions}}'] = $this->getAttributeOptions();
252
+ $placeholders['{{massActionValues}}'] = $this->getMassActionValues();
253
+
254
+ $eventObject = new Varien_Object(
255
+ array(
256
+ 'placeholders' => $placeholders
257
+ )
258
+ );
259
+ Mage::dispatchEvent('umc_attribute_placeholdrers', array('event_object'=>$eventObject));
260
+ $placeholders = $eventObject->getPlaceholders();
261
+ $this->_placeholders = $placeholders;
262
+ }
263
+ if (is_null($key)) {
264
+ return $this->_placeholders;
265
+ }
266
+ if (isset($this->_placeholders[$key])) {
267
+ return $this->_placeholders[$key];
268
+ }
269
+ return '';
270
+ }
271
+
272
+ /**
273
+ * get additional admin grid column options
274
+ *
275
+ * @access public
276
+ * @return string
277
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
278
+ */
279
+ public function getAdminColumnOptions()
280
+ {
281
+ $options = $this->getTypeInstance()->getAdminColumnOptions();
282
+ if ($this->getUseFilterIndex()) {
283
+ $options .= $this->getPadding(3).
284
+ "'filter_index' => '".$this->getEntity()->getEntityTableAlias().
285
+ ".".$this->getCode()."'".$this->getEol();
286
+ }
287
+ return $options;
288
+ }
289
+
290
+ /**
291
+ * get options for attribute
292
+ *
293
+ * @access public
294
+ * @param bool $asArray
295
+ * @return array|mixed
296
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
297
+ */
298
+ public function getOptions($asArray = false)
299
+ {
300
+ if (!$asArray) {
301
+ return $this->getData('options');
302
+ }
303
+ return explode(self::OPTION_SEPARATOR, $this->getData('options'));
304
+ }
305
+
306
+ /**
307
+ * get form type
308
+ *
309
+ * @access public
310
+ * @return string
311
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
312
+ */
313
+ public function getFormType()
314
+ {
315
+ return $this->getTypeInstance()->getFormType();
316
+ }
317
+
318
+ /**
319
+ * get text for rss
320
+ *
321
+ * @access public
322
+ * @return string
323
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
324
+ */
325
+ public function getRssText()
326
+ {
327
+ return $this->getTypeInstance()->getRssText();
328
+ }
329
+
330
+ /**
331
+ * get the sql column
332
+ *
333
+ * @access public
334
+ * @return string
335
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
336
+ */
337
+ public function getDdlSqlColumn()
338
+ {
339
+ $eol = $this->getEol();
340
+ $padding = $this->getPadding(2);
341
+ $tab = $this->getPadding();
342
+ $ddl = '';
343
+ $ddl .= "->addColumn(".$eol;
344
+ $ddl .= $padding."'{$this->getCode()}',".$eol;
345
+ $ddl .= $padding."Varien_Db_Ddl_Table::".$this->getTypeDdl().", ".$this->getSizeDdl().",".$eol;
346
+ $ddl .= $padding."array(";
347
+ $newLine = false;
348
+ if ($this->getRequired()) {
349
+ $ddl .= $eol.$padding.$tab."'nullable' => false,";
350
+ $newLine = true;
351
+ }
352
+ //TODO: move this inside the type class
353
+ if ($this->getType() == 'int') {
354
+ $ddl .= $eol.$padding.$tab."'unsigned' => true,";
355
+ $newLine = true;
356
+ }
357
+ if ($newLine) {
358
+ $ddl .= $eol. $padding;
359
+ }
360
+ $ddl .= "),".$eol;
361
+ $ddl .= $padding."'".$this->getLabel()."'".$eol.$tab.")";
362
+ return $ddl;
363
+ }
364
+
365
+ /**
366
+ * get column ddl type
367
+ *
368
+ * @access public
369
+ * @return string
370
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
371
+ */
372
+ public function getTypeDdl()
373
+ {
374
+ return $this->getTypeInstance()->getTypeDdl();
375
+ }
376
+
377
+ /**
378
+ * get column ddl size
379
+ *
380
+ * @access public
381
+ * @return string
382
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
383
+ */
384
+ public function getSizeDdl()
385
+ {
386
+ return $this->getTypeInstance()->getSizeDdl();
387
+ }
388
+
389
+ /**
390
+ * get the frontend html
391
+ *
392
+ * @access public
393
+ * @return string
394
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
395
+ */
396
+ public function getFrontendHtml()
397
+ {
398
+ return $this->getTypeInstance()->getFrontendHtml();
399
+ }
400
+
401
+ /**
402
+ * get wsdl format for attribute
403
+ *
404
+ * @access public
405
+ * @param bool $wsi
406
+ * @return string
407
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
408
+ */
409
+ public function getWsdlFormat($wsi = false)
410
+ {
411
+ if ($wsi) {
412
+ return '<xsd:element name="'.$this->getCode().'" type="xsd:string" />';
413
+ }
414
+ return '<element name="'.$this->getCode().'" type="xsd:string" minOccurs="'.(int)$this->getRequired().'" />';
415
+ }
416
+
417
+ /**
418
+ * get setup content for attribute
419
+ *
420
+ * @access public
421
+ * @return mixed
422
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
423
+ */
424
+ public function getSetupContent()
425
+ {
426
+ $content = '';
427
+ $padding5 = $this->getPadding(5);
428
+ $padding6 = $this->getPadding(6);
429
+ $eol = $this->getEol();
430
+ $coreHelper = Mage::helper('core');
431
+ $content .= $padding5."'".$this->getCode()."' => array(".$eol;
432
+ $content .= $padding6."'group' => 'General',".$eol;
433
+ $content .= $padding6."'type' => '".$this->getSetupType()."',".$eol;
434
+ $content .= $padding6."'backend' => '".$this->getSetupBackend()."',".$eol;
435
+ $content .= $padding6."'frontend' => '',".$eol;
436
+ $content .= $padding6."'label' => '".$coreHelper->jsQuoteEscape($this->getLabel())."',".$eol;
437
+ $content .= $padding6."'input' => '".$this->getSetupInput()."',".$eol;
438
+ $content .= $padding6."'source' => '".$this->getSetupSource()."',".$eol;
439
+ $content .= $padding6."'global' => ".$this->getSetupIsGlobal().",".$eol;
440
+ $content .= $padding6."'required' => '".$this->getRequired()."',".$eol;
441
+ $content .= $padding6."'user_defined' => ".$this->getIsUserDefined().",".$eol;
442
+ $content .= $padding6."'default' => '".$coreHelper->jsQuoteEscape($this->getDefaultValueProcessed()).
443
+ "',".$eol;
444
+ $content .= $padding6."'unique' => false,".$eol;
445
+ $content .= $padding6."'position' => '".(int)$this->getPosition()."',".$eol;
446
+ $content .= $padding6."'note' => '".$coreHelper->jsQuoteEscape($this->getNote())."',".$eol;
447
+ $content .= $padding6."'visible' => '".(int)$this->getVisible()."',".$eol;
448
+ $content .= $padding6."'wysiwyg_enabled'=> '".(int)$this->getEditor()."',".$eol;
449
+ $content .= $this->getAdditionalSetup();
450
+ $content .= $padding5 .'),'.$eol;
451
+
452
+ return $content;
453
+ }
454
+
455
+ /**
456
+ * get setup type
457
+ *
458
+ * @access public
459
+ * @return string
460
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
461
+ */
462
+ public function getSetupType()
463
+ {
464
+ if ($this->hasForcedSetupType()) {
465
+ return $this->getForcedSetupType();
466
+ }
467
+ return $this->getTypeInstance()->getSetupType();
468
+ }
469
+
470
+ /**
471
+ * get setup backend
472
+ *
473
+ * @access public
474
+ * @return string
475
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
476
+ */
477
+ public function getSetupBackend()
478
+ {
479
+ if ($this->getForcedSetupBackend()) {
480
+ return $this->getForcedSetupBackend();
481
+ }
482
+ return $this->getTypeInstance()->getSetupBackend();
483
+ }
484
+
485
+ /**
486
+ * get setup input
487
+ *
488
+ * @access public
489
+ * @return string
490
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
491
+ */
492
+ public function getSetupInput()
493
+ {
494
+ return $this->getTypeInstance()->getSetupInput();
495
+ }
496
+
497
+ /**
498
+ * get setup source
499
+ *
500
+ * @access public
501
+ * @return string
502
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
503
+ */
504
+ public function getSetupSource()
505
+ {
506
+ if ($this->getForcedSource()) {
507
+ return $this->getForcedSource();
508
+ }
509
+ return $this->getTypeInstance()->getSetupSource();
510
+ }
511
+
512
+ /**
513
+ * check id an attribute is global
514
+ *
515
+ * @access public
516
+ * @return int
517
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
518
+ */
519
+ public function getSetupIsGlobal()
520
+ {
521
+ switch ($this->getScope()) {
522
+ case Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE:
523
+ return 'Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE';
524
+ break;
525
+ case Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL:
526
+ return 'Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL';
527
+ break;
528
+ case Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE:
529
+ return 'Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE';
530
+ break;
531
+ default :
532
+ return '';
533
+ break;
534
+ }
535
+ }
536
+
537
+ /**
538
+ * get attribute code for file name
539
+ *
540
+ * @access public
541
+ * @param bool $uppercase
542
+ * @return string
543
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
544
+ */
545
+ public function getCodeForFileName($uppercase = false)
546
+ {
547
+ $code = str_replace('_', '', $this->getCode());
548
+ if ($uppercase) {
549
+ $code = ucfirst($code);
550
+ }
551
+ return $code;
552
+ }
553
+
554
+ /**
555
+ * check if attribute is visible
556
+ *
557
+ * @access public
558
+ * @return string
559
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
560
+ */
561
+ public function getVisible()
562
+ {
563
+ if (($this->hasForcedVisible())) {
564
+ return $this->getForcedVisible();
565
+ }
566
+ return $this->getTypeInstance()->getVisible();
567
+ }
568
+
569
+ /**
570
+ * check if source needs to be generated
571
+ *
572
+ * @access public
573
+ * @return string
574
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
575
+ */
576
+ public function getGenerateSource()
577
+ {
578
+ return $this->getTypeInstance()->getGenerateSource();
579
+ }
580
+
581
+ /**
582
+ * get additional setup values
583
+ *
584
+ * @access public
585
+ * @return string
586
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
587
+ */
588
+ public function getAdditionalSetup()
589
+ {
590
+ return $this->getTypeInstance()->getAdditionalSetup();
591
+ }
592
+
593
+ /**
594
+ * check if attribute is yes/no
595
+ *
596
+ * @access public
597
+ * @return bool
598
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
599
+ */
600
+ public function getIsYesNo()
601
+ {
602
+ return $this->getTypeInstance()->getIsYesNo();
603
+ }
604
+
605
+ /**
606
+ * get attribute options for source model
607
+ *
608
+ * @access public
609
+ * @return string
610
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
611
+ */
612
+ public function getAttributeOptions()
613
+ {
614
+ return $this->getTypeInstance()->getAttributeOptions();
615
+ }
616
+
617
+ /**
618
+ * check if attribute is user defined
619
+ *
620
+ * @access public
621
+ * @param bool $asText
622
+ * @return string
623
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
624
+ */
625
+ public function getIsUserDefined($asText = true)
626
+ {
627
+ if (!$this->hasData('user_defined')) {
628
+ $this->setData('user_defined', true);
629
+ }
630
+ if (!$asText) {
631
+ return $this->getData('user_defined');
632
+ }
633
+ if ($this->getData('user_defined')) {
634
+ return 'true';
635
+ }
636
+ return 'false';
637
+ }
638
+
639
+ /**
640
+ * get admin from options
641
+ *
642
+ * @access public
643
+ * @return string
644
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
645
+ */
646
+ public function getFormOptions()
647
+ {
648
+ return $this->getTypeInstance()->getFormOptions();
649
+ }
650
+
651
+ /**
652
+ * check if attribute is multiple select
653
+ *
654
+ * @access public
655
+ * @return bool
656
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
657
+ */
658
+ public function getIsMultipleSelect()
659
+ {
660
+ return $this->getTypeInstance()->getIsMultipleSelect();
661
+ }
662
+
663
+ /**
664
+ * check if entity is eav
665
+ *
666
+ * @access public
667
+ * @return bool
668
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
669
+ */
670
+ public function getEntityEav()
671
+ {
672
+ return $this->getEntity()->getIsEav();
673
+ }
674
+
675
+ /**
676
+ * check if entity is not eav
677
+ *
678
+ * @access public
679
+ * @return bool
680
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
681
+ */
682
+ public function getNotEntityEav()
683
+ {
684
+ return !$this->getEntityEav();
685
+ }
686
+
687
+ /**
688
+ * check if attribute can be in mass update
689
+ *
690
+ * @access public
691
+ * @return mixed
692
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
693
+ */
694
+ public function getMassUpdate()
695
+ {
696
+ return $this->getTypeInstance()->getMassUpdate();
697
+ }
698
+
699
+ /**
700
+ * get values for mass action
701
+ *
702
+ * @access public
703
+ * @return string
704
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
705
+ */
706
+ public function getMassActionValues()
707
+ {
708
+ return $this->getTypeInstance()->getMassActionValues();
709
+ }
710
+
711
+ /**
712
+ * get module
713
+ *
714
+ * @access public
715
+ * @return Ultimate_ModuleCreator_Model_Module
716
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
717
+ */
718
+ public function getModule()
719
+ {
720
+ return $this->getEntity()->getModule();
721
+ }
722
+
723
+ /**
724
+ * get namespace
725
+ *
726
+ * @access public
727
+ * @param bool $lower
728
+ * @return string
729
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
730
+ */
731
+ public function getNamespace($lower = false)
732
+ {
733
+ return $this->getModule()->getNamespace($lower);
734
+ }
735
+
736
+ /**
737
+ * get attribute default value
738
+ *
739
+ * @access public
740
+ * @return string
741
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
742
+ */
743
+ public function getDefaultValueProcessed()
744
+ {
745
+ return $this->getTypeInstance()->getDefaultValueProcessed();
746
+ }
747
+
748
+ /**
749
+ * get attribute default value setup content
750
+ *
751
+ * @access public
752
+ * @return string
753
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
754
+ */
755
+ public function getDefaultValueSetup()
756
+ {
757
+ return $this->getTypeInstance()->getDefaultValueSetup();
758
+ }
759
+ }
app/code/community/Ultimate/ModuleCreator/Model/Attribute/Type/Abstract.php CHANGED
@@ -1,390 +1,510 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
- */
18
- /**
19
- * abstract attribute type
20
- *
21
- * @category Ultimate
22
- * @package Ultimate_ModuleCreator
23
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
- */
25
- /**
26
- * @method bool getIsMultipleSelect()
27
- */
28
- class Ultimate_ModuleCreator_Model_Attribute_Type_Abstract
29
- extends Ultimate_ModuleCreator_Model_Abstract {
30
- /**
31
- * type code
32
- * @var string
33
- */
34
- protected $_type = 'abstract';
35
- /**
36
- * attribute object
37
- * @var mixed
38
- */
39
- protected $_attribute = null;
40
- /**
41
- * sql column ddl type
42
- * @var string
43
- */
44
- protected $_typeDdl = 'TYPE_TEXT';
45
- /**
46
- * sql column ddl size
47
- * @var string
48
- */
49
- protected $_sizeDdl = '255';
50
-
51
- /**
52
- * eav setup type
53
- */
54
- protected $_setupType = 'varchar';
55
- /**
56
- * eav setup backend
57
- * @var string
58
- */
59
- protected $_setupBackend = '';
60
- /**
61
- * eav setup input
62
- * @var string
63
- */
64
- protected $_setupInput = 'text';
65
- /**
66
- * eav setup source
67
- * @var string
68
- */
69
- protected $_setupSource = '';
70
-
71
- /**
72
- * set the attribute
73
- * @param Ultimate_ModuleCreator_Model_Attribute $attribute
74
- * @return Ultimate_ModuleCreator_Model_Attribute_Type_Abstract
75
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
76
- */
77
- public function setAttribute(Ultimate_ModuleCreator_Model_Attribute $attribute) {
78
- $this->_attribute = $attribute;
79
- return $this;
80
- }
81
-
82
- /**
83
- * get attribute object
84
- * @access public
85
- * @return Ultimate_ModuleCreator_Model_Attribute|null
86
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
87
- */
88
- public function getAttribute() {
89
- return $this->_attribute;
90
- }
91
- /**
92
- * get module
93
- * @access public
94
- * @return Ultimate_ModuleCreator_Model_Entity
95
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
96
- */
97
- public function getEntity(){
98
- return $this->getAttribute()->getEntity();
99
- }
100
- /**
101
- * get module
102
- * @access public
103
- * @return Ultimate_ModuleCreator_Model_Module
104
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
105
- */
106
- public function getModule(){
107
- return $this->getAttribute()->getModule();
108
- }
109
- /**
110
- * get namespace
111
- * @access public
112
- * @param bool $lower
113
- * @return string
114
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
115
- */
116
- public function getNamespace($lower = false){
117
- return $this->getModule()->getNamespace($lower);
118
- }
119
- /**
120
- * check if attribute can be in admin grid
121
- * @access public
122
- * @return bool
123
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
124
- */
125
- public function getAdminGrid() {
126
- return $this->getAttribute()->getData('admin_grid');
127
- }
128
- /**
129
- * get column options
130
- * @access public
131
- * @return string
132
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
133
- */
134
- public function getAdminColumnOptions() {
135
- return '';
136
- }
137
-
138
- /**
139
- * get text for rss
140
- * @access public
141
- * @return string
142
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
143
- */
144
- public function getRssText() {
145
- $attribute = $this->getAttribute();
146
- $module = $this->getModule()->getLowerModuleName();
147
- $namespace = $this->getNamespace(true);
148
- return $this->getPadding(3).'$'.'description .= \'<div>\'.Mage::helper(\''.$namespace.'_'.$module.'\')->__(\''.$attribute->getLabel().'\').\': \'.$item->get'.$this->getAttribute()->getMagicMethodCode().'().\'</div>\';'.$this->getEol();
149
- }
150
- /**
151
- * get the type for the form
152
- * @access public
153
- * @return string
154
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
155
- */
156
- public function getFormType() {
157
- return 'text';
158
- }
159
- /**
160
- * get column ddl type
161
- * @access public
162
- * @return string
163
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
164
- */
165
- public function getTypeDdl() {
166
- return $this->_typeDdl;
167
- }
168
- /**
169
- * get column ddl size
170
- * @access public
171
- * @return string
172
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
173
- */
174
- public function getSizeDdl() {
175
- return $this->_sizeDdl;
176
- }
177
- /**
178
- * get the html for frontend
179
- * @access public
180
- * @return string
181
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
182
- */
183
- public function getFrontendHtml() {
184
- return '<?php echo Mage::helper(\''.$this->getNamespace(true).'_'.$this->getModule()->getLowerModuleName().'\')->__(\''.$this->getAttribute()->getLabel().'\');?>:<?php echo $_'.strtolower($this->getAttribute()->getEntity()->getNameSingular()).'->get'.$this->getAttribute()->getMagicMethodCode().'();?>'.$this->getHelper()->getEol();
185
- }
186
- /**
187
- * get the setup type
188
- * @access public
189
- * @return string
190
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
191
- */
192
- public function getSetupType(){
193
- return $this->_setupType;
194
- }
195
- /**
196
- * get setup backend type
197
- * @access public
198
- * @return string
199
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
200
- */
201
- public function getSetupBackend(){
202
- return $this->_setupBackend;
203
- }
204
- /**
205
- * get the setup input
206
- * @access public
207
- * @return string
208
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
209
- */
210
- public function getSetupInput(){
211
- return $this->_setupInput;
212
- }
213
- /**
214
- * get the setup source
215
- * @access public
216
- * @return string
217
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
218
- */
219
- public function getSetupSource(){
220
- return $this->_setupSource;
221
- }
222
- /**
223
- * check if attribute is visible
224
- * @access public
225
- * @return string
226
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
227
- */
228
- public function getVisible(){
229
- return true;
230
- }
231
- /**
232
- * check if source needs to be generated
233
- * @access public
234
- * @return string
235
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
236
- */
237
- public function getGenerateSource(){
238
- return false;
239
- }
240
- /**
241
- * get additional setup values
242
- * @access public
243
- * @return string
244
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
245
- */
246
- public function getAdditionalSetup(){
247
- return '';
248
- }
249
-
250
- /**
251
- * check if attribute is required
252
- * @access public
253
- * @return mixed
254
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
255
- */
256
- public function getRequired(){
257
- return $this->getAttribute()->getData('required');
258
- }
259
-
260
- /**
261
- * check if attribute is yes/no
262
- * @access public
263
- * @return bool
264
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
265
- */
266
- public function getIsYesNo() {
267
- return false;
268
- }
269
-
270
- /**
271
- * can use editor
272
- * @access public
273
- * @return bool
274
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
275
- */
276
- public function getEditor() {
277
- return false;
278
- }
279
- /**
280
- * get attribute options for source model
281
- * @access public
282
- * @return string
283
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
284
- */
285
- public function getAttributeOptions(){
286
- return $this->getPadding(2).'return array();';
287
- }
288
- /**
289
- * get admin from options
290
- * @access public
291
- * @return string
292
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
293
- */
294
- public function getFormOptions(){
295
- $options = '';
296
- $padding = $this->getPadding(3);
297
- $eol = $this->getEol();
298
- $note = $this->getAttribute()->getNote();
299
- if ($note){
300
- $options .= $padding."'note' => $"."this->__('".$note."'),".$eol;
301
- }
302
- if ($this->getRequired()){
303
- $options .= $padding."'required' => true,".$eol;
304
- $options .= $padding."'class' => 'required-entry',".$eol;
305
- }
306
- return $options.$eol;
307
- }
308
-
309
- /**
310
- * getter for attribute type
311
- * @return string
312
- * @access public
313
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
314
- */
315
- public function getType(){
316
- return $this->_type;
317
- }
318
- /**
319
- * getter xml node for attribute
320
- * @return string
321
- * @access public
322
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
323
- */
324
- public function getTypeConfigPath() {
325
- return Ultimate_ModuleCreator_Helper_Data::ATTRIBUTE_TYPES_PATH.'/'.$this->getType();
326
- }
327
- /**
328
- * getter config for attribute
329
- * @access public
330
- * @param $path
331
- * @return Varien_Simplexml_Element
332
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
333
- */
334
- public function getConfig($path = null) {
335
- if (!is_null($path)){
336
- $path = $this->getTypeConfigPath().'/'.$path;
337
- }
338
- else {
339
- $path = $this->getTypeConfigPath();
340
- }
341
- /** @var Ultimate_ModuleCreator_Helper_Data $helper */
342
- $helper = Mage::helper('modulecreator');
343
- return $helper->getConfig()->getNode($path);
344
- }
345
- /**
346
- * check if attribute can behave as name
347
- * @access public
348
- * @return bool
349
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
350
- */
351
- public function getIsAllowedAsName() {
352
- return (bool)(string)$this->getConfig('allow_is_name');
353
- }
354
- /**
355
- * check if attribute can be in mass update
356
- * @access public
357
- * @return mixed
358
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
359
- */
360
- public function getMassUpdate() {
361
- return (bool)(string)$this->getConfig('mass_update');
362
- }
363
- /**
364
- * get values for mass action
365
- * @access public
366
- * @return string
367
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
368
- */
369
- public function getMassActionValues() {
370
- return '';
371
- }
372
- /**
373
- * get attribute default value
374
- * @access public
375
- * @return string
376
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
377
- */
378
- public function getDefaultValueProcessed() {
379
- return $this->getAttribute()->getData('default_value');
380
- }
381
- /**
382
- * get attribute default value setup content
383
- * @access public
384
- * @return string
385
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
386
- */
387
- public function getDefaultValueSetup() {
388
- return '';
389
- }
390
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
+ */
18
+ /**
19
+ * abstract attribute type
20
+ *
21
+ * @category Ultimate
22
+ * @package Ultimate_ModuleCreator
23
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
+ */
25
+ /**
26
+ * @method bool getIsMultipleSelect()
27
+ */
28
+ class Ultimate_ModuleCreator_Model_Attribute_Type_Abstract extends Ultimate_ModuleCreator_Model_Abstract
29
+ {
30
+ /**
31
+ * type code
32
+ *
33
+ * @var string
34
+ */
35
+ protected $_type = 'abstract';
36
+
37
+ /**
38
+ * attribute object
39
+ *
40
+ * @var mixed
41
+ */
42
+ protected $_attribute = null;
43
+
44
+ /**
45
+ * sql column ddl type
46
+ *
47
+ * @var string
48
+ */
49
+ protected $_typeDdl = 'TYPE_TEXT';
50
+
51
+ /**
52
+ * sql column ddl size
53
+ *
54
+ * @var string
55
+ */
56
+ protected $_sizeDdl = '255';
57
+
58
+ /**
59
+ * eav setup type
60
+ *
61
+ * @var string
62
+ */
63
+ protected $_setupType = 'varchar';
64
+
65
+ /**
66
+ * eav setup backend
67
+ *
68
+ * @var string
69
+ */
70
+ protected $_setupBackend = '';
71
+
72
+ /**
73
+ * eav setup input
74
+ *
75
+ * @var string
76
+ */
77
+ protected $_setupInput = 'text';
78
+
79
+ /**
80
+ * eav setup source
81
+ *
82
+ * @var string
83
+ */
84
+ protected $_setupSource = '';
85
+
86
+ /**
87
+ * set the attribute
88
+ *
89
+ * @param Ultimate_ModuleCreator_Model_Attribute $attribute
90
+ * @return Ultimate_ModuleCreator_Model_Attribute_Type_Abstract
91
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
92
+ */
93
+ public function setAttribute(Ultimate_ModuleCreator_Model_Attribute $attribute)
94
+ {
95
+ $this->_attribute = $attribute;
96
+ return $this;
97
+ }
98
+
99
+ /**
100
+ * get attribute object
101
+ *
102
+ * @access public
103
+ * @return Ultimate_ModuleCreator_Model_Attribute|null
104
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
105
+ */
106
+ public function getAttribute()
107
+ {
108
+ return $this->_attribute;
109
+ }
110
+
111
+ /**
112
+ * get entity
113
+ *
114
+ * @access public
115
+ * @return Ultimate_ModuleCreator_Model_Entity
116
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
117
+ */
118
+ public function getEntity()
119
+ {
120
+ return $this->getAttribute()->getEntity();
121
+ }
122
+
123
+ /**
124
+ * get module
125
+ *
126
+ * @access public
127
+ * @return Ultimate_ModuleCreator_Model_Module
128
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
129
+ */
130
+ public function getModule()
131
+ {
132
+ return $this->getAttribute()->getModule();
133
+ }
134
+
135
+ /**
136
+ * get namespace
137
+ *
138
+ * @access public
139
+ * @param bool $lower
140
+ * @return string
141
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
142
+ */
143
+ public function getNamespace($lower = false)
144
+ {
145
+ return $this->getModule()->getNamespace($lower);
146
+ }
147
+
148
+ /**
149
+ * check if attribute can be in admin grid
150
+ *
151
+ * @access public
152
+ * @return bool
153
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
154
+ */
155
+ public function getAdminGrid()
156
+ {
157
+ return $this->getAttribute()->getData('admin_grid');
158
+ }
159
+
160
+ /**
161
+ * get column options
162
+ *
163
+ * @access public
164
+ * @return string
165
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
166
+ */
167
+ public function getAdminColumnOptions()
168
+ {
169
+ return '';
170
+ }
171
+
172
+ /**
173
+ * get text for rss
174
+ *
175
+ * @access public
176
+ * @return string
177
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
178
+ */
179
+ public function getRssText()
180
+ {
181
+ $eol = $this->getEol();
182
+ $attribute = $this->getAttribute();
183
+ $module = $this->getModule()->getLowerModuleName();
184
+ $namespace = $this->getNamespace(true);
185
+ $html = $this->getPadding(3);
186
+ $html .= '$'.'description .= \'<div>\'.'.$eol.$this->getPadding(4).'Mage::helper(\'';
187
+ $html .= $namespace.'_'.$module;
188
+ $html .= '\')->__(\''.$attribute->getLabel();
189
+ $html .= '\').\': '.$eol.$this->getPadding(4).'\'.$item->get';
190
+ $html .= $this->getAttribute()->getMagicMethodCode();
191
+ $html .= '().'.$eol.$this->getPadding(4).'\'</div>\';'.$this->getEol();
192
+
193
+ return $html;
194
+ }
195
+
196
+ /**
197
+ * get the type for the form
198
+ *
199
+ * @access public
200
+ * @return string
201
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
202
+ */
203
+ public function getFormType()
204
+ {
205
+ return 'text';
206
+ }
207
+
208
+ /**
209
+ * get column ddl type
210
+ *
211
+ * @access public
212
+ * @return string
213
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
214
+ */
215
+ public function getTypeDdl()
216
+ {
217
+ return $this->_typeDdl;
218
+ }
219
+
220
+ /**
221
+ * get column ddl size
222
+ *
223
+ * @access public
224
+ * @return string
225
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
226
+ */
227
+ public function getSizeDdl()
228
+ {
229
+ return $this->_sizeDdl;
230
+ }
231
+
232
+ /**
233
+ * get the html for frontend
234
+ *
235
+ * @access public
236
+ * @return string
237
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
238
+ */
239
+ public function getFrontendHtml()
240
+ {
241
+ $html = '<?php echo Mage::helper(\'';
242
+ $html .= $this->getNamespace(true).'_'.$this->getModule()->getLowerModuleName();
243
+ $html .= '\')->__(\'';
244
+ $html .= $this->getAttribute()->getLabel();
245
+ $html .= '\');?>:<?php echo $_';
246
+ $html .= strtolower($this->getAttribute()->getEntity()->getNameSingular());
247
+ $html .= '->get'.$this->getAttribute()->getMagicMethodCode().'();?>';
248
+ $html .= $this->getHelper()->getEol();
249
+ return $html;
250
+ }
251
+
252
+ /**
253
+ * get the setup type
254
+ *
255
+ * @access public
256
+ * @return string
257
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
258
+ */
259
+ public function getSetupType()
260
+ {
261
+ return $this->_setupType;
262
+ }
263
+
264
+ /**
265
+ * get setup backend type
266
+ *
267
+ * @access public
268
+ * @return string
269
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
270
+ */
271
+ public function getSetupBackend()
272
+ {
273
+ return $this->_setupBackend;
274
+ }
275
+
276
+ /**
277
+ * get the setup input
278
+ *
279
+ * @access public
280
+ * @return string
281
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
282
+ */
283
+ public function getSetupInput()
284
+ {
285
+ return $this->_setupInput;
286
+ }
287
+
288
+ /**
289
+ * get the setup source
290
+ *
291
+ * @access public
292
+ * @return string
293
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
294
+ */
295
+ public function getSetupSource()
296
+ {
297
+ return $this->_setupSource;
298
+ }
299
+
300
+ /**
301
+ * check if attribute is visible
302
+ *
303
+ * @access public
304
+ * @return string
305
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
306
+ */
307
+ public function getVisible()
308
+ {
309
+ return true;
310
+ }
311
+
312
+ /**
313
+ * check if source needs to be generated
314
+ *
315
+ * @access public
316
+ * @return string
317
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
318
+ */
319
+ public function getGenerateSource()
320
+ {
321
+ return false;
322
+ }
323
+
324
+ /**
325
+ * get additional setup values
326
+ *
327
+ * @access public
328
+ * @return string
329
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
330
+ */
331
+ public function getAdditionalSetup()
332
+ {
333
+ return '';
334
+ }
335
+
336
+ /**
337
+ * check if attribute is required
338
+ *
339
+ * @access public
340
+ * @return mixed
341
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
342
+ */
343
+ public function getRequired()
344
+ {
345
+ return $this->getAttribute()->getData('required');
346
+ }
347
+
348
+ /**
349
+ * check if attribute is yes/no
350
+ *
351
+ * @access public
352
+ * @return bool
353
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
354
+ */
355
+ public function getIsYesNo()
356
+ {
357
+ return false;
358
+ }
359
+
360
+ /**
361
+ * can use editor
362
+ *
363
+ * @access public
364
+ * @return bool
365
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
366
+ */
367
+ public function getEditor()
368
+ {
369
+ return false;
370
+ }
371
+
372
+ /**
373
+ * get attribute options for source model
374
+ *
375
+ * @access public
376
+ * @return string
377
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
378
+ */
379
+ public function getAttributeOptions()
380
+ {
381
+ return $this->getPadding(2).'return array();';
382
+ }
383
+
384
+ /**
385
+ * get admin from options
386
+ *
387
+ * @access public
388
+ * @return string
389
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
390
+ */
391
+ public function getFormOptions()
392
+ {
393
+ $options = '';
394
+ $padding = $this->getPadding(3);
395
+ $eol = $this->getEol();
396
+ $note = $this->getAttribute()->getNote();
397
+ if ($note) {
398
+ $options .= $padding."'note' => $"."this->__('".$note."'),".$eol;
399
+ }
400
+ if ($this->getRequired()) {
401
+ $options .= $padding."'required' => true,".$eol;
402
+ $options .= $padding."'class' => 'required-entry',".$eol;
403
+ }
404
+ return $options.$eol;
405
+ }
406
+
407
+ /**
408
+ * getter for attribute type
409
+ *
410
+ * @return string
411
+ * @access public
412
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
413
+ */
414
+ public function getType()
415
+ {
416
+ return $this->_type;
417
+ }
418
+
419
+ /**
420
+ * getter xml node for attribute
421
+ *
422
+ * @return string
423
+ * @access public
424
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
425
+ */
426
+ public function getTypeConfigPath()
427
+ {
428
+ return Ultimate_ModuleCreator_Helper_Data::ATTRIBUTE_TYPES_PATH.'/'.$this->getType();
429
+ }
430
+
431
+ /**
432
+ * getter config for attribute
433
+ *
434
+ * @access public
435
+ * @param $path
436
+ * @return Varien_Simplexml_Element
437
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
438
+ */
439
+ public function getConfig($path = null)
440
+ {
441
+ if (!is_null($path)) {
442
+ $path = $this->getTypeConfigPath().'/'.$path;
443
+ } else {
444
+ $path = $this->getTypeConfigPath();
445
+ }
446
+ /** @var Ultimate_ModuleCreator_Helper_Data $helper */
447
+ $helper = Mage::helper('modulecreator');
448
+ return $helper->getConfig()->getNode($path);
449
+ }
450
+
451
+ /**
452
+ * check if attribute can behave as name
453
+ *
454
+ * @access public
455
+ * @return bool
456
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
457
+ */
458
+ public function getIsAllowedAsName()
459
+ {
460
+ return (bool)(string)$this->getConfig('allow_is_name');
461
+ }
462
+
463
+ /**
464
+ * check if attribute can be in mass update
465
+ *
466
+ * @access public
467
+ * @return mixed
468
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
469
+ */
470
+ public function getMassUpdate()
471
+ {
472
+ return (bool)(string)$this->getConfig('mass_update');
473
+ }
474
+
475
+ /**
476
+ * get values for mass action
477
+ *
478
+ * @access public
479
+ * @return string
480
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
481
+ */
482
+ public function getMassActionValues()
483
+ {
484
+ return '';
485
+ }
486
+
487
+ /**
488
+ * get attribute default value
489
+ *
490
+ * @access public
491
+ * @return string
492
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
493
+ */
494
+ public function getDefaultValueProcessed()
495
+ {
496
+ return $this->getAttribute()->getData('default_value');
497
+ }
498
+
499
+ /**
500
+ * get attribute default value setup content
501
+ *
502
+ * @access public
503
+ * @return string
504
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
505
+ */
506
+ public function getDefaultValueSetup()
507
+ {
508
+ return '';
509
+ }
510
+ }
app/code/community/Ultimate/ModuleCreator/Model/Attribute/Type/Country.php CHANGED
@@ -1,122 +1,180 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
- */
18
- /**
19
- * country attribute type
20
- *
21
- * @category Ultimate
22
- * @package Ultimate_ModuleCreator
23
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
- */
25
- class Ultimate_ModuleCreator_Model_Attribute_Type_Country
26
- extends Ultimate_ModuleCreator_Model_Attribute_Type_Abstract {
27
- /**
28
- * type code
29
- * @var string
30
- */
31
- protected $_type = 'country';
32
- /**
33
- * sql column ddl size
34
- * @var string
35
- */
36
- protected $_sizeDdl = '2';
37
- /**
38
- * eav setup input
39
- */
40
- protected $_setupInput = 'select';
41
-
42
-
43
- /**
44
- * get admin column options
45
- * @access public
46
- * @return string
47
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
48
- */
49
- public function getAdminColumnOptions() {
50
- $options = $this->getEol();
51
- $options .= $this->getPadding(3);
52
- $options .= "'type'=> 'country',".$this->getEol();
53
- return $options;
54
- }
55
- /**
56
- * get the type for the form
57
- * @access public
58
- * @return string
59
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
60
- */
61
- public function getFormType() {
62
- return 'select';
63
- }
64
-
65
- /**
66
- * get text for rss
67
- * @access public
68
- * @return string
69
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
70
- */
71
- public function getRssText() {
72
- $module = $this->getModule()->getLowerModuleName();
73
- $namespace = $this->getNamespace(true);
74
- return $this->getPadding(3).'$description .= \'<div>\'.Mage::helper(\''.$namespace.'_'.$module.'\')->__("'.$this->getAttribute()->getLabel().'").\':\'.(($item->get'.$this->getAttribute()->getMagicMethodCode().'()) ? Mage::getModel(\'directory/country\')->load($item->get'.$this->getAttribute()->getMagicMethodCode().'())->getName():Mage::helper(\''.$namespace.'_'.$module.'\')->__(\'None\')).\'</div>\';'.$this->getEol();
75
- }
76
- /**
77
- * get html for frontend
78
- * @access public
79
- * @return string
80
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
81
- */
82
- public function getFrontendHtml() {
83
- $entityName = $this->getEntity()->getNameSingular(true);
84
- $module = $this->getModule()->getLowerModuleName();
85
- $namespace = $this->getNamespace(true);
86
- if ($this->getEntity()->getIsEav()){
87
- return '<?php echo Mage::helper(\''.$namespace.'_'.$module.'\')->__("'.$this->getAttribute()->getLabel().'");?>:<?php echo $_'.$this->getEntity()->getNameSingular(true).'->getAttributeText(\''.$this->getAttribute()->getCode().'\');?>'.$this->getEol();
88
- }
89
- return '<?php echo Mage::helper(\''.$namespace.'_'.$module.'\')->__("'.$this->getAttribute()->getLabel().'");?>:<?php echo ($_'.$entityName.'->get'.$this->getAttribute()->getMagicMethodCode().'()) ? Mage::getModel(\'directory/country\')->load($_'.$entityName.'->get'.$this->getAttribute()->getMagicMethodCode().'())->getName():Mage::helper(\''.$namespace.'_'.$module.'\')->__(\'None\') ?>'.$this->getEol();
90
- }
91
- /**
92
- * get source for setup
93
- * @access public
94
- * @return string|void
95
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
96
- */
97
- public function getSetupSource() {
98
- $module = $this->getModule()->getLowerModuleName();
99
- $namespace = $this->getNamespace(true);
100
- return $namespace.'_'.$module.'/attribute_source_country';
101
- }
102
- /**
103
- * get admin from options
104
- * @access public
105
- * @return string
106
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
107
- */
108
- public function getFormOptions(){
109
- $options = parent::getFormOptions();
110
- $options .= $this->getPadding(3)."'values'=> Mage::getResourceModel('directory/country_collection')->toOptionArray(),".$this->getEol();
111
- return $options;
112
- }
113
- /**
114
- * get values for mass action
115
- * @access public
116
- * @return string
117
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
118
- */
119
- public function getMassActionValues() {
120
- return 'Mage::getResourceModel(\'directory/country_collection\')->toOptionArray()'.$this->getEol();
121
- }
122
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
+ */
18
+ /**
19
+ * country attribute type
20
+ *
21
+ * @category Ultimate
22
+ * @package Ultimate_ModuleCreator
23
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
+ */
25
+ class Ultimate_ModuleCreator_Model_Attribute_Type_Country extends Ultimate_ModuleCreator_Model_Attribute_Type_Abstract
26
+ {
27
+ /**
28
+ * type code
29
+ *
30
+ * @var string
31
+ */
32
+ protected $_type = 'country';
33
+
34
+ /**
35
+ * sql column ddl size
36
+ *
37
+ * @var string
38
+ */
39
+ protected $_sizeDdl = '2';
40
+
41
+ /**
42
+ * eav setup input
43
+ *
44
+ * @var string
45
+ */
46
+ protected $_setupInput = 'select';
47
+
48
+ /**
49
+ * get admin column options
50
+ *
51
+ * @access public
52
+ * @return string
53
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
54
+ */
55
+ public function getAdminColumnOptions()
56
+ {
57
+ $options = $this->getEol();
58
+ $options .= $this->getPadding(4);
59
+ $options .= "'type'=> 'country',".$this->getEol();
60
+ return $options;
61
+ }
62
+
63
+ /**
64
+ * get the type for the form
65
+ *
66
+ * @access public
67
+ * @return string
68
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
69
+ */
70
+ public function getFormType()
71
+ {
72
+ return 'select';
73
+ }
74
+
75
+ /**
76
+ * get text for rss
77
+ *
78
+ * @access public
79
+ * @return string
80
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
81
+ */
82
+ public function getRssText()
83
+ {
84
+ $eol = $this->getEol();
85
+ $module = $this->getModule()->getLowerModuleName();
86
+ $namespace = $this->getNamespace(true);
87
+ $text = $this->getPadding(3);
88
+ $text .= '$description .= \'<div>\''.$eol.$this->getPadding(4).'.Mage::helper(\'';
89
+ $text .= $namespace.'_'.$module;
90
+ $text .= '\')->__("';
91
+ $text .= $this->getAttribute()->getLabel();
92
+ $text .= '").\':'.$eol.$this->getPadding(4).'\'.(($item->get';
93
+ $text .= $this->getAttribute()->getMagicMethodCode();
94
+ $text .= '()) '.$eol.$this->getPadding(4).'? Mage::getModel(\'directory/country\')->load($item->get';
95
+ $text .= $this->getAttribute()->getMagicMethodCode();
96
+ $text .= '())->getName():'.$eol.$this->getPadding(4).'Mage::helper(\'';
97
+ $text .= $namespace.'_'.$module;
98
+ $text .= '\')->__(\'None\')).'.$eol.$this->getPadding(4).'\'</div>\';'.$this->getEol();
99
+ return $text;
100
+ }
101
+
102
+ /**
103
+ * get html for frontend
104
+ *
105
+ * @access public
106
+ * @return string
107
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
108
+ */
109
+ public function getFrontendHtml()
110
+ {
111
+ $entityName = $this->getEntity()->getNameSingular(true);
112
+ $module = $this->getModule()->getLowerModuleName();
113
+ $namespace = $this->getNamespace(true);
114
+ if ($this->getEntity()->getIsEav()) {
115
+ $html = '<?php echo Mage::helper(\'';
116
+ $html .= $namespace.'_'.$module;
117
+ $html .= '\')->__("';
118
+ $html .= $this->getAttribute()->getLabel();
119
+ $html .= '");?>:<?php echo $_';
120
+ $html .= $this->getEntity()->getNameSingular(true);
121
+ $html .= '->getAttributeText(\'';
122
+ $html .= $this->getAttribute()->getCode().'\');?>'.$this->getEol();
123
+ return $html;
124
+ }
125
+ $html = '<?php echo Mage::helper(\'';
126
+ $html .= $namespace.'_'.$module;
127
+ $html .= '\')->__("';
128
+ $html .= $this->getAttribute()->getLabel();
129
+ $html .= '");?>:<?php echo ($_';
130
+ $html .= $entityName.'->get'.$this->getAttribute()->getMagicMethodCode();
131
+ $html .= '()) ? Mage::getModel(\'directory/country\')->load($_';
132
+ $html .= $entityName.'->get'.$this->getAttribute()->getMagicMethodCode();
133
+ $html .= '())->getName():Mage::helper(\'';
134
+ $html .= $namespace.'_'.$module;
135
+ $html .= '\')->__(\'None\') ?>'.$this->getEol();
136
+ return $html;
137
+ }
138
+
139
+ /**
140
+ * get source for setup
141
+ *
142
+ * @access public
143
+ * @return string|void
144
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
145
+ */
146
+ public function getSetupSource()
147
+ {
148
+ $module = $this->getModule()->getLowerModuleName();
149
+ $namespace = $this->getNamespace(true);
150
+ return $namespace.'_'.$module.'/attribute_source_country';
151
+ }
152
+
153
+ /**
154
+ * get admin from options
155
+ *
156
+ * @access public
157
+ * @return string
158
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
159
+ */
160
+ public function getFormOptions()
161
+ {
162
+ $options = parent::getFormOptions();
163
+ $options .= $this->getPadding(3);
164
+ $options .="'values'=> Mage::getResourceModel('directory/country_collection')->toOptionArray(),";
165
+ $options .= $this->getEol();
166
+ return $options;
167
+ }
168
+
169
+ /**
170
+ * get values for mass action
171
+ *
172
+ * @access public
173
+ * @return string
174
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
175
+ */
176
+ public function getMassActionValues()
177
+ {
178
+ return 'Mage::getResourceModel(\'directory/country_collection\')->toOptionArray()'.$this->getEol();
179
+ }
180
+ }
app/code/community/Ultimate/ModuleCreator/Model/Attribute/Type/Decimal.php CHANGED
@@ -1,47 +1,54 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
- */
18
- /**
19
- * decimal attribute type
20
- *
21
- * @category Ultimate
22
- * @package Ultimate_ModuleCreator
23
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
- */
25
- class Ultimate_ModuleCreator_Model_Attribute_Type_Decimal
26
- extends Ultimate_ModuleCreator_Model_Attribute_Type_Int {
27
- /**
28
- * type code
29
- * @var string
30
- */
31
- protected $_type = 'decimal';
32
- /**
33
- * sql column ddl type
34
- * @var string
35
- */
36
- protected $_typeDdl = 'TYPE_DECIMAL';
37
- /**
38
- * sql column ddl size
39
- * @var string
40
- */
41
- protected $_sizeDdl = "'12,4'";
42
- /**
43
- * eav setup type
44
- * @var string
45
- */
46
- protected $_setupType = 'decimal';
47
- }
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
+ */
18
+ /**
19
+ * decimal attribute type
20
+ *
21
+ * @category Ultimate
22
+ * @package Ultimate_ModuleCreator
23
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
+ */
25
+ class Ultimate_ModuleCreator_Model_Attribute_Type_Decimal extends Ultimate_ModuleCreator_Model_Attribute_Type_Int
26
+ {
27
+ /**
28
+ * type code
29
+ *
30
+ * @var string
31
+ */
32
+ protected $_type = 'decimal';
33
+
34
+ /**
35
+ * sql column ddl type
36
+ *
37
+ * @var string
38
+ */
39
+ protected $_typeDdl = 'TYPE_DECIMAL';
40
+
41
+ /**
42
+ * sql column ddl size
43
+ *
44
+ * @var string
45
+ */
46
+ protected $_sizeDdl = "'12,4'";
47
+
48
+ /**
49
+ * eav setup type
50
+ *
51
+ * @var string
52
+ */
53
+ protected $_setupType = 'decimal';
54
+ }
app/code/community/Ultimate/ModuleCreator/Model/Attribute/Type/Dropdown.php CHANGED
@@ -1,312 +1,412 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
- */
18
- /**
19
- * dropdown attribute type
20
- *
21
- * @category Ultimate
22
- * @package Ultimate_ModuleCreator
23
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
- */
25
- class Ultimate_ModuleCreator_Model_Attribute_Type_Dropdown
26
- extends Ultimate_ModuleCreator_Model_Attribute_Type_Abstract {
27
- /**
28
- * type code
29
- * @var string
30
- */
31
- protected $_type = 'dropdown';
32
- /**
33
- * dropdown subtype
34
- * @var Ultimate_ModuleCreator_Model_Abstract
35
- */
36
- protected $_subTypeInstance;
37
- /**
38
- * sql colum ddl type
39
- * @var string
40
- */
41
- protected $_typeDdl = 'TYPE_INTEGER';
42
- /**
43
- * sql colum ddl size
44
- * @var string
45
- */
46
- protected $_sizeDdl = 'null';
47
- /**
48
- * eav setup type
49
- */
50
- protected $_setupType = 'int';
51
- /**
52
- * eav setup input
53
- */
54
- protected $_setupInput = 'select';
55
- /**
56
- * eav setup source
57
- * @var string
58
- */
59
- protected $_setupSource = 'eav/entity_attribute_source_table';
60
-
61
- /**
62
- * get source for setup
63
- * @access public
64
- * @return string|void
65
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
66
- */
67
- public function getSetupSource() {
68
- if (!$this->getGenerateSource()){
69
- return parent::getSetupSource();
70
- }
71
- $module = $this->getModule()->getLowerModuleName();
72
- $namespace = $this->getNamespace(true);
73
- $entity = $this->getEntity()->getNameSingular(true);
74
- return $namespace.'_'.$module.'/'.$entity.'_attribute_source_'.$this->getAttribute()->getCodeForFileName();
75
- }
76
- /**
77
- * get admin column options
78
- * @return string
79
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
80
- */
81
- public function getAdminColumnOptions() {
82
- $options = $this->getEol();
83
- $module = $this->getModule()->getLowerModuleName();
84
- $namespace = $this->getNamespace(true);
85
- $entity = strtolower($this->getAttribute()->getEntity()->getNameSingular());
86
- $attr = $this->getAttribute()->getCode();
87
- $options .= $this->getPadding(3)."'type' => 'options',".$this->getEol();
88
- if ($this->getAttribute()->getEntity()->getIsEav()) {
89
- $options .= $this->getPadding(3)."'options' => Mage::helper('".$namespace.'_'.$module."')->convertOptions(Mage::getModel('eav/config')->getAttribute('".$namespace.'_'.$module.'_'.$entity."', '".$attr."')->getSource()->getAllOptions(false))".$this->getEol();
90
- }
91
- else {
92
- $options .= $this->getPadding(3)."'options' => Mage::helper('".$namespace.'_'.$module."')->convertOptions(Mage::getModel('".$namespace.'_'.$module.'/'.$entity."_attribute_source_".$this->getAttribute()->getCodeForFileName(false)."')->getAllOptions(false))".$this->getEol();
93
- }
94
- return $options;
95
- }
96
- /**
97
- * get the type for the form
98
- * @access public
99
- * @return string
100
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
101
- */
102
- public function getFormType(){
103
- return 'select';
104
- }
105
- /**
106
- * get text for rss
107
- * @access public
108
- * @return string
109
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
110
- */
111
- public function getRssText(){
112
- $entityName = $this->getEntity()->getNameSingular(true);
113
- $module = $this->getModule()->getLowerModuleName();
114
- $namespace = $this->getNamespace(true);
115
- if ($this->getAttribute()->getEntity()->getIsEav()){
116
- return $this->getPadding(3).'$description .= \'<div>\'.Mage::helper(\''.$namespace.'_'.$module.'\')->__("'.$this->getAttribute()->getLabel().'").\': \'.$item->getAttributeText(\''.$this->getAttribute()->getCode().'\').\'</div>\';'.$this->getEol();
117
- }
118
- else {
119
- $attributeFile = $this->getAttribute()->getCodeForFileName(false);
120
- $code = $this->getAttribute()->getMagicMethodCode();
121
- return $this->getPadding(3).'$description .= \'<div>\'.Mage::helper(\''.$namespace.'_'.$module.'\')->__("'.$this->getAttribute()->getLabel().'").\': \'.Mage::getSingleton(\''.$namespace.'_'.$module.'/'.$entityName.'_attribute_source_'.$attributeFile.'\')->getOptionText($item->get'.$code.'()).\'</div>\';'.$this->getEol();
122
- }
123
- }
124
- /**
125
- * check if source needs to be generated
126
- * @access public
127
- * @return string
128
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
129
- */
130
- public function getGenerateSource(){
131
- return $this->getSubTypeInstance()->getGenerateSource();
132
- }
133
- /**
134
- * get subtype instance
135
- * @access public
136
- * @return Ultimate_ModuleCreator_Model_Attribute_Type_Dropdown_Abstract
137
- * @throws Ultimate_ModuleCreator_Exception
138
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
139
- */
140
- public function getSubTypeInstance(){
141
- if (!$this->_subTypeInstance){
142
- $type = $this->getAttribute()->getOptionsSource();
143
- try{
144
- /** @var Ultimate_ModuleCreator_Helper_Data $helper */
145
- $helper = Mage::helper('modulecreator');
146
- $types = $helper->getDropdownSubtypes(false);
147
- $instanceModel = (string)$types->$type->type_model;
148
- /** @var Ultimate_ModuleCreator_Model_Attribute_Type_Dropdown_Abstract $subtypeInstance */
149
- $subtypeInstance = Mage::getModel($instanceModel);
150
- $this->_subTypeInstance = $subtypeInstance;
151
- $this->_subTypeInstance->setTypeAttribute($this);
152
- }
153
- catch (Exception $e){
154
- throw new Ultimate_ModuleCreator_Exception("Invalid dropdown subtype: ". $type);
155
- }
156
- }
157
- return $this->_subTypeInstance;
158
- }
159
- /**
160
- * get additional setup values
161
- * @access public
162
- * @return string
163
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
164
- */
165
- public function getAdditionalSetup(){
166
- return $this->getSubTypeInstance()->getAdditionalSetup();
167
- }
168
- /**
169
- * get html for frontend
170
- * @access public
171
- * @return string
172
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
173
- */
174
- public function getFrontendHtml() {
175
- $entityName = $this->getEntity()->getNameSingular(true);
176
- $module = $this->getModule()->getLowerModuleName();
177
- $namespace = $this->getNamespace(true);
178
- if ($this->getAttribute()->getEntity()->getIsEav()){
179
- return '<?php echo Mage::helper(\''.$namespace.'_'.$module.'\')->__("'.$this->getAttribute()->getLabel().'");?>:<?php echo $_'.$entityName.'->getAttributeText(\''.$this->getAttribute()->getCode().'\');?>'.$this->getEol();
180
- }
181
- else {
182
- $attributeFile = $this->getAttribute()->getCodeForFileName(false);
183
- $code = $this->getAttribute()->getMagicMethodCode();
184
- return '<?php echo Mage::helper(\''.$namespace.'_'.$module.'\')->__("'.$this->getAttribute()->getLabel().'");?>:<?php echo Mage::getSingleton(\''.$namespace.'_'.$module.'/'.$entityName.'_attribute_source_'.$attributeFile.'\')->getOptionText($_'.$entityName.'->get'.$code.'())'.';?>'.$this->getEol();
185
- }
186
- }
187
- /**
188
- * get attribute options for source model
189
- * @access public
190
- * @return string
191
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
192
- */
193
- public function getAttributeOptions(){
194
- return $this->getSubTypeInstance()->getAttributeOptions();
195
- }
196
- /**
197
- * get the options for form input
198
- * @access public
199
- * @return string
200
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
201
- */
202
- public function getFormOptions(){
203
- $options = parent::getFormOptions();
204
- $padding = $this->getPadding(3);
205
- $module = $this->getModule()->getLowerModuleName();
206
- $entity = $this->getEntity()->getNameSingular(true);
207
- $namespace = $this->getNamespace(true);
208
- $options .= $padding."'values'=> Mage::getModel('".$namespace.'_'.$module.'/'.$entity."_attribute_source_".$this->getAttribute()->getCodeForFileName(false)."')->getAllOptions(".$this->getOptionsFlag()."),".$this->getEol();
209
- return $options;
210
- }
211
-
212
- /**
213
- * check if options should be returned with empty
214
- * @access public
215
- * @return string
216
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
217
- */
218
- public function getOptionsFlag() {
219
- return 'true';
220
- }
221
- /**
222
- * get the setup type of the dropdown
223
- * @access public
224
- * @return string|void
225
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
226
- */
227
- public function getSetupType(){
228
- $setupType = $this->getSubTypeInstance()->getSetupType();
229
- if (empty($setupType)) {
230
- return parent::getSetupType();
231
- }
232
- return $setupType;
233
- }
234
- /**
235
- * get the setup type of the dropdown
236
- * @access public
237
- * @return string|void
238
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
239
- */
240
- public function getTypeDdl(){
241
- $setupType = $this->getSubTypeInstance()->getTypeDdl();
242
- if (empty($setupType)) {
243
- return parent::getTypeDdl();
244
- }
245
- return $setupType;
246
- }
247
- /**
248
- * get column ddl size
249
- * @access public
250
- * @return string
251
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
252
- */
253
- public function getSizeDdl() {
254
- $size = $this->getSubTypeInstance()->getSizeDdl();
255
- if (empty($size)) {
256
- return parent::getSizeDdl();
257
- }
258
- return $size;
259
- }
260
- /**
261
- * get values for mass action
262
- * @access public
263
- * @return string
264
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
265
- */
266
- public function getMassActionValues() {
267
- $module = $this->getModule()->getLowerModuleName();
268
- $entity = $this->getEntity()->getNameSingular(true);
269
- $namespace = $this->getNamespace(true);
270
- if ($this->getEntity()->getIsEav()) {
271
- return "Mage::getModel('eav/config')->getAttribute('".$namespace.'_'.$module."_".$entity."', '".$this->getAttribute()->getCode()."')->getSource()->getAllOptions(".$this->getOptionsFlag()."),".$this->getEol();
272
- }
273
- else {
274
- return "Mage::getModel('".$namespace.'_'.$module.'/'.$entity."_attribute_source_".$this->getAttribute()->getCodeForFileName(false)."')->getAllOptions(".$this->getOptionsFlag()."),".$this->getEol();
275
- }
276
- }
277
-
278
- /**
279
- * get attribute default value
280
- * @access public
281
- * @return string
282
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
283
- */
284
- public function getDefaultValueProcessed() {
285
- return $this->getSubTypeInstance()->getDefaultValueProcessed();
286
- }
287
- /**
288
- * get attribute default value setup content
289
- * @access public
290
- * @return string
291
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
292
- */
293
- public function getDefaultValueSetup() {
294
- $content = '';
295
- if ($this->getSubTypeInstance() instanceof Ultimate_ModuleCreator_Model_Attribute_Type_Dropdown_Custom
296
- && $this->getAttribute()->getDefaultValue()
297
- ) {
298
- $eol = $this->getEol();
299
- $entity = $this->getEntity();
300
- $attribute= $this->getAttribute();
301
- $content .= '$attribute = Mage::getSingleton(\'eav/config\')->getAttribute(\''.$this->getNamespace(true).'_'.$this->getModule()->getLowerModuleName().'_'.$entity->getNameSingular().'\', \''.$attribute->getCode().'\');'.$eol;
302
- $content .= '$options = $attribute->getSource()->getAllOptions(false);'.$eol;
303
- $content .= 'foreach ($options as $option) {'.$eol;
304
- $content .= $this->getPadding().'if ($option[\'label\'] == \''.Mage::helper('core')->jsQuoteEscape($attribute->getDefaultValue()).'\') {'.$eol;
305
- $content .= $this->getPadding(2).'$this->updateAttribute(\''.$this->getNamespace(true).'_'.$this->getModule()->getLowerModuleName().'_'.$entity->getNameSingular().'\', \''.$attribute->getCode().'\', \'default_value\', $option[\'value\']);'.$eol;
306
- $content .= $this->getPadding().'}'.$eol;
307
- $content .= '}'.$eol;
308
- }
309
- return $content;
310
- }
311
-
312
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
+ */
18
+ /**
19
+ * dropdown attribute type
20
+ *
21
+ * @category Ultimate
22
+ * @package Ultimate_ModuleCreator
23
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
+ */
25
+ class Ultimate_ModuleCreator_Model_Attribute_Type_Dropdown extends Ultimate_ModuleCreator_Model_Attribute_Type_Abstract
26
+ {
27
+ /**
28
+ * type code
29
+ *
30
+ * @var string
31
+ */
32
+ protected $_type = 'dropdown';
33
+
34
+ /**
35
+ * dropdown subtype
36
+ *
37
+ * @var Ultimate_ModuleCreator_Model_Abstract
38
+ */
39
+ protected $_subTypeInstance;
40
+
41
+ /**
42
+ * sql colum ddl type
43
+ *
44
+ * @var string
45
+ */
46
+ protected $_typeDdl = 'TYPE_INTEGER';
47
+
48
+ /**
49
+ * sql colum ddl size
50
+ *
51
+ * @var string
52
+ */
53
+ protected $_sizeDdl = 'null';
54
+
55
+ /**
56
+ * eav setup type
57
+ *
58
+ * @var string
59
+ */
60
+ protected $_setupType = 'int';
61
+
62
+ /**
63
+ * eav setup input
64
+ *
65
+ * @var string
66
+ */
67
+ protected $_setupInput = 'select';
68
+
69
+ /**
70
+ * eav setup source
71
+ *
72
+ * @var string
73
+ */
74
+ protected $_setupSource = 'eav/entity_attribute_source_table';
75
+
76
+ /**
77
+ * get source for setup
78
+ *
79
+ * @access public
80
+ * @return string|void
81
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
82
+ */
83
+ public function getSetupSource()
84
+ {
85
+ if (!$this->getGenerateSource()) {
86
+ return parent::getSetupSource();
87
+ }
88
+ $module = $this->getModule()->getLowerModuleName();
89
+ $namespace = $this->getNamespace(true);
90
+ $entity = $this->getEntity()->getNameSingular(true);
91
+ return $namespace.'_'.$module.'/'.$entity.'_attribute_source_'.$this->getAttribute()->getCodeForFileName();
92
+ }
93
+
94
+ /**
95
+ * get admin column options
96
+ *
97
+ * @return string
98
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
99
+ */
100
+ public function getAdminColumnOptions()
101
+ {
102
+ $options = $this->getEol();
103
+ $module = $this->getModule()->getLowerModuleName();
104
+ $namespace = $this->getNamespace(true);
105
+ $entity = strtolower($this->getAttribute()->getEntity()->getNameSingular());
106
+ $attr = $this->getAttribute()->getCode();
107
+ $options .= $this->getPadding(4)."'type' => 'options',".$this->getEol();
108
+ if ($this->getAttribute()->getEntity()->getIsEav()) {
109
+ $options .= $this->getPadding(4).
110
+ "'options' => Mage::helper('".$namespace.'_'.$module.
111
+ "')->convertOptions(".$this->getEol().$this->getPadding(5)."Mage::getModel('eav/config')->getAttribute('".
112
+ $namespace.'_'.$module.'_'.$entity."', '".$attr.
113
+ "')->getSource()->getAllOptions(false)".$this->getEol().$this->getPadding(4).")".$this->getEol();
114
+ } else {
115
+ $options .= $this->getPadding(4).
116
+ "'options' => Mage::helper('".$namespace.'_'.$module.
117
+ "')->convertOptions(".$this->getEol().$this->getPadding(5)."Mage::getModel('".
118
+ $namespace.'_'.$module.'/'.$entity."_attribute_source_".
119
+ $this->getAttribute()->getCodeForFileName(false).
120
+ "')->getAllOptions(false)".$this->getEol().$this->getPadding(4).")".$this->getEol();
121
+ }
122
+ return $options;
123
+ }
124
+
125
+ /**
126
+ * get the type for the form
127
+ *
128
+ * @access public
129
+ * @return string
130
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
131
+ */
132
+ public function getFormType()
133
+ {
134
+ return 'select';
135
+ }
136
+
137
+ /**
138
+ * get text for rss
139
+ *
140
+ * @access public
141
+ * @return string
142
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
143
+ */
144
+ public function getRssText()
145
+ {
146
+ $eol = $this->getEol();
147
+ $entityName = $this->getEntity()->getNameSingular(true);
148
+ $module = $this->getModule()->getLowerModuleName();
149
+ $namespace = $this->getNamespace(true);
150
+ if ($this->getAttribute()->getEntity()->getIsEav()) {
151
+ return $this->getPadding(3).
152
+ '$description .= \'<div>\'.'.$eol.$this->getPadding(4).'Mage::helper(\''.
153
+ $namespace.'_'.$module.'\')->__("'.$this->getAttribute()->getLabel().
154
+ '").\': \''.$eol.$this->getPadding(4).'.$item->getAttributeText(\''.
155
+ $this->getAttribute()->getCode().'\').'.$eol.$this->getPadding(4).'\'</div>\';'.$this->getEol();
156
+ } else {
157
+ $attributeFile = $this->getAttribute()->getCodeForFileName(false);
158
+ $code = $this->getAttribute()->getMagicMethodCode();
159
+ return $this->getPadding(3).
160
+ '$description .= \'<div>\'.'.$eol.$this->getPadding(4).'Mage::helper(\''.
161
+ $namespace.'_'.$module.'\')->__("'.
162
+ $this->getAttribute()->getLabel().'").\': \''.$eol.$this->getPadding(4).'.Mage::getSingleton(\''.
163
+ $namespace.'_'.$module.'/'.$entityName.'_attribute_source_'.$attributeFile.
164
+ '\')->getOptionText($item->get'.$code.'()).'.$eol.$this->getPadding(4).'\'</div>\';'.$this->getEol();
165
+ }
166
+ }
167
+
168
+ /**
169
+ * check if source needs to be generated
170
+ *
171
+ * @access public
172
+ * @return string
173
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
174
+ */
175
+ public function getGenerateSource()
176
+ {
177
+ return $this->getSubTypeInstance()->getGenerateSource();
178
+ }
179
+
180
+ /**
181
+ * get subtype instance
182
+ *
183
+ * @access public
184
+ * @return Ultimate_ModuleCreator_Model_Attribute_Type_Dropdown_Abstract
185
+ * @throws Ultimate_ModuleCreator_Exception
186
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
187
+ */
188
+ public function getSubTypeInstance()
189
+ {
190
+ if (!$this->_subTypeInstance) {
191
+ $type = $this->getAttribute()->getOptionsSource();
192
+ try{
193
+ /** @var Ultimate_ModuleCreator_Helper_Data $helper */
194
+ $helper = Mage::helper('modulecreator');
195
+ $types = $helper->getDropdownSubtypes(false);
196
+ $instanceModel = (string)$types->$type->type_model;
197
+ /** @var Ultimate_ModuleCreator_Model_Attribute_Type_Dropdown_Abstract $subtypeInstance */
198
+ $subtypeInstance = Mage::getModel($instanceModel);
199
+ $this->_subTypeInstance = $subtypeInstance;
200
+ $this->_subTypeInstance->setTypeAttribute($this);
201
+ } catch (Exception $e){
202
+ throw new Ultimate_ModuleCreator_Exception("Invalid dropdown subtype: ". $type);
203
+ }
204
+ }
205
+ return $this->_subTypeInstance;
206
+ }
207
+
208
+ /**
209
+ * get additional setup values
210
+ *
211
+ * @access public
212
+ * @return string
213
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
214
+ */
215
+ public function getAdditionalSetup()
216
+ {
217
+ return $this->getSubTypeInstance()->getAdditionalSetup();
218
+ }
219
+
220
+ /**
221
+ * get html for frontend
222
+ *
223
+ * @access public
224
+ * @return string
225
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
226
+ */
227
+ public function getFrontendHtml()
228
+ {
229
+ $entityName = $this->getEntity()->getNameSingular(true);
230
+ $module = $this->getModule()->getLowerModuleName();
231
+ $namespace = $this->getNamespace(true);
232
+ if ($this->getAttribute()->getEntity()->getIsEav()) {
233
+ return '<?php echo Mage::helper(\''.
234
+ $namespace.'_'.$module.'\')->__("'.
235
+ $this->getAttribute()->getLabel().'");?>:<?php echo $_'.
236
+ $entityName.'->getAttributeText(\''.
237
+ $this->getAttribute()->getCode().'\');?>'.$this->getEol();
238
+ } else {
239
+ $attributeFile = $this->getAttribute()->getCodeForFileName(false);
240
+ $code = $this->getAttribute()->getMagicMethodCode();
241
+ return '<?php echo Mage::helper(\''.
242
+ $namespace.'_'.$module.'\')->__("'.
243
+ $this->getAttribute()->getLabel().
244
+ '");?>:<?php echo Mage::getSingleton(\''.
245
+ $namespace.'_'.$module.'/'.$entityName.'_attribute_source_'.$attributeFile.
246
+ '\')->getOptionText($_'.$entityName.'->get'.$code.'())'.';?>'.$this->getEol();
247
+ }
248
+ }
249
+
250
+ /**
251
+ * get attribute options for source model
252
+ *
253
+ * @access public
254
+ * @return string
255
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
256
+ */
257
+ public function getAttributeOptions()
258
+ {
259
+ return $this->getSubTypeInstance()->getAttributeOptions();
260
+ }
261
+
262
+ /**
263
+ * get the options for form input
264
+ *
265
+ * @access public
266
+ * @return string
267
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
268
+ */
269
+ public function getFormOptions()
270
+ {
271
+ $options = parent::getFormOptions();
272
+ $padding = $this->getPadding(3);
273
+ $module = $this->getModule()->getLowerModuleName();
274
+ $entity = $this->getEntity()->getNameSingular(true);
275
+ $namespace = $this->getNamespace(true);
276
+ $options .= $padding."'values'=> Mage::getModel('".
277
+ $namespace.'_'.$module.'/'.$entity."_attribute_source_".
278
+ $this->getAttribute()->getCodeForFileName(false).
279
+ "')->getAllOptions(".$this->getOptionsFlag()."),".$this->getEol();
280
+ return $options;
281
+ }
282
+
283
+ /**
284
+ * check if options should be returned with empty
285
+ *
286
+ * @access public
287
+ * @return string
288
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
289
+ */
290
+ public function getOptionsFlag()
291
+ {
292
+ return 'true';
293
+ }
294
+
295
+ /**
296
+ * get the setup type of the dropdown
297
+ *
298
+ * @access public
299
+ * @return string|void
300
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
301
+ */
302
+ public function getSetupType()
303
+ {
304
+ $setupType = $this->getSubTypeInstance()->getSetupType();
305
+ if (empty($setupType)) {
306
+ return parent::getSetupType();
307
+ }
308
+ return $setupType;
309
+ }
310
+
311
+ /**
312
+ * get the setup type of the dropdown
313
+ *
314
+ * @access public
315
+ * @return string|void
316
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
317
+ */
318
+ public function getTypeDdl()
319
+ {
320
+ $setupType = $this->getSubTypeInstance()->getTypeDdl();
321
+ if (empty($setupType)) {
322
+ return parent::getTypeDdl();
323
+ }
324
+ return $setupType;
325
+ }
326
+
327
+ /**
328
+ * get column ddl size
329
+ *
330
+ * @access public
331
+ * @return string
332
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
333
+ */
334
+ public function getSizeDdl()
335
+ {
336
+ $size = $this->getSubTypeInstance()->getSizeDdl();
337
+ if (empty($size)) {
338
+ return parent::getSizeDdl();
339
+ }
340
+ return $size;
341
+ }
342
+
343
+ /**
344
+ * get values for mass action
345
+ *
346
+ * @access public
347
+ * @return string
348
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
349
+ */
350
+ public function getMassActionValues()
351
+ {
352
+ $module = $this->getModule()->getLowerModuleName();
353
+ $entity = $this->getEntity()->getNameSingular(true);
354
+ $namespace = $this->getNamespace(true);
355
+ if ($this->getEntity()->getIsEav()) {
356
+ return "Mage::getModel('eav/config')->getAttribute('".
357
+ $namespace.'_'.$module."_".$entity."', '".
358
+ $this->getAttribute()->getCode()."')".$this->getEol().$this->getPadding(7)."->getSource()->getAllOptions(".
359
+ $this->getOptionsFlag()."),".$this->getEol();
360
+ } else {
361
+ return "Mage::getModel('".
362
+ $namespace.'_'.$module.'/'.$entity."_attribute_source_".
363
+ $this->getAttribute()->getCodeForFileName(false).
364
+ "')".$this->getEol().$this->getPadding(7)."->getAllOptions(".$this->getOptionsFlag()."),".$this->getEol();
365
+ }
366
+ }
367
+
368
+ /**
369
+ * get attribute default value
370
+ *
371
+ * @access public
372
+ * @return string
373
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
374
+ */
375
+ public function getDefaultValueProcessed()
376
+ {
377
+ return $this->getSubTypeInstance()->getDefaultValueProcessed();
378
+ }
379
+
380
+ /**
381
+ * get attribute default value setup content
382
+ *
383
+ * @access public
384
+ * @return string
385
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
386
+ */
387
+ public function getDefaultValueSetup()
388
+ {
389
+ $content = '';
390
+ if ($this->getSubTypeInstance() instanceof Ultimate_ModuleCreator_Model_Attribute_Type_Dropdown_Custom
391
+ && $this->getAttribute()->getDefaultValue()
392
+ ) {
393
+ $eol = $this->getEol();
394
+ $entity = $this->getEntity();
395
+ $attribute= $this->getAttribute();
396
+ $content .= '$attribute = Mage::getSingleton(\'eav/config\')->getAttribute(\''.
397
+ $this->getNamespace(true).'_'.$this->getModule()->getLowerModuleName().'_'.$entity->getNameSingular().
398
+ '\', \''.$attribute->getCode().'\');'.$eol;
399
+ $content .= '$options = $attribute->getSource()->getAllOptions(false);'.$eol;
400
+ $content .= 'foreach ($options as $option) {'.$eol;
401
+ $content .= $this->getPadding().'if ($option[\'label\'] == \''.
402
+ Mage::helper('core')->jsQuoteEscape($attribute->getDefaultValue()).'\') {'.$eol;
403
+ $content .= $this->getPadding(2).
404
+ '$this->updateAttribute(\''.
405
+ $this->getNamespace(true).'_'.$this->getModule()->getLowerModuleName().'_'.$entity->getNameSingular().
406
+ '\', \''.$attribute->getCode().'\', \'default_value\', $option[\'value\']);'.$eol;
407
+ $content .= $this->getPadding().'}'.$eol;
408
+ $content .= '}'.$eol;
409
+ }
410
+ return $content;
411
+ }
412
+ }
app/code/community/Ultimate/ModuleCreator/Model/Attribute/Type/Dropdown/Abstract.php CHANGED
@@ -1,87 +1,101 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
- */
18
- /**
19
- * abstract attribute dropdown type
20
- *
21
- * @category Ultimate
22
- * @package Ultimate_ModuleCreator
23
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
- */
25
- /**
26
- * @method string getAttributeOptions
27
- * @method string getSetupType()
28
- * @method string getTypeDdl()
29
- * @method string getSizeDdl()
30
- */
31
- class Ultimate_ModuleCreator_Model_Attribute_Type_Dropdown_Abstract
32
- extends Ultimate_ModuleCreator_Model_Abstract {
33
- /**
34
- * type attribute
35
- * @var Ultimate_ModuleCreator_Model_Attribute_Type_Decimal
36
- */
37
- protected $_typeAttribute;
38
- /**
39
- * check if source needs to be generated
40
- * @access public
41
- * @return string
42
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
43
- */
44
- public function getGenerateSource(){
45
- return true;
46
- }
47
-
48
- /**
49
- * type attribute setter
50
- * @access public
51
- * @param Ultimate_ModuleCreator_Model_Attribute_Type_Dropdown $attributeType
52
- * @return $this
53
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
54
- */
55
- public function setTypeAttribute(Ultimate_ModuleCreator_Model_Attribute_Type_Dropdown $attributeType){
56
- $this->_typeAttribute = $attributeType;
57
- return $this;
58
- }
59
-
60
- /**
61
- * type attribute getter
62
- * @access public
63
- * @return Ultimate_ModuleCreator_Model_Attribute_Type_Dropdown
64
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
65
- */
66
- public function getTypeAttribute(){
67
- return $this->_typeAttribute;
68
- }
69
- /**
70
- * get additional setup values
71
- * @access public
72
- * @return string
73
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
74
- */
75
- public function getAdditionalSetup(){
76
- return '';
77
- }
78
- /**
79
- * get attribute default value
80
- * @access public
81
- * @return string
82
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
83
- */
84
- public function getDefaultValueProcessed() {
85
- return '';
86
- }
87
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
+ */
18
+ /**
19
+ * abstract attribute dropdown type
20
+ *
21
+ * @category Ultimate
22
+ * @package Ultimate_ModuleCreator
23
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
+ */
25
+ /**
26
+ * @method string getAttributeOptions
27
+ * @method string getSetupType()
28
+ * @method string getTypeDdl()
29
+ * @method string getSizeDdl()
30
+ */
31
+ class Ultimate_ModuleCreator_Model_Attribute_Type_Dropdown_Abstract extends Ultimate_ModuleCreator_Model_Abstract
32
+ {
33
+ /**
34
+ * type attribute
35
+ *
36
+ * @var Ultimate_ModuleCreator_Model_Attribute_Type_Decimal
37
+ */
38
+ protected $_typeAttribute;
39
+
40
+ /**
41
+ * check if source needs to be generated
42
+ *
43
+ * @access public
44
+ * @return string
45
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
46
+ */
47
+ public function getGenerateSource()
48
+ {
49
+ return true;
50
+ }
51
+
52
+ /**
53
+ * type attribute setter
54
+ *
55
+ * @access public
56
+ * @param Ultimate_ModuleCreator_Model_Attribute_Type_Dropdown $attributeType
57
+ * @return $this
58
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
59
+ */
60
+ public function setTypeAttribute(Ultimate_ModuleCreator_Model_Attribute_Type_Dropdown $attributeType)
61
+ {
62
+ $this->_typeAttribute = $attributeType;
63
+ return $this;
64
+ }
65
+
66
+ /**
67
+ * type attribute getter
68
+ *
69
+ * @access public
70
+ * @return Ultimate_ModuleCreator_Model_Attribute_Type_Dropdown
71
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
72
+ */
73
+ public function getTypeAttribute()
74
+ {
75
+ return $this->_typeAttribute;
76
+ }
77
+
78
+ /**
79
+ * get additional setup values
80
+ *
81
+ * @access public
82
+ * @return string
83
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
84
+ */
85
+ public function getAdditionalSetup()
86
+ {
87
+ return '';
88
+ }
89
+
90
+ /**
91
+ * get attribute default value
92
+ *
93
+ * @access public
94
+ * @return string
95
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
96
+ */
97
+ public function getDefaultValueProcessed()
98
+ {
99
+ return '';
100
+ }
101
+ }
app/code/community/Ultimate/ModuleCreator/Model/Attribute/Type/Dropdown/Category.php CHANGED
@@ -1,32 +1,33 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
- */
18
- /**
19
- * category attribute dropdown type
20
- *
21
- * @category Ultimate
22
- * @package Ultimate_ModuleCreator
23
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
- */
25
- class Ultimate_ModuleCreator_Model_Attribute_Type_Dropdown_Category
26
- extends Ultimate_ModuleCreator_Model_Attribute_Type_Dropdown_Product {
27
- /**
28
- * entity code for source
29
- * @var string
30
- */
31
- protected $_entityCode = 'catalog_category';
32
- }
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
+ */
18
+ /**
19
+ * category attribute dropdown type
20
+ *
21
+ * @category Ultimate
22
+ * @package Ultimate_ModuleCreator
23
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
+ */
25
+ class Ultimate_ModuleCreator_Model_Attribute_Type_Dropdown_Category extends Ultimate_ModuleCreator_Model_Attribute_Type_Dropdown_Product
26
+ {
27
+ /**
28
+ * entity code for source
29
+ *
30
+ * @var string
31
+ */
32
+ protected $_entityCode = 'catalog_category';
33
+ }
app/code/community/Ultimate/ModuleCreator/Model/Attribute/Type/Dropdown/Custom.php CHANGED
@@ -1,124 +1,134 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
- */
18
- /**
19
- * custom attribute dropdown type
20
- *
21
- * @category Ultimate
22
- * @package Ultimate_ModuleCreator
23
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
- */
25
- class Ultimate_ModuleCreator_Model_Attribute_Type_Dropdown_Custom
26
- extends Ultimate_ModuleCreator_Model_Attribute_Type_Dropdown_Abstract {
27
- /**
28
- * check if source needs to be generated
29
- * @access public
30
- * @return string
31
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
32
- */
33
- public function getGenerateSource(){
34
- return $this->getTypeAttribute()->getAttribute()->getEntity()->getIsFlat();
35
- }
36
- /**
37
- * get additional setup values
38
- * @access public
39
- * @return string
40
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
41
- */
42
- public function getAdditionalSetup(){
43
- $content = '';
44
- if ($this->getTypeAttribute()->getAttribute()->getEntity()->getIsEav()){
45
- $padding = $this->getPadding(6);
46
- $tab = $this->getPadding();
47
- $eol = $this->getEol();
48
- if ($this->getTypeAttribute()->getAttribute()->getOptions()) {
49
- $content .= $padding."'option' =>".$eol;
50
- $content .= $padding.$tab."array (".$eol;
51
- $content .= $padding.$tab.$tab."'values' =>".$eol;
52
- $content .= $padding.$tab.$tab.$tab."array (".$eol;
53
- foreach ($this->getTypeAttribute()->getAttribute()->getOptions(true) as $option) {
54
- $content .= $padding.$tab.$tab.$tab.$tab."'".Mage::helper('core')->jsQuoteEscape($option)."',".$eol;
55
- }
56
- $content .= $padding.$tab.$tab.$tab."),".$eol;
57
- $content .= $padding.$tab.$tab."),".$eol;
58
- }
59
- }
60
- return $content;
61
- }
62
- /**
63
- * get attribute options for source model
64
- * @access public
65
- * @return string
66
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
67
- */
68
- public function getAttributeOptions(){
69
- $content = '';
70
- $padding = $this->getPadding(2);
71
- $tab = $this->getPadding();
72
- $eol = $this->getEol();
73
- $module = $this->getTypeAttribute()->getAttribute()->getEntity()->getModule()->getLowerModuleName();
74
- $namespace = $this->getTypeAttribute()->getAttribute()->getEntity()->getModule()->getNamespace(true);
75
- if ($this->getTypeAttribute()->getAttribute()->getOptions()) {
76
- $content .= $padding.'$options = array('.$eol;
77
- foreach ($this->getTypeAttribute()->getAttribute()->getOptions(true) as $index=>$option) {
78
- $content .= $padding.$tab.'array('.$eol;
79
- $content .= $padding.$tab.$tab."'label' => Mage::helper('".$namespace.'_'.$module."')->__('".Mage::helper('core')->jsQuoteEscape($option)."'),".$eol;
80
- $content .= $padding.$tab.$tab."'value' => ".($index+1).$eol;
81
- $content .= $padding.$tab.'),'.$eol;
82
- }
83
- $content .= $padding.");".$eol;
84
- $content .= $padding.'if ($withEmpty) {'.$eol;
85
- $content .= $padding.$tab.'array_unshift($options, array(\'label\'=>\'\', \'value\'=>\'\'));'.$eol;
86
- $content .= $padding.'}'.$eol;
87
- $content .= $padding.'return $options;'.$eol;
88
- }
89
- else {
90
- $content = $padding.'return array();';
91
- }
92
- return $content;
93
- }
94
- /**
95
- * get attribute default value
96
- * @access public
97
- * @return string
98
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
99
- */
100
- public function getDefaultValueProcessed() {
101
- if ($this->getTypeAttribute()->getAttribute()->getForcedDefaultValue()) {
102
- return $this->getTypeAttribute()->getAttribute()->getForcedDefaultValue();
103
- }
104
- if ($this->getTypeAttribute()->getAttribute()->getEntity()->getIsFlat()) {
105
- $options = $this->getTypeAttribute()->getAttribute()->getOptions(true);
106
- $defaultValue = trim($this->getTypeAttribute()->getAttribute()->getDefaultValue());
107
- $defaultValue = explode(Ultimate_ModuleCreator_Model_Attribute::OPTION_SEPARATOR, $defaultValue);
108
- $multiselectValues = array();
109
- foreach ($options as $index=>$option) {
110
- if (in_array($option, $defaultValue)) {
111
- if ($this->getTypeAttribute() instanceof Ultimate_ModuleCreator_Model_Attribute_Type_Multiselect) {
112
- $multiselectValues[] = $index + 1;
113
- }
114
- else {
115
- return ($index + 1);
116
- }
117
- }
118
- }
119
- return implode(',', $multiselectValues);
120
- }
121
- //EAV default values are handled in the install script. there is no way of doing it through the definition.
122
- return '';
123
- }
 
 
 
 
 
 
 
 
 
 
124
  }
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
+ */
18
+ /**
19
+ * custom attribute dropdown type
20
+ *
21
+ * @category Ultimate
22
+ * @package Ultimate_ModuleCreator
23
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
+ */
25
+ class Ultimate_ModuleCreator_Model_Attribute_Type_Dropdown_Custom extends Ultimate_ModuleCreator_Model_Attribute_Type_Dropdown_Abstract
26
+ {
27
+ /**
28
+ * check if source needs to be generated
29
+ *
30
+ * @access public
31
+ * @return string
32
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
33
+ */
34
+ public function getGenerateSource()
35
+ {
36
+ return $this->getTypeAttribute()->getAttribute()->getEntity()->getIsFlat();
37
+ }
38
+
39
+ /**
40
+ * get additional setup values
41
+ *
42
+ * @access public
43
+ * @return string
44
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
45
+ */
46
+ public function getAdditionalSetup()
47
+ {
48
+ $content = '';
49
+ if ($this->getTypeAttribute()->getAttribute()->getEntity()->getIsEav()) {
50
+ $padding = $this->getPadding(6);
51
+ $tab = $this->getPadding();
52
+ $eol = $this->getEol();
53
+ if ($this->getTypeAttribute()->getAttribute()->getOptions()) {
54
+ $content .= $padding."'option' =>".$eol;
55
+ $content .= $padding.$tab."array (".$eol;
56
+ $content .= $padding.$tab.$tab."'values' =>".$eol;
57
+ $content .= $padding.$tab.$tab.$tab."array (".$eol;
58
+ foreach ($this->getTypeAttribute()->getAttribute()->getOptions(true) as $option) {
59
+ $content .= $padding.$tab.$tab.$tab.$tab."'".Mage::helper('core')->jsQuoteEscape($option)."',".$eol;
60
+ }
61
+ $content .= $padding.$tab.$tab.$tab."),".$eol;
62
+ $content .= $padding.$tab.$tab."),".$eol;
63
+ }
64
+ }
65
+ return $content;
66
+ }
67
+
68
+ /**
69
+ * get attribute options for source model
70
+ *
71
+ * @access public
72
+ * @return string
73
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
74
+ */
75
+ public function getAttributeOptions()
76
+ {
77
+ $content = '';
78
+ $padding = $this->getPadding(2);
79
+ $tab = $this->getPadding();
80
+ $eol = $this->getEol();
81
+ $module = $this->getTypeAttribute()->getAttribute()->getEntity()->getModule()->getLowerModuleName();
82
+ $namespace = $this->getTypeAttribute()->getAttribute()->getEntity()->getModule()->getNamespace(true);
83
+ if ($this->getTypeAttribute()->getAttribute()->getOptions()) {
84
+ $content .= $padding.'$options = array('.$eol;
85
+ foreach ($this->getTypeAttribute()->getAttribute()->getOptions(true) as $index=>$option) {
86
+ $content .= $padding.$tab.'array('.$eol;
87
+ $content .= $padding.$tab.$tab."'label' => Mage::helper('";
88
+ $content .= $namespace.'_'.$module."')->__('".Mage::helper('core')->jsQuoteEscape($option)."'),".$eol;
89
+ $content .= $padding.$tab.$tab."'value' => ".($index+1).$eol;
90
+ $content .= $padding.$tab.'),'.$eol;
91
+ }
92
+ $content .= $padding.");".$eol;
93
+ $content .= $padding.'if ($withEmpty) {'.$eol;
94
+ $content .= $padding.$tab.'array_unshift($options, array(\'label\'=>\'\', \'value\'=>\'\'));'.$eol;
95
+ $content .= $padding.'}'.$eol;
96
+ $content .= $padding.'return $options;'.$eol;
97
+ } else {
98
+ $content = $padding.'return array();';
99
+ }
100
+ return $content;
101
+ }
102
+
103
+ /**
104
+ * get attribute default value
105
+ *
106
+ * @access public
107
+ * @return string
108
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
109
+ */
110
+ public function getDefaultValueProcessed()
111
+ {
112
+ if ($this->getTypeAttribute()->getAttribute()->getForcedDefaultValue()) {
113
+ return $this->getTypeAttribute()->getAttribute()->getForcedDefaultValue();
114
+ }
115
+ if ($this->getTypeAttribute()->getAttribute()->getEntity()->getIsFlat()) {
116
+ $options = $this->getTypeAttribute()->getAttribute()->getOptions(true);
117
+ $defaultValue = trim($this->getTypeAttribute()->getAttribute()->getDefaultValue());
118
+ $defaultValue = explode(Ultimate_ModuleCreator_Model_Attribute::OPTION_SEPARATOR, $defaultValue);
119
+ $multiselectValues = array();
120
+ foreach ($options as $index=>$option) {
121
+ if (in_array($option, $defaultValue)) {
122
+ if ($this->getTypeAttribute() instanceof Ultimate_ModuleCreator_Model_Attribute_Type_Multiselect) {
123
+ $multiselectValues[] = $index + 1;
124
+ } else {
125
+ return ($index + 1);
126
+ }
127
+ }
128
+ }
129
+ return implode(',', $multiselectValues);
130
+ }
131
+ //EAV default values are handled in the install script. there is no way of doing it through the definition.
132
+ return '';
133
+ }
134
  }
app/code/community/Ultimate/ModuleCreator/Model/Attribute/Type/Dropdown/Customer.php CHANGED
@@ -1,32 +1,33 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
- */
18
- /**
19
- * customer attribute dropdown type
20
- *
21
- * @category Ultimate
22
- * @package Ultimate_ModuleCreator
23
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
- */
25
- class Ultimate_ModuleCreator_Model_Attribute_Type_Dropdown_Customer
26
- extends Ultimate_ModuleCreator_Model_Attribute_Type_Dropdown_Product {
27
- /**
28
- * entity code for source
29
- * @var string
30
- */
31
- protected $_entityCode = 'customer';
32
- }
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
+ */
18
+ /**
19
+ * customer attribute dropdown type
20
+ *
21
+ * @category Ultimate
22
+ * @package Ultimate_ModuleCreator
23
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
+ */
25
+ class Ultimate_ModuleCreator_Model_Attribute_Type_Dropdown_Customer extends Ultimate_ModuleCreator_Model_Attribute_Type_Dropdown_Product
26
+ {
27
+ /**
28
+ * entity code for source
29
+ *
30
+ * @var string
31
+ */
32
+ protected $_entityCode = 'customer';
33
+ }
app/code/community/Ultimate/ModuleCreator/Model/Attribute/Type/Dropdown/Product.php CHANGED
@@ -1,157 +1,175 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
- */
18
- /**
19
- * product attribute dropdown type
20
- *
21
- * @category Ultimate
22
- * @package Ultimate_ModuleCreator
23
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
- */
25
- class Ultimate_ModuleCreator_Model_Attribute_Type_Dropdown_Product
26
- extends Ultimate_ModuleCreator_Model_Attribute_Type_Dropdown_Abstract {
27
- /**
28
- * entity code for source
29
- * @var string
30
- */
31
- protected $_entityCode = 'catalog_product';
32
- /**
33
- * entity attribute
34
- * @var string
35
- */
36
- protected $_entityAttribute = null;
37
- /**
38
- * get attribute options for source model
39
- * @access public
40
- * @return string
41
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
42
- */
43
- public function getAttributeOptions(){
44
- $content = '';
45
- $padding = $this->getPadding(2);
46
- $eol = $this->getEol();
47
- $attrCode = $this->getTypeAttribute()->getAttribute()->getOptionsSourceAttribute();
48
- $content .= $padding.'$'."source = Mage::getModel('eav/config')->getAttribute('".$this->getEntityCode()."', '".$attrCode."');".$eol;
49
- $content .= $padding.'return $source->getSource()->getAllOptions($withEmpty, $defaultValues);';
50
- return $content;
51
- }
52
-
53
- /**
54
- * get entity code
55
- * @access public
56
- * @return string
57
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
58
- */
59
- public function getEntityCode(){
60
- return $this->_entityCode;
61
- }
62
- /**
63
- * get attribute setup type
64
- * @access public
65
- * @return string
66
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
67
- */
68
- public function getSetupType(){
69
- $attrCode = $this->getTypeAttribute()->getAttribute()->getOptionsSourceAttribute();
70
- /** @var Mage_Eav_Model_Config $config */
71
- $config = Mage::getModel('eav/config');
72
- $productAttribute = $config->getAttribute($this->getEntityCode(), $attrCode);
73
- if ($productAttribute->getId()){
74
- $type = $productAttribute->getBackendType();
75
- if ($type == 'static'){
76
- return false;
77
- }
78
- return $type;
79
- }
80
- return false;
81
- }
82
- /**
83
- * get attribute setup type
84
- * @access public
85
- * @return string
86
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
87
- */
88
- public function getTypeDdl(){
89
- $entityAttribute = $this->_getEntityAttribute();
90
- switch($entityAttribute->getBackendType()){
91
- case 'int':
92
- return 'TYPE_INTEGER';
93
- break;
94
- case 'varchar':
95
- return 'TYPE_TEXT';
96
- break;
97
- case 'text':
98
- return 'TYPE_TEXT';
99
- case 'datetime':
100
- return 'TYPE_DATETIME';
101
- break;
102
- case 'decimal':
103
- return 'TYPE_DECIMAL';
104
- break;
105
- default:
106
- return false;
107
- break;
108
- }
109
- }
110
-
111
- /**
112
- * get attribute setup type
113
- * @access public
114
- * @return string
115
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
116
- */
117
- public function getTypeSize(){
118
- $entityAttribute = $this->_getEntityAttribute();
119
- switch($entityAttribute->getBackendType()){
120
- case 'int':
121
- return 'null';
122
- break;
123
- case 'varchar':
124
- return '255';
125
- break;
126
- case 'text':
127
- return "'64k'";
128
- break;
129
- case 'datetime':
130
- return "255";
131
- break;
132
- case 'decimal':
133
- return "'12,4'";
134
- break;
135
- default:
136
- return false;
137
- break;
138
- }
139
- }
140
-
141
- /**
142
- * get the source model attribute
143
- * @access public
144
- * @return null|Mage_Eav_Model_Entity_Attribute_Abstract
145
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
146
- */
147
- protected function _getEntityAttribute(){
148
- if (is_null($this->_entityAttribute)){
149
- $attrCode = $this->getTypeAttribute()->getAttribute()->getOptionsSourceAttribute();
150
- /** @var Mage_Eav_Model_Config $config */
151
- $config = Mage::getModel('eav/config');
152
- $productAttribute = $config->getAttribute($this->getEntityCode(), $attrCode);
153
- $this->_entityAttribute = $productAttribute;
154
- }
155
- return $this->_entityAttribute;
156
- }
157
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
+ */
18
+ /**
19
+ * product attribute dropdown type
20
+ *
21
+ * @category Ultimate
22
+ * @package Ultimate_ModuleCreator
23
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
+ */
25
+ class Ultimate_ModuleCreator_Model_Attribute_Type_Dropdown_Product extends Ultimate_ModuleCreator_Model_Attribute_Type_Dropdown_Abstract
26
+ {
27
+ /**
28
+ * entity code for source
29
+ *
30
+ * @var string
31
+ */
32
+ protected $_entityCode = 'catalog_product';
33
+ /**
34
+ * entity attribute
35
+ *
36
+ * @var string
37
+ */
38
+ protected $_entityAttribute = null;
39
+
40
+ /**
41
+ * get attribute options for source model
42
+ *
43
+ * @access public
44
+ * @return string
45
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
46
+ */
47
+ public function getAttributeOptions()
48
+ {
49
+ $content = '';
50
+ $padding = $this->getPadding(2);
51
+ $eol = $this->getEol();
52
+ $attrCode = $this->getTypeAttribute()->getAttribute()->getOptionsSourceAttribute();
53
+ $content .= $padding.'$'."source = Mage::getModel('eav/config')->getAttribute('";
54
+ $content .= $this->getEntityCode()."', '".$attrCode."');".$eol;
55
+ $content .= $padding.'return $source->getSource()->getAllOptions($withEmpty, $defaultValues);';
56
+ return $content;
57
+ }
58
+
59
+ /**
60
+ * get entity code
61
+ *
62
+ * @access public
63
+ * @return string
64
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
65
+ */
66
+ public function getEntityCode()
67
+ {
68
+ return $this->_entityCode;
69
+ }
70
+
71
+ /**
72
+ * get attribute setup type
73
+ *
74
+ * @access public
75
+ * @return string
76
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
77
+ */
78
+ public function getSetupType()
79
+ {
80
+ $attrCode = $this->getTypeAttribute()->getAttribute()->getOptionsSourceAttribute();
81
+ /** @var Mage_Eav_Model_Config $config */
82
+ $config = Mage::getModel('eav/config');
83
+ $productAttribute = $config->getAttribute($this->getEntityCode(), $attrCode);
84
+ if ($productAttribute->getId()) {
85
+ $type = $productAttribute->getBackendType();
86
+ if ($type == 'static') {
87
+ return false;
88
+ }
89
+ return $type;
90
+ }
91
+ return false;
92
+ }
93
+
94
+ /**
95
+ * get attribute setup type
96
+ *
97
+ * @access public
98
+ * @return string
99
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
100
+ */
101
+ public function getTypeDdl()
102
+ {
103
+ $entityAttribute = $this->_getEntityAttribute();
104
+ switch($entityAttribute->getBackendType()) {
105
+ case 'int':
106
+ return 'TYPE_INTEGER';
107
+ break;
108
+ case 'varchar':
109
+ return 'TYPE_TEXT';
110
+ break;
111
+ case 'text':
112
+ return 'TYPE_TEXT';
113
+ case 'datetime':
114
+ return 'TYPE_DATETIME';
115
+ break;
116
+ case 'decimal':
117
+ return 'TYPE_DECIMAL';
118
+ break;
119
+ default:
120
+ return false;
121
+ break;
122
+ }
123
+ }
124
+
125
+ /**
126
+ * get attribute setup type
127
+ *
128
+ * @access public
129
+ * @return string
130
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
131
+ */
132
+ public function getTypeSize()
133
+ {
134
+ $entityAttribute = $this->_getEntityAttribute();
135
+ switch($entityAttribute->getBackendType()) {
136
+ case 'int':
137
+ return 'null';
138
+ break;
139
+ case 'varchar':
140
+ return '255';
141
+ break;
142
+ case 'text':
143
+ return "'64k'";
144
+ break;
145
+ case 'datetime':
146
+ return "255";
147
+ break;
148
+ case 'decimal':
149
+ return "'12,4'";
150
+ break;
151
+ default:
152
+ return false;
153
+ break;
154
+ }
155
+ }
156
+
157
+ /**
158
+ * get the source model attribute
159
+ *
160
+ * @access public
161
+ * @return null|Mage_Eav_Model_Entity_Attribute_Abstract
162
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
163
+ */
164
+ protected function _getEntityAttribute()
165
+ {
166
+ if (is_null($this->_entityAttribute)) {
167
+ $attrCode = $this->getTypeAttribute()->getAttribute()->getOptionsSourceAttribute();
168
+ /** @var Mage_Eav_Model_Config $config */
169
+ $config = Mage::getModel('eav/config');
170
+ $productAttribute = $config->getAttribute($this->getEntityCode(), $attrCode);
171
+ $this->_entityAttribute = $productAttribute;
172
+ }
173
+ return $this->_entityAttribute;
174
+ }
175
+ }
app/code/community/Ultimate/ModuleCreator/Model/Attribute/Type/File.php CHANGED
@@ -1,128 +1,161 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
- */
18
- /**
19
- * file attribute type
20
- *
21
- * @category Ultimate
22
- * @package Ultimate_ModuleCreator
23
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
- */
25
- class Ultimate_ModuleCreator_Model_Attribute_Type_File
26
- extends Ultimate_ModuleCreator_Model_Attribute_Type_Abstract {
27
- /**
28
- * type code
29
- * @var string
30
- */
31
- protected $_type = 'file';
32
- /**
33
- * eav setup input
34
- * @var string
35
- */
36
- protected $_setupInput = 'file';
37
- /**
38
- * don't show in admin grid
39
- * @access public
40
- * @return bool
41
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
42
- */
43
- public function getAdminGrid() {
44
- return false;
45
- }
46
- /**
47
- * check if attribute is required
48
- * @access public
49
- * @return mixed
50
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
51
- */
52
- public function getRequired(){
53
- return false;
54
- }
55
- /**
56
- * get the type for the form
57
- * @access public
58
- * @return string
59
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
60
- */
61
- public function getFormType() {
62
- return 'file';
63
- }
64
- /**
65
- * get text for rss
66
- * @access public
67
- * @return string
68
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
69
- */
70
- public function getRssText(){
71
- $content = '';
72
- $entityName = $this->getEntity()->getNameSingular(true);
73
- $eol = $this->getEol();
74
- $module = $this->getModule()->getLowerModuleName();
75
- $namespace = $this->getNamespace(true);
76
- $content .= $this->getPadding(3).'if ($item->get'.$this->getAttribute()->getMagicMethodCode().'()) {'.$eol;
77
- $content .= $this->getPadding(4).'$description .= \'<div>\';'.$eol;
78
- $content .= $this->getPadding(4).'$description .= Mage::helper(\''.$namespace.'_'.$module.'\')->__(\''.$this->getAttribute()->getLabel().'\');'.$eol;
79
- $content .= $this->getPadding(4).'$description .= \' <a href="\'.Mage::helper(\''.$namespace.'_'.$module.'/'.$entityName.'\')->getFileBaseUrl().$item->get'.$this->getAttribute()->getMagicMethodCode().'().\'">\';'.$eol;
80
- $content .= $this->getPadding(4).'$description .= \' <span>\'. basename($item->get'.$this->getAttribute()->getMagicMethodCode().'()).\'</span>\';'.$eol;
81
- $content .= $this->getPadding(4).'$description .= \' </a>\';'.$eol;
82
- $content .= $this->getPadding(4).'$description .= \'</div>\';'.$eol;
83
- $content .= $this->getPadding(3).'}'.$eol;
84
-
85
- return $content;
86
- }
87
-
88
- /**
89
- * get the html for frontend
90
- * @access public
91
- * @return string
92
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
93
- */
94
- public function getFrontendHtml() {
95
- $content = '';
96
- $eol = $this->getEol();
97
- $entityName = $this->getAttribute()->getEntity()->getNameSingular(true);
98
- $module = $this->getModule()->getLowerModuleName();
99
- $namespace = $this->getNamespace(true);
100
- $content .= $this->getPadding().'<?php if ($_'.$entityName.'->get'.$this->getAttribute()->getMagicMethodCode().'()) :?>'.$eol;
101
- $content .= $this->getPadding(2).'<a href="<?php echo Mage::helper(\''.$namespace.'_'.$module.'/'.$entityName.'\')->getFileBaseUrl().$_'.$entityName.'->get'.$this->getAttribute()->getMagicMethodCode().'();?>">'.$eol;
102
- $content .= $this->getPadding(3).'<span><?php echo basename($_'.$entityName.'->get'.$this->getAttribute()->getMagicMethodCode().'())?></span>'.$eol;
103
- $content .= $this->getPadding(2).'</a>'.$eol;
104
- $content .= $this->getPadding().'<?php endif;?>'.$eol;
105
- return $content;
106
- }
107
- /**
108
- * get the setup backend type
109
- * @access public
110
- * @return string
111
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
112
- */
113
- public function getSetupBackend(){
114
- $attribute = $this->getAttribute();
115
- $entity = $attribute->getEntity();
116
- $module = $this->getModule();
117
- return $this->getNamespace(true).'_'.$module->getLowerModuleName().'/'.$entity->getNameSingular(true).'_attribute_backend_file';
118
- }
119
- /**
120
- * get attribute default value
121
- * @access public
122
- * @return string
123
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
124
- */
125
- public function getDefaultValueProcessed() {
126
- return '';
127
- }
128
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
+ */
18
+ /**
19
+ * file attribute type
20
+ *
21
+ * @category Ultimate
22
+ * @package Ultimate_ModuleCreator
23
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
+ */
25
+ class Ultimate_ModuleCreator_Model_Attribute_Type_File extends Ultimate_ModuleCreator_Model_Attribute_Type_Abstract
26
+ {
27
+ /**
28
+ * type code
29
+ *
30
+ * @var string
31
+ */
32
+ protected $_type = 'file';
33
+
34
+ /**
35
+ * eav setup input
36
+ *
37
+ * @var string
38
+ */
39
+ protected $_setupInput = 'file';
40
+
41
+ /**
42
+ * don't show in admin grid
43
+ *
44
+ * @access public
45
+ * @return bool
46
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
47
+ */
48
+ public function getAdminGrid()
49
+ {
50
+ return false;
51
+ }
52
+
53
+ /**
54
+ * check if attribute is required
55
+ *
56
+ * @access public
57
+ * @return mixed
58
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
59
+ */
60
+ public function getRequired()
61
+ {
62
+ return false;
63
+ }
64
+
65
+ /**
66
+ * get the type for the form
67
+ *
68
+ * @access public
69
+ * @return string
70
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
71
+ */
72
+ public function getFormType()
73
+ {
74
+ return 'file';
75
+ }
76
+
77
+ /**
78
+ * get text for rss
79
+ *
80
+ * @access public
81
+ * @return string
82
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
83
+ */
84
+ public function getRssText()
85
+ {
86
+ $content = '';
87
+ $entityName = $this->getEntity()->getNameSingular(true);
88
+ $eol = $this->getEol();
89
+ $module = $this->getModule()->getLowerModuleName();
90
+ $namespace = $this->getNamespace(true);
91
+ $content .= $this->getPadding(3).'if ($item->get'.$this->getAttribute()->getMagicMethodCode().'()) {'.$eol;
92
+ $content .= $this->getPadding(4).'$description .= \'<div>\';'.$eol;
93
+ $content .= $this->getPadding(4).'$description .= Mage::helper(\''.
94
+ $namespace.'_'.$module.'\')->__(\''.$this->getAttribute()->getLabel().'\');'.$eol;
95
+ $content .= $this->getPadding(4).'$description .= \' <a href="\'.Mage::helper(\''.
96
+ $namespace.'_'.$module.'/'.$entityName.'\')->getFileBaseUrl().$item->get'.
97
+ $this->getAttribute()->getMagicMethodCode().'().\'">\';'.$eol;
98
+ $content .= $this->getPadding(4).'$description .= \' <span>\'. basename($item->get'.
99
+ $this->getAttribute()->getMagicMethodCode().'()).\'</span>\';'.$eol;
100
+ $content .= $this->getPadding(4).'$description .= \' </a>\';'.$eol;
101
+ $content .= $this->getPadding(4).'$description .= \'</div>\';'.$eol;
102
+ $content .= $this->getPadding(3).'}'.$eol;
103
+
104
+ return $content;
105
+ }
106
+
107
+ /**
108
+ * get the html for frontend
109
+ *
110
+ * @access public
111
+ * @return string
112
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
113
+ */
114
+ public function getFrontendHtml()
115
+ {
116
+ $content = '';
117
+ $eol = $this->getEol();
118
+ $entityName = $this->getAttribute()->getEntity()->getNameSingular(true);
119
+ $module = $this->getModule()->getLowerModuleName();
120
+ $namespace = $this->getNamespace(true);
121
+ $content .= $this->getPadding().'<?php if ($_'.$entityName.'->get'.
122
+ $this->getAttribute()->getMagicMethodCode().'()) :?>'.$eol;
123
+ $content .= $this->getPadding(2).'<a href="<?php echo Mage::helper(\''.
124
+ $namespace.'_'.$module.'/'.$entityName.'\')->getFileBaseUrl().$_'.
125
+ $entityName.'->get'.$this->getAttribute()->getMagicMethodCode().'();?>">'.$eol;
126
+ $content .= $this->getPadding(3).'<span><?php echo basename($_'.
127
+ $entityName.'->get'.$this->getAttribute()->getMagicMethodCode().'())?></span>'.$eol;
128
+ $content .= $this->getPadding(2).'</a>'.$eol;
129
+ $content .= $this->getPadding().'<?php endif;?>'.$eol;
130
+ return $content;
131
+ }
132
+
133
+ /**
134
+ * get the setup backend type
135
+ *
136
+ * @access public
137
+ * @return string
138
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
139
+ */
140
+ public function getSetupBackend()
141
+ {
142
+ $attribute = $this->getAttribute();
143
+ $entity = $attribute->getEntity();
144
+ $module = $this->getModule();
145
+ return $this->getNamespace(true).'_'.
146
+ $module->getLowerModuleName().'/'.
147
+ $entity->getNameSingular(true).'_attribute_backend_file';
148
+ }
149
+
150
+ /**
151
+ * get attribute default value
152
+ *
153
+ * @access public
154
+ * @return string
155
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
156
+ */
157
+ public function getDefaultValueProcessed()
158
+ {
159
+ return '';
160
+ }
161
+ }
app/code/community/Ultimate/ModuleCreator/Model/Attribute/Type/Image.php CHANGED
@@ -1,122 +1,155 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
- */
18
- /**
19
- * image attribute type
20
- *
21
- * @category Ultimate
22
- * @package Ultimate_ModuleCreator
23
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
- */
25
- class Ultimate_ModuleCreator_Model_Attribute_Type_Image
26
- extends Ultimate_ModuleCreator_Model_Attribute_Type_Abstract {
27
- /**
28
- * type code
29
- * @var string
30
- */
31
- protected $_type = 'image';
32
- /**
33
- * eav setup input
34
- * @var string
35
- */
36
- protected $_setupInput = 'image';
37
- /**
38
- * don't show in admin grid
39
- * @access public
40
- * @return bool
41
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
42
- */
43
- public function getAdminGrid() {
44
- return false;
45
- }
46
- /**
47
- * check if attribute is required
48
- * @access public
49
- * @return mixed
50
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
51
- */
52
- public function getRequired(){
53
- return false;
54
- }
55
- /**
56
- * get the type for the form
57
- * @access public
58
- * @return string
59
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
60
- */
61
- public function getFormType() {
62
- return 'image';
63
- }
64
- /**
65
- * get text for rss
66
- * @access public
67
- * @return string
68
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
69
- */
70
- public function getRssText() {
71
- $eol = $this->getEol();
72
- $content = '';
73
- $entityName = $this->getEntity()->getNameSingular(true);
74
- $module = $this->getModule()->getLowerModuleName();
75
- $namespace = $this->getNamespace(true);
76
- $content .= $this->getPadding(3).'if ($item->get'.$this->getAttribute()->getMagicMethodCode().'()) {'.$eol;
77
- $content .= $this->getPadding(4).'$description .= \'<div>\';'.$eol;
78
- $content .= $this->getPadding(4).'$description .= Mage::helper(\''.$namespace.'_'.$module.'\')->__(\''.$this->getAttribute()->getLabel().'\');'.$eol;
79
- $content .= $this->getPadding(4).'$description .= \'<img src="\'.Mage::helper(\''.$namespace.'_'.$module.'/'.$entityName.'_image\')->init($item, \''.$this->getAttribute()->getCode().'\')->resize(75).\'" alt="\'.$this->htmlEscape($item->get'.$this->getEntity()->getNameAttributeMagicCode().'()).\'" />\';'.$eol;
80
- $content .= $this->getPadding(4).'$description .= \'</div>\';'.$eol;
81
- $content .= $this->getPadding(3).'}'.$eol;
82
- return $content;
83
- }
84
- /**
85
- * get the html for frontend
86
- * @access public
87
- * @return string
88
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
89
- */
90
- public function getFrontendHtml() {
91
- $eol = $this->getEol();
92
- $content = '';
93
- $entityName = $this->getEntity()->getNameSingular(true);
94
- $module = $this->getModule()->getLowerModuleName();
95
- $namespace = $this->getNamespace(true);
96
- $content .= '<?php if ($_'.$entityName.'->get'.$this->getAttribute()->getMagicMethodCode().'()) :?>'.$eol;
97
- $content .= $this->getHelper()->getPadding().'<img src="<?php echo Mage::helper(\''.$namespace.'_'.$module.'/'.$entityName.'_image\')->init($_'.$entityName.', \''.$this->getAttribute()->getCode().'\')->resize(75);?>" alt="<?php echo $this->htmlEscape($_'.$entityName.'->get'.$this->getAttribute()->getEntity()->getNameAttributeMagicCode().'());?>" />'.$eol;
98
- $content .= '<?php endif;?>'.$eol;
99
- return $content;
100
- }
101
- /**
102
- * get the setup backend type
103
- * @access public
104
- * @return string
105
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
106
- */
107
- public function getSetupBackend(){
108
- $attribute = $this->getAttribute();
109
- $entity = $attribute->getEntity();
110
- $module = $entity->getModule();
111
- return $this->getNamespace(true).'_'.$module->getLowerModuleName().'/'.$entity->getNameSingular(true).'_attribute_backend_image';
112
- }
113
- /**
114
- * get attribute default value
115
- * @access public
116
- * @return string
117
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
118
- */
119
- public function getDefaultValueProcessed() {
120
- return '';
121
- }
122
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
+ */
18
+ /**
19
+ * image attribute type
20
+ *
21
+ * @category Ultimate
22
+ * @package Ultimate_ModuleCreator
23
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
+ */
25
+ class Ultimate_ModuleCreator_Model_Attribute_Type_Image extends Ultimate_ModuleCreator_Model_Attribute_Type_Abstract
26
+ {
27
+ /**
28
+ * type code
29
+ *
30
+ * @var string
31
+ */
32
+ protected $_type = 'image';
33
+ /**
34
+ * eav setup input
35
+ *
36
+ * @var string
37
+ */
38
+ protected $_setupInput = 'image';
39
+
40
+ /**
41
+ * don't show in admin grid
42
+ *
43
+ * @access public
44
+ * @return bool
45
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
46
+ */
47
+ public function getAdminGrid()
48
+ {
49
+ return false;
50
+ }
51
+
52
+ /**
53
+ * check if attribute is required
54
+ *
55
+ * @access public
56
+ * @return mixed
57
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
58
+ */
59
+ public function getRequired()
60
+ {
61
+ return false;
62
+ }
63
+
64
+ /**
65
+ * get the type for the form
66
+ *
67
+ * @access public
68
+ * @return string
69
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
70
+ */
71
+ public function getFormType()
72
+ {
73
+ return 'image';
74
+ }
75
+
76
+ /**
77
+ * get text for rss
78
+ *
79
+ * @access public
80
+ * @return string
81
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
82
+ */
83
+ public function getRssText()
84
+ {
85
+ $eol = $this->getEol();
86
+ $content = '';
87
+ $entityName = $this->getEntity()->getNameSingular(true);
88
+ $module = $this->getModule()->getLowerModuleName();
89
+ $namespace = $this->getNamespace(true);
90
+ $content .= $this->getPadding(3).'if ($item->get'.$this->getAttribute()->getMagicMethodCode().'()) {'.$eol;
91
+ $content .= $this->getPadding(4).'$description .= \'<div>\';'.$eol;
92
+ $content .= $this->getPadding(4).'$description .= Mage::helper(\''.$namespace.'_'.$module.
93
+ '\')->__(\''.$this->getAttribute()->getLabel().'\');'.$eol;
94
+ $content .= $this->getPadding(4).'$description .= \'<img src="\'.Mage::helper(\''.
95
+ $namespace.'_'.$module.'/'.$entityName.'_image\')->init($item, \''.
96
+ $this->getAttribute()->getCode().'\')->resize(75).\'" alt="\'.$this->escapeHtml($item->get'.
97
+ $this->getEntity()->getNameAttributeMagicCode().'()).\'" />\';'.$eol;
98
+ $content .= $this->getPadding(4).'$description .= \'</div>\';'.$eol;
99
+ $content .= $this->getPadding(3).'}'.$eol;
100
+ return $content;
101
+ }
102
+
103
+ /**
104
+ * get the html for frontend
105
+ *
106
+ * @access public
107
+ * @return string
108
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
109
+ */
110
+ public function getFrontendHtml()
111
+ {
112
+ $eol = $this->getEol();
113
+ $content = '';
114
+ $entityName = $this->getEntity()->getNameSingular(true);
115
+ $module = $this->getModule()->getLowerModuleName();
116
+ $namespace = $this->getNamespace(true);
117
+ $content .= '<?php if ($_'.$entityName.'->get'.$this->getAttribute()->getMagicMethodCode().'()) :?>'.$eol;
118
+ $content .= $this->getHelper()->getPadding().
119
+ '<img src="<?php echo Mage::helper(\''.$namespace.'_'.$module.'/'.$entityName.'_image\')->init($_'.
120
+ $entityName.', \''.$this->getAttribute()->getCode().
121
+ '\')->resize(75);?>" alt="<?php echo $this->escapeHtml($_'.
122
+ $entityName.'->get'.$this->getAttribute()->getEntity()->getNameAttributeMagicCode().'());?>" />'.$eol;
123
+ $content .= '<?php endif;?>'.$eol;
124
+ return $content;
125
+ }
126
+
127
+ /**
128
+ * get the setup backend type
129
+ *
130
+ * @access public
131
+ * @return string
132
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
133
+ */
134
+ public function getSetupBackend()
135
+ {
136
+ $attribute = $this->getAttribute();
137
+ $entity = $attribute->getEntity();
138
+ $module = $entity->getModule();
139
+ return $this->getNamespace(true).'_'.
140
+ $module->getLowerModuleName().'/'.
141
+ $entity->getNameSingular(true).'_attribute_backend_image';
142
+ }
143
+
144
+ /**
145
+ * get attribute default value
146
+ *
147
+ * @access public
148
+ * @return string
149
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
150
+ */
151
+ public function getDefaultValueProcessed()
152
+ {
153
+ return '';
154
+ }
155
+ }
app/code/community/Ultimate/ModuleCreator/Model/Attribute/Type/Int.php CHANGED
@@ -1,58 +1,69 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
- */
18
- /**
19
- * int attribute type
20
- *
21
- * @category Ultimate
22
- * @package Ultimate_ModuleCreator
23
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
- */
25
- class Ultimate_ModuleCreator_Model_Attribute_Type_Int
26
- extends Ultimate_ModuleCreator_Model_Attribute_Type_Abstract {
27
- /**
28
- * type code
29
- * @var string
30
- */
31
- protected $_type = 'int';
32
- /**
33
- * sql colum ddl type
34
- * @var string
35
- */
36
- protected $_typeDdl = 'TYPE_INTEGER';
37
- /**
38
- * sql colum ddl size
39
- * @var string
40
- */
41
- protected $_sizeDdl = 'null';
42
- /**
43
- * eav setup type
44
- */
45
- protected $_setupType = 'int';
46
- /**
47
- * get admin column options
48
- * @access public
49
- * @return string
50
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
51
- */
52
- public function getAdminColumnOptions() {
53
- $options = $this->getEol();
54
- $options .= $this->getPadding(3);
55
- $options .= "'type'=> 'number',".$this->getEol();
56
- return $options;
57
- }
58
- }
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
+ */
18
+ /**
19
+ * int attribute type
20
+ *
21
+ * @category Ultimate
22
+ * @package Ultimate_ModuleCreator
23
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
+ */
25
+ class Ultimate_ModuleCreator_Model_Attribute_Type_Int extends Ultimate_ModuleCreator_Model_Attribute_Type_Abstract
26
+ {
27
+ /**
28
+ * type code
29
+ *
30
+ * @var string
31
+ */
32
+ protected $_type = 'int';
33
+
34
+ /**
35
+ * sql column ddl type
36
+ *
37
+ * @var string
38
+ */
39
+ protected $_typeDdl = 'TYPE_INTEGER';
40
+
41
+ /**
42
+ * sql column ddl size
43
+ *
44
+ * @var string
45
+ */
46
+ protected $_sizeDdl = 'null';
47
+
48
+ /**
49
+ * eav setup type
50
+ *
51
+ * @var string
52
+ */
53
+ protected $_setupType = 'int';
54
+
55
+ /**
56
+ * get admin column options
57
+ *
58
+ * @access public
59
+ * @return string
60
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
61
+ */
62
+ public function getAdminColumnOptions()
63
+ {
64
+ $options = $this->getEol();
65
+ $options .= $this->getPadding(4);
66
+ $options .= "'type'=> 'number',".$this->getEol();
67
+ return $options;
68
+ }
69
+ }
app/code/community/Ultimate/ModuleCreator/Model/Attribute/Type/Multiselect.php CHANGED
@@ -1,144 +1,193 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
- */
18
- /**
19
- * multiselect attribute type
20
- *
21
- * @category Ultimate
22
- * @package Ultimate_ModuleCreator
23
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
- */
25
- class Ultimate_ModuleCreator_Model_Attribute_Type_Multiselect
26
- extends Ultimate_ModuleCreator_Model_Attribute_Type_Dropdown {
27
- /**
28
- * type code
29
- * @var string
30
- */
31
- protected $_type = 'multiselect';
32
- /**
33
- * sql column ddl type
34
- * @var string
35
- */
36
- protected $_typeDdl = 'TYPE_TEXT';
37
- /**
38
- * sql column ddl size
39
- * @var string
40
- */
41
- protected $_sizeDdl = "'64k'";
42
- /**
43
- * eav setup input
44
- */
45
- protected $_setupInput = 'multiselect';
46
- /**
47
- * eav setup type
48
- */
49
- protected $_setupType = 'text';
50
- /**
51
- * backend setup type
52
- * @var string
53
- */
54
- protected $_setupBackend = 'eav/entity_attribute_backend_array';
55
- /**
56
- * don't show in admin grid
57
- * @access public
58
- * @return bool
59
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
60
- */
61
- public function getAdminGrid(){
62
- return false;
63
- }
64
- /**
65
- * get the type for the form
66
- * @access public
67
- * @return string
68
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
69
- */
70
- public function getFormType(){
71
- return 'multiselect';
72
- }
73
- /**
74
- * check if attribute is multiple select
75
- * @access public
76
- * @return bool
77
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
78
- */
79
- public function getIsMultipleSelect(){
80
- return true;
81
- }
82
- /**
83
- * get the setup type of the dropdown
84
- * @access public
85
- * @return string|void
86
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
87
- */
88
- public function getSetupType(){
89
- return $this->_setupType;
90
- }
91
- /**
92
- * get attribute setup type
93
- * @access public
94
- * @return string
95
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
96
- */
97
- public function getTypeDdl(){
98
- return $this->_typeDdl;
99
- }
100
- /**
101
- * check if options should be returned with empty
102
- * @access public
103
- * @return string
104
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
105
- */
106
- public function getOptionsFlag() {
107
- return 'false';
108
- }
109
- /**
110
- * get values for mass action
111
- * @access public
112
- * @return string
113
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
114
- */
115
- public function getMassActionValues() {
116
- return '';
117
- }
118
- /**
119
- * get attribute default value setup content
120
- * @access public
121
- * @return string
122
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
123
- */
124
- public function getDefaultValueSetup() {
125
- $content = '';
126
- if ($this->getSubTypeInstance() instanceof Ultimate_ModuleCreator_Model_Attribute_Type_Dropdown_Custom
127
- && $this->getAttribute()->getDefaultValue()
128
- ) {
129
- $eol = $this->getEol();
130
- $entity = $this->getEntity();
131
- $attribute= $this->getAttribute();
132
- $content .= '$attribute = Mage::getSingleton(\'eav/config\')->getAttribute(\''.$this->getNamespace(true).'_'.$this->getModule()->getLowerModuleName().'_'.$entity->getNameSingular().'\', \''.$attribute->getCode().'\');'.$eol;
133
- $content .= '$options = $attribute->getSource()->getAllOptions(false);'.$eol;
134
- $content .= '$defaultOptions = array();'.$eol;
135
- $content .= 'foreach ($options as $option) {'.$eol;
136
- $content .= $this->getPadding().'if (in_array($option[\'label\'], array(\''.implode("','", explode(Ultimate_ModuleCreator_Model_Attribute::OPTION_SEPARATOR, Mage::helper('core')->jsQuoteEscape($attribute->getDefaultValue()))).'\'))) {'.$eol;
137
- $content .= $this->getPadding(2).'$defaultOptions[] = $option[\'value\'];'.$eol;
138
- $content .= $this->getPadding().'}'.$eol;
139
- $content .= '}'.$eol;
140
- $content .= '$this->updateAttribute(\''.$this->getNamespace(true).'_'.$this->getModule()->getLowerModuleName().'_'.$entity->getNameSingular().'\', \''.$attribute->getCode().'\', \'default_value\', implode(\',\', $defaultOptions));'.$eol;
141
- }
142
- return $content;
143
- }
144
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
+ */
18
+ /**
19
+ * multiselect attribute type
20
+ *
21
+ * @category Ultimate
22
+ * @package Ultimate_ModuleCreator
23
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
+ */
25
+ class Ultimate_ModuleCreator_Model_Attribute_Type_Multiselect extends Ultimate_ModuleCreator_Model_Attribute_Type_Dropdown
26
+ {
27
+ /**
28
+ * type code
29
+ *
30
+ * @var string
31
+ */
32
+ protected $_type = 'multiselect';
33
+
34
+ /**
35
+ * sql column ddl type
36
+ *
37
+ * @var string
38
+ */
39
+ protected $_typeDdl = 'TYPE_TEXT';
40
+
41
+ /**
42
+ * sql column ddl size
43
+ *
44
+ * @var string
45
+ */
46
+ protected $_sizeDdl = "'64k'";
47
+
48
+ /**
49
+ * eav setup input
50
+ *
51
+ * @var string
52
+ */
53
+ protected $_setupInput = 'multiselect';
54
+
55
+ /**
56
+ * eav setup type
57
+ *
58
+ * @var string
59
+ */
60
+ protected $_setupType = 'text';
61
+
62
+ /**
63
+ * backend setup type
64
+ *
65
+ * @var string
66
+ */
67
+ protected $_setupBackend = 'eav/entity_attribute_backend_array';
68
+
69
+ /**
70
+ * don't show in admin grid
71
+ *
72
+ * @access public
73
+ * @return bool
74
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
75
+ */
76
+ public function getAdminGrid()
77
+ {
78
+ return false;
79
+ }
80
+
81
+ /**
82
+ * get the type for the form
83
+ *
84
+ * @access public
85
+ * @return string
86
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
87
+ */
88
+ public function getFormType()
89
+ {
90
+ return 'multiselect';
91
+ }
92
+
93
+ /**
94
+ * check if attribute is multiple select
95
+ *
96
+ * @access public
97
+ * @return bool
98
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
99
+ */
100
+ public function getIsMultipleSelect()
101
+ {
102
+ return true;
103
+ }
104
+
105
+ /**
106
+ * get the setup type of the dropdown
107
+ *
108
+ * @access public
109
+ * @return string|void
110
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
111
+ */
112
+ public function getSetupType()
113
+ {
114
+ return $this->_setupType;
115
+ }
116
+
117
+ /**
118
+ * get attribute setup type
119
+ *
120
+ * @access public
121
+ * @return string
122
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
123
+ */
124
+ public function getTypeDdl()
125
+ {
126
+ return $this->_typeDdl;
127
+ }
128
+
129
+ /**
130
+ * check if options should be returned with empty
131
+ *
132
+ * @access public
133
+ * @return string
134
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
135
+ */
136
+ public function getOptionsFlag()
137
+ {
138
+ return 'false';
139
+ }
140
+
141
+ /**
142
+ * get values for mass action
143
+ *
144
+ * @access public
145
+ * @return string
146
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
147
+ */
148
+ public function getMassActionValues()
149
+ {
150
+ return '';
151
+ }
152
+
153
+ /**
154
+ * get attribute default value setup content
155
+ *
156
+ * @access public
157
+ * @return string
158
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
159
+ */
160
+ public function getDefaultValueSetup()
161
+ {
162
+ $content = '';
163
+ if ($this->getSubTypeInstance() instanceof Ultimate_ModuleCreator_Model_Attribute_Type_Dropdown_Custom
164
+ && $this->getAttribute()->getDefaultValue()
165
+ ) {
166
+ $eol = $this->getEol();
167
+ $entity = $this->getEntity();
168
+ $attribute= $this->getAttribute();
169
+ $content .= '$attribute = Mage::getSingleton(\'eav/config\')->getAttribute(\''.
170
+ $this->getNamespace(true).'_'.$this->getModule()->getLowerModuleName().'_'.
171
+ $entity->getNameSingular().'\', \''.$attribute->getCode().'\');'.$eol;
172
+ $content .= '$options = $attribute->getSource()->getAllOptions(false);'.$eol;
173
+ $content .= '$defaultOptions = array();'.$eol;
174
+ $content .= 'foreach ($options as $option) {'.$eol;
175
+ $content .= $this->getPadding().'if (in_array($option[\'label\'], array(\''.
176
+ implode(
177
+ "','",
178
+ explode(
179
+ Ultimate_ModuleCreator_Model_Attribute::OPTION_SEPARATOR,
180
+ Mage::helper('core')->jsQuoteEscape($attribute->getDefaultValue())
181
+ )
182
+ ).'\'))) {'.$eol;
183
+ $content .= $this->getPadding(2).'$defaultOptions[] = $option[\'value\'];'.$eol;
184
+ $content .= $this->getPadding().'}'.$eol;
185
+ $content .= '}'.$eol;
186
+ $content .= '$this->updateAttribute(\''.
187
+ $this->getNamespace(true).'_'.$this->getModule()->getLowerModuleName().'_'.
188
+ $entity->getNameSingular().'\', \''.$attribute->getCode().
189
+ '\', \'default_value\', implode(\',\', $defaultOptions));'.$eol;
190
+ }
191
+ return $content;
192
+ }
193
+ }
app/code/community/Ultimate/ModuleCreator/Model/Attribute/Type/Signedint.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
+ */
18
+ /**
19
+ * int attribute type
20
+ *
21
+ * @category Ultimate
22
+ * @package Ultimate_ModuleCreator
23
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
+ */
25
+ class Ultimate_ModuleCreator_Model_Attribute_Type_Signedint extends Ultimate_ModuleCreator_Model_Attribute_Type_Int
26
+ {
27
+ /**
28
+ * type code
29
+ *
30
+ * @var string
31
+ */
32
+ protected $_type = 'signedint';
33
+ }
app/code/community/Ultimate/ModuleCreator/Model/Attribute/Type/Text.php CHANGED
@@ -1,44 +1,48 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
- */
18
- /**
19
- * text attribute type
20
- *
21
- * @category Ultimate
22
- * @package Ultimate_ModuleCreator
23
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
- */
25
- class Ultimate_ModuleCreator_Model_Attribute_Type_Text
26
- extends Ultimate_ModuleCreator_Model_Attribute_Type_Abstract {
27
- /**
28
- * type code
29
- * @var string
30
- */
31
- protected $_type = 'text';
32
- /**
33
- * get admin column options
34
- * @access public
35
- * @return string
36
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
37
- */
38
- public function getAdminColumnOptions() {
39
- $options = $this->getEol();
40
- $options .= $this->getPadding(3);
41
- $options .= "'type'=> 'text',".$this->getEol();
42
- return $options;
43
- }
44
- }
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
+ */
18
+ /**
19
+ * text attribute type
20
+ *
21
+ * @category Ultimate
22
+ * @package Ultimate_ModuleCreator
23
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
+ */
25
+ class Ultimate_ModuleCreator_Model_Attribute_Type_Text extends Ultimate_ModuleCreator_Model_Attribute_Type_Abstract
26
+ {
27
+ /**
28
+ * type code
29
+ *
30
+ * @var string
31
+ */
32
+ protected $_type = 'text';
33
+
34
+ /**
35
+ * get admin column options
36
+ *
37
+ * @access public
38
+ * @return string
39
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
40
+ */
41
+ public function getAdminColumnOptions()
42
+ {
43
+ $options = $this->getEol();
44
+ $options .= $this->getPadding(4);
45
+ $options .= "'type'=> 'text',".$this->getEol();
46
+ return $options;
47
+ }
48
+ }
app/code/community/Ultimate/ModuleCreator/Model/Attribute/Type/Textarea.php CHANGED
@@ -1,97 +1,117 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
- */
18
- /**
19
- * textarea attribute type
20
- *
21
- * @category Ultimate
22
- * @package Ultimate_ModuleCreator
23
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
- */
25
- class Ultimate_ModuleCreator_Model_Attribute_Type_Textarea
26
- extends Ultimate_ModuleCreator_Model_Attribute_Type_Abstract {
27
- /**
28
- * type code
29
- * @var string
30
- */
31
- protected $_type = 'textarea';
32
- /**
33
- * sql column ddl type
34
- * @var string
35
- */
36
- protected $_typeDdl = 'TYPE_TEXT';
37
- /**
38
- * sql column ddl size
39
- * @var string
40
- */
41
- protected $_sizeDdl = "'64k'";
42
- /**
43
- * eav setup type
44
- */
45
- protected $_setupType = 'text';
46
- /**
47
- * eav setup input
48
- * @var string
49
- */
50
- protected $_setupInput = 'textarea';
51
-
52
- /**
53
- * don't show in admin grid
54
- * @access public
55
- * @return bool
56
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
57
- */
58
- public function getAdminGrid() {
59
- return false;
60
- }
61
- /**
62
- * get the type for the form
63
- * @access public
64
- * @return string
65
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
66
- */
67
- public function getFormType() {
68
- if ($this->getAttribute()->getEditor()) {
69
- return 'editor';
70
- }
71
- return 'textarea';
72
- }
73
- /**
74
- * can use editor
75
- * @access public
76
- * @return bool
77
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
78
- */
79
- public function getEditor() {
80
- return $this->getAttribute()->getData('editor');
81
- }
82
- /**
83
- * get the options for form input
84
- * @access public
85
- * @return string
86
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
87
- */
88
- public function getFormOptions(){
89
- $options = '';
90
- if ($this->getEditor() && !$this->getEntity()->getIsTree()){
91
- $options = $this->getPadding(3)."'config' => "."$"."wysiwygConfig,".$this->getEol();
92
- }
93
- $options .= parent::getFormOptions();
94
- return $options;
95
- }
96
-
97
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
+ */
18
+ /**
19
+ * textarea attribute type
20
+ *
21
+ * @category Ultimate
22
+ * @package Ultimate_ModuleCreator
23
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
+ */
25
+ class Ultimate_ModuleCreator_Model_Attribute_Type_Textarea extends Ultimate_ModuleCreator_Model_Attribute_Type_Abstract
26
+ {
27
+ /**
28
+ * type code
29
+ *
30
+ * @var string
31
+ */
32
+ protected $_type = 'textarea';
33
+
34
+ /**
35
+ * sql column ddl type
36
+ *
37
+ * @var string
38
+ */
39
+ protected $_typeDdl = 'TYPE_TEXT';
40
+
41
+ /**
42
+ * sql column ddl size
43
+ *
44
+ * @var string
45
+ */
46
+ protected $_sizeDdl = "'64k'";
47
+
48
+ /**
49
+ * eav setup type
50
+ *
51
+ * @var string
52
+ */
53
+ protected $_setupType = 'text';
54
+
55
+ /**
56
+ * eav setup input
57
+ *
58
+ * @var string
59
+ */
60
+ protected $_setupInput = 'textarea';
61
+
62
+ /**
63
+ * don't show in admin grid
64
+ *
65
+ * @access public
66
+ * @return bool
67
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
68
+ */
69
+ public function getAdminGrid()
70
+ {
71
+ return false;
72
+ }
73
+
74
+ /**
75
+ * get the type for the form
76
+ *
77
+ * @access public
78
+ * @return string
79
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
80
+ */
81
+ public function getFormType()
82
+ {
83
+ if ($this->getAttribute()->getEditor()) {
84
+ return 'editor';
85
+ }
86
+ return 'textarea';
87
+ }
88
+
89
+ /**
90
+ * can use editor
91
+ *
92
+ * @access public
93
+ * @return bool
94
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
95
+ */
96
+ public function getEditor()
97
+ {
98
+ return $this->getAttribute()->getData('editor');
99
+ }
100
+
101
+ /**
102
+ * get the options for form input
103
+ *
104
+ * @access public
105
+ * @return string
106
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
107
+ */
108
+ public function getFormOptions()
109
+ {
110
+ $options = '';
111
+ if ($this->getEditor() && !$this->getEntity()->getIsTree()) {
112
+ $options = $this->getPadding(3)."'config' => "."$"."wysiwygConfig,".$this->getEol();
113
+ }
114
+ $options .= parent::getFormOptions();
115
+ return $options;
116
+ }
117
+ }
app/code/community/Ultimate/ModuleCreator/Model/Attribute/Type/Timestamp.php CHANGED
@@ -1,111 +1,144 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
- */
18
- /**
19
- * timestamp attribute type
20
- *
21
- * @category Ultimate
22
- * @package Ultimate_ModuleCreator
23
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
- */
25
- class Ultimate_ModuleCreator_Model_Attribute_Type_Timestamp
26
- extends Ultimate_ModuleCreator_Model_Attribute_Type_Abstract {
27
- /**
28
- * type code
29
- * @var string
30
- */
31
- protected $_type = 'timestamp';
32
- /**
33
- * sql column ddl type
34
- * @var string
35
- */
36
- protected $_typeDdl = 'TYPE_DATETIME';
37
- /**
38
- * eav setup type
39
- */
40
- protected $_setupType = 'datetime';
41
- /**
42
- * eav setup input
43
- * @var string
44
- */
45
- protected $_setupInput = 'date';
46
- /**
47
- * setup backend
48
- * @var string
49
- */
50
- protected $_setupBackend = 'eav/entity_attribute_backend_datetime';
51
-
52
- /**
53
- * get admin column options
54
- * @access public
55
- * @return string
56
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
57
- */
58
- public function getAdminColumnOptions() {
59
- $options = $this->getEol();
60
- $options .= $this->getPadding(3);
61
- $options .= "'type'=> 'date',".$this->getEol();
62
- return $options;
63
- }
64
- /**
65
- * get the type for the form
66
- * @access public
67
- * @return string
68
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
69
- */
70
- public function getFormType() {
71
- return 'date';
72
- }
73
- /**
74
- * get html for frontend
75
- * @access public
76
- * @return string
77
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
78
- */
79
- public function getFrontendHtml() {
80
- $entityName = $this->getEntity()->getNameSingular(true);
81
- $module = $this->getModule()->getLowerModuleName();
82
- $namespace = $this->getNamespace(true);
83
- return '<?php echo Mage::helper(\''.$namespace.'_'.$module.'\')->__("'.$this->getAttribute()->getLabel().'");?>: <?php echo Mage::helper(\'core\')->formatDate($_'.$entityName.'->get'.$this->getAttribute()->getMagicMethodCode().'(), \'full\');?>'.$this->getEol();
84
- }
85
- /**
86
- * get options for admin form
87
- * @access public
88
- * @return string
89
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
90
- */
91
- public function getFormOptions(){
92
- $options = parent::getFormOptions();
93
- $padding = $this->getPadding(3);
94
- $eol = $this->getEol();
95
- $options .= $padding.'\'image\' => $this->getSkinUrl(\'images/grid-cal.gif\'),'.$eol;;
96
- $options .= $padding.'\'format\' => Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT),'.$eol;
97
- return $options;
98
- }
99
- /**
100
- * get text for rss
101
- * @access public
102
- * @return string
103
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
104
- */
105
- public function getRssText() {
106
- $attribute = $this->getAttribute();
107
- $module = $this->getModule()->getLowerModuleName();
108
- $namespace = $this->getNamespace(true);
109
- return $this->getPadding(3).'$'.'description .= \'<div>\'.Mage::helper(\''.$namespace.'_'.$module.'\')->__(\''.$attribute->getLabel().'\').\': \'.Mage::helper(\'core\')->formatDate($item->get'.$this->getAttribute()->getMagicMethodCode().'(), \'full\').\'</div>\';'.$this->getEol();
110
- }
111
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
+ */
18
+ /**
19
+ * timestamp attribute type
20
+ *
21
+ * @category Ultimate
22
+ * @package Ultimate_ModuleCreator
23
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
+ */
25
+ class Ultimate_ModuleCreator_Model_Attribute_Type_Timestamp extends Ultimate_ModuleCreator_Model_Attribute_Type_Abstract
26
+ {
27
+ /**
28
+ * type code
29
+ *
30
+ * @var string
31
+ */
32
+ protected $_type = 'timestamp';
33
+
34
+ /**
35
+ * sql column ddl type
36
+ *
37
+ * @var string
38
+ */
39
+ protected $_typeDdl = 'TYPE_DATETIME';
40
+
41
+ /**
42
+ * eav setup type
43
+ *
44
+ * @var string
45
+ */
46
+ protected $_setupType = 'datetime';
47
+
48
+ /**
49
+ * eav setup input
50
+ *
51
+ * @var string
52
+ */
53
+ protected $_setupInput = 'date';
54
+
55
+ /**
56
+ * setup backend
57
+ *
58
+ * @var string
59
+ */
60
+ protected $_setupBackend = 'eav/entity_attribute_backend_datetime';
61
+
62
+ /**
63
+ * get admin column options
64
+ *
65
+ * @access public
66
+ * @return string
67
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
68
+ */
69
+ public function getAdminColumnOptions()
70
+ {
71
+ $options = $this->getEol();
72
+ $options .= $this->getPadding(4);
73
+ $options .= "'type'=> 'date',".$this->getEol();
74
+ return $options;
75
+ }
76
+
77
+ /**
78
+ * get the type for the form
79
+ *
80
+ * @access public
81
+ * @return string
82
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
83
+ */
84
+ public function getFormType()
85
+ {
86
+ return 'date';
87
+ }
88
+
89
+ /**
90
+ * get html for frontend
91
+ *
92
+ * @access public
93
+ * @return string
94
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
95
+ */
96
+ public function getFrontendHtml()
97
+ {
98
+ $entityName = $this->getEntity()->getNameSingular(true);
99
+ $module = $this->getModule()->getLowerModuleName();
100
+ $namespace = $this->getNamespace(true);
101
+ return '<?php echo Mage::helper(\''.
102
+ $namespace.'_'.$module.'\')->__("'.
103
+ $this->getAttribute()->getLabel().
104
+ '");?>: <?php echo Mage::helper(\'core\')->formatDate($_'.
105
+ $entityName.'->get'.$this->getAttribute()->getMagicMethodCode().'(), \'full\');?>'.$this->getEol();
106
+ }
107
+
108
+ /**
109
+ * get options for admin form
110
+ *
111
+ * @access public
112
+ * @return string
113
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
114
+ */
115
+ public function getFormOptions()
116
+ {
117
+ $options = parent::getFormOptions();
118
+ $padding = $this->getPadding(3);
119
+ $eol = $this->getEol();
120
+ $options .= $padding.'\'image\' => $this->getSkinUrl(\'images/grid-cal.gif\'),'.$eol;;
121
+ $options .= $padding.
122
+ '\'format\' => Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT),'.$eol;
123
+ return $options;
124
+ }
125
+
126
+ /**
127
+ * get text for rss
128
+ *
129
+ * @access public
130
+ * @return string
131
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
132
+ */
133
+ public function getRssText()
134
+ {
135
+ $attribute = $this->getAttribute();
136
+ $module = $this->getModule()->getLowerModuleName();
137
+ $namespace = $this->getNamespace(true);
138
+ return $this->getPadding(3).'$'.
139
+ 'description .= \'<div>\'.Mage::helper(\''.
140
+ $namespace.'_'.$module.'\')->__(\''.
141
+ $attribute->getLabel().'\').\': \'.Mage::helper(\'core\')->formatDate($item->get'.
142
+ $this->getAttribute()->getMagicMethodCode().'(), \'full\').\'</div>\';'.$this->getEol();
143
+ }
144
+ }
app/code/community/Ultimate/ModuleCreator/Model/Attribute/Type/Yesno.php CHANGED
@@ -1,156 +1,200 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
- */
18
- /**
19
- * yes/no attribute type
20
- *
21
- * @category Ultimate
22
- * @package Ultimate_ModuleCreator
23
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
- */
25
- class Ultimate_ModuleCreator_Model_Attribute_Type_Yesno
26
- extends Ultimate_ModuleCreator_Model_Attribute_Type_Abstract {
27
- /**
28
- * type code
29
- * @var string
30
- */
31
- protected $_type = 'yesno';
32
- /**
33
- * sql colum ddl type
34
- * @var string
35
- */
36
- protected $_typeDdl = 'TYPE_SMALLINT';
37
- /**
38
- * sql colum ddl size
39
- * @var string
40
- */
41
- protected $_sizeDdl = 'null';
42
- /**
43
- * eav setup type
44
- */
45
- protected $_setupType = 'int';
46
- /**
47
- * eav setup input
48
- */
49
- protected $_setupInput = 'select';
50
- /**
51
- * eav setup source
52
- */
53
- protected $_setupSource = 'eav/entity_attribute_source_boolean';
54
-
55
- /**
56
- * get admin column options
57
- * @access public
58
- * @return string
59
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
60
- */
61
- public function getAdminColumnOptions() {
62
- $eol = $this->getEol();
63
- $options = $eol;
64
- $extension = $this->getModule()->getExtensionName(true);
65
- $options .= $this->getPadding(3)."'type' => 'options',".$eol;
66
- $options .= $this->getPadding(3)."'options' => array(".$eol;
67
- $options .= $this->getPadding(4)."'1' => Mage::helper('".$extension."')->__('Yes'),".$eol;
68
- $options .= $this->getPadding(4)."'0' => Mage::helper('".$extension."')->__('No'),".$eol;
69
- $options .= $this->getPadding(3).")".$eol;
70
- return $options;
71
- }
72
- /**
73
- * get the type for the form
74
- * @access public
75
- * @return string
76
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
77
- */
78
- public function getFormType() {
79
- return 'select';
80
- }
81
- /**
82
- * get text for rss
83
- * @access public
84
- * @return string
85
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
86
- */
87
- public function getRssText() {
88
- $module = $this->getModule()->getLowerModuleName();
89
- $namespace = $this->getNamespace(true);
90
- return $this->getPadding(3).'$description .= \'<div>\'.Mage::helper(\''.$namespace.'_'.$module.'\')->__("'.$this->getAttribute()->getLabel().'").\':\'.(($item->get'.$this->getAttribute()->getMagicMethodCode().'() == 1) ? Mage::helper(\''.$namespace.'_'.$module.'\')->__(\'Yes\') : Mage::helper(\''.$namespace.'_'.$module.'\')->__(\'No\')).\'</div>\';'.$this->getEol();
91
- }
92
- /**
93
- * get html for frontend
94
- * @access public
95
- * @return string
96
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
97
- */
98
- public function getFrontendHtml() {
99
- $entityName = $this->getEntity()->getNameSingular(true);
100
- $module = $this->getModule()->getLowerModuleName();
101
- $namespace = $this->getNamespace(true);
102
- return '<?php echo Mage::helper(\''.$namespace.'_'.$module.'\')->__("'.$this->getAttribute()->getLabel().'");?>:<?php echo ($_'.$entityName.'->get'.$this->getAttribute()->getMagicMethodCode().'() == 1)?Mage::helper(\''.$module.'\')->__(\'Yes\'):Mage::helper(\''.$module.'\')->__(\'No\') ?>'.$this->getEol();
103
- }
104
- /**
105
- * check if attribute is yes/no
106
- * @access public
107
- * @return bool
108
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
109
- */
110
- public function getIsYesNo(){
111
- return true;
112
- }
113
- /**
114
- * get the options for form input
115
- * @access public
116
- * @return string
117
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
118
- */
119
- public function getFormOptions(){
120
- $options = parent::getFormOptions();
121
- $padding = $this->getPadding(3);
122
- $tab = $this->getPadding();
123
- $eol = $this->getEol();
124
- $module = $this->getModule()->getLowerModuleName();
125
- $namespace = $this->getNamespace(true);
126
- $options .= $padding."'values'=> array(".$eol;
127
- $options .= $padding.$tab.'array('.$eol;
128
- $options .= $padding.$tab.$tab."'value' => 1,".$eol;
129
- $options .= $padding.$tab.$tab."'label' => Mage::helper('".$namespace.'_'.$module."')->__('Yes'),".$eol;
130
- $options .= $padding.$tab."),".$eol;
131
- $options .= $padding.$tab.'array('.$eol;
132
- $options .= $padding.$tab.$tab."'value' => 0,".$eol;
133
- $options .= $padding.$tab.$tab."'label' => Mage::helper('".$namespace.'_'.$module."')->__('No'),".$eol;
134
- $options .= $padding.$tab."),".$eol;
135
- $options .= $padding."),".$eol;
136
- return $options;
137
- }
138
- /**
139
- * get values for mass action
140
- * @access public
141
- * @return string
142
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
143
- */
144
- public function getMassActionValues() {
145
- $eol = $this->getEol();
146
- $module = $this->getModule()->getLowerModuleName();
147
- $namespace = $this->getNamespace(true);
148
- $padding = $this->getPadding(7);
149
- $tab = $this->getPadding();
150
- $content = 'array('.$eol;
151
- $content .= $padding.$tab."'1' => Mage::helper('".$namespace.'_'.$module."')->__('Yes'),".$eol;
152
- $content .= $padding.$tab."'0' => Mage::helper('".$namespace.'_'.$module."')->__('No'),".$eol;
153
- $content .= $padding.')'.$eol;
154
- return $content;
155
- }
156
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
+ */
18
+ /**
19
+ * yes/no attribute type
20
+ *
21
+ * @category Ultimate
22
+ * @package Ultimate_ModuleCreator
23
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
+ */
25
+ class Ultimate_ModuleCreator_Model_Attribute_Type_Yesno extends Ultimate_ModuleCreator_Model_Attribute_Type_Abstract
26
+ {
27
+ /**
28
+ * type code
29
+ *
30
+ * @var string
31
+ */
32
+ protected $_type = 'yesno';
33
+
34
+ /**
35
+ * sql column ddl type
36
+ *
37
+ * @var string
38
+ */
39
+ protected $_typeDdl = 'TYPE_SMALLINT';
40
+
41
+ /**
42
+ * sql column ddl size
43
+ *
44
+ * @var string
45
+ */
46
+ protected $_sizeDdl = 'null';
47
+
48
+ /**
49
+ * eav setup type
50
+ *
51
+ * @var string
52
+ */
53
+ protected $_setupType = 'int';
54
+
55
+ /**
56
+ * eav setup input
57
+ */
58
+ protected $_setupInput = 'select';
59
+
60
+ /**
61
+ * eav setup source
62
+ */
63
+ protected $_setupSource = 'eav/entity_attribute_source_boolean';
64
+
65
+ /**
66
+ * get admin column options
67
+ *
68
+ * @access public
69
+ * @return string
70
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
71
+ */
72
+ public function getAdminColumnOptions()
73
+ {
74
+ $eol = $this->getEol();
75
+ $options = $eol;
76
+ $extension = $this->getModule()->getExtensionName(true);
77
+ $options .= $this->getPadding(4)."'type' => 'options',".$eol;
78
+ $options .= $this->getPadding(5)."'options' => array(".$eol;
79
+ $options .= $this->getPadding(5)."'1' => Mage::helper('".$extension."')->__('Yes'),".$eol;
80
+ $options .= $this->getPadding(5)."'0' => Mage::helper('".$extension."')->__('No'),".$eol;
81
+ $options .= $this->getPadding(4).")".$eol;
82
+ return $options;
83
+ }
84
+
85
+ /**
86
+ * get the type for the form
87
+ *
88
+ * @access public
89
+ * @return string
90
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
91
+ */
92
+ public function getFormType()
93
+ {
94
+ return 'select';
95
+ }
96
+
97
+ /**
98
+ * get text for rss
99
+ *
100
+ * @access public
101
+ * @return string
102
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
103
+ */
104
+ public function getRssText()
105
+ {
106
+ $module = $this->getModule()->getLowerModuleName();
107
+ $namespace = $this->getNamespace(true);
108
+ return $this->getPadding(3).
109
+ '$description .= \'<div>\'.Mage::helper(\''.
110
+ $namespace.'_'.$module.'\')->__("'.
111
+ $this->getAttribute()->getLabel().
112
+ '").\':\'.(($item->get'.$this->getAttribute()->getMagicMethodCode().
113
+ '() == 1) ? Mage::helper(\''.$namespace.'_'.$module.
114
+ '\')->__(\'Yes\') : Mage::helper(\''.
115
+ $namespace.'_'.$module.'\')->__(\'No\')).\'</div>\';'.$this->getEol();
116
+ }
117
+
118
+ /**
119
+ * get html for frontend
120
+ *
121
+ * @access public
122
+ * @return string
123
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
124
+ */
125
+ public function getFrontendHtml()
126
+ {
127
+ $entityName = $this->getEntity()->getNameSingular(true);
128
+ $module = $this->getModule()->getLowerModuleName();
129
+ $namespace = $this->getNamespace(true);
130
+ return '<?php echo Mage::helper(\''.
131
+ $namespace.'_'.$module.'\')->__("'.
132
+ $this->getAttribute()->getLabel().
133
+ '");?>:<?php echo ($_'.
134
+ $entityName.'->get'.$this->getAttribute()->getMagicMethodCode().
135
+ '() == 1) ? Mage::helper(\''.$namespace.'_'.$module.
136
+ '\')->__(\'Yes\') : Mage::helper(\''.
137
+ $namespace.'_'.$module.'\')->__(\'No\') ?>'.$this->getEol();
138
+ }
139
+
140
+ /**
141
+ * check if attribute is yes/no
142
+ *
143
+ * @access public
144
+ * @return bool
145
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
146
+ */
147
+ public function getIsYesNo()
148
+ {
149
+ return true;
150
+ }
151
+
152
+ /**
153
+ * get the options for form input
154
+ *
155
+ * @access public
156
+ * @return string
157
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
158
+ */
159
+ public function getFormOptions()
160
+ {
161
+ $options = parent::getFormOptions();
162
+ $padding = $this->getPadding(3);
163
+ $tab = $this->getPadding();
164
+ $eol = $this->getEol();
165
+ $module = $this->getModule()->getLowerModuleName();
166
+ $namespace = $this->getNamespace(true);
167
+ $options .= $padding."'values'=> array(".$eol;
168
+ $options .= $padding.$tab.'array('.$eol;
169
+ $options .= $padding.$tab.$tab."'value' => 1,".$eol;
170
+ $options .= $padding.$tab.$tab."'label' => Mage::helper('".$namespace.'_'.$module."')->__('Yes'),".$eol;
171
+ $options .= $padding.$tab."),".$eol;
172
+ $options .= $padding.$tab.'array('.$eol;
173
+ $options .= $padding.$tab.$tab."'value' => 0,".$eol;
174
+ $options .= $padding.$tab.$tab."'label' => Mage::helper('".$namespace.'_'.$module."')->__('No'),".$eol;
175
+ $options .= $padding.$tab."),".$eol;
176
+ $options .= $padding."),".$eol;
177
+ return $options;
178
+ }
179
+
180
+ /**
181
+ * get values for mass action
182
+ *
183
+ * @access public
184
+ * @return string
185
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
186
+ */
187
+ public function getMassActionValues()
188
+ {
189
+ $eol = $this->getEol();
190
+ $module = $this->getModule()->getLowerModuleName();
191
+ $namespace = $this->getNamespace(true);
192
+ $padding = $this->getPadding(7);
193
+ $tab = $this->getPadding();
194
+ $content = 'array('.$eol;
195
+ $content .= $padding.$tab."'1' => Mage::helper('".$namespace.'_'.$module."')->__('Yes'),".$eol;
196
+ $content .= $padding.$tab."'0' => Mage::helper('".$namespace.'_'.$module."')->__('No'),".$eol;
197
+ $content .= $padding.')'.$eol;
198
+ return $content;
199
+ }
200
+ }
app/code/community/Ultimate/ModuleCreator/Model/Config.php CHANGED
@@ -1,71 +1,81 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
- */
18
- class Ultimate_ModuleCreator_Model_Config extends Varien_Simplexml_Config {
19
- /**
20
- * cache key
21
- */
22
- const CACHE_ID = 'umc_config';
23
- /**
24
- * get DOM of the config
25
- * @access public
26
- * @return null|Varien_Simplexml_Element
27
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
28
- */
29
- public function getDom() {
30
- if (is_null($this->_xml)){
31
- $this->_xml = Mage::getConfig()->loadModulesConfiguration('umc.xml')
32
- ->applyExtends();
33
- }
34
- return $this->_xml;
35
- }
36
-
37
- /**
38
- * get default translation module
39
- * @return string
40
- * @access protected
41
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
42
- */
43
- protected function _getDefaultTranslateModule(){
44
- return 'Ultimate_ModuleCreator';
45
- }
46
-
47
- /**
48
- * translate node
49
- * @access protected
50
- * @param Varien_Simplexml_Element $node
51
- * @return Ultimate_ModuleCreator_Model_Config
52
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
53
- */
54
- protected function _translateNode(&$node){
55
- if ($node->getAttribute('translate')){
56
- $fields = explode(' ', $node->getAttribute('translate'));
57
- $module = ($node->getAttribute('module')) ? (string)$node->getAttribute('module') : $this->_getDefaultTranslateModule();
58
- foreach ($fields as $field){
59
- if ($node->$field){
60
- $node->$field = Mage::helper($module)->__((string)$node->$field);
61
- }
62
- }
63
- }
64
- if ($node->hasChildren()){
65
- foreach ($node->children() as $child){
66
- $this->_translateNode($child);
67
- }
68
- }
69
- return $this;
70
- }
71
- }
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
+ */
18
+ class Ultimate_ModuleCreator_Model_Config extends Varien_Simplexml_Config
19
+ {
20
+ /**
21
+ * cache key
22
+ */
23
+ const CACHE_ID = 'umc_config';
24
+
25
+ /**
26
+ * get DOM of the config
27
+ *
28
+ * @access public
29
+ * @return null|Varien_Simplexml_Element
30
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
31
+ */
32
+ public function getDom()
33
+ {
34
+ if (is_null($this->_xml)) {
35
+ $this->_xml = Mage::getConfig()->loadModulesConfiguration('umc.xml')
36
+ ->applyExtends();
37
+ }
38
+ return $this->_xml;
39
+ }
40
+
41
+ /**
42
+ * get default translation module
43
+ *
44
+ * @return string
45
+ * @access protected
46
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
47
+ */
48
+ protected function _getDefaultTranslateModule()
49
+ {
50
+ return 'Ultimate_ModuleCreator';
51
+ }
52
+
53
+ /**
54
+ * translate node
55
+ *
56
+ * @access protected
57
+ * @param Varien_Simplexml_Element $node
58
+ * @return Ultimate_ModuleCreator_Model_Config
59
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
60
+ */
61
+ protected function _translateNode(&$node)
62
+ {
63
+ if ($node->getAttribute('translate')) {
64
+ $fields = explode(' ', $node->getAttribute('translate'));
65
+ $module = ($node->getAttribute('module'))
66
+ ? (string)$node->getAttribute('module')
67
+ : $this->_getDefaultTranslateModule();
68
+ foreach ($fields as $field) {
69
+ if ($node->$field) {
70
+ $node->$field = Mage::helper($module)->__((string)$node->$field);
71
+ }
72
+ }
73
+ }
74
+ if ($node->hasChildren()) {
75
+ foreach ($node->children() as $child) {
76
+ $this->_translateNode($child);
77
+ }
78
+ }
79
+ return $this;
80
+ }
81
+ }
app/code/community/Ultimate/ModuleCreator/Model/Entity.php CHANGED
@@ -1,2992 +1,3502 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
- */
18
- /**
19
- * entity model
20
- *
21
- * @category Ultimate
22
- * @package Ultimate_ModuleCreator
23
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
- */
25
- /**
26
- * @method Ultimate_ModuleCreator_Model_Entity setIndex()
27
- * @method Ultimate_ModuleCreator_Model_Entity setEditor()
28
- * @method Ultimate_ModuleCreator_Model_Entity setHasImage()
29
- * @method Ultimate_ModuleCreator_Model_Entity setHasFile()
30
- * @method Ultimate_ModuleCreator_Model_Entity setHasCountry()
31
- * @method Ultimate_ModuleCreator_Model_Entity setHasMultipleSelect()
32
- * @method bool getCreateFrontend()
33
- * @method bool getLinkProduct()
34
- * @method bool getLinkCategory()
35
- * @method bool getIsTree()
36
- * @method string getType()
37
- * @method string getLabelSingular()
38
- * @method string getLabelPlural()
39
- * @method string getProductAttributeCode()
40
- * @method string getCategoryAttributeCode()
41
- * @method int getPosition()
42
- * @method string getUrlRewriteList()
43
- * @method bool getAllowComment()
44
- * @method bool getStore()
45
- * @method bool getShowCategory()
46
- * @method int getProductAttributeScope()
47
- * @method int getCategoryAttributeScope()
48
- * @method bool getProductAttribute();
49
- * @method bool getCategoryAttribute()
50
- * @method string getProductAttributeGroup()
51
- * @method string getCategoryAttributeGroup()
52
- * @method int getListMenu()
53
- * @method bool getRest()
54
- * @method Ultimate_ModuleCreator_Model_Entity setPosition()
55
- * @method Ultimate_ModuleCreator_Model_Entity setRss()
56
- * @method bool getEditor()
57
- * @method bool getApi()
58
- * @method bool getHasCountry()
59
- * @method bool getSearch()
60
- * @method int getIndex()
61
- */
62
- class Ultimate_ModuleCreator_Model_Entity
63
- extends Ultimate_ModuleCreator_Model_Abstract {
64
- /**
65
- * reference to type instance
66
- * @var null|Ultimate_ModuleCreator_Model_Entity_Type_Abstract
67
- */
68
- protected $_typeInstance = null;
69
- /**
70
- * entity code
71
- * @var string
72
- */
73
- protected $_entityCode = 'umc_entity';
74
- /**
75
- * entity attributes
76
- * @var array
77
- */
78
- protected $_attributes = array();
79
- /**
80
- * entity module
81
- * @var Ultimate_ModuleCreator_Model_Module
82
- */
83
- protected $_module = null;
84
- /**
85
- * attribute that behaves as name
86
- * @var Ultimate_ModuleCreator_Model_Attribute
87
- */
88
- protected $_nameAttribute = null;
89
- /**
90
- * remember if attributes were prepared
91
- * @var bool
92
- */
93
- protected $_preparedAttributes = null;
94
- /**
95
- * related entities
96
- * @var array()
97
- */
98
- protected $_relatedEntities = array();
99
- /**
100
- * placeholders for replacing in source files
101
- * @var mixed
102
- */
103
- protected $_placeholders = null;
104
- /**
105
- * placeholders for sibling entities
106
- * @var mixed
107
- */
108
- protected $_placeholdersAsSibling = null;
109
- /**
110
- * set the entity module
111
- * @access public
112
- * @param Ultimate_ModuleCreator_Model_Module $module
113
- * @return Ultimate_ModuleCreator_Model_Entity
114
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
115
- */
116
- public function setModule(Ultimate_ModuleCreator_Model_Module $module){
117
- $this->_module = $module;
118
- return $this;
119
- }
120
- /**
121
- * get the entity module
122
- * @access public
123
- * @return Ultimate_ModuleCreator_Model_Module
124
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
125
- */
126
- public function getModule(){
127
- return $this->_module;
128
- }
129
- /**
130
- * add new attribute
131
- * @access public
132
- * @param Ultimate_ModuleCreator_Model_Attribute $attribute
133
- * @return Ultimate_ModuleCreator_Model_Entity
134
- * @throws Ultimate_ModuleCreator_Exception
135
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
136
- */
137
- public function addAttribute(Ultimate_ModuleCreator_Model_Attribute $attribute){
138
- Mage::dispatchEvent('umc_entity_add_attribute_before', array('attribute'=>$attribute, 'entity'=>$this));
139
- $attribute->setEntity($this);
140
- if (isset($this->_attributes[$attribute->getCode()])){
141
- throw new Ultimate_ModuleCreator_Exception(Mage::helper('modulecreator')->__('An attribute with the code "%s" already exists for entity "%s"', $attribute->getCode(), $this->getNameSingular()));
142
- }
143
- $this->_preparedAttributes = false;
144
- $this->_attributes[$attribute->getCode()] = $attribute;
145
- if ($attribute->getIsName()){
146
- if (!$attribute->getIsAllowedAsName()){
147
- /** @var Ultimate_ModuleCreator_Helper_Data $helper */
148
- $helper = Mage::helper('modulecreator');
149
- $attributeTypes = $helper->getNameAttributeTypes(true);
150
- throw new Ultimate_ModuleCreator_Exception(Mage::helper('modulecreator')->__('An attribute that acts as name must have one of the types "%s".', implode(', ', $attributeTypes)));
151
- }
152
- $attribute->setUserDefined(false);
153
- $this->_nameAttribute = $attribute;
154
- }
155
- if ($attribute->getEditor()){
156
- $this->setEditor(true);
157
- }
158
- if ($attribute->getType() == 'image'){
159
- $this->setHasImage(true);
160
- }
161
- if ($attribute->getType() == 'file'){
162
- $this->setHasFile(true);
163
- }
164
- if ($attribute->getType() == 'country'){
165
- $this->setHasCountry(true);
166
- }
167
- if ($attribute->getIsMultipleSelect()) {
168
- $this->setHasMultipleSelect(true);
169
- }
170
- Mage::dispatchEvent('umc_entity_add_attribute_after', array('attribute'=>$attribute, 'entity'=>$this));
171
- return $this;
172
- }
173
- /**
174
- * prepare attributes
175
- * @access protected
176
- * @return Ultimate_ModuleCreator_Model_Entity
177
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
178
- */
179
- protected function _prepareAttributes(){
180
- if ($this->_preparedAttributes){
181
- return $this;
182
- }
183
- $attributesByPosition = array();
184
- foreach ($this->_attributes as $attribute){
185
- /** @var Ultimate_ModuleCreator_Model_Attribute $attribute */
186
- $attributesByPosition[$attribute->getPosition()][] = $attribute;
187
- }
188
- ksort($attributesByPosition);
189
- $attributes = array();
190
- foreach ($attributesByPosition as $attributeList){
191
- foreach ($attributeList as $attribute){
192
- $attributes[$attribute->getCode()] = $attribute;
193
- }
194
- }
195
- $this->_attributes = $attributes;
196
- Mage::dispatchEvent('umc_entity_prepare_attributes', array('entity'=>$this));
197
- $this->_preparedAttributes = true;
198
- return $this;
199
- }
200
- /**
201
- * ge the entity attributes
202
- * @access public
203
- * @return Ultimate_ModuleCreator_Model_Attribute[]
204
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
205
- */
206
- public function getAttributes(){
207
- if (!$this->_preparedAttributes){
208
- $this->_prepareAttributes();
209
- }
210
- return $this->_attributes;
211
- }
212
- /**
213
- * entity to xml
214
- * @access public
215
- * @param array $arrAttributes
216
- * @param string $rootName
217
- * @param bool $addOpenTag
218
- * @param bool $addCdata
219
- * @return string
220
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
221
- */
222
- public function toXml(array $arrAttributes = array(), $rootName = 'entity', $addOpenTag=false, $addCdata=false){
223
- $xml = '';
224
- if ($addOpenTag) {
225
- $xml.= '<?xml version="1.0" encoding="UTF-8"?>'.$this->getEol();
226
- }
227
- if (!empty($rootName)) {
228
- $xml.= '<'.$rootName.'>'.$this->getEol();
229
- }
230
- $xml .= parent::toXml($this->getXmlAttributes(), '', false, $addCdata);
231
- $xml .= '<attributes>'.$this->getEol();
232
- foreach ($this->getAttributes() as $attribute){
233
- $xml .= $attribute->toXml(array(), 'attribute', false, $addCdata);
234
- }
235
- $xml .= '</attributes>'.$this->getEol();
236
- if (!empty($rootName)) {
237
- $xml.= '</'.$rootName.'>'.$this->getEol();
238
- }
239
- return $xml;
240
- }
241
- /**
242
- * get magic function code for the name attribute
243
- * @access public
244
- * @return string
245
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
246
- */
247
- public function getNameAttributeMagicCode(){
248
- $nameAttribute = $this->getNameAttribute();
249
- if ($nameAttribute){
250
- $entityNameMagicCode = $nameAttribute->getMagicMethodCode();
251
- }
252
- else{
253
- $entityNameMagicCode = 'Name';
254
- }
255
- return $entityNameMagicCode;
256
- }
257
- /**
258
- * get the name attribute
259
- * @access public
260
- * @return mixed(null|Ultimate_ModuleCreator_Model_Attribute)
261
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
262
- */
263
- public function getNameAttribute(){
264
- return $this->_nameAttribute;
265
- }
266
-
267
- /**
268
- * get the attribute code for the name attribute
269
- * @access public
270
- * @return string
271
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
272
- */
273
- public function getNameAttributeCode(){
274
- return $this->_nameAttribute->getCode();
275
- }
276
- /**
277
- * get the attribute label for the name attribute
278
- * @access public
279
- * @return string
280
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
281
- */
282
- public function getNameAttributeLabel(){
283
- return $this->getNameAttribute()->getLabel();
284
- }
285
- /**
286
- * check if the entity has file attributes
287
- * @access public
288
- * @return bool
289
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
290
- */
291
- public function getHasFile(){
292
- return $this->getTypeInstance()->getHasFile();
293
- }
294
- /**
295
- * check if the entity has image attributes
296
- * @access public
297
- * @return bool
298
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
299
- */
300
- public function getHasImage(){
301
- return $this->getTypeInstance()->getHasImage();
302
- }
303
- /**
304
- * check if the entity has upload attributes
305
- * @access public
306
- * @return bool
307
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
308
- */
309
- public function getHasUpload(){
310
- return $this->getHasFile() || $this->getHasImage();
311
- }
312
- /**
313
- * get the first image attribute code
314
- * @access public
315
- * @return string
316
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
317
- */
318
- public function getFirstImageField(){
319
- foreach ($this->getAttributes() as $attribute){
320
- if ($attribute->getType() == 'image'){
321
- return $attribute->getCode();
322
- }
323
- }
324
- return '';
325
- }
326
- /**
327
- * get the attribute name for plural
328
- * @access public
329
- * @param bool $lower
330
- * @return string
331
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
332
- */
333
- public function getNamePlural($lower = false){
334
- $plural = $this->getData('name_plural');
335
- if ($plural == $this->getNameSingular()){
336
- if ($plural == ""){
337
- return "";
338
- }
339
- $plural = $this->getNameSingular().'s';
340
- }
341
- if ($lower){
342
- $plural = strtolower($plural);
343
- }
344
- return $plural;
345
- }
346
- /**
347
- * check if frontend list files must be created
348
- * @access public
349
- * @return bool
350
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
351
- */
352
- public function getCreateList(){
353
- return $this->getCreateFrontend() && $this->getData('create_list');
354
- }
355
- /**
356
- * get list template
357
- * @access public
358
- * @return string
359
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
360
- */
361
- public function getListTemplate(){
362
- if ($this->getCreateList()){
363
- return $this->getData('list_template');
364
- }
365
- return '';
366
- }
367
- /**
368
- * check if frontend view files must be created
369
- * @access public
370
- * @return bool
371
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
372
- */
373
- public function getCreateView(){
374
- return $this->getCreateFrontend() && $this->getData('create_view');
375
- }
376
- /**
377
- * get list template
378
- * @access public
379
- * @return string
380
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
381
- */
382
- public function getViewTemplate(){
383
- if ($this->getCreateView()){
384
- return $this->getData('view_template');
385
- }
386
- return '';
387
- }
388
- /**
389
- * check if widget list files must be created
390
- * @access public
391
- * @return bool
392
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
393
- */
394
- public function getWidget(){
395
- return $this->getCreateFrontend() && $this->getData('widget');
396
- }
397
- /**
398
- * check if SEO attributes should be added
399
- * @access public
400
- * @return bool
401
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
402
- */
403
- public function getAddSeo(){
404
- return $this->getCreateView() && $this->getData('add_seo');
405
- }
406
- /**
407
- * check if SEO attributes should be added
408
- * @access public
409
- * @return bool
410
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
411
- */
412
- public function getRss(){
413
- return $this->getCreateFrontend() && $this->getData('rss');
414
- }
415
- /**
416
- * check if url rewrite shoul be added
417
- * @access public
418
- * @return bool
419
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
420
- */
421
- public function getUrlRewrite(){
422
- return $this->getCreateView() && $this->getData('url_rewrite');
423
- }
424
- /**
425
- * get url prefix
426
- * @access public
427
- * @return string
428
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
429
- */
430
- public function getUrlPrefix(){
431
- if ($this->getUrlRewrite()){
432
- return $this->getData('url_prefix');
433
- }
434
- return '';
435
- }
436
- /**
437
- * get url suffix
438
- * @access public
439
- * @return string
440
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
441
- */
442
- public function getUrlSuffix(){
443
- if ($this->getUrlRewrite()){
444
- return $this->getData('url_suffix');
445
- }
446
- return '';
447
- }
448
- /**
449
- * check if products are listed in the entity view page
450
- * @access public
451
- * @return bool
452
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
453
- */
454
- public function getShowProducts(){
455
- return $this->getLinkProduct() && $this->getCreateFrontend() && $this->getData('show_products');
456
- }
457
- /**
458
- * check if entity list is shown on product page
459
- * @access public
460
- * @return bool
461
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
462
- */
463
- public function getShowOnProduct(){
464
- return $this->getLinkProduct() && $this->getData('show_on_product');
465
- }
466
- /**
467
- * check if entity list is shown on category page
468
- * @access public
469
- * @return bool
470
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
471
- */
472
- public function getShowOnCategory(){
473
- return $this->getLinkCategory() && $this->getData('show_on_category');
474
- }
475
- /**
476
- * add related entities
477
- * @access public
478
- * @param string $type
479
- * @param Ultimate_ModuleCreator_Model_Entity $entity
480
- * @return Ultimate_ModuleCreator_Model_Entity
481
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
482
- */
483
- public function addRelatedEntity($type, $entity){
484
- $this->_relatedEntities[$type][] = $entity;
485
- return $this;
486
- }
487
- /**
488
- * get the related entities
489
- * @access public
490
- * @param mixed $type
491
- * @return Ultimate_ModuleCreator_Model_Entity[]
492
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
493
- */
494
- public function getRelatedEntities($type = null){
495
- if (is_null($type)){
496
- return $this->_relatedEntities;
497
- }
498
- if (isset($this->_relatedEntities[$type])){
499
- return $this->_relatedEntities[$type];
500
- }
501
- return array();
502
- }
503
- /**
504
- * check if entity does not behave as tree
505
- * @access public
506
- * @return bool
507
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
508
- */
509
- public function getNotIsTree(){
510
- return !$this->getIsTree();
511
- }
512
- /**
513
- * check if entity does not have url rewrites
514
- * @access public
515
- * @return bool
516
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
517
- */
518
- public function getNotUrlRewrite(){
519
- return !$this->getUrlRewrite();
520
- }
521
- /**
522
- * check if entity is EAV
523
- * @access public
524
- * @return bool
525
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
526
- */
527
- public function getIsEav(){
528
- return $this->getType() == Ultimate_ModuleCreator_Model_Entity_Type_Abstract::TYPE_EAV;
529
- }
530
- /**
531
- * check if entity is Flat
532
- * @access public
533
- * @return bool
534
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
535
- */
536
- public function getIsFlat(){
537
- return $this->getType() == Ultimate_ModuleCreator_Model_Entity_Type_Abstract::TYPE_FLAT;
538
- }
539
-
540
- /**
541
- * get the entity type instance
542
- * @access public
543
- * @return Ultimate_ModuleCreator_Model_Entity_Type_Abstract
544
- * @throws Ultimate_ModuleCreator_Exception
545
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
546
- */
547
- public function getTypeInstance(){
548
- if (is_null($this->_typeInstance)) {
549
- $type = $this->getType();
550
- /** @var Ultimate_ModuleCreator_Helper_Data $helper */
551
- $helper = Mage::helper('modulecreator');
552
- $types = $helper->getEntityTypes(false);
553
- if (isset($types[$type])) {
554
- /** @var Ultimate_ModuleCreator_Model_Entity_Type_Abstract $typeInstance */
555
- $typeInstance = Mage::getModel((string)$types[$type]->type_model);
556
- $this->_typeInstance = $typeInstance;
557
- }
558
- else {
559
- throw new Ultimate_ModuleCreator_Exception(Mage::helper('modulecreator')->__('Entity "%s" type is not valid', $type));
560
- }
561
- $this->_typeInstance->setEntity($this);
562
- }
563
- return $this->_typeInstance;
564
- }
565
-
566
- /**
567
- * check if entity has default config settings
568
- * @access public
569
- * @return bool
570
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
571
- */
572
- public function getHasConfigDefaults(){
573
- return $this->getCreateFrontend();
574
- }
575
- /**
576
- * check if entity is linked to core entities (product, category)
577
- * @access public
578
- * @return bool
579
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
580
- */
581
- public function getLinkCore(){
582
- return $this->getLinkProduct() || $this->getLinkCategory();
583
- }
584
-
585
- /**
586
- * get entity placeholders
587
- * @access public
588
- * @param null $param
589
- * @return array|mixed|null|string
590
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
591
- */
592
- public function getPlaceholders($param = null){
593
- if (is_null($this->_placeholders)){
594
- $this->_placeholders = array();
595
- $this->_placeholders['{{entity_default_config}}'] = $this->getDefaultConfig();
596
- $this->_placeholders['{{entity}}'] = $this->getNameSingular(true);
597
- $this->_placeholders['{{Entity}}'] = ucfirst($this->getNameSingular(true));
598
- $this->_placeholders['{{ENTITY}}'] = strtoupper($this->getNameSingular());
599
- $this->_placeholders['{{EntityLabel}}'] = ucfirst($this->getLabelSingular());
600
- $this->_placeholders['{{entityLabel}}'] = strtolower($this->getLabelSingular());
601
- $this->_placeholders['{{EntitiesLabel}}'] = ucfirst($this->getLabelPlural());
602
- $this->_placeholders['{{entitiesLabel}}'] = strtolower($this->getLabelPlural());
603
- $this->_placeholders['{{entityCollectionAttributes}}'] = $this->getCollectionAttributes();
604
- $this->_placeholders['{{entityAdminJoin}}'] = $this->getAdminJoin();
605
- $this->_placeholders['{{prepareColumnsHeader}}'] = $this->getPrepareColumnsHeader();
606
- $this->_placeholders['{{nameAttributeGridEav}}'] = $this->getNameAttributeGridEav();
607
- $this->_placeholders['{{nameAttributeCode}}'] = $this->getNameAttributeCode();
608
- $this->_placeholders['{{nameAttributeLabel}}'] = $this->getNameAttributeLabel();
609
- $this->_placeholders['{{entities}}'] = $this->getNamePlural(true);
610
- $this->_placeholders['{{Entities}}'] = ucfirst($this->getNamePlural(true));
611
- $this->_placeholders['{{EntityNameMagicCode}}'] = $this->getNameAttributeMagicCode();
612
- $this->_placeholders['{{attributeDdlSql}}'] = $this->getAttributesDdlSql();
613
- $this->_placeholders['{{referenceHead}}'] = $this->getReferenceHeadLayout();
614
- $this->_placeholders['{{EntityViewRelationLayout}}'] = $this->getRelationLayoutXml();
615
- $this->_placeholders['{{listLayout}}'] = $this->getListTemplate();
616
- $this->_placeholders['{{viewLayout}}'] = $this->getViewTemplate();
617
- $this->_placeholders['{{entityHtmlLink}}'] = $this->getHtmlLink();
618
- $this->_placeholders['{{EntityViewAttributes}}'] = $this->getViewAttributesHtml();
619
- $this->_placeholders['{{EntityViewWidgetAttributes}}'] = $this->getViewWidgetAttributesHtml();
620
- $this->_placeholders['{{systemAttributes}}'] = $this->getSystemAttributes();
621
- $this->_placeholders['{{entityApiAdditional}}'] = $this->getApiAdditional();
622
- $this->_placeholders['{{entityApiFaults}}'] = $this->getApiFaults();
623
- $this->_placeholders['{{entityAdditionalApiAcl}}'] = $this->getAdditionalApiAcl();
624
- $this->_placeholders['{{entityWsdlAttributes}}'] = $this->getWsdlAttributes();
625
- $this->_placeholders['{{entityWsdlAttributesForAdd}}'] = $this->getWsdlAttributes(false, true);
626
- $this->_placeholders['{{entityWsdlRelationTypes}}'] = $this->getWsdlRelationTypes();
627
- $this->_placeholders['{{entityWsdlPortTypeRelation}}'] = $this->getWsdlPortTypeRelation();
628
- $this->_placeholders['{{entityWsdlRelationBinding}}'] = $this->getWsdlRelationBinding();
629
- $this->_placeholders['{{entityWsiRelationParamTypes}}'] = $this->getWsiRelationParamTypes();
630
- $this->_placeholders['{{entityWsiRelationMessages}}'] = $this->getWsiRelationMessages();
631
- $this->_placeholders['{{entityWsiPortTypeRelation}}'] = $this->getWsiPortTypeRelation();
632
- $this->_placeholders['{{entityWsiRelationBinding}}'] = $this->getWsiRelationBinding();
633
- $this->_placeholders['{{entityWsiAttributes}}'] = $this->getWsiAttributes();
634
- $this->_placeholders['{{entityWsiAttributesForAdd}}'] = $this->getWsiAttributes(true);
635
- $this->_placeholders['{{entityWsiRelationTypes}}'] = $this->getWsiRelationTypes();
636
- $this->_placeholders['{{entityWsdlMessages}}'] = $this->getWsdlMessages();
637
- $this->_placeholders['{{fksDdl}}'] = $this->getParentEntitiesFksDdl();
638
- $this->_placeholders['{{selectedMenuPath}}'] = $this->getSelectedMenuPath();
639
- $this->_placeholders['{{entityAttributesSetup}}'] = $this->getAttributesSetup();
640
- $this->_placeholders['{{ResourceModelParent}}'] = $this->getResourceModelParent();
641
- $this->_placeholders['{{ResourceCollectionParent}}'] = $this->getResourceCollectionModelParent();
642
- $this->_placeholders['{{RelationsResourceTables}}'] = $this->getResourceRelationsTables();
643
- $this->_placeholders['{{RelationsResourceTablesDeclare}}'] = $this->getResourceRelationsTablesDeclare();
644
- $this->_placeholders['{{adminIndexContent}}'] = $this->getAdminIndexLayoutContent();
645
- $this->_placeholders['{{EntityParentModel}}'] = $this->getEntityParentModel();
646
- $this->_placeholders['{{entityTableAlias}}'] = $this->getEntityTableAlias();
647
- $this->_placeholders['{{additionalPrepareCollection}}'] = $this->getAdditionalPrepareCollection();
648
- $this->_placeholders['{{entityEditLayoutLeft}}'] = $this->getEditLayoutLeft();
649
- $this->_placeholders['{{entityLayoutAdditional}}'] = $this->getEditLayoutAdditional();
650
- $this->_placeholders['{{productAttributeCode}}'] = $this->getProductAttributeCode();
651
- $this->_placeholders['{{categoryAttributeCode}}'] = $this->getCategoryAttributeCode();
652
- $this->_placeholders['{{entityProductAttributeScope}}'] = $this->getProductAttributeScopeLabel();
653
- $this->_placeholders['{{entityCategoryAttributeScope}}']= $this->getCategoryAttributeScopeLabel();
654
- $this->_placeholders['{{productAttributeGroup}}'] = $this->getProductAttributeGroupLabel();
655
- $this->_placeholders['{{categoryAttributeGroup}}'] = $this->getCategoryAttributeGroupLabel();
656
- $this->_placeholders['{{beforeSaveParam}}'] = $this->getBeforeSaveParam();
657
- $this->_placeholders['{{EntityAttributeSetId}}'] = $this->getEntityAttributeSetId();
658
- $this->_placeholders['{{filterMethod}}'] = $this->getFilterMethod();
659
- $this->_placeholders['{{multipleSelectConvert}}'] = $this->getMultipleSelectConvert();
660
- $this->_placeholders['{{toOptionAddition}}'] = $this->getToOptionAddition();
661
- $this->_placeholders['{{multiselectMethods}}'] = $this->getMultiselectMethods();
662
- $this->_placeholders['{{nameHtml}}'] = $this->getNameHtml();
663
- $this->_placeholders['{{isTree}}'] = (int)$this->getIsTree();
664
- $this->_placeholders['{{commentFilterIndexPrefix}}'] = $this->getCommentFilterIndexPrefix();
665
- $this->_placeholders['{{entityApiAdditionalSettings}}'] = $this->getApiAdditionalSettings();
666
- $this->_placeholders['{{subEntitiesAcl}}'] = $this->getSubEntitiesAcl();
667
- $this->_placeholders['{{position}}'] = $this->getPosition();
668
- $this->_placeholders['{{entityApiResourcesAlias}}'] = $this->getApiResourcesAlias();
669
- $this->_placeholders['{{entityApiResourcesAliasV2}}'] = $this->getApiResourcesAliasV2();
670
- $this->_placeholders['{{defaultApiAttributes}}'] = $this->getDefaultApiAttributes();
671
- $this->_placeholders['{{filterEntityDates}}'] = $this->getFilterDates();
672
- $this->_placeholders['{{filterEntityDates3}}'] = $this->getFilterDates(3);
673
- $this->_placeholders['{{allAttributesToCollection}}'] = $this->getAllAttributesToCollection();
674
- $this->_placeholders['{{loadStoreId}}'] = $this->getLoadStoreId();
675
- $this->_placeholders['{{restCollectionCleanup}}'] = $this->getRestCollectionCleanup();
676
- $this->_placeholders['{{restCollectionStoreId}}'] = $this->getRestCollectionStoreId();
677
- $this->_placeholders['{{defaultAttributeValues}}'] = $this->getDefaultAttributeValues();
678
- $this->_placeholders['{{toOptionArraySelect}}'] = $this->getToOptionArraySelect();
679
- $this->_placeholders['{{parentStaticParams}}'] = $this->getParentStaticParams();
680
-
681
-
682
- $eventObject = new Varien_Object(
683
- array(
684
- 'placeholders' => $this->_placeholders
685
- )
686
- );
687
- Mage::dispatchEvent('umc_entity_placeholdrers', array('event_object'=>$eventObject));
688
- $this->_placeholders = $eventObject->getPlaceholders();
689
- }
690
- if (is_null($param)){
691
- return $this->_placeholders;
692
- }
693
- if (isset($this->_placeholders[$param])){
694
- return $this->_placeholders[$param];
695
- }
696
- return '';
697
- }
698
-
699
- /**
700
- * get placeholders as sibling
701
- * @access public
702
- * @param null $param
703
- * @return array|mixed|null|string
704
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
705
- */
706
- public function getPlaceholdersAsSibling($param = null){
707
- if (is_null($this->_placeholdersAsSibling)){
708
- $this->_placeholdersAsSibling = array();
709
- $this->_placeholdersAsSibling['{{sibling_default_config}}'] = $this->getDefaultConfig();
710
- $this->_placeholdersAsSibling['{{sibling}}'] = $this->getNameSingular(true);
711
- $this->_placeholdersAsSibling['{{Sibling}}'] = ucfirst($this->getNameSingular(true));
712
- $this->_placeholdersAsSibling['{{SIBLING}}'] = strtoupper($this->getNameSingular());
713
- $this->_placeholdersAsSibling['{{SiblingLabel}}'] = ucfirst($this->getLabelSingular());
714
- $this->_placeholdersAsSibling['{{siblingLabel}}'] = strtolower($this->getLabelSingular());
715
- $this->_placeholdersAsSibling['{{SiblingsLabel}}'] = ucfirst($this->getLabelPlural());
716
- $this->_placeholdersAsSibling['{{siblingsLabel}}'] = $this->getLabelPlural(true);
717
- $this->_placeholdersAsSibling['{{siblingCollectionAttributes}}'] = $this->getCollectionAttributes();
718
- $this->_placeholdersAsSibling['{{siblingAdminJoin}}'] = $this->getAdminJoin();
719
- $this->_placeholdersAsSibling['{{siblingColumnsHeader}}'] = $this->getPrepareColumnsHeader();
720
- $this->_placeholdersAsSibling['{{siblingNameAttributeGridEav}}'] = $this->getNameAttributeGridEav();
721
- $this->_placeholdersAsSibling['{{siblingNameAttributeCode}}'] = $this->getNameAttributeCode();
722
- $this->_placeholdersAsSibling['{{siblingNameAttributeLabel}}'] = $this->getNameAttributeLabel();
723
- $this->_placeholdersAsSibling['{{siblings}}'] = strtolower($this->getNamePlural());
724
- $this->_placeholdersAsSibling['{{Siblings}}'] = ucfirst($this->getNamePlural(true));
725
- $this->_placeholdersAsSibling['{{SiblingNameMagicCode}}'] = $this->getNameAttributeMagicCode();
726
- $this->_placeholdersAsSibling['{{SiblingViewRelationLayout}}'] = $this->getRelationLayoutXml();
727
- $this->_placeholdersAsSibling['{{siblingListLayout}}'] = $this->getListTemplate();
728
- $this->_placeholdersAsSibling['{{siblingViewLayout}}'] = $this->getViewTemplate();
729
- $this->_placeholdersAsSibling['{{SiblingListItem}}'] = $this->getHtmlLink();
730
- $this->_placeholdersAsSibling['{{siblingNameAttribute}}'] = $this->getNameAttributeCode();
731
- $this->_placeholdersAsSibling['{{siblingAdditionalPrepareCollection}}'] = $this->getAdditionalPrepareCollection();
732
- $this->_placeholdersAsSibling['{{siblingTableAlias}}'] = $this->getEntityTableAlias();
733
- $this->_placeholdersAsSibling['{{siblingFilterMethod}}'] = $this->getFilterMethod();
734
- $this->_placeholdersAsSibling['{{siblingAllAttributesToCollection}}'] = $this->getAllAttributesToCollection();
735
- $this->_placeholdersAsSibling['{{siblingLoadStoreId}}'] = $this->getLoadStoreId();
736
- $this->_placeholdersAsSibling['{{siblingToOptionArraySelect}}'] = $this->getToOptionArraySelect();
737
- $this->_placeholdersAsSibling['{{siblingParentStaticParams}}'] = $this->getParentStaticParams();
738
-
739
- $eventObject = new Varien_Object(
740
- array(
741
- 'placeholders' => $this->_placeholdersAsSibling
742
- )
743
- );
744
- Mage::dispatchEvent('umc_entity_placeholdrers_as_sibling', array('event_object'=>$eventObject));
745
- $this->_placeholdersAsSibling = $eventObject->getPlaceholders();
746
- }
747
- if (is_null($param)){
748
- return $this->_placeholdersAsSibling;
749
- }
750
- if (isset($this->_placeholdersAsSibling[$param])){
751
- return $this->_placeholdersAsSibling[$param];
752
- }
753
- return '';
754
- }
755
-
756
- /**
757
- * get default config settings
758
- * @access public
759
- * @return string
760
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
761
- */
762
- public function getDefaultConfig(){
763
- if (!$this->getHasConfigDefaults()){
764
- return '';
765
- }
766
- $padding3 = $this->getPadding(3);
767
- $padding = $this->getPadding();
768
- $eol = $this->getEol();
769
-
770
- $text = '<'.$this->getNameSingular().'>'.$eol;
771
- if ($this->getCreateFrontend()){
772
- $text.= $padding3.$padding.'<breadcrumbs>1</breadcrumbs>'.$eol;
773
- }
774
- if ($this->getUrlRewrite() && $this->getUrlPrefix()){
775
- $text.= $padding3.$padding.'<url_prefix>'.$this->getUrlPrefix().'</url_prefix>'.$eol;
776
- }
777
- if ($this->getUrlRewrite() && $this->getUrlSuffix()){
778
- $text.= $padding3.$padding.'<url_suffix>'.$this->getUrlSuffix().'</url_suffix>'.$eol;
779
- }
780
- if ($this->getUrlRewrite() && $this->getUrlRewriteList()) {
781
- $text.= $padding3.$padding.'<url_rewrite_list>'.$this->getUrlRewriteList().'</url_rewrite_list>'.$eol;
782
- }
783
- if ($this->getAllowComment()){
784
- $text.= $padding3.$padding.'<allow_comment>1</allow_comment>'.$eol;
785
- }
786
- if ($this->getRss()){
787
- $text.= $padding3.$padding.'<rss>1</rss>'.$eol;
788
- }
789
- if ($this->getAddSeo()){
790
- $text.= $padding3.$padding.'<meta_title>'.$this->getLabelPlural().'</meta_title>'.$eol;
791
- }
792
- if ($this->getIsTree() && $this->getCreateFrontend()){
793
- $text.= $padding3.$padding.'<tree>1</tree>'.$eol;
794
- $text.= $padding3.$padding.'<recursion>0</recursion>'.$eol;
795
- }
796
- $text .= $padding3.'</'.$this->getNameSingular().'>'.$eol;
797
- return $text;
798
- }
799
-
800
- /**
801
- * get xml for add product event
802
- * @access public
803
- * @return string
804
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
805
- */
806
- public function getAddBlockToProductEvent(){
807
- $text = '';
808
- if ($this->getLinkProduct()){
809
- $ns = $this->getNamespace(true);
810
- $eol = $this->getEol();
811
- $text = $this->getPadding(5).'<'.$ns.'_'.$this->getModule()->getLowerModuleName().'_'.$this->getNameSingular(true).'>'.$eol;
812
- $text .= $this->getPadding(6).'<type>singleton</type>'.$eol;
813
- $text .= $this->getPadding(6).'<class>'.$ns.'_'.$this->getModule()->getLowerModuleName().'/adminhtml_observer</class>'.$eol;
814
- $text .= $this->getPadding(6).'<method>add'.ucfirst(strtolower($this->getNameSingular())).'Block</method>'.$eol;
815
- $text .= $this->getPadding(5).'</'.$ns.'_'.$this->getModule()->getLowerModuleName().'_'.$this->getNameSingular(true).'>'.$eol;
816
- }
817
- return $text;
818
- }
819
- /**
820
- * get xml for add product save after event
821
- * @access public
822
- * @return string
823
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
824
- */
825
- public function getProductSaveAfterEvent(){
826
- $text = '';
827
- if ($this->getLinkProduct()){
828
- $ns = strtolower($this->getModule()->getNamespace());
829
- $eol = $this->getEol();
830
- $text = $this->getPadding(5).'<'.$ns.'_'.$this->getModule()->getLowerModuleName().'_'.$this->getNameSingular(true).'>'.$eol;
831
- $text .= $this->getPadding(6).'<type>singleton</type>'.$eol;
832
- $text .= $this->getPadding(6).'<class>'.$ns.'_'.$this->getModule()->getLowerModuleName().'/adminhtml_observer</class>'.$eol;
833
- $text .= $this->getPadding(6).'<method>save'.ucfirst(strtolower($this->getNameSingular())).'Data</method>'.$eol;
834
- $text .= $this->getPadding(5).'</'.$ns.'_'.$this->getModule()->getLowerModuleName().'_'.$this->getNameSingular(true).'>'.$eol;
835
- }
836
- return $text;
837
- }
838
- /**
839
- * get xml for add can load ext js
840
- * @access public
841
- * @return string
842
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
843
- */
844
- public function getCanLoadExtJsEvent(){
845
- $text = '';
846
- if ($this->getLinkProduct() && $this->getIsTree()){
847
- $eol = $this->getEol();
848
- $ns = strtolower($this->getModule()->getNamespace());
849
- $text = $this->getPadding(5).'<'.$ns.'_'.$this->getModule()->getLowerModuleName().'_'.$this->getNameSingular(true).'>'.$eol;
850
- $text .= $this->getPadding(6).'<type>singleton</type>'.$eol;
851
- $text .= $this->getPadding(6).'<class>'.$ns.'_'.$this->getModule()->getLowerModuleName().'/adminhtml_observer</class>'.$eol;
852
- $text .= $this->getPadding(6).'<method>setCanLoadExtJs</method>'.$eol;
853
- $text .= $this->getPadding(5).'</'.$ns.'_'.$this->getModule()->getLowerModuleName().'_'.$this->getNameSingular(true).'>'.$eol;
854
- }
855
- return $text;
856
- }
857
-
858
- /**
859
- * get xml for admin menu
860
- * @access public
861
- * @param $padding
862
- * @return string
863
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
864
- */
865
- public function getMenu($padding){
866
- $extension = $this->getModule()->getExtensionName(true);
867
- $module = $this->getModule()->getLowerModuleName();
868
- $title = ucwords($this->getLabelSingular());
869
- $entity = strtolower($this->getNameSingular());
870
- $action = $module.'_'.$entity;
871
- $eol = $this->getEol();
872
-
873
- $text = $this->getPadding($padding).'<'.$entity.' translate="title" module="'.$extension.'">'.$eol;
874
- $text .= $this->getPadding($padding + 1).'<title>'.$title.'</title>'.$eol;
875
- $text .= $this->getPadding($padding + 1).'<action>adminhtml/'.$action.'</action>'.$eol;
876
- $text .= $this->getPadding($padding + 1).'<sort_order>'.$this->getPosition().'</sort_order>'.$eol;
877
- $text .= $this->getPadding($padding).'</'.$entity.'>'.$eol;
878
- if ($this->getAllowComment()){
879
- $text .= $this->getPadding($padding).'<'.$entity.'_comments translate="title" module="'.$extension.'">'.$eol;
880
- $text .= $this->getPadding($padding + 1).'<title>Manage '.$title.' Comments</title>'.$eol;
881
- $text .= $this->getPadding($padding + 1).'<action>adminhtml/'.$action.'_comment</action>'.$eol;
882
- $text .= $this->getPadding($padding + 1).'<sort_order>'.($this->getPosition() + 4).'</sort_order>'.$eol;
883
- $text .= $this->getPadding($padding).'</'.$entity.'_comments>'.$eol;
884
- }
885
-
886
- $text .= $this->getTypeInstance()->getAdditionalMenu($padding);
887
- return $text;
888
-
889
- }
890
-
891
- /**
892
- * get xml for acl
893
- * @access public
894
- * @param $padding
895
- * @return string
896
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
897
- */
898
- public function getMenuAcl($padding){
899
- $extension = $this->getModule()->getExtensionName(true);
900
- $title = ucwords($this->getLabelSingular());
901
- $entity = $this->getNameSingular(true);
902
- $eol = $this->getEol();
903
-
904
- $text = $this->getPadding($padding).'<'.$entity.' translate="title" module="'.$extension.'">'.$eol;
905
- $text .= $this->getPadding($padding + 1).'<title>'.$title.'</title>'.$eol;
906
- $text .= $this->getPadding($padding + 1).'<sort_order>'.$this->getPosition().'</sort_order>'.$eol;
907
- $text .= $this->getPadding($padding).'</'.$entity.'>'.$eol;
908
-
909
- if ($this->getAllowComment()){
910
- $text .= $this->getPadding($padding).'<'.$entity.'_comments translate="title" module="'.$extension.'">'.$eol;
911
- $text .= $this->getPadding($padding + 1).'<title>Manage '.$title.' Comments</title>'.$eol;
912
- $text .= $this->getPadding($padding + 1).'<sort_order>'.($this->getPosition() + 5).'</sort_order>'.$eol;
913
- $text .= $this->getPadding($padding).'</'.$entity.'_comments>'.$eol;
914
- }
915
- $text .= $this->getTypeInstance()->getAdditionalMenuAcl($padding);
916
- return $text;
917
-
918
- }
919
-
920
- /**
921
- * get attributes that need to be added in the admin grid collection
922
- * @access public
923
- * @return string
924
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
925
- */
926
- public function getCollectionAttributes(){
927
- return $this->getTypeInstance()->getCollectionAttributes();
928
- }
929
- /**
930
- * get join with admin - for the admin grid
931
- * @access public
932
- * @return string
933
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
934
- */
935
- public function getAdminJoin(){
936
- return $this->getTypeInstance()->getAdminJoin();
937
- }
938
- /**
939
- * code above the prepare columns
940
- * @access public
941
- * @return string
942
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
943
- */
944
- public function getPrepareColumnsHeader(){
945
- return $this->getTypeInstance()->getPrepareColumnsHeader();
946
- }
947
- /**
948
- * name attribute in grid
949
- * @access public
950
- * @return string
951
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
952
- */
953
- public function getNameAttributeGridEav(){
954
- return $this->getTypeInstance()->getNameAttributeGridEav();
955
- }
956
-
957
- /**
958
- * check if the frontend list block can be created
959
- * @access public
960
- * @return bool
961
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
962
- */
963
- public function getCanCreateListBlock(){
964
- if ($this->getCreateList()){
965
- return true;
966
- }
967
- if ($this->getShowOnProduct()){
968
- return true;
969
- }
970
- if ($this->getShowOnCategory()){
971
- return true;
972
- }
973
- //check for siblings with frontend view
974
- $related = $this->getRelatedEntities(Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_SIBLING);
975
- foreach ($related as $r){
976
- if ($r->getCreateView()){
977
- return true;
978
- }
979
- }
980
- //check for parents with frontend view
981
- $related = $this->getRelatedEntities(Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_CHILD);
982
- foreach ($related as $r){
983
- if ($r->getCreateView()){
984
- return true;
985
- }
986
- }
987
- return false;
988
- }
989
- /**
990
- * get ddl text for attributes
991
- * @access public
992
- * @return bool
993
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
994
- */
995
- public function getAttributesDdlSql(){
996
- $padding = $this->getPadding();
997
- $eol = $this->getEol();
998
- $content = '';
999
- $content .= $this->getParentEntitiesFkAttributes($padding, true);
1000
- if ($this->getIsFlat()){
1001
- foreach ($this->getAttributes() as $attribute){
1002
- $content .= $padding.$attribute->getDdlSqlColumn().$eol;
1003
- }
1004
- }
1005
- if ($this->getIsFlat()) {
1006
- $simulated = $this->getSimulatedAttributes(null, false);
1007
- }
1008
- elseif ($this->getIsTree()) {
1009
- $simulated = $this->getSimulatedAttributes('tree', false);
1010
- }
1011
- else {
1012
- $simulated = array();
1013
- }
1014
- foreach ($simulated as $attr){
1015
- $content .= $padding.$attr->getDdlSqlColumn().$eol;
1016
- }
1017
- return substr($content,0, strlen($content) - strlen($eol));
1018
- }
1019
-
1020
- /**
1021
- * get foreign key columns
1022
- * @access public
1023
- * @param $padding
1024
- * @return string
1025
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1026
- */
1027
- public function getParentEntitiesFkAttributes($padding){
1028
- if ($this->getIsEav()) {
1029
- return '';
1030
- }
1031
- $parents = $this->getRelatedEntities(Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_CHILD);
1032
- $content = '';
1033
- foreach ($parents as $parent){
1034
- /** @var Ultimate_ModuleCreator_Model_Attribute $attr */
1035
- $attr = Mage::getModel('modulecreator/attribute');
1036
- $attr->setCode($parent->getPlaceholders('{{entity}}').'_id');
1037
- $attr->setLabel($parent->getPlaceholders('{{EntityLabel}}'). ' ID');
1038
- $attr->setType('int');
1039
- $content .= $padding.$attr->getDdlSqlColumn()."\n";
1040
- }
1041
- return $content;
1042
- }
1043
-
1044
- /**
1045
- * get simulated attributes
1046
- * @access public
1047
- * @param mixed $type
1048
- * @param bool $ignoreSettings
1049
- * @param array $except
1050
- * @return Ultimate_ModuleCreator_Model_Attribute[]
1051
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1052
- */
1053
- public function getSimulatedAttributes($type = null, $ignoreSettings = false, $except = array()){
1054
- /** @var Ultimate_ModuleCreator_Model_Attribute[] $attributes */
1055
- $attributes = array();
1056
- $namespace = $this->getNamespace(true);
1057
- if (is_null($type)){
1058
- $types = array('status', 'url_rewrite', 'tree', 'rss', 'seo', 'comment');
1059
- $attributes = array();
1060
- foreach ($types as $type){
1061
- if (!in_array($type, $except)){
1062
- $attributes = array_merge($attributes, $this->getSimulatedAttributes($type, $ignoreSettings));
1063
- }
1064
- }
1065
- return $attributes;
1066
- }
1067
- switch ($type){
1068
- case 'status':
1069
- /** @var Ultimate_ModuleCreator_Model_Attribute $attr */
1070
- $attr = Mage::getModel('modulecreator/attribute');
1071
- $attr->setCode('status');
1072
- $attr->setLabel('Enabled');
1073
- $attr->setType('yesno');
1074
- $attr->setDefaultValue('1');
1075
- $attributes[] = $attr;
1076
- break;
1077
- case 'url_rewrite':
1078
- if ($this->getUrlRewrite() || $ignoreSettings){
1079
- /** @var Ultimate_ModuleCreator_Model_Attribute $attr */
1080
- $attr = Mage::getModel('modulecreator/attribute');
1081
- $attr->setCode('url_key');
1082
- $attr->setLabel('URL key');
1083
- $attr->setType('text');
1084
- $module = $this->getModule()->getLowerModuleName();
1085
- $entity = $this->getNameSingular(true);
1086
- $attr->setForcedSetupBackend($namespace.'_'.$module.'/'.$entity.'_attribute_backend_urlkey');
1087
- $attributes[] = $attr;
1088
- }
1089
- break;
1090
- case 'tree' :
1091
- if ($this->getIsTree() || $ignoreSettings){
1092
- /** @var Ultimate_ModuleCreator_Model_Attribute $attr */
1093
- $attr = Mage::getModel('modulecreator/attribute');
1094
- $attr->setCode('parent_id');
1095
- $attr->setLabel('Parent id');
1096
- $attr->setType('int');
1097
- $attributes[] = $attr;
1098
-
1099
- /** @var Ultimate_ModuleCreator_Model_Attribute $attr */
1100
- $attr = Mage::getModel('modulecreator/attribute');
1101
- $attr->setCode('path');
1102
- $attr->setLabel('Path');
1103
- $attr->setType('text');
1104
- $attr->setIgnoreApi(true);
1105
- $attributes[] = $attr;
1106
-
1107
- /** @var Ultimate_ModuleCreator_Model_Attribute $attr */
1108
- $attr = Mage::getModel('modulecreator/attribute');
1109
- $attr->setCode('position');
1110
- $attr->setLabel('Position');
1111
- $attr->setType('int');
1112
- $attr->setIgnoreApi(true);
1113
- $attributes[] = $attr;
1114
-
1115
- /** @var Ultimate_ModuleCreator_Model_Attribute $attr */
1116
- $attr = Mage::getModel('modulecreator/attribute');
1117
- $attr->setCode('level');
1118
- $attr->setLabel('Level');
1119
- $attr->setType('int');
1120
- $attr->setIgnoreApi(true);
1121
- $attributes[] = $attr;
1122
-
1123
- /** @var Ultimate_ModuleCreator_Model_Attribute $attr */
1124
- $attr = Mage::getModel('modulecreator/attribute');
1125
- $attr->setCode('children_count');
1126
- $attr->setLabel('Children count');
1127
- $attr->setType('int');
1128
- $attr->setIgnoreApi(true);
1129
- $attributes[] = $attr;
1130
- }
1131
- break;
1132
- case 'rss':
1133
- if($this->getRss() || $ignoreSettings){
1134
- /** @var Ultimate_ModuleCreator_Model_Attribute $attr */
1135
- $attr = Mage::getModel('modulecreator/attribute');
1136
- $attr->setCode('in_rss');
1137
- $attr->setLabel('In RSS');
1138
- $attr->setType('yesno');
1139
- $attr->setDefaultValue('1');
1140
- $attributes[] = $attr;
1141
- }
1142
- break;
1143
- case 'seo':
1144
- if ($this->getAddSeo() || $ignoreSettings){
1145
- /** @var Ultimate_ModuleCreator_Model_Attribute $attr */
1146
- $attr = Mage::getModel('modulecreator/attribute');
1147
- $attr->setCode('meta_title');
1148
- $attr->setLabel('Meta title');
1149
- $attr->setType('text');
1150
- $attributes[] = $attr;
1151
-
1152
- /** @var Ultimate_ModuleCreator_Model_Attribute $attr */
1153
- $attr = Mage::getModel('modulecreator/attribute');
1154
- $attr->setCode('meta_keywords');
1155
- $attr->setLabel('Meta keywords');
1156
- $attr->setType('textarea');
1157
- $attributes[] = $attr;
1158
-
1159
- $attr = Mage::getModel('modulecreator/attribute');
1160
- $attr->setCode('meta_description');
1161
- $attr->setLabel('Meta description');
1162
- $attr->setType('textarea');
1163
- $attributes[] = $attr;
1164
- }
1165
- break;
1166
- case 'comment':
1167
- if ($this->getAllowComment() || $ignoreSettings){
1168
- /** @var Ultimate_ModuleCreator_Model_Attribute $attr */
1169
- $attr = Mage::getModel('modulecreator/attribute');
1170
- $attr->setCode('allow_comment');
1171
- $attr->setLabel('Allow Comment');
1172
- $attr->setType('dropdown');
1173
- $attr->setOptionsSource('custom');
1174
- $attr->setOptions(false);
1175
- $attr->setEntity($this);
1176
- $attr->setDefaultValue('2');
1177
- $attr->setForcedDefaultValue('2');
1178
- $attr->setForcedSource($namespace.'_'.$this->getModule()->getLowerModuleName().'/adminhtml_source_yesnodefault');
1179
- $attributes[] = $attr;
1180
- }
1181
- break;
1182
- default:
1183
- break;
1184
- }
1185
- foreach ($attributes as $attribute) {
1186
- $attribute->setUserDefined(false);
1187
- }
1188
- return $attributes;
1189
- }
1190
- /**
1191
- * get layout xml head reference
1192
- * @access public
1193
- * @return string
1194
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1195
- */
1196
- public function getReferenceHeadLayout(){
1197
- $eol = $this->getEol();
1198
- $content = $this->getPadding(2);
1199
- if ($this->getIsTree()){
1200
- $namespace = $this->getNamespace(true);
1201
- $module = $this->getModule()->getLowerModuleName();
1202
- $entity = $this->getNameSingular(true);
1203
- $content .= '<reference name="head">'.$eol;
1204
- $content .= $this->getPadding(3).'<action method="addItem" ifconfig="'.$namespace.'_'.$module.'/'.$entity.'/tree"><type>skin_js</type><js>js/'.$namespace.'_'.$module.'/tree.js</js></action>'.$eol;
1205
- $content .= $this->getPadding(2).'</reference>'.$eol;
1206
- $content .= $this->getPadding(2);
1207
- }
1208
- return $content;
1209
- }
1210
- /**
1211
- * get layout xml for relation to product
1212
- * @access public
1213
- * @return string
1214
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1215
- */
1216
- public function getRelationLayoutXml(){
1217
- $eol = $this->getEol();
1218
- $content = $this->getPadding(2);
1219
- $module = $this->getModule()->getLowerModuleName();
1220
- $entityName = $this->getNameSingular(true);
1221
- $namespace = $this->getNamespace(true);
1222
- if ($this->getIsTree()){
1223
- $content .= $this->getPadding().'<block type="'.$namespace.'_'.$module.'/'.$entityName.'_children" name="'.$entityName.'_children" template="'.$namespace.'_'.$module.'/'.$entityName.'/children.phtml" />'.$eol.$this->getPadding(2);
1224
- }
1225
- if ($this->getShowProducts()){
1226
- $content .= $this->getPadding().'<block type="'.$namespace.'_'.$module.'/'.$entityName.'_catalog_product_list" name="'.$entityName.'.info.products" as="'.$entityName.'_products" template="'.$namespace.'_'.$module.'/'.$entityName.'/catalog/product/list.phtml" />'.$eol.$this->getPadding(2);
1227
- }
1228
- if ($this->getShowCategory()){
1229
- $content .= $this->getPadding().'<block type="'.$namespace.'_'.$module.'/'.$entityName.'_catalog_category_list" name="'.$entityName.'.info.categories" as="'.$entityName.'_categories" template="'.$namespace.'_'.$module.'/'.$entityName.'/catalog/category/list.phtml" />'.$eol.$this->getPadding(2);
1230
- }
1231
- $children = $this->getRelatedEntities(Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_PARENT);
1232
- $siblings = $this->getRelatedEntities(Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_SIBLING);
1233
- /** @var Ultimate_ModuleCreator_Model_Entity[] $relatedEntities */
1234
- $relatedEntities = array_merge($children, $siblings);
1235
- foreach ($relatedEntities as $entity){
1236
- $content .= $this->getPadding().'<block type="'.$namespace.'_'.$module.'/'.$entityName.'_'.strtolower($entity->getNameSingular()).'_list" name="'.$entityName.'.'.strtolower($entity->getNameSingular()).'_list" as="'.$entityName.'_'.strtolower($this->getNamePlural()).'" template="'.$namespace.'_'.$module.'/'.$entityName.'/'.strtolower($entity->getNameSingular()).'/list.phtml" />'.$eol.$this->getPadding(2);
1237
- }
1238
- if ($this->getAllowComment()) {
1239
- $content .= $this->getPadding().'<block type="'.$namespace.'_'.$module.'/'.$entityName.'_comment_list" name="'.$entityName.'.comments_list" as="'.$entityName.'_comment_list" template="'.$namespace.'_'.$module.'/'.$entityName.'/comment/list.phtml">'.$eol.$this->getPadding(2);
1240
- $content .= $this->getPadding(2).'<block type="'.$namespace.'_'.$module.'/'.$entityName.'_comment_form" name="comment_form" as="comment_form" template="'.$namespace.'_'.$module.'/'.$entityName.'/comment/form.phtml" />'.$eol.$this->getPadding(2);
1241
- $content .= $this->getPadding().'</block>'.$eol.$this->getPadding(2);
1242
- }
1243
- return $content;
1244
- }
1245
- /**
1246
- * get html link to entity
1247
- * @access public
1248
- * @return string
1249
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1250
- */
1251
- public function getHtmlLink(){
1252
- $eol = $this->getEol();
1253
- $entity = $this->getNameSingular(true);
1254
- $entityUc = ucfirst($this->getNameSingular());
1255
- $nameCode = $this->getNameAttributeMagicCode();
1256
- $content = '';
1257
- $padd = 3;
1258
- if ($this->getCreateView()){
1259
- $padd = 4;
1260
- $content .= $this->getPadding(3).'<a href="<?php echo $_'.$entity.'->get'.$entityUc.'Url()?>">'.$eol;
1261
- }
1262
- $content .= $this->getPadding($padd).'<?php echo $_'.$entity.'->get'.$nameCode.'();?>'.$eol;
1263
- if ($this->getCreateView()){
1264
- $content .= $this->getPadding(3).'</a>';
1265
- }
1266
- $content .= '<br />';
1267
- return $content;
1268
- }
1269
-
1270
- /**
1271
- * get the html for attributes in view page
1272
- * @access public
1273
- * @return string
1274
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1275
- */
1276
- public function getViewAttributesHtml(){
1277
- $eol = $this->getEol();
1278
- $content = '';
1279
- foreach ($this->getAttributes() as $attribute){
1280
- if ($attribute->getFrontend()){
1281
- $content .= $this->getPadding().'<div class="'.$this->getNameSingular().'-'.$attribute->getCode().'">'.$eol;
1282
- $content .= $this->getPadding(2).$attribute->getFrontendHtml().$eol;
1283
- $content .= $this->getPadding().'</div>'.$eol;
1284
- }
1285
- }
1286
- return $content;
1287
- }
1288
-
1289
- /**
1290
- * check if comments should be split by store
1291
- * @access public
1292
- * @return bool
1293
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1294
- */
1295
- public function getAllowCommentByStore(){
1296
- return $this->getTypeInstance()->getAllowCommentByStore();
1297
- }
1298
-
1299
- /**
1300
- * get view widget attributes
1301
- * @access public
1302
- * @return string
1303
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1304
- */
1305
- public function getViewWidgetAttributesHtml(){
1306
- $content = '';
1307
- $padding = $this->getPadding(3);
1308
- $tab = $this->getPadding();
1309
- $eol = $this->getEol();
1310
- foreach ($this->getAttributes() as $attribute){
1311
- if ($attribute->getWidget()){
1312
- $content .= $padding.'<div class="'.$attribute->getCode().'-widget">'.$eol.$padding.$tab.$attribute->getFrontendHtml().$padding.'</div>'.$eol;
1313
- }
1314
- }
1315
- return $content;
1316
- }
1317
- /**
1318
- * get the system attributes
1319
- * @access public
1320
- * @return string
1321
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1322
- */
1323
- public function getSystemAttributes(){
1324
- $position = 10;
1325
- $content = '';
1326
- $tab = $this->getPadding();
1327
- $eol = $this->getEol();
1328
- $padding = str_repeat($tab, 6);
1329
- if ($this->getCreateFrontend()) {
1330
- $content .= $padding.'<breadcrumbs translate="label">'.$eol;
1331
- $content .= $padding.$tab.'<label>Use Breadcrumbs</label>'.$eol;
1332
- $content .= $padding.$tab.'<frontend_type>select</frontend_type>'.$eol;
1333
- $content .= $padding.$tab.'<source_model>adminhtml/system_config_source_yesno</source_model>'.$eol;
1334
- $content .= $padding.$tab.'<sort_order>'.$position.'</sort_order>'.$eol;
1335
- $content .= $padding.$tab.'<show_in_default>1</show_in_default>'.$eol;
1336
- $content .= $padding.$tab.'<show_in_website>1</show_in_website>'.$eol;
1337
- $content .= $padding.$tab.'<show_in_store>1</show_in_store>'.$eol;
1338
- $content .= $padding.'</breadcrumbs>'.$eol;
1339
- $position += 10;
1340
- }
1341
- if ($this->getUrlRewrite()){
1342
- $content .= $padding.'<url_rewrite_list translate="label comment">'.$eol;
1343
- $content .= $padding.$tab.'<label>URL key for list page</label>'.$eol;
1344
- $content .= $padding.$tab.'<frontend_type>text</frontend_type>'.$eol;
1345
- $content .= $padding.$tab.'<sort_order>'.$position.'</sort_order>'.$eol;
1346
- $content .= $padding.$tab.'<show_in_default>1</show_in_default>'.$eol;
1347
- $content .= $padding.$tab.'<show_in_website>1</show_in_website>'.$eol;
1348
- $content .= $padding.$tab.'<show_in_store>1</show_in_store>'.$eol;
1349
- $content .= $padding.$tab.'<comment>Leave empty to use default URL module/controller/action</comment>'.$eol;
1350
- $content .= $padding.'</url_rewrite_list>'.$eol;
1351
- $position += 10;
1352
-
1353
-
1354
- $content .= $padding.'<url_prefix translate="label comment">'.$eol;
1355
- $content .= $padding.$tab.'<label>URL prefix</label>'.$eol;
1356
- $content .= $padding.$tab.'<frontend_type>text</frontend_type>'.$eol;
1357
- $content .= $padding.$tab.'<sort_order>'.$position.'</sort_order>'.$eol;
1358
- $content .= $padding.$tab.'<show_in_default>1</show_in_default>'.$eol;
1359
- $content .= $padding.$tab.'<show_in_website>1</show_in_website>'.$eol;
1360
- $content .= $padding.$tab.'<show_in_store>1</show_in_store>'.$eol;
1361
- $content .= $padding.$tab.'<comment>Leave empty for no prefix</comment>'.$eol;
1362
- $content .= $padding.'</url_prefix>'.$eol;
1363
- $position += 10;
1364
-
1365
- $content .= $padding.'<url_suffix translate="label comment">'.$eol;
1366
- $content .= $padding.$tab.'<label>Url suffix</label>'.$eol;
1367
- $content .= $padding.$tab.'<frontend_type>text</frontend_type>'.$eol;
1368
- $content .= $padding.$tab.'<sort_order>'.$position.'</sort_order>'.$eol;
1369
- $content .= $padding.$tab.'<show_in_default>1</show_in_default>'.$eol;
1370
- $content .= $padding.$tab.'<show_in_website>1</show_in_website>'.$eol;
1371
- $content .= $padding.$tab.'<show_in_store>1</show_in_store>'.$eol;
1372
- $content .= $padding.$tab.'<comment>What goes after the dot. Leave empty for no suffix.</comment>'.$eol;
1373
- $content .= $padding.'</url_suffix>'.$eol;
1374
- $position += 10;
1375
- }
1376
- if ($this->getAllowComment()) {
1377
- $content .= $padding.'<allow_comment translate="label">'.$eol;
1378
- $content .= $padding.$tab.'<label>Allow comments</label>'.$eol;
1379
- $content .= $padding.$tab.'<frontend_type>select</frontend_type>'.$eol;
1380
- $content .= $padding.$tab.'<source_model>adminhtml/system_config_source_yesno</source_model>'.$eol;
1381
- $content .= $padding.$tab.'<sort_order>'.$position.'</sort_order>'.$eol;
1382
- $content .= $padding.$tab.'<show_in_default>1</show_in_default>'.$eol;
1383
- $content .= $padding.$tab.'<show_in_website>1</show_in_website>'.$eol;
1384
- $content .= $padding.$tab.'<show_in_store>1</show_in_store>'.$eol;
1385
- $content .= $padding.'</allow_comment>'.$eol;
1386
- $position += 10;
1387
-
1388
- $content .= $padding.'<allow_guest_comment translate="label">'.$eol;
1389
- $content .= $padding.$tab.'<label>Allow guest comments</label>'.$eol;
1390
- $content .= $padding.$tab.'<frontend_type>select</frontend_type>'.$eol;
1391
- $content .= $padding.$tab.'<source_model>adminhtml/system_config_source_yesno</source_model>'.$eol;
1392
- $content .= $padding.$tab.'<sort_order>'.$position.'</sort_order>'.$eol;
1393
- $content .= $padding.$tab.'<show_in_default>1</show_in_default>'.$eol;
1394
- $content .= $padding.$tab.'<show_in_website>1</show_in_website>'.$eol;
1395
- $content .= $padding.$tab.'<show_in_store>1</show_in_store>'.$eol;
1396
- $content .= $padding.$tab.'<depends>'.$eol;
1397
- $content .= $padding.$tab.$tab.'<allow_comment>1</allow_comment>'.$eol;
1398
- $content .= $padding.$tab.'</depends>'.$eol;
1399
- $content .= $padding.'</allow_guest_comment>'.$eol;
1400
- $position += 10;
1401
- }
1402
- if ($this->getRss()){
1403
- $content .= $padding.'<rss translate="label">'.$eol;
1404
- $content .= $padding.$tab.'<label>Enable rss</label>'.$eol;
1405
- $content .= $padding.$tab.'<frontend_type>select</frontend_type>'.$eol;
1406
- $content .= $padding.$tab.'<source_model>adminhtml/system_config_source_yesno</source_model>'.$eol;
1407
- $content .= $padding.$tab.'<sort_order>'.$position.'</sort_order>'.$eol;
1408
- $content .= $padding.$tab.'<show_in_default>1</show_in_default>'.$eol;
1409
- $content .= $padding.$tab.'<show_in_website>1</show_in_website>'.$eol;
1410
- $content .= $padding.$tab.'<show_in_store>1</show_in_store>'.$eol;
1411
- $content .= $padding.'</rss>'.$eol;
1412
- $position += 10;
1413
- }
1414
- if ($this->getIsTree() && $this->getCreateList()){
1415
- $content .= $padding.'<tree translate="label">'.$eol;
1416
- $content .= $padding.$tab.'<label>Display as tree</label>'.$eol;
1417
- $content .= $padding.$tab.'<frontend_type>select</frontend_type>'.$eol;
1418
- $content .= $padding.$tab.'<source_model>adminhtml/system_config_source_yesno</source_model>'.$eol;
1419
- $content .= $padding.$tab.'<sort_order>'.$position.'</sort_order>'.$eol;
1420
- $content .= $padding.$tab.'<show_in_default>1</show_in_default>'.$eol;
1421
- $content .= $padding.$tab.'<show_in_website>1</show_in_website>'.$eol;
1422
- $content .= $padding.$tab.'<show_in_store>1</show_in_store>'.$eol;
1423
- $content .= $padding.'</tree>'.$eol;
1424
- $position += 10;
1425
- }
1426
- if ($this->getIsTree() && ($this->getCreateList() || $this->getWidget())){
1427
- $content .= $padding.'<recursion translate="label">'.$eol;
1428
- $content .= $padding.$tab.'<label>Recursion level</label>'.$eol;
1429
- $content .= $padding.$tab.'<frontend_type>text</frontend_type>'.$eol;
1430
- $content .= $padding.$tab.'<sort_order>'.$position.'</sort_order>'.$eol;
1431
- $content .= $padding.$tab.'<show_in_default>1</show_in_default>'.$eol;
1432
- $content .= $padding.$tab.'<show_in_website>1</show_in_website>'.$eol;
1433
- $content .= $padding.$tab.'<show_in_store>1</show_in_store>'.$eol;
1434
- $content .= $padding.'</recursion>'.$eol;
1435
- $position += 10;
1436
- }
1437
-
1438
- if ($this->getAddSeo() && $this->getCreateList()){
1439
- $content .= $padding.'<meta_title translate="label">'.$eol;
1440
- $content .= $padding.$tab.'<label>Meta title for '.strtolower($this->getLabelPlural()).' list page</label>'.$eol;
1441
- $content .= $padding.$tab.'<frontend_type>text</frontend_type>'.$eol;
1442
- $content .= $padding.$tab.'<sort_order>'.$position.'</sort_order>'.$eol;
1443
- $content .= $padding.$tab.'<show_in_default>1</show_in_default>'.$eol;
1444
- $content .= $padding.$tab.'<show_in_website>1</show_in_website>'.$eol;
1445
- $content .= $padding.$tab.'<show_in_store>1</show_in_store>'.$eol;
1446
- $content .= $padding.'</meta_title>'.$eol;
1447
- $position += 10;
1448
-
1449
- $content .= $padding.'<meta_description translate="label">'.$eol;
1450
- $content .= $padding.$tab.'<label>Meta description for '.strtolower($this->getLabelPlural()).' list page</label>'.$eol;
1451
- $content .= $padding.$tab.'<frontend_type>textarea</frontend_type>'.$eol;
1452
- $content .= $padding.$tab.'<sort_order>'.$position.'</sort_order>'.$eol;
1453
- $content .= $padding.$tab.'<show_in_default>1</show_in_default>'.$eol;
1454
- $content .= $padding.$tab.'<show_in_website>1</show_in_website>'.$eol;
1455
- $content .= $padding.$tab.'<show_in_store>1</show_in_store>'.$eol;
1456
- $content .= $padding.'</meta_description>'.$eol;
1457
- $position += 10;
1458
-
1459
- $content .= $padding.'<meta_keywords translate="label">'.$eol;
1460
- $content .= $padding.$tab.'<label>Meta keywords for '.strtolower($this->getLabelPlural()).' list page</label>'.$eol;
1461
- $content .= $padding.$tab.'<frontend_type>textarea</frontend_type>'.$eol;
1462
- $content .= $padding.$tab.'<sort_order>'.$position.'</sort_order>'.$eol;
1463
- $content .= $padding.$tab.'<show_in_default>1</show_in_default>'.$eol;
1464
- $content .= $padding.$tab.'<show_in_website>1</show_in_website>'.$eol;
1465
- $content .= $padding.$tab.'<show_in_store>1</show_in_store>'.$eol;
1466
- $content .= $padding.'</meta_keywords>'.$eol;
1467
- }
1468
- return substr($content,0, strlen($content) - strlen($eol));
1469
- }
1470
- /**
1471
- * get additional api xml
1472
- * @access public
1473
- * @return string
1474
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1475
- */
1476
- public function getApiAdditional(){
1477
- $content = $this->getApiTree();
1478
- $content .= $this->getTypeInstance()->getApiAdditional();
1479
- $content .= $this->getApiRelations();
1480
- return $content;
1481
- }
1482
- /**
1483
- * get additional api xml for tree entities
1484
- * @access public
1485
- * @return string
1486
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1487
- */
1488
- public function getApiTree(){
1489
- $content = '';
1490
- $padding = $this->getPadding();
1491
- $prefix = str_repeat($padding, 5);
1492
- $eol = $this->getEol();
1493
- $extension = $this->getModule()->getExtensionName(true);
1494
- if ($this->getIsTree()){
1495
- $module = $this->getModule()->getLowerModuleName();
1496
- $entity = $this->getNameSingular(true);
1497
- $entityLabel = strtolower($this->getLabelSingular());
1498
- $entitiesLabel = strtolower($this->getLabelPlural());
1499
- $content = $prefix.'<level translate="title" module="'.$extension.'">'.$eol;
1500
- $content .= $prefix.$padding.'<title>Retrieve one level of '.$entitiesLabel.'</title>'.$eol;
1501
- $content .= $prefix.$padding.'<acl>'.$module.'/'.$entity.'/info</acl>'.$eol;
1502
- $content .= $prefix.'</level>'.$eol;
1503
- $content .= $prefix.'<move translate="title" module="'.$extension.'">'.$eol;
1504
- $content .= $prefix.$padding.'<title>Move '.$entityLabel.' in tree</title>'.$eol;
1505
- $content .= $prefix.$padding.'<acl>'.$module.'/'.$entity.'/move</acl>'.$eol;
1506
- $content .= $prefix.'</move>'.$eol;
1507
- }
1508
- return $content;
1509
- }
1510
-
1511
- /**
1512
- * get api relations for a section
1513
- * @access public
1514
- * @param $relatedCode
1515
- * @param $relatedLabel
1516
- * @return string
1517
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1518
- */
1519
- public function getApiRelationsSection($relatedCode, $relatedLabel){
1520
- $eol = $this->getEol();
1521
- $padding = $this->getPadding();
1522
- $prefix = $this->getPadding(5);
1523
- $module = $this->getModule()->getLowerModuleName();
1524
- $entity = $this->getNameSingular(true);
1525
- $entityLabelUc = ucfirst($this->getLabelSingular());
1526
- $entityLabel = strtolower($this->getLabelSingular());
1527
- $extension = $this->getModule()->getExtensionName(true);
1528
- $string = '';
1529
- $string .= $prefix. '<assign'.$relatedCode.' translate="title" module="'.$extension.'">'.$eol;
1530
- $string .= $prefix.$padding. '<title>Assign '.$relatedLabel.' to '.$entityLabelUc.'</title>'.$eol;
1531
- $string .= $prefix.$padding. '<acl>'.$module.'/'.$entity.'/update</acl>'.$eol;
1532
- $string .= $prefix. '</assign'.$relatedCode.'>'.$eol;
1533
-
1534
- $string .= $prefix. '<unassign'.$relatedCode.' translate="title" module="'.$extension.'">'.$eol;
1535
- $string .= $prefix.$padding. '<title>Remove '.$relatedLabel.' from '.$entityLabel.'</title>'.$eol;
1536
- $string .= $prefix.$padding. '<acl>'.$module.'/'.$entity.'/update</acl>'.$eol;
1537
- $string .= $prefix. '</unassign'.$relatedCode.'>'.$eol;
1538
- return $string;
1539
- }
1540
-
1541
- /**
1542
- * get API xml for entity relations
1543
- * @access public
1544
- * @return string
1545
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1546
- */
1547
- public function getApiRelations(){
1548
- $string = '';
1549
- if ($this->getLinkProduct()){
1550
- $string .= $this->getApiRelationsSection('Product', 'product');
1551
- }
1552
- if ($this->getLinkCategory()){
1553
- $string .= $this->getApiRelationsSection('Category', 'category');
1554
- }
1555
- $siblings = $this->getRelatedEntities(Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_SIBLING);
1556
- foreach ($siblings as $sibling){
1557
- $siblingNameUc = ucfirst($sibling->getNameSingular());
1558
- $siblingLabel = strtolower($sibling->getLabelSingular());
1559
- $string .= $this->getApiRelationsSection($siblingNameUc, $siblingLabel);
1560
- }
1561
- $string .= $this->getPadding(4);
1562
- return $string;
1563
- }
1564
-
1565
- /**
1566
- * get API faults for a section
1567
- * @access public
1568
- * @param $relatedCode
1569
- * @param $relatedLabel
1570
- * @param $code
1571
- * @return string
1572
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1573
- */
1574
- public function getApiFaultsSection($relatedCode, $relatedLabel, $code){
1575
- $padding = $this->getPadding();
1576
- $prefix = str_repeat($padding, 5);
1577
- $eol = $this->getEol();
1578
- $string = '';
1579
- $string .= $prefix.'<'.$relatedCode.'_not_exists>'.$eol;
1580
- $string .= $prefix.$padding.'<code>'.$code.'</code>'.$eol;
1581
- $string .= $prefix.$padding.'<message>'.$relatedLabel.' does not exist.</message>'.$eol;
1582
- $string .= $prefix.'</'.$relatedCode.'_not_exists>'.$eol;
1583
-
1584
- return $string;
1585
- }
1586
-
1587
- /**
1588
- * get list of faults for API
1589
- * @access public
1590
- * @return string
1591
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1592
- */
1593
- public function getApiFaults(){
1594
- $string = '';
1595
- $padding = $this->getPadding();
1596
- $prefix = str_repeat($padding, 5);
1597
- $eol = $this->getEol();
1598
- $code = 105;
1599
- $entity = $this->getNameSingular(true);
1600
- $entityLabelUc = ucfirst($this->getLabelSingular());
1601
- if ($this->getIsTree()){
1602
- $string .= $prefix.'<not_moved>'.$eol;
1603
- $string .= $prefix.$padding.'<code>'.$code.'</code>'.$eol;
1604
- $string .= $prefix.$padding.'<message>'.$entityLabelUc.' not moved. Details in error message.</message>'.$eol;
1605
- $string .= $prefix.'</not_moved>'.$eol;
1606
- $code++;
1607
- }
1608
- if ($this->getLinkProduct()){
1609
- $string .= $this->getApiFaultsSection('product', 'Product', $code);
1610
- $code++;
1611
- }
1612
- if ($this->getLinkCategory()){
1613
- $string .= $this->getApiFaultsSection('category', 'Category', $code);
1614
- $code++;
1615
- }
1616
- $siblings = $this->getRelatedEntities(Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_SIBLING);
1617
- foreach ($siblings as $sibling){
1618
- $siblingName = $sibling->getNameSingular(true);
1619
- $siblingLabelUc = ucfirst($sibling->getLabelSingular());
1620
-
1621
- $string .= $this->getApiFaultsSection($entity.'_'.$siblingName, $siblingLabelUc, $code);
1622
- $code++;
1623
- }
1624
- $string .= $this->getTypeInstance()->getApiFaults();
1625
- $string .= str_repeat($padding, 4);
1626
- return $string;
1627
- }
1628
-
1629
- /**
1630
- * get additional api acl
1631
- * @access public
1632
- * @return string
1633
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1634
- */
1635
- public function getAdditionalApiAcl(){
1636
- $content = '';
1637
- $padding = $this->getPadding();
1638
- $prefix = str_repeat($padding, 6);
1639
- $eol = $this->getEol();
1640
- $extension = $this->getModule()->getExtensionName(true);
1641
- if ($this->getIsTree()){
1642
- $content .= $prefix.'<move translate="title" module="'.$extension.'">'.$eol;
1643
- $content .= $prefix.$padding.'<title>Move</title>'.$eol;
1644
- $content .= $prefix.'</move>'.$eol;
1645
- }
1646
- $content .= str_repeat($padding, 5);
1647
- return $content;
1648
- }
1649
- /**
1650
- * get attributes format for wsdl
1651
- * @access public
1652
- * @param bool $wsi
1653
- * @param bool $forAdd
1654
- * @return string
1655
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1656
- */
1657
- public function getWsdlAttributes($wsi = false, $forAdd = false){
1658
- $parents = $this->getRelatedEntities(Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_CHILD);
1659
- $tab = $this->getPadding();
1660
- $padding = str_repeat($tab, 5);
1661
- $eol = $this->getEol();
1662
- $content = '';
1663
- foreach ($parents as $parent){
1664
- /** @var Ultimate_ModuleCreator_Model_Attribute $attr */
1665
- $attr = Mage::getModel('modulecreator/attribute');
1666
- $attr->setCode($parent->getNameSingular().'_id');
1667
- $attr->setLabel($parent->getLabelSingular());
1668
- $attr->setType('int');
1669
- $content .= $padding.$attr->getWsdlFormat($wsi).$eol;
1670
- }
1671
- foreach ($this->getAttributes() as $attribute){
1672
- $content .= $padding.$attribute->getWsdlFormat($wsi).$eol;
1673
- }
1674
- $simulated = $this->getSimulatedAttributes(null, false);
1675
- foreach ($simulated as $attr){
1676
- if (!$forAdd || !$attr->getIgnoreApi()){
1677
- $content .= $padding.$attr->getWsdlFormat($wsi).$eol;
1678
- }
1679
- }
1680
- $content .= $this->getTypeInstance()->getWsdlAttributes($wsi);
1681
- return $content;
1682
- }
1683
- /**
1684
- * get attributes format for wsi
1685
- * @access public
1686
- * @param bool $forAdd
1687
- * @return string
1688
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1689
- */
1690
- public function getWsiAttributes($forAdd = false){
1691
- return $this->getWsdlAttributes(true, $forAdd);
1692
- }
1693
-
1694
- /**
1695
- * get wsdl relation type for a section
1696
- * @param $relatedCode
1697
- * @param $relatedId
1698
- * @param bool $wsi
1699
- * @return string
1700
- */
1701
- public function getWsdlRelationTypesSection($relatedCode, $relatedId, $wsi = false){
1702
- $content = '';
1703
- $tab = $this->getPadding();
1704
- $padding = str_repeat($tab, 3);
1705
- $mainTag = ($wsi) ? 'xsd:complexType':'complexType';
1706
- $subtag = ($wsi) ? 'xsd:sequence' : 'all';
1707
- $element = ($wsi) ? 'xsd:element' : 'element';
1708
- $eol = $this->getEol();
1709
- $module = $this->getModule()->getLowerModuleName();
1710
- $entity = $this->getNameSingular(true);
1711
- $entityUc = ucfirst($this->getNameSingular());
1712
-
1713
- $content .= $padding.'<'.$mainTag .' name="'.$module.$entityUc.'Assign'.$relatedCode.'Entity">'.$eol;
1714
- $content .= $padding.$tab.'<'.$subtag.'>'.$eol;
1715
- $content .= $padding.$tab.'<'.$element.' name="'.$entity.'Id" type="xsd:string"'.((!$wsi)?' minOccurs="1"':'').' />'.$eol;
1716
- $content .= $padding.$tab.'<'.$element.' name="'.$relatedId.'Id" type="xsd:string"'.((!$wsi)?' minOccurs="1"':'').' />'.$eol;
1717
- $content .= $padding.$tab.'<'.$element.' name="position" type="xsd:string"'.((!$wsi)?' minOccurs="0"':'').' />'.$eol;
1718
- $content .= $padding.$tab.'</'.$subtag.'>'.$eol;
1719
- $content .= $padding.'</'.$mainTag.'>'.$eol;
1720
-
1721
- $content .= $padding.'<'.$mainTag .' name="'.$module.$entityUc.'Unassign'.$relatedCode.'Entity">'.$eol;
1722
- $content .= $padding.$tab.'<'.$subtag.'>'.$eol;
1723
- $content .= $padding.$tab.'<'.$element.' name="'.$entity.'Id" type="xsd:string"'.((!$wsi)?' minOccurs="1"':'').' />'.$eol;
1724
- $content .= $padding.$tab.'<'.$element.' name="'.$relatedId.'Id" type="xsd:string"'.((!$wsi)?' minOccurs="1"':'').' />'.$eol;
1725
- $content .= $padding.$tab.'</'.$subtag.'>'.$eol;
1726
- $content .= $padding.'</'.$mainTag.'>'.$eol;
1727
-
1728
- return $content;
1729
- }
1730
-
1731
- /**
1732
- * get entity WSDL relation types
1733
- * @access public
1734
- * @param bool $wsi
1735
- * @return string
1736
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1737
- */
1738
- public function getWsdlRelationTypes($wsi = false){
1739
- $content = '';
1740
- $tab = $this->getPadding();
1741
- $padding = str_repeat($tab, 3);
1742
- $mainTag = ($wsi) ? 'xsd:complexType':'complexType';
1743
- $subtag = ($wsi) ? 'xsd:sequence' : 'all';
1744
- $element = ($wsi) ? 'xsd:element' : 'element';
1745
- $eol = $this->getEol();
1746
- $module = $this->getModule()->getLowerModuleName();
1747
- $entity = $this->getNameSingular(true);
1748
- $entityUc = ucfirst($this->getNameSingular());
1749
- if ($this->getIsTree()){
1750
- $content .= $padding.'<'.$mainTag .' name="'.$module.$entityUc.'MoveEntity">'.$eol;
1751
- $content .= $padding.$tab.'<'.$subtag.'>'.$eol;
1752
- $content .= $padding.$tab.'<'.$element.' name="'.$entity.'_id" type="xsd:string"'.((!$wsi)?' minOccurs="1"':'').' />'.$eol;
1753
- $content .= $padding.$tab.'<'.$element.' name="parent_id" type="xsd:string"'.((!$wsi)?' minOccurs="1"':'').' />'.$eol;
1754
- $content .= $padding.$tab.'<'.$element.' name="after_id" type="xsd:string"'.((!$wsi)?' minOccurs="0"':'').' />'.$eol;
1755
- $content .= $padding.$tab.'</'.$subtag.'>'.$eol;
1756
- $content .= $padding.'</'.$mainTag.'>'.$eol;
1757
- }
1758
- if ($this->getLinkProduct()){
1759
- $content .= $this->getWsdlRelationTypesSection('Product', 'product', $wsi);
1760
- }
1761
- if ($this->getLinkCategory()){
1762
- $content .= $this->getWsdlRelationTypesSection('Category', 'category', $wsi);
1763
- }
1764
- $siblings = $this->getRelatedEntities(Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_SIBLING);
1765
- foreach ($siblings as $sibling){
1766
- $siblingName = $sibling->getNameSingular(true);
1767
- $siblingNameUc = ucfirst($sibling->getNameSingular());
1768
- $content .= $this->getWsdlRelationTypesSection($siblingNameUc, $siblingName, $wsi);
1769
-
1770
- }
1771
- $content .= $tab.$tab;
1772
- return $content;
1773
- }
1774
- /**
1775
- * get entity WSI relation types
1776
- * @access public
1777
- * @return string
1778
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1779
- */
1780
- public function getWsiRelationTypes(){
1781
- return $this->getWsdlRelationTypes(true);
1782
- }
1783
-
1784
- /**
1785
- * get wsdl port type relations for a section
1786
- * @access public
1787
- * @param $relatedLabel
1788
- * @param $relatedText
1789
- * @param $wsi
1790
- * @return string
1791
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1792
- */
1793
- public function getWsdlPortTypeRelationSection($relatedLabel, $relatedText, $wsi){
1794
- $content = '';
1795
- $tab = $this->getPadding();
1796
- $padding = $tab.$tab;
1797
- $eol = $this->getEol();
1798
- $module = $this->getModule()->getLowerModuleName();
1799
- $entityUc = ucfirst($this->getNameSingular());
1800
- $label = strtolower($this->getLabelSingular());
1801
- $tagPrefix = ($wsi) ? 'wsdl:':'';
1802
-
1803
- $content .= $padding.'<'.$tagPrefix.'operation name="'.$module.$entityUc.'Assign'.$relatedLabel.'">'.$eol;
1804
- $content .= $padding.$tab.'<'.$tagPrefix.'documentation>Assign '.$relatedText.' to '.$label.'</'.$tagPrefix.'documentation>'.$eol;
1805
- $content .= $padding.$tab.'<'.$tagPrefix.'input message="typens:'.$module.$entityUc.'Assign'.$relatedLabel.'Request" />'.$eol;
1806
- $content .= $padding.$tab.'<'.$tagPrefix.'output message="typens:'.$module.$entityUc.'Assign'.$relatedLabel.'Response" />'.$eol;
1807
- $content .= $padding.'</'.$tagPrefix.'operation>'.$eol;
1808
- $content .= $padding.'<'.$tagPrefix.'operation name="'.$module.$entityUc.'Unassign'.$relatedLabel.'">'.$eol;
1809
- $content .= $padding.$tab.'<'.$tagPrefix.'documentation>Remove '.$relatedText.' from '.$label.'</'.$tagPrefix.'documentation>'.$eol;
1810
- $content .= $padding.$tab.'<'.$tagPrefix.'input message="typens:'.$module.$entityUc.'Unassign'.$relatedLabel.'Request" />'.$eol;
1811
- $content .= $padding.$tab.'<'.$tagPrefix.'output message="typens:'.$module.$entityUc.'Unassign'.$relatedLabel.'Response" />'.$eol;
1812
- $content .= $padding.'</'.$tagPrefix.'operation>'.$eol;
1813
-
1814
- return $content;
1815
- }
1816
-
1817
- /**
1818
- * get entity WSDL port type for relations
1819
- * @access public
1820
- * @param bool $wsi
1821
- * @return string
1822
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1823
- */
1824
- public function getWsdlPortTypeRelation($wsi = false){
1825
- $content = '';
1826
- $tab = $this->getPadding();
1827
- $padding = $tab.$tab;
1828
- $eol = $this->getEol();
1829
- $module = $this->getModule()->getLowerModuleName();
1830
- $entity = $this->getNameSingular(true);
1831
- $entityUc = ucfirst($entity);
1832
- $label = strtolower($this->getLabelSingular());
1833
-
1834
- $tagPrefix = ($wsi) ? 'wsdl:':'';
1835
-
1836
- if ($this->getIsTree()){
1837
- $content .= $padding.'<'.$tagPrefix.'operation name="'.$module.$entityUc.'Move">'.$eol;
1838
- $content .= $padding.$tab.'<'.$tagPrefix.'documentation>Move '.$label.' in tree</'.$tagPrefix.'documentation>'.$eol;
1839
- $content .= $padding.$tab.'<'.$tagPrefix.'input message="typens:'.$module.$entityUc.'MoveRequest" />'.$eol;
1840
- $content .= $padding.$tab.'<'.$tagPrefix.'output message="typens:'.$module.$entityUc.'MoveResponse" />'.$eol;
1841
- $content .= $padding.'</'.$tagPrefix.'operation>'.$eol;
1842
-
1843
- }
1844
-
1845
- if ($this->getLinkProduct()){
1846
- $content .= $this->getWsdlPortTypeRelationSection('Product', 'product', $wsi);
1847
- }
1848
-
1849
- if ($this->getLinkCategory()){
1850
- $content .= $this->getWsdlPortTypeRelationSection('Category', 'category', $wsi);
1851
- }
1852
- $siblings = $this->getRelatedEntities(Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_SIBLING);
1853
- foreach ($siblings as $sibling){
1854
- $siblingNameUc = ucfirst($sibling->getNameSingular());
1855
- $siblingLabel = strtolower($sibling->getLabelSingular());
1856
-
1857
- $content .= $this->getWsdlPortTypeRelationSection($siblingNameUc, $siblingLabel, $wsi);
1858
-
1859
- }
1860
- $content .= $tab;
1861
- return $content;
1862
- }
1863
- /**
1864
- * get entity WSI port type for relations
1865
- * @access public
1866
- * @return string
1867
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1868
- */
1869
- public function getWsiPortTypeRelation(){
1870
- return $this->getWsdlPortTypeRelation(true);
1871
- }
1872
-
1873
- /**
1874
- * get wsld relation binding for a section
1875
- * @access public
1876
- * @param $sectionName
1877
- * @return string
1878
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1879
- */
1880
- public function getWsdlRelationBindingSection($sectionName){
1881
- $content = '';
1882
- $tab = $this->getPadding();
1883
- $doubleTab = $tab.$tab;
1884
- $padding = $doubleTab;
1885
- $eol = $this->getEol();
1886
- $module = $this->getModule()->getLowerModuleName();
1887
- $entity = $this->getNameSingular(true);
1888
- $entityUc = ucfirst($entity);
1889
-
1890
- $content .= $padding.'<operation name="'.$module.$entityUc.$sectionName.'">'.$eol;
1891
- $content .= $padding.$tab.'<soap:operation soapAction="urn:{{var wsdl.handler}}Action" />'.$eol;
1892
- $content .= $padding.$tab.'<input>'.$eol;
1893
- $content .= $padding.$doubleTab.'<soap:body namespace="urn:{{var wsdl.name}}" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />'.$eol;
1894
- $content .= $padding.$tab.'</input>'.$eol;
1895
- $content .= $padding.$tab.'<output>'.$eol;
1896
- $content .= $padding.$doubleTab.'<soap:body namespace="urn:{{var wsdl.name}}" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />'.$eol;
1897
- $content .= $padding.$tab.'</output>'.$eol;
1898
- $content .= $padding.'</operation>'.$eol;
1899
- return $content;
1900
- }
1901
- /**
1902
- * get WSDL relation binding
1903
- * @access public
1904
- * @return string
1905
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1906
- */
1907
- public function getWsdlRelationBinding(){
1908
- $content = '';
1909
- if ($this->getIsTree()){
1910
- $content .= $this->getWsdlRelationBindingSection('Move');
1911
- }
1912
- if ($this->getLinkProduct()){
1913
- $content .= $this->getWsdlRelationBindingSection('AssignProduct');
1914
- $content .= $this->getWsdlRelationBindingSection('UnassignProduct');
1915
- }
1916
- if ($this->getLinkCategory()){
1917
- $content .= $this->getWsdlRelationBindingSection('AssignCategory');
1918
- $content .= $this->getWsdlRelationBindingSection('UnassignCategory');
1919
- }
1920
-
1921
- $siblings = $this->getRelatedEntities(Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_SIBLING);
1922
- foreach ($siblings as $sibling){
1923
- $siblingName = $sibling->getNameSingular(true);
1924
- $siblingNameUc = ucfirst($siblingName);
1925
- $content .= $this->getWsdlRelationBindingSection('Assign'.$siblingNameUc);
1926
- $content .= $this->getWsdlRelationBindingSection('Unassign'.$siblingNameUc);
1927
- }
1928
- $content .= $this->getPadding();
1929
- return $content;
1930
- }
1931
-
1932
- /**
1933
- * get wsld relation binding for a section
1934
- * @access public
1935
- * @param $sectionName
1936
- * @return string
1937
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1938
- */
1939
- public function getWsiRelationBindingSection($sectionName){
1940
- $content = '';
1941
- $tab = $this->getPadding();
1942
- $doubleTab = $tab.$tab;
1943
- $padding = $doubleTab;
1944
- $eol = $this->getEol();
1945
- $module = $this->getModule()->getLowerModuleName();
1946
- $entity = $this->getNameSingular(true);
1947
- $entityUc = ucfirst($entity);
1948
-
1949
- $content .= $padding.'<wsdl:operation name="'.$module.$entityUc.$sectionName.'">'.$eol;
1950
- $content .= $padding.$tab.'<soap:operation soapAction="" />'.$eol;
1951
- $content .= $padding.$tab.'<wsdl:input>'.$eol;
1952
- $content .= $padding.$doubleTab.'<soap:body use="literal" />'.$eol;
1953
- $content .= $padding.$tab.'</wsdl:input>'.$eol;
1954
- $content .= $padding.$tab.'<wsdl:output>'.$eol;
1955
- $content .= $padding.$doubleTab.'<soap:body use="literal" />'.$eol;
1956
- $content .= $padding.$tab.'</wsdl:output>'.$eol;
1957
- $content .= $padding.'</wsdl:operation>'.$eol;
1958
- return $content;
1959
- }
1960
-
1961
- /**
1962
- * get WSI relation binding
1963
- * @access public
1964
- * @return string
1965
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1966
- */
1967
- public function getWsiRelationBinding(){
1968
- $content = '';
1969
- if ($this->getIsTree()){
1970
- $content .= $this->getWsiRelationBindingSection('Move');
1971
- }
1972
- if ($this->getLinkProduct()){
1973
- $content .= $this->getWsiRelationBindingSection('AssignProduct');
1974
- $content .= $this->getWsiRelationBindingSection('UnassignProduct');
1975
- }
1976
- if ($this->getLinkCategory()){
1977
- $content .= $this->getWsiRelationBindingSection('AssignCategory');
1978
- $content .= $this->getWsiRelationBindingSection('UnassignCategory');
1979
- }
1980
-
1981
- $siblings = $this->getRelatedEntities(Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_SIBLING);
1982
- foreach ($siblings as $sibling){
1983
- $siblingName = $sibling->getNameSingular(true);
1984
- $siblingNameUc = ucfirst($siblingName);
1985
-
1986
- $content .= $this->getWsiRelationBindingSection('Assign'.$siblingNameUc);
1987
- $content .= $this->getWsiRelationBindingSection('Unassign'.$siblingNameUc);
1988
- }
1989
- $content .= $this->getPadding();
1990
- return $content;
1991
- }
1992
-
1993
- /**
1994
- * get wsi relation param types for a section
1995
- * @access public
1996
- * @param $sectionName
1997
- * @param $sectionParam
1998
- * @return string
1999
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2000
- */
2001
- public function getWsiRelationParamTypesSection($sectionName, $sectionParam){
2002
- $content = '';
2003
- $tab = $this->getPadding();
2004
- $padding = $this->getPadding(3);
2005
- $eol = $this->getEol();
2006
- $module = $this->getModule()->getLowerModuleName();
2007
- $entity = $this->getNameSingular(true);
2008
- $entityUc = ucfirst($entity);
2009
- $content .= $padding.'<xsd:element name="'.$module.$entityUc.'Assign'.$sectionName.'RequestParam">'.$eol;
2010
- $content .= $padding.$tab.'<xsd:complexType>'.$eol;
2011
- $content .= $padding.str_repeat($tab, 2).'<xsd:sequence>'.$eol;
2012
- $content .= $padding.str_repeat($tab, 3).'<xsd:element minOccurs="1" maxOccurs="1" name="sessionId" type="xsd:string" />'.$eol;
2013
- $content .= $padding.str_repeat($tab, 3).'<xsd:element minOccurs="1" maxOccurs="1" name="'.$entity.'Id" type="xsd:string" />'.$eol;
2014
- $content .= $padding.str_repeat($tab, 3).'<xsd:element minOccurs="1" maxOccurs="1" name="'.$sectionParam.'Id" type="xsd:string" />'.$eol;
2015
- $content .= $padding.str_repeat($tab, 3).'<xsd:element minOccurs="0" maxOccurs="1" name="position" type="xsd:string" />'.$eol;
2016
- $content .= $padding.str_repeat($tab, 2).'</xsd:sequence>'.$eol;
2017
- $content .= $padding.$tab.'</xsd:complexType>'.$eol;
2018
- $content .= $padding.'</xsd:element>'.$eol;
2019
-
2020
- $content .= $padding.'<xsd:element name="'.$module.$entityUc.'Assign'.$sectionName.'ResponseParam">'.$eol;
2021
- $content .= $padding.$tab.'<xsd:complexType>'.$eol;
2022
- $content .= $padding.str_repeat($tab, 2).'<xsd:sequence>'.$eol;
2023
- $content .= $padding.str_repeat($tab, 3).'<xsd:element minOccurs="1" maxOccurs="1" name="result" type="xsd:boolean" />'.$eol;
2024
- $content .= $padding.str_repeat($tab, 2).'</xsd:sequence>'.$eol;
2025
- $content .= $padding.$tab.'</xsd:complexType>'.$eol;
2026
- $content .= $padding.'</xsd:element>'.$eol;
2027
-
2028
- $content .= $padding.'<xsd:element name="'.$module.$entityUc.'Unassign'.$sectionName.'RequestParam">'.$eol;
2029
- $content .= $padding.$tab.'<xsd:complexType>'.$eol;
2030
- $content .= $padding.str_repeat($tab, 2).'<xsd:sequence>'.$eol;
2031
- $content .= $padding.str_repeat($tab, 3).'<xsd:element minOccurs="1" maxOccurs="1" name="sessionId" type="xsd:string" />'.$eol;
2032
- $content .= $padding.str_repeat($tab, 3).'<xsd:element minOccurs="1" maxOccurs="1" name="'.$entity.'Id" type="xsd:string" />'.$eol;
2033
- $content .= $padding.str_repeat($tab, 3).'<xsd:element minOccurs="1" maxOccurs="1" name="'.$sectionParam.'Id" type="xsd:string" />'.$eol;
2034
- $content .= $padding.str_repeat($tab, 2).'</xsd:sequence>'.$eol;
2035
- $content .= $padding.$tab.'</xsd:complexType>'.$eol;
2036
- $content .= $padding.'</xsd:element>'.$eol;
2037
-
2038
- $content .= $padding.'<xsd:element name="'.$module.$entityUc.'Unassign'.$sectionName.'ResponseParam">'.$eol;
2039
- $content .= $padding.$tab.'<xsd:complexType>'.$eol;
2040
- $content .= $padding.str_repeat($tab, 2).'<xsd:sequence>'.$eol;
2041
- $content .= $padding.str_repeat($tab, 3).'<xsd:element minOccurs="1" maxOccurs="1" name="result" type="xsd:boolean" />'.$eol;
2042
- $content .= $padding.str_repeat($tab, 2).'</xsd:sequence>'.$eol;
2043
- $content .= $padding.$tab.'</xsd:complexType>'.$eol;
2044
- $content .= $padding.'</xsd:element>'.$eol;
2045
-
2046
- return $content;
2047
- }
2048
- /**
2049
- * get entity WSI relation param types
2050
- * @access public
2051
- * @return string
2052
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2053
- */
2054
- public function getWsiRelationParamTypes(){
2055
- $content = '';
2056
- $tab = $this->getPadding();
2057
- $padding = str_repeat($tab, 3);
2058
- $eol = $this->getEol();
2059
- $module = $this->getModule()->getLowerModuleName();
2060
- $entity = $this->getNameSingular(true);
2061
- $entityUc = ucfirst($entity);
2062
-
2063
- if ($this->getIsTree()){
2064
- $content .= $padding.'<xsd:element name="'.$module.$entityUc.'MoveRequestParam">'.$eol;
2065
- $content .= $padding.$tab.'<xsd:complexType>'.$eol;
2066
- $content .= $padding.str_repeat($tab, 2).'<xsd:sequence>'.$eol;
2067
- $content .= $padding.str_repeat($tab, 3).'<xsd:element minOccurs="1" maxOccurs="1" name="session_id" type="xsd:string" />'.$eol;
2068
- $content .= $padding.str_repeat($tab, 3).'<xsd:element minOccurs="1" maxOccurs="1" name="'.$entity.'Id" type="xsd:string" />'.$eol;
2069
- $content .= $padding.str_repeat($tab, 3).'<xsd:element minOccurs="1" maxOccurs="1" name="parentId" type="xsd:string" />'.$eol;
2070
- $content .= $padding.str_repeat($tab, 3).'<xsd:element minOccurs="0" maxOccurs="1" name="afterId" type="xsd:string" />'.$eol;
2071
- $content .= $padding.str_repeat($tab, 2).'</xsd:sequence>'.$eol;
2072
- $content .= $padding.$tab.'</xsd:complexType>'.$eol;
2073
- $content .= $padding.'</xsd:element>'.$eol;
2074
-
2075
- $content .= $padding.'<xsd:element name="'.$module.$entityUc.'AssignProductResponseParam">'.$eol;
2076
- $content .= $padding.$tab.'<xsd:complexType>'.$eol;
2077
- $content .= $padding.str_repeat($tab, 2).'<xsd:sequence>'.$eol;
2078
- $content .= $padding.str_repeat($tab, 3).'<xsd:element minOccurs="1" maxOccurs="1" name="result" type="xsd:boolean" />'.$eol;
2079
- $content .= $padding.str_repeat($tab, 2).'</xsd:sequence>'.$eol;
2080
- $content .= $padding.$tab.'</xsd:complexType>'.$eol;
2081
- $content .= $padding.'</xsd:element>'.$eol;
2082
- }
2083
-
2084
- if ($this->getLinkProduct()){
2085
- $content .= $this->getWsiRelationParamTypesSection('Product', 'product');
2086
- }
2087
-
2088
- if ($this->getLinkCategory()){
2089
- $content .= $this->getWsiRelationParamTypesSection('Category', 'category');
2090
- }
2091
-
2092
- $siblings = $this->getRelatedEntities(Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_SIBLING);
2093
- foreach ($siblings as $sibling){
2094
- $siblingName = $sibling->getNameSingular(true);
2095
- $siblingNameUc = ucfirst($siblingName);
2096
- $content .= $this->getWsiRelationParamTypesSection($siblingNameUc, $siblingName);
2097
- }
2098
- $content .= $tab.$tab;
2099
- return $content;
2100
- }
2101
-
2102
- /**
2103
- * get wsi relation messaged for a section
2104
- * @param $sectionName
2105
- * @return string
2106
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2107
- */
2108
- public function getWsiRelationMessagesSection($sectionName){
2109
- $content = '';
2110
- $padding = $this->getPadding();
2111
- $tab = $padding;
2112
- $eol = $this->getEol();
2113
- $module = $this->getModule()->getLowerModuleName();
2114
- $entity = $this->getNameSingular(true);
2115
- $entityUc = ucfirst($entity);
2116
-
2117
- $content .= $padding.'<wsdl:message name="'.$module.$entityUc.$sectionName.'Request">'.$eol;
2118
- $content .= $padding.$tab.'<wsdl:part name="parameters" element="typens:'.$module.$entityUc.$sectionName.'RequestParam" />'.$eol;
2119
- $content .= $padding.'</wsdl:message>'.$eol;
2120
- $content .= $padding.'<wsdl:message name="'.$module.$entityUc.$sectionName.'Response">'.$eol;
2121
- $content .= $padding.$tab.'<wsdl:part name="parameters" element="typens:'.$module.$entityUc.$sectionName.'ResponseParam" />'.$eol;
2122
- $content .= $padding.'</wsdl:message>'.$eol;
2123
-
2124
- return $content;
2125
- }
2126
-
2127
- /**
2128
- * get entity WSI relation messages
2129
- * @access public
2130
- * @return string
2131
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2132
- */
2133
- public function getWsiRelationMessages(){
2134
- $content = '';
2135
- if ($this->getIsTree()){
2136
- $content .= $this->getWsiRelationMessagesSection('Move');
2137
- }
2138
-
2139
- if ($this->getLinkProduct()){
2140
- $content .= $this->getWsiRelationMessagesSection('AssignProduct');
2141
- $content .= $this->getWsiRelationMessagesSection('UnassignProduct');
2142
- }
2143
-
2144
- if ($this->getLinkCategory()){
2145
- $content .= $this->getWsiRelationMessagesSection('AssignCategory');
2146
- $content .= $this->getWsiRelationMessagesSection('UnassignCategory');
2147
- }
2148
- $siblings = $this->getRelatedEntities(Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_SIBLING);
2149
- foreach ($siblings as $sibling){
2150
- $siblingName = $sibling->getNameSingular(true);
2151
- $siblingNameUc = ucfirst($siblingName);
2152
-
2153
- $content .= $this->getWsiRelationMessagesSection('Assign'.$siblingNameUc);
2154
- $content .= $this->getWsiRelationMessagesSection('Unassign'.$siblingNameUc);
2155
- }
2156
- return $content;
2157
- }
2158
-
2159
- /**
2160
- * get wsdl messages for a section
2161
- * @param $sectionName
2162
- * @param $sectionParam
2163
- * @return string
2164
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2165
- */
2166
- public function getWsdlMessagesSection($sectionName, $sectionParam){
2167
- $content = '';
2168
- $tab = $this->getPadding();
2169
- $padding = $tab.$tab;
2170
- $eol = $this->getEol();
2171
- $module = $this->getModule()->getLowerModuleName();
2172
- $entity = $this->getNameSingular(true);
2173
- $entityUc = ucfirst($entity);
2174
-
2175
- $content .= $padding.'<message name="'.$module.$entityUc.'Assign'.$sectionName.'Request">'.$eol;
2176
- $content .= $padding.$tab.'<part name="sessionId" type="xsd:string" />'.$eol;
2177
- $content .= $padding.$tab.'<part name="'.$entity.'_id" type="xsd:string" />'.$eol;
2178
- $content .= $padding.$tab.'<part name="'.$sectionParam.'_id" type="xsd:string" />'.$eol;
2179
- $content .= $padding.$tab.'<part name="position" type="xsd:string" />'.$eol;
2180
- $content .= $padding.'</message>'.$eol;
2181
- $content .= $padding.'<message name="'.$module.$entityUc.'Assign'.$sectionName.'Response">'.$eol;
2182
- $content .= $padding.$tab.'<part name="result" type="xsd:boolean" />'.$eol;
2183
- $content .= $padding.'</message>'.$eol;
2184
- $content .= $padding.'<message name="'.$module.$entityUc.'Unassign'.$sectionName.'Request">'.$eol;
2185
- $content .= $padding.$tab.'<part name="session_id" type="xsd:string" />'.$eol;
2186
- $content .= $padding.$tab.'<part name="'.$entity.'_id" type="xsd:string" />'.$eol;
2187
- $content .= $padding.$tab.'<part name="'.$sectionParam.'_id" type="xsd:string" />'.$eol;
2188
- $content .= $padding.'</message>'.$eol;
2189
- $content .= $padding.'<message name="'.$module.$entityUc.'Unassign'.$sectionName.'Response">'.$eol;
2190
- $content .= $padding.$tab.'<part name="result" type="xsd:boolean" />'.$eol;
2191
- $content .= $padding.'</message>'.$eol;
2192
-
2193
- return $content;
2194
- }
2195
-
2196
- /**
2197
- * get entity WSDL messages for relations
2198
- * @access public
2199
- * @return string
2200
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2201
- */
2202
- public function getWsdlMessages(){
2203
- $content = '';
2204
- $tab = $this->getPadding();
2205
- $padding = $tab.$tab;
2206
- $eol = $this->getEol();
2207
- $module = $this->getModule()->getLowerModuleName();
2208
- $entity = $this->getNameSingular(true);
2209
- $entityUc = ucfirst($entity);
2210
-
2211
- if ($this->getIsTree()){
2212
- $content .= $padding.'<message name="'.$module.$entityUc.'MoveRequest">'.$eol;
2213
- $content .= $padding.$tab.'<part name="session_id" type="xsd:string" />'.$eol;
2214
- $content .= $padding.$tab.'<part name="'.$entity.'_id" type="xsd:string" />'.$eol;
2215
- $content .= $padding.$tab.'<part name="parent_id" type="xsd:string" />'.$eol;
2216
- $content .= $padding.$tab.'<part name="after_id" type="xsd:string" />'.$eol;
2217
- $content .= $padding.'</message>'.$eol;
2218
-
2219
- $content .= $padding.'<message name="'.$module.$entityUc.'MoveResponse">'.$eol;
2220
- $content .= $padding.$tab.'<part name="id" type="xsd:boolean"/>'.$eol;
2221
- $content .= $padding.'</message>'.$eol;
2222
- }
2223
- if ($this->getLinkProduct()){
2224
- $content .= $this->getWsdlMessagesSection('Product', 'product');
2225
- }
2226
-
2227
- if ($this->getLinkCategory()){
2228
- $content .= $this->getWsdlMessagesSection('Category', 'category');
2229
- }
2230
-
2231
- $siblings = $this->getRelatedEntities(Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_SIBLING);
2232
- foreach ($siblings as $sibling){
2233
- $siblingName = $sibling->getNameSingular(true);
2234
- $siblingNameUc = ucfirst($siblingName);
2235
-
2236
- $content .= $this->getWsdlMessagesSection($siblingNameUc, $siblingName);
2237
- }
2238
- $content .= $tab;
2239
- return $content;
2240
- }
2241
- /**
2242
- * get foreign keys for sql (Ddl)
2243
- * @access public
2244
- * @return string
2245
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2246
- */
2247
- public function getParentEntitiesFksDdl(){
2248
- $padding = $this->getPadding();
2249
- $eol = $this->getEol();
2250
- $parents = $this->getRelatedEntities(Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_CHILD);
2251
- $content = '';
2252
-
2253
- $module = $this->getModule()->getLowerModuleName();
2254
- $namespace = $this->getNamespace(true);
2255
- foreach ($parents as $parent){
2256
- $parentName = $parent->getNameSingular(true);
2257
- $content .= $eol.$padding."->addIndex($"."this->getIdxName('".$namespace.'_'.$module.'/'.$parentName."', array('".$parentName."_id')), array('".$parentName."_id'))";
2258
- }
2259
- return $content;
2260
- }
2261
-
2262
- /**
2263
- * get selected menu path
2264
- * @access public
2265
- * @param string $suffix
2266
- * @return string
2267
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2268
- */
2269
- public function getSelectedMenuPath($suffix = ''){
2270
- $path = $this->getModule()->getMenuParent();
2271
- if (!empty($path)){
2272
- $path .= '/';
2273
- }
2274
- $path .= $this->getModule()->getExtensionName(true).'/';
2275
- $path .= $this->getNameSingular(true);
2276
-
2277
- return $path . $suffix;
2278
- }
2279
-
2280
- /**
2281
- * get attributes content for setup
2282
- * @access public
2283
- * @return string
2284
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2285
- */
2286
- public function getAttributesSetup(){
2287
- return $this->getTypeInstance()->getAttributesSetup();
2288
- }
2289
-
2290
- /**
2291
- * get parent class for the entity resource model
2292
- * @access public
2293
- * @return string
2294
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2295
- */
2296
- public function getResourceModelParent(){
2297
- return $this->getTypeInstance()->getResourceModelParent();
2298
- }
2299
- /**
2300
- * get parent class for the entity resource model
2301
- * @access public
2302
- * @return string
2303
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2304
- */
2305
- public function getResourceCollectionModelParent(){
2306
- return $this->getTypeInstance()->getResourceCollectionModelParent();
2307
- }
2308
- /**
2309
- * get related entities relations table
2310
- * @access public
2311
- * @return string
2312
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2313
- */
2314
- public function getResourceRelationsTables(){
2315
- return $this->getTypeInstance()->getResourceRelationsTables();
2316
- }
2317
- /**
2318
- * get related entities relations table declaration
2319
- * @access public
2320
- * @return string
2321
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2322
- */
2323
- public function getResourceRelationsTablesDeclare(){
2324
- return $this->getTypeInstance()->getResourceRelationsTablesDeclare();
2325
- }
2326
- /**
2327
- * get admin layout content for index page
2328
- * @access public
2329
- * @return string
2330
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2331
- */
2332
- public function getAdminIndexLayoutContent(){
2333
- return $this->getTypeInstance()->getAdminIndexLayoutContent();
2334
- }
2335
-
2336
- /**
2337
- * get the parent model class
2338
- * @access public
2339
- * @return mixed
2340
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2341
- */
2342
- public function getEntityParentModel() {
2343
- return $this->getTypeInstance()->getEntityParentModel();
2344
- }
2345
- /**
2346
- * get entity table alias
2347
- * @access public
2348
- * @return mixed
2349
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2350
- */
2351
- public function getEntityTableAlias() {
2352
- return $this->getTypeInstance()->getEntityTableAlias();
2353
- }
2354
- /**
2355
- * get additional prepare collection
2356
- * @access public
2357
- * @return mixed
2358
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2359
- */
2360
- public function getAdditionalPrepareCollection(){
2361
- return $this->getTypeInstance()->getAdditionalPrepareCollection();
2362
- }
2363
-
2364
- /**
2365
- * additional layout block for left section
2366
- * @access public
2367
- * @return mixed
2368
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2369
- */
2370
- public function getEditLayoutLeft() {
2371
- return $this->getTypeInstance()->getEditLayoutLeft();
2372
- }
2373
- /**
2374
- * additional layout block edit
2375
- * @access public
2376
- * @return mixed
2377
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2378
- */
2379
- public function getEditLayoutAdditional(){
2380
- return $this->getTypeInstance()->getEditLayoutAdditional();
2381
- }
2382
-
2383
- /**
2384
- * get the label for product attribute scope
2385
- * @access public
2386
- * @return string
2387
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2388
- */
2389
- public function getProductAttributeScopeLabel(){
2390
- return $this->_getScopeLabel($this->getProductAttributeScope());
2391
- }
2392
- /**
2393
- * get the label for category attribute scope
2394
- * @access public
2395
- * @return string
2396
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2397
- */
2398
- public function getCategoryAttributeScopeLabel(){
2399
- return $this->_getScopeLabel($this->getCategoryAttributeScope());
2400
- }
2401
-
2402
- /**
2403
- * get scope label for install scripts
2404
- * @param $value
2405
- * @return string
2406
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2407
- */
2408
- protected function _getScopeLabel($value){
2409
- $values = array(
2410
- Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE => 'Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE',
2411
- Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE => 'Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE',
2412
- Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL => 'Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL'
2413
- );
2414
- if (!isset($values[$value])) {
2415
- $value = Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL;
2416
- }
2417
- return $values[$value];
2418
- }
2419
-
2420
- /**
2421
- * check if the entity is used as an attribute
2422
- * @access public
2423
- * @return bool
2424
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2425
- */
2426
- public function getIsAttribute() {
2427
- return $this->getProductAttribute() || $this->getCategoryAttribute();
2428
- }
2429
-
2430
- /**
2431
- * check if source model can be created
2432
- * @access public
2433
- * @return bool
2434
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2435
- */
2436
- public function getCanCreateSourceModel() {
2437
- return $this->getIsAttribute() || $this->getIsParent();
2438
- }
2439
-
2440
- /**
2441
- * check if entity has children
2442
- * @access public
2443
- * @return bool
2444
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2445
- */
2446
- public function getIsParent() {
2447
- $children = $this->getRelatedEntities(Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_PARENT);
2448
- return count($children) > 0;
2449
- }
2450
-
2451
- /**
2452
- * get product attribute group
2453
- * @access public
2454
- * @return string
2455
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2456
- */
2457
- public function getProductAttributeGroupLabel() {
2458
- if ($this->getProductAttributeGroup()) {
2459
- return "'group' => '".$this->getProductAttributeGroup()."',".$this->getEol().$this->getPadding();
2460
- }
2461
- return '';
2462
- }
2463
- /**
2464
- * get category attribute group
2465
- * @access public
2466
- * @return string
2467
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2468
- */
2469
- public function getCategoryAttributeGroupLabel() {
2470
- if ($this->getCategoryAttributeGroup()) {
2471
- return "'group' => '".$this->getCategoryAttributeGroup()."',".$this->getEol().$this->getPadding();
2472
- }
2473
- return '';
2474
- }
2475
-
2476
- /**
2477
- * get param name for before save
2478
- * @access public
2479
- * @return mixed
2480
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2481
- */
2482
- public function getBeforeSaveParam() {
2483
- return $this->getTypeInstance()->getBeforeSaveParam();
2484
- }
2485
-
2486
- /**
2487
- * entity attribute set string
2488
- * @access public
2489
- * @return string
2490
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2491
- */
2492
- public function getEntityAttributeSetId() {
2493
- return $this->getTypeInstance()->getEntityAttributeSetId();
2494
- }
2495
- /**
2496
- * filter method name
2497
- * @access public
2498
- * @return string
2499
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2500
- */
2501
- public function getFilterMethod() {
2502
- return $this->getTypeInstance()->getFilterMethod();
2503
- }
2504
-
2505
- /**
2506
- * convert multiple select fields to strings
2507
- * @access public
2508
- * @return mixed
2509
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2510
- */
2511
- public function getMultipleSelectConvert(){
2512
- return $this->getTypeInstance()->getMultipleSelectConvert();
2513
- }
2514
-
2515
- /**
2516
- * check if the entity helper can be created
2517
- * @access public
2518
- * @return bool
2519
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2520
- */
2521
- public function getCanCreateEntityHelper(){
2522
- if ($this->getIsTree()) {
2523
- return true;
2524
- }
2525
- if ($this->getHasFile()) {
2526
- return true;
2527
- }
2528
- if ($this->getCreateFrontend()) {
2529
- return true;
2530
- }
2531
- return $this->getTypeInstance()->getCanCreateEntityHelper();
2532
- }
2533
-
2534
- /**
2535
- * get additional code for toOptionArray()
2536
- * @access public
2537
- * @return string
2538
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2539
- */
2540
- public function getToOptionAddition(){
2541
- return $this->getTypeInstance()->getToOptionAddition();
2542
- }
2543
-
2544
- /**
2545
- * check if entity should be included in the category menu
2546
- * @access public
2547
- * @return bool
2548
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2549
- */
2550
- public function getShowInCategoryMenu() {
2551
- return $this->getListMenu() == Ultimate_ModuleCreator_Model_Source_Entity_Menu::CATEGORY_MENU;
2552
- }
2553
-
2554
- /**
2555
- * get multiselect methods
2556
- * @access public
2557
- * @return string
2558
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2559
- */
2560
- public function getMultiselectMethods() {
2561
- $content = '';
2562
- $padding = $this->getPadding();
2563
- $tab = $this->getPadding();
2564
- $eol = $this->getEol();
2565
- foreach ($this->getAttributes() as $attribute) {
2566
- $magicCode = $attribute->getMagicMethodCode();
2567
- $code = $attribute->getCode();
2568
- if ($attribute->getTypeInstance() instanceof Ultimate_ModuleCreator_Model_Attribute_Type_Multiselect) {
2569
- $content .= $eol.$padding.'/**'.$eol;
2570
- $content .= $padding.' * get '.$attribute->getLabel().$eol;
2571
- $content .= $padding.' * @access public'.$eol;
2572
- $content .= $padding.' * @return array'.$eol;
2573
- $content .= $padding.' * '.$this->getModule()->getQwertyuiop().$eol;
2574
- $content .= $padding.' */'.$eol;
2575
- $content .= $padding.'public function get'.$magicCode.'() {'.$eol;
2576
- $content .= $padding.$tab.'if (!$this->getData(\''.$code.'\')) {'.$eol;
2577
- $content .= $padding.$tab.$tab.'return explode(\',\',$this->getData(\''.$code.'\'));'.$eol;
2578
- $content .= $padding.$tab.'}'.$eol;
2579
- $content .= $padding.$tab.'return $this->getData(\''.$code.'\');'.$eol;
2580
- $content .= $padding.'}';
2581
- }
2582
- }
2583
- return $content;
2584
- }
2585
-
2586
- /**
2587
- * get html for displaying the name
2588
- * @access public
2589
- * @return string
2590
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2591
- */
2592
- public function getNameHtml() {
2593
- $content = '';
2594
- $lower = $this->getNameSingular(true);
2595
- $ucFirst = ucfirst($lower);
2596
- $name = $this->getNameAttributeMagicCode();
2597
- if ($this->getCreateView()) {
2598
- $content .= '\'<a href="\'.$'.$lower.'->get'.$ucFirst.'Url().\'">\'.$'.$lower.'->get'.$name.'().\'</a>\'';
2599
- }
2600
- else {
2601
- $content .= '\'<a href="#">\'.$'.$lower.'->get'.$name.'().\'</a>\'';
2602
- }
2603
- return $content;
2604
- }
2605
-
2606
- /**
2607
- * check if the entity is not store related
2608
- * @access public
2609
- * @return bool
2610
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2611
- */
2612
- public function getNoStore() {
2613
- return !$this->getStore();
2614
- }
2615
- /**
2616
- * get comment name field filter index
2617
- * @access public
2618
- * @return string
2619
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2620
- */
2621
- public function getCommentFilterIndexPrefix() {
2622
- return $this->getTypeInstance()->getCommentFilterIndexPrefix();
2623
- }
2624
- /**
2625
- * additional API subentities.
2626
- * @access public
2627
- * @return string
2628
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2629
- */
2630
- public function getApiAdditionalSettings() {
2631
- $content = '';
2632
-
2633
- if ($this->getAllowComment()) {
2634
- $padding = $this->getPadding(3);
2635
- $tab = $this->getPadding();
2636
- $module = $this->getModule()->getLowerModuleName();
2637
- $entity = $this->getNameSingular(true);
2638
- $eol = $this->getEol();
2639
- $title = $this->getLabelSingular().' Comments';
2640
- $ns = $this->getNamespace(true);
2641
-
2642
- $content .= $eol;
2643
- $content .= $padding.'<'.$module.'_'.$entity.'_comment translate="title" module="'.$ns.'_'.$module.'">'.$eol;
2644
- $content .= $padding.$tab.'<title>'.$title.'</title>'.$eol;
2645
- $content .= $padding.$tab.'<model>'.$ns.'_'.$module.'/'.$entity.'_comment_api</model>'.$eol;
2646
- $content .= $padding.$tab.'<acl>'.$module.'/'.$entity.'/comment</acl>'.$eol;
2647
- $content .= $padding.$tab.'<methods>'.$eol;
2648
- $content .= $padding.$tab.$tab.'<list translate="title" module="'.$ns.'_'.$module.'">'.$eol;
2649
- $content .= $padding.$tab.$tab.$tab.'<title>Retrieve '.$title.'</title>'.$eol;
2650
- $content .= $padding.$tab.$tab.$tab.'<method>items</method>'.$eol;
2651
- $content .= $padding.$tab.$tab.$tab.'<acl>'.$module.'/'.$entity.'_comment/list</acl>'.$eol;
2652
- $content .= $padding.$tab.$tab.'</list>'.$eol;
2653
- $content .= $padding.$tab.$tab.'<updateStatus translate="title" module="'.$ns.'_'.$module.'">'.$eol;
2654
- $content .= $padding.$tab.$tab.$tab.'<title>Update '.$this->getLabelSingular().' Status</title>'.$eol;
2655
- $content .= $padding.$tab.$tab.$tab.'<method>updateStatus</method>'.$eol;
2656
- $content .= $padding.$tab.$tab.$tab.'<acl>'.$module.'/'.$entity.'_comment/updateStatus</acl>'.$eol;
2657
- $content .= $padding.$tab.$tab.'</updateStatus>'.$eol;
2658
- $content .= $padding.$tab.'</methods>'.$eol;
2659
- $content .= $padding.$tab.'<faults module="'.$ns.'_'.$module.'">'.$eol;
2660
- $content .= $padding.$tab.$tab.'<not_exists>'.$eol;
2661
- $content .= $padding.$tab.$tab.$tab.'<code>101</code>'.$eol;
2662
- $content .= $padding.$tab.$tab.$tab.'<message>Requested comment not found.</message>'.$eol;
2663
- $content .= $padding.$tab.$tab.'</not_exists>'.$eol;
2664
- $content .= $padding.$tab.'</faults>'.$eol;
2665
- $content .= $padding.'</'.$module.'_'.$entity.'_comment>'.$eol;
2666
- }
2667
- $content .= $this->getTypeInstance()->getApiAdditionalSettings();
2668
- return $content;
2669
- }
2670
- /**
2671
- * get subentities acl
2672
- * @access public
2673
- * @return string
2674
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2675
- */
2676
- public function getSubEntitiesAcl(){
2677
- $content = '';
2678
- if ($this->getAllowComment()) {
2679
- $padding = $this->getPadding(5);
2680
- $tab = $this->getPadding();
2681
- $module = $this->getModule()->getLowerModuleName();
2682
- $entity = $this->getNameSingular(true);
2683
- $eol = $this->getEol();
2684
- $title = $this->getLabelSingular().' Comments';
2685
- $content .= $eol;
2686
- $ns = $this->getModule()->getNamespace(true);
2687
-
2688
- $content .= $padding.'<'.$entity.'_comment translate="title" module="'.$ns.'_'.$module.'">'.$eol;
2689
- $content .= $padding.$tab.'<title>'.$title.'</title>'.$eol;
2690
- $content .= $padding.$tab.'<sort_order>'.($this->getPosition() + 3).'</sort_order>'.$eol;
2691
- $content .= $padding.$tab.'<list translate="title" module="'.$ns.'_'.$module.'">'.$eol;
2692
- $content .= $padding.$tab.$tab.'<title>List</title>'.$eol;
2693
- $content .= $padding.$tab.'</list>'.$eol;
2694
- $content .= $padding.$tab.'<updateStatus translate="title" module="'.$ns.'_'.$module.'">'.$eol;
2695
- $content .= $padding.$tab.$tab.'<title>Update Status</title>'.$eol;
2696
- $content .= $padding.$tab.'</updateStatus>'.$eol;
2697
- $content .= $padding.'</'.$entity.'_comment>'.$eol;
2698
- }
2699
- $content .= $this->getTypeInstance()->getSubEntitiesAcl();
2700
- return $content;
2701
- }
2702
- /**
2703
- * get api aliases
2704
- * @access public
2705
- * @return string
2706
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2707
- */
2708
- public function getApiResourcesAlias() {
2709
- $content = '';
2710
- if ($this->getAllowComment()) {
2711
- $padding = $this->getPadding(3);
2712
- $module = $this->getModule()->getLowerModuleName();
2713
- $entity = $this->getNameSingular(true);
2714
- $eol = $this->getEol();
2715
- $content .= $eol;
2716
- $content .= $padding.'<'.$entity.'_comment>'.$module.'_'.$entity.'_comment</'.$entity.'_comment>';
2717
- }
2718
- $content .= $this->getTypeInstance()->getApiResourcesAlias();
2719
- return $content;
2720
- }
2721
- /**
2722
- * get api V2 aliases
2723
- * @access public
2724
- * @return string
2725
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2726
- */
2727
- public function getApiResourcesAliasV2() {
2728
- $content = '';
2729
- if ($this->getAllowComment()) {
2730
- $padding = $this->getPadding(4);
2731
- $module = $this->getModule()->getLowerModuleName();
2732
- $entity = strtolower($this->getNameSingular());
2733
- $eol = $this->getEol();
2734
- $content .= $eol;
2735
- $content .= $padding.'<'.$entity.'_comment>'.$module.ucfirst($entity).'Comment</'.$entity.'_comment>';
2736
- }
2737
- $content .= $this->getTypeInstance()->getApiResourcesAliasV2();
2738
- return $content;
2739
- }
2740
-
2741
- /**
2742
- * get default api attributes
2743
- * @access public
2744
- * @return string
2745
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2746
- */
2747
- public function getDefaultApiAttributes(){
2748
- return $this->getTypeInstance()->getDefaultApiAttributes();
2749
- }
2750
- /**
2751
- * get the module namespace
2752
- * @access public
2753
- * @param bool $lower
2754
- * @return mixed|string
2755
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2756
- */
2757
- public function getNamespace($lower = false){
2758
- return $this->getModule()->getNamespace($lower);
2759
- }
2760
- /**
2761
- * get entity name
2762
- * @access public
2763
- * @param bool $lower
2764
- * @return mixed|string
2765
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2766
- */
2767
- public function getNameSingular($lower = false){
2768
- $name = $this->getData('name_singular');
2769
- if ($lower){
2770
- $name = strtolower($name);
2771
- }
2772
- return $name;
2773
- }
2774
-
2775
- /**
2776
- * get code that filters dates
2777
- * @access public
2778
- * @param int $padding
2779
- * @return string
2780
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2781
- */
2782
- public function getFilterDates($padding = 4) {
2783
- $dateAttributes = array();
2784
- foreach ($this->getAttributes() as $attribute) {
2785
- if ($attribute->getTypeInstance() instanceof Ultimate_ModuleCreator_Model_Attribute_Type_Timestamp) {
2786
- $dateAttributes[] = $attribute->getCode();
2787
- }
2788
- }
2789
- if (count($dateAttributes) == 0) {
2790
- return '';
2791
- }
2792
- return $this->getEol().$this->getPadding($padding).'$data = $this->_filterDates($data, array(\''.implode("' ,'", $dateAttributes).'\'));';
2793
- }
2794
-
2795
- /**
2796
- * get add all attributes to collection
2797
- * @access public
2798
- * @return string
2799
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2800
- */
2801
- public function getAllAttributesToCollection() {
2802
- return $this->getTypeInstance()->getAllAttributesToCollection();
2803
- }
2804
-
2805
- /**
2806
- * get load store id statement
2807
- * @access public
2808
- * @return string
2809
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2810
- */
2811
- public function getLoadStoreId() {
2812
- return $this->getTypeInstance()->getLoadStoreId();
2813
- }
2814
-
2815
- /**
2816
- * get rest resource group
2817
- * @param $padding
2818
- * @return string
2819
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2820
- */
2821
- public function getRestResourceGroup($padding) {
2822
- $content = '';
2823
- $eol = $this->getEol();
2824
- if ($this->getRest()) {
2825
- $ns = $this->getNamespace(true);
2826
- $md = $this->getModule()->getLowerModuleName();
2827
- $entity = $this->getNameSingular(true);
2828
- $content .= $this->getPadding($padding).'<'.$ns.'_'.$md.'_'.$entity.' translate="title" module="'.$ns.'_'.$md.'">'.$eol;
2829
- $content .= $this->getPadding($padding + 1).'<title>'.$this->getLabelSingular().'</title>'.$eol;
2830
- $content .= $this->getPadding($padding + 1).'<sort_order>'.$this->getPosition().'</sort_order>'.$eol;
2831
- $content .= $this->getPadding($padding).'</'.$ns.'_'.$md.'_'.$entity.'>'.$eol;
2832
- }
2833
- return $content;
2834
- }
2835
-
2836
- /**
2837
- * get rest resource
2838
- * @param $padding
2839
- * @return string
2840
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2841
- */
2842
- public function getRestResource($padding) {
2843
- $content = '';
2844
- $eol = $this->getEol();
2845
- if ($this->getRest()) {
2846
- $ns = $this->getNamespace(true);
2847
- $md = $this->getModule()->getLowerModuleName();
2848
- $entity = $this->getNameSingular(true);
2849
- $content .= $this->getPadding($padding).'<'.$ns.'_'.$md.'_'.$entity.' translate="title" module="'.$ns.'_'.$md.'">'.$eol;
2850
- $content .= $this->getPadding($padding + 1).'<group>'.$ns.'_'.$md.'_'.$entity.'</group>'.$eol;
2851
- $content .= $this->getPadding($padding + 1).'<model>'.$ns.'_'.$md.'/api2_'.$entity.'</model>'.$eol;
2852
- $content .= $this->getPadding($padding + 1).'<working_model>'.$ns.'_'.$md.'/'.$entity.'</working_model>'.$eol;
2853
- $content .= $this->getPadding($padding + 1).'<title>'.$this->getLabelSingular().'</title>'.$eol;
2854
- $content .= $this->getPadding($padding + 1).'<sort_order>'.$this->getPosition().'</sort_order>'.$eol;
2855
- $content .= $this->getPadding($padding + 1).'<privileges>'.$eol;
2856
- $content .= $this->getPadding($padding + 2).'<admin>'.$eol;
2857
- $content .= $this->getPadding($padding + 3).'<create>1</create>'.$eol;
2858
- $content .= $this->getPadding($padding + 3).'<retrieve>1</retrieve>'.$eol;
2859
- $content .= $this->getPadding($padding + 3).'<update>1</update>'.$eol;
2860
- $content .= $this->getPadding($padding + 3).'<delete>1</delete>'.$eol;
2861
- $content .= $this->getPadding($padding + 2).'</admin>'.$eol;
2862
- $content .= $this->getPadding($padding + 2).'<customer>'.$eol;
2863
- $content .= $this->getPadding($padding + 3).'<retrieve>1</retrieve>'.$eol;
2864
- $content .= $this->getPadding($padding + 2).'</customer>'.$eol;
2865
- $content .= $this->getPadding($padding + 2).'<guest>'.$eol;
2866
- $content .= $this->getPadding($padding + 3).'<retrieve>1</retrieve>'.$eol;
2867
- $content .= $this->getPadding($padding + 2).'</guest>'.$eol;
2868
- $content .= $this->getPadding($padding + 1).'</privileges>'.$eol;
2869
- $content .= $this->getPadding($padding + 1).'<attributes translate="'.$this->getRestAttributes(true, true).'" module="'.$ns.'_'.$md.'">'.$eol;
2870
- foreach ($this->getRestAttributes(false, false) as $code=>$label) {
2871
- $content .= $this->getPadding($padding + 2).'<'.$code.'>'.$label.'</'.$code.'>'.$eol;
2872
- }
2873
- $content .= $this->getPadding($padding + 1).'</attributes>'.$eol;
2874
- $content .= $this->getPadding($padding + 1).'<routes>'.$eol;
2875
- $content .= $this->getPadding($padding + 2).'<route_entity>'.$eol;
2876
- $content .= $this->getPadding($padding + 3).'<route>/'.$md.'_'.$this->getNamePlural(true).'/:id</route>'.$eol;
2877
- $content .= $this->getPadding($padding + 3).'<action_type>entity</action_type>'.$eol;
2878
- $content .= $this->getPadding($padding + 2).'</route_entity>'.$eol;
2879
- if ($this->getIsEav() || $this->getStore()) {
2880
- $content .= $this->getPadding($padding + 2).'<route_entity_with_store>'.$eol;
2881
- $content .= $this->getPadding($padding + 3).'<route>/'.$md.'_'.$this->getNamePlural(true).'/:id/store/:store</route>'.$eol;
2882
- $content .= $this->getPadding($padding + 3).'<action_type>entity</action_type>'.$eol;
2883
- $content .= $this->getPadding($padding + 2).'</route_entity_with_store>'.$eol;
2884
- }
2885
- $content .= $this->getPadding($padding + 2).'<route_collection>'.$eol;
2886
- $content .= $this->getPadding($padding + 3).'<route>/'.$md.'_'.$this->getNamePlural(true).'</route>'.$eol;
2887
- $content .= $this->getPadding($padding + 3).'<action_type>collection</action_type>'.$eol;
2888
- $content .= $this->getPadding($padding + 2).'</route_collection>'.$eol;
2889
- if ($this->getIsEav() || $this->getStore()) {
2890
- $content .= $this->getPadding($padding + 2).'<route_collection_with_store>'.$eol;
2891
- $content .= $this->getPadding($padding + 3).'<route>/'.$md.'_'.$this->getNamePlural(true).'/store/:store</route>'.$eol;
2892
- $content .= $this->getPadding($padding + 3).'<action_type>collection</action_type>'.$eol;
2893
- $content .= $this->getPadding($padding + 2).'</route_collection_with_store>'.$eol;
2894
- }
2895
- $content .= $this->getPadding($padding + 1).'</routes>'.$eol;
2896
- $content .= $this->getPadding($padding + 1).'<versions>1</versions>'.$eol;
2897
- $content .= $this->getPadding($padding).'</'.$ns.'_'.$md.'_'.$entity.'>'.$eol;
2898
- }
2899
- return $content;
2900
- }
2901
-
2902
- /**
2903
- * get rest attributes
2904
- * @param bool $codeOnly
2905
- * @param bool $asString
2906
- * @return array|string
2907
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2908
- */
2909
- public function getRestAttributes($codeOnly = false, $asString = false) {
2910
- $attributes = array(
2911
- 'entity_id' => 'Id',
2912
- );
2913
- foreach ($this->getAttributes() as $attribute) {
2914
- $attributes[$attribute->getCode()] = $attribute->getLabel();
2915
- }
2916
- foreach ($this->getSimulatedAttributes() as $attribute) {
2917
- $attributes[$attribute->getCode()] = $attribute->getLabel();
2918
- }
2919
- if ($codeOnly) {
2920
- if ($asString) {
2921
- return implode(' ', array_keys($attributes));
2922
- }
2923
- return array_keys($attributes);
2924
- }
2925
- return $attributes;
2926
- }
2927
-
2928
- /**
2929
- * @access public
2930
- * @return string
2931
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2932
- */
2933
- public function getRestCollectionCleanup() {
2934
- return $this->getTypeInstance()->getRestCollectionCleanup();
2935
- }
2936
- /**
2937
- * @access public
2938
- * @return string
2939
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2940
- */
2941
- public function getRestCollectionStoreId() {
2942
- return $this->getTypeInstance()->getRestCollectionStoreId();
2943
- }
2944
-
2945
- /**
2946
- * @access public
2947
- * @return string
2948
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2949
- */
2950
- public function getDefaultAttributeValues(){
2951
- return $this->getTypeInstance()->getDefaultAttributeValues();
2952
- }
2953
-
2954
- /**
2955
- * check if entity has parent entities
2956
- * @access public
2957
- * @return bool
2958
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2959
- */
2960
- public function getHasParentRelation() {
2961
- return count($this->getRelatedEntities(Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_CHILD)) > 0;
2962
- }
2963
- /**
2964
- * get additional to option array select
2965
- * @access public
2966
- * @return string
2967
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2968
- */
2969
- public function getToOptionArraySelect() {
2970
- return $this->getTypeInstance()->getToOptionArraySelect();
2971
- }
2972
-
2973
- /**
2974
- * get parent grid column static params
2975
- * @access public
2976
- * @return string
2977
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2978
- */
2979
- public function getParentStaticParams() {
2980
- if ($this->getNotIsTree()) {
2981
- return '';
2982
- }
2983
- $eol = $this->getEol();
2984
- $padding = $this->getPadding(3);
2985
- $tab = $this->getPadding();
2986
- $content = $eol;
2987
- $content .= $padding."'static' => array(".$eol;
2988
- $content .= $padding.$tab."'clear' => 1".$eol;
2989
- $content .= $padding."),";
2990
- return $content;
2991
- }
2992
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
+ */
18
+ /**
19
+ * entity model
20
+ *
21
+ * @category Ultimate
22
+ * @package Ultimate_ModuleCreator
23
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
+ */
25
+ /**
26
+ * @method Ultimate_ModuleCreator_Model_Entity setIndex()
27
+ * @method Ultimate_ModuleCreator_Model_Entity setEditor()
28
+ * @method Ultimate_ModuleCreator_Model_Entity setHasImage()
29
+ * @method Ultimate_ModuleCreator_Model_Entity setHasFile()
30
+ * @method Ultimate_ModuleCreator_Model_Entity setHasCountry()
31
+ * @method Ultimate_ModuleCreator_Model_Entity setHasMultipleSelect()
32
+ * @method bool getCreateFrontend()
33
+ * @method bool getLinkProduct()
34
+ * @method bool getLinkCategory()
35
+ * @method bool getIsTree()
36
+ * @method string getType()
37
+ * @method string getLabelSingular()
38
+ * @method string getLabelPlural()
39
+ * @method string getProductAttributeCode()
40
+ * @method string getCategoryAttributeCode()
41
+ * @method int getPosition()
42
+ * @method string getUrlRewriteList()
43
+ * @method bool getAllowComment()
44
+ * @method bool getStore()
45
+ * @method bool getShowCategory()
46
+ * @method int getProductAttributeScope()
47
+ * @method int getCategoryAttributeScope()
48
+ * @method bool getProductAttribute();
49
+ * @method bool getCategoryAttribute()
50
+ * @method string getProductAttributeGroup()
51
+ * @method string getCategoryAttributeGroup()
52
+ * @method int getListMenu()
53
+ * @method bool getRest()
54
+ * @method Ultimate_ModuleCreator_Model_Entity setPosition()
55
+ * @method Ultimate_ModuleCreator_Model_Entity setRss()
56
+ * @method bool getEditor()
57
+ * @method bool getApi()
58
+ * @method bool getHasCountry()
59
+ * @method bool getSearch()
60
+ * @method int getIndex()
61
+ */
62
+ class Ultimate_ModuleCreator_Model_Entity extends Ultimate_ModuleCreator_Model_Abstract
63
+ {
64
+ /**
65
+ * reference to type instance
66
+ *
67
+ * @var null|Ultimate_ModuleCreator_Model_Entity_Type_Abstract
68
+ */
69
+ protected $_typeInstance = null;
70
+
71
+ /**
72
+ * entity code
73
+ *
74
+ * @var string
75
+ */
76
+ protected $_entityCode = 'umc_entity';
77
+
78
+ /**
79
+ * entity attributes
80
+ *
81
+ * @var array
82
+ */
83
+ protected $_attributes = array();
84
+
85
+ /**
86
+ * entity module
87
+ *
88
+ * @var Ultimate_ModuleCreator_Model_Module
89
+ */
90
+ protected $_module = null;
91
+
92
+ /**
93
+ * attribute that behaves as name
94
+ *
95
+ * @var Ultimate_ModuleCreator_Model_Attribute
96
+ */
97
+ protected $_nameAttribute = null;
98
+
99
+ /**
100
+ * remember if attributes were prepared
101
+ *
102
+ * @var bool
103
+ */
104
+ protected $_preparedAttributes = null;
105
+
106
+ /**
107
+ * related entities
108
+ *
109
+ * @var array()
110
+ */
111
+ protected $_relatedEntities = array();
112
+
113
+ /**
114
+ * placeholders for replacing in source files
115
+ *
116
+ * @var mixed
117
+ */
118
+ protected $_placeholders = null;
119
+
120
+ /**
121
+ * placeholders for sibling entities
122
+ *
123
+ * @var mixed
124
+ */
125
+ protected $_placeholdersAsSibling = null;
126
+
127
+ /**
128
+ * set the entity module
129
+ *
130
+ * @access public
131
+ * @param Ultimate_ModuleCreator_Model_Module $module
132
+ * @return Ultimate_ModuleCreator_Model_Entity
133
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
134
+ */
135
+ public function setModule(Ultimate_ModuleCreator_Model_Module $module)
136
+ {
137
+ $this->_module = $module;
138
+ return $this;
139
+ }
140
+
141
+ /**
142
+ * get the entity module
143
+ *
144
+ * @access public
145
+ * @return Ultimate_ModuleCreator_Model_Module
146
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
147
+ */
148
+ public function getModule()
149
+ {
150
+ return $this->_module;
151
+ }
152
+
153
+ /**
154
+ * add new attribute
155
+ *
156
+ * @access public
157
+ * @param Ultimate_ModuleCreator_Model_Attribute $attribute
158
+ * @return Ultimate_ModuleCreator_Model_Entity
159
+ * @throws Ultimate_ModuleCreator_Exception
160
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
161
+ */
162
+ public function addAttribute(Ultimate_ModuleCreator_Model_Attribute $attribute)
163
+ {
164
+ Mage::dispatchEvent(
165
+ 'umc_entity_add_attribute_before',
166
+ array('attribute'=>$attribute, 'entity'=>$this)
167
+ );
168
+ $attribute->setEntity($this);
169
+ if (isset($this->_attributes[$attribute->getCode()])) {
170
+ throw new Ultimate_ModuleCreator_Exception(
171
+ Mage::helper('modulecreator')->__(
172
+ 'An attribute with the code "%s" already exists for entity "%s"',
173
+ $attribute->getCode(),
174
+ $this->getNameSingular()
175
+ )
176
+ );
177
+ }
178
+ $this->_preparedAttributes = false;
179
+ $this->_attributes[$attribute->getCode()] = $attribute;
180
+ if ($attribute->getIsName()) {
181
+ if (!$attribute->getIsAllowedAsName()) {
182
+ /** @var Ultimate_ModuleCreator_Helper_Data $helper */
183
+ $helper = Mage::helper('modulecreator');
184
+ $attributeTypes = $helper->getNameAttributeTypes(true);
185
+ throw new Ultimate_ModuleCreator_Exception(
186
+ Mage::helper('modulecreator')->__(
187
+ 'An attribute that acts as name must have one of the types "%s".',
188
+ implode(', ', $attributeTypes)
189
+ )
190
+ );
191
+ }
192
+ $attribute->setUserDefined(false);
193
+ $this->_nameAttribute = $attribute;
194
+ }
195
+ if ($attribute->getEditor()) {
196
+ $this->setEditor(true);
197
+ }
198
+ if ($attribute->getType() == 'image') {
199
+ $this->setHasImage(true);
200
+ }
201
+ if ($attribute->getType() == 'file') {
202
+ $this->setHasFile(true);
203
+ }
204
+ if ($attribute->getType() == 'country') {
205
+ $this->setHasCountry(true);
206
+ }
207
+ if ($attribute->getIsMultipleSelect()) {
208
+ $this->setHasMultipleSelect(true);
209
+ }
210
+ Mage::dispatchEvent(
211
+ 'umc_entity_add_attribute_after',
212
+ array('attribute'=>$attribute, 'entity'=>$this)
213
+ );
214
+ return $this;
215
+ }
216
+
217
+ /**
218
+ * prepare attributes
219
+ *
220
+ * @access protected
221
+ * @return Ultimate_ModuleCreator_Model_Entity
222
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
223
+ */
224
+ protected function _prepareAttributes()
225
+ {
226
+ if ($this->_preparedAttributes) {
227
+ return $this;
228
+ }
229
+ $attributesByPosition = array();
230
+ foreach ($this->_attributes as $attribute) {
231
+ /** @var Ultimate_ModuleCreator_Model_Attribute $attribute */
232
+ $attributesByPosition[$attribute->getPosition()][] = $attribute;
233
+ }
234
+ ksort($attributesByPosition);
235
+ $attributes = array();
236
+ foreach ($attributesByPosition as $attributeList) {
237
+ foreach ($attributeList as $attribute) {
238
+ $attributes[$attribute->getCode()] = $attribute;
239
+ }
240
+ }
241
+ $this->_attributes = $attributes;
242
+ Mage::dispatchEvent('umc_entity_prepare_attributes', array('entity'=>$this));
243
+ $this->_preparedAttributes = true;
244
+ return $this;
245
+ }
246
+
247
+ /**
248
+ * ge the entity attributes
249
+ *
250
+ * @access public
251
+ * @return Ultimate_ModuleCreator_Model_Attribute[]
252
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
253
+ */
254
+ public function getAttributes()
255
+ {
256
+ if (!$this->_preparedAttributes) {
257
+ $this->_prepareAttributes();
258
+ }
259
+ return $this->_attributes;
260
+ }
261
+
262
+ /**
263
+ * entity to xml
264
+ *
265
+ * @access public
266
+ * @param array $arrAttributes
267
+ * @param string $rootName
268
+ * @param bool $addOpenTag
269
+ * @param bool $addCdata
270
+ * @return string
271
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
272
+ */
273
+ public function toXml(array $arrAttributes = array(), $rootName = 'entity', $addOpenTag=false, $addCdata=false)
274
+ {
275
+ $xml = '';
276
+ if ($addOpenTag) {
277
+ $xml.= '<?xml version="1.0" encoding="UTF-8"?>'.$this->getEol();
278
+ }
279
+ if (!empty($rootName)) {
280
+ $xml.= '<'.$rootName.'>'.$this->getEol();
281
+ }
282
+ $xml .= parent::toXml($this->getXmlAttributes(), '', false, $addCdata);
283
+ $xml .= '<attributes>'.$this->getEol();
284
+ foreach ($this->getAttributes() as $attribute) {
285
+ $xml .= $attribute->toXml(array(), 'attribute', false, $addCdata);
286
+ }
287
+ $xml .= '</attributes>'.$this->getEol();
288
+ if (!empty($rootName)) {
289
+ $xml.= '</'.$rootName.'>'.$this->getEol();
290
+ }
291
+ return $xml;
292
+ }
293
+
294
+ /**
295
+ * get magic function code for the name attribute
296
+ *
297
+ * @access public
298
+ * @return string
299
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
300
+ */
301
+ public function getNameAttributeMagicCode()
302
+ {
303
+ $nameAttribute = $this->getNameAttribute();
304
+ if ($nameAttribute) {
305
+ $entityNameMagicCode = $nameAttribute->getMagicMethodCode();
306
+ } else {
307
+ $entityNameMagicCode = 'Name';
308
+ }
309
+ return $entityNameMagicCode;
310
+ }
311
+
312
+ /**
313
+ * get the name attribute
314
+ *
315
+ * @access public
316
+ * @return mixed(null|Ultimate_ModuleCreator_Model_Attribute)
317
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
318
+ */
319
+ public function getNameAttribute()
320
+ {
321
+ return $this->_nameAttribute;
322
+ }
323
+
324
+ /**
325
+ * get the attribute code for the name attribute
326
+ *
327
+ * @access public
328
+ * @return string
329
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
330
+ */
331
+ public function getNameAttributeCode()
332
+ {
333
+ return $this->_nameAttribute->getCode();
334
+ }
335
+
336
+ /**
337
+ * get the attribute label for the name attribute
338
+ *
339
+ * @access public
340
+ * @return string
341
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
342
+ */
343
+ public function getNameAttributeLabel()
344
+ {
345
+ return $this->getNameAttribute()->getLabel();
346
+ }
347
+
348
+ /**
349
+ * check if the entity has file attributes
350
+ *
351
+ * @access public
352
+ * @return bool
353
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
354
+ */
355
+ public function getHasFile()
356
+ {
357
+ return $this->getTypeInstance()->getHasFile();
358
+ }
359
+
360
+ /**
361
+ * check if the entity has image attributes
362
+ *
363
+ * @access public
364
+ * @return bool
365
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
366
+ */
367
+ public function getHasImage()
368
+ {
369
+ return $this->getTypeInstance()->getHasImage();
370
+ }
371
+ /**
372
+ * check if the entity has upload attributes
373
+ * @access public
374
+ * @return bool
375
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
376
+ */
377
+ public function getHasUpload()
378
+ {
379
+ return $this->getHasFile() || $this->getHasImage();
380
+ }
381
+
382
+ /**
383
+ * get the first image attribute code
384
+ *
385
+ * @access public
386
+ * @return string
387
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
388
+ */
389
+ public function getFirstImageField()
390
+ {
391
+ foreach ($this->getAttributes() as $attribute) {
392
+ if ($attribute->getType() == 'image') {
393
+ return $attribute->getCode();
394
+ }
395
+ }
396
+ return '';
397
+ }
398
+
399
+ /**
400
+ * get the attribute name for plural
401
+ *
402
+ * @access public
403
+ * @param bool $lower
404
+ * @return string
405
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
406
+ */
407
+ public function getNamePlural($lower = false)
408
+ {
409
+ $plural = $this->getData('name_plural');
410
+ if ($plural == $this->getNameSingular()) {
411
+ if ($plural == "") {
412
+ return "";
413
+ }
414
+ $plural = $this->getNameSingular().'s';
415
+ }
416
+ if ($lower) {
417
+ $plural = strtolower($plural);
418
+ }
419
+ return $plural;
420
+ }
421
+
422
+ /**
423
+ * check if frontend list files must be created
424
+ *
425
+ * @access public
426
+ * @return bool
427
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
428
+ */
429
+ public function getCreateList()
430
+ {
431
+ return $this->getCreateFrontend() && $this->getData('create_list');
432
+ }
433
+
434
+ /**
435
+ * get list template
436
+ *
437
+ * @access public
438
+ * @return string
439
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
440
+ */
441
+ public function getListTemplate()
442
+ {
443
+ if ($this->getCreateList()) {
444
+ return $this->getData('list_template');
445
+ }
446
+ return '';
447
+ }
448
+
449
+ /**
450
+ * check if frontend view files must be created
451
+ *
452
+ * @access public
453
+ * @return bool
454
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
455
+ */
456
+ public function getCreateView()
457
+ {
458
+ return $this->getCreateFrontend() && $this->getData('create_view');
459
+ }
460
+
461
+ /**
462
+ * get list template
463
+ *
464
+ * @access public
465
+ * @return string
466
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
467
+ */
468
+ public function getViewTemplate()
469
+ {
470
+ if ($this->getCreateView()) {
471
+ return $this->getData('view_template');
472
+ }
473
+ return '';
474
+ }
475
+
476
+ /**
477
+ * check if widget list files must be created
478
+ *
479
+ * @access public
480
+ * @return bool
481
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
482
+ */
483
+ public function getWidget()
484
+ {
485
+ return $this->getCreateFrontend() && $this->getData('widget');
486
+ }
487
+
488
+ /**
489
+ * check if SEO attributes should be added
490
+ *
491
+ * @access public
492
+ * @return bool
493
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
494
+ */
495
+ public function getAddSeo()
496
+ {
497
+ return $this->getCreateView() && $this->getData('add_seo');
498
+ }
499
+
500
+ /**
501
+ * check if SEO attributes should be added
502
+ *
503
+ * @access public
504
+ * @return bool
505
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
506
+ */
507
+ public function getRss()
508
+ {
509
+ return $this->getCreateFrontend() && $this->getData('rss');
510
+ }
511
+
512
+ /**
513
+ * check if url rewrite should be added
514
+ *
515
+ * @access public
516
+ * @return bool
517
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
518
+ */
519
+ public function getUrlRewrite()
520
+ {
521
+ return $this->getCreateView() && $this->getData('url_rewrite');
522
+ }
523
+
524
+ /**
525
+ * get url prefix
526
+ *
527
+ * @access public
528
+ * @return string
529
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
530
+ */
531
+ public function getUrlPrefix()
532
+ {
533
+ if ($this->getUrlRewrite()) {
534
+ return $this->getData('url_prefix');
535
+ }
536
+ return '';
537
+ }
538
+
539
+ /**
540
+ * get url suffix
541
+ *
542
+ * @access public
543
+ * @return string
544
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
545
+ */
546
+ public function getUrlSuffix()
547
+ {
548
+ if ($this->getUrlRewrite()) {
549
+ return $this->getData('url_suffix');
550
+ }
551
+ return '';
552
+ }
553
+
554
+ /**
555
+ * check if products are listed in the entity view page
556
+ *
557
+ * @access public
558
+ * @return bool
559
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
560
+ */
561
+ public function getShowProducts()
562
+ {
563
+ return $this->getLinkProduct() &&
564
+ $this->getCreateFrontend() &&
565
+ $this->getData('show_products');
566
+ }
567
+
568
+ /**
569
+ * check if entity list is shown on product page
570
+ *
571
+ * @access public
572
+ * @return bool
573
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
574
+ */
575
+ public function getShowOnProduct()
576
+ {
577
+ return $this->getLinkProduct() && $this->getData('show_on_product');
578
+ }
579
+
580
+ /**
581
+ * check if entity list is shown on category page
582
+ *
583
+ * @access public
584
+ * @return bool
585
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
586
+ */
587
+ public function getShowOnCategory()
588
+ {
589
+ return $this->getLinkCategory() && $this->getData('show_on_category');
590
+ }
591
+
592
+ /**
593
+ * add related entities
594
+ *
595
+ * @access public
596
+ * @param string $type
597
+ * @param Ultimate_ModuleCreator_Model_Entity $entity
598
+ * @return Ultimate_ModuleCreator_Model_Entity
599
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
600
+ */
601
+ public function addRelatedEntity($type, $entity)
602
+ {
603
+ $this->_relatedEntities[$type][] = $entity;
604
+ return $this;
605
+ }
606
+
607
+ /**
608
+ * get the related entities
609
+ *
610
+ * @access public
611
+ * @param mixed $type
612
+ * @return Ultimate_ModuleCreator_Model_Entity[]
613
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
614
+ */
615
+ public function getRelatedEntities($type = null)
616
+ {
617
+ if (is_null($type)) {
618
+ return $this->_relatedEntities;
619
+ }
620
+ if (isset($this->_relatedEntities[$type])) {
621
+ return $this->_relatedEntities[$type];
622
+ }
623
+ return array();
624
+ }
625
+
626
+ /**
627
+ * check if entity does not behave as tree
628
+ *
629
+ * @access public
630
+ * @return bool
631
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
632
+ */
633
+ public function getNotIsTree()
634
+ {
635
+ return !$this->getIsTree();
636
+ }
637
+
638
+ /**
639
+ * check if entity does not have url rewrites
640
+ *
641
+ * @access public
642
+ * @return bool
643
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
644
+ */
645
+ public function getNotUrlRewrite()
646
+ {
647
+ return !$this->getUrlRewrite();
648
+ }
649
+
650
+ /**
651
+ * check if entity is EAV
652
+ *
653
+ * @access public
654
+ * @return bool
655
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
656
+ */
657
+ public function getIsEav()
658
+ {
659
+ return $this->getType() == Ultimate_ModuleCreator_Model_Entity_Type_Abstract::TYPE_EAV;
660
+ }
661
+
662
+ /**
663
+ * check if entity is Flat
664
+ *
665
+ * @access public
666
+ * @return bool
667
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
668
+ */
669
+ public function getIsFlat()
670
+ {
671
+ return $this->getType() == Ultimate_ModuleCreator_Model_Entity_Type_Abstract::TYPE_FLAT;
672
+ }
673
+
674
+ /**
675
+ * get the entity type instance
676
+ *
677
+ * @access public
678
+ * @return Ultimate_ModuleCreator_Model_Entity_Type_Abstract
679
+ * @throws Ultimate_ModuleCreator_Exception
680
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
681
+ */
682
+ public function getTypeInstance()
683
+ {
684
+ if (is_null($this->_typeInstance)) {
685
+ $type = $this->getType();
686
+ /** @var Ultimate_ModuleCreator_Helper_Data $helper */
687
+ $helper = Mage::helper('modulecreator');
688
+ $types = $helper->getEntityTypes(false);
689
+ if (isset($types[$type])) {
690
+ /** @var Ultimate_ModuleCreator_Model_Entity_Type_Abstract $typeInstance */
691
+ $typeInstance = Mage::getModel((string)$types[$type]->type_model);
692
+ $this->_typeInstance = $typeInstance;
693
+ } else {
694
+ throw new Ultimate_ModuleCreator_Exception(
695
+ Mage::helper('modulecreator')->__('Entity "%s" type is not valid', $type)
696
+ );
697
+ }
698
+ $this->_typeInstance->setEntity($this);
699
+ }
700
+ return $this->_typeInstance;
701
+ }
702
+
703
+ /**
704
+ * check if entity has default config settings
705
+ *
706
+ * @access public
707
+ * @return bool
708
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
709
+ */
710
+ public function getHasConfigDefaults()
711
+ {
712
+ return $this->getCreateFrontend();
713
+ }
714
+
715
+ /**
716
+ * check if entity is linked to core entities (product, category)
717
+ *
718
+ * @access public
719
+ * @return bool
720
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
721
+ */
722
+ public function getLinkCore()
723
+ {
724
+ return $this->getLinkProduct() || $this->getLinkCategory();
725
+ }
726
+
727
+ /**
728
+ * get entity placeholders
729
+ *
730
+ * @access public
731
+ * @param null $param
732
+ * @return array|mixed|null|string
733
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
734
+ */
735
+ public function getPlaceholders($param = null)
736
+ {
737
+ if (is_null($this->_placeholders)) {
738
+ $this->_placeholders = array();
739
+ $this->_placeholders['{{entity_default_config}}'] = $this->getDefaultConfig();
740
+ $this->_placeholders['{{entity}}'] = $this->getNameSingular(true);
741
+ $this->_placeholders['{{Entity}}'] = ucfirst($this->getNameSingular(true));
742
+ $this->_placeholders['{{ENTITY}}'] = strtoupper($this->getNameSingular());
743
+ $this->_placeholders['{{EntityLabel}}'] = ucfirst($this->getLabelSingular());
744
+ $this->_placeholders['{{entityLabel}}'] = strtolower($this->getLabelSingular());
745
+ $this->_placeholders['{{EntitiesLabel}}'] = ucfirst($this->getLabelPlural());
746
+ $this->_placeholders['{{entitiesLabel}}'] = strtolower($this->getLabelPlural());
747
+ $this->_placeholders['{{entityCollectionAttributes}}'] = $this->getCollectionAttributes();
748
+ $this->_placeholders['{{entityAdminJoin}}'] = $this->getAdminJoin();
749
+ $this->_placeholders['{{prepareColumnsHeader}}'] = $this->getPrepareColumnsHeader();
750
+ $this->_placeholders['{{nameAttributeGridEav}}'] = $this->getNameAttributeGridEav();
751
+ $this->_placeholders['{{nameAttributeCode}}'] = $this->getNameAttributeCode();
752
+ $this->_placeholders['{{nameAttributeLabel}}'] = $this->getNameAttributeLabel();
753
+ $this->_placeholders['{{entities}}'] = $this->getNamePlural(true);
754
+ $this->_placeholders['{{Entities}}'] = ucfirst($this->getNamePlural(true));
755
+ $this->_placeholders['{{EntityNameMagicCode}}'] = $this->getNameAttributeMagicCode();
756
+ $this->_placeholders['{{attributeDdlSql}}'] = $this->getAttributesDdlSql();
757
+ $this->_placeholders['{{referenceHead}}'] = $this->getReferenceHeadLayout();
758
+ $this->_placeholders['{{EntityViewRelationLayout}}'] = $this->getRelationLayoutXml();
759
+ $this->_placeholders['{{listLayout}}'] = $this->getListTemplate();
760
+ $this->_placeholders['{{viewLayout}}'] = $this->getViewTemplate();
761
+ $this->_placeholders['{{entityHtmlLink}}'] = $this->getHtmlLink();
762
+ $this->_placeholders['{{EntityViewAttributes}}'] = $this->getViewAttributesHtml();
763
+ $this->_placeholders['{{EntityViewWidgetAttributes}}'] = $this->getViewWidgetAttributesHtml();
764
+ $this->_placeholders['{{systemAttributes}}'] = $this->getSystemAttributes();
765
+ $this->_placeholders['{{entityApiAdditional}}'] = $this->getApiAdditional();
766
+ $this->_placeholders['{{entityApiFaults}}'] = $this->getApiFaults();
767
+ $this->_placeholders['{{entityAdditionalApiAcl}}'] = $this->getAdditionalApiAcl();
768
+ $this->_placeholders['{{entityWsdlAttributes}}'] = $this->getWsdlAttributes();
769
+ $this->_placeholders['{{entityWsdlAttributesForAdd}}'] = $this->getWsdlAttributes(false, true);
770
+ $this->_placeholders['{{entityWsdlRelationTypes}}'] = $this->getWsdlRelationTypes();
771
+ $this->_placeholders['{{entityWsdlPortTypeRelation}}'] = $this->getWsdlPortTypeRelation();
772
+ $this->_placeholders['{{entityWsdlRelationBinding}}'] = $this->getWsdlRelationBinding();
773
+ $this->_placeholders['{{entityWsiRelationParamTypes}}'] = $this->getWsiRelationParamTypes();
774
+ $this->_placeholders['{{entityWsiRelationMessages}}'] = $this->getWsiRelationMessages();
775
+ $this->_placeholders['{{entityWsiPortTypeRelation}}'] = $this->getWsiPortTypeRelation();
776
+ $this->_placeholders['{{entityWsiRelationBinding}}'] = $this->getWsiRelationBinding();
777
+ $this->_placeholders['{{entityWsiAttributes}}'] = $this->getWsiAttributes();
778
+ $this->_placeholders['{{entityWsiAttributesForAdd}}'] = $this->getWsiAttributes(true);
779
+ $this->_placeholders['{{entityWsiRelationTypes}}'] = $this->getWsiRelationTypes();
780
+ $this->_placeholders['{{entityWsdlMessages}}'] = $this->getWsdlMessages();
781
+ $this->_placeholders['{{fksDdl}}'] = $this->getParentEntitiesFksDdl();
782
+ $this->_placeholders['{{selectedMenuPath}}'] = $this->getSelectedMenuPath();
783
+ $this->_placeholders['{{entityAttributesSetup}}'] = $this->getAttributesSetup();
784
+ $this->_placeholders['{{ResourceModelParent}}'] = $this->getResourceModelParent();
785
+ $this->_placeholders['{{ResourceCollectionParent}}'] = $this->getResourceCollectionModelParent();
786
+ $this->_placeholders['{{RelationsResourceTables}}'] = $this->getResourceRelationsTables();
787
+ $this->_placeholders['{{RelationsResourceTablesDeclare}}'] = $this->getResourceRelationsTablesDeclare();
788
+ $this->_placeholders['{{adminIndexContent}}'] = $this->getAdminIndexLayoutContent();
789
+ $this->_placeholders['{{EntityParentModel}}'] = $this->getEntityParentModel();
790
+ $this->_placeholders['{{entityTableAlias}}'] = $this->getEntityTableAlias();
791
+ $this->_placeholders['{{additionalPrepareCollection}}'] = $this->getAdditionalPrepareCollection();
792
+ $this->_placeholders['{{entityEditLayoutLeft}}'] = $this->getEditLayoutLeft();
793
+ $this->_placeholders['{{entityLayoutAdditional}}'] = $this->getEditLayoutAdditional();
794
+ $this->_placeholders['{{productAttributeCode}}'] = $this->getProductAttributeCode();
795
+ $this->_placeholders['{{categoryAttributeCode}}'] = $this->getCategoryAttributeCode();
796
+ $this->_placeholders['{{entityProductAttributeScope}}'] = $this->getProductAttributeScopeLabel();
797
+ $this->_placeholders['{{entityCategoryAttributeScope}}']= $this->getCategoryAttributeScopeLabel();
798
+ $this->_placeholders['{{productAttributeGroup}}'] = $this->getProductAttributeGroupLabel();
799
+ $this->_placeholders['{{categoryAttributeGroup}}'] = $this->getCategoryAttributeGroupLabel();
800
+ $this->_placeholders['{{beforeSaveParam}}'] = $this->getBeforeSaveParam();
801
+ $this->_placeholders['{{EntityAttributeSetId}}'] = $this->getEntityAttributeSetId();
802
+ $this->_placeholders['{{filterMethod}}'] = $this->getFilterMethod();
803
+ $this->_placeholders['{{multipleSelectConvert}}'] = $this->getMultipleSelectConvert();
804
+ $this->_placeholders['{{toOptionAddition}}'] = $this->getToOptionAddition();
805
+ $this->_placeholders['{{multiselectMethods}}'] = $this->getMultiselectMethods();
806
+ $this->_placeholders['{{nameHtml}}'] = $this->getNameHtml();
807
+ $this->_placeholders['{{isTree}}'] = (int)$this->getIsTree();
808
+ $this->_placeholders['{{commentFilterIndexPrefix}}'] = $this->getCommentFilterIndexPrefix();
809
+ $this->_placeholders['{{entityApiAdditionalSettings}}'] = $this->getApiAdditionalSettings();
810
+ $this->_placeholders['{{subEntitiesAcl}}'] = $this->getSubEntitiesAcl();
811
+ $this->_placeholders['{{position}}'] = $this->getPosition();
812
+ $this->_placeholders['{{entityApiResourcesAlias}}'] = $this->getApiResourcesAlias();
813
+ $this->_placeholders['{{entityApiResourcesAliasV2}}'] = $this->getApiResourcesAliasV2();
814
+ $this->_placeholders['{{defaultApiAttributes}}'] = $this->getDefaultApiAttributes();
815
+ $this->_placeholders['{{filterEntityDates}}'] = $this->getFilterDates();
816
+ $this->_placeholders['{{filterEntityDates3}}'] = $this->getFilterDates(3);
817
+ $this->_placeholders['{{allAttributesToCollection}}'] = $this->getAllAttributesToCollection();
818
+ $this->_placeholders['{{loadStoreId}}'] = $this->getLoadStoreId();
819
+ $this->_placeholders['{{restCollectionCleanup}}'] = $this->getRestCollectionCleanup();
820
+ $this->_placeholders['{{restCollectionStoreId}}'] = $this->getRestCollectionStoreId();
821
+ $this->_placeholders['{{defaultAttributeValues}}'] = $this->getDefaultAttributeValues();
822
+ $this->_placeholders['{{toOptionArraySelect}}'] = $this->getToOptionArraySelect();
823
+ $this->_placeholders['{{parentStaticParams}}'] = $this->getParentStaticParams();
824
+
825
+
826
+ $eventObject = new Varien_Object(
827
+ array(
828
+ 'placeholders' => $this->_placeholders
829
+ )
830
+ );
831
+ Mage::dispatchEvent('umc_entity_placeholdrers', array('event_object'=>$eventObject));
832
+ $this->_placeholders = $eventObject->getPlaceholders();
833
+ }
834
+ if (is_null($param)) {
835
+ return $this->_placeholders;
836
+ }
837
+ if (isset($this->_placeholders[$param])) {
838
+ return $this->_placeholders[$param];
839
+ }
840
+ return '';
841
+ }
842
+
843
+ /**
844
+ * get placeholders as sibling
845
+ *
846
+ * @access public
847
+ * @param null $param
848
+ * @return array|mixed|null|string
849
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
850
+ */
851
+ public function getPlaceholdersAsSibling($param = null)
852
+ {
853
+ if (is_null($this->_placeholdersAsSibling)) {
854
+ $this->_placeholdersAsSibling = array();
855
+ $this->_placeholdersAsSibling['{{sibling_default_config}}'] = $this->getDefaultConfig();
856
+ $this->_placeholdersAsSibling['{{sibling}}'] = $this->getNameSingular(true);
857
+ $this->_placeholdersAsSibling['{{Sibling}}'] = ucfirst($this->getNameSingular(true));
858
+ $this->_placeholdersAsSibling['{{SIBLING}}'] = strtoupper($this->getNameSingular());
859
+ $this->_placeholdersAsSibling['{{SiblingLabel}}'] = ucfirst($this->getLabelSingular());
860
+ $this->_placeholdersAsSibling['{{siblingLabel}}'] = strtolower($this->getLabelSingular());
861
+ $this->_placeholdersAsSibling['{{SiblingsLabel}}'] = ucfirst($this->getLabelPlural());
862
+ $this->_placeholdersAsSibling['{{siblingsLabel}}'] = $this->getLabelPlural(true);
863
+ $this->_placeholdersAsSibling['{{siblingCollectionAttributes}}'] = $this->getCollectionAttributes();
864
+ $this->_placeholdersAsSibling['{{siblingAdminJoin}}'] = $this->getAdminJoin();
865
+ $this->_placeholdersAsSibling['{{siblingColumnsHeader}}'] = $this->getPrepareColumnsHeader();
866
+ $this->_placeholdersAsSibling['{{siblingNameAttributeGridEav}}'] = $this->getNameAttributeGridEav();
867
+ $this->_placeholdersAsSibling['{{siblingNameAttributeCode}}'] = $this->getNameAttributeCode();
868
+ $this->_placeholdersAsSibling['{{siblingNameAttributeLabel}}'] = $this->getNameAttributeLabel();
869
+ $this->_placeholdersAsSibling['{{siblings}}'] = strtolower($this->getNamePlural());
870
+ $this->_placeholdersAsSibling['{{Siblings}}'] = ucfirst($this->getNamePlural(true));
871
+ $this->_placeholdersAsSibling['{{SiblingNameMagicCode}}'] = $this->getNameAttributeMagicCode();
872
+ $this->_placeholdersAsSibling['{{SiblingViewRelationLayout}}'] = $this->getRelationLayoutXml();
873
+ $this->_placeholdersAsSibling['{{siblingListLayout}}'] = $this->getListTemplate();
874
+ $this->_placeholdersAsSibling['{{siblingViewLayout}}'] = $this->getViewTemplate();
875
+ $this->_placeholdersAsSibling['{{SiblingListItem}}'] = $this->getHtmlLink();
876
+ $this->_placeholdersAsSibling['{{siblingNameAttribute}}'] = $this->getNameAttributeCode();
877
+ $this->_placeholdersAsSibling['{{siblingAdditionalPrepareCollection}}']
878
+ = $this->getAdditionalPrepareCollection();
879
+ $this->_placeholdersAsSibling['{{siblingTableAlias}}'] = $this->getEntityTableAlias();
880
+ $this->_placeholdersAsSibling['{{siblingFilterMethod}}'] = $this->getFilterMethod();
881
+ $this->_placeholdersAsSibling['{{siblingAllAttributesToCollection}}']
882
+ = $this->getAllAttributesToCollection();
883
+ $this->_placeholdersAsSibling['{{siblingLoadStoreId}}'] = $this->getLoadStoreId();
884
+ $this->_placeholdersAsSibling['{{siblingToOptionArraySelect}}'] = $this->getToOptionArraySelect();
885
+ $this->_placeholdersAsSibling['{{siblingParentStaticParams}}'] = $this->getParentStaticParams();
886
+
887
+ $eventObject = new Varien_Object(
888
+ array(
889
+ 'placeholders' => $this->_placeholdersAsSibling
890
+ )
891
+ );
892
+ Mage::dispatchEvent(
893
+ 'umc_entity_placeholdrers_as_sibling',
894
+ array('event_object'=>$eventObject)
895
+ );
896
+ $this->_placeholdersAsSibling = $eventObject->getPlaceholders();
897
+ }
898
+ if (is_null($param)) {
899
+ return $this->_placeholdersAsSibling;
900
+ }
901
+ if (isset($this->_placeholdersAsSibling[$param])) {
902
+ return $this->_placeholdersAsSibling[$param];
903
+ }
904
+ return '';
905
+ }
906
+
907
+ /**
908
+ * get default config settings
909
+ *
910
+ * @access public
911
+ * @return string
912
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
913
+ */
914
+ public function getDefaultConfig()
915
+ {
916
+ if (!$this->getHasConfigDefaults()) {
917
+ return '';
918
+ }
919
+ $padding3 = $this->getPadding(3);
920
+ $padding = $this->getPadding();
921
+ $eol = $this->getEol();
922
+
923
+ $text = '<'.$this->getNameSingular().'>'.$eol;
924
+ if ($this->getCreateFrontend()) {
925
+ $text.= $padding3.$padding.'<breadcrumbs>1</breadcrumbs>'.$eol;
926
+ }
927
+ if ($this->getUrlRewrite() && $this->getUrlPrefix()) {
928
+ $text.= $padding3.$padding.'<url_prefix>'.$this->getUrlPrefix().'</url_prefix>'.$eol;
929
+ }
930
+ if ($this->getUrlRewrite() && $this->getUrlSuffix()) {
931
+ $text.= $padding3.$padding.'<url_suffix>'.$this->getUrlSuffix().'</url_suffix>'.$eol;
932
+ }
933
+ if ($this->getUrlRewrite() && $this->getUrlRewriteList()) {
934
+ $text.= $padding3.$padding.'<url_rewrite_list>'.$this->getUrlRewriteList().'</url_rewrite_list>'.$eol;
935
+ }
936
+ if ($this->getAllowComment()) {
937
+ $text.= $padding3.$padding.'<allow_comment>1</allow_comment>'.$eol;
938
+ }
939
+ if ($this->getRss()) {
940
+ $text.= $padding3.$padding.'<rss>1</rss>'.$eol;
941
+ }
942
+ if ($this->getAddSeo()) {
943
+ $text.= $padding3.$padding.'<meta_title>'.$this->getLabelPlural().'</meta_title>'.$eol;
944
+ }
945
+ if ($this->getIsTree() && $this->getCreateFrontend()) {
946
+ $text.= $padding3.$padding.'<tree>1</tree>'.$eol;
947
+ $text.= $padding3.$padding.'<recursion>0</recursion>'.$eol;
948
+ }
949
+ $text .= $padding3.'</'.$this->getNameSingular().'>'.$eol;
950
+ return $text;
951
+ }
952
+
953
+ /**
954
+ * get xml for add product event
955
+ *
956
+ * @access public
957
+ * @return string
958
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
959
+ */
960
+ public function getAddBlockToProductEvent()
961
+ {
962
+ $text = '';
963
+ if ($this->getLinkProduct()) {
964
+ $ns = $this->getNamespace(true);
965
+ $eol = $this->getEol();
966
+ $text = $this->getPadding(5).'<'.$ns.'_'.$this->getModule()->getLowerModuleName().'_'.
967
+ $this->getNameSingular(true).'>'.$eol;
968
+ $text .= $this->getPadding(6).'<type>singleton</type>'.$eol;
969
+ $text .= $this->getPadding(6).'<class>'.$ns.'_'.$this->getModule()->getLowerModuleName().
970
+ '/adminhtml_observer</class>'.$eol;
971
+ $text .= $this->getPadding(6).'<method>add'.ucfirst(strtolower($this->getNameSingular())).
972
+ 'Block</method>'.$eol;
973
+ $text .= $this->getPadding(5).'</'.$ns.'_'.$this->getModule()->getLowerModuleName().'_'.
974
+ $this->getNameSingular(true).'>'.$eol;
975
+ }
976
+ return $text;
977
+ }
978
+
979
+ /**
980
+ * get xml for add product save after event
981
+ *
982
+ * @access public
983
+ * @return string
984
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
985
+ */
986
+ public function getProductSaveAfterEvent()
987
+ {
988
+ $text = '';
989
+ if ($this->getLinkProduct()) {
990
+ $ns = strtolower($this->getModule()->getNamespace());
991
+ $eol = $this->getEol();
992
+ $text = $this->getPadding(5).'<'.$ns.'_'.$this->getModule()->getLowerModuleName().'_'.
993
+ $this->getNameSingular(true).'>'.$eol;
994
+ $text .= $this->getPadding(6).'<type>singleton</type>'.$eol;
995
+ $text .= $this->getPadding(6).'<class>'.$ns.'_'.$this->getModule()->getLowerModuleName().
996
+ '/adminhtml_observer</class>'.$eol;
997
+ $text .= $this->getPadding(6).'<method>save'.ucfirst(strtolower($this->getNameSingular())).
998
+ 'Data</method>'.$eol;
999
+ $text .= $this->getPadding(5).'</'.$ns.'_'.$this->getModule()->getLowerModuleName().
1000
+ '_'.$this->getNameSingular(true).'>'.$eol;
1001
+ }
1002
+ return $text;
1003
+ }
1004
+
1005
+ /**
1006
+ * get xml for add can load ext js
1007
+ *
1008
+ * @access public
1009
+ * @return string
1010
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1011
+ */
1012
+ public function getCanLoadExtJsEvent()
1013
+ {
1014
+ $text = '';
1015
+ if ($this->getLinkProduct() && $this->getIsTree()) {
1016
+ $eol = $this->getEol();
1017
+ $ns = strtolower($this->getModule()->getNamespace());
1018
+ $text = $this->getPadding(5).'<'.$ns.'_'.$this->getModule()->getLowerModuleName().'_'.
1019
+ $this->getNameSingular(true).'>'.$eol;
1020
+ $text .= $this->getPadding(6).'<type>singleton</type>'.$eol;
1021
+ $text .= $this->getPadding(6).'<class>'.$ns.'_'.$this->getModule()->getLowerModuleName().
1022
+ '/adminhtml_observer</class>'.$eol;
1023
+ $text .= $this->getPadding(6).'<method>setCanLoadExtJs</method>'.$eol;
1024
+ $text .= $this->getPadding(5).'</'.$ns.'_'.$this->getModule()->getLowerModuleName().
1025
+ '_'.$this->getNameSingular(true).'>'.$eol;
1026
+ }
1027
+ return $text;
1028
+ }
1029
+
1030
+ /**
1031
+ * get xml for admin menu
1032
+ *
1033
+ * @access public
1034
+ * @param $padding
1035
+ * @return string
1036
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1037
+ */
1038
+ public function getMenu($padding)
1039
+ {
1040
+ $extension = $this->getModule()->getExtensionName(true);
1041
+ $module = $this->getModule()->getLowerModuleName();
1042
+ $title = ucwords($this->getLabelSingular());
1043
+ $entity = strtolower($this->getNameSingular());
1044
+ $action = $module.'_'.$entity;
1045
+ $eol = $this->getEol();
1046
+
1047
+ $text = $this->getPadding($padding).'<'.$entity.' translate="title" module="'.$extension.'">'.$eol;
1048
+ $text .= $this->getPadding($padding + 1).'<title>'.$title.'</title>'.$eol;
1049
+ $text .= $this->getPadding($padding + 1).'<action>adminhtml/'.$action.'</action>'.$eol;
1050
+ $text .= $this->getPadding($padding + 1).'<sort_order>'.$this->getPosition().'</sort_order>'.$eol;
1051
+ $text .= $this->getPadding($padding).'</'.$entity.'>'.$eol;
1052
+ if ($this->getAllowComment()) {
1053
+ $text .= $this->getPadding($padding).'<'.$entity.
1054
+ '_comments translate="title" module="'.$extension.'">'.$eol;
1055
+ $text .= $this->getPadding($padding + 1).'<title>Manage '.$title.' Comments</title>'.$eol;
1056
+ $text .= $this->getPadding($padding + 1).'<action>adminhtml/'.$action.'_comment</action>'.$eol;
1057
+ $text .= $this->getPadding($padding + 1).'<sort_order>'.($this->getPosition() + 4).'</sort_order>'.$eol;
1058
+ $text .= $this->getPadding($padding).'</'.$entity.'_comments>'.$eol;
1059
+ }
1060
+
1061
+ $text .= $this->getTypeInstance()->getAdditionalMenu($padding);
1062
+ return $text;
1063
+
1064
+ }
1065
+
1066
+ /**
1067
+ * get xml for acl
1068
+ *
1069
+ * @access public
1070
+ * @param $padding
1071
+ * @return string
1072
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1073
+ */
1074
+ public function getMenuAcl($padding)
1075
+ {
1076
+ $extension = $this->getModule()->getExtensionName(true);
1077
+ $title = ucwords($this->getLabelSingular());
1078
+ $entity = $this->getNameSingular(true);
1079
+ $eol = $this->getEol();
1080
+
1081
+ $text = $this->getPadding($padding).'<'.$entity.' translate="title" module="'.$extension.'">'.$eol;
1082
+ $text .= $this->getPadding($padding + 1).'<title>'.$title.'</title>'.$eol;
1083
+ $text .= $this->getPadding($padding + 1).'<sort_order>'.$this->getPosition().'</sort_order>'.$eol;
1084
+ $text .= $this->getPadding($padding).'</'.$entity.'>'.$eol;
1085
+
1086
+ if ($this->getAllowComment()) {
1087
+ $text .= $this->getPadding($padding).'<'.$entity.
1088
+ '_comments translate="title" module="'.$extension.'">'.$eol;
1089
+ $text .= $this->getPadding($padding + 1).'<title>Manage '.$title.' Comments</title>'.$eol;
1090
+ $text .= $this->getPadding($padding + 1).'<sort_order>'.($this->getPosition() + 5).'</sort_order>'.$eol;
1091
+ $text .= $this->getPadding($padding).'</'.$entity.'_comments>'.$eol;
1092
+ }
1093
+ $text .= $this->getTypeInstance()->getAdditionalMenuAcl($padding);
1094
+ return $text;
1095
+
1096
+ }
1097
+
1098
+ /**
1099
+ * get attributes that need to be added in the admin grid collection
1100
+ *
1101
+ * @access public
1102
+ * @return string
1103
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1104
+ */
1105
+ public function getCollectionAttributes()
1106
+ {
1107
+ return $this->getTypeInstance()->getCollectionAttributes();
1108
+ }
1109
+
1110
+ /**
1111
+ * get join with admin - for the admin grid
1112
+ *
1113
+ * @access public
1114
+ * @return string
1115
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1116
+ */
1117
+ public function getAdminJoin()
1118
+ {
1119
+ return $this->getTypeInstance()->getAdminJoin();
1120
+ }
1121
+
1122
+ /**
1123
+ * code above the prepare columns
1124
+ *
1125
+ * @access public
1126
+ * @return string
1127
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1128
+ */
1129
+ public function getPrepareColumnsHeader()
1130
+ {
1131
+ return $this->getTypeInstance()->getPrepareColumnsHeader();
1132
+ }
1133
+
1134
+ /**
1135
+ * name attribute in grid
1136
+ *
1137
+ * @access public
1138
+ * @return string
1139
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1140
+ */
1141
+ public function getNameAttributeGridEav()
1142
+ {
1143
+ return $this->getTypeInstance()->getNameAttributeGridEav();
1144
+ }
1145
+
1146
+ /**
1147
+ * check if the frontend list block can be created
1148
+ *
1149
+ * @access public
1150
+ * @return bool
1151
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1152
+ */
1153
+ public function getCanCreateListBlock()
1154
+ {
1155
+ if ($this->getCreateList()) {
1156
+ return true;
1157
+ }
1158
+ if ($this->getShowOnProduct()) {
1159
+ return true;
1160
+ }
1161
+ if ($this->getShowOnCategory()) {
1162
+ return true;
1163
+ }
1164
+ //check for siblings with frontend view
1165
+ $related = $this->getRelatedEntities(
1166
+ Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_SIBLING
1167
+ );
1168
+ foreach ($related as $r) {
1169
+ if ($r->getCreateView()) {
1170
+ return true;
1171
+ }
1172
+ }
1173
+ //check for parents with frontend view
1174
+ $related = $this->getRelatedEntities(
1175
+ Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_CHILD
1176
+ );
1177
+ foreach ($related as $r) {
1178
+ if ($r->getCreateView()) {
1179
+ return true;
1180
+ }
1181
+ }
1182
+ return false;
1183
+ }
1184
+
1185
+ /**
1186
+ * get ddl text for attributes
1187
+ *
1188
+ * @access public
1189
+ * @return bool
1190
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1191
+ */
1192
+ public function getAttributesDdlSql()
1193
+ {
1194
+ $padding = $this->getPadding();
1195
+ $eol = $this->getEol();
1196
+ $content = '';
1197
+ $content .= $this->getParentEntitiesFkAttributes($padding, true);
1198
+ if ($this->getIsFlat()) {
1199
+ foreach ($this->getAttributes() as $attribute) {
1200
+ $content .= $padding.$attribute->getDdlSqlColumn().$eol;
1201
+ }
1202
+ }
1203
+ if ($this->getIsFlat()) {
1204
+ $simulated = $this->getSimulatedAttributes(null, false);
1205
+ } elseif ($this->getIsTree()) {
1206
+ $simulated = $this->getSimulatedAttributes('tree', false);
1207
+ } else {
1208
+ $simulated = array();
1209
+ }
1210
+ foreach ($simulated as $attr) {
1211
+ $content .= $padding.$attr->getDdlSqlColumn().$eol;
1212
+ }
1213
+ return substr($content, 0, strlen($content) - strlen($eol));
1214
+ }
1215
+
1216
+ /**
1217
+ * get foreign key columns
1218
+ *
1219
+ * @access public
1220
+ * @param $padding
1221
+ * @return string
1222
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1223
+ */
1224
+ public function getParentEntitiesFkAttributes($padding)
1225
+ {
1226
+ if ($this->getIsEav()) {
1227
+ return '';
1228
+ }
1229
+ $parents = $this->getRelatedEntities(
1230
+ Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_CHILD
1231
+ );
1232
+ $content = '';
1233
+ foreach ($parents as $parent) {
1234
+ /** @var Ultimate_ModuleCreator_Model_Attribute $attr */
1235
+ $attr = Mage::getModel('modulecreator/attribute');
1236
+ $attr->setCode($parent->getPlaceholders('{{entity}}').'_id');
1237
+ $attr->setLabel($parent->getPlaceholders('{{EntityLabel}}'). ' ID');
1238
+ $attr->setType('int');
1239
+ $content .= $padding.$attr->getDdlSqlColumn()."\n";
1240
+ }
1241
+ return $content;
1242
+ }
1243
+
1244
+ /**
1245
+ * get simulated attributes
1246
+ *
1247
+ * @access public
1248
+ * @param mixed $type
1249
+ * @param bool $ignoreSettings
1250
+ * @param array $except
1251
+ * @return Ultimate_ModuleCreator_Model_Attribute[]
1252
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1253
+ */
1254
+ public function getSimulatedAttributes($type = null, $ignoreSettings = false, $except = array())
1255
+ {
1256
+ /** @var Ultimate_ModuleCreator_Model_Attribute[] $attributes */
1257
+ $attributes = array();
1258
+ $namespace = $this->getNamespace(true);
1259
+ if (is_null($type)) {
1260
+ $types = array('status', 'url_rewrite', 'tree', 'rss', 'seo', 'comment');
1261
+ $attributes = array();
1262
+ foreach ($types as $type) {
1263
+ if (!in_array($type, $except)) {
1264
+ $attributes = array_merge($attributes, $this->getSimulatedAttributes($type, $ignoreSettings));
1265
+ }
1266
+ }
1267
+ return $attributes;
1268
+ }
1269
+ switch ($type) {
1270
+ case 'status':
1271
+ /** @var Ultimate_ModuleCreator_Model_Attribute $attr */
1272
+ $attr = Mage::getModel('modulecreator/attribute');
1273
+ $attr->setCode('status');
1274
+ $attr->setLabel('Enabled');
1275
+ $attr->setType('yesno');
1276
+ $attr->setDefaultValue('1');
1277
+ $attributes[] = $attr;
1278
+ break;
1279
+ case 'url_rewrite':
1280
+ if ($this->getUrlRewrite() || $ignoreSettings) {
1281
+ /** @var Ultimate_ModuleCreator_Model_Attribute $attr */
1282
+ $attr = Mage::getModel('modulecreator/attribute');
1283
+ $attr->setCode('url_key');
1284
+ $attr->setLabel('URL key');
1285
+ $attr->setType('text');
1286
+ $module = $this->getModule()->getLowerModuleName();
1287
+ $entity = $this->getNameSingular(true);
1288
+ $attr->setForcedSetupBackend($namespace.'_'.$module.'/'.$entity.'_attribute_backend_urlkey');
1289
+ $attributes[] = $attr;
1290
+ }
1291
+ break;
1292
+ case 'tree' :
1293
+ if ($this->getIsTree() || $ignoreSettings) {
1294
+ /** @var Ultimate_ModuleCreator_Model_Attribute $attr */
1295
+ $attr = Mage::getModel('modulecreator/attribute');
1296
+ $attr->setCode('parent_id');
1297
+ $attr->setLabel('Parent id');
1298
+ $attr->setType('int');
1299
+ $attributes[] = $attr;
1300
+
1301
+ /** @var Ultimate_ModuleCreator_Model_Attribute $attr */
1302
+ $attr = Mage::getModel('modulecreator/attribute');
1303
+ $attr->setCode('path');
1304
+ $attr->setLabel('Path');
1305
+ $attr->setType('text');
1306
+ $attr->setIgnoreApi(true);
1307
+ $attributes[] = $attr;
1308
+
1309
+ /** @var Ultimate_ModuleCreator_Model_Attribute $attr */
1310
+ $attr = Mage::getModel('modulecreator/attribute');
1311
+ $attr->setCode('position');
1312
+ $attr->setLabel('Position');
1313
+ $attr->setType('int');
1314
+ $attr->setIgnoreApi(true);
1315
+ $attributes[] = $attr;
1316
+
1317
+ /** @var Ultimate_ModuleCreator_Model_Attribute $attr */
1318
+ $attr = Mage::getModel('modulecreator/attribute');
1319
+ $attr->setCode('level');
1320
+ $attr->setLabel('Level');
1321
+ $attr->setType('int');
1322
+ $attr->setIgnoreApi(true);
1323
+ $attributes[] = $attr;
1324
+
1325
+ /** @var Ultimate_ModuleCreator_Model_Attribute $attr */
1326
+ $attr = Mage::getModel('modulecreator/attribute');
1327
+ $attr->setCode('children_count');
1328
+ $attr->setLabel('Children count');
1329
+ $attr->setType('int');
1330
+ $attr->setIgnoreApi(true);
1331
+ $attributes[] = $attr;
1332
+ }
1333
+ break;
1334
+ case 'rss':
1335
+ if ($this->getRss() || $ignoreSettings) {
1336
+ /** @var Ultimate_ModuleCreator_Model_Attribute $attr */
1337
+ $attr = Mage::getModel('modulecreator/attribute');
1338
+ $attr->setCode('in_rss');
1339
+ $attr->setLabel('In RSS');
1340
+ $attr->setType('yesno');
1341
+ $attr->setDefaultValue('1');
1342
+ $attributes[] = $attr;
1343
+ }
1344
+ break;
1345
+ case 'seo':
1346
+ if ($this->getAddSeo() || $ignoreSettings) {
1347
+ /** @var Ultimate_ModuleCreator_Model_Attribute $attr */
1348
+ $attr = Mage::getModel('modulecreator/attribute');
1349
+ $attr->setCode('meta_title');
1350
+ $attr->setLabel('Meta title');
1351
+ $attr->setType('text');
1352
+ $attributes[] = $attr;
1353
+
1354
+ /** @var Ultimate_ModuleCreator_Model_Attribute $attr */
1355
+ $attr = Mage::getModel('modulecreator/attribute');
1356
+ $attr->setCode('meta_keywords');
1357
+ $attr->setLabel('Meta keywords');
1358
+ $attr->setType('textarea');
1359
+ $attributes[] = $attr;
1360
+
1361
+ $attr = Mage::getModel('modulecreator/attribute');
1362
+ $attr->setCode('meta_description');
1363
+ $attr->setLabel('Meta description');
1364
+ $attr->setType('textarea');
1365
+ $attributes[] = $attr;
1366
+ }
1367
+ break;
1368
+ case 'comment':
1369
+ if ($this->getAllowComment() || $ignoreSettings) {
1370
+ /** @var Ultimate_ModuleCreator_Model_Attribute $attr */
1371
+ $attr = Mage::getModel('modulecreator/attribute');
1372
+ $attr->setCode('allow_comment');
1373
+ $attr->setLabel('Allow Comment');
1374
+ $attr->setType('dropdown');
1375
+ $attr->setOptionsSource('custom');
1376
+ $attr->setOptions(false);
1377
+ $attr->setEntity($this);
1378
+ $attr->setDefaultValue('2');
1379
+ $attr->setForcedDefaultValue('2');
1380
+ $attr->setForcedSource(
1381
+ $namespace.'_'.$this->getModule()->getLowerModuleName().
1382
+ '/adminhtml_source_yesnodefault'
1383
+ );
1384
+ $attributes[] = $attr;
1385
+ }
1386
+ break;
1387
+ default:
1388
+ break;
1389
+ }
1390
+ foreach ($attributes as $attribute) {
1391
+ $attribute->setUserDefined(false);
1392
+ }
1393
+ return $attributes;
1394
+ }
1395
+
1396
+ /**
1397
+ * get layout xml head reference
1398
+ *
1399
+ * @access public
1400
+ * @return string
1401
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1402
+ */
1403
+ public function getReferenceHeadLayout()
1404
+ {
1405
+ $eol = $this->getEol();
1406
+ $content = $this->getPadding(2);
1407
+ if ($this->getIsTree()) {
1408
+ $namespace = $this->getNamespace(true);
1409
+ $module = $this->getModule()->getLowerModuleName();
1410
+ $entity = $this->getNameSingular(true);
1411
+ $content .= '<reference name="head">'.$eol;
1412
+ $content .= $this->getPadding(3).
1413
+ '<action method="addItem" ifconfig="'.$namespace.'_'.$module.'/'.$entity.
1414
+ '/tree"><type>skin_js</type><js>js/'.$namespace.'_'.$module.'/tree.js</js></action>'.$eol;
1415
+ $content .= $this->getPadding(2).'</reference>'.$eol;
1416
+ $content .= $this->getPadding(2);
1417
+ }
1418
+ return $content;
1419
+ }
1420
+
1421
+ /**
1422
+ * get layout xml for relation to product
1423
+ *
1424
+ * @access public
1425
+ * @return string
1426
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1427
+ */
1428
+ public function getRelationLayoutXml()
1429
+ {
1430
+ $eol = $this->getEol();
1431
+ $content = $this->getPadding(2);
1432
+ $module = $this->getModule()->getLowerModuleName();
1433
+ $entityName = $this->getNameSingular(true);
1434
+ $namespace = $this->getNamespace(true);
1435
+ if ($this->getIsTree()) {
1436
+ $content .= $this->getPadding().'<block type="'.$namespace.'_'.$module.'/'.
1437
+ $entityName.'_children" name="'.$entityName.'_children" template="'.
1438
+ $namespace.'_'.$module.'/'.$entityName.'/children.phtml" />'.$eol.$this->getPadding(2);
1439
+ }
1440
+ if ($this->getShowProducts()) {
1441
+ $content .= $this->getPadding().'<block type="'.
1442
+ $namespace.'_'.$module.'/'.$entityName.'_catalog_product_list" name="'.
1443
+ $entityName.'.info.products" as="'.$entityName.'_products" template="'.
1444
+ $namespace.'_'.$module.'/'.$entityName.'/catalog/product/list.phtml" />'.
1445
+ $eol.$this->getPadding(2);
1446
+ }
1447
+ if ($this->getShowCategory()) {
1448
+ $content .= $this->getPadding().'<block type="'.
1449
+ $namespace.'_'.$module.'/'.$entityName.'_catalog_category_list" name="'.
1450
+ $entityName.'.info.categories" as="'.$entityName.
1451
+ '_categories" template="'.$namespace.'_'.$module.'/'.$entityName.
1452
+ '/catalog/category/list.phtml" />'.$eol.$this->getPadding(2);
1453
+ }
1454
+ $children = $this->getRelatedEntities(
1455
+ Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_PARENT
1456
+ );
1457
+ $siblings = $this->getRelatedEntities(
1458
+ Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_SIBLING
1459
+ );
1460
+ /** @var Ultimate_ModuleCreator_Model_Entity[] $relatedEntities */
1461
+ $relatedEntities = array_merge($children, $siblings);
1462
+ foreach ($relatedEntities as $entity) {
1463
+ $content .= $this->getPadding().'<block type="'.$namespace.'_'.$module.'/'.
1464
+ $entityName.'_'.strtolower($entity->getNameSingular()).'_list" name="'.$entityName.
1465
+ '.'.strtolower($entity->getNameSingular()).'_list" as="'.$entityName.'_'.
1466
+ strtolower($this->getNamePlural()).'" template="'.$namespace.'_'.$module.'/'.$entityName.'/'.
1467
+ strtolower($entity->getNameSingular()).'/list.phtml" />'.$eol.$this->getPadding(2);
1468
+ }
1469
+ if ($this->getAllowComment()) {
1470
+ $content .= $this->getPadding().'<block type="'.
1471
+ $namespace.'_'.$module.'/'.$entityName.'_comment_list" name="'.
1472
+ $entityName.'.comments_list" as="'.$entityName.'_comment_list" template="'.$namespace.'_'.$module.'/'.
1473
+ $entityName.'/comment/list.phtml">'.$eol.$this->getPadding(2);
1474
+ $content .= $this->getPadding(2).
1475
+ '<block type="'.$namespace.'_'.$module.'/'.$entityName.
1476
+ '_comment_form" name="comment_form" as="comment_form" template="'.
1477
+ $namespace.'_'.$module.'/'.$entityName.'/comment/form.phtml" />'.$eol.$this->getPadding(2);
1478
+ $content .= $this->getPadding().'</block>'.$eol.$this->getPadding(2);
1479
+ }
1480
+ return $content;
1481
+ }
1482
+
1483
+ /**
1484
+ * get html link to entity
1485
+ *
1486
+ * @access public
1487
+ * @return string
1488
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1489
+ */
1490
+ public function getHtmlLink()
1491
+ {
1492
+ $eol = $this->getEol();
1493
+ $entity = $this->getNameSingular(true);
1494
+ $entityUc = ucfirst($this->getNameSingular());
1495
+ $nameCode = $this->getNameAttributeMagicCode();
1496
+ $content = '';
1497
+ $padd = 3;
1498
+ if ($this->getCreateView()) {
1499
+ $padd = 4;
1500
+ $content .= $this->getPadding(3).'<a href="<?php echo $_'.$entity.'->get'.$entityUc.'Url()?>">'.$eol;
1501
+ }
1502
+ $content .= $this->getPadding($padd).'<?php echo $_'.$entity.'->get'.$nameCode.'();?>'.$eol;
1503
+ if ($this->getCreateView()) {
1504
+ $content .= $this->getPadding(3).'</a>';
1505
+ }
1506
+ $content .= '<br />';
1507
+ return $content;
1508
+ }
1509
+
1510
+ /**
1511
+ * get the html for attributes in view page
1512
+ *
1513
+ * @access public
1514
+ * @return string
1515
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1516
+ */
1517
+ public function getViewAttributesHtml()
1518
+ {
1519
+ $eol = $this->getEol();
1520
+ $content = '';
1521
+ foreach ($this->getAttributes() as $attribute) {
1522
+ if ($attribute->getFrontend()) {
1523
+ $content .= $this->getPadding().
1524
+ '<div class="'.$this->getNameSingular().'-'.$attribute->getCode().'">'.$eol;
1525
+ $content .= $this->getPadding(2).$attribute->getFrontendHtml().$eol;
1526
+ $content .= $this->getPadding().'</div>'.$eol;
1527
+ }
1528
+ }
1529
+ return $content;
1530
+ }
1531
+
1532
+ /**
1533
+ * check if comments should be split by store
1534
+ *
1535
+ * @access public
1536
+ * @return bool
1537
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1538
+ */
1539
+ public function getAllowCommentByStore()
1540
+ {
1541
+ return $this->getTypeInstance()->getAllowCommentByStore();
1542
+ }
1543
+
1544
+ /**
1545
+ * get view widget attributes
1546
+ *
1547
+ * @access public
1548
+ * @return string
1549
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1550
+ */
1551
+ public function getViewWidgetAttributesHtml()
1552
+ {
1553
+ $content = '';
1554
+ $padding = $this->getPadding(3);
1555
+ $tab = $this->getPadding();
1556
+ $eol = $this->getEol();
1557
+ foreach ($this->getAttributes() as $attribute) {
1558
+ if ($attribute->getWidget()) {
1559
+ $content .= $padding.'<div class="'.$attribute->getCode().'-widget">'.
1560
+ $eol.$padding.$tab.$attribute->getFrontendHtml().$padding.'</div>'.$eol;
1561
+ }
1562
+ }
1563
+ return $content;
1564
+ }
1565
+
1566
+ /**
1567
+ * get the system attributes
1568
+ *
1569
+ * @access public
1570
+ * @return string
1571
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1572
+ */
1573
+ public function getSystemAttributes()
1574
+ {
1575
+ $position = 10;
1576
+ $content = '';
1577
+ $tab = $this->getPadding();
1578
+ $eol = $this->getEol();
1579
+ $padding = str_repeat($tab, 6);
1580
+ if ($this->getCreateFrontend()) {
1581
+ $content .= $padding.'<breadcrumbs translate="label">'.$eol;
1582
+ $content .= $padding.$tab.'<label>Use Breadcrumbs</label>'.$eol;
1583
+ $content .= $padding.$tab.'<frontend_type>select</frontend_type>'.$eol;
1584
+ $content .= $padding.$tab.'<source_model>adminhtml/system_config_source_yesno</source_model>'.$eol;
1585
+ $content .= $padding.$tab.'<sort_order>'.$position.'</sort_order>'.$eol;
1586
+ $content .= $padding.$tab.'<show_in_default>1</show_in_default>'.$eol;
1587
+ $content .= $padding.$tab.'<show_in_website>1</show_in_website>'.$eol;
1588
+ $content .= $padding.$tab.'<show_in_store>1</show_in_store>'.$eol;
1589
+ $content .= $padding.'</breadcrumbs>'.$eol;
1590
+ $position += 10;
1591
+ }
1592
+ if ($this->getUrlRewrite()) {
1593
+ $content .= $padding.'<url_rewrite_list translate="label comment">'.$eol;
1594
+ $content .= $padding.$tab.'<label>URL key for list page</label>'.$eol;
1595
+ $content .= $padding.$tab.'<frontend_type>text</frontend_type>'.$eol;
1596
+ $content .= $padding.$tab.'<sort_order>'.$position.'</sort_order>'.$eol;
1597
+ $content .= $padding.$tab.'<show_in_default>1</show_in_default>'.$eol;
1598
+ $content .= $padding.$tab.'<show_in_website>1</show_in_website>'.$eol;
1599
+ $content .= $padding.$tab.'<show_in_store>1</show_in_store>'.$eol;
1600
+ $content .= $padding.$tab.'<comment>Leave empty to use default URL module/controller/action</comment>'.$eol;
1601
+ $content .= $padding.'</url_rewrite_list>'.$eol;
1602
+ $position += 10;
1603
+
1604
+
1605
+ $content .= $padding.'<url_prefix translate="label comment">'.$eol;
1606
+ $content .= $padding.$tab.'<label>URL prefix</label>'.$eol;
1607
+ $content .= $padding.$tab.'<frontend_type>text</frontend_type>'.$eol;
1608
+ $content .= $padding.$tab.'<sort_order>'.$position.'</sort_order>'.$eol;
1609
+ $content .= $padding.$tab.'<show_in_default>1</show_in_default>'.$eol;
1610
+ $content .= $padding.$tab.'<show_in_website>1</show_in_website>'.$eol;
1611
+ $content .= $padding.$tab.'<show_in_store>1</show_in_store>'.$eol;
1612
+ $content .= $padding.$tab.'<comment>Leave empty for no prefix</comment>'.$eol;
1613
+ $content .= $padding.'</url_prefix>'.$eol;
1614
+ $position += 10;
1615
+
1616
+ $content .= $padding.'<url_suffix translate="label comment">'.$eol;
1617
+ $content .= $padding.$tab.'<label>Url suffix</label>'.$eol;
1618
+ $content .= $padding.$tab.'<frontend_type>text</frontend_type>'.$eol;
1619
+ $content .= $padding.$tab.'<sort_order>'.$position.'</sort_order>'.$eol;
1620
+ $content .= $padding.$tab.'<show_in_default>1</show_in_default>'.$eol;
1621
+ $content .= $padding.$tab.'<show_in_website>1</show_in_website>'.$eol;
1622
+ $content .= $padding.$tab.'<show_in_store>1</show_in_store>'.$eol;
1623
+ $content .= $padding.$tab.'<comment>What goes after the dot. Leave empty for no suffix.</comment>'.$eol;
1624
+ $content .= $padding.'</url_suffix>'.$eol;
1625
+ $position += 10;
1626
+ }
1627
+ if ($this->getAllowComment()) {
1628
+ $content .= $padding.'<allow_comment translate="label">'.$eol;
1629
+ $content .= $padding.$tab.'<label>Allow comments</label>'.$eol;
1630
+ $content .= $padding.$tab.'<frontend_type>select</frontend_type>'.$eol;
1631
+ $content .= $padding.$tab.'<source_model>adminhtml/system_config_source_yesno</source_model>'.$eol;
1632
+ $content .= $padding.$tab.'<sort_order>'.$position.'</sort_order>'.$eol;
1633
+ $content .= $padding.$tab.'<show_in_default>1</show_in_default>'.$eol;
1634
+ $content .= $padding.$tab.'<show_in_website>1</show_in_website>'.$eol;
1635
+ $content .= $padding.$tab.'<show_in_store>1</show_in_store>'.$eol;
1636
+ $content .= $padding.'</allow_comment>'.$eol;
1637
+ $position += 10;
1638
+
1639
+ $content .= $padding.'<allow_guest_comment translate="label">'.$eol;
1640
+ $content .= $padding.$tab.'<label>Allow guest comments</label>'.$eol;
1641
+ $content .= $padding.$tab.'<frontend_type>select</frontend_type>'.$eol;
1642
+ $content .= $padding.$tab.'<source_model>adminhtml/system_config_source_yesno</source_model>'.$eol;
1643
+ $content .= $padding.$tab.'<sort_order>'.$position.'</sort_order>'.$eol;
1644
+ $content .= $padding.$tab.'<show_in_default>1</show_in_default>'.$eol;
1645
+ $content .= $padding.$tab.'<show_in_website>1</show_in_website>'.$eol;
1646
+ $content .= $padding.$tab.'<show_in_store>1</show_in_store>'.$eol;
1647
+ $content .= $padding.$tab.'<depends>'.$eol;
1648
+ $content .= $padding.$tab.$tab.'<allow_comment>1</allow_comment>'.$eol;
1649
+ $content .= $padding.$tab.'</depends>'.$eol;
1650
+ $content .= $padding.'</allow_guest_comment>'.$eol;
1651
+ $position += 10;
1652
+ }
1653
+ if ($this->getRss()) {
1654
+ $content .= $padding.'<rss translate="label">'.$eol;
1655
+ $content .= $padding.$tab.'<label>Enable rss</label>'.$eol;
1656
+ $content .= $padding.$tab.'<frontend_type>select</frontend_type>'.$eol;
1657
+ $content .= $padding.$tab.'<source_model>adminhtml/system_config_source_yesno</source_model>'.$eol;
1658
+ $content .= $padding.$tab.'<sort_order>'.$position.'</sort_order>'.$eol;
1659
+ $content .= $padding.$tab.'<show_in_default>1</show_in_default>'.$eol;
1660
+ $content .= $padding.$tab.'<show_in_website>1</show_in_website>'.$eol;
1661
+ $content .= $padding.$tab.'<show_in_store>1</show_in_store>'.$eol;
1662
+ $content .= $padding.'</rss>'.$eol;
1663
+ $position += 10;
1664
+ }
1665
+ if ($this->getIsTree() && $this->getCreateList()) {
1666
+ $content .= $padding.'<tree translate="label">'.$eol;
1667
+ $content .= $padding.$tab.'<label>Display as tree</label>'.$eol;
1668
+ $content .= $padding.$tab.'<frontend_type>select</frontend_type>'.$eol;
1669
+ $content .= $padding.$tab.'<source_model>adminhtml/system_config_source_yesno</source_model>'.$eol;
1670
+ $content .= $padding.$tab.'<sort_order>'.$position.'</sort_order>'.$eol;
1671
+ $content .= $padding.$tab.'<show_in_default>1</show_in_default>'.$eol;
1672
+ $content .= $padding.$tab.'<show_in_website>1</show_in_website>'.$eol;
1673
+ $content .= $padding.$tab.'<show_in_store>1</show_in_store>'.$eol;
1674
+ $content .= $padding.'</tree>'.$eol;
1675
+ $position += 10;
1676
+ }
1677
+ if ($this->getIsTree() && ($this->getCreateList() || $this->getWidget())) {
1678
+ $content .= $padding.'<recursion translate="label">'.$eol;
1679
+ $content .= $padding.$tab.'<label>Recursion level</label>'.$eol;
1680
+ $content .= $padding.$tab.'<frontend_type>text</frontend_type>'.$eol;
1681
+ $content .= $padding.$tab.'<sort_order>'.$position.'</sort_order>'.$eol;
1682
+ $content .= $padding.$tab.'<show_in_default>1</show_in_default>'.$eol;
1683
+ $content .= $padding.$tab.'<show_in_website>1</show_in_website>'.$eol;
1684
+ $content .= $padding.$tab.'<show_in_store>1</show_in_store>'.$eol;
1685
+ $content .= $padding.'</recursion>'.$eol;
1686
+ $position += 10;
1687
+ }
1688
+
1689
+ if ($this->getAddSeo() && $this->getCreateList()) {
1690
+ $content .= $padding.'<meta_title translate="label">'.$eol;
1691
+ $content .= $padding.$tab.'<label>Meta title for '.
1692
+ strtolower($this->getLabelPlural()).' list page</label>'.$eol;
1693
+ $content .= $padding.$tab.'<frontend_type>text</frontend_type>'.$eol;
1694
+ $content .= $padding.$tab.'<sort_order>'.$position.'</sort_order>'.$eol;
1695
+ $content .= $padding.$tab.'<show_in_default>1</show_in_default>'.$eol;
1696
+ $content .= $padding.$tab.'<show_in_website>1</show_in_website>'.$eol;
1697
+ $content .= $padding.$tab.'<show_in_store>1</show_in_store>'.$eol;
1698
+ $content .= $padding.'</meta_title>'.$eol;
1699
+ $position += 10;
1700
+
1701
+ $content .= $padding.'<meta_description translate="label">'.$eol;
1702
+ $content .= $padding.$tab.'<label>Meta description for '.
1703
+ strtolower($this->getLabelPlural()).' list page</label>'.$eol;
1704
+ $content .= $padding.$tab.'<frontend_type>textarea</frontend_type>'.$eol;
1705
+ $content .= $padding.$tab.'<sort_order>'.$position.'</sort_order>'.$eol;
1706
+ $content .= $padding.$tab.'<show_in_default>1</show_in_default>'.$eol;
1707
+ $content .= $padding.$tab.'<show_in_website>1</show_in_website>'.$eol;
1708
+ $content .= $padding.$tab.'<show_in_store>1</show_in_store>'.$eol;
1709
+ $content .= $padding.'</meta_description>'.$eol;
1710
+ $position += 10;
1711
+
1712
+ $content .= $padding.'<meta_keywords translate="label">'.$eol;
1713
+ $content .= $padding.$tab.'<label>Meta keywords for '.
1714
+ strtolower($this->getLabelPlural()).' list page</label>'.$eol;
1715
+ $content .= $padding.$tab.'<frontend_type>textarea</frontend_type>'.$eol;
1716
+ $content .= $padding.$tab.'<sort_order>'.$position.'</sort_order>'.$eol;
1717
+ $content .= $padding.$tab.'<show_in_default>1</show_in_default>'.$eol;
1718
+ $content .= $padding.$tab.'<show_in_website>1</show_in_website>'.$eol;
1719
+ $content .= $padding.$tab.'<show_in_store>1</show_in_store>'.$eol;
1720
+ $content .= $padding.'</meta_keywords>'.$eol;
1721
+ }
1722
+ return substr($content, 0, strlen($content) - strlen($eol));
1723
+ }
1724
+
1725
+ /**
1726
+ * get additional api xml
1727
+ *
1728
+ * @access public
1729
+ * @return string
1730
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1731
+ */
1732
+ public function getApiAdditional()
1733
+ {
1734
+ $content = $this->getApiTree();
1735
+ $content .= $this->getTypeInstance()->getApiAdditional();
1736
+ $content .= $this->getApiRelations();
1737
+ return $content;
1738
+ }
1739
+
1740
+ /**
1741
+ * get additional api xml for tree entities
1742
+ *
1743
+ * @access public
1744
+ * @return string
1745
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1746
+ */
1747
+ public function getApiTree()
1748
+ {
1749
+ $content = '';
1750
+ $padding = $this->getPadding();
1751
+ $prefix = str_repeat($padding, 5);
1752
+ $eol = $this->getEol();
1753
+ $extension = $this->getModule()->getExtensionName(true);
1754
+ if ($this->getIsTree()) {
1755
+ $module = $this->getModule()->getLowerModuleName();
1756
+ $entity = $this->getNameSingular(true);
1757
+ $entityLabel = strtolower($this->getLabelSingular());
1758
+ $entitiesLabel = strtolower($this->getLabelPlural());
1759
+ $content = $prefix.'<level translate="title" module="'.$extension.'">'.$eol;
1760
+ $content .= $prefix.$padding.'<title>Retrieve one level of '.$entitiesLabel.'</title>'.$eol;
1761
+ $content .= $prefix.$padding.'<acl>'.$module.'/'.$entity.'/info</acl>'.$eol;
1762
+ $content .= $prefix.'</level>'.$eol;
1763
+ $content .= $prefix.'<move translate="title" module="'.$extension.'">'.$eol;
1764
+ $content .= $prefix.$padding.'<title>Move '.$entityLabel.' in tree</title>'.$eol;
1765
+ $content .= $prefix.$padding.'<acl>'.$module.'/'.$entity.'/move</acl>'.$eol;
1766
+ $content .= $prefix.'</move>'.$eol;
1767
+ }
1768
+ return $content;
1769
+ }
1770
+
1771
+ /**
1772
+ * get api relations for a section
1773
+ *
1774
+ * @access public
1775
+ * @param $relatedCode
1776
+ * @param $relatedLabel
1777
+ * @return string
1778
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1779
+ */
1780
+ public function getApiRelationsSection($relatedCode, $relatedLabel)
1781
+ {
1782
+ $eol = $this->getEol();
1783
+ $padding = $this->getPadding();
1784
+ $prefix = $this->getPadding(5);
1785
+ $module = $this->getModule()->getLowerModuleName();
1786
+ $entity = $this->getNameSingular(true);
1787
+ $entityLabelUc = ucfirst($this->getLabelSingular());
1788
+ $entityLabel = strtolower($this->getLabelSingular());
1789
+ $extension = $this->getModule()->getExtensionName(true);
1790
+
1791
+ $string = '';
1792
+ $string .= $prefix. '<assign'.$relatedCode.' translate="title" module="'.$extension.'">'.$eol;
1793
+ $string .= $prefix.$padding. '<title>Assign '.$relatedLabel.' to '.$entityLabelUc.'</title>'.$eol;
1794
+ $string .= $prefix.$padding. '<acl>'.$module.'/'.$entity.'/update</acl>'.$eol;
1795
+ $string .= $prefix. '</assign'.$relatedCode.'>'.$eol;
1796
+
1797
+ $string .= $prefix. '<unassign'.$relatedCode.' translate="title" module="'.$extension.'">'.$eol;
1798
+ $string .= $prefix.$padding. '<title>Remove '.$relatedLabel.' from '.$entityLabel.'</title>'.$eol;
1799
+ $string .= $prefix.$padding. '<acl>'.$module.'/'.$entity.'/update</acl>'.$eol;
1800
+ $string .= $prefix. '</unassign'.$relatedCode.'>'.$eol;
1801
+ return $string;
1802
+ }
1803
+
1804
+ /**
1805
+ * get API xml for entity relations
1806
+ *
1807
+ * @access public
1808
+ * @return string
1809
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1810
+ */
1811
+ public function getApiRelations()
1812
+ {
1813
+ $string = '';
1814
+ if ($this->getLinkProduct()) {
1815
+ $string .= $this->getApiRelationsSection('Product', 'product');
1816
+ }
1817
+ if ($this->getLinkCategory()) {
1818
+ $string .= $this->getApiRelationsSection('Category', 'category');
1819
+ }
1820
+ $siblings = $this->getRelatedEntities(Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_SIBLING);
1821
+ foreach ($siblings as $sibling) {
1822
+ $siblingNameUc = ucfirst($sibling->getNameSingular());
1823
+ $siblingLabel = strtolower($sibling->getLabelSingular());
1824
+ $string .= $this->getApiRelationsSection($siblingNameUc, $siblingLabel);
1825
+ }
1826
+ $string .= $this->getPadding(4);
1827
+ return $string;
1828
+ }
1829
+
1830
+ /**
1831
+ * get API faults for a section
1832
+ *
1833
+ * @access public
1834
+ * @param $relatedCode
1835
+ * @param $relatedLabel
1836
+ * @param $code
1837
+ * @return string
1838
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1839
+ */
1840
+ public function getApiFaultsSection($relatedCode, $relatedLabel, $code)
1841
+ {
1842
+ $padding = $this->getPadding();
1843
+ $prefix = str_repeat($padding, 5);
1844
+ $eol = $this->getEol();
1845
+ $string = '';
1846
+ $string .= $prefix.'<'.$relatedCode.'_not_exists>'.$eol;
1847
+ $string .= $prefix.$padding.'<code>'.$code.'</code>'.$eol;
1848
+ $string .= $prefix.$padding.'<message>'.$relatedLabel.' does not exist.</message>'.$eol;
1849
+ $string .= $prefix.'</'.$relatedCode.'_not_exists>'.$eol;
1850
+
1851
+ return $string;
1852
+ }
1853
+
1854
+ /**
1855
+ * get list of faults for API
1856
+ *
1857
+ * @access public
1858
+ * @return string
1859
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1860
+ */
1861
+ public function getApiFaults()
1862
+ {
1863
+ $string = '';
1864
+ $padding = $this->getPadding();
1865
+ $prefix = str_repeat($padding, 5);
1866
+ $eol = $this->getEol();
1867
+ $code = 105;
1868
+ $entity = $this->getNameSingular(true);
1869
+ $entityLabelUc = ucfirst($this->getLabelSingular());
1870
+ if ($this->getIsTree()) {
1871
+ $string .= $prefix.'<not_moved>'.$eol;
1872
+ $string .= $prefix.$padding.'<code>'.$code.'</code>'.$eol;
1873
+ $string .= $prefix.$padding.'<message>'.
1874
+ $entityLabelUc.' not moved. Details in error message.</message>'.$eol;
1875
+ $string .= $prefix.'</not_moved>'.$eol;
1876
+ $code++;
1877
+ }
1878
+ if ($this->getLinkProduct()) {
1879
+ $string .= $this->getApiFaultsSection('product', 'Product', $code);
1880
+ $code++;
1881
+ }
1882
+ if ($this->getLinkCategory()) {
1883
+ $string .= $this->getApiFaultsSection('category', 'Category', $code);
1884
+ $code++;
1885
+ }
1886
+ $siblings = $this->getRelatedEntities(
1887
+ Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_SIBLING
1888
+ );
1889
+ foreach ($siblings as $sibling) {
1890
+ $siblingName = $sibling->getNameSingular(true);
1891
+ $siblingLabelUc = ucfirst($sibling->getLabelSingular());
1892
+
1893
+ $string .= $this->getApiFaultsSection($entity.'_'.$siblingName, $siblingLabelUc, $code);
1894
+ $code++;
1895
+ }
1896
+ $string .= $this->getTypeInstance()->getApiFaults();
1897
+ $string .= str_repeat($padding, 4);
1898
+ return $string;
1899
+ }
1900
+
1901
+ /**
1902
+ * get additional api acl
1903
+ *
1904
+ * @access public
1905
+ * @return string
1906
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1907
+ */
1908
+ public function getAdditionalApiAcl()
1909
+ {
1910
+ $content = '';
1911
+ $padding = $this->getPadding();
1912
+ $prefix = str_repeat($padding, 6);
1913
+ $eol = $this->getEol();
1914
+ $extension = $this->getModule()->getExtensionName(true);
1915
+ if ($this->getIsTree()) {
1916
+ $content .= $prefix.'<move translate="title" module="'.$extension.'">'.$eol;
1917
+ $content .= $prefix.$padding.'<title>Move</title>'.$eol;
1918
+ $content .= $prefix.'</move>'.$eol;
1919
+ }
1920
+ $content .= str_repeat($padding, 5);
1921
+ return $content;
1922
+ }
1923
+
1924
+ /**
1925
+ * get attributes format for wsdl
1926
+ *
1927
+ * @access public
1928
+ * @param bool $wsi
1929
+ * @param bool $forAdd
1930
+ * @return string
1931
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1932
+ */
1933
+ public function getWsdlAttributes($wsi = false, $forAdd = false)
1934
+ {
1935
+ $parents = $this->getRelatedEntities(
1936
+ Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_CHILD
1937
+ );
1938
+ $tab = $this->getPadding();
1939
+ $padding = str_repeat($tab, 5);
1940
+ $eol = $this->getEol();
1941
+ $content = '';
1942
+ foreach ($parents as $parent) {
1943
+ /** @var Ultimate_ModuleCreator_Model_Attribute $attr */
1944
+ $attr = Mage::getModel('modulecreator/attribute');
1945
+ $attr->setCode($parent->getNameSingular().'_id');
1946
+ $attr->setLabel($parent->getLabelSingular());
1947
+ $attr->setType('int');
1948
+ $content .= $padding.$attr->getWsdlFormat($wsi).$eol;
1949
+ }
1950
+ foreach ($this->getAttributes() as $attribute) {
1951
+ $content .= $padding.$attribute->getWsdlFormat($wsi).$eol;
1952
+ }
1953
+ $simulated = $this->getSimulatedAttributes(null, false);
1954
+ foreach ($simulated as $attr) {
1955
+ if (!$forAdd || !$attr->getIgnoreApi()) {
1956
+ $content .= $padding.$attr->getWsdlFormat($wsi).$eol;
1957
+ }
1958
+ }
1959
+ $content .= $this->getTypeInstance()->getWsdlAttributes($wsi);
1960
+ return $content;
1961
+ }
1962
+
1963
+ /**
1964
+ * get attributes format for wsi
1965
+ *
1966
+ * @access public
1967
+ * @param bool $forAdd
1968
+ * @return string
1969
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1970
+ */
1971
+ public function getWsiAttributes($forAdd = false)
1972
+ {
1973
+ return $this->getWsdlAttributes(true, $forAdd);
1974
+ }
1975
+
1976
+ /**
1977
+ * get wsdl relation type for a section
1978
+ *
1979
+ * @param $relatedCode
1980
+ * @param $relatedId
1981
+ * @param bool $wsi
1982
+ * @return string
1983
+ */
1984
+ public function getWsdlRelationTypesSection($relatedCode, $relatedId, $wsi = false)
1985
+ {
1986
+ $content = '';
1987
+ $tab = $this->getPadding();
1988
+ $padding = str_repeat($tab, 3);
1989
+ $mainTag = ($wsi) ? 'xsd:complexType':'complexType';
1990
+ $subtag = ($wsi) ? 'xsd:sequence' : 'all';
1991
+ $element = ($wsi) ? 'xsd:element' : 'element';
1992
+ $eol = $this->getEol();
1993
+ $module = $this->getModule()->getLowerModuleName();
1994
+ $entity = $this->getNameSingular(true);
1995
+ $entityUc = ucfirst($this->getNameSingular());
1996
+
1997
+ $content .= $padding.'<'.$mainTag .' name="'.$module.$entityUc.'Assign'.$relatedCode.'Entity">'.$eol;
1998
+ $content .= $padding.$tab.'<'.$subtag.'>'.$eol;
1999
+ $content .= $padding.$tab.'<'.$element.' name="'.$entity.'Id" type="xsd:string"'.
2000
+ ((!$wsi)?' minOccurs="1"':'').' />'.$eol;
2001
+ $content .= $padding.$tab.'<'.$element.' name="'.$relatedId.'Id" type="xsd:string"'.
2002
+ ((!$wsi)?' minOccurs="1"':'').' />'.$eol;
2003
+ $content .= $padding.$tab.'<'.$element.' name="position" type="xsd:string"'.
2004
+ ((!$wsi)?' minOccurs="0"':'').' />'.$eol;
2005
+ $content .= $padding.$tab.'</'.$subtag.'>'.$eol;
2006
+ $content .= $padding.'</'.$mainTag.'>'.$eol;
2007
+
2008
+ $content .= $padding.'<'.$mainTag .' name="'.$module.$entityUc.'Unassign'.$relatedCode.'Entity">'.$eol;
2009
+ $content .= $padding.$tab.'<'.$subtag.'>'.$eol;
2010
+ $content .= $padding.$tab.'<'.$element.' name="'.
2011
+ $entity.'Id" type="xsd:string"'.((!$wsi)?' minOccurs="1"':'').' />'.$eol;
2012
+ $content .= $padding.$tab.'<'.$element.' name="'.
2013
+ $relatedId.'Id" type="xsd:string"'.((!$wsi)?' minOccurs="1"':'').' />'.$eol;
2014
+ $content .= $padding.$tab.'</'.$subtag.'>'.$eol;
2015
+ $content .= $padding.'</'.$mainTag.'>'.$eol;
2016
+
2017
+ return $content;
2018
+ }
2019
+
2020
+ /**
2021
+ * get entity WSDL relation types
2022
+ *
2023
+ * @access public
2024
+ * @param bool $wsi
2025
+ * @return string
2026
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2027
+ */
2028
+ public function getWsdlRelationTypes($wsi = false)
2029
+ {
2030
+ $content = '';
2031
+ $tab = $this->getPadding();
2032
+ $padding = str_repeat($tab, 3);
2033
+ $mainTag = ($wsi) ? 'xsd:complexType':'complexType';
2034
+ $subtag = ($wsi) ? 'xsd:sequence' : 'all';
2035
+ $element = ($wsi) ? 'xsd:element' : 'element';
2036
+ $eol = $this->getEol();
2037
+ $module = $this->getModule()->getLowerModuleName();
2038
+ $entity = $this->getNameSingular(true);
2039
+ $entityUc = ucfirst($this->getNameSingular());
2040
+ if ($this->getIsTree()) {
2041
+ $content .= $padding.'<'.$mainTag .' name="'.$module.$entityUc.'MoveEntity">'.$eol;
2042
+ $content .= $padding.$tab.'<'.$subtag.'>'.$eol;
2043
+ $content .= $padding.$tab.'<'.$element.
2044
+ ' name="'.$entity.'_id" type="xsd:string"'.((!$wsi)?' minOccurs="1"':'').' />'.$eol;
2045
+ $content .= $padding.$tab.'<'.$element.
2046
+ ' name="parent_id" type="xsd:string"'.((!$wsi)?' minOccurs="1"':'').' />'.$eol;
2047
+ $content .= $padding.$tab.'<'.$element.
2048
+ ' name="after_id" type="xsd:string"'.((!$wsi)?' minOccurs="0"':'').' />'.$eol;
2049
+ $content .= $padding.$tab.'</'.$subtag.'>'.$eol;
2050
+ $content .= $padding.'</'.$mainTag.'>'.$eol;
2051
+ }
2052
+ if ($this->getLinkProduct()) {
2053
+ $content .= $this->getWsdlRelationTypesSection('Product', 'product', $wsi);
2054
+ }
2055
+ if ($this->getLinkCategory()) {
2056
+ $content .= $this->getWsdlRelationTypesSection('Category', 'category', $wsi);
2057
+ }
2058
+ $siblings = $this->getRelatedEntities(
2059
+ Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_SIBLING
2060
+ );
2061
+ foreach ($siblings as $sibling) {
2062
+ $siblingName = $sibling->getNameSingular(true);
2063
+ $siblingNameUc = ucfirst($sibling->getNameSingular());
2064
+ $content .= $this->getWsdlRelationTypesSection($siblingNameUc, $siblingName, $wsi);
2065
+
2066
+ }
2067
+ $content .= $tab.$tab;
2068
+ return $content;
2069
+ }
2070
+
2071
+ /**
2072
+ * get entity WSI relation types
2073
+ *
2074
+ * @access public
2075
+ * @return string
2076
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2077
+ */
2078
+ public function getWsiRelationTypes()
2079
+ {
2080
+ return $this->getWsdlRelationTypes(true);
2081
+ }
2082
+
2083
+ /**
2084
+ * get wsdl port type relations for a section
2085
+ *
2086
+ * @access public
2087
+ * @param $relatedLabel
2088
+ * @param $relatedText
2089
+ * @param $wsi
2090
+ * @return string
2091
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2092
+ */
2093
+ public function getWsdlPortTypeRelationSection($relatedLabel, $relatedText, $wsi)
2094
+ {
2095
+ $content = '';
2096
+ $tab = $this->getPadding();
2097
+ $padding = $tab.$tab;
2098
+ $eol = $this->getEol();
2099
+ $module = $this->getModule()->getLowerModuleName();
2100
+ $entityUc = ucfirst($this->getNameSingular());
2101
+ $label = strtolower($this->getLabelSingular());
2102
+ $tagPrefix = ($wsi) ? 'wsdl:':'';
2103
+
2104
+ $content .= $padding.'<'.$tagPrefix.'operation name="'.$module.$entityUc.'Assign'.$relatedLabel.'">'.$eol;
2105
+ $content .= $padding.$tab.'<'.$tagPrefix.'documentation>Assign '.
2106
+ $relatedText.' to '.$label.'</'.$tagPrefix.'documentation>'.$eol;
2107
+ $content .= $padding.$tab.'<'.$tagPrefix.'input message="typens:'.
2108
+ $module.$entityUc.'Assign'.$relatedLabel.'Request" />'.$eol;
2109
+ $content .= $padding.$tab.'<'.$tagPrefix.'output message="typens:'.
2110
+ $module.$entityUc.'Assign'.$relatedLabel.'Response" />'.$eol;
2111
+ $content .= $padding.'</'.$tagPrefix.'operation>'.$eol;
2112
+ $content .= $padding.'<'.$tagPrefix.'operation name="'.$module.$entityUc.'Unassign'.$relatedLabel.'">'.$eol;
2113
+ $content .= $padding.$tab.'<'.$tagPrefix.'documentation>Remove '.
2114
+ $relatedText.' from '.$label.'</'.$tagPrefix.'documentation>'.$eol;
2115
+ $content .= $padding.$tab.'<'.$tagPrefix.'input message="typens:'.
2116
+ $module.$entityUc.'Unassign'.$relatedLabel.'Request" />'.$eol;
2117
+ $content .= $padding.$tab.'<'.$tagPrefix.'output message="typens:'.
2118
+ $module.$entityUc.'Unassign'.$relatedLabel.'Response" />'.$eol;
2119
+ $content .= $padding.'</'.$tagPrefix.'operation>'.$eol;
2120
+
2121
+ return $content;
2122
+ }
2123
+
2124
+ /**
2125
+ * get entity WSDL port type for relations
2126
+ *
2127
+ * @access public
2128
+ * @param bool $wsi
2129
+ * @return string
2130
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2131
+ */
2132
+ public function getWsdlPortTypeRelation($wsi = false)
2133
+ {
2134
+ $content = '';
2135
+ $tab = $this->getPadding();
2136
+ $padding = $tab.$tab;
2137
+ $eol = $this->getEol();
2138
+ $module = $this->getModule()->getLowerModuleName();
2139
+ $entity = $this->getNameSingular(true);
2140
+ $entityUc = ucfirst($entity);
2141
+ $label = strtolower($this->getLabelSingular());
2142
+
2143
+ $tagPrefix = ($wsi) ? 'wsdl:':'';
2144
+
2145
+ if ($this->getIsTree()) {
2146
+ $content .= $padding.'<'.$tagPrefix.'operation name="'.$module.$entityUc.'Move">'.$eol;
2147
+ $content .= $padding.$tab.'<'.$tagPrefix.'documentation>Move '.$label.
2148
+ ' in tree</'.$tagPrefix.'documentation>'.$eol;
2149
+ $content .= $padding.$tab.'<'.$tagPrefix.'input message="typens:'.$module.$entityUc.'MoveRequest" />'.$eol;
2150
+ $content .= $padding.$tab.'<'.$tagPrefix.'output message="typens:'.
2151
+ $module.$entityUc.'MoveResponse" />'.$eol;
2152
+ $content .= $padding.'</'.$tagPrefix.'operation>'.$eol;
2153
+
2154
+ }
2155
+
2156
+ if ($this->getLinkProduct()) {
2157
+ $content .= $this->getWsdlPortTypeRelationSection('Product', 'product', $wsi);
2158
+ }
2159
+
2160
+ if ($this->getLinkCategory()) {
2161
+ $content .= $this->getWsdlPortTypeRelationSection('Category', 'category', $wsi);
2162
+ }
2163
+ $siblings = $this->getRelatedEntities(
2164
+ Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_SIBLING
2165
+ );
2166
+ foreach ($siblings as $sibling) {
2167
+ $siblingNameUc = ucfirst($sibling->getNameSingular());
2168
+ $siblingLabel = strtolower($sibling->getLabelSingular());
2169
+
2170
+ $content .= $this->getWsdlPortTypeRelationSection($siblingNameUc, $siblingLabel, $wsi);
2171
+
2172
+ }
2173
+ $content .= $tab;
2174
+ return $content;
2175
+ }
2176
+
2177
+ /**
2178
+ * get entity WSI port type for relations
2179
+ *
2180
+ * @access public
2181
+ * @return string
2182
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2183
+ */
2184
+ public function getWsiPortTypeRelation()
2185
+ {
2186
+ return $this->getWsdlPortTypeRelation(true);
2187
+ }
2188
+
2189
+ /**
2190
+ * get wsld relation binding for a section
2191
+ *
2192
+ * @access public
2193
+ * @param $sectionName
2194
+ * @return string
2195
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2196
+ */
2197
+ public function getWsdlRelationBindingSection($sectionName)
2198
+ {
2199
+ $content = '';
2200
+ $tab = $this->getPadding();
2201
+ $doubleTab = $tab.$tab;
2202
+ $padding = $doubleTab;
2203
+ $eol = $this->getEol();
2204
+ $module = $this->getModule()->getLowerModuleName();
2205
+ $entity = $this->getNameSingular(true);
2206
+ $entityUc = ucfirst($entity);
2207
+
2208
+ $content .= $padding.'<operation name="'.$module.$entityUc.$sectionName.'">'.$eol;
2209
+ $content .= $padding.$tab.'<soap:operation soapAction="urn:{{var wsdl.handler}}Action" />'.$eol;
2210
+ $content .= $padding.$tab.'<input>'.$eol;
2211
+ $content .= $padding.$doubleTab.
2212
+ '<soap:body namespace="urn:{{var wsdl.name}}"'.
2213
+ ' use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />'.
2214
+ $eol;
2215
+ $content .= $padding.$tab.'</input>'.$eol;
2216
+ $content .= $padding.$tab.'<output>'.$eol;
2217
+ $content .= $padding.$doubleTab.
2218
+ '<soap:body namespace="urn:{{var wsdl.name}}"'.
2219
+ ' use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />'.
2220
+ $eol;
2221
+ $content .= $padding.$tab.'</output>'.$eol;
2222
+ $content .= $padding.'</operation>'.$eol;
2223
+ return $content;
2224
+ }
2225
+
2226
+ /**
2227
+ * get WSDL relation binding
2228
+ *
2229
+ * @access public
2230
+ * @return string
2231
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2232
+ */
2233
+ public function getWsdlRelationBinding()
2234
+ {
2235
+ $content = '';
2236
+ if ($this->getIsTree()) {
2237
+ $content .= $this->getWsdlRelationBindingSection('Move');
2238
+ }
2239
+ if ($this->getLinkProduct()) {
2240
+ $content .= $this->getWsdlRelationBindingSection('AssignProduct');
2241
+ $content .= $this->getWsdlRelationBindingSection('UnassignProduct');
2242
+ }
2243
+ if ($this->getLinkCategory()) {
2244
+ $content .= $this->getWsdlRelationBindingSection('AssignCategory');
2245
+ $content .= $this->getWsdlRelationBindingSection('UnassignCategory');
2246
+ }
2247
+
2248
+ $siblings = $this->getRelatedEntities(
2249
+ Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_SIBLING
2250
+ );
2251
+ foreach ($siblings as $sibling) {
2252
+ $siblingName = $sibling->getNameSingular(true);
2253
+ $siblingNameUc = ucfirst($siblingName);
2254
+ $content .= $this->getWsdlRelationBindingSection('Assign'.$siblingNameUc);
2255
+ $content .= $this->getWsdlRelationBindingSection('Unassign'.$siblingNameUc);
2256
+ }
2257
+ $content .= $this->getPadding();
2258
+ return $content;
2259
+ }
2260
+
2261
+ /**
2262
+ * get wsld relation binding for a section
2263
+ *
2264
+ * @access public
2265
+ * @param $sectionName
2266
+ * @return string
2267
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2268
+ */
2269
+ public function getWsiRelationBindingSection($sectionName)
2270
+ {
2271
+ $content = '';
2272
+ $tab = $this->getPadding();
2273
+ $doubleTab = $tab.$tab;
2274
+ $padding = $doubleTab;
2275
+ $eol = $this->getEol();
2276
+ $module = $this->getModule()->getLowerModuleName();
2277
+ $entity = $this->getNameSingular(true);
2278
+ $entityUc = ucfirst($entity);
2279
+
2280
+ $content .= $padding.'<wsdl:operation name="'.$module.$entityUc.$sectionName.'">'.$eol;
2281
+ $content .= $padding.$tab.'<soap:operation soapAction="" />'.$eol;
2282
+ $content .= $padding.$tab.'<wsdl:input>'.$eol;
2283
+ $content .= $padding.$doubleTab.'<soap:body use="literal" />'.$eol;
2284
+ $content .= $padding.$tab.'</wsdl:input>'.$eol;
2285
+ $content .= $padding.$tab.'<wsdl:output>'.$eol;
2286
+ $content .= $padding.$doubleTab.'<soap:body use="literal" />'.$eol;
2287
+ $content .= $padding.$tab.'</wsdl:output>'.$eol;
2288
+ $content .= $padding.'</wsdl:operation>'.$eol;
2289
+ return $content;
2290
+ }
2291
+
2292
+ /**
2293
+ * get WSI relation binding
2294
+ *
2295
+ * @access public
2296
+ * @return string
2297
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2298
+ */
2299
+ public function getWsiRelationBinding()
2300
+ {
2301
+ $content = '';
2302
+ if ($this->getIsTree()) {
2303
+ $content .= $this->getWsiRelationBindingSection('Move');
2304
+ }
2305
+ if ($this->getLinkProduct()) {
2306
+ $content .= $this->getWsiRelationBindingSection('AssignProduct');
2307
+ $content .= $this->getWsiRelationBindingSection('UnassignProduct');
2308
+ }
2309
+ if ($this->getLinkCategory()) {
2310
+ $content .= $this->getWsiRelationBindingSection('AssignCategory');
2311
+ $content .= $this->getWsiRelationBindingSection('UnassignCategory');
2312
+ }
2313
+
2314
+ $siblings = $this->getRelatedEntities(
2315
+ Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_SIBLING
2316
+ );
2317
+ foreach ($siblings as $sibling) {
2318
+ $siblingName = $sibling->getNameSingular(true);
2319
+ $siblingNameUc = ucfirst($siblingName);
2320
+
2321
+ $content .= $this->getWsiRelationBindingSection('Assign'.$siblingNameUc);
2322
+ $content .= $this->getWsiRelationBindingSection('Unassign'.$siblingNameUc);
2323
+ }
2324
+ $content .= $this->getPadding();
2325
+ return $content;
2326
+ }
2327
+
2328
+ /**
2329
+ * get wsi relation param types for a section
2330
+ *
2331
+ * @access public
2332
+ * @param $sectionName
2333
+ * @param $sectionParam
2334
+ * @return string
2335
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2336
+ */
2337
+ public function getWsiRelationParamTypesSection($sectionName, $sectionParam)
2338
+ {
2339
+ $content = '';
2340
+ $tab = $this->getPadding();
2341
+ $padding = $this->getPadding(3);
2342
+ $eol = $this->getEol();
2343
+ $module = $this->getModule()->getLowerModuleName();
2344
+ $entity = $this->getNameSingular(true);
2345
+ $entityUc = ucfirst($entity);
2346
+ $content .= $padding.'<xsd:element name="'.$module.$entityUc.'Assign'.$sectionName.'RequestParam">'.$eol;
2347
+ $content .= $padding.$tab.'<xsd:complexType>'.$eol;
2348
+ $content .= $padding.str_repeat($tab, 2).'<xsd:sequence>'.$eol;
2349
+ $content .= $padding.str_repeat($tab, 3).
2350
+ '<xsd:element minOccurs="1" maxOccurs="1" name="sessionId" type="xsd:string" />'.$eol;
2351
+ $content .= $padding.str_repeat($tab, 3).
2352
+ '<xsd:element minOccurs="1" maxOccurs="1" name="'.$entity.'Id" type="xsd:string" />'.$eol;
2353
+ $content .= $padding.str_repeat($tab, 3).
2354
+ '<xsd:element minOccurs="1" maxOccurs="1" name="'.$sectionParam.'Id" type="xsd:string" />'.$eol;
2355
+ $content .= $padding.str_repeat($tab, 3).
2356
+ '<xsd:element minOccurs="0" maxOccurs="1" name="position" type="xsd:string" />'.$eol;
2357
+ $content .= $padding.str_repeat($tab, 2).'</xsd:sequence>'.$eol;
2358
+ $content .= $padding.$tab.'</xsd:complexType>'.$eol;
2359
+ $content .= $padding.'</xsd:element>'.$eol;
2360
+
2361
+ $content .= $padding.'<xsd:element name="'.$module.$entityUc.'Assign'.$sectionName.'ResponseParam">'.$eol;
2362
+ $content .= $padding.$tab.'<xsd:complexType>'.$eol;
2363
+ $content .= $padding.str_repeat($tab, 2).'<xsd:sequence>'.$eol;
2364
+ $content .= $padding.str_repeat($tab, 3).
2365
+ '<xsd:element minOccurs="1" maxOccurs="1" name="result" type="xsd:boolean" />'.$eol;
2366
+ $content .= $padding.str_repeat($tab, 2).'</xsd:sequence>'.$eol;
2367
+ $content .= $padding.$tab.'</xsd:complexType>'.$eol;
2368
+ $content .= $padding.'</xsd:element>'.$eol;
2369
+
2370
+ $content .= $padding.'<xsd:element name="'.$module.$entityUc.'Unassign'.$sectionName.'RequestParam">'.$eol;
2371
+ $content .= $padding.$tab.'<xsd:complexType>'.$eol;
2372
+ $content .= $padding.str_repeat($tab, 2).'<xsd:sequence>'.$eol;
2373
+ $content .= $padding.str_repeat($tab, 3).
2374
+ '<xsd:element minOccurs="1" maxOccurs="1" name="sessionId" type="xsd:string" />'.$eol;
2375
+ $content .= $padding.str_repeat($tab, 3).
2376
+ '<xsd:element minOccurs="1" maxOccurs="1" name="'.$entity.'Id" type="xsd:string" />'.$eol;
2377
+ $content .= $padding.str_repeat($tab, 3).
2378
+ '<xsd:element minOccurs="1" maxOccurs="1" name="'.$sectionParam.'Id" type="xsd:string" />'.$eol;
2379
+ $content .= $padding.str_repeat($tab, 2).'</xsd:sequence>'.$eol;
2380
+ $content .= $padding.$tab.'</xsd:complexType>'.$eol;
2381
+ $content .= $padding.'</xsd:element>'.$eol;
2382
+
2383
+ $content .= $padding.'<xsd:element name="'.$module.$entityUc.'Unassign'.$sectionName.'ResponseParam">'.$eol;
2384
+ $content .= $padding.$tab.'<xsd:complexType>'.$eol;
2385
+ $content .= $padding.str_repeat($tab, 2).'<xsd:sequence>'.$eol;
2386
+ $content .= $padding.str_repeat($tab, 3).
2387
+ '<xsd:element minOccurs="1" maxOccurs="1" name="result" type="xsd:boolean" />'.$eol;
2388
+ $content .= $padding.str_repeat($tab, 2).'</xsd:sequence>'.$eol;
2389
+ $content .= $padding.$tab.'</xsd:complexType>'.$eol;
2390
+ $content .= $padding.'</xsd:element>'.$eol;
2391
+
2392
+ return $content;
2393
+ }
2394
+
2395
+ /**
2396
+ * get entity WSI relation param types
2397
+ *
2398
+ * @access public
2399
+ * @return string
2400
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2401
+ */
2402
+ public function getWsiRelationParamTypes()
2403
+ {
2404
+ $content = '';
2405
+ $tab = $this->getPadding();
2406
+ $padding = str_repeat($tab, 3);
2407
+ $eol = $this->getEol();
2408
+ $module = $this->getModule()->getLowerModuleName();
2409
+ $entity = $this->getNameSingular(true);
2410
+ $entityUc = ucfirst($entity);
2411
+
2412
+ if ($this->getIsTree()) {
2413
+ $content .= $padding.'<xsd:element name="'.$module.$entityUc.'MoveRequestParam">'.$eol;
2414
+ $content .= $padding.$tab.'<xsd:complexType>'.$eol;
2415
+ $content .= $padding.str_repeat($tab, 2).'<xsd:sequence>'.$eol;
2416
+ $content .= $padding.str_repeat($tab, 3).
2417
+ '<xsd:element minOccurs="1" maxOccurs="1" name="session_id" type="xsd:string" />'.$eol;
2418
+ $content .= $padding.str_repeat($tab, 3).
2419
+ '<xsd:element minOccurs="1" maxOccurs="1" name="'.$entity.'Id" type="xsd:string" />'.$eol;
2420
+ $content .= $padding.str_repeat($tab, 3).
2421
+ '<xsd:element minOccurs="1" maxOccurs="1" name="parentId" type="xsd:string" />'.$eol;
2422
+ $content .= $padding.str_repeat($tab, 3).
2423
+ '<xsd:element minOccurs="0" maxOccurs="1" name="afterId" type="xsd:string" />'.$eol;
2424
+ $content .= $padding.str_repeat($tab, 2).'</xsd:sequence>'.$eol;
2425
+ $content .= $padding.$tab.'</xsd:complexType>'.$eol;
2426
+ $content .= $padding.'</xsd:element>'.$eol;
2427
+
2428
+ $content .= $padding.'<xsd:element name="'.$module.$entityUc.'AssignProductResponseParam">'.$eol;
2429
+ $content .= $padding.$tab.'<xsd:complexType>'.$eol;
2430
+ $content .= $padding.str_repeat($tab, 2).'<xsd:sequence>'.$eol;
2431
+ $content .= $padding.str_repeat($tab, 3).
2432
+ '<xsd:element minOccurs="1" maxOccurs="1" name="result" type="xsd:boolean" />'.$eol;
2433
+ $content .= $padding.str_repeat($tab, 2).'</xsd:sequence>'.$eol;
2434
+ $content .= $padding.$tab.'</xsd:complexType>'.$eol;
2435
+ $content .= $padding.'</xsd:element>'.$eol;
2436
+ }
2437
+
2438
+ if ($this->getLinkProduct()) {
2439
+ $content .= $this->getWsiRelationParamTypesSection('Product', 'product');
2440
+ }
2441
+
2442
+ if ($this->getLinkCategory()) {
2443
+ $content .= $this->getWsiRelationParamTypesSection('Category', 'category');
2444
+ }
2445
+
2446
+ $siblings = $this->getRelatedEntities(
2447
+ Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_SIBLING
2448
+ );
2449
+ foreach ($siblings as $sibling) {
2450
+ $siblingName = $sibling->getNameSingular(true);
2451
+ $siblingNameUc = ucfirst($siblingName);
2452
+ $content .= $this->getWsiRelationParamTypesSection($siblingNameUc, $siblingName);
2453
+ }
2454
+ $content .= $tab.$tab;
2455
+ return $content;
2456
+ }
2457
+
2458
+ /**
2459
+ * get wsi relation messaged for a section
2460
+ *
2461
+ * @param $sectionName
2462
+ * @return string
2463
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2464
+ */
2465
+ public function getWsiRelationMessagesSection($sectionName)
2466
+ {
2467
+ $content = '';
2468
+ $padding = $this->getPadding();
2469
+ $tab = $padding;
2470
+ $eol = $this->getEol();
2471
+ $module = $this->getModule()->getLowerModuleName();
2472
+ $entity = $this->getNameSingular(true);
2473
+ $entityUc = ucfirst($entity);
2474
+
2475
+ $content .= $padding.'<wsdl:message name="'.$module.$entityUc.$sectionName.'Request">'.$eol;
2476
+ $content .= $padding.$tab.'<wsdl:part name="parameters" element="typens:'.
2477
+ $module.$entityUc.$sectionName.'RequestParam" />'.$eol;
2478
+ $content .= $padding.'</wsdl:message>'.$eol;
2479
+ $content .= $padding.'<wsdl:message name="'.$module.$entityUc.$sectionName.'Response">'.$eol;
2480
+ $content .= $padding.$tab.'<wsdl:part name="parameters" element="typens:'.
2481
+ $module.$entityUc.$sectionName.'ResponseParam" />'.$eol;
2482
+ $content .= $padding.'</wsdl:message>'.$eol;
2483
+
2484
+ return $content;
2485
+ }
2486
+
2487
+ /**
2488
+ * get entity WSI relation messages
2489
+ *
2490
+ * @access public
2491
+ * @return string
2492
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2493
+ */
2494
+ public function getWsiRelationMessages()
2495
+ {
2496
+ $content = '';
2497
+ if ($this->getIsTree()) {
2498
+ $content .= $this->getWsiRelationMessagesSection('Move');
2499
+ }
2500
+
2501
+ if ($this->getLinkProduct()) {
2502
+ $content .= $this->getWsiRelationMessagesSection('AssignProduct');
2503
+ $content .= $this->getWsiRelationMessagesSection('UnassignProduct');
2504
+ }
2505
+
2506
+ if ($this->getLinkCategory()) {
2507
+ $content .= $this->getWsiRelationMessagesSection('AssignCategory');
2508
+ $content .= $this->getWsiRelationMessagesSection('UnassignCategory');
2509
+ }
2510
+ $siblings = $this->getRelatedEntities(Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_SIBLING);
2511
+ foreach ($siblings as $sibling) {
2512
+ $siblingName = $sibling->getNameSingular(true);
2513
+ $siblingNameUc = ucfirst($siblingName);
2514
+
2515
+ $content .= $this->getWsiRelationMessagesSection('Assign'.$siblingNameUc);
2516
+ $content .= $this->getWsiRelationMessagesSection('Unassign'.$siblingNameUc);
2517
+ }
2518
+ return $content;
2519
+ }
2520
+
2521
+ /**
2522
+ * get wsdl messages for a section
2523
+ *
2524
+ * @param $sectionName
2525
+ * @param $sectionParam
2526
+ * @return string
2527
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2528
+ */
2529
+ public function getWsdlMessagesSection($sectionName, $sectionParam)
2530
+ {
2531
+ $content = '';
2532
+ $tab = $this->getPadding();
2533
+ $padding = $tab.$tab;
2534
+ $eol = $this->getEol();
2535
+ $module = $this->getModule()->getLowerModuleName();
2536
+ $entity = $this->getNameSingular(true);
2537
+ $entityUc = ucfirst($entity);
2538
+
2539
+ $content .= $padding.'<message name="'.$module.$entityUc.'Assign'.$sectionName.'Request">'.$eol;
2540
+ $content .= $padding.$tab.'<part name="sessionId" type="xsd:string" />'.$eol;
2541
+ $content .= $padding.$tab.'<part name="'.$entity.'_id" type="xsd:string" />'.$eol;
2542
+ $content .= $padding.$tab.'<part name="'.$sectionParam.'_id" type="xsd:string" />'.$eol;
2543
+ $content .= $padding.$tab.'<part name="position" type="xsd:string" />'.$eol;
2544
+ $content .= $padding.'</message>'.$eol;
2545
+ $content .= $padding.'<message name="'.$module.$entityUc.'Assign'.$sectionName.'Response">'.$eol;
2546
+ $content .= $padding.$tab.'<part name="result" type="xsd:boolean" />'.$eol;
2547
+ $content .= $padding.'</message>'.$eol;
2548
+ $content .= $padding.'<message name="'.$module.$entityUc.'Unassign'.$sectionName.'Request">'.$eol;
2549
+ $content .= $padding.$tab.'<part name="session_id" type="xsd:string" />'.$eol;
2550
+ $content .= $padding.$tab.'<part name="'.$entity.'_id" type="xsd:string" />'.$eol;
2551
+ $content .= $padding.$tab.'<part name="'.$sectionParam.'_id" type="xsd:string" />'.$eol;
2552
+ $content .= $padding.'</message>'.$eol;
2553
+ $content .= $padding.'<message name="'.$module.$entityUc.'Unassign'.$sectionName.'Response">'.$eol;
2554
+ $content .= $padding.$tab.'<part name="result" type="xsd:boolean" />'.$eol;
2555
+ $content .= $padding.'</message>'.$eol;
2556
+
2557
+ return $content;
2558
+ }
2559
+
2560
+ /**
2561
+ * get entity WSDL messages for relations
2562
+ *
2563
+ * @access public
2564
+ * @return string
2565
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2566
+ */
2567
+ public function getWsdlMessages()
2568
+ {
2569
+ $content = '';
2570
+ $tab = $this->getPadding();
2571
+ $padding = $tab.$tab;
2572
+ $eol = $this->getEol();
2573
+ $module = $this->getModule()->getLowerModuleName();
2574
+ $entity = $this->getNameSingular(true);
2575
+ $entityUc = ucfirst($entity);
2576
+
2577
+ if ($this->getIsTree()) {
2578
+ $content .= $padding.'<message name="'.$module.$entityUc.'MoveRequest">'.$eol;
2579
+ $content .= $padding.$tab.'<part name="session_id" type="xsd:string" />'.$eol;
2580
+ $content .= $padding.$tab.'<part name="'.$entity.'_id" type="xsd:string" />'.$eol;
2581
+ $content .= $padding.$tab.'<part name="parent_id" type="xsd:string" />'.$eol;
2582
+ $content .= $padding.$tab.'<part name="after_id" type="xsd:string" />'.$eol;
2583
+ $content .= $padding.'</message>'.$eol;
2584
+
2585
+ $content .= $padding.'<message name="'.$module.$entityUc.'MoveResponse">'.$eol;
2586
+ $content .= $padding.$tab.'<part name="id" type="xsd:boolean"/>'.$eol;
2587
+ $content .= $padding.'</message>'.$eol;
2588
+ }
2589
+ if ($this->getLinkProduct()) {
2590
+ $content .= $this->getWsdlMessagesSection('Product', 'product');
2591
+ }
2592
+
2593
+ if ($this->getLinkCategory()) {
2594
+ $content .= $this->getWsdlMessagesSection('Category', 'category');
2595
+ }
2596
+
2597
+ $siblings = $this->getRelatedEntities(
2598
+ Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_SIBLING
2599
+ );
2600
+ foreach ($siblings as $sibling) {
2601
+ $siblingName = $sibling->getNameSingular(true);
2602
+ $siblingNameUc = ucfirst($siblingName);
2603
+
2604
+ $content .= $this->getWsdlMessagesSection($siblingNameUc, $siblingName);
2605
+ }
2606
+ $content .= $tab;
2607
+ return $content;
2608
+ }
2609
+ /**
2610
+ * get foreign keys for sql (Ddl)
2611
+ *
2612
+ * @access public
2613
+ * @return string
2614
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2615
+ */
2616
+ public function getParentEntitiesFksDdl()
2617
+ {
2618
+ $padding = $this->getPadding();
2619
+ $eol = $this->getEol();
2620
+ $parents = $this->getRelatedEntities(
2621
+ Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_CHILD
2622
+ );
2623
+ $content = '';
2624
+
2625
+ $module = $this->getModule()->getLowerModuleName();
2626
+ $namespace = $this->getNamespace(true);
2627
+ foreach ($parents as $parent) {
2628
+ $parentName = $parent->getNameSingular(true);
2629
+ $content .= $eol.$padding."->addIndex($"."this->getIdxName('".
2630
+ $namespace.'_'.$module.'/'.$parentName."', array('".$parentName."_id')), array('".
2631
+ $parentName."_id'))";
2632
+ }
2633
+ return $content;
2634
+ }
2635
+
2636
+ /**
2637
+ * get selected menu path
2638
+ *
2639
+ * @access public
2640
+ * @param string $suffix
2641
+ * @return string
2642
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2643
+ */
2644
+ public function getSelectedMenuPath($suffix = '')
2645
+ {
2646
+ $path = $this->getModule()->getMenuParent();
2647
+ if (!empty($path)) {
2648
+ $path .= '/';
2649
+ }
2650
+ $path .= $this->getModule()->getExtensionName(true).'/';
2651
+ $path .= $this->getNameSingular(true);
2652
+
2653
+ return $path . $suffix;
2654
+ }
2655
+
2656
+ /**
2657
+ * get attributes content for setup
2658
+ *
2659
+ * @access public
2660
+ * @return string
2661
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2662
+ */
2663
+ public function getAttributesSetup()
2664
+ {
2665
+ return $this->getTypeInstance()->getAttributesSetup();
2666
+ }
2667
+
2668
+ /**
2669
+ * get parent class for the entity resource model
2670
+ *
2671
+ * @access public
2672
+ * @return string
2673
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2674
+ */
2675
+ public function getResourceModelParent()
2676
+ {
2677
+ return $this->getTypeInstance()->getResourceModelParent();
2678
+ }
2679
+
2680
+ /**
2681
+ * get parent class for the entity resource model
2682
+ *
2683
+ * @access public
2684
+ * @return string
2685
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2686
+ */
2687
+ public function getResourceCollectionModelParent()
2688
+ {
2689
+ return $this->getTypeInstance()->getResourceCollectionModelParent();
2690
+ }
2691
+
2692
+ /**
2693
+ * get related entities relations table
2694
+ *
2695
+ * @access public
2696
+ * @return string
2697
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2698
+ */
2699
+ public function getResourceRelationsTables()
2700
+ {
2701
+ return $this->getTypeInstance()->getResourceRelationsTables();
2702
+ }
2703
+
2704
+ /**
2705
+ * get related entities relations table declaration
2706
+ *
2707
+ * @access public
2708
+ * @return string
2709
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2710
+ */
2711
+ public function getResourceRelationsTablesDeclare()
2712
+ {
2713
+ return $this->getTypeInstance()->getResourceRelationsTablesDeclare();
2714
+ }
2715
+
2716
+ /**
2717
+ * get admin layout content for index page
2718
+ *
2719
+ * @access public
2720
+ * @return string
2721
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2722
+ */
2723
+ public function getAdminIndexLayoutContent()
2724
+ {
2725
+ return $this->getTypeInstance()->getAdminIndexLayoutContent();
2726
+ }
2727
+
2728
+ /**
2729
+ * get the parent model class
2730
+ *
2731
+ * @access public
2732
+ * @return mixed
2733
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2734
+ */
2735
+ public function getEntityParentModel()
2736
+ {
2737
+ return $this->getTypeInstance()->getEntityParentModel();
2738
+ }
2739
+
2740
+ /**
2741
+ * get entity table alias
2742
+ *
2743
+ * @access public
2744
+ * @return mixed
2745
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2746
+ */
2747
+ public function getEntityTableAlias()
2748
+ {
2749
+ return $this->getTypeInstance()->getEntityTableAlias();
2750
+ }
2751
+
2752
+ /**
2753
+ * get additional prepare collection
2754
+ *
2755
+ * @access public
2756
+ * @return mixed
2757
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2758
+ */
2759
+ public function getAdditionalPrepareCollection()
2760
+ {
2761
+ return $this->getTypeInstance()->getAdditionalPrepareCollection();
2762
+ }
2763
+
2764
+ /**
2765
+ * additional layout block for left section
2766
+ *
2767
+ * @access public
2768
+ * @return mixed
2769
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2770
+ */
2771
+ public function getEditLayoutLeft()
2772
+ {
2773
+ return $this->getTypeInstance()->getEditLayoutLeft();
2774
+ }
2775
+
2776
+ /**
2777
+ * additional layout block edit
2778
+ *
2779
+ * @access public
2780
+ * @return mixed
2781
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2782
+ */
2783
+ public function getEditLayoutAdditional()
2784
+ {
2785
+ return $this->getTypeInstance()->getEditLayoutAdditional();
2786
+ }
2787
+
2788
+ /**
2789
+ * get the label for product attribute scope
2790
+ *
2791
+ * @access public
2792
+ * @return string
2793
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2794
+ */
2795
+ public function getProductAttributeScopeLabel()
2796
+ {
2797
+ return $this->_getScopeLabel($this->getProductAttributeScope());
2798
+ }
2799
+
2800
+ /**
2801
+ * get the label for category attribute scope
2802
+ *
2803
+ * @access public
2804
+ * @return string
2805
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2806
+ */
2807
+ public function getCategoryAttributeScopeLabel()
2808
+ {
2809
+ return $this->_getScopeLabel($this->getCategoryAttributeScope());
2810
+ }
2811
+
2812
+ /**
2813
+ * get scope label for install scripts
2814
+ *
2815
+ * @param $value
2816
+ * @return string
2817
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2818
+ */
2819
+ protected function _getScopeLabel($value)
2820
+ {
2821
+ $values = array(
2822
+ Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE =>
2823
+ 'Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE',
2824
+ Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE =>
2825
+ 'Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE',
2826
+ Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL =>
2827
+ 'Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL'
2828
+ );
2829
+ if (!isset($values[$value])) {
2830
+ $value = Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL;
2831
+ }
2832
+ return $values[$value];
2833
+ }
2834
+
2835
+ /**
2836
+ * check if the entity is used as an attribute
2837
+ *
2838
+ * @access public
2839
+ * @return bool
2840
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2841
+ */
2842
+ public function getIsAttribute()
2843
+ {
2844
+ return $this->getProductAttribute() || $this->getCategoryAttribute();
2845
+ }
2846
+
2847
+ /**
2848
+ * check if source model can be created
2849
+ *
2850
+ * @access public
2851
+ * @return bool
2852
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2853
+ */
2854
+ public function getCanCreateSourceModel()
2855
+ {
2856
+ return $this->getIsAttribute() || $this->getIsParent();
2857
+ }
2858
+
2859
+ /**
2860
+ * check if entity has children
2861
+ *
2862
+ * @access public
2863
+ * @return bool
2864
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2865
+ */
2866
+ public function getIsParent()
2867
+ {
2868
+ $children = $this->getRelatedEntities(Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_PARENT);
2869
+ return count($children) > 0;
2870
+ }
2871
+
2872
+ /**
2873
+ * get product attribute group
2874
+ *
2875
+ * @access public
2876
+ * @return string
2877
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2878
+ */
2879
+ public function getProductAttributeGroupLabel()
2880
+ {
2881
+ if ($this->getProductAttributeGroup()) {
2882
+ return "'group' => '".$this->getProductAttributeGroup()."',".
2883
+ $this->getEol().$this->getPadding(2);
2884
+ }
2885
+ return '';
2886
+ }
2887
+ /**
2888
+ * get category attribute group
2889
+ *
2890
+ * @access public
2891
+ * @return string
2892
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2893
+ */
2894
+ public function getCategoryAttributeGroupLabel()
2895
+ {
2896
+ if ($this->getCategoryAttributeGroup()) {
2897
+ return "'group' => '".$this->getCategoryAttributeGroup().
2898
+ "',".$this->getEol().$this->getPadding(2);
2899
+ }
2900
+ return '';
2901
+ }
2902
+
2903
+ /**
2904
+ * get param name for before save
2905
+ *
2906
+ * @access public
2907
+ * @return mixed
2908
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2909
+ */
2910
+ public function getBeforeSaveParam()
2911
+ {
2912
+ return $this->getTypeInstance()->getBeforeSaveParam();
2913
+ }
2914
+
2915
+ /**
2916
+ * entity attribute set string
2917
+ *
2918
+ * @access public
2919
+ * @return string
2920
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2921
+ */
2922
+ public function getEntityAttributeSetId()
2923
+ {
2924
+ return $this->getTypeInstance()->getEntityAttributeSetId();
2925
+ }
2926
+
2927
+ /**
2928
+ * filter method name
2929
+ *
2930
+ * @access public
2931
+ * @return string
2932
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2933
+ */
2934
+ public function getFilterMethod()
2935
+ {
2936
+ return $this->getTypeInstance()->getFilterMethod();
2937
+ }
2938
+
2939
+ /**
2940
+ * convert multiple select fields to strings
2941
+ *
2942
+ * @access public
2943
+ * @return mixed
2944
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2945
+ */
2946
+ public function getMultipleSelectConvert()
2947
+ {
2948
+ return $this->getTypeInstance()->getMultipleSelectConvert();
2949
+ }
2950
+
2951
+ /**
2952
+ * check if the entity helper can be created
2953
+ *
2954
+ * @access public
2955
+ * @return bool
2956
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2957
+ */
2958
+ public function getCanCreateEntityHelper()
2959
+ {
2960
+ if ($this->getIsTree()) {
2961
+ return true;
2962
+ }
2963
+ if ($this->getHasFile()) {
2964
+ return true;
2965
+ }
2966
+ if ($this->getCreateFrontend()) {
2967
+ return true;
2968
+ }
2969
+ return $this->getTypeInstance()->getCanCreateEntityHelper();
2970
+ }
2971
+
2972
+ /**
2973
+ * get additional code for toOptionArray()
2974
+ *
2975
+ * @access public
2976
+ * @return string
2977
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2978
+ */
2979
+ public function getToOptionAddition()
2980
+ {
2981
+ return $this->getTypeInstance()->getToOptionAddition();
2982
+ }
2983
+
2984
+ /**
2985
+ * check if entity should be included in the category menu
2986
+ *
2987
+ * @access public
2988
+ * @return bool
2989
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2990
+ */
2991
+ public function getShowInCategoryMenu()
2992
+ {
2993
+ return $this->getListMenu() ==
2994
+ Ultimate_ModuleCreator_Model_Source_Entity_Menu::CATEGORY_MENU;
2995
+ }
2996
+
2997
+ /**
2998
+ * get multiselect methods
2999
+ *
3000
+ * @access public
3001
+ * @return string
3002
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
3003
+ */
3004
+ public function getMultiselectMethods()
3005
+ {
3006
+ $content = '';
3007
+ $padding = $this->getPadding();
3008
+ $tab = $this->getPadding();
3009
+ $eol = $this->getEol();
3010
+ foreach ($this->getAttributes() as $attribute) {
3011
+ $magicCode = $attribute->getMagicMethodCode();
3012
+ $code = $attribute->getCode();
3013
+ if ($attribute->getTypeInstance() instanceof Ultimate_ModuleCreator_Model_Attribute_Type_Multiselect) {
3014
+ $content .= $eol.$padding.'/**'.$eol;
3015
+ $content .= $padding.' * get '.$attribute->getLabel().$eol;
3016
+ $content .= $padding.' *'.$eol;
3017
+ $content .= $padding.' * @access public'.$eol;
3018
+ $content .= $padding.' * @return array'.$eol;
3019
+ $content .= $padding.' * '.$this->getModule()->getQwertyuiop().$eol;
3020
+ $content .= $padding.' */'.$eol;
3021
+ $content .= $padding.'public function get'.$magicCode.'()'.$eol;
3022
+ $content .= $padding.'{'.$eol;
3023
+ $content .= $padding.$tab.'if (!$this->getData(\''.$code.'\')) {'.$eol;
3024
+ $content .= $padding.$tab.$tab.'return explode(\',\', $this->getData(\''.$code.'\'));'.$eol;
3025
+ $content .= $padding.$tab.'}'.$eol;
3026
+ $content .= $padding.$tab.'return $this->getData(\''.$code.'\');'.$eol;
3027
+ $content .= $padding.'}';
3028
+ }
3029
+ }
3030
+ return $content;
3031
+ }
3032
+
3033
+ /**
3034
+ * get html for displaying the name
3035
+ *
3036
+ * @access public
3037
+ * @return string
3038
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
3039
+ */
3040
+ public function getNameHtml()
3041
+ {
3042
+ $content = '';
3043
+ $lower = $this->getNameSingular(true);
3044
+ $ucFirst = ucfirst($lower);
3045
+ $name = $this->getNameAttributeMagicCode();
3046
+ if ($this->getCreateView()) {
3047
+ $content .= '\'<a href="\'.$'.$lower.'->get'.$ucFirst.'Url().\'">\'.$'.$lower.'->get'.$name.'().\'</a>\'';
3048
+ } else {
3049
+ $content .= '\'<a href="#">\'.$'.$lower.'->get'.$name.'().\'</a>\'';
3050
+ }
3051
+ return $content;
3052
+ }
3053
+
3054
+ /**
3055
+ * check if the entity is not store related
3056
+ *
3057
+ * @access public
3058
+ * @return bool
3059
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
3060
+ */
3061
+ public function getNoStore()
3062
+ {
3063
+ return !$this->getStore();
3064
+ }
3065
+
3066
+ /**
3067
+ * get comment name field filter index
3068
+ *
3069
+ * @access public
3070
+ * @return string
3071
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
3072
+ */
3073
+ public function getCommentFilterIndexPrefix()
3074
+ {
3075
+ return $this->getTypeInstance()->getCommentFilterIndexPrefix();
3076
+ }
3077
+
3078
+ /**
3079
+ * additional API subentities.
3080
+ *
3081
+ * @access public
3082
+ * @return string
3083
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
3084
+ */
3085
+ public function getApiAdditionalSettings()
3086
+ {
3087
+ $content = '';
3088
+
3089
+ if ($this->getAllowComment()) {
3090
+ $padding = $this->getPadding(3);
3091
+ $tab = $this->getPadding();
3092
+ $module = $this->getModule()->getLowerModuleName();
3093
+ $entity = $this->getNameSingular(true);
3094
+ $eol = $this->getEol();
3095
+ $title = $this->getLabelSingular().' Comments';
3096
+ $ns = $this->getNamespace(true);
3097
+
3098
+ $content .= $eol;
3099
+ $content .= $padding.'<'.$module.'_'.$entity.'_comment translate="title" module="'.
3100
+ $ns.'_'.$module.'">'.$eol;
3101
+ $content .= $padding.$tab.'<title>'.$title.'</title>'.$eol;
3102
+ $content .= $padding.$tab.'<model>'.$ns.'_'.$module.'/'.$entity.'_comment_api</model>'.$eol;
3103
+ $content .= $padding.$tab.'<acl>'.$module.'/'.$entity.'/comment</acl>'.$eol;
3104
+ $content .= $padding.$tab.'<methods>'.$eol;
3105
+ $content .= $padding.$tab.$tab.'<list translate="title" module="'.$ns.'_'.$module.'">'.$eol;
3106
+ $content .= $padding.$tab.$tab.$tab.'<title>Retrieve '.$title.'</title>'.$eol;
3107
+ $content .= $padding.$tab.$tab.$tab.'<method>items</method>'.$eol;
3108
+ $content .= $padding.$tab.$tab.$tab.'<acl>'.$module.'/'.$entity.'_comment/list</acl>'.$eol;
3109
+ $content .= $padding.$tab.$tab.'</list>'.$eol;
3110
+ $content .= $padding.$tab.$tab.'<updateStatus translate="title" module="'.$ns.'_'.$module.'">'.$eol;
3111
+ $content .= $padding.$tab.$tab.$tab.'<title>Update '.$this->getLabelSingular().' Status</title>'.$eol;
3112
+ $content .= $padding.$tab.$tab.$tab.'<method>updateStatus</method>'.$eol;
3113
+ $content .= $padding.$tab.$tab.$tab.'<acl>'.$module.'/'.$entity.'_comment/updateStatus</acl>'.$eol;
3114
+ $content .= $padding.$tab.$tab.'</updateStatus>'.$eol;
3115
+ $content .= $padding.$tab.'</methods>'.$eol;
3116
+ $content .= $padding.$tab.'<faults module="'.$ns.'_'.$module.'">'.$eol;
3117
+ $content .= $padding.$tab.$tab.'<not_exists>'.$eol;
3118
+ $content .= $padding.$tab.$tab.$tab.'<code>101</code>'.$eol;
3119
+ $content .= $padding.$tab.$tab.$tab.'<message>Requested comment not found.</message>'.$eol;
3120
+ $content .= $padding.$tab.$tab.'</not_exists>'.$eol;
3121
+ $content .= $padding.$tab.'</faults>'.$eol;
3122
+ $content .= $padding.'</'.$module.'_'.$entity.'_comment>'.$eol;
3123
+ }
3124
+ $content .= $this->getTypeInstance()->getApiAdditionalSettings();
3125
+ return $content;
3126
+ }
3127
+
3128
+ /**
3129
+ * get subentities acl
3130
+ *
3131
+ * @access public
3132
+ * @return string
3133
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
3134
+ */
3135
+ public function getSubEntitiesAcl()
3136
+ {
3137
+ $content = '';
3138
+ if ($this->getAllowComment()) {
3139
+ $padding = $this->getPadding(5);
3140
+ $tab = $this->getPadding();
3141
+ $module = $this->getModule()->getLowerModuleName();
3142
+ $entity = $this->getNameSingular(true);
3143
+ $eol = $this->getEol();
3144
+ $title = $this->getLabelSingular().' Comments';
3145
+ $content .= $eol;
3146
+ $ns = $this->getModule()->getNamespace(true);
3147
+
3148
+ $content .= $padding.'<'.$entity.'_comment translate="title" module="'.$ns.'_'.$module.'">'.$eol;
3149
+ $content .= $padding.$tab.'<title>'.$title.'</title>'.$eol;
3150
+ $content .= $padding.$tab.'<sort_order>'.($this->getPosition() + 3).'</sort_order>'.$eol;
3151
+ $content .= $padding.$tab.'<list translate="title" module="'.$ns.'_'.$module.'">'.$eol;
3152
+ $content .= $padding.$tab.$tab.'<title>List</title>'.$eol;
3153
+ $content .= $padding.$tab.'</list>'.$eol;
3154
+ $content .= $padding.$tab.'<updateStatus translate="title" module="'.$ns.'_'.$module.'">'.$eol;
3155
+ $content .= $padding.$tab.$tab.'<title>Update Status</title>'.$eol;
3156
+ $content .= $padding.$tab.'</updateStatus>'.$eol;
3157
+ $content .= $padding.'</'.$entity.'_comment>'.$eol;
3158
+ }
3159
+ $content .= $this->getTypeInstance()->getSubEntitiesAcl();
3160
+ return $content;
3161
+ }
3162
+
3163
+ /**
3164
+ * get api aliases
3165
+ *
3166
+ * @access public
3167
+ * @return string
3168
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
3169
+ */
3170
+ public function getApiResourcesAlias()
3171
+ {
3172
+ $content = '';
3173
+ if ($this->getAllowComment()) {
3174
+ $padding = $this->getPadding(3);
3175
+ $module = $this->getModule()->getLowerModuleName();
3176
+ $entity = $this->getNameSingular(true);
3177
+ $eol = $this->getEol();
3178
+ $content .= $eol;
3179
+ $content .= $padding.'<'.$entity.'_comment>'.$module.'_'.$entity.'_comment</'.$entity.'_comment>';
3180
+ }
3181
+ $content .= $this->getTypeInstance()->getApiResourcesAlias();
3182
+ return $content;
3183
+ }
3184
+
3185
+ /**
3186
+ * get api V2 aliases
3187
+ *
3188
+ * @access public
3189
+ * @return string
3190
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
3191
+ */
3192
+ public function getApiResourcesAliasV2()
3193
+ {
3194
+ $content = '';
3195
+ if ($this->getAllowComment()) {
3196
+ $padding = $this->getPadding(4);
3197
+ $module = $this->getModule()->getLowerModuleName();
3198
+ $entity = strtolower($this->getNameSingular());
3199
+ $eol = $this->getEol();
3200
+ $content .= $eol;
3201
+ $content .= $padding.'<'.$entity.'_comment>'.$module.ucfirst($entity).'Comment</'.$entity.'_comment>';
3202
+ }
3203
+ $content .= $this->getTypeInstance()->getApiResourcesAliasV2();
3204
+ return $content;
3205
+ }
3206
+
3207
+ /**
3208
+ * get default api attributes
3209
+ *
3210
+ * @access public
3211
+ * @return string
3212
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
3213
+ */
3214
+ public function getDefaultApiAttributes()
3215
+ {
3216
+ return $this->getTypeInstance()->getDefaultApiAttributes();
3217
+ }
3218
+
3219
+ /**
3220
+ * get the module namespace
3221
+ *
3222
+ * @access public
3223
+ * @param bool $lower
3224
+ * @return mixed|string
3225
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
3226
+ */
3227
+ public function getNamespace($lower = false)
3228
+ {
3229
+ return $this->getModule()->getNamespace($lower);
3230
+ }
3231
+
3232
+ /**
3233
+ * get entity name
3234
+ *
3235
+ * @access public
3236
+ * @param bool $lower
3237
+ * @return mixed|string
3238
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
3239
+ */
3240
+ public function getNameSingular($lower = false)
3241
+ {
3242
+ $name = $this->getData('name_singular');
3243
+ if ($lower) {
3244
+ $name = strtolower($name);
3245
+ }
3246
+ return $name;
3247
+ }
3248
+
3249
+ /**
3250
+ * get code that filters dates
3251
+ *
3252
+ * @access public
3253
+ * @param int $padding
3254
+ * @return string
3255
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
3256
+ */
3257
+ public function getFilterDates($padding = 4)
3258
+ {
3259
+ $dateAttributes = array();
3260
+ foreach ($this->getAttributes() as $attribute) {
3261
+ if ($attribute->getTypeInstance() instanceof
3262
+ Ultimate_ModuleCreator_Model_Attribute_Type_Timestamp) {
3263
+ $dateAttributes[] = $attribute->getCode();
3264
+ }
3265
+ }
3266
+ if (count($dateAttributes) == 0) {
3267
+ return '';
3268
+ }
3269
+ return $this->getEol().$this->getPadding($padding).
3270
+ '$data = $this->_filterDates($data, array(\''.implode("' ,'", $dateAttributes).'\'));';
3271
+ }
3272
+
3273
+ /**
3274
+ * get add all attributes to collection
3275
+ *
3276
+ * @access public
3277
+ * @return string
3278
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
3279
+ */
3280
+ public function getAllAttributesToCollection()
3281
+ {
3282
+ return $this->getTypeInstance()->getAllAttributesToCollection();
3283
+ }
3284
+
3285
+ /**
3286
+ * get load store id statement
3287
+ *
3288
+ * @access public
3289
+ * @return string
3290
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
3291
+ */
3292
+ public function getLoadStoreId()
3293
+ {
3294
+ return $this->getTypeInstance()->getLoadStoreId();
3295
+ }
3296
+
3297
+ /**
3298
+ * get rest resource group
3299
+ *
3300
+ * @param $padding
3301
+ * @return string
3302
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
3303
+ */
3304
+ public function getRestResourceGroup($padding)
3305
+ {
3306
+ $content = '';
3307
+ $eol = $this->getEol();
3308
+ if ($this->getRest()) {
3309
+ $ns = $this->getNamespace(true);
3310
+ $md = $this->getModule()->getLowerModuleName();
3311
+ $entity = $this->getNameSingular(true);
3312
+ $content .= $this->getPadding($padding).'<'.$ns.'_'.$md.'_'.$entity.
3313
+ ' translate="title" module="'.$ns.'_'.$md.'">'.$eol;
3314
+ $content .= $this->getPadding($padding + 1).'<title>'.$this->getLabelSingular().'</title>'.$eol;
3315
+ $content .= $this->getPadding($padding + 1).'<sort_order>'.$this->getPosition().'</sort_order>'.$eol;
3316
+ $content .= $this->getPadding($padding).'</'.$ns.'_'.$md.'_'.$entity.'>'.$eol;
3317
+ }
3318
+ return $content;
3319
+ }
3320
+
3321
+ /**
3322
+ * get rest resource
3323
+ *
3324
+ * @param $padding
3325
+ * @return string
3326
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
3327
+ */
3328
+ public function getRestResource($padding)
3329
+ {
3330
+ $content = '';
3331
+ $eol = $this->getEol();
3332
+ if ($this->getRest()) {
3333
+ $ns = $this->getNamespace(true);
3334
+ $md = $this->getModule()->getLowerModuleName();
3335
+ $entity = $this->getNameSingular(true);
3336
+ $content .= $this->getPadding($padding).'<'.$ns.'_'.$md.'_'.$entity.
3337
+ ' translate="title" module="'.$ns.'_'.$md.'">'.$eol;
3338
+ $content .= $this->getPadding($padding + 1).'<group>'.$ns.'_'.$md.'_'.$entity.'</group>'.$eol;
3339
+ $content .= $this->getPadding($padding + 1).'<model>'.$ns.'_'.$md.'/api2_'.$entity.'</model>'.$eol;
3340
+ $content .= $this->getPadding($padding + 1).'<working_model>'.$ns.'_'.$md.'/'.$entity.
3341
+ '</working_model>'.$eol;
3342
+ $content .= $this->getPadding($padding + 1).'<title>'.$this->getLabelSingular().'</title>'.$eol;
3343
+ $content .= $this->getPadding($padding + 1).'<sort_order>'.$this->getPosition().'</sort_order>'.$eol;
3344
+ $content .= $this->getPadding($padding + 1).'<privileges>'.$eol;
3345
+ $content .= $this->getPadding($padding + 2).'<admin>'.$eol;
3346
+ $content .= $this->getPadding($padding + 3).'<create>1</create>'.$eol;
3347
+ $content .= $this->getPadding($padding + 3).'<retrieve>1</retrieve>'.$eol;
3348
+ $content .= $this->getPadding($padding + 3).'<update>1</update>'.$eol;
3349
+ $content .= $this->getPadding($padding + 3).'<delete>1</delete>'.$eol;
3350
+ $content .= $this->getPadding($padding + 2).'</admin>'.$eol;
3351
+ $content .= $this->getPadding($padding + 2).'<customer>'.$eol;
3352
+ $content .= $this->getPadding($padding + 3).'<retrieve>1</retrieve>'.$eol;
3353
+ $content .= $this->getPadding($padding + 2).'</customer>'.$eol;
3354
+ $content .= $this->getPadding($padding + 2).'<guest>'.$eol;
3355
+ $content .= $this->getPadding($padding + 3).'<retrieve>1</retrieve>'.$eol;
3356
+ $content .= $this->getPadding($padding + 2).'</guest>'.$eol;
3357
+ $content .= $this->getPadding($padding + 1).'</privileges>'.$eol;
3358
+ $content .= $this->getPadding($padding + 1).'<attributes translate="'.
3359
+ $this->getRestAttributes(true, true).'" module="'.$ns.'_'.$md.'">'.$eol;
3360
+ foreach ($this->getRestAttributes(false, false) as $code=>$label) {
3361
+ $content .= $this->getPadding($padding + 2).'<'.$code.'>'.$label.'</'.$code.'>'.$eol;
3362
+ }
3363
+ $content .= $this->getPadding($padding + 1).'</attributes>'.$eol;
3364
+ $content .= $this->getPadding($padding + 1).'<routes>'.$eol;
3365
+ $content .= $this->getPadding($padding + 2).'<route_entity>'.$eol;
3366
+ $content .= $this->getPadding($padding + 3).'<route>/'.$md.'_'.$this->getNamePlural(true).
3367
+ '/:id</route>'.$eol;
3368
+ $content .= $this->getPadding($padding + 3).'<action_type>entity</action_type>'.$eol;
3369
+ $content .= $this->getPadding($padding + 2).'</route_entity>'.$eol;
3370
+ if ($this->getIsEav() || $this->getStore()) {
3371
+ $content .= $this->getPadding($padding + 2).'<route_entity_with_store>'.$eol;
3372
+ $content .= $this->getPadding($padding + 3).'<route>/'.$md.'_'.$this->getNamePlural(true).
3373
+ '/:id/store/:store</route>'.$eol;
3374
+ $content .= $this->getPadding($padding + 3).'<action_type>entity</action_type>'.$eol;
3375
+ $content .= $this->getPadding($padding + 2).'</route_entity_with_store>'.$eol;
3376
+ }
3377
+ $content .= $this->getPadding($padding + 2).'<route_collection>'.$eol;
3378
+ $content .= $this->getPadding($padding + 3).'<route>/'.$md.'_'.$this->getNamePlural(true).'</route>'.$eol;
3379
+ $content .= $this->getPadding($padding + 3).'<action_type>collection</action_type>'.$eol;
3380
+ $content .= $this->getPadding($padding + 2).'</route_collection>'.$eol;
3381
+ if ($this->getIsEav() || $this->getStore()) {
3382
+ $content .= $this->getPadding($padding + 2).'<route_collection_with_store>'.$eol;
3383
+ $content .= $this->getPadding($padding + 3).'<route>/'.$md.'_'.$this->getNamePlural(true).
3384
+ '/store/:store</route>'.$eol;
3385
+ $content .= $this->getPadding($padding + 3).'<action_type>collection</action_type>'.$eol;
3386
+ $content .= $this->getPadding($padding + 2).'</route_collection_with_store>'.$eol;
3387
+ }
3388
+ $content .= $this->getPadding($padding + 1).'</routes>'.$eol;
3389
+ $content .= $this->getPadding($padding + 1).'<versions>1</versions>'.$eol;
3390
+ $content .= $this->getPadding($padding).'</'.$ns.'_'.$md.'_'.$entity.'>'.$eol;
3391
+ }
3392
+ return $content;
3393
+ }
3394
+
3395
+ /**
3396
+ * get rest attributes
3397
+ *
3398
+ * @param bool $codeOnly
3399
+ * @param bool $asString
3400
+ * @return array|string
3401
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
3402
+ */
3403
+ public function getRestAttributes($codeOnly = false, $asString = false)
3404
+ {
3405
+ $attributes = array(
3406
+ 'entity_id' => 'Id',
3407
+ );
3408
+ foreach ($this->getAttributes() as $attribute) {
3409
+ $attributes[$attribute->getCode()] = $attribute->getLabel();
3410
+ }
3411
+ foreach ($this->getSimulatedAttributes() as $attribute) {
3412
+ $attributes[$attribute->getCode()] = $attribute->getLabel();
3413
+ }
3414
+ if ($codeOnly) {
3415
+ if ($asString) {
3416
+ return implode(' ', array_keys($attributes));
3417
+ }
3418
+ return array_keys($attributes);
3419
+ }
3420
+ return $attributes;
3421
+ }
3422
+
3423
+ /**
3424
+ * @access public
3425
+ *
3426
+ * @return string
3427
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
3428
+ */
3429
+ public function getRestCollectionCleanup()
3430
+ {
3431
+ return $this->getTypeInstance()->getRestCollectionCleanup();
3432
+ }
3433
+
3434
+ /**
3435
+ * @access public
3436
+ *
3437
+ * @return string
3438
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
3439
+ */
3440
+ public function getRestCollectionStoreId()
3441
+ {
3442
+ return $this->getTypeInstance()->getRestCollectionStoreId();
3443
+ }
3444
+
3445
+ /**
3446
+ * get default attribute values
3447
+ *
3448
+ * @access public
3449
+ * @return string
3450
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
3451
+ */
3452
+ public function getDefaultAttributeValues()
3453
+ {
3454
+ return $this->getTypeInstance()->getDefaultAttributeValues();
3455
+ }
3456
+
3457
+ /**
3458
+ * check if entity has parent entities
3459
+ *
3460
+ * @access public
3461
+ * @return bool
3462
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
3463
+ */
3464
+ public function getHasParentRelation()
3465
+ {
3466
+ return count($this->getRelatedEntities(Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_CHILD)) > 0;
3467
+ }
3468
+
3469
+ /**
3470
+ * get additional to option array select
3471
+ *
3472
+ * @access public
3473
+ * @return string
3474
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
3475
+ */
3476
+ public function getToOptionArraySelect()
3477
+ {
3478
+ return $this->getTypeInstance()->getToOptionArraySelect();
3479
+ }
3480
+
3481
+ /**
3482
+ * get parent grid column static params
3483
+ *
3484
+ * @access public
3485
+ * @return string
3486
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
3487
+ */
3488
+ public function getParentStaticParams()
3489
+ {
3490
+ if ($this->getNotIsTree()) {
3491
+ return '';
3492
+ }
3493
+ $eol = $this->getEol();
3494
+ $padding = $this->getPadding(4);
3495
+ $tab = $this->getPadding();
3496
+ $content = $eol;
3497
+ $content .= $padding."'static' => array(".$eol;
3498
+ $content .= $padding.$tab."'clear' => 1".$eol;
3499
+ $content .= $padding."),";
3500
+ return $content;
3501
+ }
3502
+ }
app/code/community/Ultimate/ModuleCreator/Model/Entity/Type/Abstract.php CHANGED
@@ -1,495 +1,644 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
- */
18
- /**
19
- * abstract entity type
20
- *
21
- * @category Ultimate
22
- * @package Ultimate_ModuleCreator
23
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
- */
25
- abstract class Ultimate_ModuleCreator_Model_Entity_Type_Abstract
26
- extends Ultimate_ModuleCreator_Model_Abstract {
27
- /**
28
- * constant for eav type
29
- */
30
- const TYPE_EAV = 'eav';
31
- /**
32
- * constant for flat type
33
- */
34
- const TYPE_FLAT = 'flat';
35
- /**
36
- * current entity
37
- * @var mixed
38
- */
39
- protected $_entity = null;
40
- /**
41
- * set the entity
42
- * @access public
43
- * @param Ultimate_ModuleCreator_Model_Entity $entity
44
- * @return Ultimate_ModuleCreator_Model_Entity_Type_Abstract
45
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
46
- */
47
- public function setEntity(Ultimate_ModuleCreator_Model_Entity $entity) {
48
- $this->_entity = $entity;
49
- return $this;
50
- }
51
-
52
- /**
53
- * get the entity object
54
- * @access public
55
- * @return Ultimate_ModuleCreator_Model_Entity|null
56
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
57
- */
58
- public function getEntity() {
59
- return $this->_entity;
60
- }
61
- /**
62
- * get the module object
63
- * @access public
64
- * @return Ultimate_ModuleCreator_Model_Module|null
65
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
66
- */
67
- public function getModule(){
68
- return $this->getEntity()->getModule();
69
- }
70
- /**
71
- * get the namespace
72
- * @access public
73
- * @param bool $lower
74
- * @return string
75
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
76
- */
77
- public function getNamespace($lower = false) {
78
- return $this->getModule()->getNamespace($lower);
79
- }
80
- /**
81
- * get lower module name
82
- * @access public
83
- * @return string
84
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
85
- */
86
- public function getLowerModuleName() {
87
- return $this->getModule()->getLowerModuleName();
88
- }
89
- /**
90
- * get collection attributes
91
- * @access public
92
- * @return string
93
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
94
- */
95
- public function getCollectionAttributes() {
96
- return '';
97
- }
98
- /**
99
- * get admin join
100
- * @access public
101
- * @return string
102
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
103
- */
104
- public function getAdminJoin() {
105
- return '';
106
- }
107
- /**
108
- * prepare columns text
109
- * @access public
110
- * @return string
111
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
112
- */
113
- public function getPrepareColumnsHeader() {
114
- return '';
115
- }
116
- /**
117
- * get name attribute grid eav
118
- * @access public
119
- * @return string
120
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
121
- */
122
- public function getNameAttributeGridEav() {
123
- return '';
124
- }
125
- /**
126
- * check if entity has images
127
- * @access public
128
- * @return bool
129
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
130
- */
131
- public function getHasImage() {
132
- return $this->getEntity()->getData('has_image');
133
- }
134
- /**
135
- * check if entity has files
136
- * @access public
137
- * @return bool
138
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
139
- */
140
- public function getHasFile() {
141
- return $this->getEntity()->getData('has_file');
142
- }
143
- /**
144
- * check if submenu should exist
145
- * @access public
146
- * @return bool
147
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
148
- */
149
- public function getHasSubmenu() {
150
- return false;
151
- }
152
- /**
153
- * get Additional submenu
154
- * @access public
155
- * @param $padding
156
- * @return string
157
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
158
- */
159
- public function getAdditionalMenu($padding) {
160
- return '';
161
- }
162
- /**
163
- * get Additional menu acl
164
- * @access public
165
- * @param $padding
166
- * @return string
167
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
168
- */
169
- public function getAdditionalMenuAcl($padding) {
170
- return '';
171
- }
172
- /**
173
- * check if comments are allowed by store
174
- * @access public
175
- * @return string
176
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
177
- */
178
- public function getAllowCommentByStore() {
179
- return $this->getEntity()->getAllowComment() && $this->getEntity()->getStore();
180
- }
181
- /**
182
- * get attributes content for setup
183
- * @access public
184
- * @return string
185
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
186
- */
187
- public function getAttributesSetup(){
188
- return '';
189
- }
190
- /**
191
- * get parent class for the entity resource model
192
- * @access public
193
- * @return string
194
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
195
- */
196
- public function getResourceModelParent(){
197
- return 'Mage_Core_Model_Resource_Db_Abstract';
198
- }
199
- /**
200
- * get parent class for the entity resource collection model
201
- * @access public
202
- * @return string
203
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
204
- */
205
- public function getResourceCollectionModelParent(){
206
- return 'Mage_Core_Model_Resource_Db_Collection_Abstract';
207
- }
208
-
209
- /**
210
- * get related entities relations table
211
- * @access public
212
- * @return string
213
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
214
- */
215
- public function getResourceRelationsTables(){
216
- return '';
217
- }
218
- /**
219
- * get related entities relations table declaration
220
- * @access public
221
- * @return string
222
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
223
- */
224
- public function getResourceRelationsTablesDeclare(){
225
- return '';
226
- }
227
- /**
228
- * get admin layout content for index page
229
- * @access public
230
- * @return string
231
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
232
- */
233
- public function getAdminIndexLayoutContent(){
234
- $entity = $this->getEntity()->getNameSingular(true);
235
- $module = $this->getLowerModuleName();
236
- $namespace = $this->getNamespace(true);
237
- return $this->getPadding(3).'<block type="'.$namespace.'_'.$module.'/adminhtml_'.$entity.'" name="'.$entity.'" />'.$this->getEol();
238
- }
239
- /**
240
- * get the parent model class
241
- * @access public
242
- * @return mixed
243
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
244
- */
245
- public function getEntityParentModel(){
246
- return 'Mage_Core_Model_Abstract';
247
- }
248
- /**
249
- * get entity table alias
250
- * @access public
251
- * @return mixed
252
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
253
- */
254
- public function getEntityTableAlias() {
255
- return 'main_table';
256
- }
257
- /**
258
- * get additional prepare collection
259
- * @access public
260
- * @return mixed
261
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
262
- */
263
- public function getAdditionalPrepareCollection(){
264
- return '';
265
- }
266
- /**
267
- * additional layout block for left section
268
- * @access public
269
- * @return mixed
270
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
271
- */
272
- public function getEditLayoutLeft() {
273
- return '';
274
- }
275
- /**
276
- * additional layout block edit
277
- * @access public
278
- * @return mixed
279
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
280
- */
281
- public function getEditLayoutAdditional() {
282
- return '';
283
- }
284
- /**
285
- * get param name for before save
286
- * @access public
287
- * @return mixed
288
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
289
- */
290
- public function getBeforeSaveParam() {
291
- return 'Mage_Core_Model_Abstract';
292
- }
293
- /**
294
- * entity attribute set string
295
- * @access public
296
- * @return string
297
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
298
- */
299
- public function getEntityAttributeSetId() {
300
- return '';
301
- }
302
- /**
303
- * filter method name
304
- * @access public
305
- * @return string
306
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
307
- */
308
- public function getFilterMethod() {
309
- return 'addFieldToFilter';
310
- }
311
- /**
312
- * convert multiple select fields to strings
313
- * @access public
314
- * @return mixed
315
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
316
- */
317
- public function getMultipleSelectConvert(){
318
- $padding = $this->getPadding(2);
319
- $tab = $this->getPadding();
320
- $eol = $this->getEol();
321
- $content = '';
322
- foreach ($this->getEntity()->getAttributes() as $attribute){
323
- if ($attribute->getIsMultipleSelect()){
324
- $ucCode = $attribute->getMagicMethodCode();
325
- $lcCode = $attribute->getCodeForFileName(false);
326
- $content .= '$'.$attribute->getCodeForFileName(false).' = $object->get'.$ucCode.'();'.$eol;
327
- $content .= $padding.'if (is_array($'.$lcCode.')) {'.$eol;
328
- $content .= $padding.$tab.'$object->set'.$ucCode."(implode(',', $".$lcCode.'));'.$eol;
329
- $content .= $padding.'}'.$eol.$padding;
330
- }
331
- }
332
- return $content;
333
- }
334
- /**
335
- * check if the entity helper can be created
336
- * @access public
337
- * @return bool
338
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
339
- */
340
- public function getCanCreateEntityHelper(){
341
- return false;
342
- }
343
- /**
344
- * get additional code for toOptionArray()
345
- * @access public
346
- * @return string
347
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
348
- */
349
- public function getToOptionAddition(){
350
- return '';
351
- }
352
- /**
353
- * get comment name field filter index
354
- * @access public
355
- * @return string
356
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
357
- */
358
- public function getCommentFilterIndexPrefix() {
359
- return $this->getEntityTableAlias().'.';
360
- }
361
- /**
362
- * get additional api xml
363
- * @access public
364
- * @return string
365
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
366
- */
367
- public function getApiAdditional(){
368
- return '';
369
- }
370
- /**
371
- * get additional api faults
372
- * @access public
373
- * @return string
374
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
375
- */
376
- public function getApiFaults(){
377
- return '';
378
- }
379
- /**
380
- * additional API subentities.
381
- * @access public
382
- * @return string
383
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
384
- */
385
- public function getApiAdditionalSettings() {
386
- return '';
387
- }
388
- /**
389
- * get subentities acl
390
- * @access public
391
- * @return string
392
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
393
- */
394
- public function getSubEntitiesAcl(){
395
- return '';
396
- }
397
- /**
398
- * get api aliases
399
- * @access public
400
- * @return string
401
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
402
- */
403
- public function getApiResourcesAlias() {
404
- return '';
405
- }
406
- /**
407
- * get api V2 aliases
408
- * @access public
409
- * @return string
410
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
411
- */
412
- public function getApiResourcesAliasV2() {
413
- return '';
414
- }
415
- /**
416
- * get attributes format for wsdl
417
- * @access public
418
- * @param bool $wsi
419
- * @return string
420
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
421
- */
422
- public function getWsdlAttributes($wsi = false){
423
- return '';
424
- }
425
- /**
426
- * get default api attributes
427
- * @access public
428
- * @return string
429
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
430
- */
431
- public function getDefaultApiAttributes(){
432
- return '';
433
- }
434
- /**
435
- * get add all attributes to collection
436
- * @access public
437
- * @return string
438
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
439
- */
440
- public function getAllAttributesToCollection() {
441
- return '';
442
- }
443
- /**
444
- * get load store id statement
445
- * @access public
446
- * @return string
447
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
448
- */
449
- public function getLoadStoreId() {
450
- return '';
451
- }
452
- /**
453
- * @access public
454
- * @return string
455
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
456
- */
457
- public function getRestCollectionCleanup() {
458
- return $this->getEol().$this->getPadding(2).'$'.$this->getEntity()->getNamePlural(true).'Array = $'.$this->getEntity()->getNamePlural(true).'Array[\'items\'];'.$this->getEol();
459
- }
460
- /**
461
- * @access public
462
- * @return string
463
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
464
- */
465
- public function getRestCollectionStoreId() {
466
- return '';
467
- }
468
- /**
469
- * @access public
470
- * @return string
471
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
472
- */
473
- public function getDefaultAttributeValues(){
474
- $content = '';
475
- foreach ($this->getEntity()->getAttributes() as $attribute) {
476
- $defaultValue = $attribute->getDefaultValueProcessed();
477
- if (!empty($defaultValue)) {
478
- $content .= $this->getPadding(2). '$values[\''.$attribute->getCode().'\'] = \''.$defaultValue.'\';'.$this->getEol();
479
- }
480
- }
481
- if ($content) {
482
- $content .= $this->getEol();
483
- }
484
- return $content;
485
- }
486
- /**
487
- * get additional to option array select
488
- * @access public
489
- * @return string
490
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
491
- */
492
- public function getToOptionArraySelect() {
493
- return '';
494
- }
495
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
+ */
18
+ /**
19
+ * abstract entity type
20
+ *
21
+ * @category Ultimate
22
+ * @package Ultimate_ModuleCreator
23
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
+ */
25
+ abstract class Ultimate_ModuleCreator_Model_Entity_Type_Abstract extends Ultimate_ModuleCreator_Model_Abstract
26
+ {
27
+ /**
28
+ * constant for eav type
29
+ */
30
+ const TYPE_EAV = 'eav';
31
+
32
+ /**
33
+ * constant for flat type
34
+ */
35
+ const TYPE_FLAT = 'flat';
36
+
37
+ /**
38
+ * current entity
39
+ *
40
+ * @var Ultimate_ModuleCreator_Model_Entity
41
+ */
42
+ protected $_entity;
43
+
44
+ /**
45
+ * set the entity
46
+ *
47
+ * @access public
48
+ * @param Ultimate_ModuleCreator_Model_Entity $entity
49
+ * @return Ultimate_ModuleCreator_Model_Entity_Type_Abstract
50
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
51
+ */
52
+ public function setEntity(Ultimate_ModuleCreator_Model_Entity $entity)
53
+ {
54
+ $this->_entity = $entity;
55
+ return $this;
56
+ }
57
+
58
+ /**
59
+ * get the entity object
60
+ *
61
+ * @access public
62
+ * @return Ultimate_ModuleCreator_Model_Entity|null
63
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
64
+ */
65
+ public function getEntity()
66
+ {
67
+ return $this->_entity;
68
+ }
69
+
70
+ /**
71
+ * get the module object
72
+ *
73
+ * @access public
74
+ * @return Ultimate_ModuleCreator_Model_Module|null
75
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
76
+ */
77
+ public function getModule()
78
+ {
79
+ return $this->getEntity()->getModule();
80
+ }
81
+
82
+ /**
83
+ * get the namespace
84
+ *
85
+ * @access public
86
+ * @param bool $lower
87
+ * @return string
88
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
89
+ */
90
+ public function getNamespace($lower = false)
91
+ {
92
+ return $this->getModule()->getNamespace($lower);
93
+ }
94
+
95
+ /**
96
+ * get lower module name
97
+ *
98
+ * @access public
99
+ * @return string
100
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
101
+ */
102
+ public function getLowerModuleName()
103
+ {
104
+ return $this->getModule()->getLowerModuleName();
105
+ }
106
+
107
+ /**
108
+ * get collection attributes
109
+ *
110
+ * @access public
111
+ * @return string
112
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
113
+ */
114
+ public function getCollectionAttributes()
115
+ {
116
+ return '';
117
+ }
118
+
119
+ /**
120
+ * get admin join
121
+ *
122
+ * @access public
123
+ * @return string
124
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
125
+ */
126
+ public function getAdminJoin()
127
+ {
128
+ return '';
129
+ }
130
+
131
+ /**
132
+ * prepare columns text
133
+ *
134
+ * @access public
135
+ * @return string
136
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
137
+ */
138
+ public function getPrepareColumnsHeader()
139
+ {
140
+ return '';
141
+ }
142
+
143
+ /**
144
+ * get name attribute grid eav
145
+ *
146
+ * @access public
147
+ * @return string
148
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
149
+ */
150
+ public function getNameAttributeGridEav()
151
+ {
152
+ return '';
153
+ }
154
+
155
+ /**
156
+ * check if entity has images
157
+ *
158
+ * @access public
159
+ * @return bool
160
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
161
+ */
162
+ public function getHasImage()
163
+ {
164
+ return $this->getEntity()->getData('has_image');
165
+ }
166
+
167
+ /**
168
+ * check if entity has files
169
+ *
170
+ * @access public
171
+ * @return bool
172
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
173
+ */
174
+ public function getHasFile()
175
+ {
176
+ return $this->getEntity()->getData('has_file');
177
+ }
178
+
179
+ /**
180
+ * check if submenu should exist
181
+ *
182
+ * @access public
183
+ * @return bool
184
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
185
+ */
186
+ public function getHasSubmenu()
187
+ {
188
+ return false;
189
+ }
190
+
191
+ /**
192
+ * get Additional submenu
193
+ *
194
+ * @access public
195
+ * @param $padding
196
+ * @return string
197
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
198
+ */
199
+ public function getAdditionalMenu($padding)
200
+ {
201
+ return '';
202
+ }
203
+
204
+ /**
205
+ * get Additional menu acl
206
+ *
207
+ * @access public
208
+ * @param $padding
209
+ * @return string
210
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
211
+ */
212
+ public function getAdditionalMenuAcl($padding)
213
+ {
214
+ return '';
215
+ }
216
+
217
+ /**
218
+ * check if comments are allowed by store
219
+ *
220
+ * @access public
221
+ * @return string
222
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
223
+ */
224
+ public function getAllowCommentByStore()
225
+ {
226
+ return $this->getEntity()->getAllowComment() && $this->getEntity()->getStore();
227
+ }
228
+
229
+ /**
230
+ * get attributes content for setup
231
+ *
232
+ * @access public
233
+ * @return string
234
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
235
+ */
236
+ public function getAttributesSetup()
237
+ {
238
+ return '';
239
+ }
240
+
241
+ /**
242
+ * get parent class for the entity resource model
243
+ *
244
+ * @access public
245
+ * @return string
246
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
247
+ */
248
+ public function getResourceModelParent()
249
+ {
250
+ return 'Mage_Core_Model_Resource_Db_Abstract';
251
+ }
252
+
253
+ /**
254
+ * get parent class for the entity resource collection model
255
+ *
256
+ * @access public
257
+ * @return string
258
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
259
+ */
260
+ public function getResourceCollectionModelParent()
261
+ {
262
+ return 'Mage_Core_Model_Resource_Db_Collection_Abstract';
263
+ }
264
+
265
+ /**
266
+ * get related entities relations table
267
+ *
268
+ * @access public
269
+ * @return string
270
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
271
+ */
272
+ public function getResourceRelationsTables()
273
+ {
274
+ return '';
275
+ }
276
+
277
+ /**
278
+ * get related entities relations table declaration
279
+ *
280
+ * @access public
281
+ * @return string
282
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
283
+ */
284
+ public function getResourceRelationsTablesDeclare()
285
+ {
286
+ return '';
287
+ }
288
+
289
+ /**
290
+ * get admin layout content for index page
291
+ *
292
+ * @access public
293
+ * @return string
294
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
295
+ */
296
+ public function getAdminIndexLayoutContent()
297
+ {
298
+ $entity = $this->getEntity()->getNameSingular(true);
299
+ $module = $this->getLowerModuleName();
300
+ $namespace = $this->getNamespace(true);
301
+ return $this->getPadding(3).'<block type="'.
302
+ $namespace.'_'.$module.'/adminhtml_'.$entity.'" name="'.$entity.'" />'.$this->getEol();
303
+ }
304
+
305
+ /**
306
+ * get the parent model class
307
+ *
308
+ * @access public
309
+ * @return mixed
310
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
311
+ */
312
+ public function getEntityParentModel()
313
+ {
314
+ return 'Mage_Core_Model_Abstract';
315
+ }
316
+
317
+ /**
318
+ * get entity table alias
319
+ *
320
+ * @access public
321
+ * @return mixed
322
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
323
+ */
324
+ public function getEntityTableAlias()
325
+ {
326
+ return 'main_table';
327
+ }
328
+
329
+ /**
330
+ * get additional prepare collection
331
+ *
332
+ * @access public
333
+ * @return mixed
334
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
335
+ */
336
+ public function getAdditionalPrepareCollection()
337
+ {
338
+ return '';
339
+ }
340
+
341
+ /**
342
+ * additional layout block for left section
343
+ *
344
+ * @access public
345
+ * @return mixed
346
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
347
+ */
348
+ public function getEditLayoutLeft()
349
+ {
350
+ return '';
351
+ }
352
+
353
+ /**
354
+ * additional layout block edit
355
+ *
356
+ * @access public
357
+ * @return mixed
358
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
359
+ */
360
+ public function getEditLayoutAdditional()
361
+ {
362
+ return '';
363
+ }
364
+
365
+ /**
366
+ * get param name for before save
367
+ *
368
+ * @access public
369
+ * @return mixed
370
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
371
+ */
372
+ public function getBeforeSaveParam()
373
+ {
374
+ return 'Mage_Core_Model_Abstract';
375
+ }
376
+
377
+ /**
378
+ * entity attribute set string
379
+ *
380
+ * @access public
381
+ * @return string
382
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
383
+ */
384
+ public function getEntityAttributeSetId()
385
+ {
386
+ return '';
387
+ }
388
+
389
+ /**
390
+ * filter method name
391
+ *
392
+ * @access public
393
+ * @return string
394
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
395
+ */
396
+ public function getFilterMethod()
397
+ {
398
+ return 'addFieldToFilter';
399
+ }
400
+
401
+ /**
402
+ * convert multiple select fields to strings
403
+ *
404
+ * @access public
405
+ * @return mixed
406
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
407
+ */
408
+ public function getMultipleSelectConvert()
409
+ {
410
+ $padding = $this->getPadding(2);
411
+ $tab = $this->getPadding();
412
+ $eol = $this->getEol();
413
+ $content = '';
414
+ foreach ($this->getEntity()->getAttributes() as $attribute) {
415
+ if ($attribute->getIsMultipleSelect()) {
416
+ $ucCode = $attribute->getMagicMethodCode();
417
+ $lcCode = $attribute->getCodeForFileName(false);
418
+ $content .= '$'.$attribute->getCodeForFileName(false).' = $object->get'.$ucCode.'();'.$eol;
419
+ $content .= $padding.'if (is_array($'.$lcCode.')) {'.$eol;
420
+ $content .= $padding.$tab.'$object->set'.$ucCode."(implode(',', $".$lcCode.'));'.$eol;
421
+ $content .= $padding.'}'.$eol.$padding;
422
+ }
423
+ }
424
+ return $content;
425
+ }
426
+
427
+ /**
428
+ * check if the entity helper can be created
429
+ *
430
+ * @access public
431
+ * @return bool
432
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
433
+ */
434
+ public function getCanCreateEntityHelper()
435
+ {
436
+ return false;
437
+ }
438
+
439
+ /**
440
+ * get additional code for toOptionArray()
441
+ *
442
+ * @access public
443
+ * @return string
444
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
445
+ */
446
+ public function getToOptionAddition()
447
+ {
448
+ return '';
449
+ }
450
+
451
+ /**
452
+ * get comment name field filter index
453
+ *
454
+ * @access public
455
+ * @return string
456
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
457
+ */
458
+ public function getCommentFilterIndexPrefix()
459
+ {
460
+ return $this->getEntityTableAlias().'.';
461
+ }
462
+
463
+ /**
464
+ * get additional api xml
465
+ *
466
+ * @access public
467
+ * @return string
468
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
469
+ */
470
+ public function getApiAdditional()
471
+ {
472
+ return '';
473
+ }
474
+
475
+ /**
476
+ * get additional api faults
477
+ *
478
+ * @access public
479
+ * @return string
480
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
481
+ */
482
+ public function getApiFaults()
483
+ {
484
+ return '';
485
+ }
486
+
487
+ /**
488
+ * additional API sub-entities.
489
+ *
490
+ * @access public
491
+ * @return string
492
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
493
+ */
494
+ public function getApiAdditionalSettings()
495
+ {
496
+ return '';
497
+ }
498
+
499
+ /**
500
+ * get sub-entities acl
501
+ *
502
+ * @access public
503
+ * @return string
504
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
505
+ */
506
+ public function getSubEntitiesAcl()
507
+ {
508
+ return '';
509
+ }
510
+
511
+ /**
512
+ * get api aliases
513
+ *
514
+ * @access public
515
+ * @return string
516
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
517
+ */
518
+ public function getApiResourcesAlias()
519
+ {
520
+ return '';
521
+ }
522
+
523
+ /**
524
+ * get api V2 aliases
525
+ *
526
+ * @access public
527
+ * @return string
528
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
529
+ */
530
+ public function getApiResourcesAliasV2()
531
+ {
532
+ return '';
533
+ }
534
+
535
+ /**
536
+ * get attributes format for wsdl
537
+ *
538
+ * @access public
539
+ * @param bool $wsi
540
+ * @return string
541
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
542
+ */
543
+ public function getWsdlAttributes($wsi = false)
544
+ {
545
+ return '';
546
+ }
547
+
548
+ /**
549
+ * get default api attributes
550
+ *
551
+ * @access public
552
+ * @return string
553
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
554
+ */
555
+ public function getDefaultApiAttributes()
556
+ {
557
+ return '';
558
+ }
559
+
560
+ /**
561
+ * get add all attributes to collection
562
+ *
563
+ * @access public
564
+ * @return string
565
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
566
+ */
567
+ public function getAllAttributesToCollection()
568
+ {
569
+ return '';
570
+ }
571
+
572
+ /**
573
+ * get load store id statement
574
+ *
575
+ * @access public
576
+ * @return string
577
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
578
+ */
579
+ public function getLoadStoreId()
580
+ {
581
+ return '';
582
+ }
583
+
584
+ /**
585
+ * get rest collection cleanup
586
+ *
587
+ * @access public
588
+ * @return string
589
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
590
+ */
591
+ public function getRestCollectionCleanup()
592
+ {
593
+ return $this->getEol().$this->getPadding(2).'$'.
594
+ $this->getEntity()->getNamePlural(true).
595
+ 'Array = $'.$this->getEntity()->getNamePlural(true).'Array[\'items\'];'.$this->getEol();
596
+ }
597
+
598
+ /**
599
+ * get rest collection store id
600
+ *
601
+ * @access public
602
+ * @return string
603
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
604
+ */
605
+ public function getRestCollectionStoreId()
606
+ {
607
+ return '';
608
+ }
609
+
610
+ /**
611
+ * get default attribute values
612
+ *
613
+ * @access public
614
+ * @return string
615
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
616
+ */
617
+ public function getDefaultAttributeValues()
618
+ {
619
+ $content = '';
620
+ foreach ($this->getEntity()->getAttributes() as $attribute) {
621
+ $defaultValue = $attribute->getDefaultValueProcessed();
622
+ if (!empty($defaultValue)) {
623
+ $content .= $this->getPadding(2).
624
+ '$values[\''.$attribute->getCode().'\'] = \''.$defaultValue.'\';'.$this->getEol();
625
+ }
626
+ }
627
+ if ($content) {
628
+ $content .= $this->getEol();
629
+ }
630
+ return $content;
631
+ }
632
+
633
+ /**
634
+ * get additional to option array select
635
+ *
636
+ * @access public
637
+ * @return string
638
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
639
+ */
640
+ public function getToOptionArraySelect()
641
+ {
642
+ return '';
643
+ }
644
+ }
app/code/community/Ultimate/ModuleCreator/Model/Entity/Type/Eav.php CHANGED
@@ -1,783 +1,971 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
- */
18
- class Ultimate_ModuleCreator_Model_Entity_Type_Eav extends Ultimate_ModuleCreator_Model_Entity_Type_Abstract{
19
- protected $_parentAttributes = null;
20
- /**
21
- * get collection attributes
22
- * @access public
23
- * @return string
24
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
25
- */
26
- public function getCollectionAttributes(){
27
- $result = '';
28
- $eol = $this->getEol();
29
- $padding = $this->getPadding(3);
30
- foreach ($this->_getParentAttributes() as $attribute) {
31
- $result .= $eol;
32
- $result .= $padding;
33
- $result .= '->addAttributeToSelect(\''.$attribute->getCode().'\')';
34
- }
35
- foreach ($this->getEntity()->getAttributes() as $attribute){
36
- if ($attribute->getAdminGrid() && $attribute->getCode() != $this->getEntity()->getNameAttributeCode()){
37
- $result .= $eol;
38
- $result .= $padding;
39
- $result .= '->addAttributeToSelect(\''.$attribute->getCode().'\')';
40
- }
41
- }
42
- foreach ($this->getEntity()->getSimulatedAttributes('status') as $attribute){
43
- $result .= $eol;
44
- $result .= $padding;
45
- $result .= '->addAttributeToSelect(\''.$attribute->getCode().'\')';
46
- }
47
- if ($this->getEntity()->getUrlRewrite()){
48
- foreach ($this->getEntity()->getSimulatedAttributes('url_rewrite') as $attribute){
49
- $result .= $eol;
50
- $result .= $padding;
51
- $result .= '->addAttributeToSelect(\''.$attribute->getCode().'\')';
52
- }
53
- }
54
- return $result;
55
- }
56
- /**
57
- * get admin join
58
- * @access public
59
- * @return string
60
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
61
- */
62
- public function getAdminJoin(){
63
- $eol = $this->getEol();
64
- $result = $eol;
65
- $result .= $this->getPadding(2).'$adminStore = Mage_Core_Model_App::ADMIN_STORE_ID;'.$eol;
66
- $result .= $this->getPadding(2).'$store = $this->_getStore();'.$eol;
67
- $result .= $this->getPadding(2).'$collection->joinAttribute(\''.$this->getEntity()->getNameAttributeCode().'\', \''.strtolower($this->getEntity()->getModule()->getNamespace()).'_'.$this->getEntity()->getModule()->getLowerModuleName().'_'.$this->getEntity()->getNameSingular().'/'.$this->getEntity()->getNameAttributeCode().'\', \'entity_id\', null, \'inner\', $adminStore);'.$eol;
68
- $result .= $this->getPadding(2).'if ($store->getId()) {'.$eol;
69
- $result .= $this->getPadding(3). '$collection->joinAttribute(\''.$this->getModule()->getNamespace(true).'_'.$this->getModule()->getLowerModuleName().'_'.$this->getEntity()->getNameSingular().'_'.$this->getEntity()->getNameAttributeCode().'\', \''.$this->getModule()->getNamespace(true).'_'.$this->getModule()->getLowerModuleName().'_'.$this->getEntity()->getNameSingular().'/'.$this->getEntity()->getNameAttributeCode().'\', \'entity_id\', null, \'inner\', $store->getId());'.$eol;
70
- $result .= $this->getPadding(2).'}'.$eol;
71
- return $result;
72
- }
73
-
74
- /**
75
- * prepare columns header
76
- * @access public
77
- * @return string
78
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
79
- */
80
- public function getPrepareColumnsHeader(){
81
- return '$store = $this->_getStore();'.$this->getEol().$this->getPadding(2);
82
- }
83
-
84
- /**
85
- * get name attribute for grid
86
- * @access public
87
- * @return string
88
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
89
- */
90
- public function getNameAttributeGridEav(){
91
- $eol = $this->getEol();
92
- $result = $eol;
93
- $result .= $this->getPadding(2).'if ($this->_getStore()->getId()){'.$eol;
94
- $result .= $this->getPadding(3). '$this->addColumn(\''.$this->getNamespace(true).'_'.$this->getLowerModuleName().'_'.$this->getEntity()->getNameSingular().'_'.$this->getEntity()->getNameAttributeCode().'\', array('.$eol;
95
- $result .= $this->getPadding(4). '\'header\' => Mage::helper(\''.$this->getNamespace(true).'_'.$this->getLowerModuleName().'\')->__(\''.$this->getEntity()->getNameAttributeLabel().' in %s\', $this->_getStore()->getName()),'.$eol;
96
- $result .= $this->getPadding(4). '\'align\' => \'left\','.$eol;
97
- $result .= $this->getPadding(4). '\'index\' => \''.$this->getNamespace(true).'_'.$this->getLowerModuleName().'_'.$this->getEntity()->getNameSingular().'_'.$this->getEntity()->getNameAttributeCode().'\','.$eol;
98
- $result .= $this->getPadding(3). '));'.$eol;
99
- $result .= $this->getPadding(2).'}'.$eol;
100
- return $result;
101
- }
102
-
103
- /**
104
- * eav always has image
105
- * @access public
106
- * @return bool
107
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
108
- */
109
- public function getHasImage(){
110
- return true;
111
- }
112
- /**
113
- * eav always has files
114
- * @access public
115
- * @return bool
116
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
117
- */
118
- public function getHasFile(){
119
- return true;
120
- }
121
- /**
122
- * eav always has submenu
123
- * @access public
124
- * @return bool
125
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
126
- */
127
- public function getHasSubmenu(){
128
- return true;
129
- }
130
- /**
131
- * get additional menu
132
- * @access public
133
- * @param $padding
134
- * @return bool
135
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
136
- */
137
- public function getAdditionalMenu($padding) {
138
- $extension = $this->getModule()->getExtensionName(true);
139
- $module = $this->getLowerModuleName();
140
- $entity = $this->getEntity()->getNameSingular(true);
141
- $entityTitle = $this->getEntity()->getLabelSingular();
142
- $action = $module.'_'.$entity;
143
- $eol = $this->getEol();
144
-
145
- $text = $this->getPadding($padding).'<'.$entity.'_attributes translate="title" module="'.$extension.'">'.$eol;
146
- $text .= $this->getPadding($padding + 1).'<title>Manage '.$entityTitle.' Attributes</title>'.$eol;
147
- $text .= $this->getPadding($padding + 1).'<action>adminhtml/'.$action.'_attribute</action>'.$eol;
148
- $text .= $this->getPadding($padding + 1).'<sort_order>'.($this->getEntity()->getPosition() + 7).'</sort_order>'.$eol;
149
- $text .= $this->getPadding($padding).'</'.$entity.'_attributes>'.$eol;
150
- return $text;
151
- }
152
-
153
- /**
154
- * get additional menu acl
155
- * @access public
156
- * @param $padding
157
- * @return string
158
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
159
- */
160
- public function getAdditionalMenuAcl($padding) {
161
- $extension = $this->getModule()->getExtensionName(true);
162
- $entity = $this->getEntity()->getNameSingular(true);
163
- $entityTitle = $this->getEntity()->getLabelSingular();
164
- $eol = $this->getEol();
165
-
166
- $text = $this->getPadding($padding).'<'.$entity.'_attributes translate="title" module="'.$extension.'">'.$eol;
167
- $text .= $this->getPadding($padding + 1).'<title>Manage '.$entityTitle.' attributes</title>'.$eol;
168
- $text .= $this->getPadding($padding + 1).'<sort_order>'.($this->getEntity()->getPosition() + 7).'</sort_order>'.$eol;
169
- $text .= $this->getPadding($padding).'</'.$entity.'_attributes>'.$eol;
170
- return $text;
171
- }
172
- /**
173
- * allow comments by store
174
- * @access public
175
- * @return string
176
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
177
- */
178
- public function getAllowCommentByStore() {
179
- return $this->getEntity()->getAllowComment();
180
- }
181
-
182
- /**
183
- * get parent attributes
184
- * @access protected
185
- * @return Ultimate_ModuleCreator_Model_Attribute[]
186
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
187
- */
188
- protected function _getParentAttributes(){
189
- if (is_null($this->_parentAttributes)) {
190
- $parents = $this->getEntity()->getRelatedEntities(Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_CHILD);
191
- $this->_parentAttributes = array();
192
- foreach ($parents as $parent) {
193
- $module = $parent->getModule()->getLowerModuleName();
194
- $namespace = $parent->getModule()->getNamespace(true);
195
- $name = $parent->getNameSingular();
196
- /** @var Ultimate_ModuleCreator_Model_Attribute $attr */
197
- $attr = Mage::getModel('modulecreator/attribute');
198
- $attr->setCode($name.'_id');
199
- $attr->setLabel($parent->getLabelSingular());
200
- $attr->setType('dropdown');
201
- $attr->setOptionsSource('custom');
202
- $attr->setForcedSource($namespace.'_'.$module.'/'.$name.'_source');
203
- $attr->setScope(Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL);
204
- $attr->setEntity($this->getEntity());
205
- $attr->setUseFilterIndex(true);
206
- $this->_parentAttributes[] = $attr;
207
- }
208
- }
209
- return $this->_parentAttributes;
210
- }
211
-
212
- /**
213
- * get attributes content for setup
214
- * @access public
215
- * @return string
216
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
217
- */
218
- public function getAttributesSetup() {
219
- $content = '';
220
- $position = 0;
221
- //all parent attributes
222
- /** @var Ultimate_ModuleCreator_Model_Attribute $attribute */
223
- foreach ($this->_getParentAttributes() as $attribute) {
224
- $content .= $attribute->getSetupContent();
225
- }
226
- foreach ($this->getEntity()->getAttributes() as $attribute){
227
- $content .= $attribute->getSetupContent();
228
- $position = $attribute->getPosition();
229
- }
230
- $position += 10;
231
- foreach ($this->getEntity()->getSimulatedAttributes(null, false, array('tree')) as $attribute) {
232
- $attribute->setPosition($position);
233
- $content .= $attribute->getSetupContent();
234
- $position += 10;
235
- }
236
- foreach ($this->getEntity()->getSimulatedAttributes('tree', false) as $attribute){
237
- $attribute->setForcedSetupType('static');
238
- $attribute->setForcedVisible(0);
239
- $content .= $attribute->getSetupContent();
240
- $position += 10;
241
- }
242
- return $content;
243
- }
244
- /**
245
- * get parent class for the entity resource model
246
- * @access public
247
- * @return string
248
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
249
- */
250
- public function getResourceModelParent(){
251
- return 'Mage_Catalog_Model_Resource_Abstract';
252
- }
253
- /**
254
- * get parent class for the entity resource collection model
255
- * @access public
256
- * @return string
257
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
258
- */
259
- public function getResourceCollectionModelParent(){
260
- return 'Mage_Catalog_Model_Resource_Collection_Abstract';
261
- }
262
- /**
263
- * get related entities relations table
264
- * @access public
265
- * @return string
266
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
267
- */
268
- public function getResourceRelationsTables() {
269
- $padding = $this->getPadding(2);
270
- $content = '';
271
- $eol = $this->getEol();
272
- $entity = $this->getEntity()->getNameSingular(true);
273
- $module = $this->getLowerModuleName();
274
- $namespace = $this->getNamespace(true);
275
- if ($this->getEntity()->getLinkProduct()){
276
- $content .= $padding.'$'.'this->_'.$entity.'ProductTable = $'."this->getTable('".$namespace.'_'.$module."/".$entity."_product');".$eol;
277
- }
278
- if ($this->getEntity()->getLinkCategory()){
279
- $content .= $padding.'$'.'this->_'.$entity.'CategoryTable = $'."this->getTable('".$namespace.'_'.$module."/".$entity."_category');".$eol;
280
- }
281
- $related = $this->getEntity()->getRelatedEntities(Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_SIBLING);
282
- foreach ($related as $_entity){
283
- $_entityUc = ucfirst($_entity->getNameSingular());
284
- $_entityLower = $_entity->getNameSingular(true);
285
- $content .= $padding.'$'.'this->_'.$entity.$_entityUc.'Table = $'."this->getTable('".$namespace.'_'.$module."/".$entity."_".$_entityLower."');".$eol;
286
- }
287
- return $content;
288
- }
289
- /**
290
- * get related entities relations table declaration
291
- * @access public
292
- * @return string
293
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
294
- */
295
- public function getResourceRelationsTablesDeclare() {
296
- $padding = $this->getPadding();
297
- $content = '';
298
- $eol = $this->getEol();
299
- $entity = $this->getEntity()->getNameSingular(true);
300
- if ($this->getEntity()->getLinkProduct()) {
301
- $content .= $padding.'protected $'.'_'.$entity.'ProductTable = null;'.$eol;
302
- }
303
- if ($this->getEntity()->getLinkCategory()) {
304
- $content .= $padding.'protected $'.'_'.$entity.'CategoryTable = null;'.$eol;
305
- }
306
- $related = $this->getEntity()->getRelatedEntities(Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_SIBLING);
307
- foreach ($related as $_entity) {
308
- $_entityUc = ucfirst($_entity->getNameSingular());
309
- $content .= $padding.'protected $'.'_'.$entity.$_entityUc.'Table = null;'.$eol;
310
- }
311
- return $content;
312
- }
313
- /**
314
- * get admin layout content for index page
315
- * @access public
316
- * @return string
317
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
318
- */
319
- public function getAdminIndexLayoutContent() {
320
- $entity = $this->getEntity()->getNameSingular(true);
321
- $module = $this->getLowerModuleName();
322
- $namespace = $this->getNamespace(true);
323
- $eol = $this->getEol();
324
- $content = $this->getPadding(3).'<block type="'.$namespace.'_'.$module.'/adminhtml_'.$entity.'" name="'.$entity.'">'.$eol;
325
- $content .= $this->getPadding(4).'<block type="adminhtml/store_switcher" name="store_switcher" as="store_switcher">'.$eol;
326
- $content .= $this->getPadding(5).'<action method="setUseConfirm"><params>0</params></action>'.$eol;
327
- $content .= $this->getPadding(4).'</block>'.$eol;
328
- $content .= $this->getPadding(3).'</block>'.$eol;
329
- return $content;
330
- }
331
- /**
332
- * get the parent model class
333
- * @access public
334
- * @return mixed
335
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
336
- */
337
- public function getEntityParentModel() {
338
- return 'Mage_Catalog_Model_Abstract';
339
- }
340
- /**
341
- * get entity table alias
342
- * @access public
343
- * @return mixed
344
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
345
- */
346
- public function getEntityTableAlias() {
347
- return 'e';
348
- }
349
- /**
350
- * get additional prepare collection
351
- * @access public
352
- * @return mixed
353
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
354
- */
355
- public function getAdditionalPrepareCollection(){
356
- return "->addAttributeToSelect('".$this->getEntity()->getNameAttributeCode()."')";
357
- }
358
- /**
359
- * additional layout block for left section
360
- * @access public
361
- * @return mixed
362
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
363
- */
364
- public function getEditLayoutLeft() {
365
- return '<block type="adminhtml/store_switcher" name="store_switcher" before="-"></block>'.$this->getEol().$this->getPadding(3);
366
- }
367
- /**
368
- * additional layout block edit
369
- * @access public
370
- * @return mixed
371
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
372
- */
373
- public function getEditLayoutAdditional(){
374
- $content = '';
375
- $eol = $this->getEol();
376
- $content .= $eol.$this->getPadding(2).'<reference name="head">'.$eol;
377
- $content .= $this->getPadding(3).'<action method="setCanLoadTinyMce"><load>1</load></action>'.$eol;
378
- $content .= $this->getPadding(2).'</reference>'.$eol;
379
- $content .= $this->getPadding(2).'<reference name="js">'.$eol;
380
- $content .= $this->getPadding(3).'<block type="core/template" name="catalog.wysiwyg.js" template="catalog/wysiwyg/js.phtml"/>'.$eol;
381
- $content .= $this->getPadding(2).'</reference>';
382
- return $content;
383
- }
384
- /**
385
- * get param name for before save
386
- * @access public
387
- * @return mixed
388
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
389
- */
390
- public function getBeforeSaveParam() {
391
- return 'Varien_Object';
392
- }
393
- /**
394
- * entity attribute set string
395
- * @access public
396
- * @return string
397
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
398
- */
399
- public function getEntityAttributeSetId() {
400
- $namespace = $this->getNamespace(true);
401
- $module = $this->getLowerModuleName();
402
- $entity = $this->getEntity()->getNameSingular(true);
403
- return $this->getEol().$this->getPadding()."->setAttributeSetId(Mage::getModel('".$namespace.'_'.$module.'/'.$entity."')->getDefaultAttributeSetId())";
404
- }
405
- /**
406
- * filter method name
407
- * @access public
408
- * @return string
409
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
410
- */
411
- public function getFilterMethod() {
412
- return 'addAttributeToFilter';
413
- }
414
- /**
415
- * convert multiple select fields to strings
416
- * @access public
417
- * @return mixed
418
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
419
- */
420
- public function getMultipleSelectConvert(){
421
- return $this->getEol();
422
- }
423
- /**
424
- * check if the entity helper can be created
425
- * @access public
426
- * @return bool
427
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
428
- */
429
- public function getCanCreateEntityHelper(){
430
- return true;
431
- }
432
- /**
433
- * get additional code for toOptionArray()
434
- * @access public
435
- * @return string
436
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
437
- */
438
- public function getToOptionAddition(){
439
- $attribute = $this->getEntity()->getNameAttributeCode();
440
- return '$this->addAttributeToSelect(\''.$attribute.'\');'.$this->getEol().$this->getPadding(2);
441
- }
442
- /**
443
- * get comment name field filter index
444
- * @access public
445
- * @return string
446
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
447
- */
448
- public function getCommentFilterIndexPrefix() {
449
- return '';
450
- }
451
- /**
452
- * get additional api xml
453
- * @access public
454
- * @return string
455
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
456
- */
457
- public function getApiAdditional(){
458
- $eol = $this->getEol();
459
- $padding = $this->getPadding(5);
460
- $tab = $this->getPadding();
461
- $content = '';
462
- $content .= $padding.'<currentStore>'.$eol;
463
- $content .= $padding.$tab.'<title>Set/Get current store view</title>'.$eol;
464
- $content .= $padding.'</currentStore>'.$eol;
465
- $content .= $padding.'<listOfAdditionalAttributes translate="title" module="'.$this->getNamespace(true).'_'.$this->getLowerModuleName().'">'.$eol;
466
- $content .= $padding.$tab.'<title>Get list of non-default attributes</title>'.$eol;
467
- $content .= $padding.$tab.'<method>getAdditionalAttributes</method>'.$eol;
468
- $content .= $padding.'</listOfAdditionalAttributes>'.$eol;
469
- return $content;
470
- }
471
- /**
472
- * get additional api faults
473
- * @access public
474
- * @return string
475
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
476
- */
477
- public function getApiFaults(){
478
- $eol = $this->getEol();
479
- $padding = $this->getPadding(5);
480
- $tab = $this->getPadding();
481
- $content = '';
482
- $content .= $padding.'<store_not_exists>'.$eol;
483
- $content .= $padding.$tab.'<code>100</code>'.$eol;
484
- $content .= $padding.$tab.'<message>Requested store view not found.</message>'.$eol;
485
- $content .= $padding.'</store_not_exists>'.$eol;
486
- return $content;
487
- }
488
- /**
489
- * additional API subentities.
490
- * @access public
491
- * @return string
492
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
493
- */
494
- public function getApiAdditionalSettings() {
495
- $content = '';
496
- $padding = $this->getPadding(3);
497
- $tab = $this->getPadding();
498
- $module = $this->getLowerModuleName();
499
- $entity = $this->getEntity()->getNameSingular(true);
500
- $eol = $this->getEol();
501
- $content .= $eol;
502
- $extension = $this->getModule()->getExtensionName(true);
503
- $content .= $padding.'<'.$module.'_'.$entity.'_attribute translate="title" module="'.$extension.'">'.$eol;
504
- $content .= $padding.$tab.'<title>Product attributes API</title>'.$eol;
505
- $content .= $padding.$tab.'<model>'.$extension.'/'.$entity.'_attribute_api</model>'.$eol;
506
- $content .= $padding.$tab.'<acl>'.$module.'/'.$entity.'</acl>'.$eol;
507
- $content .= $padding.$tab.'<methods>'.$eol;
508
- $content .= $padding.$tab.$tab.'<currentStore translate="title" module="'.$extension.'">'.$eol;
509
- $content .= $padding.$tab.$tab.$tab.'<title>Set/Get current store view</title>'.$eol;
510
- $content .= $padding.$tab.$tab.$tab.'<acl>'.$module.'/'.$entity.'_attribute/write</acl>'.$eol;
511
- $content .= $padding.$tab.$tab.'</currentStore>'.$eol;
512
- $content .= $padding.$tab.$tab.'<list translate="title" module="'.$extension.'">'.$eol;
513
- $content .= $padding.$tab.$tab.$tab.'<title>Retrieve attribute list</title>'.$eol;
514
- $content .= $padding.$tab.$tab.$tab.'<method>items</method>'.$eol;
515
- $content .= $padding.$tab.$tab.$tab.'<acl>'.$module.'/'.$entity.'_attribute/read</acl>'.$eol;
516
- $content .= $padding.$tab.$tab.'</list>'.$eol;
517
- $content .= $padding.$tab.$tab.'<options translate="title" module="'.$extension.'">'.$eol;
518
- $content .= $padding.$tab.$tab.$tab.'<title>Retrieve attribute options</title>'.$eol;
519
- $content .= $padding.$tab.$tab.$tab.'<acl>'.$module.'/'.$entity.'_attribute/read</acl>'.$eol;
520
- $content .= $padding.$tab.$tab.'</options>'.$eol;
521
- $content .= $padding.$tab.$tab.'<types translate="title" module="'.$extension.'">'.$eol;
522
- $content .= $padding.$tab.$tab.$tab.'<title>Get list of possible attribute types</title>'.$eol;
523
- $content .= $padding.$tab.$tab.$tab.'<acl>'.$module.'/'.$entity.'_attribute/types</acl>'.$eol;
524
- $content .= $padding.$tab.$tab.'</types>'.$eol;
525
- $content .= $padding.$tab.$tab.'<create translate="title" module="'.$extension.'">'.$eol;
526
- $content .= $padding.$tab.$tab.$tab.'<title>Create new attribute</title>'.$eol;
527
- $content .= $padding.$tab.$tab.$tab.'<acl>'.$module.'/'.$entity.'_attribute/create</acl>'.$eol;
528
- $content .= $padding.$tab.$tab.'</create>'.$eol;
529
- $content .= $padding.$tab.$tab.'<update translate="title" module="'.$extension.'">'.$eol;
530
- $content .= $padding.$tab.$tab.$tab.'<title>Update attribute</title>'.$eol;
531
- $content .= $padding.$tab.$tab.$tab.'<acl>'.$module.'/'.$entity.'_attribute/update</acl>'.$eol;
532
- $content .= $padding.$tab.$tab.'</update>'.$eol;
533
- $content .= $padding.$tab.$tab.'<remove translate="title" module="'.$extension.'">'.$eol;
534
- $content .= $padding.$tab.$tab.$tab.'<title>Delete attribute</title>'.$eol;
535
- $content .= $padding.$tab.$tab.$tab.'<acl>'.$module.'/'.$entity.'_attribute/remove</acl>'.$eol;
536
- $content .= $padding.$tab.$tab.'</remove>'.$eol;
537
- $content .= $padding.$tab.$tab.'<info translate="title" module="'.$extension.'">'.$eol;
538
- $content .= $padding.$tab.$tab.$tab.'<title>Get full information about attribute with list of options</title>'.$eol;
539
- $content .= $padding.$tab.$tab.$tab.'<acl>'.$module.'/'.$entity.'_attribute/info</acl>'.$eol;
540
- $content .= $padding.$tab.$tab.'</info>'.$eol;
541
- $content .= $padding.$tab.$tab.'<addOption translate="title" module="'.$extension.'">'.$eol;
542
- $content .= $padding.$tab.$tab.$tab.'<title>Add option</title>'.$eol;
543
- $content .= $padding.$tab.$tab.$tab.'<acl>'.$module.'/'.$entity.'_attribute/option/add</acl>'.$eol;
544
- $content .= $padding.$tab.$tab.'</addOption>'.$eol;
545
- $content .= $padding.$tab.$tab.'<removeOption translate="title" module="'.$extension.'">'.$eol;
546
- $content .= $padding.$tab.$tab.$tab.'<title>Remove option</title>'.$eol;
547
- $content .= $padding.$tab.$tab.$tab.'<acl>'.$module.'/'.$entity.'_attribute/option/remove</acl>'.$eol;
548
- $content .= $padding.$tab.$tab.'</removeOption>'.$eol;
549
- $content .= $padding.$tab.'</methods>'.$eol;
550
- $content .= $padding.$tab.'<faults module="'.$extension.'">'.$eol;
551
- $content .= $padding.$tab.$tab.'<store_not_exists>'.$eol;
552
- $content .= $padding.$tab.$tab.$tab.'<code>100</code>'.$eol;
553
- $content .= $padding.$tab.$tab.$tab.'<message>Requested store view not found.</message>'.$eol;
554
- $content .= $padding.$tab.$tab.'</store_not_exists>'.$eol;
555
- $content .= $padding.$tab.$tab.'<not_exists>'.$eol;
556
- $content .= $padding.$tab.$tab.$tab.'<code>101</code>'.$eol;
557
- $content .= $padding.$tab.$tab.$tab.'<message>Requested attribute not found.</message>'.$eol;
558
- $content .= $padding.$tab.$tab.'</not_exists>'.$eol;
559
- $content .= $padding.$tab.$tab.'<invalid_parameters>'.$eol;
560
- $content .= $padding.$tab.$tab.$tab.'<code>102</code>'.$eol;
561
- $content .= $padding.$tab.$tab.$tab.'<message>Invalid request parameters.</message>'.$eol;
562
- $content .= $padding.$tab.$tab.'</invalid_parameters>'.$eol;
563
- $content .= $padding.$tab.$tab.'<invalid_code>'.$eol;
564
- $content .= $padding.$tab.$tab.$tab.'<code>103</code>'.$eol;
565
- $content .= $padding.$tab.$tab.$tab.'<message>Attribute code is invalid. Please use only letters (a-z), numbers (0-9) or underscore(_) in this field, first character should be a letter.</message>'.$eol;
566
- $content .= $padding.$tab.$tab.'</invalid_code>'.$eol;
567
- $content .= $padding.$tab.$tab.'<invalid_frontend_input>'.$eol;
568
- $content .= $padding.$tab.$tab.$tab.'<code>104</code>'.$eol;
569
- $content .= $padding.$tab.$tab.$tab.'<message>Incorrect attribute type.</message>'.$eol;
570
- $content .= $padding.$tab.$tab.'</invalid_frontend_input>'.$eol;
571
- $content .= $padding.$tab.$tab.'<unable_to_save>'.$eol;
572
- $content .= $padding.$tab.$tab.$tab.'<code>105</code>'.$eol;
573
- $content .= $padding.$tab.$tab.$tab.'<message>Unable to save attribute.</message>'.$eol;
574
- $content .= $padding.$tab.$tab.'</unable_to_save>'.$eol;
575
- $content .= $padding.$tab.$tab.'<can_not_delete>'.$eol;
576
- $content .= $padding.$tab.$tab.$tab.'<code>106</code>'.$eol;
577
- $content .= $padding.$tab.$tab.$tab.'<message>This attribute cannot be deleted.</message>'.$eol;
578
- $content .= $padding.$tab.$tab.'</can_not_delete>'.$eol;
579
- $content .= $padding.$tab.$tab.'<can_not_edit>'.$eol;
580
- $content .= $padding.$tab.$tab.$tab.'<code>107</code>'.$eol;
581
- $content .= $padding.$tab.$tab.$tab.'<message>This attribute cannot be edited.</message>'.$eol;
582
- $content .= $padding.$tab.$tab.'</can_not_edit>'.$eol;
583
- $content .= $padding.$tab.$tab.'<unable_to_add_option>'.$eol;
584
- $content .= $padding.$tab.$tab.$tab.'<code>108</code>'.$eol;
585
- $content .= $padding.$tab.$tab.$tab.'<message>Unable to add option.</message>'.$eol;
586
- $content .= $padding.$tab.$tab.'</unable_to_add_option>'.$eol;
587
- $content .= $padding.$tab.$tab.'<unable_to_remove_option>'.$eol;
588
- $content .= $padding.$tab.$tab.$tab.'<code>109</code>'.$eol;
589
- $content .= $padding.$tab.$tab.$tab.'<message>Unable to remove option.</message>'.$eol;
590
- $content .= $padding.$tab.$tab.'</unable_to_remove_option>'.$eol;
591
- $content .= $padding.$tab.'</faults>'.$eol;
592
- $content .= $padding.'</'.$module.'_'.$entity.'_attribute>'.$eol;
593
- return $content;
594
- }
595
-
596
- /**
597
- * get subentities acl
598
- * @access public
599
- * @return string
600
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
601
- */
602
- public function getSubEntitiesAcl(){
603
- $content = '';
604
- $padding = $this->getPadding(5);
605
- $tab = $this->getPadding();
606
- $entity = $this->getEntity()->getNameSingular(true);
607
- $eol = $this->getEol();
608
- $title = $this->getEntity()->getLabelSingular().' Attributes';
609
- $extension = $this->getModule()->getExtensionName(true);
610
- $content .= $eol;
611
-
612
- $content .= $padding.'<'.$entity.'_attribute translate="title" module="'.$extension.'">'.$eol;
613
- $content .= $padding.$tab.'<title>'.$title.'</title>'.$eol;
614
- $content .= $padding.$tab.'<sort_order>'.($this->getEntity()->getPosition() + 6).'</sort_order>'.$eol;
615
- $content .= $padding.$tab.'<currentStore translate="title" module="'.$extension.'">'.$eol;
616
- $content .= $padding.$tab.$tab.'<title>Set/Get current store view</title>'.$eol;
617
- $content .= $padding.$tab.'</currentStore>'.$eol;
618
- $content .= $padding.$tab.'<list translate="title" module="'.$extension.'">'.$eol;
619
- $content .= $padding.$tab.$tab.'<title>Retrieve attribute list</title>'.$eol;
620
- $content .= $padding.$tab.'</list>'.$eol;
621
- $content .= $padding.$tab.'<options translate="title" module="'.$extension.'">'.$eol;
622
- $content .= $padding.$tab.$tab.'<title>Retrieve attribute options</title>'.$eol;
623
- $content .= $padding.$tab.'</options>'.$eol;
624
- $content .= $padding.$tab.'<types translate="title" module="'.$extension.'">'.$eol;
625
- $content .= $padding.$tab.$tab.'<title>Get list of possible attribute types</title>'.$eol;
626
- $content .= $padding.$tab.'</types>'.$eol;
627
- $content .= $padding.$tab.'<create translate="title" module="'.$extension.'">'.$eol;
628
- $content .= $padding.$tab.$tab.'<title>Create new attribute</title>'.$eol;
629
- $content .= $padding.$tab.'</create>'.$eol;
630
- $content .= $padding.$tab.'<update translate="title" module="'.$extension.'">'.$eol;
631
- $content .= $padding.$tab.$tab.'<title>Update attribute</title>'.$eol;
632
- $content .= $padding.$tab.'</update>'.$eol;
633
- $content .= $padding.$tab.'<remove translate="title" module="'.$extension.'">'.$eol;
634
- $content .= $padding.$tab.$tab.'<title>Remove attribute</title>'.$eol;
635
- $content .= $padding.$tab.'</remove>'.$eol;
636
- $content .= $padding.$tab.'<info translate="title" module="'.$extension.'">'.$eol;
637
- $content .= $padding.$tab.$tab.'<title>Get full information about attribute with list of options</title>'.$eol;
638
- $content .= $padding.$tab.'</info>'.$eol;
639
- $content .= $padding.$tab.'<addOption translate="title" module="'.$extension.'">'.$eol;
640
- $content .= $padding.$tab.$tab.'<title>Add option</title>'.$eol;
641
- $content .= $padding.$tab.'</addOption>'.$eol;
642
- $content .= $padding.$tab.'<removeOption translate="title" module="'.$extension.'">'.$eol;
643
- $content .= $padding.$tab.$tab.'<title>Remove option</title>'.$eol;
644
- $content .= $padding.$tab.'</removeOption>'.$eol;
645
- $content .= $padding.'</'.$entity.'_attribute>'.$eol;
646
- return $content;
647
- }
648
- /**
649
- * get api aliases
650
- * @access public
651
- * @return string
652
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
653
- */
654
- public function getApiResourcesAlias() {
655
- $content = '';
656
- $padding = $this->getPadding(3);
657
- $module = $this->getLowerModuleName();
658
- $entity = $this->getEntity()->getNameSingular(true);
659
- $eol = $this->getEol();
660
- $content .= $eol;
661
- $content .= $padding.'<'.$entity.'_attribute>'.$module.'_'.$entity.'_attribute</'.$entity.'_attribute>';
662
- return $content;
663
- }
664
- /**
665
- * get api V2 aliases
666
- * @access public
667
- * @return string
668
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
669
- */
670
- public function getApiResourcesAliasV2() {
671
- $content = '';
672
- $padding = $this->getPadding(4);
673
- $module = $this->getLowerModuleName();
674
- $entity = $this->getEntity()->getNameSingular(true);
675
- $eol = $this->getEol();
676
- $content .= $eol;
677
- $content .= $padding.'<'.$entity.'_attribute>'.$module.ucfirst($entity).'Attribute</'.$entity.'_attribute>';
678
- return $content;
679
- }
680
- /**
681
- * get attributes format for wsdl
682
- * @access public
683
- * @param bool $wsi
684
- * @return string
685
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
686
- */
687
- public function getWsdlAttributes($wsi = false){
688
- $tab = $this->getPadding();
689
- $padding = str_repeat($tab, 5);
690
- $eol = $this->getEol();
691
- $content = '';
692
- $module = $this->getLowerModuleName();
693
- $entity = ucfirst($this->getEntity()->getNameSingular(true));
694
- if (!$wsi) {
695
- $content .= $padding.'<element name="additional_attributes" type="typens:'.$module.$entity.'AdditionalAttributesEntity" minOccurs="0"/>'.$eol;
696
- }
697
- else {
698
- $content .= $padding.'<xsd:element name="additional_attributes" type="typens:associativeArray" minOccurs="0" />'.$eol;
699
- }
700
- return $content;
701
- }
702
- /**
703
- * get default api attributes
704
- * @access public
705
- * @return string
706
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
707
- */
708
- public function getDefaultApiAttributes(){
709
- $padding = $this->getPadding();
710
- $tab = $padding;
711
- $eol = $this->getEol();
712
- $entity = $this->getEntity();
713
- $content = $padding.'protected $_defaultAttributeList = array('.$eol;
714
- $parents = $entity->getRelatedEntities(Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_CHILD);
715
- foreach ($parents as $parent){
716
- $content .= $padding.$tab."'".$parent->getNameSingular(true).'_id'."', ".$eol;
717
- }
718
- foreach ($entity->getAttributes() as $attribute){
719
- $content .= $padding.$tab."'".$attribute->getCode()."'".', '.$eol;
720
- }
721
- $simulated = $entity->getSimulatedAttributes(null, false);
722
- foreach ($simulated as $attr){
723
- //if (!$attr->getIgnoreApi()){
724
- $content .= $padding.$tab."'".$attr->getCode()."'".', '.$eol;
725
- //}
726
- }
727
- $content .= $padding.$tab."'created_at', ".$eol;
728
- $content .= $padding.$tab."'updated_at', ".$eol;
729
- $content .= $padding.');'.$eol;
730
- return $content;
731
- }
732
- /**
733
- * get add all attributes to collection
734
- * @access public
735
- * @return string
736
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
737
- */
738
- public function getAllAttributesToCollection() {
739
- return '->addAttributeToSelect(\'*\')';
740
- }
741
- /**
742
- * get load store id statement
743
- * @access public
744
- * @return string
745
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
746
- */
747
- public function getLoadStoreId() {
748
- return '->setStoreId(Mage::app()->getStore()->getId())';
749
- }
750
- /**
751
- * @access public
752
- * @return string
753
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
754
- */
755
- public function getRestCollectionCleanup() {
756
- return '';
757
- }
758
- /**
759
- * @access public
760
- * @return string
761
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
762
- */
763
- public function getRestCollectionStoreId() {
764
- return $this->getEol().$this->getPadding(2).'$collection->setStoreId($this->_getStore()->getId());';
765
- }
766
- /**
767
- * @access public
768
- * @return string
769
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
770
- */
771
- public function getDefaultAttributeValues(){
772
- return '';
773
- }
774
- /**
775
- * get additional to option array select
776
- * @access public
777
- * @return string
778
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
779
- */
780
- public function getToOptionArraySelect() {
781
- return '->addAttributeToSelect(\''.$this->getEntity()->getNameAttributeCode().'\')';
782
- }
783
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
+ */
18
+ class Ultimate_ModuleCreator_Model_Entity_Type_Eav extends Ultimate_ModuleCreator_Model_Entity_Type_Abstract
19
+ {
20
+ /**
21
+ * parent entities FK
22
+ *
23
+ * @var null
24
+ */
25
+ protected $_parentAttributes = null;
26
+
27
+ /**
28
+ * get collection attributes
29
+ *
30
+ * @access public
31
+ * @return string
32
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
33
+ */
34
+ public function getCollectionAttributes()
35
+ {
36
+ $result = '';
37
+ $eol = $this->getEol();
38
+ $padding = $this->getPadding(3);
39
+ foreach ($this->_getParentAttributes() as $attribute) {
40
+ $result .= $eol;
41
+ $result .= $padding;
42
+ $result .= '->addAttributeToSelect(\''.$attribute->getCode().'\')';
43
+ }
44
+ foreach ($this->getEntity()->getAttributes() as $attribute) {
45
+ if ($attribute->getAdminGrid() && $attribute->getCode() != $this->getEntity()->getNameAttributeCode()) {
46
+ $result .= $eol;
47
+ $result .= $padding;
48
+ $result .= '->addAttributeToSelect(\''.$attribute->getCode().'\')';
49
+ }
50
+ }
51
+ foreach ($this->getEntity()->getSimulatedAttributes('status') as $attribute) {
52
+ $result .= $eol;
53
+ $result .= $padding;
54
+ $result .= '->addAttributeToSelect(\''.$attribute->getCode().'\')';
55
+ }
56
+ if ($this->getEntity()->getUrlRewrite()) {
57
+ foreach ($this->getEntity()->getSimulatedAttributes('url_rewrite') as $attribute) {
58
+ $result .= $eol;
59
+ $result .= $padding;
60
+ $result .= '->addAttributeToSelect(\''.$attribute->getCode().'\')';
61
+ }
62
+ }
63
+ return $result;
64
+ }
65
+
66
+ /**
67
+ * get admin join
68
+ *
69
+ * @access public
70
+ * @return string
71
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
72
+ */
73
+ public function getAdminJoin()
74
+ {
75
+ $eol = $this->getEol();
76
+ $result = $eol;
77
+ $result .= $this->getPadding(2).'$adminStore = Mage_Core_Model_App::ADMIN_STORE_ID;'.$eol;
78
+ $result .= $this->getPadding(2).'$store = $this->_getStore();'.$eol;
79
+ $result .= $this->getPadding(2).'$collection->joinAttribute('.$eol.$this->getPadding(3).'\''.
80
+ $this->getEntity()->getNameAttributeCode().'\', '.$eol.$this->getPadding(3).'\''.
81
+ strtolower($this->getEntity()->getModule()->getNamespace()).'_'.
82
+ $this->getEntity()->getModule()->getLowerModuleName().'_'.
83
+ $this->getEntity()->getNameSingular().'/'.
84
+ $this->getEntity()->getNameAttributeCode().'\', '.
85
+ $eol.$this->getPadding(3).'\'entity_id\', '
86
+ .$eol.$this->getPadding(3).'null, '.
87
+ $eol.$this->getPadding(3).'\'inner\', '.
88
+ $eol.$this->getPadding(3).'$adminStore'
89
+ .$eol.$this->getPadding(2).');'.$eol;
90
+ $result .= $this->getPadding(2).'if ($store->getId()) {'.$eol;
91
+ $result .= $this->getPadding(3). '$collection->joinAttribute(\''.
92
+ $eol.$this->getPadding(4).$this->getModule()->getNamespace(true).'_'.
93
+ $this->getModule()->getLowerModuleName().'_'.
94
+ $this->getEntity()->getNameSingular().'_'.
95
+ $this->getEntity()->getNameAttributeCode().'\', '.
96
+ $eol.$this->getPadding(4).'\''.$this->getModule()->getNamespace(true).
97
+ '_'.$this->getModule()->getLowerModuleName().
98
+ '_'.$this->getEntity()->getNameSingular().
99
+ '/'.$this->getEntity()->getNameAttributeCode().'\', '.
100
+ $eol.$this->getPadding(4).'\'entity_id\', '.
101
+ $eol.$this->getPadding(4).'null, '.
102
+ $eol.$this->getPadding(4).'\'inner\', '.
103
+ $eol.$this->getPadding(4).'$store->getId()'.
104
+ $eol.$this->getPadding(3).');'.$eol;
105
+ $result .= $this->getPadding(2).'}'.$eol;
106
+ return $result;
107
+ }
108
+
109
+ /**
110
+ * prepare columns header
111
+ *
112
+ * @access public
113
+ * @return string
114
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
115
+ */
116
+ public function getPrepareColumnsHeader()
117
+ {
118
+ return '$store = $this->_getStore();'.$this->getEol().$this->getPadding(2);
119
+ }
120
+
121
+ /**
122
+ * get name attribute for grid
123
+ *
124
+ * @access public
125
+ * @return string
126
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
127
+ */
128
+ public function getNameAttributeGridEav()
129
+ {
130
+ $eol = $this->getEol();
131
+ $result = $eol;
132
+ $result .= $this->getPadding(2).'if ($this->_getStore()->getId()) {'.$eol;
133
+ $result .= $this->getPadding(3). '$this->addColumn('.
134
+ $eol.$this->getPadding(4).'\''.$this->getNamespace(true).'_'.
135
+ $this->getLowerModuleName().'_'.$this->getEntity()->getNameSingular().'_'.
136
+ $this->getEntity()->getNameAttributeCode().'\', '.
137
+ $eol.$this->getPadding(4).'array('.$eol;
138
+ $result .= $this->getPadding(5). '\'header\' => Mage::helper(\''.
139
+ $this->getNamespace(true).'_'.$this->getLowerModuleName().'\')->__(\''.
140
+ $this->getEntity()->getNameAttributeLabel().' in %s\', $this->_getStore()->getName()),'.$eol;
141
+ $result .= $this->getPadding(5).'\'align\' => \'left\','.$eol;
142
+ $result .= $this->getPadding(5).'\'index\' => \''.
143
+ $this->getNamespace(true).'_'.$this->getLowerModuleName().'_'.
144
+ $this->getEntity()->getNameSingular().'_'.$this->getEntity()->getNameAttributeCode().'\','.$eol;
145
+ $result .= $this->getPadding(4).')'.
146
+ $eol.$this->getPadding(3).');'.$eol;
147
+ $result .= $this->getPadding(2).'}'.$eol;
148
+ return $result;
149
+ }
150
+
151
+ /**
152
+ * eav always has image
153
+ *
154
+ * @access public
155
+ * @return bool
156
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
157
+ */
158
+ public function getHasImage()
159
+ {
160
+ return true;
161
+ }
162
+
163
+ /**
164
+ * eav always has files
165
+ *
166
+ * @access public
167
+ * @return bool
168
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
169
+ */
170
+ public function getHasFile()
171
+ {
172
+ return true;
173
+ }
174
+
175
+ /**
176
+ * eav always has submenu
177
+ *
178
+ * @access public
179
+ * @return bool
180
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
181
+ */
182
+ public function getHasSubmenu()
183
+ {
184
+ return true;
185
+ }
186
+
187
+ /**
188
+ * get additional menu
189
+ *
190
+ * @access public
191
+ * @param $padding
192
+ * @return bool
193
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
194
+ */
195
+ public function getAdditionalMenu($padding)
196
+ {
197
+ $extension = $this->getModule()->getExtensionName(true);
198
+ $module = $this->getLowerModuleName();
199
+ $entity = $this->getEntity()->getNameSingular(true);
200
+ $entityTitle = $this->getEntity()->getLabelSingular();
201
+ $action = $module.'_'.$entity;
202
+ $eol = $this->getEol();
203
+
204
+ $text = $this->getPadding($padding).'<'.$entity.'_attributes translate="title" module="'.$extension.'">'.$eol;
205
+ $text .= $this->getPadding($padding + 1).'<title>Manage '.$entityTitle.' Attributes</title>'.$eol;
206
+ $text .= $this->getPadding($padding + 1).'<action>adminhtml/'.$action.'_attribute</action>'.$eol;
207
+ $text .= $this->getPadding($padding + 1).
208
+ '<sort_order>'.($this->getEntity()->getPosition() + 7).'</sort_order>'.$eol;
209
+ $text .= $this->getPadding($padding).'</'.$entity.'_attributes>'.$eol;
210
+ return $text;
211
+ }
212
+
213
+ /**
214
+ * get additional menu acl
215
+ *
216
+ * @access public
217
+ * @param $padding
218
+ * @return string
219
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
220
+ */
221
+ public function getAdditionalMenuAcl($padding)
222
+ {
223
+ $extension = $this->getModule()->getExtensionName(true);
224
+ $entity = $this->getEntity()->getNameSingular(true);
225
+ $entityTitle = $this->getEntity()->getLabelSingular();
226
+ $eol = $this->getEol();
227
+
228
+ $text = $this->getPadding($padding).'<'.$entity.'_attributes translate="title" module="'.$extension.'">'.$eol;
229
+ $text .= $this->getPadding($padding + 1).'<title>Manage '.$entityTitle.' attributes</title>'.$eol;
230
+ $text .= $this->getPadding($padding + 1).'<sort_order>'.
231
+ ($this->getEntity()->getPosition() + 7).'</sort_order>'.$eol;
232
+ $text .= $this->getPadding($padding).'</'.$entity.'_attributes>'.$eol;
233
+ return $text;
234
+ }
235
+
236
+ /**
237
+ * allow comments by store
238
+ *
239
+ * @access public
240
+ * @return string
241
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
242
+ */
243
+ public function getAllowCommentByStore()
244
+ {
245
+ return $this->getEntity()->getAllowComment();
246
+ }
247
+
248
+ /**
249
+ * get parent attributes
250
+ *
251
+ * @access protected
252
+ * @return Ultimate_ModuleCreator_Model_Attribute[]
253
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
254
+ */
255
+ protected function _getParentAttributes()
256
+ {
257
+ if (is_null($this->_parentAttributes)) {
258
+ $parents = $this->getEntity()->getRelatedEntities(
259
+ Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_CHILD
260
+ );
261
+ $this->_parentAttributes = array();
262
+ foreach ($parents as $parent) {
263
+ $module = $parent->getModule()->getLowerModuleName();
264
+ $namespace = $parent->getModule()->getNamespace(true);
265
+ $name = $parent->getNameSingular();
266
+ /** @var Ultimate_ModuleCreator_Model_Attribute $attr */
267
+ $attr = Mage::getModel('modulecreator/attribute');
268
+ $attr->setCode($name.'_id');
269
+ $attr->setLabel($parent->getLabelSingular());
270
+ $attr->setType('dropdown');
271
+ $attr->setOptionsSource('custom');
272
+ $attr->setForcedSource($namespace.'_'.$module.'/'.$name.'_source');
273
+ $attr->setScope(Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL);
274
+ $attr->setEntity($this->getEntity());
275
+ $attr->setUseFilterIndex(true);
276
+ $this->_parentAttributes[] = $attr;
277
+ }
278
+ }
279
+ return $this->_parentAttributes;
280
+ }
281
+
282
+ /**
283
+ * get attributes content for setup
284
+ *
285
+ * @access public
286
+ * @return string
287
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
288
+ */
289
+ public function getAttributesSetup()
290
+ {
291
+ $content = '';
292
+ $position = 0;
293
+ //all parent attributes
294
+ /** @var Ultimate_ModuleCreator_Model_Attribute $attribute */
295
+ foreach ($this->_getParentAttributes() as $attribute) {
296
+ $content .= $attribute->getSetupContent();
297
+ }
298
+ foreach ($this->getEntity()->getAttributes() as $attribute) {
299
+ $content .= $attribute->getSetupContent();
300
+ $position = $attribute->getPosition();
301
+ }
302
+ $position += 10;
303
+ foreach ($this->getEntity()->getSimulatedAttributes(null, false, array('tree')) as $attribute) {
304
+ $attribute->setPosition($position);
305
+ $content .= $attribute->getSetupContent();
306
+ $position += 10;
307
+ }
308
+ foreach ($this->getEntity()->getSimulatedAttributes('tree', false) as $attribute) {
309
+ $attribute->setForcedSetupType('static');
310
+ $attribute->setForcedVisible(0);
311
+ $content .= $attribute->getSetupContent();
312
+ $position += 10;
313
+ }
314
+ return $content;
315
+ }
316
+
317
+ /**
318
+ * get parent class for the entity resource model
319
+ *
320
+ * @access public
321
+ * @return string
322
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
323
+ */
324
+ public function getResourceModelParent()
325
+ {
326
+ return 'Mage_Catalog_Model_Resource_Abstract';
327
+ }
328
+
329
+ /**
330
+ * get parent class for the entity resource collection model
331
+ *
332
+ * @access public
333
+ * @return string
334
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
335
+ */
336
+ public function getResourceCollectionModelParent()
337
+ {
338
+ return 'Mage_Catalog_Model_Resource_Collection_Abstract';
339
+ }
340
+
341
+ /**
342
+ * get related entities relations table
343
+ *
344
+ * @access public
345
+ * @return string
346
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
347
+ */
348
+ public function getResourceRelationsTables()
349
+ {
350
+ $padding = $this->getPadding(2);
351
+ $content = '';
352
+ $eol = $this->getEol();
353
+ $entity = $this->getEntity()->getNameSingular(true);
354
+ $module = $this->getLowerModuleName();
355
+ $namespace = $this->getNamespace(true);
356
+ if ($this->getEntity()->getLinkProduct()) {
357
+ $content .= $padding.'$'.'this->_'.
358
+ $entity.'ProductTable = $'."this->getTable('".
359
+ $namespace.'_'.$module."/".$entity."_product');".$eol;
360
+ }
361
+ if ($this->getEntity()->getLinkCategory()) {
362
+ $content .= $padding.'$'.'this->_'.
363
+ $entity.'CategoryTable = $'."this->getTable('".
364
+ $namespace.'_'.$module."/".$entity."_category');".$eol;
365
+ }
366
+ $related = $this->getEntity()->getRelatedEntities(Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_SIBLING);
367
+ foreach ($related as $_entity) {
368
+ $_entityUc = ucfirst($_entity->getNameSingular());
369
+ $_entityLower = $_entity->getNameSingular(true);
370
+ $content .= $padding.'$'.'this->_'.
371
+ $entity.$_entityUc.'Table = $'."this->getTable('".
372
+ $namespace.'_'.$module."/".$entity."_".$_entityLower."');".$eol;
373
+ }
374
+ return $content;
375
+ }
376
+
377
+ /**
378
+ * get related entities relations table declaration
379
+ *
380
+ * @access public
381
+ * @return string
382
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
383
+ */
384
+ public function getResourceRelationsTablesDeclare()
385
+ {
386
+ $padding = $this->getPadding();
387
+ $content = '';
388
+ $eol = $this->getEol();
389
+ $entity = $this->getEntity()->getNameSingular(true);
390
+ if ($this->getEntity()->getLinkProduct()) {
391
+ $content .= $padding.'protected $'.'_'.$entity.'ProductTable = null;'.$eol;
392
+ }
393
+ if ($this->getEntity()->getLinkCategory()) {
394
+ $content .= $padding.'protected $'.'_'.$entity.'CategoryTable = null;'.$eol;
395
+ }
396
+ $related = $this->getEntity()->getRelatedEntities(Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_SIBLING);
397
+ foreach ($related as $_entity) {
398
+ $_entityUc = ucfirst($_entity->getNameSingular());
399
+ $content .= $padding.'protected $'.'_'.$entity.$_entityUc.'Table = null;'.$eol;
400
+ }
401
+ return $content;
402
+ }
403
+
404
+ /**
405
+ * get admin layout content for index page
406
+ *
407
+ * @access public
408
+ * @return string
409
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
410
+ */
411
+ public function getAdminIndexLayoutContent()
412
+ {
413
+ $entity = $this->getEntity()->getNameSingular(true);
414
+ $module = $this->getLowerModuleName();
415
+ $namespace = $this->getNamespace(true);
416
+ $eol = $this->getEol();
417
+ $content = $this->getPadding(3).
418
+ '<block type="'.$namespace.'_'.$module.
419
+ '/adminhtml_'.$entity.'" name="'.$entity.'">'.$eol;
420
+ $content .= $this->getPadding(4).
421
+ '<block type="adminhtml/store_switcher" name="store_switcher" as="store_switcher">'.$eol;
422
+ $content .= $this->getPadding(5).'<action method="setUseConfirm"><params>0</params></action>'.$eol;
423
+ $content .= $this->getPadding(4).'</block>'.$eol;
424
+ $content .= $this->getPadding(3).'</block>'.$eol;
425
+ return $content;
426
+ }
427
+
428
+ /**
429
+ * get the parent model class
430
+ *
431
+ * @access public
432
+ * @return mixed
433
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
434
+ */
435
+ public function getEntityParentModel()
436
+ {
437
+ return 'Mage_Catalog_Model_Abstract';
438
+ }
439
+
440
+ /**
441
+ * get entity table alias
442
+ *
443
+ * @access public
444
+ * @return mixed
445
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
446
+ */
447
+ public function getEntityTableAlias()
448
+ {
449
+ return 'e';
450
+ }
451
+
452
+ /**
453
+ * get additional prepare collection
454
+ *
455
+ * @access public
456
+ * @return mixed
457
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
458
+ */
459
+ public function getAdditionalPrepareCollection()
460
+ {
461
+ return "->addAttributeToSelect('".$this->getEntity()->getNameAttributeCode()."')";
462
+ }
463
+
464
+ /**
465
+ * additional layout block for left section
466
+ *
467
+ * @access public
468
+ * @return mixed
469
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
470
+ */
471
+ public function getEditLayoutLeft()
472
+ {
473
+ return '<block type="adminhtml/store_switcher" name="store_switcher" before="-"></block>'.
474
+ $this->getEol().$this->getPadding(3);
475
+ }
476
+
477
+ /**
478
+ * additional layout block edit
479
+ *
480
+ * @access public
481
+ * @return mixed
482
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
483
+ */
484
+ public function getEditLayoutAdditional()
485
+ {
486
+ $content = '';
487
+ $eol = $this->getEol();
488
+ $content .= $eol.$this->getPadding(2).'<reference name="head">'.$eol;
489
+ $content .= $this->getPadding(3).'<action method="setCanLoadTinyMce"><load>1</load></action>'.$eol;
490
+ $content .= $this->getPadding(2).'</reference>'.$eol;
491
+ $content .= $this->getPadding(2).'<reference name="js">'.$eol;
492
+ $content .= $this->getPadding(3).
493
+ '<block type="core/template" name="catalog.wysiwyg.js" template="catalog/wysiwyg/js.phtml"/>'.
494
+ $eol;
495
+ $content .= $this->getPadding(2).'</reference>';
496
+ return $content;
497
+ }
498
+
499
+ /**
500
+ * get param name for before save
501
+ *
502
+ * @access public
503
+ * @return mixed
504
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
505
+ */
506
+ public function getBeforeSaveParam()
507
+ {
508
+ return 'Varien_Object';
509
+ }
510
+
511
+ /**
512
+ * entity attribute set string
513
+ *
514
+ * @access public
515
+ * @return string
516
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
517
+ */
518
+ public function getEntityAttributeSetId()
519
+ {
520
+ $namespace = $this->getNamespace(true);
521
+ $module = $this->getLowerModuleName();
522
+ $entity = $this->getEntity()->getNameSingular(true);
523
+ return $this->getEol().$this->getPadding().
524
+ "->setAttributeSetId(Mage::getModel('".$namespace.'_'.$module.'/'.$entity.
525
+ "')->getDefaultAttributeSetId())";
526
+ }
527
+
528
+ /**
529
+ * filter method name
530
+ *
531
+ * @access public
532
+ * @return string
533
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
534
+ */
535
+ public function getFilterMethod()
536
+ {
537
+ return 'addAttributeToFilter';
538
+ }
539
+
540
+ /**
541
+ * convert multiple select fields to strings
542
+ *
543
+ * @access public
544
+ * @return mixed
545
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
546
+ */
547
+ public function getMultipleSelectConvert()
548
+ {
549
+ return $this->getEol();
550
+ }
551
+
552
+ /**
553
+ * check if the entity helper can be created
554
+ *
555
+ * @access public
556
+ * @return bool
557
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
558
+ */
559
+ public function getCanCreateEntityHelper()
560
+ {
561
+ return true;
562
+ }
563
+
564
+ /**
565
+ * get additional code for toOptionArray()
566
+ *
567
+ * @access public
568
+ * @return string
569
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
570
+ */
571
+ public function getToOptionAddition()
572
+ {
573
+ $attribute = $this->getEntity()->getNameAttributeCode();
574
+ return '$this->addAttributeToSelect(\''.$attribute.'\');'.$this->getEol().$this->getPadding(2);
575
+ }
576
+
577
+ /**
578
+ * get comment name field filter index
579
+ *
580
+ * @access public
581
+ * @return string
582
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
583
+ */
584
+ public function getCommentFilterIndexPrefix()
585
+ {
586
+ return '';
587
+ }
588
+
589
+ /**
590
+ * get additional api xml
591
+ *
592
+ * @access public
593
+ * @return string
594
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
595
+ */
596
+ public function getApiAdditional()
597
+ {
598
+ $eol = $this->getEol();
599
+ $padding = $this->getPadding(5);
600
+ $tab = $this->getPadding();
601
+ $content = '';
602
+ $content .= $padding.'<currentStore>'.$eol;
603
+ $content .= $padding.$tab.'<title>Set/Get current store view</title>'.$eol;
604
+ $content .= $padding.'</currentStore>'.$eol;
605
+ $content .= $padding.'<listOfAdditionalAttributes translate="title" module="'.
606
+ $this->getNamespace(true).'_'.$this->getLowerModuleName().'">'.$eol;
607
+ $content .= $padding.$tab.'<title>Get list of non-default attributes</title>'.$eol;
608
+ $content .= $padding.$tab.'<method>getAdditionalAttributes</method>'.$eol;
609
+ $content .= $padding.'</listOfAdditionalAttributes>'.$eol;
610
+ return $content;
611
+ }
612
+
613
+ /**
614
+ * get additional api faults
615
+ *
616
+ * @access public
617
+ * @return string
618
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
619
+ */
620
+ public function getApiFaults()
621
+ {
622
+ $eol = $this->getEol();
623
+ $padding = $this->getPadding(5);
624
+ $tab = $this->getPadding();
625
+ $content = '';
626
+ $content .= $padding.'<store_not_exists>'.$eol;
627
+ $content .= $padding.$tab.'<code>100</code>'.$eol;
628
+ $content .= $padding.$tab.'<message>Requested store view not found.</message>'.$eol;
629
+ $content .= $padding.'</store_not_exists>'.$eol;
630
+ return $content;
631
+ }
632
+
633
+ /**
634
+ * additional API subentities.
635
+ *
636
+ * @access public
637
+ * @return string
638
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
639
+ */
640
+ public function getApiAdditionalSettings()
641
+ {
642
+ $content = '';
643
+ $padding = $this->getPadding(3);
644
+ $tab = $this->getPadding();
645
+ $module = $this->getLowerModuleName();
646
+ $entity = $this->getEntity()->getNameSingular(true);
647
+ $eol = $this->getEol();
648
+ $content .= $eol;
649
+ $extension = $this->getModule()->getExtensionName(true);
650
+ $content .= $padding.'<'.$module.'_'.$entity.'_attribute translate="title" module="'.$extension.'">'.$eol;
651
+ $content .= $padding.$tab.'<title>Product attributes API</title>'.$eol;
652
+ $content .= $padding.$tab.'<model>'.$extension.'/'.$entity.'_attribute_api</model>'.$eol;
653
+ $content .= $padding.$tab.'<acl>'.$module.'/'.$entity.'</acl>'.$eol;
654
+ $content .= $padding.$tab.'<methods>'.$eol;
655
+ $content .= $padding.$tab.$tab.'<currentStore translate="title" module="'.$extension.'">'.$eol;
656
+ $content .= $padding.$tab.$tab.$tab.'<title>Set/Get current store view</title>'.$eol;
657
+ $content .= $padding.$tab.$tab.$tab.'<acl>'.$module.'/'.$entity.'_attribute/write</acl>'.$eol;
658
+ $content .= $padding.$tab.$tab.'</currentStore>'.$eol;
659
+ $content .= $padding.$tab.$tab.'<list translate="title" module="'.$extension.'">'.$eol;
660
+ $content .= $padding.$tab.$tab.$tab.'<title>Retrieve attribute list</title>'.$eol;
661
+ $content .= $padding.$tab.$tab.$tab.'<method>items</method>'.$eol;
662
+ $content .= $padding.$tab.$tab.$tab.'<acl>'.$module.'/'.$entity.'_attribute/read</acl>'.$eol;
663
+ $content .= $padding.$tab.$tab.'</list>'.$eol;
664
+ $content .= $padding.$tab.$tab.'<options translate="title" module="'.$extension.'">'.$eol;
665
+ $content .= $padding.$tab.$tab.$tab.'<title>Retrieve attribute options</title>'.$eol;
666
+ $content .= $padding.$tab.$tab.$tab.'<acl>'.$module.'/'.$entity.'_attribute/read</acl>'.$eol;
667
+ $content .= $padding.$tab.$tab.'</options>'.$eol;
668
+ $content .= $padding.$tab.$tab.'<types translate="title" module="'.$extension.'">'.$eol;
669
+ $content .= $padding.$tab.$tab.$tab.'<title>Get list of possible attribute types</title>'.$eol;
670
+ $content .= $padding.$tab.$tab.$tab.'<acl>'.$module.'/'.$entity.'_attribute/types</acl>'.$eol;
671
+ $content .= $padding.$tab.$tab.'</types>'.$eol;
672
+ $content .= $padding.$tab.$tab.'<create translate="title" module="'.$extension.'">'.$eol;
673
+ $content .= $padding.$tab.$tab.$tab.'<title>Create new attribute</title>'.$eol;
674
+ $content .= $padding.$tab.$tab.$tab.'<acl>'.$module.'/'.$entity.'_attribute/create</acl>'.$eol;
675
+ $content .= $padding.$tab.$tab.'</create>'.$eol;
676
+ $content .= $padding.$tab.$tab.'<update translate="title" module="'.$extension.'">'.$eol;
677
+ $content .= $padding.$tab.$tab.$tab.'<title>Update attribute</title>'.$eol;
678
+ $content .= $padding.$tab.$tab.$tab.'<acl>'.$module.'/'.$entity.'_attribute/update</acl>'.$eol;
679
+ $content .= $padding.$tab.$tab.'</update>'.$eol;
680
+ $content .= $padding.$tab.$tab.'<remove translate="title" module="'.$extension.'">'.$eol;
681
+ $content .= $padding.$tab.$tab.$tab.'<title>Delete attribute</title>'.$eol;
682
+ $content .= $padding.$tab.$tab.$tab.'<acl>'.$module.'/'.$entity.'_attribute/remove</acl>'.$eol;
683
+ $content .= $padding.$tab.$tab.'</remove>'.$eol;
684
+ $content .= $padding.$tab.$tab.'<info translate="title" module="'.$extension.'">'.$eol;
685
+ $content .= $padding.$tab.$tab.$tab.
686
+ '<title>Get full information about attribute with list of options</title>'.
687
+ $eol;
688
+ $content .= $padding.$tab.$tab.$tab.'<acl>'.$module.'/'.$entity.'_attribute/info</acl>'.$eol;
689
+ $content .= $padding.$tab.$tab.'</info>'.$eol;
690
+ $content .= $padding.$tab.$tab.'<addOption translate="title" module="'.$extension.'">'.$eol;
691
+ $content .= $padding.$tab.$tab.$tab.'<title>Add option</title>'.$eol;
692
+ $content .= $padding.$tab.$tab.$tab.'<acl>'.$module.'/'.$entity.'_attribute/option/add</acl>'.$eol;
693
+ $content .= $padding.$tab.$tab.'</addOption>'.$eol;
694
+ $content .= $padding.$tab.$tab.'<removeOption translate="title" module="'.$extension.'">'.$eol;
695
+ $content .= $padding.$tab.$tab.$tab.'<title>Remove option</title>'.$eol;
696
+ $content .= $padding.$tab.$tab.$tab.'<acl>'.$module.'/'.$entity.'_attribute/option/remove</acl>'.$eol;
697
+ $content .= $padding.$tab.$tab.'</removeOption>'.$eol;
698
+ $content .= $padding.$tab.'</methods>'.$eol;
699
+ $content .= $padding.$tab.'<faults module="'.$extension.'">'.$eol;
700
+ $content .= $padding.$tab.$tab.'<store_not_exists>'.$eol;
701
+ $content .= $padding.$tab.$tab.$tab.'<code>100</code>'.$eol;
702
+ $content .= $padding.$tab.$tab.$tab.'<message>Requested store view not found.</message>'.$eol;
703
+ $content .= $padding.$tab.$tab.'</store_not_exists>'.$eol;
704
+ $content .= $padding.$tab.$tab.'<not_exists>'.$eol;
705
+ $content .= $padding.$tab.$tab.$tab.'<code>101</code>'.$eol;
706
+ $content .= $padding.$tab.$tab.$tab.'<message>Requested attribute not found.</message>'.$eol;
707
+ $content .= $padding.$tab.$tab.'</not_exists>'.$eol;
708
+ $content .= $padding.$tab.$tab.'<invalid_parameters>'.$eol;
709
+ $content .= $padding.$tab.$tab.$tab.'<code>102</code>'.$eol;
710
+ $content .= $padding.$tab.$tab.$tab.'<message>Invalid request parameters.</message>'.$eol;
711
+ $content .= $padding.$tab.$tab.'</invalid_parameters>'.$eol;
712
+ $content .= $padding.$tab.$tab.'<invalid_code>'.$eol;
713
+ $content .= $padding.$tab.$tab.$tab.'<code>103</code>'.$eol;
714
+ $content .= $padding.$tab.$tab.$tab.
715
+ '<message>Attribute code is invalid. Please use only letters (a-z), '.
716
+ 'numbers (0-9) or underscore(_) in this field, first character should be a letter.</message>'.
717
+ $eol;
718
+ $content .= $padding.$tab.$tab.'</invalid_code>'.$eol;
719
+ $content .= $padding.$tab.$tab.'<invalid_frontend_input>'.$eol;
720
+ $content .= $padding.$tab.$tab.$tab.'<code>104</code>'.$eol;
721
+ $content .= $padding.$tab.$tab.$tab.'<message>Incorrect attribute type.</message>'.$eol;
722
+ $content .= $padding.$tab.$tab.'</invalid_frontend_input>'.$eol;
723
+ $content .= $padding.$tab.$tab.'<unable_to_save>'.$eol;
724
+ $content .= $padding.$tab.$tab.$tab.'<code>105</code>'.$eol;
725
+ $content .= $padding.$tab.$tab.$tab.'<message>Unable to save attribute.</message>'.$eol;
726
+ $content .= $padding.$tab.$tab.'</unable_to_save>'.$eol;
727
+ $content .= $padding.$tab.$tab.'<can_not_delete>'.$eol;
728
+ $content .= $padding.$tab.$tab.$tab.'<code>106</code>'.$eol;
729
+ $content .= $padding.$tab.$tab.$tab.'<message>This attribute cannot be deleted.</message>'.$eol;
730
+ $content .= $padding.$tab.$tab.'</can_not_delete>'.$eol;
731
+ $content .= $padding.$tab.$tab.'<can_not_edit>'.$eol;
732
+ $content .= $padding.$tab.$tab.$tab.'<code>107</code>'.$eol;
733
+ $content .= $padding.$tab.$tab.$tab.'<message>This attribute cannot be edited.</message>'.$eol;
734
+ $content .= $padding.$tab.$tab.'</can_not_edit>'.$eol;
735
+ $content .= $padding.$tab.$tab.'<unable_to_add_option>'.$eol;
736
+ $content .= $padding.$tab.$tab.$tab.'<code>108</code>'.$eol;
737
+ $content .= $padding.$tab.$tab.$tab.'<message>Unable to add option.</message>'.$eol;
738
+ $content .= $padding.$tab.$tab.'</unable_to_add_option>'.$eol;
739
+ $content .= $padding.$tab.$tab.'<unable_to_remove_option>'.$eol;
740
+ $content .= $padding.$tab.$tab.$tab.'<code>109</code>'.$eol;
741
+ $content .= $padding.$tab.$tab.$tab.'<message>Unable to remove option.</message>'.$eol;
742
+ $content .= $padding.$tab.$tab.'</unable_to_remove_option>'.$eol;
743
+ $content .= $padding.$tab.'</faults>'.$eol;
744
+ $content .= $padding.'</'.$module.'_'.$entity.'_attribute>'.$eol;
745
+ return $content;
746
+ }
747
+
748
+ /**
749
+ * get subentities acl
750
+ *
751
+ * @access public
752
+ * @return string
753
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
754
+ */
755
+ public function getSubEntitiesAcl()
756
+ {
757
+ $content = '';
758
+ $padding = $this->getPadding(5);
759
+ $tab = $this->getPadding();
760
+ $entity = $this->getEntity()->getNameSingular(true);
761
+ $eol = $this->getEol();
762
+ $title = $this->getEntity()->getLabelSingular().' Attributes';
763
+ $extension = $this->getModule()->getExtensionName(true);
764
+ $content .= $eol;
765
+
766
+ $content .= $padding.'<'.$entity.'_attribute translate="title" module="'.$extension.'">'.$eol;
767
+ $content .= $padding.$tab.'<title>'.$title.'</title>'.$eol;
768
+ $content .= $padding.$tab.'<sort_order>'.($this->getEntity()->getPosition() + 6).'</sort_order>'.$eol;
769
+ $content .= $padding.$tab.'<currentStore translate="title" module="'.$extension.'">'.$eol;
770
+ $content .= $padding.$tab.$tab.'<title>Set/Get current store view</title>'.$eol;
771
+ $content .= $padding.$tab.'</currentStore>'.$eol;
772
+ $content .= $padding.$tab.'<list translate="title" module="'.$extension.'">'.$eol;
773
+ $content .= $padding.$tab.$tab.'<title>Retrieve attribute list</title>'.$eol;
774
+ $content .= $padding.$tab.'</list>'.$eol;
775
+ $content .= $padding.$tab.'<options translate="title" module="'.$extension.'">'.$eol;
776
+ $content .= $padding.$tab.$tab.'<title>Retrieve attribute options</title>'.$eol;
777
+ $content .= $padding.$tab.'</options>'.$eol;
778
+ $content .= $padding.$tab.'<types translate="title" module="'.$extension.'">'.$eol;
779
+ $content .= $padding.$tab.$tab.'<title>Get list of possible attribute types</title>'.$eol;
780
+ $content .= $padding.$tab.'</types>'.$eol;
781
+ $content .= $padding.$tab.'<create translate="title" module="'.$extension.'">'.$eol;
782
+ $content .= $padding.$tab.$tab.'<title>Create new attribute</title>'.$eol;
783
+ $content .= $padding.$tab.'</create>'.$eol;
784
+ $content .= $padding.$tab.'<update translate="title" module="'.$extension.'">'.$eol;
785
+ $content .= $padding.$tab.$tab.'<title>Update attribute</title>'.$eol;
786
+ $content .= $padding.$tab.'</update>'.$eol;
787
+ $content .= $padding.$tab.'<remove translate="title" module="'.$extension.'">'.$eol;
788
+ $content .= $padding.$tab.$tab.'<title>Remove attribute</title>'.$eol;
789
+ $content .= $padding.$tab.'</remove>'.$eol;
790
+ $content .= $padding.$tab.'<info translate="title" module="'.$extension.'">'.$eol;
791
+ $content .= $padding.$tab.$tab.'<title>Get full information about attribute with list of options</title>'.$eol;
792
+ $content .= $padding.$tab.'</info>'.$eol;
793
+ $content .= $padding.$tab.'<addOption translate="title" module="'.$extension.'">'.$eol;
794
+ $content .= $padding.$tab.$tab.'<title>Add option</title>'.$eol;
795
+ $content .= $padding.$tab.'</addOption>'.$eol;
796
+ $content .= $padding.$tab.'<removeOption translate="title" module="'.$extension.'">'.$eol;
797
+ $content .= $padding.$tab.$tab.'<title>Remove option</title>'.$eol;
798
+ $content .= $padding.$tab.'</removeOption>'.$eol;
799
+ $content .= $padding.'</'.$entity.'_attribute>'.$eol;
800
+ return $content;
801
+ }
802
+
803
+ /**
804
+ * get api aliases
805
+ *
806
+ * @access public
807
+ * @return string
808
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
809
+ */
810
+ public function getApiResourcesAlias()
811
+ {
812
+ $content = '';
813
+ $padding = $this->getPadding(3);
814
+ $module = $this->getLowerModuleName();
815
+ $entity = $this->getEntity()->getNameSingular(true);
816
+ $eol = $this->getEol();
817
+ $content .= $eol;
818
+ $content .= $padding.'<'.$entity.'_attribute>'.$module.'_'.$entity.'_attribute</'.$entity.'_attribute>';
819
+ return $content;
820
+ }
821
+
822
+ /**
823
+ * get api V2 aliases
824
+ *
825
+ * @access public
826
+ * @return string
827
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
828
+ */
829
+ public function getApiResourcesAliasV2()
830
+ {
831
+ $content = '';
832
+ $padding = $this->getPadding(4);
833
+ $module = $this->getLowerModuleName();
834
+ $entity = $this->getEntity()->getNameSingular(true);
835
+ $eol = $this->getEol();
836
+ $content .= $eol;
837
+ $content .= $padding.'<'.$entity.'_attribute>'.$module.ucfirst($entity).'Attribute</'.$entity.'_attribute>';
838
+ return $content;
839
+ }
840
+
841
+ /**
842
+ * get attributes format for wsdl
843
+ *
844
+ * @access public
845
+ * @param bool $wsi
846
+ * @return string
847
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
848
+ */
849
+ public function getWsdlAttributes($wsi = false)
850
+ {
851
+ $tab = $this->getPadding();
852
+ $padding = str_repeat($tab, 5);
853
+ $eol = $this->getEol();
854
+ $content = '';
855
+ $module = $this->getLowerModuleName();
856
+ $entity = ucfirst($this->getEntity()->getNameSingular(true));
857
+ if (!$wsi) {
858
+ $content .= $padding.
859
+ '<element name="additional_attributes" type="typens:'.$module.$entity.
860
+ 'AdditionalAttributesEntity" minOccurs="0"/>'.$eol;
861
+ } else {
862
+ $content .= $padding.
863
+ '<xsd:element name="additional_attributes" type="typens:associativeArray" minOccurs="0" />'.
864
+ $eol;
865
+ }
866
+ return $content;
867
+ }
868
+
869
+ /**
870
+ * get default api attributes
871
+ *
872
+ * @access public
873
+ * @return string
874
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
875
+ */
876
+ public function getDefaultApiAttributes()
877
+ {
878
+ $padding = $this->getPadding();
879
+ $tab = $padding;
880
+ $eol = $this->getEol();
881
+ $entity = $this->getEntity();
882
+ $content = $padding.'protected $_defaultAttributeList = array('.$eol;
883
+ $parents = $entity->getRelatedEntities(Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_CHILD);
884
+ foreach ($parents as $parent) {
885
+ $content .= $padding.$tab."'".$parent->getNameSingular(true).'_id'."', ".$eol;
886
+ }
887
+ foreach ($entity->getAttributes() as $attribute) {
888
+ $content .= $padding.$tab."'".$attribute->getCode()."'".', '.$eol;
889
+ }
890
+ $simulated = $entity->getSimulatedAttributes(null, false);
891
+ foreach ($simulated as $attr) {
892
+ $content .= $padding.$tab."'".$attr->getCode()."'".', '.$eol;
893
+ }
894
+ $content .= $padding.$tab."'created_at', ".$eol;
895
+ $content .= $padding.$tab."'updated_at', ".$eol;
896
+ $content .= $padding.');'.$eol;
897
+ return $content;
898
+ }
899
+
900
+ /**
901
+ * get add all attributes to collection
902
+ *
903
+ * @access public
904
+ * @return string
905
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
906
+ */
907
+ public function getAllAttributesToCollection()
908
+ {
909
+ return '->addAttributeToSelect(\'*\')';
910
+ }
911
+
912
+ /**
913
+ * get load store id statement
914
+ *
915
+ * @access public
916
+ * @return string
917
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
918
+ */
919
+ public function getLoadStoreId()
920
+ {
921
+ return '->setStoreId(Mage::app()->getStore()->getId())';
922
+ }
923
+
924
+ /**
925
+ * get rest collection cleanup
926
+ *
927
+ * @access public
928
+ * @return string
929
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
930
+ */
931
+ public function getRestCollectionCleanup()
932
+ {
933
+ return '';
934
+ }
935
+
936
+ /**
937
+ * get rest collection store id
938
+ *
939
+ * @access public
940
+ * @return string
941
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
942
+ */
943
+ public function getRestCollectionStoreId()
944
+ {
945
+ return $this->getEol().$this->getPadding(2).'$collection->setStoreId($this->_getStore()->getId());';
946
+ }
947
+
948
+ /**
949
+ * get default attribute values
950
+ *
951
+ * @access public
952
+ * @return string
953
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
954
+ */
955
+ public function getDefaultAttributeValues()
956
+ {
957
+ return '';
958
+ }
959
+
960
+ /**
961
+ * get additional to option array select
962
+ *
963
+ * @access public
964
+ * @return string
965
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
966
+ */
967
+ public function getToOptionArraySelect()
968
+ {
969
+ return '->addAttributeToSelect(\''.$this->getEntity()->getNameAttributeCode().'\')';
970
+ }
971
+ }
app/code/community/Ultimate/ModuleCreator/Model/Entity/Type/Flat.php CHANGED
@@ -1,28 +1,28 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
- */
18
- /**
19
- * flat entity type
20
- *
21
- * @category Ultimate
22
- * @package Ultimate_ModuleCreator
23
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
- */
25
- class Ultimate_ModuleCreator_Model_Entity_Type_Flat
26
- extends Ultimate_ModuleCreator_Model_Entity_Type_Abstract {
27
-
28
- }
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
+ */
18
+ /**
19
+ * flat entity type
20
+ *
21
+ * @category Ultimate
22
+ * @package Ultimate_ModuleCreator
23
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
+ */
25
+ class Ultimate_ModuleCreator_Model_Entity_Type_Flat extends Ultimate_ModuleCreator_Model_Entity_Type_Abstract
26
+ {
27
+
28
+ }
app/code/community/Ultimate/ModuleCreator/Model/Module.php CHANGED
@@ -1,1915 +1,2326 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
- */
18
- /**
19
- * @method string getFilenameId()
20
- * @method string getMenuParent()
21
- * @method Ultimate_ModuleCreator_Model_Module setRss()
22
- * @method Ultimate_ModuleCreator_Model_Module setHasFile()
23
- * @method Ultimate_ModuleCreator_Model_Module setHasImage()
24
- * @method Ultimate_ModuleCreator_Model_Module setAddSeo()
25
- * @method Ultimate_ModuleCreator_Model_Module setWidget()
26
- * @method Ultimate_ModuleCreator_Model_Module setCreateFrontend()
27
- * @method Ultimate_ModuleCreator_Model_Module setCanCreateRouter()
28
- * @method Ultimate_ModuleCreator_Model_Module setCreateList()
29
- * @method Ultimate_ModuleCreator_Model_Module setHasTree()
30
- * @method Ultimate_ModuleCreator_Model_Module setEditor()
31
- * @method Ultimate_ModuleCreator_Model_Module setHasConfigDefaults()
32
- * @method Ultimate_ModuleCreator_Model_Module setLinkProduct()
33
- * @method Ultimate_ModuleCreator_Model_Module setHasObserver()
34
- * @method Ultimate_ModuleCreator_Model_Module setLinkCategory()
35
- * @method Ultimate_ModuleCreator_Model_Module setLinkCore()
36
- * @method Ultimate_ModuleCreator_Model_Module setUrlRewrite()
37
- * @method Ultimate_ModuleCreator_Model_Module setHasEav()
38
- * @method Ultimate_ModuleCreator_Model_Module setHasFlat()
39
- * @method Ultimate_ModuleCreator_Model_Module setApi()
40
- * @method Ultimate_ModuleCreator_Model_Module setAllowComment()
41
- * @method Ultimate_ModuleCreator_Model_Module setAllowCommentByStore()
42
- * @method Ultimate_ModuleCreator_Model_Module setHasCountry()
43
- * @method Ultimate_ModuleCreator_Model_Module setHasSeo()
44
- * @method Ultimate_ModuleCreator_Model_Module setShowOnProduct()
45
- * @method Ultimate_ModuleCreator_Model_Module setShowOnCategory()
46
- * @method Ultimate_ModuleCreator_Model_Module setShowInCategoryMenu()
47
- * @method Ultimate_ModuleCreator_Model_Module setSearch()
48
- * @method Ultimate_ModuleCreator_Model_Module setHasCatalogAttribute()
49
- * @method Ultimate_ModuleCreator_Model_Module setRest()
50
- * @method string getModuleName()
51
- * @method int getInstall()
52
- * @method Ultimate_ModuleCreator_Model_Module setInstall()
53
- * @method bool getHasEav()
54
- * @method int getSortOrder()
55
- * @method string getMenuText()
56
- * @method string getCodepool()
57
- * @method string getVersion()
58
- * @method bool getCreateFrontend()
59
- * @method bool getLinkProduct()
60
- * @method bool getLinkCategory()
61
- * @method bool getHasCatalogAttribute()
62
- * @method bool getLinkCore()
63
- * @method bool getShowInCategoryMenu()
64
- */
65
- class Ultimate_ModuleCreator_Model_Module extends Ultimate_ModuleCreator_Model_Abstract{
66
- const EFFIN_VERSION_ENTERPRISE = '1.13.1';
67
- const EFFIN_VERSION_COMMUNITY = '1.8.1';
68
- /**
69
- * entity code
70
- * @var string
71
- */
72
- protected $_entityCode = 'umc_module';
73
- /**
74
- * module entities
75
- * @var array()
76
- */
77
- protected $_entities = array();
78
- /**
79
- * module config
80
- * @var mixed (null|Varien_Simplexml_Element)
81
- */
82
- protected $_config = null;
83
- /**
84
- * entity relations
85
- * @var array
86
- */
87
- protected $_relations = array();
88
- /**
89
- * io member
90
- * @var null|Varien_Io_File
91
- */
92
- protected $_io = null;
93
- /**
94
- * error log
95
- * @var array
96
- */
97
- protected $_errors = array();
98
- /**
99
- * source folder
100
- * @var null
101
- */
102
- protected $_sourceFolder = null;
103
- /**
104
- * placeholders
105
- * @var null
106
- */
107
- protected $_placeholders = null;
108
- /**
109
- * base placeholders
110
- * @var array
111
- */
112
- protected $_basePlaceholders = array();
113
- /**
114
- * generated files
115
- * @var array
116
- */
117
- protected $_files = array();
118
- /**
119
- * add entity to module
120
- * @access public
121
- * @param Ultimate_ModuleCreator_Model_Entity $entity
122
- * @return Ultimate_ModuleCreator_Model_Module
123
- * @throws Ultimate_ModuleCreator_Exception
124
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
125
- */
126
- public function addEntity(Ultimate_ModuleCreator_Model_Entity $entity){
127
- Mage::dispatchEvent('umc_module_add_entity_before', array('entity'=>$entity, 'module'=>$this));
128
- if (isset($this->_entities[$entity->getNameSingular()])){
129
- throw new Ultimate_ModuleCreator_Exception(Mage::helper('modulecreator')->__('An entity with the code "%s" already exists', $entity->getNameSingular()));
130
- }
131
- $entity->setModule($this);
132
- $entity->setIndex(count($this->_entities));
133
- $position = 10 * (count($this->_entities));
134
- $entity->setPosition($position);
135
- $this->_entities[$entity->getNameSingular()] = $entity;
136
- if ($entity->getRss()){
137
- $this->setRss(true);
138
- }
139
- if ($entity->getHasFile()){
140
- $this->setHasFile(true);
141
- }
142
- if ($entity->getHasImage()){
143
- $this->setHasImage(true);
144
- }
145
- if ($entity->getAddSeo()){
146
- $this->setAddSeo(true);
147
- }
148
- if ($entity->getWidget()){
149
- $this->setWidget(true);
150
- }
151
- if ($entity->getCreateFrontend()){
152
- $this->setCreateFrontend(true);
153
- $this->setCanCreateRouter(true);
154
- }
155
- if ($entity->getCreateList()){
156
- $this->setCreateList(true);
157
- }
158
- if ($entity->getIsTree()){
159
- $this->setHasTree(true);
160
- }
161
- if ($entity->getEditor()){
162
- $this->setEditor(true);
163
- }
164
- if ($entity->getHasConfigDefaults()){
165
- $this->setHasConfigDefaults(true);
166
- }
167
- if ($entity->getLinkProduct()){
168
- $this->setLinkProduct(true);
169
- $this->setHasObserver(true);
170
- }
171
- if ($entity->getLinkCategory()){
172
- $this->setLinkCategory(true);
173
- $this->setHasObserver(true);
174
- }
175
- if ($entity->getLinkCore()){
176
- $this->setLinkCore(true);
177
- }
178
- if ($entity->getUrlRewrite()){
179
- $this->setUrlRewrite(true);
180
- }
181
- if ($entity->getIsEav()) {
182
- $this->setHasEav(true);
183
- }
184
- if ($entity->getIsFlat()) {
185
- $this->setHasFlat(true);
186
- }
187
- if ($entity->getApi()){
188
- $this->setApi(true);
189
- }
190
- if ($entity->getAllowComment()){
191
- $this->setAllowComment(true);
192
- }
193
- if ($entity->getAllowCommentByStore()){
194
- $this->setAllowCommentByStore(true);
195
- }
196
- if ($entity->getHasCountry()){
197
- $this->setHasCountry(true);
198
- }
199
- if ($entity->getAddSeo()){
200
- $this->setHasSeo(true);
201
- }
202
- if ($entity->getCanCreateListBlock()){
203
- $this->setCreateFrontend(true);
204
- }
205
- if ($entity->getShowOnProduct()) {
206
- $this->setShowOnProduct(true);
207
- }
208
- if ($entity->getShowOnCategory()) {
209
- $this->setShowOnCategory(true);
210
- }
211
- if ($entity->getShowInCategoryMenu()) {
212
- $this->setShowInCategoryMenu(true);
213
- }
214
- if ($entity->getSearch()) {
215
- $this->setSearch(true);
216
- }
217
- if ($entity->getProductAttribute() ||$entity->getCategoryAttribute()) {
218
- $this->setHasCatalogAttribute(true);
219
- }
220
- if ($entity->getRest()) {
221
- $this->setRest(true);
222
- }
223
- Mage::dispatchEvent('umc_module_add_entity_after', array('entity'=>$entity, 'module'=>$this));
224
- return $this;
225
- }
226
- /**
227
- * get a module entity
228
- * @access public
229
- * @param string $code
230
- * @return mixed(Ultimate_ModuleCreator_Model_Entity|null)
231
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
232
- */
233
- public function getEntity($code){
234
- if (isset($this->_entities[$code])){
235
- return $this->_entities[$code];
236
- }
237
- return null;
238
- }
239
- /**
240
- * module to xml
241
- * @access public
242
- * @param array $arrAttributes
243
- * @param string $rootName
244
- * @param bool $addOpenTag
245
- * @param bool $addCdata
246
- * @return string
247
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
248
- */
249
- public function toXml(array $arrAttributes = array(), $rootName = 'module', $addOpenTag=false, $addCdata=false){
250
- $xml = '';
251
- $eol = $this->getEol();
252
- if ($addOpenTag) {
253
- $xml.= '<?xml version="1.0" encoding="UTF-8"?>'.$eol;
254
- }
255
- if (!empty($rootName)) {
256
- $xml.= '<'.$rootName.'>'.$eol;
257
- }
258
- $xml .= parent::toXml($this->getXmlAttributes(), '', false, $addCdata);
259
- $xml .= '<entities>'.$eol;
260
- foreach ($this->getEntities() as $entity){
261
- $xml .= $entity->toXml(array(), 'entity', false, $addCdata);
262
- }
263
- $xml .= '</entities>'.$eol;
264
- $xml .= '<relations>'.$eol;
265
- foreach ($this->getRelations() as $relation){
266
- $xml .= $relation->toXml(array(), '', false, $addCdata);
267
- }
268
- $xml .= '</relations>'.$eol;
269
- if (!empty($rootName)) {
270
- $xml.= '</'.$rootName.'>'.$eol;
271
- }
272
- return $xml;
273
- }
274
- /**
275
- * get the module entities
276
- * @access public
277
- * @return Ultimate_ModuleCreator_Model_Entity[]
278
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
279
- */
280
- public function getEntities(){
281
- $this->_prepareEntities();
282
- return $this->_entities;
283
- }
284
- /**
285
- * prepare the entities before saving
286
- * @access protected
287
- * @return Ultimate_ModuleCreator_Model_Module
288
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
289
- */
290
- protected function _prepareEntities(){
291
- Mage::dispatchEvent('umc_module_prepare_entities', array('module'=>$this));
292
- return $this;
293
- }
294
- /**
295
- * add relation to module
296
- * @access public
297
- * @param Ultimate_ModuleCreator_Model_Relation $relation
298
- * @return Ultimate_ModuleCreator_Model_Module
299
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
300
- */
301
- public function addRelation(Ultimate_ModuleCreator_Model_Relation $relation){
302
- Mage::dispatchEvent('umc_module_add_relation_before', array('relation'=>$relation, 'module'=>$this));
303
- $this->_relations[] = $relation;
304
- Mage::dispatchEvent('umc_module_add_relation_after', array('relation'=>$relation, 'module'=>$this));
305
- return $this;
306
- }
307
- /**
308
- * get module relations
309
- * @access public
310
- * @param mixed $type
311
- * @return Ultimate_ModuleCreator_Model_Relation[]
312
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
313
- */
314
- public function getRelations($type = null){
315
- if (is_null($type)){
316
- return $this->_relations;
317
- }
318
- $relations = array();
319
- foreach ($this->_relations as $relation){
320
- /** @var Ultimate_ModuleCreator_Model_Relation $relation */
321
- if ($relation->getType() == $type){
322
- $relations[] = $relation;
323
- }
324
- }
325
- return $relations;
326
- }
327
- /**
328
- * get the extensions xml path
329
- * @access public
330
- * @return string
331
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
332
- */
333
- public function getXmlPath(){
334
- return $this->getHelper()->getLocalPackagesPath().$this->getNamespace()."_".$this->getModuleName().'.xml';
335
- }
336
- /**
337
- * save the module as xml
338
- * @access public
339
- * @return Ultimate_ModuleCreator_Model_Module
340
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
341
- */
342
- public function save(){
343
- $destination = $this->getXmlPath();
344
- $xml = $this->toXml(array(), 'module', true, true);
345
- $this->_writeFile($destination, $xml);
346
- return $this;
347
- }
348
-
349
- /**
350
- * validate the module
351
- * @access public
352
- * @return array
353
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
354
- */
355
- public function validate(){
356
- $config = $this->getHelper()->getConfig();
357
- $settings = $config->getNode('forms/settings/fieldsets');
358
- foreach ($settings->fieldset as $set){
359
- foreach ($set->fields->children() as $key => $values){
360
- $v = $this->getData($key);
361
- if ((string)$values->required == 1 && (!$this->hasData($key) || $v === "")) {
362
- $this->_addError(Mage::helper("modulecreator")->__('This is a required field.'), 'settings_'.$key);
363
- }
364
- }
365
- }
366
- //validate namespace
367
- if (strtolower($this->getNamespace()) == 'mage'){
368
- $this->_addError(Mage::helper('modulecreator')->__("You shouldn't use the namespace Mage. Be Creative"), 'settings_namespace');
369
- }
370
- //validate module name
371
- $routers = Mage::getConfig()->getNode('frontend/routers');
372
- $moduleName = $this->getModuleName();
373
- $lower = strtolower($moduleName);
374
- $extension = $this->getExtensionName();
375
- if ($routers->$lower){
376
- if ((string)$routers->$lower->args->module != $extension) {
377
- $this->_addError(Mage::helper('modulecreator')->__('You cannot use the module name %s', $this->getModuleName()), 'settings_module_name');
378
- }
379
- }
380
- //validate front key
381
- foreach ((array)$routers as $router) {
382
- if ((string)$router->args->frontName == $this->getFrontKey() && $router->args->module != $extension){
383
- $this->_addError(Mage::helper('modulecreator')->__('You cannot use the front key %s. It is used by the module %s', $this->getFrontKey(), (string)$router->args->module), 'settings_front_key');
384
- break;
385
- }
386
- }
387
- //validate entity count
388
- if (count($this->getEntities()) == 0){
389
- $this->_addError(Mage::helper('modulecreator')->__('Add at least an entity'));
390
- }
391
- else {
392
- //validate entities
393
- foreach ($this->getEntities() as $entity){
394
- $entityCode = $entity->getNameSingular(true);
395
- if (in_array($entityCode, $this->getRestrictedEntityNames())){
396
- $this->_addError(Mage::helper('modulecreator')->__('The entity code "%s" is restricted', $entityCode), 'entity_'.$entity->getIndex().'_name_singular');
397
- }
398
- if (count($entity->getAttributes()) == 0){
399
- $this->_addError(Mage::helper('modulecreator')->__('The entity "%s" must have at least one attribute.', $entity->getLabelSingular()));
400
- }
401
- else{
402
- //validate name attribute
403
- if (is_null($entity->getNameAttribute())){
404
- $this->_addError(Mage::helper('modulecreator')->__('The entity "%s" must have an attribute that behaves as a name.', $entity->getLabelSingular()));
405
- }
406
- $restrictedAttributes = $this->getRestrictedAttributeCodes();
407
- //validate attributes
408
- foreach ($entity->getAttributes() as $attribute){
409
- $code = $attribute->getCode();
410
- if (isset($restrictedAttributes[$code])){
411
- //presume "not guilty"
412
- $valid = true;
413
- if (!isset($restrictedAttributes[$code]->depend_entity)){//if general restriction.
414
- $valid = false;
415
- }
416
- else{//if depends on entity setting.
417
- foreach ((array)$restrictedAttributes[$code]->depend_entity as $prop=>$value){
418
- if ($entity->getDataUsingMethod($prop) == $value){
419
- //"found guilty"
420
- $valid = false;
421
- break;
422
- }
423
- }
424
- }
425
- if (!$valid){
426
- $this->_addError($restrictedAttributes[$code]->message, 'attribute_'.$entity->getIndex().'_'.$attribute->getIndex().'_code');
427
- }
428
- }
429
- //validate attributes against getters ("getData", "getCollection", ,....)
430
- $methodCodes = $this->getMethodAttributeCodes();
431
- if (in_array($code, $methodCodes)){
432
- $method = $method = str_replace(' ', '', ucwords(str_replace('_', ' ', $code)));
433
- $this->_addError(Mage::helper('modulecreator')->__('Attribute code %s is restricted because a method similar to "set%s()" or "get%s()" exists in parent model class', $code, $method, $method), 'attribute_'.$entity->getIndex().'_'.$attribute->getIndex().'_code');
434
- }
435
- }
436
- }
437
- }
438
- }
439
-
440
- return $this->_errors;
441
- }
442
-
443
- /**
444
- * add an error to the error list
445
- * @access protected
446
- * @param $message
447
- * @param null $attribute
448
- * @param string $separator
449
- * @return Ultimate_ModuleCreator_Model_Module
450
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
451
- */
452
- protected function _addError($message, $attribute = null, $separator = '<br />'){
453
- if (empty($attribute)){
454
- $this->_errors[''][] = $message;
455
- }
456
- else{
457
- if (!isset($this->_errors[$attribute])){
458
- $this->_errors[$attribute] = '';
459
- }
460
- else{
461
- $this->_errors[$attribute] .= $separator;
462
- }
463
- $this->_errors[$attribute] .= $message;
464
- }
465
- return $this;
466
- }
467
- /**
468
- * write a file
469
- * @access protected
470
- * @param string $destinationFile
471
- * @param string $contents
472
- * @throws Exception
473
- * @return Ultimate_ModuleCreator_Model_Module
474
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
475
- */
476
- protected function _writeFile($destinationFile, $contents){
477
- try{
478
- $io = $this->getIo();
479
- $io->mkdir(dirname($destinationFile));
480
- /**
481
- * Varien_Io_File has changed in CE 1.8.1 / EE 1.13.1 A LOT
482
- */
483
- if (version_compare(Mage::getVersion(), $this->getEffinVersion(), '<')) {
484
- $io->write($destinationFile, $contents, 0777);
485
- }
486
- else {
487
- $io->filePutContent($destinationFile, $contents);
488
- }
489
-
490
- }
491
- catch (Exception $e){
492
- if ($e->getCode() != 0){
493
- throw $e;
494
- }
495
- }
496
- return $this;
497
- }
498
-
499
- /**
500
- * get the version for which the io writer has changed
501
- * @access public
502
- * @return string
503
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
504
- */
505
- public function getEffinVersion() {
506
- if (Mage::getEdition() == Mage::EDITION_ENTERPRISE) {
507
- return self::EFFIN_VERSION_ENTERPRISE;
508
- }
509
- return self::EFFIN_VERSION_COMMUNITY;
510
- }
511
- /**
512
- * get the IO - class
513
- * @access public
514
- * @return Varien_Io_File
515
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
516
- */
517
- public function getIo(){
518
- if (!$this->_io){
519
- $this->_io = new Varien_Io_File();
520
- $this->_io->setAllowCreateFolders(true);
521
- }
522
- return $this->_io;
523
- }
524
-
525
- /**
526
- * get module relations as json
527
- * @access public
528
- * @return string
529
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
530
- */
531
- public function getRelationsAsJson(){
532
- $json = array();
533
- $relations = $this->getRelations();
534
- foreach ($relations as $relation){
535
- $entities = $relation->getEntities();
536
- $json[$entities[0]->getIndex().'_'.$entities[1]->getIndex()] = $relation->getType();
537
- }
538
- return json_encode($json);
539
- }
540
-
541
- /**
542
- * get the extension name
543
- * @param bool $lower
544
- * @return string
545
- * @access public
546
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
547
- */
548
- public function getExtensionName($lower = false){
549
- $name = $this->getNamespace().'_'.$this->getModuleName();
550
- if ($lower) {
551
- $name = strtolower($name);
552
- }
553
- return $name;
554
- }
555
-
556
- /**
557
- * get the restricted entity name
558
- * @access public
559
- * @return array
560
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
561
- */
562
- public function getRestrictedEntityNames(){
563
- return $this->getDataSetDefault('restricted_entity_names', array_keys((array)$this->getHelper()->getConfig()->getNode('restricted/entity')));
564
- }
565
- /**
566
- * get the restricted attribute codes
567
- * @access public
568
- * @return array
569
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
570
- */
571
- public function getRestrictedAttributeCodes(){
572
- return $this->getDataSetDefault('restricted_attribute_codes', (array)$this->getHelper()->getConfig()->getNode('restricted/attribute'));
573
- }
574
- /**
575
- * get the restricted attribute codes because of the method names
576
- * @access public
577
- * @return array
578
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
579
- */
580
- public function getMethodAttributeCodes(){
581
- if (!$this->hasData('method_attribute_codes')){
582
- $attributes = array();
583
- $methods = get_class_methods('Mage_Catalog_Model_Abstract');
584
- $start = array('get', 'set', 'has', 'uns');
585
- foreach ($methods as $method){
586
- if (in_array(substr($method, 0, 3), $start)){
587
- $attribute = strtolower(preg_replace('/(.)([A-Z])/', "$1_$2", substr($method,3)));
588
- $attributes[$attribute] = 1;
589
- }
590
- }
591
- $this->setData('method_attribute_codes', array_keys($attributes));
592
- }
593
- return $this->getData('method_attribute_codes');
594
- }
595
-
596
- /**
597
- * build the module
598
- * @access public
599
- * @return array
600
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
601
- */
602
- public function buildModule(){
603
- $config = $this->getConfig();
604
- $files = $config->getNode('files');
605
- $messages = array();
606
- foreach ((array)$files as $file){
607
- if ($file->scope == 'disabled'){
608
- continue;
609
- }
610
- $this->_createFile($file);
611
- }
612
- if ($this->getInstall()){
613
- $existingFiles = $this->_checkExistingFiles();
614
- if (count($existingFiles) > 0){
615
- $this->setInstall(false);
616
- $messages[] = Mage::helper('modulecreator')->__('The following files already exist. They were NOT overwritten. The extension was not installed. You can download it from the list of extensions and install it manually: %s', implode('<br />', $existingFiles));
617
- }
618
- }
619
- $this->_writeFiles();
620
- if (!$this->getInstall()){
621
- $contents = array();
622
- foreach ($this->_files as $filename=>$file){
623
- $contents[] = $this->getRelativeBasePath().$filename;
624
- }
625
- /** @var Ultimate_ModuleCreator_Model_Writer $_writer */
626
- $_writer = Mage::getModel('modulecreator/writer', $contents);
627
- $_writer->setNamePackage(Mage::getBaseDir('var').DS.'modulecreator'.DS.$this->getExtensionName());
628
- $_writer->composePackage()->archivePackage();
629
- $this->_io->rmdir($this->getBasePath(), true);
630
- }
631
- return $messages;
632
- }
633
-
634
- /**
635
- * write files to disk
636
- * @access protected
637
- * @return Ultimate_ModuleCreator_Model_Module
638
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
639
- */
640
- protected function _writeFiles(){
641
- $basePath = $this->getBasePath();
642
- foreach ($this->_files as $name=>$file){
643
- $destinationFile = $basePath.$name;
644
- $this->_writeFile($destinationFile, $file);
645
- }
646
- $this->_writeLog();
647
- $this->_writeUninstall();
648
- return $this;
649
- }
650
-
651
- /**
652
- * write log with generated files
653
- * can be used for uninstall
654
- * @access protected
655
- * @return Ultimate_ModuleCreator_Model_Module
656
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
657
- */
658
- protected function _writeLog(){
659
- $filesToWrite = array_keys($this->_files);
660
- asort($filesToWrite);
661
- $filesToWrite = array_values($filesToWrite);
662
- $text = implode($this->getEol(), $filesToWrite);
663
- $this->_writeFile($this->getLogPath(), $text);
664
- return $this;
665
- }
666
- /**
667
- * write sql uninstall script
668
- * @access protected
669
- * @return Ultimate_ModuleCreator_Model_Module
670
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
671
- */
672
- protected function _writeUninstall(){
673
- $lines = array();
674
- $module = $this->getPlaceholder('{{module}}');
675
- $namespace = $this->getNamespace(true);
676
- $lines[] = '-- add table prefix if you have one';
677
- foreach ($this->getRelations(Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_SIBLING) as $relation){
678
- $entities = $relation->getEntities();
679
- $tableName = $namespace.'_'.$module.'_'.$entities[0]->getPlaceholders('{{entity}}').'_'.$entities[1]->getPlaceholders('{{entity}}');
680
- $lines[] = 'DROP TABLE '.$tableName.';';
681
- }
682
- foreach ($this->getEntities() as $entity){
683
- if ($entity->getIsEav()){
684
- $entityTypeCode = $namespace.'_'.$this->getLowerModuleName().'_'.$entity->getPlaceholders('{{entity}}');
685
- $lines[] = "DELETE FROM eav_attribute WHERE entity_type_id IN (SELECT entity_type_id FROM eav_entity_type WHERE entity_type_code = '{$entityTypeCode}');";
686
- $lines[] = "DELETE FROM eav_entity_type WHERE entity_type_code = '{$entityTypeCode}';";
687
- }
688
- if ($entity->getProductAttribute()){
689
- $lines[] = "DELETE FROM eav_attribute WHERE attribute_code = '".$entity->getProductAttributeCode()."' AND entity_type_id IN (SELECT entity_type_id FROM eav_entity_type WHERE entity_type_code = 'catalog_product');";
690
- }
691
- if ($entity->getCategoryAttribute()){
692
- $lines[] = "DELETE FROM eav_attribute WHERE attribute_code = '".$entity->getCategoryAttributeCode()."' AND entity_type_id IN (SELECT entity_type_id FROM eav_entity_type WHERE entity_type_code = 'catalog_category');";
693
- }
694
- if ($entity->getAllowCommentByStore()){
695
- $tableName = $namespace.'_'.$module.'_'.$entity->getPlaceholders('{{entity}}').'_comment_store';
696
- $lines[] = 'DROP TABLE '.$tableName.';';
697
- }
698
- if ($entity->getAllowComment()){
699
- $tableName = $namespace.'_'.$module.'_'.$entity->getPlaceholders('{{entity}}').'_comment';
700
- $lines[] = 'DROP TABLE '.$tableName.';';
701
- }
702
- if ($entity->getLinkProduct()){
703
- $tableName = $namespace.'_'.$module.'_'.$entity->getPlaceholders('{{entity}}').'_product';
704
- $lines[] = 'DROP TABLE '.$tableName.';';
705
- }
706
- if ($entity->getLinkCategory()){
707
- $tableName = $namespace.'_'.$module.'_'.$entity->getPlaceholders('{{entity}}').'_category';
708
- $lines[] = 'DROP TABLE '.$tableName.';';
709
- }
710
- if ($entity->getStore()){
711
- $tableName = $namespace.'_'.$module.'_'.$entity->getPlaceholders('{{entity}}').'_store';
712
- $lines[] = 'DROP TABLE '.$tableName.';';
713
- }
714
- if ($entity->getIsEav()){
715
- foreach (array('int', 'decimal','datetime', 'varchar', 'text') as $type){
716
- $tableName = $namespace.'_'.$module.'_'.$entity->getPlaceholders('{{entity}}').'_'.$type;
717
- $lines[] = 'DROP TABLE '.$tableName.';';
718
- }
719
- }
720
- $tableName = $namespace.'_'.$module.'_'.$entity->getPlaceholders('{{entity}}');
721
- $lines[] = 'DROP TABLE '.$tableName.';';
722
- }
723
- if ($this->getHasEav()){
724
- $tableName = $namespace.'_'.$module.'_eav_attribute';
725
- $lines[] = 'DROP TABLE '.$tableName.';';
726
- }
727
- $lines[] = "DELETE FROM core_resource WHERE code = '".$namespace.'_'.$module."_setup';";
728
- $lines[] = "DELETE FROM core_config_data WHERE path like '".$namespace.'_'.$module."/%';";
729
- $text = implode($this->getEol(), $lines);
730
- $this->_writeFile($this->getUninstallPath(),$text);
731
- return $this;
732
- }
733
- /**
734
- * check if some files already exist so it won't be overwritten
735
- * @access protected
736
- * @return array()
737
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
738
- */
739
- protected function _checkExistingFiles(){
740
- $existingFiles = array();
741
- $io = $this->getIo();
742
- $basePath = $this->getBasePath();
743
- foreach ($this->_files as $name=>$content){
744
- if ($io->fileExists($basePath.$name)){
745
- $existingFiles[] = $basePath.$name;
746
- }
747
- }
748
- return $existingFiles;
749
- }
750
-
751
- /**
752
- * get path for log file
753
- * @access public
754
- * @return string
755
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
756
- */
757
- public function getLogPath(){
758
- return $this->getHelper()->getLocalPackagesPath().$this->getExtensionName().'/files.log';
759
- }
760
- /**
761
- * get path for uninstall sql file
762
- * @access public
763
- * @return string
764
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
765
- */
766
- public function getUninstallPath(){
767
- return $this->getHelper()->getLocalPackagesPath().$this->getExtensionName().'/uninstall.sql';
768
- }
769
-
770
- /**
771
- * get module base path
772
- * @access public
773
- * @return string
774
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
775
- */
776
- public function getBasePath(){
777
- if (!$this->getInstall()){
778
- return Mage::getBaseDir('var').DS.'modulecreator'.DS.$this->getExtensionName().DS;
779
- }
780
- return Mage::getBaseDir().DS;
781
- }
782
- /**
783
- * get relative path ro the module
784
- * @access public
785
- * @return string
786
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
787
- */
788
- public function getRelativeBasePath(){
789
- $basePath = $this->getBasePath();
790
- $remove = Mage::getBaseDir().DS;
791
- $relativePath = substr($basePath, strlen($remove));
792
- return $relativePath;
793
- }
794
- /**
795
- * get the module config
796
- * @access public
797
- * @return Varien_Simplexml_Config
798
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
799
- */
800
- public function getConfig(){
801
- if (is_null($this->_config)){
802
- $this->_config = Mage::getConfig()->loadModulesConfiguration('umc_source.xml')->applyExtends();
803
- }
804
- return $this->_config;
805
- }
806
- /**
807
- * get contents of a file
808
- * @access public
809
- * @param string $file
810
- * @return string
811
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
812
- */
813
- public function getFileContents($file){
814
- return file_get_contents($file);
815
- }
816
-
817
- /**
818
- * create a file
819
- * @access protected
820
- * @param Varien_Simplexml_Element
821
- * @return Ultimate_ModuleCreator_Model_Module
822
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
823
- */
824
- protected function _createFile($config){
825
- switch ($config->scope){
826
- case 'entity' :
827
- $this->_buildEntityFile($config);
828
- break;
829
- case 'siblings':
830
- $this->_buildSiblingFile($config);
831
- break;
832
- case 'children' :
833
- $this->_buildChildrenFile($config);
834
- break;
835
- case 'attribute' :
836
- $this->_buildAttributeFile($config);
837
- break;
838
- case 'global':
839
- default:
840
- $this->_buildGlobalFile($config);
841
- break;
842
- }
843
- return $this;
844
- }
845
-
846
- /**
847
- * validate xml condition
848
- * @access protected
849
- * @param Ultimate_ModuleCreator_Model_Abstract $entity
850
- * @param Mage_Core_Model_Config_Element $conditions
851
- * @param mixed $params
852
- * @return bool
853
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
854
- */
855
- protected function _validateDepend(Ultimate_ModuleCreator_Model_Abstract $entity, Mage_Core_Model_Config_Element $conditions, $params = null){
856
- if (!$conditions){
857
- return true;
858
- }
859
- if (!is_array($conditions)){
860
- $conditions = $conditions->asArray();
861
- }
862
- foreach ($conditions as $condition=>$value){
863
- if (!$entity->getDataUsingMethod($condition, $params)){
864
- return false;
865
- }
866
- }
867
- return true;
868
- }
869
-
870
- /** create a file with global scope
871
- * @access protected
872
- * @param Varien_Simplexml_Element
873
- * @return Ultimate_ModuleCreator_Model_Module
874
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
875
- */
876
- public function _buildGlobalFile($config) {
877
- $filetype = $config->filetype;
878
- $sourceFolder = $this->getSourceFolder().$this->_filterString((string)$config->source, $filetype);
879
- $destination = $this->_filterString((string)$config->destination, $filetype);
880
- $content = '';
881
- $depend = $config->depend;
882
- if (!$this->_validateDepend($this, $depend)){
883
- return '';
884
- }
885
- if ($config->method){
886
- $method = (string)$config->method;
887
- $content = $this->$method();
888
- }
889
- else{
890
- $code = $this->_sortCodeFiles((array)$config->code);
891
- foreach ($code as $file){
892
- $sourceContent = $this->getFileContents($sourceFolder.(string)$file->name);
893
- $scope = (string)$file->scope;
894
- $depend = $file->depend;
895
- if ($scope == 'entity'){
896
- foreach ($this->getEntities() as $entity){
897
- if ($this->_validateDepend($entity, $depend)){
898
- $replace = $entity->getPlaceholders();
899
- $content .= $this->_filterString($sourceContent, $filetype, $replace, true);
900
- }
901
- }
902
- }
903
- elseif($scope == 'attribute'){
904
- $depend = $file->depend;
905
- /** @var Mage_Core_Model_Config_Element $dependType */
906
- $dependType = $file->depend_type;
907
- foreach ($this->getEntities() as $entity){
908
- foreach ($entity->getAttributes() as $attribute){
909
- $valid = $this->_validateDepend($attribute, $depend);
910
- $typeValid = true;
911
- if ($dependType){
912
- $typeValid = false;
913
- foreach ($dependType->asArray() as $condition=>$value){
914
- if ($attribute->getType() == $condition){
915
- $typeValid = true;
916
- break;
917
- }
918
- }
919
- }
920
- if ($valid && $typeValid){
921
- $replace = $entity->getPlaceholders();
922
- $attributeReplace = $attribute->getPlaceholders();
923
- $replace = array_merge($replace, $attributeReplace);
924
- $content .= $this->_filterString($sourceContent, $filetype, $replace, true);
925
- }
926
- }
927
- }
928
- }
929
- elseif($scope == 'siblings'){
930
- foreach ($this->getRelations(Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_SIBLING) as $relation){
931
- $entities = $relation->getEntities();
932
- $replaceEntity = $entities[0]->getPlaceholders();
933
- $replaceSibling = $entities[1]->getPlaceholdersAsSibling();
934
- $replace = array_merge($replaceEntity, $replaceSibling);
935
- $content .= $this->_filterString($sourceContent, $filetype, $replace, true);
936
- }
937
- }
938
- elseif($scope == 'siblings_both_tree'){
939
- foreach ($this->getRelations(Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_SIBLING) as $relation){
940
- $entities = $relation->getEntities();
941
- if ($entities[0]->getIsTree() || $entities[1]->getIsTree()){
942
- if ($entities[0]->getIsTree()){
943
- $tree = $entities[0];
944
- $sibling = $entities[1];
945
- }
946
- else{
947
- $tree = $entities[1];
948
- $sibling = $entities[0];
949
- }
950
- $replaceEntity = $tree->getPlaceholders();
951
- $replaceSibling = $sibling->getPlaceholdersAsSibling();
952
- $replace = array_merge($replaceEntity, $replaceSibling);
953
- $content .= $this->_filterString($sourceContent, $filetype, $replace, true);
954
- }
955
- }
956
- }
957
- elseif($scope == 'siblings_both_not_tree'){
958
- foreach ($this->getRelations(Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_SIBLING) as $relation){
959
- $entities = $relation->getEntities();
960
- if ($entities[0]->getIsTree() || $entities[1]->getIsTree()){
961
- continue;
962
- }
963
- $replaceEntity = $entities[0]->getPlaceholders();
964
- $replaceSibling = $entities[1]->getPlaceholdersAsSibling();
965
- $replace = array_merge($replaceEntity, $replaceSibling);
966
- $content .= $this->_filterString($sourceContent, $filetype, $replace, true);
967
-
968
- $replaceEntity = $entities[1]->getPlaceholders();
969
- $replaceSibling = $entities[0]->getPlaceholdersAsSibling();
970
- $replace = array_merge($replaceEntity, $replaceSibling);
971
- $content .= $this->_filterString($sourceContent, $filetype, $replace, true);
972
- }
973
- }
974
- elseif ($scope == 'children'){
975
- foreach ($this->getRelations(Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_CHILD) as $relation){
976
- $entities = $relation->getEntities();
977
- $replaceEntity = $entities[0]->getPlaceholders();
978
- $replaceSibling = $entities[1]->getPlaceholdersAsSibling();
979
- $replace = array_merge($replaceEntity, $replaceSibling);
980
- $content .= $this->_filterString($sourceContent, $filetype, $replace, true);
981
- }
982
- foreach ($this->getRelations(Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_PARENT) as $relation){
983
- $entities = $relation->getEntities();
984
- $replaceEntity = $entities[1]->getPlaceholders();
985
- $replaceSibling = $entities[0]->getPlaceholdersAsSibling();
986
- $replace = array_merge($replaceEntity, $replaceSibling);
987
- $content .= $this->_filterString($sourceContent, $filetype, $replace, true);
988
- }
989
- }
990
- else{
991
- if ($this->_validateDepend($this, $depend)){
992
- $content .= $this->_filterString($sourceContent, $filetype);
993
- }
994
- }
995
- }
996
- }
997
-
998
- if ($config->after_build){
999
- $function = (string)$config->after_build;
1000
- $content = $this->$function($content);
1001
- }
1002
-
1003
- $content = $this->_filterString($content, $config->type);
1004
- $this->_addFile($destination, $content);
1005
- return $this;
1006
- }
1007
-
1008
- public function _buildEntityFile($config) {
1009
- foreach ($this->getEntities() as $entity){
1010
- $filetype = $config->filetype;
1011
- $sourceFolder = $this->getSourceFolder().$this->_filterString((string)$config->source, $filetype);
1012
- $destinationFile = $this->_filterString((string)$config->destination, $filetype, $entity->getPlaceholders(), true);
1013
- $content = '';
1014
- $depend = $config->depend;
1015
- if (!$this->_validateDepend($entity, $depend)){
1016
- continue;
1017
- }
1018
- $code = $this->_sortCodeFiles((array)$config->code);
1019
- foreach ($code as $file){
1020
- $sourceContent = $this->getFileContents($sourceFolder.(string)$file->name);
1021
- $scope = (string)$file->scope;
1022
- $depend = $file->depend;
1023
- /** @var Mage_Core_Model_Config_Element $dependType */
1024
- $dependType = $file->depend_type;
1025
- if ($scope == 'attribute'){
1026
- foreach ($entity->getAttributes() as $attribute){
1027
- $valid = $this->_validateDepend($attribute, $depend);
1028
- $typeValid = true;
1029
- if ($dependType){
1030
- $typeValid = false;
1031
- foreach ($dependType->asArray() as $condition=>$value){
1032
- if ($attribute->getType() == $condition){
1033
- $typeValid = true;
1034
- break;
1035
- }
1036
- }
1037
- }
1038
- if ($valid && $typeValid){
1039
- $replace = $entity->getPlaceholders();
1040
- $attributeReplace = $attribute->getPlaceholders();
1041
- $replace = array_merge($replace, $attributeReplace);
1042
- $content .= $this->_filterString($sourceContent, $filetype, $replace, true);
1043
- }
1044
- }
1045
- }
1046
- elseif($scope == 'siblings'){
1047
- foreach ($entity->getRelatedEntities(Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_SIBLING) as $related){
1048
- if ($this->_validateDepend($entity, $depend)){
1049
- $placeholders = $entity->getPlaceholders();
1050
- $replaceSibling = $related->getPlaceholdersAsSibling();
1051
- $replace = array_merge($placeholders, $replaceSibling);
1052
- $content .= $this->_filterString($sourceContent, $filetype, $replace, true);
1053
- }
1054
- }
1055
- }
1056
- elseif($scope == 'siblings_not_tree'){
1057
- foreach ($entity->getRelatedEntities(Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_SIBLING) as $related){
1058
- if ($related->getNotIsTree()){
1059
- $placeholders = $entity->getPlaceholders();
1060
- $replaceSibling = $related->getPlaceholdersAsSibling();
1061
- $replace = array_merge($placeholders, $replaceSibling);
1062
- $content .= $this->_filterString($sourceContent, $filetype, $replace, true);
1063
- }
1064
- }
1065
- }
1066
- elseif($scope == 'siblings_tree'){
1067
- foreach ($entity->getRelatedEntities(Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_SIBLING) as $related){
1068
- if ($related->getIsTree()){
1069
- $placeholders = $entity->getPlaceholders();
1070
- $replaceSibling = $related->getPlaceholdersAsSibling();
1071
- $replace = array_merge($placeholders, $replaceSibling);
1072
- $content .= $this->_filterString($sourceContent, $filetype, $replace, true);
1073
- }
1074
- }
1075
- }
1076
- elseif($scope == 'parents'){
1077
- foreach ($entity->getRelatedEntities(Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_CHILD) as $related){
1078
- $placeholders = $entity->getPlaceholders();
1079
- $replaceSibling = $related->getPlaceholdersAsSibling();
1080
- $replace = array_merge($placeholders, $replaceSibling);
1081
- $content .= $this->_filterString($sourceContent, $filetype, $replace, true);
1082
- }
1083
- }
1084
- elseif($scope == 'children'){
1085
- foreach ($entity->getRelatedEntities(Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_PARENT) as $related){
1086
- $placeholders = $entity->getPlaceholders();
1087
- $replaceSibling = $related->getPlaceholdersAsSibling();
1088
- $replace = array_merge($placeholders, $replaceSibling);
1089
- $content .= $this->_filterString($sourceContent, $filetype, $replace, true);
1090
- }
1091
- }
1092
- elseif ($depend){
1093
- if ($this->_validateDepend($entity, $depend)){
1094
- $content .= $this->_filterString($sourceContent, $filetype, $entity->getPlaceholders(), true);
1095
- }
1096
- }
1097
- else{
1098
- $content .= $this->_filterString($sourceContent, $filetype, $entity->getPlaceholders(), true);
1099
- }
1100
- $this->_addFile($destinationFile, $content);
1101
- }
1102
- }
1103
- return $this;
1104
- }
1105
-
1106
- /**
1107
- * generate files for sibling relations
1108
- * @access protected
1109
- * @param $config
1110
- * @return $this
1111
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1112
- */
1113
- protected function _buildSiblingFile($config) {
1114
- foreach ($this->getRelations(Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_SIBLING) as $relation){
1115
- $entities = $relation->getEntities();
1116
- foreach ($entities as $index=>$entity){
1117
- $depend = $config->depend;
1118
- if (!$this->_validateDepend($relation, $depend, $index)){
1119
- continue;
1120
- }
1121
-
1122
- $placeholders = array_merge($entities[$index]->getPlaceholders(), $entities[1 - $index]->getPlaceholdersAsSibling());
1123
- $filetype = $config->filetype;
1124
- $sourceFolder = $this->getSourceFolder().$this->_filterString((string)$config->source, $filetype);
1125
- $destinationFile = $this->_filterString((string)$config->destination, $filetype, $placeholders, true);
1126
- $content = '';
1127
- $code = $this->_sortCodeFiles((array)$config->code);
1128
- foreach ($code as $file){
1129
- $depend = $file->depend;
1130
- if (!$this->_validateDepend($relation, $depend, $index)){
1131
- continue;
1132
- }
1133
- $sourceContent = $this->getFileContents($sourceFolder.(string)$file->name);
1134
- $content .= $this->_filterString($sourceContent, $filetype, $placeholders, true);
1135
- }
1136
- $this->_addFile($destinationFile, $content);
1137
- }
1138
- }
1139
- return $this;
1140
- }
1141
-
1142
- /**
1143
- * create files for children relations
1144
- * @access protected
1145
- * @param Varien_Simplexml_Element
1146
- * @return Ultimate_ModuleCreator_Model_Module
1147
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1148
- */
1149
- protected function _buildChildrenFile($config){
1150
- foreach ($this->getRelations() as $relation){
1151
- $type = $relation->getType();
1152
- $entities = $relation->getEntities();
1153
- $parent = false;
1154
- $child = false;
1155
- if ($type == Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_PARENT){
1156
- $parent = $entities[0];
1157
- $child = $entities[1];
1158
- }
1159
- elseif ($type == Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_CHILD){
1160
- $parent = $entities[1];
1161
- $child = $entities[0];
1162
- }
1163
- if ($parent && $child){
1164
- $depend = $config->depend;
1165
- if ($this->_validateDepend($relation, $depend)){
1166
- $placeholders = array_merge($parent->getPlaceholders(), $child->getPlaceholdersAsSibling());
1167
- $filetype = $config->filetype;
1168
- $sourceFolder = $this->getSourceFolder().$this->_filterString((string)$config->source, $filetype);
1169
- $destinationFile = $this->_filterString((string)$config->destination, $filetype, $placeholders, true);
1170
- $content = '';
1171
- $code = $this->_sortCodeFiles((array)$config->code);
1172
- foreach ($code as $file){
1173
- $depend = $file->depend;
1174
- if (!$this->_validateDepend($relation, $depend)){
1175
- continue;
1176
- }
1177
- $sourceContent = $this->getFileContents($sourceFolder.(string)$file->name);
1178
- $content .= $this->_filterString($sourceContent, $filetype, $placeholders, true);
1179
- }
1180
- $this->_addFile($destinationFile, $content);
1181
- }
1182
- }
1183
- }
1184
- return $this;
1185
- }
1186
-
1187
- /**
1188
- * build source file for an attribute
1189
- * @access public
1190
- * @param $config
1191
- * @return Ultimate_ModuleCreator_Model_Module
1192
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1193
- */
1194
- protected function _buildAttributeFile($config){
1195
- foreach ($this->getEntities() as $entity){
1196
- foreach ($entity->getAttributes() as $attribute){
1197
- $filetype = $config->filetype;
1198
- $sourceFolder = $this->getSourceFolder().$this->_filterString((string)$config->source, $filetype);
1199
- $placeholders = array_merge($entity->getPlaceholders(), $attribute->getPlaceholders());
1200
- $destinationFile = $this->_filterString((string)$config->destination, $filetype, $placeholders, true);
1201
- $content = '';
1202
- $depend = $config->depend;
1203
- if (!$this->_validateDepend($attribute, $depend)){
1204
- continue;
1205
- }
1206
- $code = $this->_sortCodeFiles((array)$config->code);
1207
- foreach ($code as $file){
1208
- $depend = $file->depend;
1209
- if (!$this->_validateDepend($attribute, $depend)){
1210
- continue;
1211
- }
1212
- $sourceContent = $this->getFileContents($sourceFolder.(string)$file->name);
1213
- $content .= $this->_filterString($sourceContent, $filetype, $placeholders, true);
1214
- }
1215
- $this->_addFile($destinationFile, $content);
1216
- }
1217
- }
1218
- return $this;
1219
- }
1220
-
1221
- /**
1222
- * get sample files source folder
1223
- * @access public
1224
- * @return string
1225
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1226
- */
1227
- public function getSourceFolder(){
1228
- if (!isset($this->_sourceFolder)){
1229
- $this->_sourceFolder = Mage::getConfig()->getModuleDir('etc', 'Ultimate_ModuleCreator').DS.'source'.DS;
1230
- }
1231
- return $this->_sourceFolder;
1232
- }
1233
- /**
1234
- * filter placeholders
1235
- * @access protected
1236
- * @param string $string
1237
- * @param string $fileType
1238
- * @param mixed (null|array()) $replaceArray
1239
- * @param bool $mergeReplace
1240
- * @param bool $forLicence
1241
- * @return string
1242
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1243
- */
1244
- protected function _filterString($string, $fileType, $replaceArray = null, $mergeReplace = false, $forLicence = false){
1245
- $replace = $this->getPlaceholder();
1246
- if (!$forLicence) {
1247
- $replace['{{License}}'] = $this->getLicenseText($fileType);
1248
- }
1249
- if (!is_null($replaceArray)){
1250
- if ($mergeReplace){
1251
- $replace = array_merge($replace, $replaceArray);
1252
- }
1253
- else{
1254
- $replace = $replaceArray;
1255
- }
1256
- }
1257
- return str_replace(array_keys($replace), array_values($replace), $string);
1258
- }
1259
- /**
1260
- * add file to create list
1261
- * @access protected
1262
- * @param $destinationFile
1263
- * @param $content
1264
- * @return $this
1265
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1266
- */
1267
- protected function _addFile($destinationFile, $content){
1268
- if (trim($content)){
1269
- $this->_files[$destinationFile] = $content;
1270
- }
1271
- return $this;
1272
- }
1273
- /**
1274
- * get text for licence
1275
- * @access public
1276
- * @param string $fileType
1277
- * @return string
1278
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1279
- */
1280
- public function getLicenseText($fileType){
1281
- if (!$this->getData('processed_license_'.$fileType)){
1282
- $eol = $this->getEol();
1283
- $license = trim($this->getData('license'));
1284
- if (!$license){
1285
- return '';
1286
- }
1287
- while(strpos($license, '*/') !== false){
1288
- $license = str_replace('*/', '', $license);
1289
- }
1290
- while(strpos($license, '/*') !== false){
1291
- $license = str_replace('/*', '', $license);
1292
- }
1293
- while(strpos($license, '<!--') !== false){
1294
- $license = str_replace('<!--', '', $license);
1295
- }
1296
- while(strpos($license, '-->') !== false){
1297
- $license = str_replace('-->', '', $license);
1298
- }
1299
- $lines = explode("\n", $license);
1300
- $top = '';
1301
- $footer = '';
1302
- if ($fileType == 'xml'){
1303
- $top = '<!--'.$eol;
1304
- $footer = $eol.'-->';
1305
- }
1306
- $processed = $top.'/**'.$eol;
1307
- foreach ($lines as $line){
1308
- $processed .= ' * '.$line.$eol;
1309
- }
1310
- $processed .= ' */'.$footer;
1311
- $this->setData('processed_license_'.$fileType, $this->_filterString($processed, $fileType, array(), true, true));
1312
- }
1313
- return $this->getData('processed_license_'.$fileType);
1314
- }
1315
- /**
1316
- * get all placeholders
1317
- * @access public
1318
- * @param null $param
1319
- * @return array|null|string
1320
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1321
- */
1322
- public function getPlaceholder($param = null){
1323
- if (is_null($this->_placeholders)){
1324
- $this->_placeholders = array(
1325
- '{{DS}}' => DS,
1326
- '{{namespace}}' => $this->getNamespace(true),
1327
- '{{sort_order}}' => (int)$this->getSortOrder(),
1328
- '{{module}}' => strtolower($this->getModuleName()),
1329
- '{{Namespace}}' => $this->getNamespace(),
1330
- '{{Module}}' => $this->getModuleName(),
1331
- '{{NAMESPACE}}' => strtoupper($this->getNamespace()),
1332
- '{{MODULE}}' => strtoupper($this->getModuleName()),
1333
- '{{qwertyuiop}}' => $this->getQwertyuiop(),
1334
- '{{qwertyuiopp}}' => $this->getQwertyuiopp(),
1335
- '{{Y}}' => date('Y'),
1336
- '{{entity_default_config}}' => $this->getEntityDefaultConfig(),
1337
- '{{module_menu}}' => $this->getMenuText(),
1338
- '{{codepool}}' => $this->getCodepool(),
1339
- '{{version}}' => $this->getVersion(),
1340
- '{{menuItemsXml}}' => $this->getMenuItemsXml(),
1341
- '{{menuAcl}}' => $this->getMenuAcl(),
1342
- '{{ModuleFolder}}' => ucfirst(strtolower($this->getModuleName())),
1343
- '{{ResourceSetup}}' => $this->getResourceSetupModel(),
1344
- '{{depends}}' => $this->getDepends(),
1345
- '{{productViewLayout}}' => $this->getProductViewLayout(),
1346
- '{{categoryViewLayout}}' => $this->getCategoryViewLayout(),
1347
- '{{defaultLayoutHandle}}' => $this->getFrontendDefaultLayoutHandle(),
1348
- '{{categoryMenuEvent}}' => $this->getCategoryMenuEvent(),
1349
- '{{customerCommentLinks}}' => $this->getCustomerCommentLinks(),
1350
- '{{frontKey}}' => $this->getFrontKey(),
1351
- '{{SystemTabName}}' => $this->getSystemTabName(),
1352
- '{{systemTabPosition}}' => $this->getSystemTabPosition(),
1353
- '{{RestResourceGroupsChildren}}' => $this->getRestResourceGroupsChildren(),
1354
- '{{RestResources}}' => $this->getRestResources(),
1355
- '{{eavOptionsDefaults}}' => $this->getEavOptionsDefaults()
1356
- );
1357
- }
1358
- if (is_null($param)){
1359
- return $this->_placeholders;
1360
- }
1361
- if (isset($this->_placeholders[$param])){
1362
- return $this->_placeholders[$param];
1363
- }
1364
- return '';
1365
- }
1366
- /**
1367
- * get config.xml default section
1368
- * @access public
1369
- * @return string
1370
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1371
- */
1372
- public function getEntityDefaultConfig(){
1373
- $eol = $this->getEol();
1374
- $text = '';
1375
- if ($this->getCreateFrontend()) {
1376
- $text = $eol.$this->getPadding().'<default>'.$eol;
1377
- $text.= $this->getPadding(2).'<'.strtolower($this->getModuleName()).'>'.$eol;
1378
- foreach ($this->getEntities() as $entity){
1379
- $text .= $this->getPadding(3).$entity->getDefaultConfig();
1380
- }
1381
- $text.= $this->getPadding(2).'</'.strtolower($this->getModuleName()).'>'.$eol;
1382
- $text.= $this->getPadding().'</default>';
1383
- }
1384
- return $text;
1385
- }
1386
-
1387
- /**
1388
- * check if module related to catalog
1389
- * @access public
1390
- * @return bool
1391
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1392
- */
1393
- public function getHasCatalogRelation(){
1394
- return $this->getLinkProduct() || $this->getLinkCategory();
1395
- }
1396
-
1397
- /**
1398
- * get menu for entities
1399
- * @access public
1400
- * @param $padding
1401
- * @return string
1402
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1403
- */
1404
- public function getEntityMenu($padding){
1405
- $text = '';
1406
- foreach ($this->getEntities() as $entity){
1407
- $text .= $entity->getMenu($padding);
1408
- }
1409
- return $text;
1410
- }
1411
- /**
1412
- * get menu ACL for entities
1413
- * @access public
1414
- * @param $padding
1415
- * @return string
1416
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1417
- */
1418
- public function getEntityMenuAcl($padding){
1419
- $text = '';
1420
- foreach ($this->getEntities() as $entity){
1421
- $text .= $entity->getMenuAcl($padding);
1422
- }
1423
- return $text;
1424
- }
1425
-
1426
- /**
1427
- * sort source code files
1428
- * @access protected
1429
- * @param $files
1430
- * @param string $sortField
1431
- * @return array
1432
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1433
- */
1434
- protected function _sortCodeFiles($files, $sortField = 'sort_order'){
1435
- $sorted = array();
1436
- foreach ($files as $values){
1437
- $sorted[(int)$values->$sortField][] = $values;
1438
- }
1439
- ksort($sorted);
1440
- $return = array();
1441
- foreach ($sorted as $values){
1442
- foreach ($values as $file){
1443
- $return[] = $file;
1444
- }
1445
- }
1446
- return $return;
1447
- }
1448
-
1449
- /**
1450
- * get module name in lower case
1451
- * @access public
1452
- * @return string
1453
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1454
- */
1455
- public function getLowerModuleName(){
1456
- return strtolower($this->getModuleName());
1457
- }
1458
-
1459
- /**
1460
- * get menu items xml
1461
- * @access public
1462
- * @return string
1463
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1464
- */
1465
- public function getMenuItemsXml(){
1466
- $xml = '';
1467
- $parts = array();
1468
- $padding = 2;
1469
- $namespace = $this->getNamespace(true);
1470
- $eol = $this->getEol();
1471
- if ($this->getMenuParent()){
1472
- $parts = explode('/', $this->getMenuParent());
1473
- }
1474
- foreach ($parts as $part){
1475
- $xml .= $this->getPadding($padding++).'<'.$part.'>'.$eol;
1476
- $xml .= $this->getPadding($padding++).'<children>'.$eol;
1477
- }
1478
- $xml .= $this->getPadding($padding++).'<'.$namespace.'_'.$this->getLowerModuleName().' translate="title" module="'.$namespace.'_'.$this->getLowerModuleName().'">'.$eol;
1479
- $xml .= $this->getPadding($padding).'<title>'.$this->getMenuText().'</title>'.$eol;
1480
- $xml .= $this->getPadding($padding).'<sort_order>'.$this->getSortOrder().'</sort_order>'.$eol;
1481
- $xml .= $this->getPadding($padding++).'<children>'.$eol;
1482
- $xml .= $this->getEntityMenu($padding);
1483
- $xml .= $this->getPadding(--$padding).'</children>'.$eol;
1484
- $xml .= $this->getPadding(--$padding).'</'.$namespace.'_'.$this->getLowerModuleName().'>';
1485
-
1486
- $parts = array_reverse($parts);
1487
- foreach ($parts as $part){
1488
- $xml .= $this->getPadding(--$padding).'</children>'.$eol;
1489
- $xml .= $this->getPadding(--$padding).'</'.$part.'>'.$eol;
1490
- }
1491
- return $xml;
1492
- }
1493
-
1494
- /**
1495
- * get menu ACL
1496
- * @access public
1497
- * @return string
1498
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1499
- */
1500
- public function getMenuAcl(){
1501
- $xml = '';
1502
- $parts = array();
1503
- $padding = 5;
1504
- $eol = $this->getEol();
1505
- $namespace = $this->getNamespace(true);
1506
- if ($this->getMenuParent()){
1507
- $parts = explode('/', $this->getMenuParent());
1508
- }
1509
- foreach ($parts as $part){
1510
- $xml .= $this->getPadding($padding++).'<'.$part.'>'.$eol;
1511
- $xml .= $this->getPadding($padding++).'<children>'.$eol;
1512
- }
1513
- $xml .= $this->getPadding($padding++).'<'.$namespace.'_'.$this->getLowerModuleName().' translate="title" module="'.$namespace.'_'.$this->getLowerModuleName().'">'.$eol;
1514
- $xml .= $this->getPadding($padding).'<title>'.$this->getMenuText().'</title>'.$eol;
1515
- $xml .= $this->getPadding($padding++).'<children>'.$eol;
1516
- $xml .= $this->getEntityMenuAcl($padding);
1517
- $xml .= $this->getPadding(--$padding).'</children>'.$eol;
1518
- $xml .= $this->getPadding(--$padding).'</'.$namespace.'_'.$this->getLowerModuleName().'>';
1519
-
1520
- $parts = array_reverse($parts);
1521
- foreach ($parts as $part){
1522
- $xml .= $this->getPadding(--$padding).'</children>'.$eol;
1523
- $xml .= $this->getPadding(--$padding).'</'.$part.'>'.$eol;
1524
- }
1525
- return $xml;
1526
- }
1527
-
1528
- /**
1529
- * get resource setup base class
1530
- * @access public
1531
- * @return string
1532
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1533
- */
1534
- public function getResourceSetupModel(){
1535
- if ($this->getHasCatalogRelation() || $this->getHasEav() || $this->getHasCatalogAttribute()){
1536
- return 'Mage_Catalog_Model_Resource_Setup';
1537
- }
1538
- return 'Mage_Core_Model_Resource_Setup';
1539
- }
1540
- /**
1541
- * sort the translation file
1542
- * @access protected
1543
- * @param string $content
1544
- * @return string
1545
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1546
- */
1547
- protected function _sortTranslationFile($content){
1548
- $lines = explode($this->getEol(), $content);
1549
- $distinct = array();
1550
- foreach ($lines as $line){
1551
- if (trim($line)){
1552
- $distinct[$line] = 1;
1553
- }
1554
- }
1555
- //remove blank line
1556
- if (isset($distinct['"",""'])){
1557
- unset($distinct['"",""']);
1558
- }
1559
- ksort($distinct);
1560
- $content = implode($this->getEol(), array_keys($distinct));
1561
- return $content;
1562
- }
1563
-
1564
- /**
1565
- * this does nothing
1566
- * don't look through the code - go away
1567
- * I said it does nothing
1568
- * @access public
1569
- * @return string
1570
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1571
- */
1572
- public function getQwertyuiop(){
1573
- return $this->getHelper()->getQwertyuiop();
1574
- }
1575
- /**
1576
- * this also does nothing
1577
- * don't look here either
1578
- * @access public
1579
- * @return string
1580
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1581
- */
1582
- public function getQwertyuiopp(){
1583
- return $this->getHelper()->getQwertyuiopp();
1584
- }
1585
- /**
1586
- * check module dependency
1587
- * @access public
1588
- * @return array
1589
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1590
- */
1591
- public function getDepends() {
1592
- if (!$this->hasData('_depends')){
1593
- $dependency = array('<Mage_Core />'=>1);
1594
- if ($this->getLinkCore() || $this->getHasEav()){
1595
- $dependency['<Mage_Catalog />'] = 1;
1596
- }
1597
- $eol = $this->getEol();
1598
- $padding = $this->getPadding(4);
1599
- $depends = '';
1600
- foreach ($dependency as $key=>$value){
1601
- $depends = $padding.$key.$eol;
1602
- }
1603
- $this->setData('_depends', $depends);
1604
- }
1605
- return $this->getData('_depends');
1606
- }
1607
-
1608
- /**
1609
- * get layout for product view page
1610
- * @access public
1611
- * @return string
1612
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1613
- */
1614
- public function getProductViewLayout() {
1615
- $content = '';
1616
- $padding = $this->getPadding(3);
1617
- $eol = $this->getEol();
1618
- $tab = $this->getPadding();
1619
- $ns = $this->getNamespace(true);
1620
- $module = $this->getLowerModuleName();
1621
- foreach ($this->getEntities() as $entity) {
1622
- $name = strtolower($entity->getNameSingular());
1623
- $names = strtolower($entity->getNamePlural());
1624
- $label = $entity->getLabelPlural();
1625
- if ($entity->getShowOnProduct()) {
1626
- $content .= $padding.'<block type="'.$ns.'_'.$module.'/catalog_product_list_'.$name.'" name="product.info.'.$names.'" as="product_'.$names.'" template="'.$ns.'_'.$module.'/catalog/product/list/'.$name.'.phtml">'.$eol;
1627
- $content .= $padding.$tab.'<action method="addToParentGroup"><group>detailed_info</group></action>'.$eol;
1628
- $content .= $padding.$tab.'<action method="setTitle" translate="value" module="'.$ns.'_'.$module.'"><value>'.$label.'</value></action>'.$eol;
1629
- $content .= $padding.'</block>'.$eol;
1630
- }
1631
- }
1632
- return $content;
1633
- }
1634
- /**
1635
- * get layout for category view page
1636
- * @access public
1637
- * @return string
1638
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1639
- */
1640
- public function getCategoryViewLayout() {
1641
- $content = '';
1642
- $padding = $this->getPadding(3);
1643
- $eol = $this->getEol();
1644
- $ns = $this->getNamespace(true);
1645
- $module = $this->getLowerModuleName();
1646
- foreach ($this->getEntities() as $entity) {
1647
- $name = $entity->getNameSingular(true);
1648
- $names = $entity->getNamePlural(true);
1649
- if ($entity->getShowOnCategory()) {
1650
- $content .= $padding.'<block type="'.$ns.'_'.$module.'/catalog_category_list_'.$name.'" name="category.info.'.$names.'" as="category_'.$names.'" template="'.$ns.'_'.$module.'/catalog/category/list/'.$name.'.phtml" after="-" />'.$eol;
1651
- }
1652
- }
1653
- return $content;
1654
- }
1655
-
1656
- /**
1657
- * get default layout handle
1658
- * @access public
1659
- * @return string
1660
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1661
- */
1662
- public function getFrontendDefaultLayoutHandle() {
1663
- $padding = $this->getPadding(1);
1664
- $tab = $this->getPadding();
1665
- $eol = $this->getEol();
1666
- /** @var Ultimate_ModuleCreator_Model_Entity[] $top */
1667
- $top = array();
1668
- /** @var Ultimate_ModuleCreator_Model_Entity[] $footer */
1669
- $footer = array();
1670
- $content = $eol.$padding;
1671
- $namespace = $this->getNamespace(true);
1672
- $tree = false;
1673
- if ($this->getCreateFrontend()) {
1674
- foreach ($this->getEntities() as $entity) {
1675
- if ($entity->getCreateList()) {
1676
- if ($entity->getListMenu() == Ultimate_ModuleCreator_Model_Source_Entity_Menu::TOP_LINKS) {
1677
- $top[] = $entity;
1678
- }
1679
- elseif ($entity->getListMenu() == Ultimate_ModuleCreator_Model_Source_Entity_Menu::FOOTER_LINKS) {
1680
- $footer[] = $entity;
1681
- }
1682
- if ($entity->getIsTree()) {
1683
- $tree = true;
1684
- }
1685
- }
1686
- }
1687
- }
1688
- if (count($top) > 0 || count($footer) > 0 || $tree) {
1689
- $content .= '<default>'.$eol;
1690
- if ($tree) {
1691
- $content .= $padding.'<reference name="head">'.$eol;
1692
- $content .= $padding.$tab.'<action method="addCss"><js>css/'.$this->getNamespace(true).'_'.$this->getLowerModuleName().'/tree.css</js></action>'.$eol;
1693
- $content .= $padding.'</reference>'.$eol;
1694
- }
1695
- if (count($top) > 0) {
1696
- $content .= $padding.$tab.'<reference name="top.links">'.$eol;
1697
- $position = 120;
1698
- foreach ($top as $entity) {
1699
- $content .= $padding.$tab.$tab.'<action method="addLink" translate="label title" module="'.$namespace.'_'.$this->getLowerModuleName().'">'.$eol;
1700
- $content .= $padding.$tab.$tab.$tab.'<label>'.$entity->getLabelPlural().'</label>'.$eol;
1701
- $content .= $padding.$tab.$tab.$tab.'<url helper="'.$namespace.'_'.$this->getLowerModuleName().'/'.strtolower($entity->getNameSingular()).'/get'.ucfirst(strtolower($entity->getNamePlural())).'Url" />'.$eol;
1702
- $content .= $padding.$tab.$tab.$tab.'<title>'.$entity->getLabelPlural().'</title>'.$eol;
1703
- $content .= $padding.$tab.$tab.$tab.'<prepare />'.$eol;
1704
- $content .= $padding.$tab.$tab.$tab.'<urlParams/>'.$eol;
1705
- $content .= $padding.$tab.$tab.$tab.'<position>'.$position.'</position>'.$eol;
1706
- $content .= $padding.$tab.$tab.'</action>'.$eol;
1707
- $position += 10;
1708
- }
1709
- $content .= $padding.$tab.'</reference>'.$eol;
1710
- }
1711
- if (count($footer) > 0) {
1712
- $content .= $padding.$tab.'<reference name="footer_links">'.$eol;
1713
- $position = 120;
1714
- foreach ($footer as $entity) {
1715
- $content .= $padding.$tab.$tab.'<action method="addLink" translate="label title" module="'.$namespace.'_'.$this->getLowerModuleName().'">'.$eol;
1716
- $content .= $padding.$tab.$tab.$tab.'<label>'.$entity->getLabelPlural().'</label>'.$eol;
1717
- $content .= $padding.$tab.$tab.$tab.'<url helper="'.$namespace.'_'.$this->getLowerModuleName().'/'.strtolower($entity->getNameSingular()).'/get'.ucfirst(strtolower($entity->getNamePlural())).'Url" />'.$eol;
1718
- $content .= $padding.$tab.$tab.$tab.'<title>'.$entity->getLabelPlural().'</title>'.$eol;
1719
- $content .= $padding.$tab.$tab.$tab.'<prepare />'.$eol;
1720
- $content .= $padding.$tab.$tab.$tab.'<urlParams/>'.$eol;
1721
- $content .= $padding.$tab.$tab.$tab.'<position>'.$position.'</position>'.$eol;
1722
- $content .= $padding.$tab.$tab.'</action>'.$eol;
1723
- $position += 10;
1724
- }
1725
- $content .= $padding.$tab.'</reference>'.$eol;
1726
- }
1727
- $content .= $padding.'</default>';
1728
- }
1729
- return $content;
1730
- }
1731
-
1732
- /**
1733
- * get xml for category menu event
1734
- * @access public
1735
- * @return string
1736
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1737
- */
1738
- public function getCategoryMenuEvent() {
1739
- if ($this->getShowInCategoryMenu()) {
1740
- $namespace = $this->getNamespace(true);
1741
-
1742
- $eol = $this->getEol();
1743
- $padding = $this->getPadding(2);
1744
- $tab = $this->getPadding();
1745
- $content = $eol;
1746
- $content .= $padding.'<events>'.$eol;
1747
- $content .= $padding.$tab.'<page_block_html_topmenu_gethtml_before>'.$eol;
1748
- $content .= $padding.$tab.$tab.'<observers>'.$eol;
1749
- $content .= $padding.$tab.$tab.$tab.'<'.$namespace.'_'.$this->getLowerModuleName().'>'.$eol;
1750
- $content .= $padding.$tab.$tab.$tab.$tab.'<class>'.$namespace.'_'.$this->getLowerModuleName().'/observer</class>'.$eol;
1751
- $content .= $padding.$tab.$tab.$tab.$tab.'<method>addItemsToTopmenuItems</method>'.$eol;
1752
- $content .= $padding.$tab.$tab.$tab.'</'.$namespace.'_'.$this->getLowerModuleName().'>'.$eol;
1753
- $content .= $padding.$tab.$tab.'</observers>'.$eol;
1754
- $content .= $padding.$tab.'</page_block_html_topmenu_gethtml_before>'.$eol;
1755
- $content .= $padding.'</events>'.$eol;
1756
- return $content;
1757
- }
1758
- return '';
1759
- }
1760
- /**
1761
- * get customer comment links
1762
- * @access public
1763
- * @return string
1764
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1765
- */
1766
- public function getCustomerCommentLinks() {
1767
- $namespace = $this->getNamespace(true);
1768
- $eol = $this->getEol();
1769
- $padding = $this->getPadding(3);
1770
- $content = $eol;
1771
- $module = $this->getLowerModuleName();
1772
- foreach ($this->getEntities() as $entity) {
1773
- if ($entity->getAllowComment()) {
1774
- $entityName = $entity->getNameSingular(true);
1775
- $label = $entity->getLabelPlural();
1776
- $content .= $padding . '<action method="addLink" translate="label" module="'.$namespace.'_'.$module.'"><name>'.$entityName.'_comments</name><path>'.$namespace.'_'.$module.'/'.$entityName.'_customer_comment</path><label>'.$label.' Comments</label></action>'.$eol;
1777
- }
1778
- }
1779
- return $content;
1780
- }
1781
-
1782
- /**
1783
- * get the module namespace
1784
- * @access public
1785
- * @param bool $lower
1786
- * @return mixed|string
1787
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1788
- */
1789
- public function getNamespace($lower = false){
1790
- $namespace = $this->getData('namespace');
1791
- if ($lower){
1792
- $namespace = strtolower($namespace);
1793
- }
1794
- return $namespace;
1795
- }
1796
-
1797
- /**
1798
- * get front key
1799
- * @access public
1800
- * @return mixed
1801
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1802
- */
1803
- public function getFrontKey() {
1804
- if (!$this->getCreateFrontend()) {
1805
- return $this->getData('front_key');
1806
- }
1807
- if (!$this->getData('front_key')) {
1808
- $frontKey = $this->getNamespace(true).'_'.$this->getLowerModuleName();
1809
- $this->setData('front_key', $frontKey);
1810
- }
1811
- return $this->getData('front_key');
1812
- }
1813
-
1814
- /**
1815
- * system configuration tab name
1816
- * @access public
1817
- * @return string
1818
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1819
- */
1820
- public function getSystemTabName(){
1821
- if (!$this->getData('system_tab')){
1822
- $this->setData('system_tab', $this->getNamespace());
1823
- }
1824
- return $this->getData('system_tab');
1825
- }
1826
- /**
1827
- * system configuration tab position
1828
- * @access public
1829
- * @return string
1830
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1831
- */
1832
- public function getSystemTabPosition(){
1833
- return (int)$this->getData('system_tab_position');
1834
- }
1835
-
1836
- /**
1837
- * get xml for api2.xml resource groups children
1838
- * @access public
1839
- * @return string
1840
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1841
- */
1842
- public function getRestResourceGroupsChildren(){
1843
- $content = '';
1844
- foreach ($this->getEntities() as $entity){
1845
- $content .= $entity->getRestResourceGroup(5);
1846
- }
1847
- return $content;
1848
- }
1849
- /**
1850
- * get xml for api2.xml resources
1851
- * @access public
1852
- * @return string
1853
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1854
- */
1855
- public function getRestResources() {
1856
- $content = '';
1857
- foreach ($this->getEntities() as $entity){
1858
- $content .= $entity->getRestResource(3);
1859
- }
1860
- return $content;
1861
- }
1862
-
1863
- /**
1864
- * get eav default values
1865
- * @access public
1866
- * @return string
1867
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1868
- */
1869
- public function getEavOptionsDefaults() {
1870
- $content = '';
1871
- foreach ($this->getEntities() as $entity) {
1872
- if ($entity->getIsEav()) {
1873
- foreach ($entity->getAttributes() as $attribute) {
1874
- $content .= $attribute->getDefaultValueSetup();
1875
- }
1876
- }
1877
- }
1878
- return $content;
1879
- }
1880
-
1881
- /**
1882
- * check if there are sibling relations
1883
- * @access public
1884
- * @return bool
1885
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1886
- */
1887
- public function getHasRelationColumnRenderer() {
1888
- if (count($this->getRelations(Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_SIBLING)) > 0) {
1889
- return true;
1890
- }
1891
- foreach ($this->getEntities() as $_entity) {
1892
- if ($_entity->getLinkCore()) {
1893
- return true;
1894
- }
1895
- }
1896
- return false;
1897
- }
1898
- /**
1899
- * check if there are parent-child relations
1900
- * @access public
1901
- * @return bool
1902
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1903
- */
1904
- public function getHasParentRelation() {
1905
- $parentRelations = $this->getRelations(Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_PARENT);
1906
- if (count($parentRelations)) {
1907
- return true;
1908
- }
1909
- $childRelations = $this->getRelations(Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_CHILD);
1910
- if (count($childRelations)) {
1911
- return true;
1912
- }
1913
- return false;
1914
- }
1915
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
+ */
18
+ /**
19
+ * @method string getFilenameId()
20
+ * @method string getMenuParent()
21
+ * @method Ultimate_ModuleCreator_Model_Module setRss()
22
+ * @method Ultimate_ModuleCreator_Model_Module setHasFile()
23
+ * @method Ultimate_ModuleCreator_Model_Module setHasImage()
24
+ * @method Ultimate_ModuleCreator_Model_Module setAddSeo()
25
+ * @method Ultimate_ModuleCreator_Model_Module setWidget()
26
+ * @method Ultimate_ModuleCreator_Model_Module setCreateFrontend()
27
+ * @method Ultimate_ModuleCreator_Model_Module setCanCreateRouter()
28
+ * @method Ultimate_ModuleCreator_Model_Module setCreateList()
29
+ * @method Ultimate_ModuleCreator_Model_Module setHasTree()
30
+ * @method Ultimate_ModuleCreator_Model_Module setEditor()
31
+ * @method Ultimate_ModuleCreator_Model_Module setHasConfigDefaults()
32
+ * @method Ultimate_ModuleCreator_Model_Module setLinkProduct()
33
+ * @method Ultimate_ModuleCreator_Model_Module setHasObserver()
34
+ * @method Ultimate_ModuleCreator_Model_Module setLinkCategory()
35
+ * @method Ultimate_ModuleCreator_Model_Module setLinkCore()
36
+ * @method Ultimate_ModuleCreator_Model_Module setUrlRewrite()
37
+ * @method Ultimate_ModuleCreator_Model_Module setHasEav()
38
+ * @method Ultimate_ModuleCreator_Model_Module setHasFlat()
39
+ * @method Ultimate_ModuleCreator_Model_Module setApi()
40
+ * @method Ultimate_ModuleCreator_Model_Module setAllowComment()
41
+ * @method Ultimate_ModuleCreator_Model_Module setAllowCommentByStore()
42
+ * @method Ultimate_ModuleCreator_Model_Module setHasCountry()
43
+ * @method Ultimate_ModuleCreator_Model_Module setHasSeo()
44
+ * @method Ultimate_ModuleCreator_Model_Module setShowOnProduct()
45
+ * @method Ultimate_ModuleCreator_Model_Module setShowOnCategory()
46
+ * @method Ultimate_ModuleCreator_Model_Module setShowInCategoryMenu()
47
+ * @method Ultimate_ModuleCreator_Model_Module setSearch()
48
+ * @method Ultimate_ModuleCreator_Model_Module setHasCatalogAttribute()
49
+ * @method Ultimate_ModuleCreator_Model_Module setRest()
50
+ * @method string getModuleName()
51
+ * @method int getInstall()
52
+ * @method Ultimate_ModuleCreator_Model_Module setInstall()
53
+ * @method bool getHasEav()
54
+ * @method int getSortOrder()
55
+ * @method string getMenuText()
56
+ * @method string getCodepool()
57
+ * @method string getVersion()
58
+ * @method bool getCreateFrontend()
59
+ * @method bool getLinkProduct()
60
+ * @method bool getLinkCategory()
61
+ * @method bool getHasCatalogAttribute()
62
+ * @method bool getLinkCore()
63
+ * @method bool getShowInCategoryMenu()
64
+ */
65
+ class Ultimate_ModuleCreator_Model_Module extends Ultimate_ModuleCreator_Model_Abstract
66
+ {
67
+ /**
68
+ * enterprise version where Varien_Io_File was changed
69
+ *
70
+ * @var string
71
+ */
72
+ const EFFIN_VERSION_ENTERPRISE = '1.13.1';
73
+
74
+ /**
75
+ * community version where Varien_Io_File was changed
76
+ *
77
+ * @var string
78
+ */
79
+ const EFFIN_VERSION_COMMUNITY = '1.8.1';
80
+
81
+ /**
82
+ * entity code
83
+ *
84
+ * @var string
85
+ */
86
+ protected $_entityCode = 'umc_module';
87
+
88
+ /**
89
+ * module entities
90
+ *
91
+ * @var array()
92
+ */
93
+ protected $_entities = array();
94
+
95
+ /**
96
+ * module config
97
+ *
98
+ * @var mixed (null|Varien_Simplexml_Element)
99
+ */
100
+ protected $_config = null;
101
+
102
+ /**
103
+ * entity relations
104
+ *
105
+ * @var array
106
+ */
107
+ protected $_relations = array();
108
+
109
+ /**
110
+ * io member
111
+ *
112
+ * @var null|Varien_Io_File
113
+ */
114
+ protected $_io = null;
115
+
116
+ /**
117
+ * error log
118
+ *
119
+ * @var array
120
+ */
121
+ protected $_errors = array();
122
+
123
+ /**
124
+ * source folder
125
+ *
126
+ * @var null
127
+ */
128
+ protected $_sourceFolder = null;
129
+
130
+ /**
131
+ * placeholders
132
+ *
133
+ * @var null
134
+ */
135
+ protected $_placeholders = null;
136
+
137
+ /**
138
+ * base placeholders
139
+ *
140
+ * @var array
141
+ */
142
+ protected $_basePlaceholders = array();
143
+
144
+ /**
145
+ * generated files
146
+ *
147
+ * @var array
148
+ */
149
+ protected $_files = array();
150
+
151
+ /**
152
+ * keep modman paths
153
+ *
154
+ * @var array
155
+ */
156
+ protected $_modman = array();
157
+
158
+ /**
159
+ * add entity to module
160
+ *
161
+ * @access public
162
+ * @param Ultimate_ModuleCreator_Model_Entity $entity
163
+ * @return Ultimate_ModuleCreator_Model_Module
164
+ * @throws Ultimate_ModuleCreator_Exception
165
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
166
+ */
167
+ public function addEntity(Ultimate_ModuleCreator_Model_Entity $entity)
168
+ {
169
+ Mage::dispatchEvent(
170
+ 'umc_module_add_entity_before',
171
+ array('entity'=>$entity, 'module'=>$this)
172
+ );
173
+ if (isset($this->_entities[$entity->getNameSingular()])) {
174
+ throw new Ultimate_ModuleCreator_Exception(
175
+ Mage::helper('modulecreator')->__(
176
+ 'An entity with the code "%s" already exists',
177
+ $entity->getNameSingular()
178
+ )
179
+ );
180
+ }
181
+ $entity->setModule($this);
182
+ $entity->setIndex(count($this->_entities));
183
+ $position = 10 * (count($this->_entities));
184
+ $entity->setPosition($position);
185
+ $this->_entities[$entity->getNameSingular()] = $entity;
186
+ if ($entity->getRss()) {
187
+ $this->setRss(true);
188
+ }
189
+ if ($entity->getHasFile()) {
190
+ $this->setHasFile(true);
191
+ }
192
+ if ($entity->getHasImage()) {
193
+ $this->setHasImage(true);
194
+ }
195
+ if ($entity->getAddSeo()) {
196
+ $this->setAddSeo(true);
197
+ }
198
+ if ($entity->getWidget()) {
199
+ $this->setWidget(true);
200
+ }
201
+ if ($entity->getCreateFrontend()) {
202
+ $this->setCreateFrontend(true);
203
+ $this->setCanCreateRouter(true);
204
+ }
205
+ if ($entity->getCreateList()) {
206
+ $this->setCreateList(true);
207
+ }
208
+ if ($entity->getIsTree()) {
209
+ $this->setHasTree(true);
210
+ }
211
+ if ($entity->getEditor()) {
212
+ $this->setEditor(true);
213
+ }
214
+ if ($entity->getHasConfigDefaults()) {
215
+ $this->setHasConfigDefaults(true);
216
+ }
217
+ if ($entity->getLinkProduct()) {
218
+ $this->setLinkProduct(true);
219
+ $this->setHasObserver(true);
220
+ }
221
+ if ($entity->getLinkCategory()) {
222
+ $this->setLinkCategory(true);
223
+ $this->setHasObserver(true);
224
+ }
225
+ if ($entity->getLinkCore()) {
226
+ $this->setLinkCore(true);
227
+ }
228
+ if ($entity->getUrlRewrite()) {
229
+ $this->setUrlRewrite(true);
230
+ }
231
+ if ($entity->getIsEav()) {
232
+ $this->setHasEav(true);
233
+ }
234
+ if ($entity->getIsFlat()) {
235
+ $this->setHasFlat(true);
236
+ }
237
+ if ($entity->getApi()) {
238
+ $this->setApi(true);
239
+ }
240
+ if ($entity->getAllowComment()) {
241
+ $this->setAllowComment(true);
242
+ }
243
+ if ($entity->getAllowCommentByStore()) {
244
+ $this->setAllowCommentByStore(true);
245
+ }
246
+ if ($entity->getHasCountry()) {
247
+ $this->setHasCountry(true);
248
+ }
249
+ if ($entity->getAddSeo()) {
250
+ $this->setHasSeo(true);
251
+ }
252
+ if ($entity->getCanCreateListBlock()) {
253
+ $this->setCreateFrontend(true);
254
+ }
255
+ if ($entity->getShowOnProduct()) {
256
+ $this->setShowOnProduct(true);
257
+ }
258
+ if ($entity->getShowOnCategory()) {
259
+ $this->setShowOnCategory(true);
260
+ }
261
+ if ($entity->getShowInCategoryMenu()) {
262
+ $this->setShowInCategoryMenu(true);
263
+ }
264
+ if ($entity->getSearch()) {
265
+ $this->setSearch(true);
266
+ }
267
+ if ($entity->getProductAttribute() ||$entity->getCategoryAttribute()) {
268
+ $this->setHasCatalogAttribute(true);
269
+ }
270
+ if ($entity->getRest()) {
271
+ $this->setRest(true);
272
+ }
273
+ Mage::dispatchEvent(
274
+ 'umc_module_add_entity_after',
275
+ array('entity'=>$entity, 'module'=>$this)
276
+ );
277
+ return $this;
278
+ }
279
+
280
+ /**
281
+ * get a module entity
282
+ *
283
+ * @access public
284
+ * @param string $code
285
+ * @return mixed(Ultimate_ModuleCreator_Model_Entity|null)
286
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
287
+ */
288
+ public function getEntity($code)
289
+ {
290
+ if (isset($this->_entities[$code])) {
291
+ return $this->_entities[$code];
292
+ }
293
+ return null;
294
+ }
295
+
296
+ /**
297
+ * module to xml
298
+ *
299
+ * @access public
300
+ * @param array $arrAttributes
301
+ * @param string $rootName
302
+ * @param bool $addOpenTag
303
+ * @param bool $addCdata
304
+ * @return string
305
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
306
+ */
307
+ public function toXml(array $arrAttributes = array(), $rootName = 'module', $addOpenTag=false, $addCdata=false)
308
+ {
309
+ $xml = '';
310
+ $eol = $this->getEol();
311
+ if ($addOpenTag) {
312
+ $xml.= '<?xml version="1.0" encoding="UTF-8"?>'.$eol;
313
+ }
314
+ if (!empty($rootName)) {
315
+ $xml.= '<'.$rootName.'>'.$eol;
316
+ }
317
+ $xml .= parent::toXml($this->getXmlAttributes(), '', false, $addCdata);
318
+ $xml .= '<entities>'.$eol;
319
+ foreach ($this->getEntities() as $entity) {
320
+ $xml .= $entity->toXml(array(), 'entity', false, $addCdata);
321
+ }
322
+ $xml .= '</entities>'.$eol;
323
+ $xml .= '<relations>'.$eol;
324
+ foreach ($this->getRelations() as $relation) {
325
+ $xml .= $relation->toXml(array(), '', false, $addCdata);
326
+ }
327
+ $xml .= '</relations>'.$eol;
328
+ if (!empty($rootName)) {
329
+ $xml.= '</'.$rootName.'>'.$eol;
330
+ }
331
+ return $xml;
332
+ }
333
+
334
+ /**
335
+ * get the module entities
336
+ *
337
+ * @access public
338
+ * @return Ultimate_ModuleCreator_Model_Entity[]
339
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
340
+ */
341
+ public function getEntities()
342
+ {
343
+ $this->_prepareEntities();
344
+ return $this->_entities;
345
+ }
346
+
347
+ /**
348
+ * prepare the entities before saving
349
+ *
350
+ * @access protected
351
+ * @return Ultimate_ModuleCreator_Model_Module
352
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
353
+ */
354
+ protected function _prepareEntities()
355
+ {
356
+ Mage::dispatchEvent('umc_module_prepare_entities', array('module'=>$this));
357
+ return $this;
358
+ }
359
+
360
+ /**
361
+ * add relation to module
362
+ *
363
+ * @access public
364
+ * @param Ultimate_ModuleCreator_Model_Relation $relation
365
+ * @return Ultimate_ModuleCreator_Model_Module
366
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
367
+ */
368
+ public function addRelation(Ultimate_ModuleCreator_Model_Relation $relation)
369
+ {
370
+ Mage::dispatchEvent(
371
+ 'umc_module_add_relation_before',
372
+ array('relation'=>$relation, 'module'=>$this)
373
+ );
374
+ $this->_relations[] = $relation;
375
+ Mage::dispatchEvent(
376
+ 'umc_module_add_relation_after',
377
+ array('relation'=>$relation, 'module'=>$this)
378
+ );
379
+ return $this;
380
+ }
381
+
382
+ /**
383
+ * get module relations
384
+ *
385
+ * @access public
386
+ * @param mixed $type
387
+ * @return Ultimate_ModuleCreator_Model_Relation[]
388
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
389
+ */
390
+ public function getRelations($type = null)
391
+ {
392
+ if (is_null($type)) {
393
+ return $this->_relations;
394
+ }
395
+ $relations = array();
396
+ foreach ($this->_relations as $relation) {
397
+ /** @var Ultimate_ModuleCreator_Model_Relation $relation */
398
+ if ($relation->getType() == $type) {
399
+ $relations[] = $relation;
400
+ }
401
+ }
402
+ return $relations;
403
+ }
404
+
405
+ /**
406
+ * get the extensions xml path
407
+ *
408
+ * @access public
409
+ * @return string
410
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
411
+ */
412
+ public function getXmlPath()
413
+ {
414
+ return $this->getHelper()->getLocalPackagesPath().
415
+ $this->getNamespace()."_".$this->getModuleName().'.xml';
416
+ }
417
+
418
+ /**
419
+ * save the module as xml
420
+ *
421
+ * @access public
422
+ * @return Ultimate_ModuleCreator_Model_Module
423
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
424
+ */
425
+ public function save()
426
+ {
427
+ $destination = $this->getXmlPath();
428
+ $xml = $this->toXml(array(), 'module', true, true);
429
+ $this->_writeFile($destination, $xml);
430
+ return $this;
431
+ }
432
+
433
+ /**
434
+ * validate the module
435
+ *
436
+ * @access public
437
+ * @return array
438
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
439
+ */
440
+ public function validate()
441
+ {
442
+ $config = $this->getHelper()->getConfig();
443
+ $settings = $config->getNode('forms/settings/fieldsets');
444
+ foreach ($settings->fieldset as $set) {
445
+ foreach ($set->fields->children() as $key => $values) {
446
+ $v = $this->getData($key);
447
+ if ((string)$values->required == 1 && (!$this->hasData($key) || $v === "")) {
448
+ $this->_addError(
449
+ Mage::helper("modulecreator")->__('This is a required field.'),
450
+ 'settings_'.$key
451
+ );
452
+ }
453
+ }
454
+ }
455
+ //validate namespace
456
+ if (strtolower($this->getNamespace()) == 'mage') {
457
+ $this->_addError(
458
+ Mage::helper('modulecreator')->__("You shouldn't use the namespace Mage. Be Creative"),
459
+ 'settings_namespace'
460
+ );
461
+ }
462
+ //validate module name
463
+ $routers = Mage::getConfig()->getNode('frontend/routers');
464
+ $moduleName = $this->getModuleName();
465
+ $lower = strtolower($moduleName);
466
+ $extension = $this->getExtensionName();
467
+ if ($routers->$lower) {
468
+ if ((string)$routers->$lower->args->module != $extension) {
469
+ $this->_addError(
470
+ Mage::helper('modulecreator')->__(
471
+ 'You cannot use the module name %s',
472
+ $this->getModuleName()
473
+ ),
474
+ 'settings_module_name'
475
+ );
476
+ }
477
+ }
478
+ //validate front key
479
+ foreach ((array)$routers as $router) {
480
+ if ((string)$router->args->frontName == $this->getFrontKey() &&
481
+ $router->args->module != $extension) {
482
+ $this->_addError(
483
+ Mage::helper('modulecreator')->__(
484
+ 'You cannot use the front key %s. It is used by the module %s',
485
+ $this->getFrontKey(),
486
+ (string)$router->args->module
487
+ ),
488
+ 'settings_front_key'
489
+ );
490
+ break;
491
+ }
492
+ }
493
+ //validate entity count
494
+ if (count($this->getEntities()) == 0) {
495
+ $this->_addError(Mage::helper('modulecreator')->__('Add at least an entity'));
496
+ } else {
497
+ //validate entities
498
+ foreach ($this->getEntities() as $entity) {
499
+ $entityCode = $entity->getNameSingular(true);
500
+ if (in_array($entityCode, $this->getRestrictedEntityNames())) {
501
+ $this->_addError(
502
+ Mage::helper('modulecreator')->__(
503
+ 'The entity code "%s" is restricted',
504
+ $entityCode
505
+ ),
506
+ 'entity_'.$entity->getIndex().'_name_singular'
507
+ );
508
+ }
509
+ if (count($entity->getAttributes()) == 0) {
510
+ $this->_addError(
511
+ Mage::helper('modulecreator')->__(
512
+ 'The entity "%s" must have at least one attribute.',
513
+ $entity->getLabelSingular()
514
+ )
515
+ );
516
+ } else {
517
+ //validate name attribute
518
+ if (is_null($entity->getNameAttribute())) {
519
+ $this->_addError(
520
+ Mage::helper('modulecreator')->__(
521
+ 'The entity "%s" must have an attribute that behaves as a name.',
522
+ $entity->getLabelSingular()
523
+ )
524
+ );
525
+ }
526
+ $restrictedAttributes = $this->getRestrictedAttributeCodes();
527
+ //validate attributes
528
+ foreach ($entity->getAttributes() as $attribute) {
529
+ $code = $attribute->getCode();
530
+ if (isset($restrictedAttributes[$code])) {
531
+ //presume "not guilty"
532
+ $valid = true;
533
+ if (!isset($restrictedAttributes[$code]->depend_entity)) {//if general restriction.
534
+ $valid = false;
535
+ } else {//if depends on entity setting.
536
+ foreach ((array)$restrictedAttributes[$code]->depend_entity as $prop=>$value) {
537
+ if ($entity->getDataUsingMethod($prop) == $value) {
538
+ //"found guilty"
539
+ $valid = false;
540
+ break;
541
+ }
542
+ }
543
+ }
544
+ if (!$valid) {
545
+ $this->_addError(
546
+ $restrictedAttributes[$code]->message,
547
+ 'attribute_'.$entity->getIndex().'_'.$attribute->getIndex().'_code'
548
+ );
549
+ }
550
+ }
551
+ //validate attributes against getters ("getData", "getCollection", ,....)
552
+ $methodCodes = $this->getMethodAttributeCodes();
553
+ if (in_array($code, $methodCodes)) {
554
+ $method = $method = str_replace(' ', '', ucwords(str_replace('_', ' ', $code)));
555
+ $this->_addError(
556
+ Mage::helper('modulecreator')->__('Attribute code %s is restricted because a method similar to "set%s()" or "get%s()" exists in parent model class', $code, $method, $method),
557
+ 'attribute_'.$entity->getIndex().'_'.$attribute->getIndex().'_code'
558
+ );
559
+ }
560
+ }
561
+ }
562
+ }
563
+ }
564
+
565
+ return $this->_errors;
566
+ }
567
+
568
+ /**
569
+ * add an error to the error list
570
+ *
571
+ * @access protected
572
+ * @param $message
573
+ * @param null $attribute
574
+ * @param string $separator
575
+ * @return Ultimate_ModuleCreator_Model_Module
576
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
577
+ */
578
+ protected function _addError($message, $attribute = null, $separator = '<br />')
579
+ {
580
+ if (empty($attribute)) {
581
+ $this->_errors[''][] = $message;
582
+ } else {
583
+ if (!isset($this->_errors[$attribute])) {
584
+ $this->_errors[$attribute] = '';
585
+ } else {
586
+ $this->_errors[$attribute] .= $separator;
587
+ }
588
+ $this->_errors[$attribute] .= $message;
589
+ }
590
+ return $this;
591
+ }
592
+
593
+ /**
594
+ * write a file
595
+ *
596
+ * @access protected
597
+ * @param string $destinationFile
598
+ * @param string $contents
599
+ * @throws Exception
600
+ * @return Ultimate_ModuleCreator_Model_Module
601
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
602
+ */
603
+ protected function _writeFile($destinationFile, $contents)
604
+ {
605
+ try {
606
+ $io = $this->getIo();
607
+ $io->mkdir(dirname($destinationFile));
608
+ /**
609
+ * Varien_Io_File has changed in CE 1.8.1 / EE 1.13.1 A LOT
610
+ */
611
+ if (version_compare(Mage::getVersion(), $this->getEffinVersion(), '<')) {
612
+ $io->write($destinationFile, $contents, 0777);
613
+ } else {
614
+ $io->filePutContent($destinationFile, $contents);
615
+ }
616
+ } catch (Exception $e) {
617
+ if ($e->getCode() != 0) {
618
+ throw $e;
619
+ }
620
+ }
621
+ return $this;
622
+ }
623
+
624
+ /**
625
+ * get the version for which the io writer has changed
626
+ *
627
+ * @access public
628
+ * @return string
629
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
630
+ */
631
+ public function getEffinVersion()
632
+ {
633
+ if (Mage::getEdition() == Mage::EDITION_ENTERPRISE) {
634
+ return self::EFFIN_VERSION_ENTERPRISE;
635
+ }
636
+ return self::EFFIN_VERSION_COMMUNITY;
637
+ }
638
+
639
+ /**
640
+ * get the IO - class instance
641
+ *
642
+ * @access public
643
+ * @return Varien_Io_File
644
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
645
+ */
646
+ public function getIo()
647
+ {
648
+ if (!$this->_io) {
649
+ $this->_io = new Varien_Io_File();
650
+ $this->_io->setAllowCreateFolders(true);
651
+ }
652
+ return $this->_io;
653
+ }
654
+
655
+ /**
656
+ * get module relations as json
657
+ *
658
+ * @access public
659
+ * @return string
660
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
661
+ */
662
+ public function getRelationsAsJson()
663
+ {
664
+ $json = array();
665
+ $relations = $this->getRelations();
666
+ foreach ($relations as $relation) {
667
+ $entities = $relation->getEntities();
668
+ $json[$entities[0]->getIndex().'_'.$entities[1]->getIndex()] = $relation->getType();
669
+ }
670
+ return json_encode($json);
671
+ }
672
+
673
+ /**
674
+ * get the extension name
675
+ *
676
+ * @param bool $lower
677
+ * @return string
678
+ * @access public
679
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
680
+ */
681
+ public function getExtensionName($lower = false)
682
+ {
683
+ $name = $this->getNamespace().'_'.$this->getModuleName();
684
+ if ($lower) {
685
+ $name = strtolower($name);
686
+ }
687
+ return $name;
688
+ }
689
+
690
+ /**
691
+ * get the restricted entity name
692
+ *
693
+ * @access public
694
+ * @return array
695
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
696
+ */
697
+ public function getRestrictedEntityNames()
698
+ {
699
+ return $this->getDataSetDefault(
700
+ 'restricted_entity_names',
701
+ array_keys(
702
+ (array)$this->getHelper()->getConfig()->getNode('restricted/entity')
703
+ )
704
+ );
705
+ }
706
+
707
+ /**
708
+ * get the restricted attribute codes
709
+ *
710
+ * @access public
711
+ * @return array
712
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
713
+ */
714
+ public function getRestrictedAttributeCodes()
715
+ {
716
+ return $this->getDataSetDefault(
717
+ 'restricted_attribute_codes',
718
+ (array)$this->getHelper()->getConfig()->getNode('restricted/attribute')
719
+ );
720
+ }
721
+
722
+ /**
723
+ * get the restricted attribute codes because of the method names
724
+ *
725
+ * @access public
726
+ * @return array
727
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
728
+ */
729
+ public function getMethodAttributeCodes()
730
+ {
731
+ if (!$this->hasData('method_attribute_codes')) {
732
+ $attributes = array();
733
+ $methods = get_class_methods('Mage_Catalog_Model_Abstract');
734
+ $start = array('get', 'set', 'has', 'uns');
735
+ foreach ($methods as $method) {
736
+ if (in_array(substr($method, 0, 3), $start)) {
737
+ $attribute = strtolower(preg_replace('/(.)([A-Z])/', "$1_$2", substr($method, 3)));
738
+ $attributes[$attribute] = 1;
739
+ }
740
+ }
741
+ $this->setData('method_attribute_codes', array_keys($attributes));
742
+ }
743
+ return $this->getData('method_attribute_codes');
744
+ }
745
+
746
+ /**
747
+ * build the module
748
+ *
749
+ * @access public
750
+ * @return array
751
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
752
+ */
753
+ public function buildModule()
754
+ {
755
+ $config = $this->getConfig();
756
+ $files = $config->getNode('files');
757
+ $messages = array();
758
+ foreach ((array)$files as $file) {
759
+ if ($file->scope == 'disabled') {
760
+ continue;
761
+ }
762
+ $this->_createFile($file);
763
+ }
764
+ if ($this->getInstall()) {
765
+ $existingFiles = $this->_checkExistingFiles();
766
+ if (count($existingFiles) > 0) {
767
+ $this->setInstall(false);
768
+ $messages[] = Mage::helper('modulecreator')->__(
769
+ 'The following files already exist. They were NOT overwritten. The extension was not installed. You can download it from the list of extensions and install it manually: %s',
770
+ implode('<br />', $existingFiles)
771
+ );
772
+ }
773
+ }
774
+ $this->_writeFiles();
775
+ if (!$this->getInstall()) {
776
+ $contents = array();
777
+ foreach ($this->_files as $filename=>$file) {
778
+ $contents[] = $this->getRelativeBasePath().$filename;
779
+ }
780
+ /** @var Ultimate_ModuleCreator_Model_Writer $_writer */
781
+ $_writer = Mage::getModel('modulecreator/writer', $contents);
782
+ $_writer->setPathPrefix('var'.DS.'modulecreator'.DS.$this->getExtensionName().DS);
783
+ $_writer->setNamePackage(Mage::getBaseDir('var').DS.'modulecreator'.DS.$this->getExtensionName());
784
+ $_writer->composePackage()->archivePackage();
785
+ $this->_io->rmdir($this->getBasePath(), true);
786
+ }
787
+ return $messages;
788
+ }
789
+
790
+ /**
791
+ * write files to disk
792
+ *
793
+ * @access protected
794
+ * @return Ultimate_ModuleCreator_Model_Module
795
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
796
+ */
797
+ protected function _writeFiles()
798
+ {
799
+ $basePath = $this->getBasePath();
800
+ foreach ($this->_files as $name=>$file) {
801
+ $destinationFile = $basePath.$name;
802
+ $this->_writeFile($destinationFile, $file);
803
+ }
804
+ $this->_writeLog();
805
+ $this->_writeUninstall();
806
+ $this->_writeModman();
807
+ return $this;
808
+ }
809
+
810
+ /**
811
+ * write log with generated files
812
+ *
813
+ * can be used for uninstall
814
+ * @access protected
815
+ * @return Ultimate_ModuleCreator_Model_Module
816
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
817
+ */
818
+ protected function _writeLog()
819
+ {
820
+ $filesToWrite = array_keys($this->_files);
821
+ asort($filesToWrite);
822
+ $filesToWrite = array_values($filesToWrite);
823
+ $text = implode($this->getEol(), $filesToWrite);
824
+ $this->_writeFile($this->getLogPath(), $text);
825
+ return $this;
826
+ }
827
+
828
+ /**
829
+ * write sql uninstall script
830
+ *
831
+ * @access protected
832
+ * @return Ultimate_ModuleCreator_Model_Module
833
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
834
+ */
835
+ protected function _writeUninstall()
836
+ {
837
+ $lines = array();
838
+ $module = $this->getPlaceholder('{{module}}');
839
+ $namespace = $this->getNamespace(true);
840
+ $lines[] = '-- add table prefix if you have one';
841
+ foreach ($this->getRelations(Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_SIBLING) as $relation) {
842
+ $entities = $relation->getEntities();
843
+ $tableName = $namespace.'_'.$module.'_'.
844
+ $entities[0]->getPlaceholders('{{entity}}').'_'.
845
+ $entities[1]->getPlaceholders('{{entity}}');
846
+ $lines[] = 'DROP'.' TABLE IF EXISTS '.$tableName.';';
847
+ }
848
+ foreach ($this->getEntities() as $entity) {
849
+ if ($entity->getIsEav()) {
850
+ $entityTypeCode = $namespace.'_'.$this->getLowerModuleName().'_'.$entity->getPlaceholders('{{entity}}');
851
+ $lines[] = "DELETE"." FROM eav_attribute WHERE entity_type_id IN ".
852
+ "(SELECT entity_type_id FROM eav_entity_type WHERE entity_type_code = '{$entityTypeCode}');";
853
+ $lines[] = "DELETE"." FROM eav_entity_type WHERE entity_type_code = '{$entityTypeCode}';";
854
+ }
855
+ if ($entity->getProductAttribute()) {
856
+ $lines[] = "DELETE"." FROM eav_attribute WHERE attribute_code = '".
857
+ $entity->getProductAttributeCode().
858
+ "' AND entity_type_id IN
859
+ (SELECT entity_type_id FROM eav_entity_type WHERE entity_type_code = 'catalog_product');";
860
+ }
861
+ if ($entity->getCategoryAttribute()) {
862
+ $lines[] = "DELETE"." FROM eav_attribute WHERE attribute_code = '".$entity->getCategoryAttributeCode().
863
+ "' AND entity_type_id IN (SELECT entity_type_id FROM eav_entity_type WHERE entity_type_code = 'catalog_category');";
864
+ }
865
+ if ($entity->getAllowCommentByStore()) {
866
+ $tableName = $namespace.'_'.$module.'_'.$entity->getPlaceholders('{{entity}}').'_comment_store';
867
+ $lines[] = 'DROP'.' TABLE IF EXISTS '.$tableName.';';
868
+ }
869
+ if ($entity->getAllowComment()) {
870
+ $tableName = $namespace.'_'.$module.'_'.$entity->getPlaceholders('{{entity}}').'_comment';
871
+ $lines[] = 'DROP'.' TABLE IF EXISTS '.$tableName.';';
872
+ }
873
+ if ($entity->getLinkProduct()) {
874
+ $tableName = $namespace.'_'.$module.'_'.$entity->getPlaceholders('{{entity}}').'_product';
875
+ $lines[] = 'DROP'.' TABLE IF EXISTS '.$tableName.';';
876
+ }
877
+ if ($entity->getLinkCategory()) {
878
+ $tableName = $namespace.'_'.$module.'_'.$entity->getPlaceholders('{{entity}}').'_category';
879
+ $lines[] = 'DROP'.' TABLE IF EXISTS '.$tableName.';';
880
+ }
881
+ if ($entity->getStore()) {
882
+ $tableName = $namespace.'_'.$module.'_'.$entity->getPlaceholders('{{entity}}').'_store';
883
+ $lines[] = 'DROP'.' TABLE IF EXISTS '.$tableName.';';
884
+ }
885
+ if ($entity->getIsEav()) {
886
+ foreach (array('int', 'decimal','datetime', 'varchar', 'text') as $type) {
887
+ $tableName = $namespace.'_'.$module.'_'.$entity->getPlaceholders('{{entity}}').'_'.$type;
888
+ $lines[] = 'DROP'.' TABLE IF EXISTS '.$tableName.';';
889
+ }
890
+ }
891
+ $tableName = $namespace.'_'.$module.'_'.$entity->getPlaceholders('{{entity}}');
892
+ $lines[] = 'DROP'.' TABLE IF EXISTS '.$tableName.';';
893
+ }
894
+ if ($this->getHasEav()) {
895
+ $tableName = $namespace.'_'.$module.'_eav_attribute';
896
+ $lines[] = 'DROP'.' TABLE IF EXISTS '.$tableName.';';
897
+ }
898
+ $lines[] = "DELETE"." FROM core_resource WHERE code = '".$namespace.'_'.$module."_setup';";
899
+ $lines[] = "DELETE"." FROM core_config_data WHERE path like '".$namespace.'_'.$module."/%';";
900
+ $text = implode($this->getEol(), $lines);
901
+ $this->_writeFile($this->getUninstallPath(), $text);
902
+ return $this;
903
+ }
904
+
905
+ /**
906
+ * write the modman file
907
+ *
908
+ * @access protected
909
+ * @return Ultimate_ModuleCreator_Model_Module
910
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
911
+ */
912
+ protected function _writeModman()
913
+ {
914
+ $paths = array(
915
+ 'app/etc/modules/'.$this->getNamespace().'_'.$this->getModuleName().'.xml',
916
+ 'app/code/'.$this->getCodepool().'/'.$this->getNamespace().'_'.$this->getModuleName(),
917
+ 'app/locale/en_US/'.$this->getNamespace().'_'.$this->getModuleName().'.csv',
918
+ 'app/design/adminhtml/default/default/layout/'.$this->getNamespace(true).'_'.$this->getLowerModuleName().'.xml',
919
+ 'app/design/adminhtml/default/default/template/'.$this->getNamespace(true).'_'.$this->getLowerModuleName()
920
+ );
921
+ if ($this->getCreateFrontend()) {
922
+ $paths[] = 'app/design/frontend/base/default/layout/'.$this->getNamespace(true).'_'.$this->getLowerModuleName().'.xml';
923
+ $paths[] = 'app/design/adminhtml/default/default/template/'.$this->getNamespace(true).'_'.$this->getLowerModuleName();
924
+ }
925
+ foreach ($this->getEntities() as $entity) {
926
+ if ($entity->getHasImage()) {
927
+ $paths[] = 'skin/frontend/base/default/images/placeholder/'.$entity->getNameSingular(true).'.jpg';
928
+ }
929
+ if ($entity->getIsTree()) {
930
+ $paths[] = 'skin/frontend/base/default/css/'.$this->getNamespace(true).'_'.$this->getLowerModuleName();
931
+ $paths[] = 'skin/frontend/base/default/images/'.$this->getNamespace(true).'_'.$this->getLowerModuleName();
932
+ $paths[] = 'skin/frontend/base/default/js/'.$this->getNamespace(true).'_'.$this->getLowerModuleName();
933
+ }
934
+ }
935
+ sort($paths);
936
+ $paths = array_unique($paths);
937
+ $text = '';
938
+ $eol = $this->getEol();
939
+ foreach ($paths as $path) {
940
+ $text .= $path . ' '.$path.$eol;
941
+ }
942
+ $this->_writeFile($this->getModmanPath(), $text);
943
+ return $this;
944
+ }
945
+
946
+ /**
947
+ * get path for modman file
948
+ *
949
+ * @access public
950
+ * @return string
951
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
952
+ */
953
+ public function getModmanPath()
954
+ {
955
+ return $this->getHelper()->getLocalPackagesPath().$this->getExtensionName().'/modman';
956
+ }
957
+
958
+ /**
959
+ * check if some files already exist so it won't be overwritten
960
+ *
961
+ * @access protected
962
+ * @return array()
963
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
964
+ */
965
+ protected function _checkExistingFiles()
966
+ {
967
+ $existingFiles = array();
968
+ $io = $this->getIo();
969
+ $basePath = $this->getBasePath();
970
+ foreach ($this->_files as $name=>$content) {
971
+ if ($io->fileExists($basePath.$name)) {
972
+ $existingFiles[] = $basePath.$name;
973
+ }
974
+ }
975
+ return $existingFiles;
976
+ }
977
+
978
+ /**
979
+ * get path for log file
980
+ *
981
+ * @access public
982
+ * @return string
983
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
984
+ */
985
+ public function getLogPath()
986
+ {
987
+ return $this->getHelper()->getLocalPackagesPath().$this->getExtensionName().'/files.log';
988
+ }
989
+
990
+ /**
991
+ * get path for uninstall sql file
992
+ *
993
+ * @access public
994
+ * @return string
995
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
996
+ */
997
+ public function getUninstallPath()
998
+ {
999
+ return $this->getHelper()->getLocalPackagesPath().$this->getExtensionName().'/uninstall.sql';
1000
+ }
1001
+
1002
+ /**
1003
+ * get module base path
1004
+ *
1005
+ * @access public
1006
+ * @return string
1007
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1008
+ */
1009
+ public function getBasePath()
1010
+ {
1011
+ if (!$this->getInstall()) {
1012
+ return Mage::getBaseDir('var').DS.'modulecreator'.DS.$this->getExtensionName().DS;
1013
+ }
1014
+ return Mage::getBaseDir().DS;
1015
+ }
1016
+
1017
+ /**
1018
+ * get relative path ro the module
1019
+ *
1020
+ * @access public
1021
+ * @return string
1022
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1023
+ */
1024
+ public function getRelativeBasePath()
1025
+ {
1026
+ $basePath = $this->getBasePath();
1027
+ $remove = Mage::getBaseDir().DS;
1028
+ $relativePath = substr($basePath, strlen($remove));
1029
+ return $relativePath;
1030
+ }
1031
+
1032
+ /**
1033
+ * get the module config
1034
+ *
1035
+ * @access public
1036
+ * @return Varien_Simplexml_Config
1037
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1038
+ */
1039
+ public function getConfig()
1040
+ {
1041
+ if (is_null($this->_config)) {
1042
+ $this->_config = Mage::getConfig()->loadModulesConfiguration('umc_source.xml')->applyExtends();
1043
+ }
1044
+ return $this->_config;
1045
+ }
1046
+
1047
+ /**
1048
+ * get contents of a file
1049
+ *
1050
+ * @access public
1051
+ * @param string $file
1052
+ * @return string
1053
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1054
+ */
1055
+ public function getFileContents($file)
1056
+ {
1057
+ return file_get_contents($file);
1058
+ }
1059
+
1060
+ /**
1061
+ * create a file
1062
+ *
1063
+ * @access protected
1064
+ * @param Varien_Simplexml_Element
1065
+ * @return Ultimate_ModuleCreator_Model_Module
1066
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1067
+ */
1068
+ protected function _createFile($config)
1069
+ {
1070
+ switch ($config->scope) {
1071
+ case 'entity' :
1072
+ $this->_buildEntityFile($config);
1073
+ break;
1074
+ case 'siblings':
1075
+ $this->_buildSiblingFile($config);
1076
+ break;
1077
+ case 'children' :
1078
+ $this->_buildChildrenFile($config);
1079
+ break;
1080
+ case 'attribute' :
1081
+ $this->_buildAttributeFile($config);
1082
+ break;
1083
+ case 'global':
1084
+ default:
1085
+ $this->_buildGlobalFile($config);
1086
+ break;
1087
+ }
1088
+ return $this;
1089
+ }
1090
+
1091
+ /**
1092
+ * validate xml condition
1093
+ *
1094
+ * @access protected
1095
+ * @param Ultimate_ModuleCreator_Model_Abstract $entity
1096
+ * @param Mage_Core_Model_Config_Element $conditions
1097
+ * @param mixed $params
1098
+ * @return bool
1099
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1100
+ */
1101
+ protected function _validateDepend(
1102
+ Ultimate_ModuleCreator_Model_Abstract $entity,
1103
+ Mage_Core_Model_Config_Element $conditions,
1104
+ $params = null
1105
+ ) {
1106
+ if (!$conditions) {
1107
+ return true;
1108
+ }
1109
+ if (!is_array($conditions)) {
1110
+ $conditions = $conditions->asArray();
1111
+ }
1112
+ foreach ($conditions as $condition=>$value) {
1113
+ if (!$entity->getDataUsingMethod($condition, $params)) {
1114
+ return false;
1115
+ }
1116
+ }
1117
+ return true;
1118
+ }
1119
+
1120
+ /**
1121
+ * create a file with global scope
1122
+ *
1123
+ * @access protected
1124
+ * @param Varien_Simplexml_Element
1125
+ * @return Ultimate_ModuleCreator_Model_Module
1126
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1127
+ */
1128
+ public function _buildGlobalFile($config)
1129
+ {
1130
+ $filetype = $config->filetype;
1131
+ $sourceFolder = $this->getSourceFolder().$this->_filterString((string)$config->source, $filetype);
1132
+ $destination = $this->_filterString((string)$config->destination, $filetype);
1133
+ $content = '';
1134
+ $depend = $config->depend;
1135
+ if (!$this->_validateDepend($this, $depend)) {
1136
+ return '';
1137
+ }
1138
+ if ($config->method) {
1139
+ $method = (string)$config->method;
1140
+ $content = $this->$method();
1141
+ } else {
1142
+ $code = $this->_sortCodeFiles((array)$config->code);
1143
+ foreach ($code as $file) {
1144
+ $sourceContent = $this->getFileContents($sourceFolder.(string)$file->name);
1145
+ $scope = (string)$file->scope;
1146
+ $depend = $file->depend;
1147
+ if ($scope == 'entity') {
1148
+ foreach ($this->getEntities() as $entity) {
1149
+ if ($this->_validateDepend($entity, $depend)) {
1150
+ $replace = $entity->getPlaceholders();
1151
+ $content .= $this->_filterString($sourceContent, $filetype, $replace, true);
1152
+ }
1153
+ }
1154
+ } elseif ($scope == 'attribute') {
1155
+ $depend = $file->depend;
1156
+ /** @var Mage_Core_Model_Config_Element $dependType */
1157
+ $dependType = $file->depend_type;
1158
+ foreach ($this->getEntities() as $entity) {
1159
+ foreach ($entity->getAttributes() as $attribute) {
1160
+ $valid = $this->_validateDepend($attribute, $depend);
1161
+ $typeValid = true;
1162
+ if ($dependType) {
1163
+ $typeValid = false;
1164
+ foreach ($dependType->asArray() as $condition=>$value) {
1165
+ if ($attribute->getType() == $condition) {
1166
+ $typeValid = true;
1167
+ break;
1168
+ }
1169
+ }
1170
+ }
1171
+ if ($valid && $typeValid) {
1172
+ $replace = $entity->getPlaceholders();
1173
+ $attributeReplace = $attribute->getPlaceholders();
1174
+ $replace = array_merge($replace, $attributeReplace);
1175
+ $content .= $this->_filterString($sourceContent, $filetype, $replace, true);
1176
+ }
1177
+ }
1178
+ }
1179
+ } elseif ($scope == 'siblings') {
1180
+ $relatedEntities = $this->getRelations(
1181
+ Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_SIBLING
1182
+ );
1183
+ foreach ($relatedEntities as $relation) {
1184
+ $entities = $relation->getEntities();
1185
+ $replaceEntity = $entities[0]->getPlaceholders();
1186
+ $replaceSibling = $entities[1]->getPlaceholdersAsSibling();
1187
+ $replace = array_merge($replaceEntity, $replaceSibling);
1188
+ $content .= $this->_filterString($sourceContent, $filetype, $replace, true);
1189
+ }
1190
+ } elseif ($scope == 'siblings_both_tree') {
1191
+ $relatedEntities = $this->getRelations(
1192
+ Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_SIBLING
1193
+ );
1194
+ foreach ($relatedEntities as $relation) {
1195
+ $entities = $relation->getEntities();
1196
+ if ($entities[0]->getIsTree() || $entities[1]->getIsTree()) {
1197
+ if ($entities[0]->getIsTree()) {
1198
+ $tree = $entities[0];
1199
+ $sibling = $entities[1];
1200
+ } else {
1201
+ $tree = $entities[1];
1202
+ $sibling = $entities[0];
1203
+ }
1204
+ $replaceEntity = $tree->getPlaceholders();
1205
+ $replaceSibling = $sibling->getPlaceholdersAsSibling();
1206
+ $replace = array_merge($replaceEntity, $replaceSibling);
1207
+ $content .= $this->_filterString($sourceContent, $filetype, $replace, true);
1208
+ }
1209
+ }
1210
+ } elseif ($scope == 'siblings_both_not_tree') {
1211
+ $relatedEntities = $this->getRelations(
1212
+ Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_SIBLING
1213
+ );
1214
+ foreach ($relatedEntities as $relation) {
1215
+ $entities = $relation->getEntities();
1216
+ if ($entities[0]->getIsTree() || $entities[1]->getIsTree()) {
1217
+ continue;
1218
+ }
1219
+ $replaceEntity = $entities[0]->getPlaceholders();
1220
+ $replaceSibling = $entities[1]->getPlaceholdersAsSibling();
1221
+ $replace = array_merge($replaceEntity, $replaceSibling);
1222
+ $content .= $this->_filterString($sourceContent, $filetype, $replace, true);
1223
+
1224
+ $replaceEntity = $entities[1]->getPlaceholders();
1225
+ $replaceSibling = $entities[0]->getPlaceholdersAsSibling();
1226
+ $replace = array_merge($replaceEntity, $replaceSibling);
1227
+ $content .= $this->_filterString($sourceContent, $filetype, $replace, true);
1228
+ }
1229
+ } elseif ($scope == 'children') {
1230
+ $relatedEntities = $this->getRelations(
1231
+ Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_CHILD
1232
+ );
1233
+ foreach ($relatedEntities as $relation) {
1234
+ $entities = $relation->getEntities();
1235
+ $replaceEntity = $entities[0]->getPlaceholders();
1236
+ $replaceSibling = $entities[1]->getPlaceholdersAsSibling();
1237
+ $replace = array_merge($replaceEntity, $replaceSibling);
1238
+ $content .= $this->_filterString($sourceContent, $filetype, $replace, true);
1239
+ }
1240
+ $relatedEntities = $this->getRelations(
1241
+ Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_PARENT
1242
+ );
1243
+ foreach ($relatedEntities as $relation) {
1244
+ $entities = $relation->getEntities();
1245
+ $replaceEntity = $entities[1]->getPlaceholders();
1246
+ $replaceSibling = $entities[0]->getPlaceholdersAsSibling();
1247
+ $replace = array_merge($replaceEntity, $replaceSibling);
1248
+ $content .= $this->_filterString($sourceContent, $filetype, $replace, true);
1249
+ }
1250
+ } else {
1251
+ if ($this->_validateDepend($this, $depend)) {
1252
+ $content .= $this->_filterString($sourceContent, $filetype);
1253
+ }
1254
+ }
1255
+ }
1256
+ }
1257
+
1258
+ if ($config->after_build) {
1259
+ $function = (string)$config->after_build;
1260
+ $content = $this->$function($content);
1261
+ }
1262
+
1263
+ $content = $this->_filterString($content, $config->type);
1264
+ $this->_addFile($destination, $content);
1265
+ return $this;
1266
+ }
1267
+
1268
+ /**
1269
+ * create a file with entity scope
1270
+ *
1271
+ * @access protected
1272
+ * @param Varien_Simplexml_Element
1273
+ * @return Ultimate_ModuleCreator_Model_Module
1274
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1275
+ */
1276
+ public function _buildEntityFile($config)
1277
+ {
1278
+ foreach ($this->getEntities() as $entity) {
1279
+ $filetype = $config->filetype;
1280
+ $sourceFolder = $this->getSourceFolder().$this->_filterString((string)$config->source, $filetype);
1281
+ $destinationFile = $this->_filterString(
1282
+ (string)$config->destination,
1283
+ $filetype,
1284
+ $entity->getPlaceholders(),
1285
+ true
1286
+ );
1287
+ $content = '';
1288
+ $depend = $config->depend;
1289
+ if (!$this->_validateDepend($entity, $depend)) {
1290
+ continue;
1291
+ }
1292
+ $code = $this->_sortCodeFiles((array)$config->code);
1293
+ foreach ($code as $file) {
1294
+ $sourceContent = $this->getFileContents($sourceFolder.(string)$file->name);
1295
+ $scope = (string)$file->scope;
1296
+ $depend = $file->depend;
1297
+ /** @var Mage_Core_Model_Config_Element $dependType */
1298
+ $dependType = $file->depend_type;
1299
+ if ($scope == 'attribute') {
1300
+ foreach ($entity->getAttributes() as $attribute) {
1301
+ $valid = $this->_validateDepend($attribute, $depend);
1302
+ $typeValid = true;
1303
+ if ($dependType) {
1304
+ $typeValid = false;
1305
+ foreach ($dependType->asArray() as $condition=>$value) {
1306
+ if ($attribute->getType() == $condition) {
1307
+ $typeValid = true;
1308
+ break;
1309
+ }
1310
+ }
1311
+ }
1312
+ if ($valid && $typeValid) {
1313
+ $replace = $entity->getPlaceholders();
1314
+ $attributeReplace = $attribute->getPlaceholders();
1315
+ $replace = array_merge($replace, $attributeReplace);
1316
+ $content .= $this->_filterString($sourceContent, $filetype, $replace, true);
1317
+ }
1318
+ }
1319
+ } elseif ($scope == 'siblings') {
1320
+ $relatedEntities = $entity->getRelatedEntities(
1321
+ Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_SIBLING
1322
+ );
1323
+ foreach ($relatedEntities as $related) {
1324
+ if ($this->_validateDepend($entity, $depend)) {
1325
+ $placeholders = $entity->getPlaceholders();
1326
+ $replaceSibling = $related->getPlaceholdersAsSibling();
1327
+ $replace = array_merge($placeholders, $replaceSibling);
1328
+ $content .= $this->_filterString($sourceContent, $filetype, $replace, true);
1329
+ }
1330
+ }
1331
+ } elseif ($scope == 'siblings_not_tree') {
1332
+ $relatedEntities = $entity->getRelatedEntities(
1333
+ Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_SIBLING
1334
+ );
1335
+ foreach ($relatedEntities as $related) {
1336
+ if ($related->getNotIsTree()) {
1337
+ $placeholders = $entity->getPlaceholders();
1338
+ $replaceSibling = $related->getPlaceholdersAsSibling();
1339
+ $replace = array_merge($placeholders, $replaceSibling);
1340
+ $content .= $this->_filterString($sourceContent, $filetype, $replace, true);
1341
+ }
1342
+ }
1343
+ } elseif ($scope == 'siblings_tree') {
1344
+ $relatedEntities = $entity->getRelatedEntities(
1345
+ Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_SIBLING
1346
+ );
1347
+ foreach ($relatedEntities as $related) {
1348
+ if ($related->getIsTree()) {
1349
+ $placeholders = $entity->getPlaceholders();
1350
+ $replaceSibling = $related->getPlaceholdersAsSibling();
1351
+ $replace = array_merge($placeholders, $replaceSibling);
1352
+ $content .= $this->_filterString($sourceContent, $filetype, $replace, true);
1353
+ }
1354
+ }
1355
+ } elseif ($scope == 'parents') {
1356
+ $relatedEntities = $entity->getRelatedEntities(
1357
+ Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_CHILD
1358
+ );
1359
+ foreach ($relatedEntities as $related) {
1360
+ $placeholders = $entity->getPlaceholders();
1361
+ $replaceSibling = $related->getPlaceholdersAsSibling();
1362
+ $replace = array_merge($placeholders, $replaceSibling);
1363
+ $content .= $this->_filterString($sourceContent, $filetype, $replace, true);
1364
+ }
1365
+ } elseif ($scope == 'children') {
1366
+ $relatedEntities = $entity->getRelatedEntities(
1367
+ Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_PARENT
1368
+ );
1369
+ foreach ($relatedEntities as $related) {
1370
+ $placeholders = $entity->getPlaceholders();
1371
+ $replaceSibling = $related->getPlaceholdersAsSibling();
1372
+ $replace = array_merge($placeholders, $replaceSibling);
1373
+ $content .= $this->_filterString($sourceContent, $filetype, $replace, true);
1374
+ }
1375
+ } elseif ($depend) {
1376
+ if ($this->_validateDepend($entity, $depend)) {
1377
+ $content .= $this->_filterString($sourceContent, $filetype, $entity->getPlaceholders(), true);
1378
+ }
1379
+ } else {
1380
+ $content .= $this->_filterString($sourceContent, $filetype, $entity->getPlaceholders(), true);
1381
+ }
1382
+ $this->_addFile($destinationFile, $content);
1383
+ }
1384
+ }
1385
+ return $this;
1386
+ }
1387
+
1388
+ /**
1389
+ * generate files for sibling relations
1390
+ *
1391
+ * @access protected
1392
+ * @param $config
1393
+ * @return $this
1394
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1395
+ */
1396
+ protected function _buildSiblingFile($config)
1397
+ {
1398
+ foreach ($this->getRelations(Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_SIBLING) as $relation) {
1399
+ $entities = $relation->getEntities();
1400
+ foreach ($entities as $index=>$entity) {
1401
+ $depend = $config->depend;
1402
+ if (!$this->_validateDepend($relation, $depend, $index)) {
1403
+ continue;
1404
+ }
1405
+ $placeholders = array_merge(
1406
+ $entities[$index]->getPlaceholders(),
1407
+ $entities[1 - $index]->getPlaceholdersAsSibling()
1408
+ );
1409
+ $filetype = $config->filetype;
1410
+ $sourceFolder = $this->getSourceFolder().
1411
+ $this->_filterString((string)$config->source, $filetype);
1412
+ $destinationFile = $this->_filterString(
1413
+ (string)$config->destination,
1414
+ $filetype,
1415
+ $placeholders,
1416
+ true
1417
+ );
1418
+ $content = '';
1419
+ $code = $this->_sortCodeFiles((array)$config->code);
1420
+ foreach ($code as $file) {
1421
+ $depend = $file->depend;
1422
+ if (!$this->_validateDepend($relation, $depend, $index)) {
1423
+ continue;
1424
+ }
1425
+ $sourceContent = $this->getFileContents($sourceFolder.(string)$file->name);
1426
+ $content .= $this->_filterString($sourceContent, $filetype, $placeholders, true);
1427
+ }
1428
+ $this->_addFile($destinationFile, $content);
1429
+ }
1430
+ }
1431
+ return $this;
1432
+ }
1433
+
1434
+ /**
1435
+ * create files for children relations
1436
+ *
1437
+ * @access protected
1438
+ * @param Varien_Simplexml_Element
1439
+ * @return Ultimate_ModuleCreator_Model_Module
1440
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1441
+ */
1442
+ protected function _buildChildrenFile($config)
1443
+ {
1444
+ foreach ($this->getRelations() as $relation) {
1445
+ $type = $relation->getType();
1446
+ $entities = $relation->getEntities();
1447
+ $parent = false;
1448
+ $child = false;
1449
+ if ($type == Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_PARENT) {
1450
+ $parent = $entities[0];
1451
+ $child = $entities[1];
1452
+ } elseif ($type == Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_CHILD) {
1453
+ $parent = $entities[1];
1454
+ $child = $entities[0];
1455
+ }
1456
+ if ($parent && $child) {
1457
+ $depend = $config->depend;
1458
+ if ($this->_validateDepend($relation, $depend)) {
1459
+ $placeholders = array_merge($parent->getPlaceholders(), $child->getPlaceholdersAsSibling());
1460
+ $filetype = $config->filetype;
1461
+ $sourceFolder = $this->getSourceFolder().
1462
+ $this->_filterString((string)$config->source, $filetype);
1463
+ $destinationFile = $this->_filterString(
1464
+ (string)$config->destination,
1465
+ $filetype,
1466
+ $placeholders,
1467
+ true
1468
+ );
1469
+ $content = '';
1470
+ $code = $this->_sortCodeFiles((array)$config->code);
1471
+ foreach ($code as $file) {
1472
+ $depend = $file->depend;
1473
+ if (!$this->_validateDepend($relation, $depend)) {
1474
+ continue;
1475
+ }
1476
+ $sourceContent = $this->getFileContents($sourceFolder.(string)$file->name);
1477
+ $content .= $this->_filterString($sourceContent, $filetype, $placeholders, true);
1478
+ }
1479
+ $this->_addFile($destinationFile, $content);
1480
+ }
1481
+ }
1482
+ }
1483
+ return $this;
1484
+ }
1485
+
1486
+ /**
1487
+ * build source file for an attribute
1488
+ *
1489
+ * @access public
1490
+ * @param $config
1491
+ * @return Ultimate_ModuleCreator_Model_Module
1492
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1493
+ */
1494
+ protected function _buildAttributeFile($config)
1495
+ {
1496
+ foreach ($this->getEntities() as $entity) {
1497
+ foreach ($entity->getAttributes() as $attribute) {
1498
+ $filetype = $config->filetype;
1499
+ $sourceFolder = $this->getSourceFolder().$this->_filterString((string)$config->source, $filetype);
1500
+ $placeholders = array_merge($entity->getPlaceholders(), $attribute->getPlaceholders());
1501
+ $destinationFile = $this->_filterString((string)$config->destination, $filetype, $placeholders, true);
1502
+ $content = '';
1503
+ $depend = $config->depend;
1504
+ if (!$this->_validateDepend($attribute, $depend)) {
1505
+ continue;
1506
+ }
1507
+ $code = $this->_sortCodeFiles((array)$config->code);
1508
+ foreach ($code as $file) {
1509
+ $depend = $file->depend;
1510
+ if (!$this->_validateDepend($attribute, $depend)) {
1511
+ continue;
1512
+ }
1513
+ $sourceContent = $this->getFileContents($sourceFolder.(string)$file->name);
1514
+ $content .= $this->_filterString($sourceContent, $filetype, $placeholders, true);
1515
+ }
1516
+ $this->_addFile($destinationFile, $content);
1517
+ }
1518
+ }
1519
+ return $this;
1520
+ }
1521
+
1522
+ /**
1523
+ * get sample files source folder
1524
+ *
1525
+ * @access public
1526
+ * @return string
1527
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1528
+ */
1529
+ public function getSourceFolder()
1530
+ {
1531
+ if (!isset($this->_sourceFolder)) {
1532
+ $this->_sourceFolder = Mage::getConfig()->getModuleDir('etc', 'Ultimate_ModuleCreator').DS.'source'.DS;
1533
+ }
1534
+ return $this->_sourceFolder;
1535
+ }
1536
+
1537
+ /**
1538
+ * filter placeholders
1539
+ *
1540
+ * @access protected
1541
+ * @param string $string
1542
+ * @param string $fileType
1543
+ * @param mixed (null|array()) $replaceArray
1544
+ * @param bool $mergeReplace
1545
+ * @param bool $forLicence
1546
+ * @return string
1547
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1548
+ */
1549
+ protected function _filterString(
1550
+ $string,
1551
+ $fileType,
1552
+ $replaceArray = null,
1553
+ $mergeReplace = false,
1554
+ $forLicence = false
1555
+ ) {
1556
+ $replace = $this->getPlaceholder();
1557
+ if (!$forLicence) {
1558
+ $replace['{{License}}'] = $this->getLicenseText($fileType);
1559
+ }
1560
+ if (!is_null($replaceArray)) {
1561
+ if ($mergeReplace) {
1562
+ $replace = array_merge($replace, $replaceArray);
1563
+ } else {
1564
+ $replace = $replaceArray;
1565
+ }
1566
+ }
1567
+ return str_replace(array_keys($replace), array_values($replace), $string);
1568
+ }
1569
+
1570
+ /**
1571
+ * add file to create list
1572
+ *
1573
+ * @access protected
1574
+ * @param $destinationFile
1575
+ * @param $content
1576
+ * @return $this
1577
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1578
+ */
1579
+ protected function _addFile($destinationFile, $content)
1580
+ {
1581
+ if (trim($content)) {
1582
+ $this->_files[$destinationFile] = $content;
1583
+ }
1584
+ return $this;
1585
+ }
1586
+
1587
+ /**
1588
+ * get text for licence
1589
+ *
1590
+ * @access public
1591
+ * @param string $fileType
1592
+ * @return string
1593
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1594
+ */
1595
+ public function getLicenseText($fileType)
1596
+ {
1597
+ if (!$this->getData('processed_license_'.$fileType)) {
1598
+ $eol = $this->getEol();
1599
+ $license = trim($this->getData('license'));
1600
+ if (!$license) {
1601
+ return '';
1602
+ }
1603
+ while (strpos($license, '*/') !== false) {
1604
+ $license = str_replace('*/', '', $license);
1605
+ }
1606
+ while (strpos($license, '/*') !== false) {
1607
+ $license = str_replace('/*', '', $license);
1608
+ }
1609
+ while (strpos($license, '<!--') !== false) {
1610
+ $license = str_replace('<!--', '', $license);
1611
+ }
1612
+ while (strpos($license, '-->') !== false) {
1613
+ $license = str_replace('-->', '', $license);
1614
+ }
1615
+ $lines = explode("\n", $license);
1616
+ $top = '';
1617
+ $footer = '';
1618
+ if ($fileType == 'xml') {
1619
+ $top = '<!--'.$eol;
1620
+ $footer = $eol.'-->';
1621
+ }
1622
+ $processed = $top.'/**'.$eol;
1623
+ foreach ($lines as $line) {
1624
+ $processed .= ' * '.$line.$eol;
1625
+ }
1626
+ $processed .= ' */'.$footer;
1627
+ $this->setData(
1628
+ 'processed_license_'.$fileType,
1629
+ $this->_filterString($processed, $fileType, array(), true, true)
1630
+ );
1631
+ }
1632
+ return $this->getData('processed_license_'.$fileType);
1633
+ }
1634
+
1635
+ /**
1636
+ * get all placeholders
1637
+ *
1638
+ * @access public
1639
+ * @param null $param
1640
+ * @return array|null|string
1641
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1642
+ */
1643
+ public function getPlaceholder($param = null)
1644
+ {
1645
+ if (is_null($this->_placeholders)) {
1646
+ $this->_placeholders = array(
1647
+ '{{DS}}' => DS,
1648
+ '{{namespace}}' => $this->getNamespace(true),
1649
+ '{{sort_order}}' => (int)$this->getSortOrder(),
1650
+ '{{module}}' => strtolower($this->getModuleName()),
1651
+ '{{Namespace}}' => $this->getNamespace(),
1652
+ '{{Module}}' => $this->getModuleName(),
1653
+ '{{NAMESPACE}}' => strtoupper($this->getNamespace()),
1654
+ '{{MODULE}}' => strtoupper($this->getModuleName()),
1655
+ '{{qwertyuiop}}' => $this->getQwertyuiop(),
1656
+ '{{qwertyuiopp}}' => $this->getQwertyuiopp(),
1657
+ '{{Y}}' => date('Y'),
1658
+ '{{entity_default_config}}' => $this->getEntityDefaultConfig(),
1659
+ '{{module_menu}}' => $this->getMenuText(),
1660
+ '{{codepool}}' => $this->getCodepool(),
1661
+ '{{version}}' => $this->getVersion(),
1662
+ '{{menuItemsXml}}' => $this->getMenuItemsXml(),
1663
+ '{{menuAcl}}' => $this->getMenuAcl(),
1664
+ '{{ModuleFolder}}' => ucfirst(strtolower($this->getModuleName())),
1665
+ '{{ResourceSetup}}' => $this->getResourceSetupModel(),
1666
+ '{{depends}}' => $this->getDepends(),
1667
+ '{{productViewLayout}}' => $this->getProductViewLayout(),
1668
+ '{{categoryViewLayout}}' => $this->getCategoryViewLayout(),
1669
+ '{{defaultLayoutHandle}}' => $this->getFrontendDefaultLayoutHandle(),
1670
+ '{{categoryMenuEvent}}' => $this->getCategoryMenuEvent(),
1671
+ '{{customerCommentLinks}}' => $this->getCustomerCommentLinks(),
1672
+ '{{frontKey}}' => $this->getFrontKey(),
1673
+ '{{SystemTabName}}' => $this->getSystemTabName(),
1674
+ '{{systemTabPosition}}' => $this->getSystemTabPosition(),
1675
+ '{{RestResourceGroupsChildren}}' => $this->getRestResourceGroupsChildren(),
1676
+ '{{RestResources}}' => $this->getRestResources(),
1677
+ '{{eavOptionsDefaults}}' => $this->getEavOptionsDefaults()
1678
+ );
1679
+ }
1680
+ if (is_null($param)) {
1681
+ return $this->_placeholders;
1682
+ }
1683
+ if (isset($this->_placeholders[$param])) {
1684
+ return $this->_placeholders[$param];
1685
+ }
1686
+ return '';
1687
+ }
1688
+
1689
+ /**
1690
+ * get config.xml default section
1691
+ *
1692
+ * @access public
1693
+ * @return string
1694
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1695
+ */
1696
+ public function getEntityDefaultConfig()
1697
+ {
1698
+ $eol = $this->getEol();
1699
+ $text = '';
1700
+ if ($this->getCreateFrontend()) {
1701
+ $text = $eol.$this->getPadding().'<default>'.$eol;
1702
+ $text.= $this->getPadding(2).'<'.strtolower($this->getModuleName()).'>'.$eol;
1703
+ foreach ($this->getEntities() as $entity) {
1704
+ $text .= $this->getPadding(3).$entity->getDefaultConfig();
1705
+ }
1706
+ $text.= $this->getPadding(2).'</'.strtolower($this->getModuleName()).'>'.$eol;
1707
+ $text.= $this->getPadding().'</default>';
1708
+ }
1709
+ return $text;
1710
+ }
1711
+
1712
+ /**
1713
+ * check if module related to catalog
1714
+ *
1715
+ * @access public
1716
+ * @return bool
1717
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1718
+ */
1719
+ public function getHasCatalogRelation()
1720
+ {
1721
+ return $this->getLinkProduct() || $this->getLinkCategory();
1722
+ }
1723
+
1724
+ /**
1725
+ * get menu for entities
1726
+ *
1727
+ * @access public
1728
+ * @param $padding
1729
+ * @return string
1730
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1731
+ */
1732
+ public function getEntityMenu($padding)
1733
+ {
1734
+ $text = '';
1735
+ foreach ($this->getEntities() as $entity) {
1736
+ $text .= $entity->getMenu($padding);
1737
+ }
1738
+ return $text;
1739
+ }
1740
+
1741
+ /**
1742
+ * get menu ACL for entities
1743
+ *
1744
+ * @access public
1745
+ * @param $padding
1746
+ * @return string
1747
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1748
+ */
1749
+ public function getEntityMenuAcl($padding)
1750
+ {
1751
+ $text = '';
1752
+ foreach ($this->getEntities() as $entity) {
1753
+ $text .= $entity->getMenuAcl($padding);
1754
+ }
1755
+ return $text;
1756
+ }
1757
+
1758
+ /**
1759
+ * sort source code files
1760
+ *
1761
+ * @access protected
1762
+ * @param $files
1763
+ * @param string $sortField
1764
+ * @return array
1765
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1766
+ */
1767
+ protected function _sortCodeFiles($files, $sortField = 'sort_order')
1768
+ {
1769
+ $sorted = array();
1770
+ foreach ($files as $values) {
1771
+ $sorted[(int)$values->$sortField][] = $values;
1772
+ }
1773
+ ksort($sorted);
1774
+ $return = array();
1775
+ foreach ($sorted as $values) {
1776
+ foreach ($values as $file) {
1777
+ $return[] = $file;
1778
+ }
1779
+ }
1780
+ return $return;
1781
+ }
1782
+
1783
+ /**
1784
+ * get module name in lower case
1785
+ *
1786
+ * @access public
1787
+ * @return string
1788
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1789
+ */
1790
+ public function getLowerModuleName()
1791
+ {
1792
+ return strtolower($this->getModuleName());
1793
+ }
1794
+
1795
+ /**
1796
+ * get menu items xml
1797
+ *
1798
+ * @access public
1799
+ * @return string
1800
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1801
+ */
1802
+ public function getMenuItemsXml()
1803
+ {
1804
+ $xml = '';
1805
+ $parts = array();
1806
+ $padding = 2;
1807
+ $namespace = $this->getNamespace(true);
1808
+ $eol = $this->getEol();
1809
+ if ($this->getMenuParent()) {
1810
+ $parts = explode('/', $this->getMenuParent());
1811
+ }
1812
+ foreach ($parts as $part) {
1813
+ $xml .= $this->getPadding($padding++).'<'.$part.'>'.$eol;
1814
+ $xml .= $this->getPadding($padding++).'<children>'.$eol;
1815
+ }
1816
+ $xml .= $this->getPadding($padding++).'<'.$namespace.'_'.$this->getLowerModuleName().
1817
+ ' translate="title" module="'.$namespace.'_'.$this->getLowerModuleName().'">'.$eol;
1818
+ $xml .= $this->getPadding($padding).'<title>'.$this->getMenuText().'</title>'.$eol;
1819
+ $xml .= $this->getPadding($padding).'<sort_order>'.$this->getSortOrder().'</sort_order>'.$eol;
1820
+ $xml .= $this->getPadding($padding++).'<children>'.$eol;
1821
+ $xml .= $this->getEntityMenu($padding);
1822
+ $xml .= $this->getPadding(--$padding).'</children>'.$eol;
1823
+ $xml .= $this->getPadding(--$padding).'</'.$namespace.'_'.$this->getLowerModuleName().'>';
1824
+
1825
+ $parts = array_reverse($parts);
1826
+ foreach ($parts as $part) {
1827
+ $xml .= $this->getPadding(--$padding).'</children>'.$eol;
1828
+ $xml .= $this->getPadding(--$padding).'</'.$part.'>'.$eol;
1829
+ }
1830
+ return $xml;
1831
+ }
1832
+
1833
+ /**
1834
+ * get menu ACL
1835
+ *
1836
+ * @access public
1837
+ * @return string
1838
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1839
+ */
1840
+ public function getMenuAcl()
1841
+ {
1842
+ $xml = '';
1843
+ $parts = array();
1844
+ $padding = 5;
1845
+ $eol = $this->getEol();
1846
+ $namespace = $this->getNamespace(true);
1847
+ if ($this->getMenuParent()) {
1848
+ $parts = explode('/', $this->getMenuParent());
1849
+ }
1850
+ foreach ($parts as $part) {
1851
+ $xml .= $this->getPadding($padding++).'<'.$part.'>'.$eol;
1852
+ $xml .= $this->getPadding($padding++).'<children>'.$eol;
1853
+ }
1854
+ $xml .= $this->getPadding($padding++).'<'.$namespace.'_'.
1855
+ $this->getLowerModuleName().' translate="title" module="'.
1856
+ $namespace.'_'.$this->getLowerModuleName().'">'.$eol;
1857
+ $xml .= $this->getPadding($padding).'<title>'.$this->getMenuText().'</title>'.$eol;
1858
+ $xml .= $this->getPadding($padding++).'<children>'.$eol;
1859
+ $xml .= $this->getEntityMenuAcl($padding);
1860
+ $xml .= $this->getPadding(--$padding).'</children>'.$eol;
1861
+ $xml .= $this->getPadding(--$padding).'</'.$namespace.'_'.$this->getLowerModuleName().'>';
1862
+
1863
+ $parts = array_reverse($parts);
1864
+ foreach ($parts as $part) {
1865
+ $xml .= $this->getPadding(--$padding).'</children>'.$eol;
1866
+ $xml .= $this->getPadding(--$padding).'</'.$part.'>'.$eol;
1867
+ }
1868
+ return $xml;
1869
+ }
1870
+
1871
+ /**
1872
+ * get resource setup base class
1873
+ *
1874
+ * @access public
1875
+ * @return string
1876
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1877
+ */
1878
+ public function getResourceSetupModel()
1879
+ {
1880
+ if ($this->getHasCatalogRelation() || $this->getHasEav() || $this->getHasCatalogAttribute()) {
1881
+ return 'Mage_Catalog_Model_Resource_Setup';
1882
+ }
1883
+ return 'Mage_Core_Model_Resource_Setup';
1884
+ }
1885
+
1886
+ /**
1887
+ * sort the translation file
1888
+ *
1889
+ * @access protected
1890
+ * @param string $content
1891
+ * @return string
1892
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1893
+ */
1894
+ protected function _sortTranslationFile($content)
1895
+ {
1896
+ $lines = explode($this->getEol(), $content);
1897
+ $distinct = array();
1898
+ foreach ($lines as $line) {
1899
+ if (trim($line)) {
1900
+ $distinct[$line] = 1;
1901
+ }
1902
+ }
1903
+ //remove blank line
1904
+ if (isset($distinct['"",""'])) {
1905
+ unset($distinct['"",""']);
1906
+ }
1907
+ ksort($distinct);
1908
+ $content = implode($this->getEol(), array_keys($distinct));
1909
+ return $content;
1910
+ }
1911
+
1912
+ /**
1913
+ * this does nothing
1914
+ * don't look through the code - go away
1915
+ * I said it does nothing
1916
+ *
1917
+ * @access public
1918
+ * @return string
1919
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1920
+ */
1921
+ public function getQwertyuiop()
1922
+ {
1923
+ return $this->getHelper()->getQwertyuiop();
1924
+ }
1925
+
1926
+ /**
1927
+ * this also does nothing
1928
+ * don't look here either
1929
+ *
1930
+ * @access public
1931
+ * @return string
1932
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1933
+ */
1934
+ public function getQwertyuiopp()
1935
+ {
1936
+ return $this->getHelper()->getQwertyuiopp();
1937
+ }
1938
+
1939
+ /**
1940
+ * check module dependency
1941
+ *
1942
+ * @access public
1943
+ * @return array
1944
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1945
+ */
1946
+ public function getDepends()
1947
+ {
1948
+ if (!$this->hasData('_depends')) {
1949
+ $dependency = array('<Mage_Core />'=>1);
1950
+ if ($this->getLinkCore() || $this->getHasEav()) {
1951
+ $dependency['<Mage_Catalog />'] = 1;
1952
+ }
1953
+ $eol = $this->getEol();
1954
+ $padding = $this->getPadding(4);
1955
+ $depends = '';
1956
+ foreach ($dependency as $key=>$value) {
1957
+ $depends = $padding.$key.$eol;
1958
+ }
1959
+ $this->setData('_depends', $depends);
1960
+ }
1961
+ return $this->getData('_depends');
1962
+ }
1963
+
1964
+ /**
1965
+ * get layout for product view page
1966
+ *
1967
+ * @access public
1968
+ * @return string
1969
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
1970
+ */
1971
+ public function getProductViewLayout()
1972
+ {
1973
+ $content = '';
1974
+ $padding = $this->getPadding(3);
1975
+ $eol = $this->getEol();
1976
+ $tab = $this->getPadding();
1977
+ $ns = $this->getNamespace(true);
1978
+ $module = $this->getLowerModuleName();
1979
+ foreach ($this->getEntities() as $entity) {
1980
+ $name = strtolower($entity->getNameSingular());
1981
+ $names = strtolower($entity->getNamePlural());
1982
+ $label = $entity->getLabelPlural();
1983
+ if ($entity->getShowOnProduct()) {
1984
+ $content .= $padding.
1985
+ '<block type="'.$ns.'_'.$module.'/catalog_product_list_'.
1986
+ $name.'" name="product.info.'.$names.'" as="product_'.$names.
1987
+ '" template="'.$ns.'_'.$module.'/catalog/product/list/'.$name.'.phtml">'.$eol;
1988
+ $content .= $padding.$tab.
1989
+ '<action method="addToParentGroup"><group>detailed_info</group></action>'.$eol;
1990
+ $content .= $padding.$tab.
1991
+ '<action method="setTitle" translate="value" module="'.
1992
+ $ns.'_'.$module.'"><value>'.$label.'</value></action>'.$eol;
1993
+ $content .= $padding.'</block>'.$eol;
1994
+ }
1995
+ }
1996
+ return $content;
1997
+ }
1998
+ /**
1999
+ * get layout for category view page
2000
+ *
2001
+ * @access public
2002
+ * @return string
2003
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2004
+ */
2005
+ public function getCategoryViewLayout()
2006
+ {
2007
+ $content = '';
2008
+ $padding = $this->getPadding(3);
2009
+ $eol = $this->getEol();
2010
+ $ns = $this->getNamespace(true);
2011
+ $module = $this->getLowerModuleName();
2012
+ foreach ($this->getEntities() as $entity) {
2013
+ $name = $entity->getNameSingular(true);
2014
+ $names = $entity->getNamePlural(true);
2015
+ if ($entity->getShowOnCategory()) {
2016
+ $content .= $padding.'<block type="'.
2017
+ $ns.'_'.$module.'/catalog_category_list_'.
2018
+ $name.'" name="category.info.'.$names.
2019
+ '" as="category_'.$names.'" template="'.$ns.'_'.$module.
2020
+ '/catalog/category/list/'.$name.'.phtml" after="-" />'.$eol;
2021
+ }
2022
+ }
2023
+ return $content;
2024
+ }
2025
+
2026
+ /**
2027
+ * get default layout handle
2028
+ *
2029
+ * @access public
2030
+ * @return string
2031
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2032
+ */
2033
+ public function getFrontendDefaultLayoutHandle()
2034
+ {
2035
+ $padding = $this->getPadding(1);
2036
+ $tab = $this->getPadding();
2037
+ $eol = $this->getEol();
2038
+ /** @var Ultimate_ModuleCreator_Model_Entity[] $top */
2039
+ $top = array();
2040
+ /** @var Ultimate_ModuleCreator_Model_Entity[] $footer */
2041
+ $footer = array();
2042
+ $content = $eol.$padding;
2043
+ $namespace = $this->getNamespace(true);
2044
+ $tree = false;
2045
+ if ($this->getCreateFrontend()) {
2046
+ foreach ($this->getEntities() as $entity) {
2047
+ if ($entity->getCreateList()) {
2048
+ if ($entity->getListMenu() == Ultimate_ModuleCreator_Model_Source_Entity_Menu::TOP_LINKS) {
2049
+ $top[] = $entity;
2050
+ } elseif (
2051
+ $entity->getListMenu() == Ultimate_ModuleCreator_Model_Source_Entity_Menu::FOOTER_LINKS
2052
+ ) {
2053
+ $footer[] = $entity;
2054
+ }
2055
+ if ($entity->getIsTree()) {
2056
+ $tree = true;
2057
+ }
2058
+ }
2059
+ }
2060
+ }
2061
+ if (count($top) > 0 || count($footer) > 0 || $tree) {
2062
+ $content .= '<default>'.$eol;
2063
+ if ($tree) {
2064
+ $content .= $padding.'<reference name="head">'.$eol;
2065
+ $content .= $padding.$tab.'<action method="addCss"><js>css/'.
2066
+ $this->getNamespace(true).'_'.$this->getLowerModuleName().
2067
+ '/tree.css</js></action>'.$eol;
2068
+ $content .= $padding.'</reference>'.$eol;
2069
+ }
2070
+ if (count($top) > 0) {
2071
+ $content .= $padding.$tab.'<reference name="top.links">'.$eol;
2072
+ $position = 120;
2073
+ foreach ($top as $entity) {
2074
+ $content .= $padding.$tab.$tab.'<action method="addLink" translate="label title" module="'.
2075
+ $namespace.'_'.$this->getLowerModuleName().'">'.$eol;
2076
+ $content .= $padding.$tab.$tab.$tab.'<label>'.$entity->getLabelPlural().'</label>'.$eol;
2077
+ $content .= $padding.$tab.$tab.$tab.'<url helper="'.$namespace.'_'.
2078
+ $this->getLowerModuleName().'/'.strtolower($entity->getNameSingular()).'/get'.
2079
+ ucfirst(strtolower($entity->getNamePlural())).'Url" />'.$eol;
2080
+ $content .= $padding.$tab.$tab.$tab.'<title>'.$entity->getLabelPlural().'</title>'.$eol;
2081
+ $content .= $padding.$tab.$tab.$tab.'<prepare />'.$eol;
2082
+ $content .= $padding.$tab.$tab.$tab.'<urlParams/>'.$eol;
2083
+ $content .= $padding.$tab.$tab.$tab.'<position>'.$position.'</position>'.$eol;
2084
+ $content .= $padding.$tab.$tab.'</action>'.$eol;
2085
+ $position += 10;
2086
+ }
2087
+ $content .= $padding.$tab.'</reference>'.$eol;
2088
+ }
2089
+ if (count($footer) > 0) {
2090
+ $content .= $padding.$tab.'<reference name="footer_links">'.$eol;
2091
+ $position = 120;
2092
+ foreach ($footer as $entity) {
2093
+ $content .= $padding.$tab.$tab.'<action method="addLink" translate="label title" module="'.
2094
+ $namespace.'_'.$this->getLowerModuleName().'">'.$eol;
2095
+ $content .= $padding.$tab.$tab.$tab.'<label>'.$entity->getLabelPlural().'</label>'.$eol;
2096
+ $content .= $padding.$tab.$tab.$tab.
2097
+ '<url helper="'.$namespace.'_'.$this->getLowerModuleName().'/'.
2098
+ strtolower($entity->getNameSingular()).'/get'.
2099
+ ucfirst(strtolower($entity->getNamePlural())).'Url" />'.$eol;
2100
+ $content .= $padding.$tab.$tab.$tab.'<title>'.$entity->getLabelPlural().'</title>'.$eol;
2101
+ $content .= $padding.$tab.$tab.$tab.'<prepare />'.$eol;
2102
+ $content .= $padding.$tab.$tab.$tab.'<urlParams/>'.$eol;
2103
+ $content .= $padding.$tab.$tab.$tab.'<position>'.$position.'</position>'.$eol;
2104
+ $content .= $padding.$tab.$tab.'</action>'.$eol;
2105
+ $position += 10;
2106
+ }
2107
+ $content .= $padding.$tab.'</reference>'.$eol;
2108
+ }
2109
+ $content .= $padding.'</default>';
2110
+ }
2111
+ return $content;
2112
+ }
2113
+
2114
+ /**
2115
+ * get xml for category menu event
2116
+ *
2117
+ * @access public
2118
+ * @return string
2119
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2120
+ */
2121
+ public function getCategoryMenuEvent()
2122
+ {
2123
+ if ($this->getShowInCategoryMenu()) {
2124
+ $namespace = $this->getNamespace(true);
2125
+
2126
+ $eol = $this->getEol();
2127
+ $padding = $this->getPadding(2);
2128
+ $tab = $this->getPadding();
2129
+ $content = $eol;
2130
+ $content .= $padding.'<events>'.$eol;
2131
+ $content .= $padding.$tab.'<page_block_html_topmenu_gethtml_before>'.$eol;
2132
+ $content .= $padding.$tab.$tab.'<observers>'.$eol;
2133
+ $content .= $padding.$tab.$tab.$tab.'<'.$namespace.'_'.$this->getLowerModuleName().'>'.$eol;
2134
+ $content .= $padding.$tab.$tab.$tab.$tab.
2135
+ '<class>'.$namespace.'_'.$this->getLowerModuleName().'/observer</class>'.$eol;
2136
+ $content .= $padding.$tab.$tab.$tab.$tab.'<method>addItemsToTopmenuItems</method>'.$eol;
2137
+ $content .= $padding.$tab.$tab.$tab.'</'.$namespace.'_'.$this->getLowerModuleName().'>'.$eol;
2138
+ $content .= $padding.$tab.$tab.'</observers>'.$eol;
2139
+ $content .= $padding.$tab.'</page_block_html_topmenu_gethtml_before>'.$eol;
2140
+ $content .= $padding.'</events>'.$eol;
2141
+ return $content;
2142
+ }
2143
+ return '';
2144
+ }
2145
+
2146
+ /**
2147
+ * get customer comment links
2148
+ *
2149
+ * @access public
2150
+ * @return string
2151
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2152
+ */
2153
+ public function getCustomerCommentLinks()
2154
+ {
2155
+ $namespace = $this->getNamespace(true);
2156
+ $eol = $this->getEol();
2157
+ $padding = $this->getPadding(3);
2158
+ $content = $eol;
2159
+ $module = $this->getLowerModuleName();
2160
+ foreach ($this->getEntities() as $entity) {
2161
+ if ($entity->getAllowComment()) {
2162
+ $entityName = $entity->getNameSingular(true);
2163
+ $label = $entity->getLabelPlural();
2164
+ $content .= $padding . '<action method="addLink" translate="label" module="'.
2165
+ $namespace.'_'.$module.'"><name>'.$entityName.'_comments</name><path>'.
2166
+ $namespace.'_'.$module.'/'.$entityName.'_customer_comment</path><label>'.
2167
+ $label.' Comments</label></action>'.$eol;
2168
+ }
2169
+ }
2170
+ return $content;
2171
+ }
2172
+
2173
+ /**
2174
+ * get the module namespace
2175
+ *
2176
+ * @access public
2177
+ * @param bool $lower
2178
+ * @return mixed|string
2179
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2180
+ */
2181
+ public function getNamespace($lower = false)
2182
+ {
2183
+ $namespace = $this->getData('namespace');
2184
+ if ($lower) {
2185
+ $namespace = strtolower($namespace);
2186
+ }
2187
+ return $namespace;
2188
+ }
2189
+
2190
+ /**
2191
+ * get front key
2192
+ *
2193
+ * @access public
2194
+ * @return mixed
2195
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2196
+ */
2197
+ public function getFrontKey()
2198
+ {
2199
+ if (!$this->getCreateFrontend()) {
2200
+ return $this->getData('front_key');
2201
+ }
2202
+ if (!$this->getData('front_key')) {
2203
+ $frontKey = $this->getNamespace(true).'_'.$this->getLowerModuleName();
2204
+ $this->setData('front_key', $frontKey);
2205
+ }
2206
+ return $this->getData('front_key');
2207
+ }
2208
+
2209
+ /**
2210
+ * system configuration tab name
2211
+ *
2212
+ * @access public
2213
+ * @return string
2214
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2215
+ */
2216
+ public function getSystemTabName()
2217
+ {
2218
+ if (!$this->getData('system_tab')) {
2219
+ $this->setData('system_tab', $this->getNamespace());
2220
+ }
2221
+ return $this->getData('system_tab');
2222
+ }
2223
+
2224
+ /**
2225
+ * system configuration tab position
2226
+ *
2227
+ * @access public
2228
+ * @return string
2229
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2230
+ */
2231
+ public function getSystemTabPosition()
2232
+ {
2233
+ return (int)$this->getData('system_tab_position');
2234
+ }
2235
+
2236
+ /**
2237
+ * get xml for api2.xml resource groups children
2238
+ * @access public
2239
+ * @return string
2240
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2241
+ */
2242
+ public function getRestResourceGroupsChildren()
2243
+ {
2244
+ $content = '';
2245
+ foreach ($this->getEntities() as $entity) {
2246
+ $content .= $entity->getRestResourceGroup(5);
2247
+ }
2248
+ return $content;
2249
+ }
2250
+
2251
+ /**
2252
+ * get xml for api2.xml resources
2253
+ *
2254
+ * @access public
2255
+ * @return string
2256
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2257
+ */
2258
+ public function getRestResources()
2259
+ {
2260
+ $content = '';
2261
+ foreach ($this->getEntities() as $entity) {
2262
+ $content .= $entity->getRestResource(3);
2263
+ }
2264
+ return $content;
2265
+ }
2266
+
2267
+ /**
2268
+ * get eav default values
2269
+ *
2270
+ * @access public
2271
+ * @return string
2272
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2273
+ */
2274
+ public function getEavOptionsDefaults()
2275
+ {
2276
+ $content = '';
2277
+ foreach ($this->getEntities() as $entity) {
2278
+ if ($entity->getIsEav()) {
2279
+ foreach ($entity->getAttributes() as $attribute) {
2280
+ $content .= $attribute->getDefaultValueSetup();
2281
+ }
2282
+ }
2283
+ }
2284
+ return $content;
2285
+ }
2286
+
2287
+ /**
2288
+ * check if there are sibling relations
2289
+ *
2290
+ * @access public
2291
+ * @return bool
2292
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2293
+ */
2294
+ public function getHasRelationColumnRenderer()
2295
+ {
2296
+ if (count($this->getRelations(Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_SIBLING)) > 0) {
2297
+ return true;
2298
+ }
2299
+ foreach ($this->getEntities() as $_entity) {
2300
+ if ($_entity->getLinkCore()) {
2301
+ return true;
2302
+ }
2303
+ }
2304
+ return false;
2305
+ }
2306
+
2307
+ /**
2308
+ * check if there are parent-child relations
2309
+ *
2310
+ * @access public
2311
+ * @return bool
2312
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
2313
+ */
2314
+ public function getHasParentRelation()
2315
+ {
2316
+ $parentRelations = $this->getRelations(Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_PARENT);
2317
+ if (count($parentRelations)) {
2318
+ return true;
2319
+ }
2320
+ $childRelations = $this->getRelations(Ultimate_ModuleCreator_Model_Relation::RELATION_TYPE_CHILD);
2321
+ if (count($childRelations)) {
2322
+ return true;
2323
+ }
2324
+ return false;
2325
+ }
2326
+ }
app/code/community/Ultimate/ModuleCreator/Model/Module/Collection.php CHANGED
@@ -1,96 +1,102 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
- */
18
- /**
19
- * module collection
20
- *
21
- * @category Ultimate
22
- * @package Ultimate_ModuleCreator
23
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
- */
25
- class Ultimate_ModuleCreator_Model_Module_Collection
26
- extends Varien_Data_Collection_Filesystem {
27
- /**
28
- * Files and folders regexsp
29
- * @var string
30
- */
31
- protected $_allowedDirsMask = '/^[a-z0-9\.\-]+$/i';
32
- protected $_allowedFilesMask= '/^[a-z0-9\.\-\_]+\.(xml|ser)$/i';
33
- protected $_disallowedFilesMask = '/^package\.xml$/i';
34
-
35
- /**
36
- * Base dir where packages are located
37
- *
38
- * @var string
39
- */
40
- protected $_baseDir = '';
41
-
42
- /**
43
- * Set base dir
44
- * @access public
45
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
46
- */
47
- public function __construct() {
48
- $this->_baseDir = Mage::getBaseDir('var') . DS . 'modulecreator'.DS.'package';
49
- $io = new Varien_Io_File();
50
- $io->setAllowCreateFolders(true);
51
- $io->createDestinationDir($this->_baseDir);
52
- $this->addTargetDir($this->_baseDir);
53
- }
54
-
55
- /**
56
- * Row generator
57
- * @access public
58
- * @param string $filename
59
- * @return array
60
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
61
- */
62
- protected function _generateRow($filename) {
63
- $row = parent::_generateRow($filename);
64
- $row['package'] = preg_replace('/\.(xml|ser)$/', '', str_replace($this->_baseDir . DS, '', $filename));
65
- $row['filename_id'] = $row['package'];
66
- $row['safe_id'] = strtr(base64_encode($row['package']), '+/=', '-_,');
67
- $folder = explode(DS, $row['package']);
68
- $row['folder'] = DS;
69
- array_pop($folder);
70
- if (!empty($folder)) {
71
- $row['folder'] = implode(DS, $folder) . DS;
72
- }
73
- return $row;
74
- }
75
-
76
- /**
77
- * Get all folders as options array
78
- * @access public
79
- * @return array
80
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
81
- */
82
- public function collectFolders() {
83
- $collectFiles = $this->_collectFiles;
84
- $collectDirs = $this->_collectDirs;
85
- $this->setCollectFiles(false)->setCollectDirs(true);
86
-
87
- $this->_collectRecursive($this->_baseDir);
88
- $result = array(DS => DS);
89
- foreach ($this->_collectedDirs as $dir) {
90
- $dir = str_replace($this->_baseDir . DS, '', $dir) . DS;
91
- $result[$dir] = $dir;
92
- }
93
- $this->setCollectFiles($collectFiles)->setCollectDirs($collectDirs);
94
- return $result;
95
- }
96
- }
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
+ */
18
+ /**
19
+ * module collection
20
+ *
21
+ * @category Ultimate
22
+ * @package Ultimate_ModuleCreator
23
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
+ */
25
+ class Ultimate_ModuleCreator_Model_Module_Collection extends Varien_Data_Collection_Filesystem
26
+ {
27
+ /**
28
+ * Files and folders regexsp
29
+ * @var string
30
+ */
31
+ protected $_allowedDirsMask = '/^[a-z0-9\.\-]+$/i';
32
+ protected $_allowedFilesMask = '/^[a-z0-9\.\-\_]+\.(xml)$/i';
33
+ protected $_disallowedFilesMask = '/^package\.xml$/i';
34
+
35
+ /**
36
+ * Base dir where packages are located
37
+ *
38
+ * @var string
39
+ */
40
+ protected $_baseDir = '';
41
+
42
+ /**
43
+ * Set base dir
44
+ *
45
+ * @access public
46
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
47
+ */
48
+ public function __construct()
49
+ {
50
+ $this->_baseDir = Mage::getBaseDir('var') . DS . 'modulecreator'.DS.'package';
51
+ $io = new Varien_Io_File();
52
+ $io->setAllowCreateFolders(true);
53
+ $io->createDestinationDir($this->_baseDir);
54
+ $this->addTargetDir($this->_baseDir);
55
+ }
56
+
57
+ /**
58
+ * Row generator
59
+ *
60
+ * @access public
61
+ * @param string $filename
62
+ * @return array
63
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
64
+ */
65
+ protected function _generateRow($filename)
66
+ {
67
+ $row = parent::_generateRow($filename);
68
+ $row['package'] = preg_replace('/\.(xml)$/', '', str_replace($this->_baseDir . DS, '', $filename));
69
+ $row['filename_id'] = $row['package'];
70
+ $row['safe_id'] = strtr(base64_encode($row['package']), '+/=', '-_,');
71
+ $folder = explode(DS, $row['package']);
72
+ $row['folder'] = DS;
73
+ array_pop($folder);
74
+ if (!empty($folder)) {
75
+ $row['folder'] = implode(DS, $folder) . DS;
76
+ }
77
+ return $row;
78
+ }
79
+
80
+ /**
81
+ * Get all folders as options array
82
+ *
83
+ * @access public
84
+ * @return array
85
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
86
+ */
87
+ public function collectFolders()
88
+ {
89
+ $collectFiles = $this->_collectFiles;
90
+ $collectDirs = $this->_collectDirs;
91
+ $this->setCollectFiles(false)->setCollectDirs(true);
92
+
93
+ $this->_collectRecursive($this->_baseDir);
94
+ $result = array(DS => DS);
95
+ foreach ($this->_collectedDirs as $dir) {
96
+ $dir = str_replace($this->_baseDir . DS, '', $dir) . DS;
97
+ $result[$dir] = $dir;
98
+ }
99
+ $this->setCollectFiles($collectFiles)->setCollectDirs($collectDirs);
100
+ return $result;
101
+ }
102
+ }
app/code/community/Ultimate/ModuleCreator/Model/Relation.php CHANGED
@@ -1,211 +1,253 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
- */
18
- class Ultimate_ModuleCreator_Model_Relation extends Ultimate_ModuleCreator_Model_Abstract{
19
- /**
20
- * relation type constants
21
- */
22
- const RELATION_TYPE_NONE = 'none';
23
- const RELATION_TYPE_CHILD = 'child';
24
- const RELATION_TYPE_PARENT = 'parent';
25
- const RELATION_TYPE_SIBLING = 'sibling';
26
- /**
27
- * @var Ultimate_ModuleCreator_Model_Entity
28
- */
29
- protected $_entity1;
30
- /**
31
- * @var Ultimate_ModuleCreator_Model_Entity
32
- */
33
- protected $_entity2;
34
- /**
35
- * relation type
36
- * @var string
37
- */
38
- protected $_type;
39
- /**
40
- * set entities in relation
41
- * @access public
42
- * @param Ultimate_ModuleCreator_Model_Entity $entity1
43
- * @param Ultimate_ModuleCreator_Model_Entity $entity2
44
- * @param int $type
45
- * @return Ultimate_ModuleCreator_Model_Relation
46
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
47
- */
48
- public function setEntities(Ultimate_ModuleCreator_Model_Entity $entity1, Ultimate_ModuleCreator_Model_Entity $entity2, $type){
49
- $this->_entity1 = $entity1;
50
- $this->_entity2 = $entity2;
51
- $this->_type = $type;
52
- switch($type){
53
- case self::RELATION_TYPE_NONE:
54
- break;
55
- case self::RELATION_TYPE_CHILD:
56
- $this->_entity1->addRelatedEntity($type, $this->_entity2);
57
- $this->_entity2->addRelatedEntity(self::RELATION_TYPE_PARENT, $this->_entity1);
58
- break;
59
- case self::RELATION_TYPE_PARENT:
60
- $this->_entity1->addRelatedEntity($type, $this->_entity2);
61
- $this->_entity2->addRelatedEntity(self::RELATION_TYPE_CHILD, $this->_entity1);
62
- break;
63
- case self::RELATION_TYPE_SIBLING:
64
- $this->_entity1->addRelatedEntity($type, $this->_entity2);
65
- $this->_entity2->addRelatedEntity(self::RELATION_TYPE_SIBLING, $this->_entity1);
66
- break;
67
- default:
68
- break;
69
- }
70
- return $this;
71
- }
72
- /**
73
- * get the relation type
74
- * @access public
75
- * @return int
76
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
77
- */
78
- public function getType(){
79
- return $this->_type;
80
- }
81
- /**
82
- * get relation entities
83
- * @access public
84
- * @return Ultimate_ModuleCreator_Model_Entity[]
85
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
86
- */
87
- public function getEntities(){
88
- return array($this->_entity1, $this->_entity2);
89
- }
90
- /**
91
- * relation to xml
92
- * @access protected
93
- * @param array $arrAttributes
94
- * @param string $rootName
95
- * @param bool $addOpenTag
96
- * @param bool $addCdata
97
- * @return string
98
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
99
- */
100
- public function toXml(array $arrAttributes = array(), $rootName = 'relation', $addOpenTag=false, $addCdata=false){
101
- $xml = '';
102
- $eol = $this->getEol();
103
- if ($rootName){
104
- $xml .= '<'.$rootName.'>'.$eol;
105
- }
106
- $entities = $this->getEntities();
107
- $xml .= '<'.$entities[0]->getNameSingular().'_'.$entities[1]->getNameSingular().'>';
108
- $xml .= $this->getType();
109
- $xml .= '</'.$entities[0]->getNameSingular().'_'.$entities[1]->getNameSingular().'>'.$eol;
110
- if ($rootName){
111
- $xml .= '</'.$rootName.'>'.$eol;
112
- }
113
- return $xml;
114
- }
115
- /**
116
- * check if siblings can be listed in the entity view page
117
- * @access public
118
- * @param int $index
119
- * @return bool
120
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
121
- */
122
- public function getShowFrontendRelationSiblings($index){
123
- if ($this->getType() != self::RELATION_TYPE_SIBLING){
124
- return false;
125
- }
126
- $index = !!$index;
127
- $entities = $this->getEntities();
128
- $e = $entities[$index];
129
- return $e->getCreateView();
130
- }
131
- /**
132
- * check if children can be listed in the parent view page
133
- * @access public
134
- * @return bool
135
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
136
- */
137
- public function getShowFrontendRelationChildren(){
138
- if ($this->getType() == self::RELATION_TYPE_CHILD){
139
- $index = 1;
140
- }
141
- elseif ($this->getType() == self::RELATION_TYPE_PARENT){
142
- $index = 0;
143
- }
144
- else {
145
- return false;
146
- }
147
- $entities = $this->getEntities();
148
- $e = $entities[$index];
149
- return $e->getCreateView();
150
- }
151
- /**
152
- * check if a relations has tree entities
153
- * @access public
154
- * @return bool
155
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
156
- */
157
- public function getHasTree(){
158
- return $this->_entity1->getIsTree() || $this->_entity2->getIsTree();
159
- }
160
- /**
161
- * check if a relations doesn not have tree entities
162
- * @access public
163
- * @return bool
164
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
165
- */
166
- public function getNotHasTree(){
167
- return !$this->getHasTree();
168
- }
169
- /**
170
- * check if one of the entities behaves as tree
171
- * @access public
172
- * @param int $index
173
- * @return bool
174
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
175
- */
176
- public function getEntityIsTree($index){
177
- $entities = $this->getEntities();
178
- return $entities[$index]->getIsTree();
179
- }
180
- /**
181
- * check if one of the entities behaves as tree
182
- * @access public
183
- * @param int $index
184
- * @return bool
185
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
186
- */
187
- public function getSiblingIsTree($index){
188
- return $this->getEntityIsTree(1 - $index);
189
- }
190
- /**
191
- * check if one of the entities does not behave as tree
192
- * @access public
193
- * @param int $index
194
- * @return bool
195
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
196
- */
197
- public function getSiblingIsNotTree($index){
198
- return !$this->getSiblingIsTree($index);
199
- }
200
- /**
201
- * check if entity has API
202
- * @access public
203
- * @param int $index
204
- * @return bool
205
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
206
- */
207
- public function getEntityHasApi($index){
208
- $entities = $this->getEntities();
209
- return $entities[$index]->getApi();
210
- }
211
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
+ */
18
+ class Ultimate_ModuleCreator_Model_Relation extends Ultimate_ModuleCreator_Model_Abstract
19
+ {
20
+ /**
21
+ * relation type constants
22
+ */
23
+ const RELATION_TYPE_NONE = 'none';
24
+ const RELATION_TYPE_CHILD = 'child';
25
+ const RELATION_TYPE_PARENT = 'parent';
26
+ const RELATION_TYPE_SIBLING = 'sibling';
27
+
28
+ /**
29
+ * @var Ultimate_ModuleCreator_Model_Entity
30
+ */
31
+ protected $_entity1;
32
+
33
+ /**
34
+ * @var Ultimate_ModuleCreator_Model_Entity
35
+ */
36
+ protected $_entity2;
37
+
38
+ /**
39
+ * relation type
40
+ *
41
+ * @var string
42
+ */
43
+ protected $_type;
44
+
45
+ /**
46
+ * set entities in relation
47
+ *
48
+ * @access public
49
+ * @param Ultimate_ModuleCreator_Model_Entity $entity1
50
+ * @param Ultimate_ModuleCreator_Model_Entity $entity2
51
+ * @param int $type
52
+ * @return Ultimate_ModuleCreator_Model_Relation
53
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
54
+ */
55
+ public function setEntities(
56
+ Ultimate_ModuleCreator_Model_Entity $entity1,
57
+ Ultimate_ModuleCreator_Model_Entity $entity2,
58
+ $type
59
+ ) {
60
+ $this->_entity1 = $entity1;
61
+ $this->_entity2 = $entity2;
62
+ $this->_type = $type;
63
+ switch($type) {
64
+ case self::RELATION_TYPE_NONE:
65
+ break;
66
+ case self::RELATION_TYPE_CHILD:
67
+ $this->_entity1->addRelatedEntity($type, $this->_entity2);
68
+ $this->_entity2->addRelatedEntity(self::RELATION_TYPE_PARENT, $this->_entity1);
69
+ break;
70
+ case self::RELATION_TYPE_PARENT:
71
+ $this->_entity1->addRelatedEntity($type, $this->_entity2);
72
+ $this->_entity2->addRelatedEntity(self::RELATION_TYPE_CHILD, $this->_entity1);
73
+ break;
74
+ case self::RELATION_TYPE_SIBLING:
75
+ $this->_entity1->addRelatedEntity($type, $this->_entity2);
76
+ $this->_entity2->addRelatedEntity(self::RELATION_TYPE_SIBLING, $this->_entity1);
77
+ break;
78
+ default:
79
+ break;
80
+ }
81
+ return $this;
82
+ }
83
+
84
+ /**
85
+ * get the relation type
86
+ *
87
+ * @access public
88
+ * @return int
89
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
90
+ */
91
+ public function getType()
92
+ {
93
+ return $this->_type;
94
+ }
95
+
96
+ /**
97
+ * get relation entities
98
+ *
99
+ * @access public
100
+ * @return Ultimate_ModuleCreator_Model_Entity[]
101
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
102
+ */
103
+ public function getEntities()
104
+ {
105
+ return array($this->_entity1, $this->_entity2);
106
+ }
107
+
108
+ /**
109
+ * relation to xml
110
+ *
111
+ * @access protected
112
+ * @param array $arrAttributes
113
+ * @param string $rootName
114
+ * @param bool $addOpenTag
115
+ * @param bool $addCdata
116
+ * @return string
117
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
118
+ */
119
+ public function toXml(array $arrAttributes = array(), $rootName = 'relation', $addOpenTag=false, $addCdata=false)
120
+ {
121
+ $xml = '';
122
+ $eol = $this->getEol();
123
+ if ($rootName) {
124
+ $xml .= '<'.$rootName.'>'.$eol;
125
+ }
126
+ $entities = $this->getEntities();
127
+ $xml .= '<'.$entities[0]->getNameSingular().'_'.$entities[1]->getNameSingular().'>';
128
+ $xml .= $this->getType();
129
+ $xml .= '</'.$entities[0]->getNameSingular().'_'.$entities[1]->getNameSingular().'>'.$eol;
130
+ if ($rootName) {
131
+ $xml .= '</'.$rootName.'>'.$eol;
132
+ }
133
+ return $xml;
134
+ }
135
+
136
+ /**
137
+ * check if siblings can be listed in the entity view page
138
+ *
139
+ * @access public
140
+ * @param int $index
141
+ * @return bool
142
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
143
+ */
144
+ public function getShowFrontendRelationSiblings($index)
145
+ {
146
+ if ($this->getType() != self::RELATION_TYPE_SIBLING) {
147
+ return false;
148
+ }
149
+ $index = !!$index;
150
+ $entities = $this->getEntities();
151
+ $e = $entities[$index];
152
+ return $e->getCreateView();
153
+ }
154
+
155
+ /**
156
+ * check if children can be listed in the parent view page
157
+ *
158
+ * @access public
159
+ * @return bool
160
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
161
+ */
162
+ public function getShowFrontendRelationChildren()
163
+ {
164
+ if ($this->getType() == self::RELATION_TYPE_CHILD) {
165
+ $index = 1;
166
+ } elseif ($this->getType() == self::RELATION_TYPE_PARENT) {
167
+ $index = 0;
168
+ } else {
169
+ return false;
170
+ }
171
+ $entities = $this->getEntities();
172
+ $e = $entities[$index];
173
+ return $e->getCreateView();
174
+ }
175
+
176
+ /**
177
+ * check if a relations has tree entities
178
+ *
179
+ * @access public
180
+ * @return bool
181
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
182
+ */
183
+ public function getHasTree()
184
+ {
185
+ return $this->_entity1->getIsTree() || $this->_entity2->getIsTree();
186
+ }
187
+
188
+ /**
189
+ * check if a relations does not have tree entities
190
+ *
191
+ * @access public
192
+ * @return bool
193
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
194
+ */
195
+ public function getNotHasTree()
196
+ {
197
+ return !$this->getHasTree();
198
+ }
199
+
200
+ /**
201
+ * check if one of the entities behaves as tree
202
+ *
203
+ * @access public
204
+ * @param int $index
205
+ * @return bool
206
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
207
+ */
208
+ public function getEntityIsTree($index)
209
+ {
210
+ $entities = $this->getEntities();
211
+ return $entities[$index]->getIsTree();
212
+ }
213
+
214
+ /**
215
+ * check if one of the entities behaves as tree
216
+ *
217
+ * @access public
218
+ * @param int $index
219
+ * @return bool
220
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
221
+ */
222
+ public function getSiblingIsTree($index)
223
+ {
224
+ return $this->getEntityIsTree(1 - $index);
225
+ }
226
+
227
+ /**
228
+ * check if one of the entities does not behave as tree
229
+ *
230
+ * @access public
231
+ * @param int $index
232
+ * @return bool
233
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
234
+ */
235
+ public function getSiblingIsNotTree($index)
236
+ {
237
+ return !$this->getSiblingIsTree($index);
238
+ }
239
+
240
+ /**
241
+ * check if entity has API
242
+ *
243
+ * @access public
244
+ * @param int $index
245
+ * @return bool
246
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
247
+ */
248
+ public function getEntityHasApi($index)
249
+ {
250
+ $entities = $this->getEntities();
251
+ return $entities[$index]->getApi();
252
+ }
253
+ }
app/code/community/Ultimate/ModuleCreator/Model/Source/Attribute/Scope.php CHANGED
@@ -1,60 +1,64 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
- */
18
- /**
19
- * allowed attribute scopes
20
- *
21
- * @category Ultimate
22
- * @package Ultimate_ModuleCreator
23
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
- */
25
- class Ultimate_ModuleCreator_Model_Source_Attribute_Scope {
26
- /**
27
- * options
28
- * @var null
29
- */
30
- protected $_options = null;
31
- /**
32
- * get options array
33
- * @access public
34
- * @param bool $withEmpty
35
- * @return array|null
36
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
37
- */
38
- public function toArray($withEmpty = false){
39
- if (is_null($this->_options)){
40
- $this->_options = array();
41
- $this->_options[] = array(
42
- 'label' => Mage::helper('modulecreator')->__('Store View'),
43
- 'value' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE
44
- );
45
- $this->_options[] = array(
46
- 'label' => Mage::helper('modulecreator')->__('Website'),
47
- 'value' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE
48
- );
49
- $this->_options[] = array(
50
- 'label' => Mage::helper('modulecreator')->__('Global'),
51
- 'value' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL
52
- );
53
- }
54
- $options = $this->_options;
55
- if ($withEmpty) {
56
- $options = array_merge(array(''=>''), $options);
57
- }
58
- return $options;
59
- }
60
- }
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
+ */
18
+ /**
19
+ * allowed attribute scopes
20
+ *
21
+ * @category Ultimate
22
+ * @package Ultimate_ModuleCreator
23
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
+ */
25
+ class Ultimate_ModuleCreator_Model_Source_Attribute_Scope
26
+ {
27
+ /**
28
+ * options
29
+ *
30
+ * @var null
31
+ */
32
+ protected $_options = null;
33
+ /**
34
+ * get options array
35
+ *
36
+ * @access public
37
+ * @param bool $withEmpty
38
+ * @return array|null
39
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
40
+ */
41
+ public function toArray($withEmpty = false)
42
+ {
43
+ if (is_null($this->_options)) {
44
+ $this->_options = array();
45
+ $this->_options[] = array(
46
+ 'label' => Mage::helper('modulecreator')->__('Store View'),
47
+ 'value' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE
48
+ );
49
+ $this->_options[] = array(
50
+ 'label' => Mage::helper('modulecreator')->__('Website'),
51
+ 'value' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE
52
+ );
53
+ $this->_options[] = array(
54
+ 'label' => Mage::helper('modulecreator')->__('Global'),
55
+ 'value' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL
56
+ );
57
+ }
58
+ $options = $this->_options;
59
+ if ($withEmpty) {
60
+ $options = array_merge(array(''=>''), $options);
61
+ }
62
+ return $options;
63
+ }
64
+ }
app/code/community/Ultimate/ModuleCreator/Model/Source/Attribute/Type.php CHANGED
@@ -1,64 +1,67 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
- */
18
- /**
19
- * allowed attribute types
20
- *
21
- * @category Ultimate
22
- * @package Ultimate_ModuleCreator
23
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
- */
25
- class Ultimate_ModuleCreator_Model_Source_Attribute_Type {
26
- /**
27
- * options
28
- * @var mixed
29
- */
30
- protected $_options = null;
31
- /**
32
- * get options array
33
- * @access public
34
- * @param bool $withEmpty
35
- * @return array|null
36
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
37
- */
38
- public function toArray($withEmpty = false) {
39
- if (is_null($this->_options)){
40
- /** @var Ultimate_ModuleCreator_Helper_Data $helper */
41
- $helper = Mage::helper('modulecreator');
42
- $types = $helper->getAttributeTypes();
43
- $groups = $helper->getAttributeTypeGroups();
44
- foreach ($groups as $key=>$group) {
45
- $this->_options[$key] = array('label'=>(string)$group->label, 'value'=>array());
46
- }
47
- foreach ($types as $type=>$values) {
48
- $group = (string)$values->group;
49
- if (!empty($group) && isset($this->_options[$group])) {
50
- $this->_options[$group]['value'][] = array('label'=>(string)$values->label, 'value'=>$type);
51
- }
52
- else {
53
- $this->_options[] = array('label'=>(string)$values->label, 'value'=>$type);
54
- }
55
- }
56
- $this->_options = array_values($this->_options);
57
- }
58
- $options = $this->_options;
59
- if ($withEmpty) {
60
- array_unshift($options, array('label'=>'', 'value'=>''));
61
- }
62
- return $options;
63
- }
64
- }
 
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
+ */
18
+ /**
19
+ * allowed attribute types
20
+ *
21
+ * @category Ultimate
22
+ * @package Ultimate_ModuleCreator
23
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
+ */
25
+ class Ultimate_ModuleCreator_Model_Source_Attribute_Type
26
+ {
27
+ /**
28
+ * options
29
+ *
30
+ * @var mixed
31
+ */
32
+ protected $_options = null;
33
+ /**
34
+ * get options array
35
+ *
36
+ * @access public
37
+ * @param bool $withEmpty
38
+ * @return array|null
39
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
40
+ */
41
+ public function toArray($withEmpty = false)
42
+ {
43
+ if (is_null($this->_options)) {
44
+ /** @var Ultimate_ModuleCreator_Helper_Data $helper */
45
+ $helper = Mage::helper('modulecreator');
46
+ $types = $helper->getAttributeTypes();
47
+ $groups = $helper->getAttributeTypeGroups();
48
+ foreach ($groups as $key=>$group) {
49
+ $this->_options[$key] = array('label'=>(string)$group->label, 'value'=>array());
50
+ }
51
+ foreach ($types as $type=>$values) {
52
+ $group = (string)$values->group;
53
+ if (!empty($group) && isset($this->_options[$group])) {
54
+ $this->_options[$group]['value'][] = array('label'=>(string)$values->label, 'value'=>$type);
55
+ } else {
56
+ $this->_options[] = array('label'=>(string)$values->label, 'value'=>$type);
57
+ }
58
+ }
59
+ $this->_options = array_values($this->_options);
60
+ }
61
+ $options = $this->_options;
62
+ if ($withEmpty) {
63
+ array_unshift($options, array('label'=>'', 'value'=>''));
64
+ }
65
+ return $options;
66
+ }
67
+ }
app/code/community/Ultimate/ModuleCreator/Model/Source/Attribute/Value/Source.php CHANGED
@@ -1,55 +1,59 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
- */
18
- /**
19
- * allowed attribute sources
20
- *
21
- * @category Ultimate
22
- * @package Ultimate_ModuleCreator
23
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
- */
25
- class Ultimate_ModuleCreator_Model_Source_Attribute_Value_Source {
26
- /**
27
- * options
28
- * @var mixed
29
- */
30
- protected $_options = null;
31
-
32
- /**
33
- * get options array
34
- * @access public
35
- * @param bool $withEmpty
36
- * @return array|null
37
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
38
- */
39
- public function toArray($withEmpty = false) {
40
- if (is_null($this->_options)) {
41
- /** @var Ultimate_ModuleCreator_Helper_Data $helper */
42
- $helper = Mage::helper('modulecreator');
43
- $options = $helper->getDropdownSubtypes(true);
44
- $this->_options = array();
45
- foreach ($options as $key=>$option){
46
- $this->_options[$key] = $option->label;
47
- }
48
- }
49
- $options = $this->_options;
50
- if ($withEmpty) {
51
- $options = array_merge(array(''=>''), $options);
52
- }
53
- return $options;
54
- }
55
- }
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
+ */
18
+ /**
19
+ * allowed attribute sources
20
+ *
21
+ * @category Ultimate
22
+ * @package Ultimate_ModuleCreator
23
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
+ */
25
+ class Ultimate_ModuleCreator_Model_Source_Attribute_Value_Source
26
+ {
27
+ /**
28
+ * options
29
+ *
30
+ * @var mixed
31
+ */
32
+ protected $_options = null;
33
+
34
+ /**
35
+ * get options array
36
+ *
37
+ * @access public
38
+ * @param bool $withEmpty
39
+ * @return array|null
40
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
41
+ */
42
+ public function toArray($withEmpty = false)
43
+ {
44
+ if (is_null($this->_options)) {
45
+ /** @var Ultimate_ModuleCreator_Helper_Data $helper */
46
+ $helper = Mage::helper('modulecreator');
47
+ $options = $helper->getDropdownSubtypes(true);
48
+ $this->_options = array();
49
+ foreach ($options as $key=>$option) {
50
+ $this->_options[$key] = $option->label;
51
+ }
52
+ }
53
+ $options = $this->_options;
54
+ if ($withEmpty) {
55
+ $options = array_merge(array(''=>''), $options);
56
+ }
57
+ return $options;
58
+ }
59
+ }
app/code/community/Ultimate/ModuleCreator/Model/Source/Codepool.php CHANGED
@@ -1,64 +1,76 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- */
17
- /**
18
- * code pool source model
19
- *
20
- * @category Ultimate
21
- * @package Ultimate_ModuleCreator
22
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
23
- */
24
- class Ultimate_ModuleCreator_Model_Source_Codepool {
25
- /**
26
- * get the list of available code pools
27
- * @access public
28
- * @param bool $withEmpty
29
- * @return array
30
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
31
- */
32
- public function toOptionArray($withEmpty = false){
33
- $options = array();
34
- if ($withEmpty){
35
- $options[] = array('value'=>'', 'label'=>Mage::helper('modulecreator')->__('Select a codepool'));
36
- }
37
- $options[] = array('value' => 'local', 'label'=>'local');
38
- $options[] = array('value' => 'community', 'label'=>'community');
39
- return $options;
40
- }
41
- /**
42
- * get options as an array
43
- * @access public
44
- * @param bool $withEmpty
45
- * @return array
46
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
47
- */
48
- public function getAllOptions($withEmpty = true){
49
- $options = array();
50
- foreach ($this->toOptionArray($withEmpty) as $option){
51
- $options[$option['value']] = $option['label'];
52
- }
53
- return $options;
54
- }
55
- /**
56
- * get options as an array - wrapper
57
- * @param bool $withEmpty
58
- * @return array
59
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
60
- */
61
- public function toArray($withEmpty = true){
62
- return $this->getAllOptions($withEmpty);
63
- }
64
- }
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ */
17
+ /**
18
+ * code pool source model
19
+ *
20
+ * @category Ultimate
21
+ * @package Ultimate_ModuleCreator
22
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
23
+ */
24
+ class Ultimate_ModuleCreator_Model_Source_Codepool
25
+ {
26
+ /**
27
+ * get the list of available code pools
28
+ *
29
+ * @access public
30
+ * @param bool $withEmpty
31
+ * @return array
32
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
33
+ */
34
+ public function toOptionArray($withEmpty = false)
35
+ {
36
+ $options = array();
37
+ if ($withEmpty) {
38
+ $options[] = array(
39
+ 'value'=>'',
40
+ 'label'=>Mage::helper('modulecreator')->__('Select a codepool')
41
+ );
42
+ }
43
+ $options[] = array('value' => 'local', 'label'=>'local');
44
+ $options[] = array('value' => 'community', 'label'=>'community');
45
+ return $options;
46
+ }
47
+
48
+ /**
49
+ * get options as an array
50
+ *
51
+ * @access public
52
+ * @param bool $withEmpty
53
+ * @return array
54
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
55
+ */
56
+ public function getAllOptions($withEmpty = true)
57
+ {
58
+ $options = array();
59
+ foreach ($this->toOptionArray($withEmpty) as $option) {
60
+ $options[$option['value']] = $option['label'];
61
+ }
62
+ return $options;
63
+ }
64
+
65
+ /**
66
+ * get options as an array - wrapper
67
+ *
68
+ * @param bool $withEmpty
69
+ * @return array
70
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
71
+ */
72
+ public function toArray($withEmpty = true)
73
+ {
74
+ return $this->getAllOptions($withEmpty);
75
+ }
76
+ }
app/code/community/Ultimate/ModuleCreator/Model/Source/Entity/Layout.php CHANGED
@@ -1,53 +1,57 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
- */
18
- /**
19
- * allowed entity layouts
20
- *
21
- * @category Ultimate
22
- * @package Ultimate_ModuleCreator
23
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
- */
25
- class Ultimate_ModuleCreator_Model_Source_Entity_Layout {
26
- /**
27
- * options
28
- * @var mixed
29
- */
30
- protected $_options = null;
31
- /**
32
- * get options array
33
- * @access public
34
- * @param bool $withEmpty
35
- * @return array|null
36
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
37
- */
38
- public function toArray($withEmpty = false){
39
- if (is_null($this->_options)){
40
- /** @var Mage_Page_Model_Source_Layout $layoutModel */
41
- $layoutModel = Mage::getSingleton('page/source_layout');
42
- $_options = $layoutModel->toOptionArray();
43
- foreach ($_options as $option){
44
- $this->_options[$option['value']] = $option['label'];
45
- }
46
- }
47
- $options = $this->_options;
48
- if ($withEmpty) {
49
- $options = array_merge(array(''=>''), $options);
50
- }
51
- return $options;
52
- }
53
- }
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
+ */
18
+ /**
19
+ * allowed entity layouts
20
+ *
21
+ * @category Ultimate
22
+ * @package Ultimate_ModuleCreator
23
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
+ */
25
+ class Ultimate_ModuleCreator_Model_Source_Entity_Layout
26
+ {
27
+ /**
28
+ * options
29
+ *
30
+ * @var mixed
31
+ */
32
+ protected $_options = null;
33
+ /**
34
+ * get options array
35
+ *
36
+ * @access public
37
+ * @param bool $withEmpty
38
+ * @return array|null
39
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
40
+ */
41
+ public function toArray($withEmpty = false)
42
+ {
43
+ if (is_null($this->_options)) {
44
+ /** @var Mage_Page_Model_Source_Layout $layoutModel */
45
+ $layoutModel = Mage::getSingleton('page/source_layout');
46
+ $_options = $layoutModel->toOptionArray();
47
+ foreach ($_options as $option) {
48
+ $this->_options[$option['value']] = $option['label'];
49
+ }
50
+ }
51
+ $options = $this->_options;
52
+ if ($withEmpty) {
53
+ $options = array_merge(array(''=>''), $options);
54
+ }
55
+ return $options;
56
+ }
57
+ }
app/code/community/Ultimate/ModuleCreator/Model/Source/Entity/Menu.php CHANGED
@@ -1,55 +1,62 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
- */
18
- /**
19
- * available menus
20
- *
21
- * @category Ultimate
22
- * @package Ultimate_ModuleCreator
23
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
- */
25
- class Ultimate_ModuleCreator_Model_Source_Entity_Menu {
26
- const NO_MENU = 0;
27
- const TOP_LINKS = 1;
28
- const CATEGORY_MENU = 2;
29
- const FOOTER_LINKS = 3;
30
- /**
31
- * options
32
- * @var mixed
33
- */
34
- protected $_options = null;
35
- /**
36
- * get options array
37
- * @access public
38
- * @param bool $withEmpty
39
- * @return array|null
40
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
41
- */
42
- public function toArray($withEmpty = false) {
43
- if (is_null($this->_options)){
44
- $this->_options[self::NO_MENU] = Mage::helper('modulecreator')->__('Do not include in any menu');
45
- $this->_options[self::TOP_LINKS] = Mage::helper('modulecreator')->__('Include in top links. (near My account, Checkout, ...)');
46
- $this->_options[self::CATEGORY_MENU] = Mage::helper('modulecreator')->__('Include in category menu');
47
- $this->_options[self::FOOTER_LINKS] = Mage::helper('modulecreator')->__('Include in footer links');
48
- }
49
- $options = $this->_options;
50
- if ($withEmpty) {
51
- $options = array_merge(array(''=>''), $options);
52
- }
53
- return $options;
54
- }
55
- }
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
+ */
18
+ /**
19
+ * available menus
20
+ *
21
+ * @category Ultimate
22
+ * @package Ultimate_ModuleCreator
23
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
+ */
25
+ class Ultimate_ModuleCreator_Model_Source_Entity_Menu
26
+ {
27
+ const NO_MENU = 0;
28
+ const TOP_LINKS = 1;
29
+ const CATEGORY_MENU = 2;
30
+ const FOOTER_LINKS = 3;
31
+
32
+ /**
33
+ * options
34
+ *
35
+ * @var mixed
36
+ */
37
+ protected $_options = null;
38
+
39
+ /**
40
+ * get options array
41
+ *
42
+ * @access public
43
+ * @param bool $withEmpty
44
+ * @return array|null
45
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
46
+ */
47
+ public function toArray($withEmpty = false)
48
+ {
49
+ if (is_null($this->_options)) {
50
+ $this->_options[self::NO_MENU] = Mage::helper('modulecreator')->__('Do not include in any menu');
51
+ $this->_options[self::TOP_LINKS] = Mage::helper('modulecreator')
52
+ ->__('Include in top links. (near My account, Checkout, ...)');
53
+ $this->_options[self::CATEGORY_MENU] = Mage::helper('modulecreator')->__('Include in category menu');
54
+ $this->_options[self::FOOTER_LINKS] = Mage::helper('modulecreator')->__('Include in footer links');
55
+ }
56
+ $options = $this->_options;
57
+ if ($withEmpty) {
58
+ $options = array_merge(array(''=>''), $options);
59
+ }
60
+ return $options;
61
+ }
62
+ }
app/code/community/Ultimate/ModuleCreator/Model/Source/Entity/Type.php CHANGED
@@ -1,53 +1,58 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
- */
18
- /**
19
- * allowed entity types
20
- *
21
- * @category Ultimate
22
- * @package Ultimate_ModuleCreator
23
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
- */
25
- class Ultimate_ModuleCreator_Model_Source_Entity_Type {
26
- /**
27
- * options
28
- * @var mixed
29
- */
30
- protected $_options = null;
31
- /**
32
- * get options array
33
- * @access public
34
- * @param bool $withEmpty
35
- * @return array|null
36
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
37
- */
38
- public function toArray($withEmpty = false) {
39
- if (is_null($this->_options)){
40
- /** @var Ultimate_ModuleCreator_Helper_Data $helper */
41
- $helper = Mage::helper('modulecreator');
42
- $types = $helper->getEntityTypes();
43
- foreach ($types as $type=>$values){
44
- $this->_options[$type] = Mage::helper('modulecreator')->__((string)$values->label);
45
- }
46
- }
47
- $options = $this->_options;
48
- if ($withEmpty) {
49
- $options = array_merge(array(''=>''), $options);
50
- }
51
- return $options;
52
- }
53
- }
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
+ */
18
+ /**
19
+ * allowed entity types
20
+ *
21
+ * @category Ultimate
22
+ * @package Ultimate_ModuleCreator
23
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
+ */
25
+ class Ultimate_ModuleCreator_Model_Source_Entity_Type
26
+ {
27
+ /**
28
+ * options
29
+ *
30
+ * @var mixed
31
+ */
32
+ protected $_options = null;
33
+
34
+ /**
35
+ * get options array
36
+ *
37
+ * @access public
38
+ * @param bool $withEmpty
39
+ * @return array|null
40
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
41
+ */
42
+ public function toArray($withEmpty = false)
43
+ {
44
+ if (is_null($this->_options)) {
45
+ /** @var Ultimate_ModuleCreator_Helper_Data $helper */
46
+ $helper = Mage::helper('modulecreator');
47
+ $types = $helper->getEntityTypes();
48
+ foreach ($types as $type=>$values) {
49
+ $this->_options[$type] = Mage::helper('modulecreator')->__((string)$values->label);
50
+ }
51
+ }
52
+ $options = $this->_options;
53
+ if ($withEmpty) {
54
+ $options = array_merge(array(''=>''), $options);
55
+ }
56
+ return $options;
57
+ }
58
+ }
app/code/community/Ultimate/ModuleCreator/Model/Source/Install.php CHANGED
@@ -1,74 +1,83 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
- */
18
- /**
19
- * install source mode
20
- *
21
- * @category Ultimate
22
- * @package Ultimate_ModuleCreator
23
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
- */
25
- class Ultimate_ModuleCreator_Model_Source_Install {
26
- /**
27
- * get the list of available install actions
28
- * @access public
29
- * @param bool $withEmpty
30
- * @return array
31
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
32
- */
33
- public function toOptionArray($withEmpty = false) {
34
- $options = array();
35
- if ($withEmpty){
36
- $options[] = array(
37
- 'value'=>'',
38
- 'label'=>Mage::helper('modulecreator')->__('Select action'));
39
- }
40
- $options[] = array(
41
- 'value' => '1',
42
- 'label'=>Mage::helper('modulecreator')->__('Install new extension on the current instance.')
43
- );
44
- $options[] = array(
45
- 'value' => '0',
46
- 'label'=>Mage::helper('modulecreator')->__('Create archive. I will install it later')
47
- );
48
- return $options;
49
- }
50
- /**
51
- * get options as an array
52
- * @access public
53
- * @param bool $withEmpty
54
- * @return array
55
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
56
- */
57
- public function getAllOptions($withEmpty = true) {
58
- $options = array();
59
- foreach ($this->toOptionArray($withEmpty) as $option) {
60
- $options[$option['value']] = $option['label'];
61
- }
62
- return $options;
63
- }
64
-
65
- /**
66
- * get options as an array - wrapper
67
- * @param bool $withEmpty
68
- * @return array
69
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
70
- */
71
- public function toArray($withEmpty = true) {
72
- return $this->getAllOptions($withEmpty);
73
- }
74
- }
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
+ */
18
+ /**
19
+ * install source mode
20
+ *
21
+ * @category Ultimate
22
+ * @package Ultimate_ModuleCreator
23
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
+ */
25
+ class Ultimate_ModuleCreator_Model_Source_Install
26
+ {
27
+ /**
28
+ * get the list of available install actions
29
+ *
30
+ * @access public
31
+ * @param bool $withEmpty
32
+ * @return array
33
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
34
+ */
35
+ public function toOptionArray($withEmpty = false)
36
+ {
37
+ $options = array();
38
+ if ($withEmpty) {
39
+ $options[] = array(
40
+ 'value'=>'',
41
+ 'label'=>Mage::helper('modulecreator')->__('Select action')
42
+ );
43
+ }
44
+ $options[] = array(
45
+ 'value' => '1',
46
+ 'label'=>Mage::helper('modulecreator')->__('Install new extension on the current instance.')
47
+ );
48
+ $options[] = array(
49
+ 'value' => '0',
50
+ 'label'=>Mage::helper('modulecreator')->__('Create archive. I will install it later')
51
+ );
52
+ return $options;
53
+ }
54
+
55
+ /**
56
+ * get options as an array
57
+ *
58
+ * @access public
59
+ * @param bool $withEmpty
60
+ * @return array
61
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
62
+ */
63
+ public function getAllOptions($withEmpty = true)
64
+ {
65
+ $options = array();
66
+ foreach ($this->toOptionArray($withEmpty) as $option) {
67
+ $options[$option['value']] = $option['label'];
68
+ }
69
+ return $options;
70
+ }
71
+
72
+ /**
73
+ * get options as an array - wrapper
74
+ *
75
+ * @param bool $withEmpty
76
+ * @return array
77
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
78
+ */
79
+ public function toArray($withEmpty = true)
80
+ {
81
+ return $this->getAllOptions($withEmpty);
82
+ }
83
+ }
app/code/community/Ultimate/ModuleCreator/Model/Writer.php CHANGED
@@ -1,83 +1,91 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2012
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- */
17
- /**
18
- * Zip writer
19
- *
20
- * @category Ultimate
21
- * @package Ultimate_ModuleCreator
22
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
23
- */
24
- class Ultimate_ModuleCreator_Model_Writer
25
- extends Mage_Connect_Package_Writer {
26
- /**
27
- * prefix for path
28
- * @var string
29
- */
30
- protected $_pathPrefix = '';
31
- /**
32
- * constructor
33
- * @access public
34
- * @param array $files
35
- * @param mixed $namePackage
36
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
37
- */
38
- public function __construct($files, $namePackage='') {
39
- parent::__construct($files, $namePackage='');
40
- $this->_pathPrefix = 'var'.DS.'modulecreator'.DS;
41
- }
42
- /**
43
- * build the package
44
- * @access public
45
- * @return Ultimate_ModuleCreator_Model_Writer
46
- * @see Mage_Connect_Package_Writer::composePackage()
47
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
48
- */
49
- public function composePackage() {
50
- @mkdir(self::PATH_TO_TEMPORARY_DIRECTORY, 0777, true);
51
- $root = self::PATH_TO_TEMPORARY_DIRECTORY . basename($this->_namePackage);
52
- @mkdir($root, 0777, true);
53
- foreach ($this->_files as $file) {
54
- if (is_dir($file) || is_file($file)) {
55
- $fileName = basename($file);
56
- $filePath = dirname($file);
57
- if (substr($filePath, 0, strlen($this->_pathPrefix)) == $this->_pathPrefix) {
58
- $filePath = substr($filePath, strlen($this->_pathPrefix));
59
- }
60
- @mkdir($root . DS . $filePath, 0777, true);
61
- if (is_file($file)) {
62
- copy($file, $root . DS . $filePath . DS . $fileName);
63
- }
64
- else {
65
- @mkdir($root . DS . $filePath . $fileName, 0777);
66
- }
67
- }
68
- }
69
- $this->_temporaryPackageDir = $root;
70
- return $this;
71
- }
72
- /**
73
- * set the package name
74
- * @access public
75
- * @param string $name
76
- * @return Ultimate_ModuleCreator_Model_Writer
77
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
78
- */
79
- public function setNamePackage($name) {
80
- $this->_namePackage = $name;
81
- return $this;
82
- }
83
- }
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2012
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ */
17
+ /**
18
+ * Zip writer
19
+ *
20
+ * @category Ultimate
21
+ * @package Ultimate_ModuleCreator
22
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
23
+ */
24
+ class Ultimate_ModuleCreator_Model_Writer extends Mage_Connect_Package_Writer
25
+ {
26
+ /**
27
+ * prefix for path
28
+ *
29
+ * @var string
30
+ */
31
+ protected $_pathPrefix = '';
32
+
33
+ /**
34
+ * set path prefix
35
+ *
36
+ * @param $pathPrefix
37
+ * @return $this
38
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
39
+ */
40
+ public function setPathPrefix($pathPrefix)
41
+ {
42
+ $this->_pathPrefix = $pathPrefix;
43
+ return $this;
44
+ }
45
+
46
+ /**
47
+ * build the package
48
+ *
49
+ * @access public
50
+ * @return Ultimate_ModuleCreator_Model_Writer
51
+ * @see Mage_Connect_Package_Writer::composePackage()
52
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
53
+ */
54
+ public function composePackage()
55
+ {
56
+ @mkdir(self::PATH_TO_TEMPORARY_DIRECTORY, 0777, true);
57
+ $root = self::PATH_TO_TEMPORARY_DIRECTORY . basename($this->_namePackage);
58
+ @mkdir($root, 0777, true);
59
+ foreach ($this->_files as $file) {
60
+ if (is_dir($file) || is_file($file)) {
61
+ $fileName = basename($file);
62
+ $filePath = dirname($file);
63
+ if (substr($filePath, 0, strlen($this->_pathPrefix)) == $this->_pathPrefix) {
64
+ $filePath = substr($filePath, strlen($this->_pathPrefix));
65
+ }
66
+ @mkdir($root . DS . $filePath, 0777, true);
67
+ if (is_file($file)) {
68
+ copy($file, $root . DS . $filePath . DS . $fileName);
69
+ } else {
70
+ @mkdir($root . DS . $filePath . $fileName, 0777);
71
+ }
72
+ }
73
+ }
74
+ $this->_temporaryPackageDir = $root;
75
+ return $this;
76
+ }
77
+
78
+ /**
79
+ * set the package name
80
+ *
81
+ * @access public
82
+ * @param string $name
83
+ * @return Ultimate_ModuleCreator_Model_Writer
84
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
85
+ */
86
+ public function setNamePackage($name)
87
+ {
88
+ $this->_namePackage = $name;
89
+ return $this;
90
+ }
91
+ }
app/code/community/Ultimate/ModuleCreator/controllers/Adminhtml/ModulecreatorController.php CHANGED
@@ -1,262 +1,297 @@
1
- <?php
2
- /**
3
- * Ultimate_ModuleCreator extension
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the MIT License
8
- * that is bundled with this package in the file LICENSE_UMC.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/mit-license.php
11
- *
12
- * @category Ultimate
13
- * @package Ultimate_ModuleCreator
14
- * @copyright Copyright (c) 2014
15
- * @license http://opensource.org/licenses/mit-license.php MIT License
16
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
- */
18
- /**
19
- * main admin controller
20
- *
21
- * @category Ultimate
22
- * @package Ultimate_ModuleCreator
23
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
- */
25
- class Ultimate_ModuleCreator_Adminhtml_ModulecreatorController
26
- extends Mage_Adminhtml_Controller_Action {
27
- /**
28
- * @access public
29
- * @return void
30
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
31
- */
32
- public function indexAction() {
33
- $this->_title(Mage::helper('modulecreator')->__('Ultimate module creator'));
34
- $this->_getSession()->addNotice(Mage::helper('modulecreator')->__(
35
- 'To delete a module from this list go to "<strong>%s</strong>" and remove the files "<strong>%s</strong>" and "<strong>%s</strong>" and folder "<strong>%s</strong>" if they exist. Replace <strong>Namespace_Module</strong> with the appropriate value for each module. There is no delete link in here for security reasons.',
36
- Mage::getBaseDir('var').DS.'modulecreator',
37
- 'Namespace_Module.tgz',
38
- 'package/Namespace_Module.xml',
39
- 'package/Namespace_Module/'
40
-
41
- ));
42
- $this->loadLayout();
43
- $this->renderLayout();
44
- }
45
-
46
- /**
47
- * grid action
48
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
49
- */
50
- public function gridAction() {
51
- $this->loadLayout();
52
- $this->renderLayout();
53
- }
54
-
55
- /**
56
- * new action
57
- * @access public
58
- * @return void
59
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
60
- */
61
- public function newAction() {
62
- $this->_forward('edit');
63
- }
64
- /**
65
- * edit action
66
- * @access public
67
- * @return void
68
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
69
- */
70
- public function editAction() {
71
- $module = $this->_initModule();
72
- $this->_title(Mage::helper('modulecreator')->__('Ultimate module creator'));
73
- if ($module) {
74
- $extensionName = $module->getNamespace().'_'.$module->getModuleName();
75
- $this->_getSession()->addNotice(Mage::helper('modulecreator')->__('You are editing the module: %s', $extensionName));
76
- $this->_title($extensionName);
77
- }
78
- else {
79
- $this->_title(Mage::helper('modulecreator')->__('Add module'));
80
- }
81
- $this->loadLayout();
82
- $this->renderLayout();
83
- }
84
- /**
85
- * init module
86
- * @access protected
87
- * @return mixed
88
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
89
- */
90
- protected function _initModule() {
91
- $packageName = base64_decode(strtr($this->getRequest()->getParam('id'), '-_,', '+/='));
92
- if ($packageName) {
93
- try {
94
- /** @var Ultimate_ModuleCreator_Helper_Data $helper */
95
- $helper = Mage::helper('modulecreator');
96
- $path = $helper->getLocalPackagesPath();
97
- $packageName = basename($packageName);
98
- $xmlFile = $path . $packageName . '.xml';
99
- if (file_exists($xmlFile) && is_readable($xmlFile)) {
100
- $xml = simplexml_load_file($xmlFile, 'Varien_Simplexml_Element');
101
- $module = $helper->loadModule($xml);
102
- Mage::register('current_module', $module);
103
- return $module;
104
- }
105
- }
106
- catch (Exception $e) {
107
- Mage::logException($e);
108
- $this->_getSession()->addError($e->getMessage());
109
- $this->_redirect('*/*/index');
110
- }
111
- }
112
- return false;
113
- }
114
- /**
115
- * init a module from an array
116
- * @access public
117
- * @param array $data
118
- * @return Ultimate_ModuleCreator_Model_Module
119
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
120
- */
121
- protected function _initModuleFromData($data) {
122
- $entitiesByIndex = array();
123
- /** @var Ultimate_ModuleCreator_Model_Module $module */
124
- $module = Mage::getModel('modulecreator/module');
125
- if (isset($data['settings'])) {
126
- $module->addData($data['settings']);
127
- }
128
- if (isset($data['entity'])) {
129
- $entities = $data['entity'];
130
- if (is_array($entities)) {
131
- foreach ($entities as $key=>$entityData) {
132
- /** @var Ultimate_ModuleCreator_Model_Entity $entity */
133
- $entity = Mage::getModel('modulecreator/entity');
134
- $entity->addData($entityData);
135
- $entity->setIndex($key);
136
- if (isset($entityData['attributes']) && is_array($entityData['attributes'])) {
137
- if (isset($entityData['attributes']['is_name'])) {
138
- $isName = $entityData['attributes']['is_name'];
139
- unset($entityData['attributes']['is_name']);
140
- if (isset($entityData['attributes'][$isName])) {
141
- $entityData['attributes'][$isName]['is_name'] = 1;
142
- }
143
- }
144
- foreach ($entityData['attributes'] as $aKey=>$attributeData) {
145
- /** @var Ultimate_ModuleCreator_Model_Attribute $attribute */
146
- $attribute = Mage::getModel('modulecreator/attribute');
147
- $attribute->addData($attributeData);
148
- $attribute->setIndex($aKey);
149
- $entity->addAttribute($attribute);
150
- }
151
- }
152
- $module->addEntity($entity);
153
- $entitiesByIndex[$key] = $entity;
154
- }
155
- }
156
- if (isset($data['relation'])) {
157
- foreach($data['relation'] as $index=>$values){
158
- foreach ($values as $jndex=>$type){
159
- if (isset($entitiesByIndex[$index]) && isset($entitiesByIndex[$jndex])) {
160
- /** @var Ultimate_ModuleCreator_Model_Relation $relation */
161
- $relation = Mage::getModel('modulecreator/relation');
162
- $relation->setEntities($entitiesByIndex[$index], $entitiesByIndex[$jndex], $type);
163
- $module->addRelation($relation);
164
- }
165
- }
166
- }
167
- }
168
- }
169
- return $module;
170
- }
171
-
172
- /**
173
- * validate module before saving
174
- * @access public
175
- * @return void
176
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
177
- */
178
- public function validateAction(){
179
- try{
180
- $response = new Varien_Object();
181
- $module = $this->_initModuleFromData($this->getRequest()->getPost());
182
- $errors = $module->validate();
183
- if (count($errors) == 0){
184
- $messages = $module->buildModule();
185
- $module->save();
186
- $response->setError(false);
187
- }
188
- else{
189
- if (isset($errors[''])){
190
- $response->setMessage(implode('<br />', $errors['']));
191
- unset($errors['']);
192
- }
193
- $response->setError(true);
194
- $response->setAttributes($errors);
195
- }
196
- }
197
- catch (Exception $e){
198
- $response->setError(true);
199
- $response->setMessage($e->getMessage());
200
- }
201
- $this->getResponse()->setBody($response->toJson());
202
- }
203
- /**
204
- * save module - actually only redirects the page
205
- * the save was done in validateAction(). there is no need to process the request twice.
206
- * @access public
207
- * @return void
208
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
209
- */
210
- public function saveAction() {
211
- $this->_getSession()->addSuccess(Mage::helper('modulecreator')->__('Your extension has been created!'));
212
- $module = $this->_initModuleFromData($this->getRequest()->getPost());
213
- $redirectBack = $this->getRequest()->getParam('back', false);
214
- if ($redirectBack) {
215
- $this->_redirect('*/*/edit', array(
216
- 'id' => strtr(base64_encode($module->getExtensionName()), '+/=', '-_,'),
217
- '_current' => true
218
- ));
219
- }
220
- else {
221
- $this->_redirect('*/*/');
222
- }
223
- }
224
- /**
225
- * download module action
226
- * @access public
227
- * @return void
228
- * @author Marius Strajeru <ultimate.module.creator@gmail.com>
229
- */
230
- public function downloadAction(){
231
- $what = $this->getRequest()->getParam('type');
232
- $packageName = base64_decode(strtr($this->getRequest()->getParam('id'), '-_,', '+/='));
233
- /** @var Ultimate_ModuleCreator_Helper_Data $helper */
234
- $helper = Mage::helper('modulecreator');
235
- $path = $helper->getLocalModulesDir();
236
- $namePrefix = '';
237
- switch ($what) {
238
- case 'config' :
239
- $file = $path.'package'.DS.$packageName . '.xml';
240
- break;
241
- case 'list':
242
- $file = $path.'package'.DS.$packageName . DS. 'files.log';
243
- $namePrefix = $packageName.'_';
244
- break;
245
- case 'uninstall' :
246
- $file = $path.'package'.DS.$packageName . DS. 'uninstall.sql';
247
- $namePrefix = $packageName.'_';
248
- break;
249
- default:
250
- $file = $path . $packageName . '.tgz';
251
- break;
252
- }
253
- if (file_exists($file) && is_readable($file)) {
254
- $content = file_get_contents($file);
255
- $this->_prepareDownloadResponse($namePrefix.basename($file), $content);
256
- }
257
- else{
258
- $this->_getSession()->addError(Mage::helper('modulecreator')->__('Your extension archive was not created or is not readable'));
259
- $this->_redirect('*/*');
260
- }
261
- }
262
- }
1
+ <?php
2
+ /**
3
+ * Ultimate_ModuleCreator extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
8
+ * that is bundled with this package in the file LICENSE_UMC.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/mit-license.php
11
+ *
12
+ * @category Ultimate
13
+ * @package Ultimate_ModuleCreator
14
+ * @copyright Copyright (c) 2014
15
+ * @license http://opensource.org/licenses/mit-license.php MIT License
16
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
17
+ */
18
+ /**
19
+ * main admin controller
20
+ *
21
+ * @category Ultimate
22
+ * @package Ultimate_ModuleCreator
23
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
24
+ */
25
+ class Ultimate_ModuleCreator_Adminhtml_ModulecreatorController extends Mage_Adminhtml_Controller_Action
26
+ {
27
+ /**
28
+ * default action
29
+ *
30
+ * @access public
31
+ * @return void
32
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
33
+ */
34
+ public function indexAction()
35
+ {
36
+ $this->_title(Mage::helper('modulecreator')->__('Ultimate module creator'));
37
+ $this->_getSession()->addNotice(
38
+ Mage::helper('modulecreator')->__(
39
+ 'To delete a module from this list go to "<strong>%s</strong>" and remove the files "<strong>%s</strong>" and "<strong>%s</strong>" and folder "<strong>%s</strong>" if they exist. Replace <strong>Namespace_Module</strong> with the appropriate value for each module. There is no delete link in here for security reasons.',
40
+ Mage::getBaseDir('var').DS.'modulecreator',
41
+ 'Namespace_Module.tgz',
42
+ 'package/Namespace_Module.xml',
43
+ 'package/Namespace_Module/'
44
+ )
45
+ );
46
+ $this->loadLayout();
47
+ $this->renderLayout();
48
+ }
49
+
50
+ /**
51
+ * grid action
52
+ *
53
+ * @access public
54
+ * @return void
55
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
56
+ */
57
+ public function gridAction()
58
+ {
59
+ $this->loadLayout();
60
+ $this->renderLayout();
61
+ }
62
+
63
+ /**
64
+ * new action
65
+ *
66
+ * @access public
67
+ * @return void
68
+ * @author Marius Strajeru <ultimate.module.creator@gmail.com>
69
+ */
70
+ public function newAction()
71
+ {
72
+ $this->_forward('edit');
73
+ }
74
+
75
+ /**
76
+ * edit action
77
+ *
78
+ * @access public
79
+ * @return void
80
+ * @author Marius Strajeru <ultimate