| Conditions | 7 |
| Paths | 24 |
| Total Lines | 96 |
| Code Lines | 56 |
| 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_CATEGORIES_ADD) : sprintf(AM_ADSLIGHT_CATEGORIES_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('cid', $this->targetObject->getVar('cid')); |
||
| 63 | $this->addElement($hidden); |
||
| 64 | unset($hidden); |
||
| 65 | |||
| 66 | // Cid |
||
| 67 | $this->addElement(new \XoopsFormLabel(AM_ADSLIGHT_CATEGORIES_CID, $this->targetObject->getVar('cid'), 'cid' )); |
||
| 68 | // Pid |
||
| 69 | require_once XOOPS_ROOT_PATH . '/class/tree.php'; |
||
| 70 | //$categoriesHandler = xoops_getModuleHandler('categories', 'adslight' ); |
||
| 71 | //$db = \XoopsDatabaseFactory::getDatabaseConnection(); |
||
| 72 | /** @var \XoopsPersistableObjectHandler $categoriesHandler */ |
||
| 73 | $categoriesHandler = $this->helper->getHandler('Categories'); |
||
| 74 | |||
| 75 | $criteria = new \CriteriaCompo(); |
||
| 76 | $categoryArray = $categoriesHandler->getObjects( $criteria ); |
||
| 77 | if (!empty($categoryArray)) { |
||
| 78 | |||
| 79 | $categoryTree = new \XoopsObjectTree( $categoryArray, 'cid', 'pid' ); |
||
| 80 | |||
| 81 | // if (Adslight\Utility::checkVerXoops($GLOBALS['xoopsModule'], '2.5.9')) { |
||
| 82 | $categoriesPid = $categoryTree->makeSelectElement('pid', 'title', '--', $this->targetObject->getVar('pid'), true, 0, '', AM_ADSLIGHT_CATEGORIES_PID); |
||
| 83 | $this->addElement($categoriesPid); |
||
| 84 | // } else { |
||
| 85 | // $categoriesPid = $categoryTree->makeSelBox( 'pid', 'title','--', $this->targetObject->getVar('pid', 'e' ), true ); |
||
| 86 | // $this->addElement( new \XoopsFormLabel ( AM_ADSLIGHT_CATEGORIES_PID, $categoriesPid ) ); |
||
| 87 | // } |
||
| 88 | |||
| 89 | } |
||
| 90 | // Title |
||
| 91 | $this->addElement(new \XoopsFormText(AM_ADSLIGHT_CATEGORIES_TITLE, 'title', 50, 255, $this->targetObject->getVar('title')), false); |
||
| 92 | // Cat_desc |
||
| 93 | if (class_exists('XoopsFormEditor')) { |
||
| 94 | $editorOptions = []; |
||
| 95 | $editorOptions['name'] = 'cat_desc'; |
||
| 96 | $editorOptions['value'] = $this->targetObject->getVar('cat_desc', 'e'); |
||
| 97 | $editorOptions['rows'] = 5; |
||
| 98 | $editorOptions['cols'] = 40; |
||
| 99 | $editorOptions['width'] = '100%'; |
||
| 100 | $editorOptions['height'] = '400px'; |
||
| 101 | //$editorOptions['editor'] = xoops_getModuleOption('adslight_editor', 'adslight'); |
||
| 102 | //$this->addElement( new \XoopsFormEditor(AM_ADSLIGHT_CATEGORIES_CAT_DESC, 'cat_desc', $editorOptions), false ); |
||
| 103 | if ($this->helper->isUserAdmin()) { |
||
| 104 | $descEditor = new \XoopsFormEditor(AM_ADSLIGHT_CATEGORIES_CAT_DESC, $this->helper->getConfig('adslightEditorAdmin'), $editorOptions, $nohtml = false, $onfailure = 'textarea'); |
||
| 105 | } else { |
||
| 106 | $descEditor = new \XoopsFormEditor(AM_ADSLIGHT_CATEGORIES_CAT_DESC, $this->helper->getConfig('adslightEditorUser'), $editorOptions, $nohtml = false, $onfailure = 'textarea'); |
||
| 107 | } |
||
| 108 | } else { |
||
| 109 | $descEditor = new \XoopsFormDhtmlTextArea(AM_ADSLIGHT_CATEGORIES_CAT_DESC, 'description', $this->targetObject->getVar('description', 'e'), 5, 50); |
||
| 110 | } |
||
| 111 | $this->addElement($descEditor); |
||
| 112 | // Cat_keywords |
||
| 113 | $this->addElement(new \XoopsFormText(AM_ADSLIGHT_CATEGORIES_CAT_KEYWORDS, 'cat_keywords', 50, 255, $this->targetObject->getVar('cat_keywords')), false); |
||
| 114 | // Img |
||
| 115 | $img = $this->targetObject->getVar('img') ?: 'blank.png'; |
||
| 116 | |||
| 117 | $uploadDir = '/uploads/adslight/categories/'; |
||
| 118 | $imgtray = new \XoopsFormElementTray(AM_ADSLIGHT_CATEGORIES_IMG,'<br>'); |
||
| 119 | $imgpath = sprintf(AM_ADSLIGHT_FORMIMAGE_PATH, $uploadDir); |
||
| 120 | $imageselect = new \XoopsFormSelect($imgpath, 'img', $img); |
||
| 121 | $imageArray = \XoopsLists::getImgListAsArray( XOOPS_ROOT_PATH . $uploadDir ); |
||
| 122 | foreach ($imageArray as $image) { |
||
| 123 | $imageselect->addOption((string)$image, $image); |
||
| 124 | } |
||
| 125 | $imageselect->setExtra( "onchange='showImgSelected(\"image_img\", \"img\", \"".$uploadDir.'", "", "'.XOOPS_URL."\")'" ); |
||
| 126 | $imgtray->addElement($imageselect); |
||
| 127 | $imgtray->addElement( new \XoopsFormLabel( '', "<br><img src='".XOOPS_URL.'/'.$uploadDir.'/'.$img."' name='image_img' id='image_img' alt='' style='max-width:300px' >" ) ); |
||
| 128 | $fileseltray = new \XoopsFormElementTray('','<br>'); |
||
| 129 | $fileseltray->addElement(new \XoopsFormFile(AM_ADSLIGHT_FORMUPLOAD , 'img', $this->helper->getConfig('maxsize'))); |
||
| 130 | $fileseltray->addElement(new \XoopsFormLabel('')); |
||
| 131 | $imgtray->addElement($fileseltray); |
||
| 132 | $this->addElement($imgtray); |
||
| 133 | // Cat_order |
||
| 134 | $this->addElement(new \XoopsFormText(AM_ADSLIGHT_CATEGORIES_CAT_ORDER, 'cat_order', 50, 255, $this->targetObject->getVar('cat_order')), false); |
||
| 135 | // Affprice |
||
| 136 | $this->addElement(new \XoopsFormText(AM_ADSLIGHT_CATEGORIES_AFFPRICE, 'affprice', 50, 255, $this->targetObject->getVar('affprice')), false); |
||
| 137 | // Cat_moderate |
||
| 138 | $this->addElement(new \XoopsFormSelectUser(AM_ADSLIGHT_CATEGORIES_CAT_MODERATE, 'cat_moderate', false, $this->targetObject->getVar('cat_moderate'), 1, false), false); |
||
| 139 | // Moderate_subcat |
||
| 140 | $this->addElement(new \XoopsFormSelectUser(AM_ADSLIGHT_CATEGORIES_MODERATE_SUBCAT, 'moderate_subcat', false, $this->targetObject->getVar('moderate_subcat'), 1, false), false); |
||
| 141 | |||
| 142 | $this->addElement(new \XoopsFormHidden('op', 'save')); |
||
| 143 | $this->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit')); |
||
| 144 | } |
||
| 146 |