Conditions | 12 |
Paths | 2048 |
Total Lines | 80 |
Code Lines | 54 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
88 | public function getFormImages($action = false) |
||
89 | { |
||
90 | $moduleDirName = \basename(\dirname(__DIR__, 2)); |
||
91 | $moduleDirNameUpper = \mb_strtoupper($moduleDirName); |
||
92 | $helper = Helper::getInstance(); |
||
93 | if (!$action) { |
||
94 | $action = $_SERVER['REQUEST_URI']; |
||
95 | } |
||
96 | // Title |
||
97 | $title = $this->isNew() ? \sprintf(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_ADD')) : \sprintf(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_EDIT')); |
||
98 | // Get Theme Form |
||
99 | \xoops_load('XoopsFormLoader'); |
||
100 | $form = new \XoopsThemeForm($title, 'form', $action, 'post', true); |
||
101 | $form->setExtra('enctype="multipart/form-data"'); |
||
102 | // Form Text ImgTitle |
||
103 | $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_TITLE'), 'img_title', 50, 255, $this->getVar('img_title'))); |
||
|
|||
104 | // Form editor ImgDesc |
||
105 | $editorConfigs = []; |
||
106 | $editorConfigs['name'] = 'img_desc'; |
||
107 | $editorConfigs['value'] = $this->getVar('img_desc', 'e'); |
||
108 | $editorConfigs['rows'] = 5; |
||
109 | $editorConfigs['cols'] = 40; |
||
110 | $editorConfigs['width'] = '100%'; |
||
111 | $editorConfigs['height'] = '400px'; |
||
112 | $editorConfigs['editor'] = $helper->getConfig('editor'); |
||
113 | $form->addElement(new \XoopsFormEditor(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_DESC'), 'img_desc', $editorConfigs)); |
||
114 | // Form Text ImgName |
||
115 | $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_NAME'), 'img_name', 50, 255, $this->getVar('img_name')), true); |
||
116 | // Form Text ImgNameLarge |
||
117 | $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_NAMELARGE'), 'img_namelarge', 50, 255, $this->getVar('img_namelarge')), true); |
||
118 | // Form Text ImgOrigname |
||
119 | $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_NAMEORIG'), 'img_nameorig', 50, 255, $this->getVar('img_nameorig')), true); |
||
120 | // Form Text ImgMimetype |
||
121 | $imgMimetype = $this->isNew() ? '0' : $this->getVar('img_mimetype'); |
||
122 | $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_MIMETYPE'), 'img_mimetype', 20, 150, $imgMimetype)); |
||
123 | // Form Text ImgSize |
||
124 | $imgSize = $this->isNew() ? '0' : $this->getVar('img_size'); |
||
125 | $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_SIZE'), 'img_size', 20, 150, $imgSize)); |
||
126 | // Form Text ImgResx |
||
127 | $imgResx = $this->isNew() ? '0' : $this->getVar('img_resx'); |
||
128 | $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_RESX'), 'img_resx', 20, 150, $imgResx)); |
||
129 | // Form Text ImgResy |
||
130 | $imgResy = $this->isNew() ? '0' : $this->getVar('img_resy'); |
||
131 | $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_RESY'), 'img_resy', 20, 150, $imgResy)); |
||
132 | // Form Text ImgDownloads |
||
133 | $imgDownloads = $this->isNew() ? '0' : $this->getVar('img_downloads'); |
||
134 | $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_DOWNLOADS'), 'img_downloads', 20, 150, $imgDownloads)); |
||
135 | // Form Text ImgRatinglikes |
||
136 | $imgRatinglikes = $this->isNew() ? '0' : $this->getVar('img_ratinglikes'); |
||
137 | $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_RATINGLIKES'), 'img_ratinglikes', 20, 150, $imgRatinglikes)); |
||
138 | // Form Text ImgVotes |
||
139 | $imgVotes = $this->isNew() ? '0' : $this->getVar('img_votes'); |
||
140 | $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_VOTES'), 'img_votes', 20, 150, $imgVotes)); |
||
141 | // Form Text ImgWeight |
||
142 | $imgWeight = $this->isNew() ? '0' : $this->getVar('img_weight'); |
||
143 | $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_WEIGHT'), 'img_weight', 20, 150, $imgWeight)); |
||
144 | // Form Table albums |
||
145 | /** @var \XoopsModules\Tdmdownloads\Common\ImagesHandler $albumsHandler */ |
||
146 | $albumsHandler = $helper->getHandler('Albums'); |
||
147 | $imgAlbidSelect = new \XoopsFormSelect(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_ALBID'), 'img_albid', $this->getVar('img_albid')); |
||
148 | $imgAlbidSelect->addOptionArray($albumsHandler->getList()); |
||
149 | $form->addElement($imgAlbidSelect, true); |
||
150 | // Images handler |
||
151 | $imagesHandler = $helper->getHandler('Images'); |
||
152 | // Form Select Images |
||
153 | $imgStateSelect = new \XoopsFormSelect(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_STATE'), 'img_state', $this->getVar('img_state')); |
||
154 | $imgStateSelect->addOption('Empty'); |
||
155 | $imgStateSelect->addOptionArray($imagesHandler->getList()); |
||
156 | $form->addElement($imgStateSelect, true); |
||
157 | // Form Text Date Select ImgDate |
||
158 | $imgDate = $this->isNew() ? 0 : $this->getVar('img_date'); |
||
159 | $form->addElement(new \XoopsFormTextDateSelect(\constant('CO_' . $moduleDirNameUpper . '_' . 'DATE'), 'img_date', '', $imgDate)); |
||
160 | // Form Select User ImgSubmitter |
||
161 | $form->addElement(new \XoopsFormSelectUser(\constant('CO_' . $moduleDirNameUpper . '_' . 'SUBMITTER'), 'img_submitter', false, $this->getVar('img_submitter'))); |
||
162 | // Form Text ImgIp |
||
163 | $form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_IP'), 'img_ip', 50, 255, $this->getVar('img_ip'))); |
||
164 | // To Save |
||
165 | $form->addElement(new \XoopsFormHidden('op', 'save')); |
||
166 | $form->addElement(new \XoopsFormButtonTray('', \_SUBMIT, 'submit', '', false)); |
||
167 | return $form; |
||
168 | } |
||
229 |