| Conditions | 13 |
| Paths | 3072 |
| Total Lines | 148 |
| Code Lines | 75 |
| 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 |
||
| 54 | public function __construct($target) |
||
| 55 | { |
||
| 56 | $db = \XoopsDatabaseFactory::getDatabaseConnection(); |
||
| 57 | $helper = Helper::getInstance(); |
||
| 58 | $utility = new Utility(); |
||
| 59 | |||
| 60 | $this->targetObject = $target; |
||
| 61 | |||
| 62 | $title = $this->targetObject->isNew() ? \sprintf(\_AM_LEXIKON_ENTRIES_ADD) : \sprintf(\_AM_LEXIKON_ENTRIES_EDIT); |
||
| 63 | parent::__construct($title, 'form', \xoops_getenv('SCRIPT_NAME'), 'post', true); |
||
| 64 | $this->setExtra('enctype="multipart/form-data"'); |
||
| 65 | |||
| 66 | //include ID field, it's needed so the module knows if it is a new form or an edited form |
||
| 67 | |||
| 68 | $hidden = new \XoopsFormHidden('entryID', $this->targetObject->getVar('entryID')); |
||
| 69 | $this->addElement($hidden); |
||
| 70 | unset($hidden); |
||
| 71 | |||
| 72 | // EntryID |
||
| 73 | $this->addElement(new \XoopsFormLabel(\_AM_LEXIKON_ENTRIES_ENTRYID, $this->targetObject->getVar('entryID'), 'entryID')); |
||
| 74 | // CategoryID |
||
| 75 | // $categoriesHandler = xoops_getModuleHandler('categories', 'lexikon'); |
||
| 76 | |||
| 77 | $categoriesHandler = new CategoriesHandler($db); |
||
| 78 | |||
| 79 | $categories_id_select = new \XoopsFormSelect(\_AM_LEXIKON_ENTRIES_CATEGORYID, 'categoryID', $this->targetObject->getVar('name')); |
||
| 80 | $categories_id_select->addOptionArray($categoriesHandler->getList()); |
||
| 81 | |||
| 82 | $this->addElement($categories_id_select, false); |
||
| 83 | // Uid |
||
| 84 | $this->addElement(new \XoopsFormSelectUser(\_AM_LEXIKON_ENTRIES_UID, 'uid', false, $this->targetObject->getVar('uid'), 1, false), false); |
||
| 85 | |||
| 86 | // Term |
||
| 87 | $this->addElement(new \XoopsFormText(\_AM_LEXIKON_ENTRIES_TERM, 'term', 50, 255, $this->targetObject->getVar('term')), false); |
||
| 88 | // Init |
||
| 89 | $this->addElement(new \XoopsFormText(\_AM_LEXIKON_ENTRIES_INIT, 'init', 50, 255, $this->targetObject->getVar('init')), false); |
||
| 90 | |||
| 91 | // Definition |
||
| 92 | |||
| 93 | /* |
||
| 94 | if (class_exists('XoopsFormEditor')) { |
||
| 95 | $editorOptions = []; |
||
| 96 | $editorOptions['name'] = 'definition'; |
||
| 97 | $editorOptions['value'] = $this->targetObject->getVar('definition', 'e'); |
||
| 98 | $editorOptions['rows'] = 5; |
||
| 99 | $editorOptions['cols'] = 40; |
||
| 100 | $editorOptions['width'] = '100%'; |
||
| 101 | $editorOptions['height'] = '400px'; |
||
| 102 | //$editorOptions['editor'] = xoops_getModuleOption('lexikon_editor', 'lexikon'); |
||
| 103 | //$this->addElement( new \XoopsFormEditor(_AM_LEXIKON_ENTRIES_DEFINITION, 'definition', $editorOptions), false ); |
||
| 104 | if ($helper->isUserAdmin()) { |
||
| 105 | $descEditor = new \XoopsFormEditor(_AM_LEXIKON_ENTRIES_DEFINITION, $helper->getConfig('lexikonEditorAdmin'), $editorOptions, $nohtml = false, $onfailure = 'textarea'); |
||
| 106 | } else { |
||
| 107 | $descEditor = new \XoopsFormEditor(_AM_LEXIKON_ENTRIES_DEFINITION, $helper->getConfig('lexikonEditorUser'), $editorOptions, $nohtml = false, $onfailure = 'textarea'); |
||
| 108 | } |
||
| 109 | } else { |
||
| 110 | $descEditor = new \XoopsFormDhtmlTextArea(_AM_LEXIKON_ENTRIES_DEFINITION, 'description', $this->targetObject->getVar('description', 'e'), '100%', '100%'); |
||
| 111 | } |
||
| 112 | $this->addElement($descEditor); |
||
| 113 | */ |
||
| 114 | |||
| 115 | $definition = $this->targetObject->getVar('definition', 'e'); |
||
| 116 | $editor = $utility::getWysiwygForm(_AM_LEXIKON_ENTRYDEF, 'definition', $definition, 15, 60); |
||
| 117 | if (_MD_LEXIKON_WRITEHERE == $definition) { |
||
| 118 | $editor->setExtra('onfocus="this.select()"'); |
||
| 119 | } |
||
| 120 | $this->addElement($editor, true); |
||
| 121 | unset($editor); |
||
| 122 | |||
| 123 | // Ref |
||
| 124 | if (\class_exists('XoopsFormEditor')) { |
||
| 125 | $editorOptions = []; |
||
| 126 | $editorOptions['name'] = 'ref'; |
||
| 127 | $editorOptions['value'] = $this->targetObject->getVar('ref', 'e'); |
||
| 128 | $editorOptions['rows'] = 5; |
||
| 129 | $editorOptions['cols'] = 40; |
||
| 130 | $editorOptions['width'] = '100%'; |
||
| 131 | $editorOptions['height'] = '400px'; |
||
| 132 | //$editorOptions['editor'] = xoops_getModuleOption('lexikon_editor', 'lexikon'); |
||
| 133 | //$this->addElement( new \XoopsFormEditor(_AM_LEXIKON_ENTRIES_REF, 'ref', $editorOptions), false ); |
||
| 134 | if ($helper->isUserAdmin()) { |
||
| 135 | $descEditor = new \XoopsFormEditor(\_AM_LEXIKON_ENTRIES_REF, $helper->getConfig('lexikonEditorAdmin'), $editorOptions, $nohtml = false, $onfailure = 'textarea'); |
||
| 136 | } else { |
||
| 137 | $descEditor = new \XoopsFormEditor(\_AM_LEXIKON_ENTRIES_REF, $helper->getConfig('lexikonEditorUser'), $editorOptions, $nohtml = false, $onfailure = 'textarea'); |
||
| 138 | } |
||
| 139 | } else { |
||
| 140 | $descEditor = new \XoopsFormDhtmlTextArea(\_AM_LEXIKON_ENTRIES_REF, 'description', $this->targetObject->getVar('description', 'e'), '100%', '100%'); |
||
| 141 | } |
||
| 142 | $this->addElement($descEditor); |
||
| 143 | // Url |
||
| 144 | $this->addElement(new \XoopsFormText(\_AM_LEXIKON_ENTRIES_URL, 'url', 50, 255, $this->targetObject->getVar('url')), false); |
||
| 145 | |||
| 146 | // Submit |
||
| 147 | $submit = $this->targetObject->isNew() ? 0 : $this->targetObject->getVar('submit'); |
||
| 148 | $check_submit = new \XoopsFormCheckBox(\_SUBMIT, 'submit', $submit); |
||
| 149 | $check_submit->addOption(1, ' '); |
||
| 150 | $this->addElement($check_submit); |
||
| 151 | // Datesub |
||
| 152 | $this->addElement(new \XoopsFormDateTime(\_AM_LEXIKON_ENTRIES_DATESUB, 'datesub', '', \strtotime($this->targetObject->getVar('datesub')))); |
||
| 153 | // Counter |
||
| 154 | // $this->addElement(new \XoopsFormText(_AM_LEXIKON_ENTRIES_COUNTER, 'counter', 50, 255, $this->targetObject->getVar('counter')), false); |
||
| 155 | // Html |
||
| 156 | $html = $this->targetObject->isNew() ? 0 : $this->targetObject->getVar('html'); |
||
| 157 | $check_html = new \XoopsFormCheckBox(\_AM_LEXIKON_ENTRIES_HTML, 'html', $html); |
||
| 158 | $check_html->addOption(1, ' '); |
||
| 159 | $this->addElement($check_html); |
||
| 160 | // Smiley |
||
| 161 | $smiley = $this->targetObject->isNew() ? 0 : $this->targetObject->getVar('smiley'); |
||
| 162 | $check_smiley = new \XoopsFormCheckBox(\_AM_LEXIKON_ENTRIES_SMILEY, 'smiley', $smiley); |
||
| 163 | $check_smiley->addOption(1, ' '); |
||
| 164 | $this->addElement($check_smiley); |
||
| 165 | // Xcodes |
||
| 166 | $xcodes = $this->targetObject->isNew() ? 0 : $this->targetObject->getVar('xcodes'); |
||
| 167 | $check_xcodes = new \XoopsFormCheckBox(\_AM_LEXIKON_ENTRIES_XCODES, 'xcodes', $xcodes); |
||
| 168 | $check_xcodes->addOption(1, ' '); |
||
| 169 | $this->addElement($check_xcodes); |
||
| 170 | // Breaks |
||
| 171 | $breaks = $this->targetObject->isNew() ? 0 : $this->targetObject->getVar('breaks'); |
||
| 172 | $check_breaks = new \XoopsFormCheckBox(\_AM_LEXIKON_ENTRIES_BREAKS, 'breaks', $breaks); |
||
| 173 | $check_breaks->addOption(1, ' '); |
||
| 174 | $this->addElement($check_breaks); |
||
| 175 | // Block |
||
| 176 | $block = $this->targetObject->isNew() ? 0 : $this->targetObject->getVar('block'); |
||
| 177 | $check_block = new \XoopsFormCheckBox(\_AM_LEXIKON_ENTRIES_BLOCK, 'block', $block); |
||
| 178 | $check_block->addOption(1, ' '); |
||
| 179 | $this->addElement($check_block); |
||
| 180 | // Offline |
||
| 181 | $offline = $this->targetObject->isNew() ? 0 : $this->targetObject->getVar('offline'); |
||
| 182 | $check_offline = new \XoopsFormCheckBox(\_MD_LEXIKON_ENTRIES_OFFLINE, 'offline', $offline); |
||
| 183 | $check_offline->addOption(1, ' '); |
||
| 184 | $this->addElement($check_offline); |
||
| 185 | // Notifypub |
||
| 186 | $notifypub = $this->targetObject->isNew() ? 0 : $this->targetObject->getVar('notifypub'); |
||
| 187 | $check_notifypub = new \XoopsFormCheckBox(\_AM_LEXIKON_ENTRIES_NOTIFYPUB, 'notifypub', $notifypub); |
||
| 188 | $check_notifypub->addOption(1, ' '); |
||
| 189 | $this->addElement($check_notifypub); |
||
| 190 | // Request |
||
| 191 | // $request = $this->targetObject->isNew() ? 0 : $this->targetObject->getVar('request'); |
||
| 192 | // $check_request = new \XoopsFormCheckBox(_AM_LEXIKON_ENTRIES_REQUEST, 'request', $request); |
||
| 193 | // $check_request->addOption(1, ' '); |
||
| 194 | // $this->addElement($check_request); |
||
| 195 | // Comments |
||
| 196 | //$this->addElement(new \XoopsFormText(_AM_LEXIKON_ENTRIES_COMMENTS, 'comments', 50, 255, $this->targetObject->getVar('comments')), false); |
||
| 197 | // Item_tag |
||
| 198 | // $this->addElement(new \XoopsFormTextArea(_AM_LEXIKON_ENTRIES_ITEM_TAG, 'item_tag', $this->targetObject->getVar('item_tag'), 4, 47), false); |
||
| 199 | |||
| 200 | $this->addElement(new \XoopsFormHidden('op', 'save')); |
||
| 201 | $this->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit')); |
||
| 202 | } |
||
| 204 |