Conditions | 26 |
Paths | > 20000 |
Total Lines | 126 |
Code Lines | 87 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 1 | 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 |
||
92 | public function getForm($action = false) |
||
93 | { |
||
94 | $helper = \XoopsModules\Wgfilemanager\Helper::getInstance(); |
||
95 | $fileHandler = $helper->getHandler('File'); |
||
96 | $permissionsHandler = $helper->getHandler('Permissions'); |
||
97 | if (!$action) { |
||
98 | $action = $_SERVER['REQUEST_URI']; |
||
99 | } |
||
100 | $isAdmin = \is_object($GLOBALS['xoopsUser']) && $GLOBALS['xoopsUser']->isAdmin($GLOBALS['xoopsModule']->mid()); |
||
101 | // Title |
||
102 | $title = $this->isNew() ? \_MA_WGFILEMANAGER_FILE_ADD : \_MA_WGFILEMANAGER_FILE_EDIT; |
||
103 | // Get Theme Form |
||
104 | \xoops_load('XoopsFormLoader'); |
||
105 | $form = new \XoopsThemeForm($title, 'form', $action, 'post', true); |
||
106 | $form->setExtra('enctype="multipart/form-data"'); |
||
107 | //$form->addElement(new \XoopsFormHidden('formtype', $formType)); |
||
108 | // Form Table directory |
||
109 | $directoryId = (int)$this->getVar('directory_id'); |
||
110 | $directoryHandler = $helper->getHandler('Directory'); |
||
111 | $fileDirectory_idSelect = new \XoopsFormSelect(\_MA_WGFILEMANAGER_FILE_DIRECTORY_ID, 'directory_id', $directoryId); |
||
112 | $dirListSelect = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($directoryHandler->getDirListFormSelect(0))); |
||
113 | foreach ($dirListSelect as $key => $value) { |
||
114 | $fileDirectory_idSelect->addOption($key, $value); |
||
|
|||
115 | } |
||
116 | $form->addElement($fileDirectory_idSelect, true); |
||
117 | $form->addElement(new \XoopsFormHidden('directory_id_old', $directoryId)); |
||
118 | // Form File: Upload fileName |
||
119 | $fileName = $this->isNew() ? '' : $this->getVar('name'); |
||
120 | if ($this->isNew()) { |
||
121 | if ($permissionsHandler->getPermUploadFileToDir($directoryId)) { |
||
122 | $fileUploadTray = new \XoopsFormElementTray(\_MA_WGFILEMANAGER_FILE_NAME, '<br>'); |
||
123 | //$fileDirectory = '/uploads/wgfilemanager/files/file'; |
||
124 | //$fileUploadTray->addElement(new \XoopsFormLabel(\sprintf(\_MA_WGFILEMANAGER_FILE_NAME_UPLOADS, ".$fileDirectory/"), $fileName)); |
||
125 | $maxsize = $helper->getConfig('maxsize_file'); |
||
126 | $fileUploadTray->addElement(new \XoopsFormFile('', 'fil_name', $maxsize)); |
||
127 | $fileUploadTray->addElement(new \XoopsFormLabel(\_MA_WGFILEMANAGER_FORM_UPLOAD_SIZE, ($maxsize / 1048576) . ' ' . \_MA_WGFILEMANAGER_FORM_UPLOAD_SIZE_MB)); |
||
128 | $form->addElement($fileUploadTray, true); |
||
129 | } else { |
||
130 | $form->addElement(new \XoopsFormHidden('fil_name', $fileName)); |
||
131 | } |
||
132 | } else { |
||
133 | $form->addElement(new \XoopsFormText(\_MA_WGFILEMANAGER_FILE_NAME, 'fil_name', 100, 150, $fileName)); |
||
134 | $form->addElement(new \XoopsFormHidden('fil_name_old', $fileName)); |
||
135 | } |
||
136 | // Form Editor DhtmlTextArea fileDescription |
||
137 | $editorConfigs = []; |
||
138 | if ($isAdmin) { |
||
139 | $editor = $helper->getConfig('editor_admin'); |
||
140 | } else { |
||
141 | $editor = $helper->getConfig('editor_user'); |
||
142 | } |
||
143 | $editorConfigs['name'] = 'description'; |
||
144 | $editorConfigs['value'] = $this->getVar('description', 'e'); |
||
145 | $editorConfigs['rows'] = 5; |
||
146 | $editorConfigs['cols'] = 40; |
||
147 | $editorConfigs['width'] = '100%'; |
||
148 | $editorConfigs['height'] = '400px'; |
||
149 | $editorConfigs['editor'] = $editor; |
||
150 | $form->addElement(new \XoopsFormEditor(\_MA_WGFILEMANAGER_FILE_DESCRIPTION, 'description', $editorConfigs)); |
||
151 | // Form Text fileType |
||
152 | $fileType = $this->isNew() ? '' : $this->getVar('mimetype'); |
||
153 | if (!$this->isNew()) { |
||
154 | $form->addElement(new \XoopsFormLabel(\_MA_WGFILEMANAGER_FILE_MIMETYPE, $fileType)); |
||
155 | } |
||
156 | //$form->addElement(new \XoopsFormHidden('mimetype', $fileType)); |
||
157 | // Form Text Date file modification date |
||
158 | $fileSize = $this->isNew() ? \time() : $this->getVar('size'); |
||
159 | if (!$this->isNew()) { |
||
160 | $form->addElement(new \XoopsFormLabel(\_MA_WGFILEMANAGER_FILE_SIZE, $fileHandler->FileSizeConvert($fileSize))); |
||
161 | } |
||
162 | // Form Text Date file modification date |
||
163 | $fileMtime = $this->isNew() ? \time() : $this->getVar('mtime'); |
||
164 | if (!$this->isNew()) { |
||
165 | $form->addElement(new \XoopsFormLabel(\_MA_WGFILEMANAGER_FILE_MTIME, \formatTimestamp($fileMtime, 's'))); |
||
166 | } |
||
167 | // Form Text Date file creation date |
||
168 | $fileCtime = $this->isNew() ? \time() : $this->getVar('ctime'); |
||
169 | if (!$this->isNew()) { |
||
170 | $form->addElement(new \XoopsFormLabel(\_MA_WGFILEMANAGER_FILE_CTIME, \formatTimestamp($fileCtime, 's'))); |
||
171 | } |
||
172 | //$form->addElement(new \XoopsFormHidden('mtime', $fileMtime)); |
||
173 | //$form->addElement(new \XoopsFormTextDateSelect(\_MA_WGFILEMANAGER_FILE_MTIME, 'mtime', '', $fileMtime)); |
||
174 | // Form Text IP fileIp |
||
175 | $fileIp = $_SERVER['REMOTE_ADDR']; |
||
176 | if ($isAdmin) { |
||
177 | $form->addElement(new \XoopsFormText(\_MA_WGFILEMANAGER_FILE_IP, 'ip', 20, 150, $fileIp)); |
||
178 | } else { |
||
179 | $form->addElement(new \XoopsFormHidden('ip', $fileIp)); |
||
180 | } |
||
181 | // Form Select Status fileStatus |
||
182 | $fileStatus = $this->isNew() ? Constants::STATUS_SUBMITTED : $this->getVar('status'); |
||
183 | if ($isAdmin) { |
||
184 | $fileStatusSelect = new \XoopsFormSelect(\_MA_WGFILEMANAGER_FILE_STATUS, 'status', $fileStatus); |
||
185 | $fileStatusSelect->addOption(Constants::STATUS_NONE, \_AM_WGFILEMANAGER_STATUS_NONE); |
||
186 | //$fileStatusSelect->addOption(Constants::STATUS_OFFLINE, \_AM_WGFILEMANAGER_STATUS_OFFLINE); |
||
187 | $fileStatusSelect->addOption(Constants::STATUS_SUBMITTED, \_AM_WGFILEMANAGER_STATUS_SUBMITTED); |
||
188 | //$fileStatusSelect->addOption(Constants::STATUS_APPROVED, \_AM_WGFILEMANAGER_STATUS_APPROVED); |
||
189 | $fileStatusSelect->addOption(Constants::STATUS_BROKEN, \_AM_WGFILEMANAGER_STATUS_BROKEN); |
||
190 | $form->addElement($fileStatusSelect); |
||
191 | } else { |
||
192 | $form->addElement(new \XoopsFormHidden('status', $fileStatus)); |
||
193 | } |
||
194 | |||
195 | // Form Text Date Select fileDate_created |
||
196 | $fileDate_created = $this->isNew() ? \time() : $this->getVar('date_created'); |
||
197 | if ($isAdmin) { |
||
198 | $form->addElement(new \XoopsFormTextDateSelect(\_MA_WGFILEMANAGER_FILE_DATE_CREATED, 'date_created', '', $fileDate_created)); |
||
199 | } elseif (!$this->isNew()) { |
||
200 | $form->addElement(new \XoopsFormLabel(\_MA_WGFILEMANAGER_FILE_DATE_CREATED, \formatTimestamp($fileDate_created, 's'))); |
||
201 | } |
||
202 | |||
203 | // Form Select User fileSubmitter |
||
204 | $uidCurrent = \is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->uid() : 0; |
||
205 | $fileSubmitter = $this->isNew() ? $uidCurrent : $this->getVar('submitter'); |
||
206 | if ($isAdmin) { |
||
207 | $form->addElement(new \XoopsFormSelectUser(\_MA_WGFILEMANAGER_FILE_SUBMITTER, 'submitter', false, $fileSubmitter)); |
||
208 | } else { |
||
209 | $form->addElement(new \XoopsFormLabel(\_MA_WGFILEMANAGER_FILE_SUBMITTER, \XoopsUser::getUnameFromId($fileSubmitter))); |
||
210 | $form->addElement(new \XoopsFormHidden('submitter', $fileSubmitter)); |
||
211 | } |
||
212 | // To Save |
||
213 | $form->addElement(new \XoopsFormHidden('op', 'save')); |
||
214 | $form->addElement(new \XoopsFormHidden('start', $this->start)); |
||
215 | $form->addElement(new \XoopsFormHidden('limit', $this->limit)); |
||
216 | $form->addElement(new \XoopsFormButtonTray('', \_SUBMIT, 'submit', '', false)); |
||
217 | return $form; |
||
218 | } |
||
311 |