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