Conditions | 10 |
Paths | 5 |
Total Lines | 187 |
Code Lines | 123 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 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 |
||
47 | function ManageUltimateMenu() |
||
|
|||
48 | { |
||
49 | global $context, $txt, $scripturl; |
||
50 | |||
51 | // Get rid of all of em! |
||
52 | if (!empty($_POST['removeAll'])) |
||
53 | { |
||
54 | checkSession(); |
||
55 | $this->um->deleteallButtons(); |
||
56 | $this->um->rebuildMenu(); |
||
57 | redirectexit('action=admin;area=umen'); |
||
58 | } |
||
59 | // User pressed the 'remove selection button'. |
||
60 | elseif (!empty($_POST['removeButtons']) && !empty($_POST['remove']) && is_array($_POST['remove'])) |
||
61 | { |
||
62 | checkSession(); |
||
63 | |||
64 | // Make sure every entry is a proper integer. |
||
65 | foreach ($_POST['remove'] as $index => $page_id) |
||
66 | $_POST['remove'][(int) $index] = (int) $page_id; |
||
67 | |||
68 | // Delete the page(s)! |
||
69 | $this->um->deleteButton($_POST['remove']); |
||
70 | $this->um->rebuildMenu(); |
||
71 | redirectexit('action=admin;area=umen'); |
||
72 | } |
||
73 | // Changing the status? |
||
74 | elseif (isset($_POST['save'])) |
||
75 | { |
||
76 | checkSession(); |
||
77 | $this->um->updateButton($_POST); |
||
78 | $this->um->rebuildMenu(); |
||
79 | redirectexit('action=admin;area=umen'); |
||
80 | } |
||
81 | // New item? |
||
82 | elseif (isset($_POST['new'])) |
||
83 | redirectexit('action=admin;area=umen;sa=addbutton'); |
||
84 | |||
85 | $button_names = $this->um->getButtonNames(); |
||
86 | $listOptions = array( |
||
87 | 'id' => 'menu_list', |
||
88 | 'items_per_page' => 20, |
||
89 | 'base_href' => $scripturl . '?action=admin;area=umen;sa=manmenu', |
||
90 | 'default_sort_col' => 'name', |
||
91 | 'default_sort_dir' => 'desc', |
||
92 | 'get_items' => array( |
||
93 | 'function' => array($this->um, 'list_getMenu'), |
||
94 | ), |
||
95 | 'get_count' => array( |
||
96 | 'function' => array($this->um, 'list_getNumButtons'), |
||
97 | ), |
||
98 | 'no_items_label' => $txt['um_menu_no_buttons'], |
||
99 | 'columns' => array( |
||
100 | 'name' => array( |
||
101 | 'header' => array( |
||
102 | 'value' => $txt['um_menu_button_name'], |
||
103 | ), |
||
104 | 'data' => array( |
||
105 | 'db_htmlsafe' => 'name', |
||
106 | ), |
||
107 | 'sort' => array( |
||
108 | 'default' => 'name', |
||
109 | 'reverse' => 'name DESC', |
||
110 | ), |
||
111 | ), |
||
112 | 'type' => array( |
||
113 | 'header' => array( |
||
114 | 'value' => $txt['um_menu_button_type'], |
||
115 | ), |
||
116 | 'data' => array( |
||
117 | 'function' => function($rowData) use ($txt) |
||
118 | { |
||
119 | return $txt['um_menu_' . $rowData['type'] . '_link']; |
||
120 | }, |
||
121 | ), |
||
122 | 'sort' => array( |
||
123 | 'default' => 'type', |
||
124 | 'reverse' => 'type DESC', |
||
125 | ), |
||
126 | ), |
||
127 | 'position' => array( |
||
128 | 'header' => array( |
||
129 | 'value' => $txt['um_menu_button_position'], |
||
130 | ), |
||
131 | 'data' => array( |
||
132 | 'function' => function($rowData) use ($txt, $button_names) |
||
133 | { |
||
134 | return sprintf( |
||
135 | '%s %s', |
||
136 | $txt['um_menu_' . $rowData['position']], |
||
137 | isset($button_names[$rowData['parent']]) |
||
138 | ? $button_names[$rowData['parent']] |
||
139 | : ucwords($rowData['parent']) |
||
140 | ); |
||
141 | }, |
||
142 | ), |
||
143 | 'sort' => array( |
||
144 | 'default' => 'position', |
||
145 | 'reverse' => 'position DESC', |
||
146 | ), |
||
147 | ), |
||
148 | 'link' => array( |
||
149 | 'header' => array( |
||
150 | 'value' => $txt['um_menu_button_link'], |
||
151 | ), |
||
152 | 'data' => array( |
||
153 | 'db_htmlsafe' => 'link', |
||
154 | ), |
||
155 | 'sort' => array( |
||
156 | 'default' => 'link', |
||
157 | 'reverse' => 'link DESC', |
||
158 | ), |
||
159 | ), |
||
160 | 'status' => array( |
||
161 | 'header' => array( |
||
162 | 'value' => $txt['um_menu_button_active'], |
||
163 | 'class' => 'centertext', |
||
164 | ), |
||
165 | 'data' => array( |
||
166 | 'function' => function($rowData) |
||
167 | { |
||
168 | return sprintf( |
||
169 | '<input type="checkbox" name="status[%1$s]" id="status_%1$s" value="%1$s"%2$s />', |
||
170 | $rowData['id_button'], |
||
171 | $rowData['status'] == 'inactive' ? '' : ' checked="checked"' |
||
172 | ); |
||
173 | }, |
||
174 | 'class' => 'centertext', |
||
175 | ), |
||
176 | 'sort' => array( |
||
177 | 'default' => 'status', |
||
178 | 'reverse' => 'status DESC', |
||
179 | ), |
||
180 | ), |
||
181 | 'actions' => array( |
||
182 | 'header' => array( |
||
183 | 'value' => $txt['um_menu_actions'], |
||
184 | 'class' => 'centertext', |
||
185 | ), |
||
186 | 'data' => array( |
||
187 | 'function' => function($rowData) use ($txt) |
||
188 | { |
||
189 | return sprintf( |
||
190 | '<a href="%s?action=admin;area=umen;sa=addbutton;edit;in=%d">%s</a>', |
||
191 | $scripturl, |
||
192 | $rowData['id_button'], |
||
193 | $txt['modify'] |
||
194 | ); |
||
195 | }, |
||
196 | 'class' => 'centertext', |
||
197 | ), |
||
198 | ), |
||
199 | 'check' => array( |
||
200 | 'header' => array( |
||
201 | 'value' => '<input type="checkbox" onclick="invertAll(this, this.form);" class="input_check" />', |
||
202 | 'class' => 'centertext', |
||
203 | ), |
||
204 | 'data' => array( |
||
205 | 'sprintf' => array( |
||
206 | 'format' => '<input type="checkbox" name="remove[]" value="%d" class="input_check" />', |
||
207 | 'params' => array( |
||
208 | 'id_button' => false, |
||
209 | ), |
||
210 | ), |
||
211 | 'class' => 'centertext', |
||
212 | ), |
||
213 | ), |
||
214 | ), |
||
215 | 'form' => array( |
||
216 | 'href' => $scripturl . '?action=admin;area=umen;sa=manmenu', |
||
217 | ), |
||
218 | 'additional_rows' => array( |
||
219 | array( |
||
220 | 'position' => 'below_table_data', |
||
221 | 'value' => ' |
||
222 | <input type="submit" name="removeButtons" value="' . $txt['um_menu_remove_selected'] . '" onclick="return confirm(\'' . $txt['um_menu_remove_confirm'] . '\');" class="button_submit" /> |
||
223 | <input type="submit" name="removeAll" value="' . $txt['um_menu_remove_all'] . '" onclick="return confirm(\'' . $txt['um_menu_remove_all_confirm'] . '\');" class="button_submit" /> |
||
224 | <input type="submit" name="new" value="' . $txt['um_admin_add_button'] . '" class="button_submit" /> |
||
225 | <input type="submit" name="save" value="' . $txt['save'] . '" class="button_submit" />', |
||
226 | 'class' => 'righttext', |
||
227 | ), |
||
228 | ), |
||
229 | ); |
||
230 | require_once $sourcedir . '/Subs-List.php'; |
||
231 | createList($listOptions); |
||
232 | $context['sub_template'] = 'show_list'; |
||
233 | $context['default_list'] = 'menu_list'; |
||
234 | } |
||
401 |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.