Conditions | 16 |
Paths | 3888 |
Total Lines | 157 |
Code Lines | 92 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
62 | public function __construct($target) |
||
63 | { |
||
64 | global $helper; |
||
65 | $this->targetObject = $target; |
||
66 | |||
67 | $title = $this->targetObject->isNew() ? \sprintf(\_AM_LEXIKON_CATEGORIES_ADD) : \sprintf(\_AM_LEXIKON_CATEGORIES_EDIT); |
||
68 | parent::__construct($title, 'form', \xoops_getenv('SCRIPT_NAME'), 'post', true); |
||
69 | $this->setExtra('enctype="multipart/form-data"'); |
||
70 | |||
71 | //include ID field, it's needed so the module knows if it is a new form or an edited form |
||
72 | |||
73 | $hidden = new XoopsFormHidden('categoryID', $this->targetObject->getVar('categoryID')); |
||
74 | $this->addElement($hidden); |
||
75 | unset($hidden); |
||
76 | |||
77 | // CategoryID |
||
78 | $this->addElement(new XoopsFormLabel(\_AM_LEXIKON_CATEGORIES_CATEGORYID, $this->targetObject->getVar('categoryID'), 'categoryID')); |
||
79 | // Name |
||
80 | $this->addElement(new XoopsFormText(\_AM_LEXIKON_CATEGORIES_NAME, 'name', 50, 255, $this->targetObject->getVar('name')), false); |
||
81 | // Description |
||
82 | if (\class_exists('XoopsFormEditor')) { |
||
83 | $editorOptions = []; |
||
84 | $editorOptions['name'] = 'description'; |
||
85 | $editorOptions['value'] = $this->targetObject->getVar('description', 'e'); |
||
86 | $editorOptions['rows'] = 5; |
||
87 | $editorOptions['cols'] = 40; |
||
88 | $editorOptions['width'] = '100%'; |
||
89 | $editorOptions['height'] = '400px'; |
||
90 | //$editorOptions['editor'] = xoops_getModuleOption('lexikon_editor', 'lexikon'); |
||
91 | //$this->addElement( new \XoopsFormEditor(\_AM_LEXIKON_CATEGORIES_DESCRIPTION, 'description', $editorOptions), false ); |
||
92 | if ($helper->isUserAdmin()) { |
||
93 | $descEditor = new XoopsFormEditor(\_AM_LEXIKON_CATEGORIES_DESCRIPTION, $helper->getConfig('lexikonEditorAdmin'), $editorOptions, $nohtml = false, $onfailure = 'textarea'); |
||
94 | } else { |
||
95 | $descEditor = new XoopsFormEditor(\_AM_LEXIKON_CATEGORIES_DESCRIPTION, $helper->getConfig('lexikonEditorUser'), $editorOptions, $nohtml = false, $onfailure = 'textarea'); |
||
96 | } |
||
97 | } else { |
||
98 | $descEditor = new XoopsFormDhtmlTextArea(\_AM_LEXIKON_CATEGORIES_DESCRIPTION, 'description', $this->targetObject->getVar('description', 'e'), '100%', '100%'); |
||
99 | } |
||
100 | $this->addElement($descEditor); |
||
101 | // Total |
||
102 | $this->addElement(new XoopsFormText(\_AM_LEXIKON_CATEGORIES_TOTAL, 'total', 50, 255, $this->targetObject->getVar('total')), false); |
||
103 | // Weight |
||
104 | $this->addElement(new XoopsFormText(\_AM_LEXIKON_CATEGORIES_WEIGHT, 'weight', 50, 255, $this->targetObject->getVar('weight')), false); |
||
105 | // Logourl |
||
106 | $this->addElement(new XoopsFormText(\_AM_LEXIKON_CATEGORIES_LOGOURL, 'logourl', 50, 255, $this->targetObject->getVar('logourl')), false); |
||
107 | |||
108 | //permissions |
||
109 | /** @var \XoopsMemberHandler $memberHandler */ |
||
110 | $memberHandler = \xoops_getHandler('member'); |
||
111 | $groupList = $memberHandler->getGroupList(); |
||
112 | /** @var \XoopsGroupPermHandler $grouppermHandler */ |
||
113 | $grouppermHandler = \xoops_getHandler('groupperm'); |
||
114 | $fullList = \array_keys($groupList); |
||
115 | |||
116 | //======================================================================== |
||
117 | |||
118 | $mid = $GLOBALS['xoopsModule']->mid(); |
||
119 | $groupIdAdmin = 0; |
||
120 | $groupNameAdmin = ''; |
||
121 | |||
122 | // create admin checkbox |
||
123 | foreach ($groupList as $groupId => $groupName) { |
||
124 | if (XOOPS_GROUP_ADMIN == $groupId) { |
||
125 | $groupIdAdmin = $groupId; |
||
126 | $groupNameAdmin = $groupName; |
||
127 | } |
||
128 | } |
||
129 | |||
130 | $selectPermAdmin = new XoopsFormCheckBox('', 'admin', XOOPS_GROUP_ADMIN); |
||
131 | $selectPermAdmin->addOption($groupIdAdmin, $groupNameAdmin); |
||
132 | $selectPermAdmin->setExtra("disabled='disabled'"); //comment it out, if you want to allow to remove permissions for the admin |
||
133 | |||
134 | // ******************************************************** |
||
135 | // permission view items |
||
136 | $cat_gperms_read = $grouppermHandler->getGroupIds('lexikon_view', $this->targetObject->getVar('categoryID'), $mid); |
||
137 | $arr_cat_gperms_read = $this->targetObject->isNew() ? '0' : $cat_gperms_read; |
||
138 | |||
139 | $permsTray = new XoopsFormElementTray(\_AM_LEXIKON_PERMISSIONS_VIEW, ''); |
||
140 | |||
141 | $selectAllReadCheckbox = new XoopsFormCheckBox('', 'adminbox1', 1); |
||
142 | $selectAllReadCheckbox->addOption('allbox', \_AM_SYSTEM_ALL); |
||
143 | $selectAllReadCheckbox->setExtra(" onclick='xoopsCheckGroup(\"form\", \"adminbox1\" , \"groupsRead[]\");' "); |
||
144 | $selectAllReadCheckbox->setClass('xo-checkall'); |
||
145 | $permsTray->addElement($selectAllReadCheckbox); |
||
146 | |||
147 | // checkbox webmaster |
||
148 | $permsTray->addElement($selectPermAdmin, false); |
||
149 | // checkboxes other groups |
||
150 | //$selectPerm = new \XoopsFormCheckBox('', 'cat_gperms_read', $arr_cat_gperms_read); |
||
151 | //$selectPerm = new \XoopsFormCheckBox('', 'groupsRead[]', $this->targetObject->getGroupsRead()); |
||
152 | $selectPerm = new XoopsFormCheckBox('', 'groupsRead[]', $arr_cat_gperms_read); |
||
153 | foreach ($groupList as $groupId => $groupName) { |
||
154 | if (XOOPS_GROUP_ADMIN != $groupId) { |
||
155 | $selectPerm->addOption($groupId, $groupName); |
||
156 | } |
||
157 | } |
||
158 | $permsTray->addElement($selectPerm, false); |
||
159 | $this->addElement($permsTray, false); |
||
160 | unset($permsTray, $selectPerm); |
||
161 | |||
162 | // ******************************************************** |
||
163 | // permission submit item |
||
164 | $cat_gperms_create = $grouppermHandler->getGroupIds('lexikon_submit', $this->targetObject->getVar('categoryID'), $mid); |
||
165 | $arr_cat_gperms_create = $this->targetObject->isNew() ? '0' : $cat_gperms_create; |
||
166 | |||
167 | $permsTray = new XoopsFormElementTray(\_AM_LEXIKON_PERMISSIONS_SUBMIT, ''); |
||
168 | |||
169 | $selectAllSubmitCheckbox = new XoopsFormCheckBox('', 'adminbox2', 1); |
||
170 | $selectAllSubmitCheckbox->addOption('allbox', \_AM_SYSTEM_ALL); |
||
171 | $selectAllSubmitCheckbox->setExtra(" onclick='xoopsCheckGroup(\"form\", \"adminbox2\" , \"groupsSubmit[]\");' "); |
||
172 | $selectAllSubmitCheckbox->setClass('xo-checkall'); |
||
173 | $permsTray->addElement($selectAllSubmitCheckbox); |
||
174 | |||
175 | // checkbox webmaster |
||
176 | $permsTray->addElement($selectPermAdmin, false); |
||
177 | // checkboxes other groups |
||
178 | //$selectPerm = new \XoopsFormCheckBox('', 'cat_gperms_create', $arr_cat_gperms_create); |
||
179 | $selectPerm = new XoopsFormCheckBox('', 'groupsSubmit[]', $arr_cat_gperms_create); |
||
180 | foreach ($groupList as $groupId => $groupName) { |
||
181 | if (XOOPS_GROUP_ADMIN != $groupId) { |
||
182 | $selectPerm->addOption($groupId, $groupName); |
||
183 | } |
||
184 | } |
||
185 | $permsTray->addElement($selectPerm, false); |
||
186 | $this->addElement($permsTray, false); |
||
187 | unset($permsTray, $selectPerm); |
||
188 | |||
189 | // ******************************************************** |
||
190 | // permission approve items |
||
191 | $cat_gperms_admin = $grouppermHandler->getGroupIds('lexikon_approve', $this->targetObject->getVar('categoryID'), $mid); |
||
192 | $arr_cat_gperms_admin = $this->targetObject->isNew() ? '0' : $cat_gperms_admin; |
||
193 | |||
194 | $permsTray = new XoopsFormElementTray(\_AM_LEXIKON_PERMISSIONS_APPROVE, ''); |
||
195 | |||
196 | $selectAllModerateCheckbox = new XoopsFormCheckBox('', 'adminbox3', 1); |
||
197 | $selectAllModerateCheckbox->addOption('allbox', \_AM_SYSTEM_ALL); |
||
198 | $selectAllModerateCheckbox->setExtra(" onclick='xoopsCheckGroup(\"form\", \"adminbox3\" , \"groupsModeration[]\");' "); |
||
199 | $selectAllModerateCheckbox->setClass('xo-checkall'); |
||
200 | $permsTray->addElement($selectAllModerateCheckbox); |
||
201 | |||
202 | // checkbox webmaster |
||
203 | $permsTray->addElement($selectPermAdmin, false); |
||
204 | // checkboxes other groups |
||
205 | //$selectPerm = new \XoopsFormCheckBox('', 'cat_gperms_admin', $arr_cat_gperms_admin); |
||
206 | $selectPerm = new XoopsFormCheckBox('', 'groupsModeration[]', $arr_cat_gperms_admin); |
||
207 | foreach ($groupList as $groupId => $groupName) { |
||
208 | if (XOOPS_GROUP_ADMIN != $groupId && XOOPS_GROUP_ANONYMOUS != $groupId) { |
||
209 | $selectPerm->addOption($groupId, $groupName); |
||
210 | } |
||
211 | } |
||
212 | $permsTray->addElement($selectPerm, false); |
||
213 | $this->addElement($permsTray, false); |
||
214 | unset($permsTray, $selectPerm); |
||
215 | |||
216 | //========================================================================= |
||
217 | $this->addElement(new XoopsFormHidden('op', 'save')); |
||
218 | $this->addElement(new XoopsFormButton('', 'submit', _SUBMIT, 'submit')); |
||
219 | } |
||
221 |