Conditions | 10 |
Paths | 48 |
Total Lines | 161 |
Code Lines | 95 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
32 | function editcol($columnID = '') |
||
33 | { |
||
34 | global $indexAdmin; |
||
35 | global $xoopsUser, $xoopsConfig, $xoopsModule, $xoopsLogger, $xoopsOption, $xoopsUserIsAdmin; |
||
36 | /** @var Soapbox\Helper $helper */ |
||
37 | $helper = Soapbox\Helper::getInstance(); |
||
38 | |||
39 | $adminObject = \Xmf\Module\Admin::getInstance(); |
||
40 | $xoopsDB = \XoopsDatabaseFactory::getDatabaseConnection(); |
||
|
|||
41 | $myts = \MyTextSanitizer::getInstance(); |
||
42 | |||
43 | require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||
44 | $columnID = (int)$columnID; |
||
45 | /** @var \XoopsModules\Soapbox\EntrydataHandler $entrydataHandler */ |
||
46 | $entrydataHandler = new \XoopsModules\Soapbox\EntrydataHandler(); |
||
47 | // If there is a parameter, and the id exists, retrieve data: we're editing a column |
||
48 | if (0 !== $columnID) { |
||
49 | //get category object |
||
50 | $_categoryob = $entrydataHandler->getColumn($columnID); |
||
51 | if (!is_object($_categoryob)) { |
||
52 | redirect_header('index.php', 1, _AM_SOAPBOX_NOCOLTOEDIT); |
||
53 | } |
||
54 | //get vars |
||
55 | $category_vars = $_categoryob->getVars(); |
||
56 | foreach ($category_vars as $k => $v) { |
||
57 | $e_category[$k] = $_categoryob->getVar($k, 'E'); |
||
58 | } |
||
59 | |||
60 | xoops_cp_header(); |
||
61 | $adminObject->displayNavigation(basename(__FILE__)); |
||
62 | //adminMenu(1, _AM_SOAPBOX_COLS._AM_SOAPBOX_EDITING . $_categoryob->getVar('name') . "'"); |
||
63 | //echo "<h3 style='color: #2F5376; '>"._AM_SOAPBOX_ADMINCOLMNGMT."</h3>"; |
||
64 | |||
65 | //editcol(0); |
||
66 | |||
67 | $sform = new \XoopsThemeForm(_AM_SOAPBOX_MODCOL . ': ' . $_categoryob->getVar('name'), 'op', $myts->htmlSpecialChars(xoops_getenv('PHP_SELF')), 'post', true); |
||
68 | } else { |
||
69 | $_categoryob = $entrydataHandler->createColumn(true); |
||
70 | //mb $_categoryob->cleanVars(); |
||
71 | |||
72 | //get vars |
||
73 | $category_vars = $_categoryob->getVars(); |
||
74 | foreach ($category_vars as $k => $v) { |
||
75 | $e_category[$k] = $_categoryob->getVar($k, 'E'); |
||
76 | } |
||
77 | |||
78 | $e_category['weight'] = 1; |
||
79 | $e_category['author'] = $xoopsUser->uid(); |
||
80 | |||
81 | xoops_cp_header(); |
||
82 | $adminObject->displayNavigation(basename(__FILE__)); |
||
83 | //adminMenu(1, _AM_SOAPBOX_COLS._AM_SOAPBOX_CREATINGCOL); |
||
84 | //echo "<h3 style='color: #2F5376; '>"._AM_SOAPBOX_ADMINCOLMNGMT."</h3>"; |
||
85 | |||
86 | //editcol(0); |
||
87 | |||
88 | $sform = new \XoopsThemeForm(_AM_SOAPBOX_NEWCOL, 'op', $myts->htmlSpecialChars(xoops_getenv('PHP_SELF')), 'post', true); |
||
89 | } |
||
90 | |||
91 | $sform->setExtra('enctype="multipart/form-data"'); |
||
92 | $sform->addElement(new \XoopsFormText(_AM_SOAPBOX_COLNAME, 'name', 50, 80, $e_category['name']), true); |
||
93 | |||
94 | /* |
||
95 | ob_start(); |
||
96 | getuserForm((int)($e_category['author'])); |
||
97 | $sform->addElement(new \XoopsFormLabel(_AM_SOAPBOX_AUTHOR, ob_get_contents())); |
||
98 | ob_end_clean(); |
||
99 | */ |
||
100 | require_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
||
101 | |||
102 | $userstart = \Xmf\Request::getInt('userstart', 0, 'GET'); |
||
103 | |||
104 | $memberHandler = xoops_getHandler('member'); |
||
105 | $usercount = $memberHandler->getUserCount(); |
||
106 | // Selector to get author |
||
107 | if (empty($e_category['author'])) { |
||
108 | $authorid = $xoopsUser->uid(); |
||
109 | $authoruname = $xoopsUser->uname(); |
||
110 | } else { |
||
111 | $author_ob = $memberHandler->getUser($e_category['author']); |
||
112 | $authorid = $author_ob->uid(); |
||
113 | $authoruname = $author_ob->uname(); |
||
114 | } |
||
115 | $criteria = new \CriteriaCompo(); |
||
116 | $criteria->add(new \Criteria('uid', $authorid, '!=')); |
||
117 | $criteria->setSort('uname'); |
||
118 | $criteria->setOrder('ASC'); |
||
119 | $criteria->setLimit(199); |
||
120 | $criteria->setStart($userstart); |
||
121 | $user_list_arr = [$authorid => $authoruname] + $memberHandler->getUserList($criteria); |
||
122 | |||
123 | $nav = new \XoopsPageNav($usercount, 200, $userstart, 'userstart', $myts->htmlSpecialChars('op=mod&columnID=' . $columnID)); |
||
124 | |||
125 | $user_select = new \XoopsFormSelect('', 'author', $authorid); |
||
126 | $user_select->addOptionArray($user_list_arr); |
||
127 | $user_select_tray = new \XoopsFormElementTray(_AM_SOAPBOX_AUTHOR, '<br>'); |
||
128 | $user_select_tray->addElement($user_select); |
||
129 | $user_select_nav = new \XoopsFormLabel('', $nav->renderNav(4)); |
||
130 | $user_select_tray->addElement($user_select_nav); |
||
131 | $sform->addElement($user_select_tray); |
||
132 | |||
133 | //HACK by domifara for Wysiwyg |
||
134 | $sform->addElement(new \XoopsFormTextArea(_AM_SOAPBOX_COLDESCRIPT, 'description', $e_category['description'], 7, 60)); |
||
135 | // $editor=soapbox_getWysiwygForm($helper->getConfig('editorUser') , _AM_SOAPBOX_COLDESCRIPT, 'description', $e_category['description'], '100%', '300px'); |
||
136 | // $sform->addElement($editor,true); |
||
137 | |||
138 | $sform->addElement(new \XoopsFormText(_AM_SOAPBOX_COLPOSIT, 'weight', 4, 4, $e_category['weight'])); |
||
139 | |||
140 | // notification public |
||
141 | $notifypub_radio = new \XoopsFormRadioYN(_AM_SOAPBOX_NOTIFY, 'notifypub', $e_category['notifypub'], ' ' . _AM_SOAPBOX_YES . '', ' ' . _AM_SOAPBOX_NO . ''); |
||
142 | $sform->addElement($notifypub_radio); |
||
143 | |||
144 | if (!isset($e_category['colimage']) || empty($e_category['colimage']) || '' === $e_category['colimage']) { |
||
145 | $e_category['colimage'] = 'nopicture.png'; |
||
146 | } |
||
147 | $graph_array = \XoopsLists:: getImgListAsArray(XOOPS_ROOT_PATH . '/' . $myts->htmlSpecialChars($helper->getConfig('sbuploaddir'))); |
||
148 | $colimage_select = new \XoopsFormSelect('', 'colimage', $e_category['colimage']); |
||
149 | $colimage_select->addOptionArray($graph_array); |
||
150 | $colimage_select->setExtra("onchange='showImgSelected(\"image3\", \"colimage\", \"" . $myts->htmlSpecialChars($helper->getConfig('sbuploaddir')) . '", "", "' . XOOPS_URL . "\")'"); |
||
151 | $colimage_tray = new \XoopsFormElementTray(_AM_SOAPBOX_COLIMAGE, ' '); |
||
152 | $colimage_tray->addElement($colimage_select); |
||
153 | $colimage_tray->addElement(new \XoopsFormLabel('', "<br><br><img src='" . XOOPS_URL . '/' . $myts->htmlSpecialChars($helper->getConfig('sbuploaddir')) . '/' . $e_category['colimage'] . "' name='image3' id='image3' alt=''>")); |
||
154 | $sform->addElement($colimage_tray); |
||
155 | |||
156 | // Code to call the file browser to select an image to upload |
||
157 | $sform->addElement(new \XoopsFormFile(_AM_SOAPBOX_COLIMAGEUPLOAD, 'cimage', (int)$helper->getConfig('maxfilesize')), false); |
||
158 | |||
159 | $sform->addElement(new \XoopsFormHidden('columnID', $e_category['columnID'])); |
||
160 | |||
161 | $buttonTray = new \XoopsFormElementTray('', ''); |
||
162 | $hidden = new \XoopsFormHidden('op', 'addcol'); |
||
163 | $buttonTray->addElement($hidden); |
||
164 | |||
165 | // No ID for column -- then it's new column, button says 'Create' |
||
166 | if (empty($e_category['columnID'])) { |
||
167 | $butt_create = new \XoopsFormButton('', '', _AM_SOAPBOX_CREATE, 'submit'); |
||
168 | $butt_create->setExtra('onclick="this.form.elements.op.value=\'addcol\'"'); |
||
169 | $buttonTray->addElement($butt_create); |
||
170 | |||
171 | $butt_clear = new \XoopsFormButton('', '', _AM_SOAPBOX_CLEAR, 'reset'); |
||
172 | $buttonTray->addElement($butt_clear); |
||
173 | |||
174 | $butt_cancel = new \XoopsFormButton('', '', _AM_SOAPBOX_CANCEL, 'button'); |
||
175 | $butt_cancel->setExtra('onclick="history.go(-1)"'); |
||
176 | $buttonTray->addElement($butt_cancel); |
||
177 | } else { // button says 'Update' |
||
178 | $butt_create = new \XoopsFormButton('', '', _AM_SOAPBOX_MODIFY, 'submit'); |
||
179 | $butt_create->setExtra('onclick="this.form.elements.op.value=\'addcol\'"'); |
||
180 | $buttonTray->addElement($butt_create); |
||
181 | |||
182 | $butt_cancel = new \XoopsFormButton('', '', _AM_SOAPBOX_CANCEL, 'button'); |
||
183 | $butt_cancel->setExtra('onclick="history.go(-1)"'); |
||
184 | $buttonTray->addElement($butt_cancel); |
||
185 | } |
||
186 | |||
187 | $sform->addElement($buttonTray); |
||
188 | //----------- |
||
189 | // $xoopsGTicket->addTicketXoopsFormElement($sform, __LINE__); |
||
190 | //----------- |
||
191 | $sform->display(); |
||
192 | unset($hidden); |
||
193 | } |
||
377 |