| Conditions | 6 |
| Paths | 12 |
| Total Lines | 144 |
| Code Lines | 79 |
| 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 |
||
| 48 | public function __construct($target) |
||
| 49 | { |
||
| 50 | $this->helper = $target->helper; |
||
| 51 | $this->targetObject = $target; |
||
| 52 | |||
| 53 | $title = $this->targetObject->isNew() ? sprintf(AM_ADSLIGHT_LISTING_ADD) : sprintf(AM_ADSLIGHT_LISTING_EDIT); |
||
| 54 | parent::__construct($title, 'form', xoops_getenv('SCRIPT_NAME'),'post', true); |
||
| 55 | $this->setExtra('enctype="multipart/form-data"'); |
||
| 56 | |||
| 57 | |||
| 58 | |||
| 59 | //include ID field, it's needed so the module knows if it is a new form or an edited form |
||
| 60 | |||
| 61 | |||
| 62 | $hidden = new \XoopsFormHidden('lid', $this->targetObject->getVar('lid')); |
||
| 63 | $this->addElement($hidden); |
||
| 64 | unset($hidden); |
||
| 65 | |||
| 66 | // Lid |
||
| 67 | $this->addElement(new \XoopsFormLabel(AM_ADSLIGHT_LISTING_LID, $this->targetObject->getVar('lid'), 'lid' )); |
||
| 68 | // Cid |
||
| 69 | //$categoriesHandler = $this->helper->getHandler('Categories'); |
||
| 70 | //$db = \XoopsDatabaseFactory::getDatabaseConnection(); |
||
| 71 | /** @var \XoopsPersistableObjectHandler $categoriesHandler */ |
||
| 72 | $categoriesHandler = $this->helper->getHandler('Categories'); |
||
| 73 | |||
| 74 | |||
| 75 | $categories_id_select = new \XoopsFormSelect(AM_ADSLIGHT_LISTING_CID, 'cid', $this->targetObject->getVar('cid')); |
||
| 76 | $categories_id_select->addOptionArray($categoriesHandler->getList()); |
||
| 77 | $this->addElement($categories_id_select, false); |
||
| 78 | // Title |
||
| 79 | $this->addElement(new \XoopsFormText(AM_ADSLIGHT_LISTING_TITLE, 'title', 50, 255, $this->targetObject->getVar('title')), false); |
||
| 80 | // Status |
||
| 81 | $this->addElement(new \XoopsFormText(AM_ADSLIGHT_LISTING_STATUS, 'status', 50, 255, $this->targetObject->getVar('status')), false); |
||
| 82 | // Expire |
||
| 83 | $this->addElement(new \XoopsFormText(AM_ADSLIGHT_LISTING_EXPIRE, 'expire', 50, 255, $this->targetObject->getVar('expire')), false); |
||
| 84 | // Type |
||
| 85 | //$typeHandler = $this->helper->getHandler('Type'); |
||
| 86 | //$db = \XoopsDatabaseFactory::getDatabaseConnection(); |
||
| 87 | /** @var \XoopsPersistableObjectHandler $typeHandler */ |
||
| 88 | $typeHandler = $this->helper->getHandler('Type'); |
||
| 89 | |||
| 90 | |||
| 91 | $type_id_select = new \XoopsFormSelect(AM_ADSLIGHT_LISTING_TYPE, 'type', $this->targetObject->getVar('type')); |
||
| 92 | $type_id_select->addOptionArray($typeHandler->getList()); |
||
| 93 | $this->addElement($type_id_select, false); |
||
| 94 | // Desctext |
||
| 95 | if (class_exists('XoopsFormEditor')) { |
||
| 96 | $editorOptions = []; |
||
| 97 | $editorOptions['name'] = 'desctext'; |
||
| 98 | $editorOptions['value'] = $this->targetObject->getVar('desctext', 'e'); |
||
| 99 | $editorOptions['rows'] = 5; |
||
| 100 | $editorOptions['cols'] = 40; |
||
| 101 | $editorOptions['width'] = '100%'; |
||
| 102 | $editorOptions['height'] = '400px'; |
||
| 103 | //$editorOptions['editor'] = xoops_getModuleOption('adslight_editor', 'adslight'); |
||
| 104 | //$this->addElement( new \XoopsFormEditor(AM_ADSLIGHT_LISTING_DESCTEXT, 'desctext', $editorOptions), false ); |
||
| 105 | if ($this->helper->isUserAdmin()) { |
||
| 106 | $descEditor = new \XoopsFormEditor(AM_ADSLIGHT_LISTING_DESCTEXT, $this->helper->getConfig('adslightEditorAdmin'), $editorOptions, $nohtml = false, $onfailure = 'textarea'); |
||
| 107 | } else { |
||
| 108 | $descEditor = new \XoopsFormEditor(AM_ADSLIGHT_LISTING_DESCTEXT, $this->helper->getConfig('adslightEditorUser'), $editorOptions, $nohtml = false, $onfailure = 'textarea'); |
||
| 109 | } |
||
| 110 | } else { |
||
| 111 | $descEditor = new \XoopsFormDhtmlTextArea(AM_ADSLIGHT_LISTING_DESCTEXT, 'description', $this->targetObject->getVar('description', 'e'), 5, 50); |
||
| 112 | } |
||
| 113 | $this->addElement($descEditor); |
||
| 114 | // Tel |
||
| 115 | $this->addElement(new \XoopsFormText(AM_ADSLIGHT_LISTING_TEL, 'tel', 50, 255, $this->targetObject->getVar('tel')), false); |
||
| 116 | // Price |
||
| 117 | $this->addElement(new \XoopsFormText(AM_ADSLIGHT_LISTING_PRICE, 'price', 50, 255, $this->targetObject->getVar('price')), false); |
||
| 118 | // Typeprice |
||
| 119 | //$priceHandler = $this->helper->getHandler('Price'); |
||
| 120 | //$db = \XoopsDatabaseFactory::getDatabaseConnection(); |
||
| 121 | /** @var \XoopsPersistableObjectHandler $priceHandler */ |
||
| 122 | $priceHandler = $this->helper->getHandler('Price'); |
||
| 123 | |||
| 124 | |||
| 125 | $price_id_select = new \XoopsFormSelect(AM_ADSLIGHT_LISTING_TYPEPRICE, 'typeprice', $this->targetObject->getVar('typeprice')); |
||
| 126 | $price_id_select->addOptionArray($priceHandler->getList()); |
||
| 127 | $this->addElement($price_id_select, false); |
||
| 128 | // Typecondition |
||
| 129 | //$conditionHandler = $this->helper->getHandler('Condition'); |
||
| 130 | //$db = \XoopsDatabaseFactory::getDatabaseConnection(); |
||
| 131 | /** @var \XoopsPersistableObjectHandler $conditionHandler */ |
||
| 132 | $conditionHandler = $this->helper->getHandler('Condition'); |
||
| 133 | |||
| 134 | |||
| 135 | $condition_id_select = new \XoopsFormSelect(AM_ADSLIGHT_LISTING_TYPECONDITION, 'typecondition', $this->targetObject->getVar('typecondition')); |
||
| 136 | $condition_id_select->addOptionArray($conditionHandler->getList()); |
||
| 137 | $this->addElement($condition_id_select, false); |
||
| 138 | // Date_created |
||
| 139 | $this->addElement(new \XoopsFormDateTime(AM_ADSLIGHT_LISTING_DATE_CREATED, 'date_created', 0, $this->targetObject->getVar('date_created'))); |
||
| 140 | |||
| 141 | $this->addElement(new \XoopsFormText(AM_ADSLIGHT_LISTING_EMAIL, 'email', 50, 255, $this->targetObject->getVar('email')), false); |
||
| 142 | // Submitter |
||
| 143 | $this->addElement(new \XoopsFormSelectUser(AM_ADSLIGHT_LISTING_SUBMITTER, 'submitter', false, $this->targetObject->getVar('submitter'), 1, false), false); |
||
| 144 | // Usid |
||
| 145 | $this->addElement(new \XoopsFormText(AM_ADSLIGHT_LISTING_USID, 'usid', 50, 255, $this->targetObject->getVar('usid')), false); |
||
| 146 | // Town |
||
| 147 | $this->addElement(new \XoopsFormText(AM_ADSLIGHT_LISTING_TOWN, 'town', 50, 255, $this->targetObject->getVar('town')), false); |
||
| 148 | // Country |
||
| 149 | $this->addElement(new \XoopsFormSelectCountry(AM_ADSLIGHT_LISTING_COUNTRY, 'country', $this->targetObject->getVar('country')), false); |
||
| 150 | // Contactby |
||
| 151 | $this->addElement(new \XoopsFormText(AM_ADSLIGHT_LISTING_CONTACTBY, 'contactby', 50, 255, $this->targetObject->getVar('contactby')), false); |
||
| 152 | // Premium |
||
| 153 | $this->addElement(new \XoopsFormText(AM_ADSLIGHT_LISTING_PREMIUM, 'premium', 50, 255, $this->targetObject->getVar('premium')), false); |
||
| 154 | // Valid |
||
| 155 | $this->addElement(new \XoopsFormText(AM_ADSLIGHT_LISTING_VALID, 'valid', 50, 255, $this->targetObject->getVar('valid')), false); |
||
| 156 | // Photo |
||
| 157 | $photo = $this->targetObject->getVar('photo') ?: 'blank.png'; |
||
| 158 | |||
| 159 | $uploadDir = '/uploads/adslight/listing/'; |
||
| 160 | $imgtray = new \XoopsFormElementTray(AM_ADSLIGHT_LISTING_PHOTO,'<br>'); |
||
| 161 | $imgpath = sprintf(AM_ADSLIGHT_FORMIMAGE_PATH, $uploadDir); |
||
| 162 | $imageselect = new \XoopsFormSelect($imgpath, 'photo', $photo); |
||
| 163 | $imageArray = \XoopsLists::getImgListAsArray( XOOPS_ROOT_PATH . $uploadDir ); |
||
| 164 | foreach ($imageArray as $image) { |
||
| 165 | $imageselect->addOption((string)$image, $image); |
||
| 166 | } |
||
| 167 | $imageselect->setExtra( "onchange='showImgSelected(\"image_photo\", \"photo\", \"".$uploadDir.'", "", "'.XOOPS_URL."\")'" ); |
||
| 168 | $imgtray->addElement($imageselect); |
||
| 169 | $imgtray->addElement( new \XoopsFormLabel( '', "<br><img src='".XOOPS_URL.'/'.$uploadDir.'/'.$photo."' name='image_photo' id='image_photo' alt='' style='max-width:300px' >" ) ); |
||
| 170 | $fileseltray = new \XoopsFormElementTray('','<br>'); |
||
| 171 | $fileseltray->addElement(new \XoopsFormFile(AM_ADSLIGHT_FORMUPLOAD , 'photo', $this->helper->getConfig('maxsize'))); |
||
| 172 | $fileseltray->addElement(new \XoopsFormLabel('')); |
||
| 173 | $imgtray->addElement($fileseltray); |
||
| 174 | $this->addElement($imgtray); |
||
| 175 | // Hits |
||
| 176 | $this->addElement(new \XoopsFormText(AM_ADSLIGHT_LISTING_HITS, 'hits', 50, 255, $this->targetObject->getVar('hits')), false); |
||
| 177 | // Item_rating |
||
| 178 | $this->addElement(new \XoopsFormText(AM_ADSLIGHT_LISTING_ITEM_RATING, 'item_rating', 50, 255, $this->targetObject->getVar('item_rating')), false); |
||
| 179 | // Item_votes |
||
| 180 | $this->addElement(new \XoopsFormText(AM_ADSLIGHT_LISTING_ITEM_VOTES, 'item_votes', 50, 255, $this->targetObject->getVar('item_votes')), false); |
||
| 181 | // User_rating |
||
| 182 | $this->addElement(new \XoopsFormText(AM_ADSLIGHT_LISTING_USER_RATING, 'user_rating', 50, 255, $this->targetObject->getVar('user_rating')), false); |
||
| 183 | // User_votes |
||
| 184 | $this->addElement(new \XoopsFormText(AM_ADSLIGHT_LISTING_USER_VOTES, 'user_votes', 50, 255, $this->targetObject->getVar('user_votes')), false); |
||
| 185 | // Comments |
||
| 186 | $this->addElement(new \XoopsFormText(AM_ADSLIGHT_LISTING_COMMENTS, 'comments', 50, 255, $this->targetObject->getVar('comments')), false); |
||
| 187 | // Remind |
||
| 188 | $this->addElement(new \XoopsFormText(AM_ADSLIGHT_LISTING_REMIND, 'remind', 50, 255, $this->targetObject->getVar('remind')), false); |
||
| 189 | |||
| 190 | $this->addElement(new \XoopsFormHidden('op', 'save')); |
||
| 191 | $this->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit')); |
||
| 192 | } |
||
| 194 |