| Conditions | 20 |
| Paths | > 20000 |
| Total Lines | 143 |
| Code Lines | 102 |
| 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 |
||
| 71 | public function getForm($action = false) |
||
| 72 | { |
||
| 73 | global $xoopsDB; |
||
| 74 | |||
| 75 | if (false === $action) { |
||
| 76 | $action = $_SERVER['REQUEST_URI']; |
||
| 77 | } |
||
| 78 | |||
| 79 | $title = $this->isNew() ? \_AM_WGEVENTS_ACCOUNT_ADD : \_AM_WGEVENTS_ACCOUNT_EDIT; |
||
| 80 | |||
| 81 | require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||
| 82 | $form = new \XoopsThemeForm($title, 'accounts_form', $action, 'post', true); |
||
| 83 | $form->setExtra('enctype="multipart/form-data"'); |
||
| 84 | |||
| 85 | $default = $this->getVar('type'); |
||
| 86 | |||
| 87 | switch ($default) { |
||
| 88 | case Constants::ACCOUNT_TYPE_VAL_PHP_MAIL: |
||
| 89 | default: |
||
| 90 | $dis_acc_userpass = true; |
||
| 91 | $dis_acc_server_in = true; |
||
| 92 | $dis_acc_server_out = true; |
||
| 93 | $dis_acc_button_check = true; |
||
|
|
|||
| 94 | break; |
||
| 95 | case Constants::ACCOUNT_TYPE_VAL_PHP_SENDMAIL: |
||
| 96 | $dis_acc_userpass = false; |
||
| 97 | $dis_acc_server_in = true; |
||
| 98 | $dis_acc_server_out = false; |
||
| 99 | $dis_acc_button_check = true; |
||
| 100 | break; |
||
| 101 | case Constants::ACCOUNT_TYPE_VAL_POP3: |
||
| 102 | case Constants::ACCOUNT_TYPE_VAL_SMTP: |
||
| 103 | case Constants::ACCOUNT_TYPE_VAL_GMAIL: |
||
| 104 | $dis_acc_userpass = false; |
||
| 105 | $dis_acc_server_in = false; |
||
| 106 | $dis_acc_server_out = false; |
||
| 107 | $dis_acc_button_check = false; |
||
| 108 | break; |
||
| 109 | } |
||
| 110 | // Form Select $type |
||
| 111 | $type = $this->isNew() ? 1 : $this->getVar('type'); |
||
| 112 | $accstd_select = new \XoopsFormSelect(\_AM_WGEVENTS_ACCOUNT_TYPE, 'type', $type); |
||
| 113 | $accstd_select->setExtra(" onchange='preselectAccFields()' "); |
||
| 114 | $accstd_select->addOption(Constants::ACCOUNT_TYPE_VAL_PHP_MAIL, \_AM_WGEVENTS_ACCOUNT_TYPE_PHPMAIL); |
||
| 115 | $accstd_select->addOption(Constants::ACCOUNT_TYPE_VAL_PHP_SENDMAIL, \_AM_WGEVENTS_ACCOUNT_TYPE_PHPSENDMAIL); |
||
| 116 | $accstd_select->addOption(Constants::ACCOUNT_TYPE_VAL_POP3, \_AM_WGEVENTS_ACCOUNT_TYPE_POP3); |
||
| 117 | $accstd_select->addOption(Constants::ACCOUNT_TYPE_VAL_SMTP, \_AM_WGEVENTS_ACCOUNT_TYPE_SMTP); |
||
| 118 | $accstd_select->addOption(Constants::ACCOUNT_TYPE_VAL_GMAIL, \_AM_WGEVENTS_ACCOUNT_TYPE_GMAIL); |
||
| 119 | $form->addElement($accstd_select); |
||
| 120 | // Form Text $name |
||
| 121 | $form->addElement(new \XoopsFormText(\_AM_WGEVENTS_ACCOUNT_NAME, 'name', 50, 255, $this->getVar('name'))); |
||
| 122 | // Form Text $yourname |
||
| 123 | $form->addElement(new \XoopsFormText(\_AM_WGEVENTS_ACCOUNT_YOURNAME, 'yourname', 50, 255, $this->getVar('yourname'))); |
||
| 124 | // Form Text $yourmail |
||
| 125 | $form->addElement(new \XoopsFormText(\_AM_WGEVENTS_ACCOUNT_YOURMAIL, 'yourmail', 50, 255, $this->getVar('yourmail'))); |
||
| 126 | // Form RadioYN $primary |
||
| 127 | $primary = $this->isNew() ? 0 : $this->getVar('primary'); |
||
| 128 | $form->addElement(new \XoopsFormRadioYN(\_AM_WGEVENTS_ACCOUNT_PRIMARY, 'primary', $primary, _YES, _NO)); |
||
| 129 | // Form Text $username |
||
| 130 | $username = new \XoopsFormText(\_AM_WGEVENTS_ACCOUNT_USERNAME, 'username', 50, 255, $this->getVar('username')); |
||
| 131 | if ($dis_acc_userpass) { |
||
| 132 | $username->setExtra(' disabled="disabled" style="background-color:#d4d5d6"'); |
||
| 133 | } |
||
| 134 | $form->addElement($username); |
||
| 135 | // Form Text $password |
||
| 136 | $password = new \XoopsFormText(\_AM_WGEVENTS_ACCOUNT_PASSWORD, 'password', 50, 255, $this->getVar('password')); |
||
| 137 | if ($dis_acc_userpass) { |
||
| 138 | $password->setExtra(' disabled="disabled" style="background-color:#d4d5d6"'); |
||
| 139 | } |
||
| 140 | $form->addElement($password); |
||
| 141 | |||
| 142 | // Form Tray Incoming |
||
| 143 | $incomming_tray = new \XoopsFormElementTray(\_AM_WGEVENTS_ACCOUNT_INCOMING, ''); |
||
| 144 | // Form Tray Incoming - Server in |
||
| 145 | $serverIn = new \XoopsFormText(\_AM_WGEVENTS_ACCOUNT_SERVER_IN, 'server_in', 50, 255, $this->getVar('server_in')); |
||
| 146 | if ($dis_acc_server_in) { |
||
| 147 | $serverIn->setExtra(' disabled="disabled" style="background-color:#d4d5d6"'); |
||
| 148 | } |
||
| 149 | $incomming_tray->addElement($serverIn); |
||
| 150 | // Form Tray Incoming - Port in |
||
| 151 | $portIn = new \XoopsFormText('<br>' . \_AM_WGEVENTS_ACCOUNT_PORT_IN, 'port_in', 50, 255, $this->getVar('port_in')); |
||
| 152 | if ($dis_acc_server_in) { |
||
| 153 | $portIn->setExtra(' disabled="disabled" style="background-color:#d4d5d6"'); |
||
| 154 | } |
||
| 155 | $incomming_tray->addElement($portIn); |
||
| 156 | // Form Tray Incoming - Secure type in |
||
| 157 | $formfield_securetype_in = new \XoopsFormSelect('<br>' . \_AM_WGEVENTS_ACCOUNT_SECURETYPE_IN, 'securetype_in', $this->getVar('securetype_in')); |
||
| 158 | $formfield_securetype_in->addOption(''); |
||
| 159 | $formfield_securetype_in->addOption('notls', 'NOTLS / STARTTLS'); |
||
| 160 | $formfield_securetype_in->addOption('ssl', 'SSL'); |
||
| 161 | $formfield_securetype_in->addOption('tls', 'TLS'); |
||
| 162 | if ($dis_acc_server_in) { |
||
| 163 | $formfield_securetype_in->setExtra(' disabled="disabled" style="background-color:#d4d5d6"'); |
||
| 164 | } |
||
| 165 | $incomming_tray->addElement($formfield_securetype_in); |
||
| 166 | $form->addElement($incomming_tray); |
||
| 167 | |||
| 168 | // Form Tray Outgoing |
||
| 169 | $outcomming_tray = new \XoopsFormElementTray(\_AM_WGEVENTS_ACCOUNT_OUTGOING, ''); |
||
| 170 | // Form Tray Outgoing - Server out |
||
| 171 | $serverOut = new \XoopsFormText(\_AM_WGEVENTS_ACCOUNT_SERVER_OUT, 'server_out', 50, 255, $this->getVar('server_out')); |
||
| 172 | if ($dis_acc_server_out) { |
||
| 173 | $serverOut->setExtra(' disabled="disabled" style="background-color:#d4d5d6"'); |
||
| 174 | } |
||
| 175 | $outcomming_tray->addElement($serverOut); |
||
| 176 | // Form Tray Outgoing - Port out |
||
| 177 | $portOut = new \XoopsFormText('<br>' . \_AM_WGEVENTS_ACCOUNT_PORT_OUT, 'port_out', 50, 255, $this->getVar('port_out')); |
||
| 178 | if ($dis_acc_server_out) { |
||
| 179 | $portOut->setExtra(' disabled="disabled" style="background-color:#d4d5d6"'); |
||
| 180 | } |
||
| 181 | $outcomming_tray->addElement($portOut); |
||
| 182 | // Form Tray Outgoing - Secure type out |
||
| 183 | $formfield_securetype_out = new \XoopsFormSelect('<br>' . \_AM_WGEVENTS_ACCOUNT_SECURETYPE_OUT, 'securetype_out', $this->getVar('securetype_out')); |
||
| 184 | $formfield_securetype_out->addOption(''); |
||
| 185 | $formfield_securetype_out->addOption('notls', 'NOTLS / STARTTLS'); |
||
| 186 | $formfield_securetype_out->addOption('ssl', 'SSL'); |
||
| 187 | $formfield_securetype_out->addOption('tls', 'TLS'); |
||
| 188 | if ($dis_acc_server_out) { |
||
| 189 | $formfield_securetype_out->setExtra(' disabled="disabled" style="background-color:#d4d5d6"'); |
||
| 190 | } |
||
| 191 | $outcomming_tray->addElement($formfield_securetype_out); |
||
| 192 | $form->addElement($outcomming_tray); |
||
| 193 | // Form Text $limitHour |
||
| 194 | $limitHour = $this->isNew() ? 0 : $this->getVar('limit_hour'); |
||
| 195 | $limitHourText = new \XoopsFormText(\_AM_WGEVENTS_ACCOUNT_LIMIT_HOUR, 'limit_hour', 50, 255, $limitHour); |
||
| 196 | $limitHourText->setDescription(\_AM_WGEVENTS_ACCOUNT_LIMIT_HOUR_DESC); |
||
| 197 | $form->addElement($limitHourText); |
||
| 198 | // |
||
| 199 | $time = $this->isNew() ? time() : $this->getVar('datecreated'); |
||
| 200 | $form->addElement(new \XoopsFormHidden('submitter', $GLOBALS['xoopsUser']->uid())); |
||
| 201 | $form->addElement(new \XoopsFormHidden('datecreated', time())); |
||
| 202 | $form->addElement(new \XoopsFormLabel(\_MA_WGEVENTS_SUBMITTER, $GLOBALS['xoopsUser']->uname())); |
||
| 203 | $form->addElement(new \XoopsFormLabel(\_MA_WGEVENTS_DATECREATED, formatTimestamp($time, 's'))); |
||
| 204 | |||
| 205 | // Buttons |
||
| 206 | $buttonTray = new \XoopsFormElementTray(' ', ' '); |
||
| 207 | $buttonTray->addElement(new \XoopsFormHidden('op', 'save')); |
||
| 208 | $buttonTray->addElement(new \XoopsFormButtonTray('', \_SUBMIT, 'submit', '', false)); |
||
| 209 | //$button_check = new \XoopsFormButton('', 'save_and_check', \_AM_WGEVENTS_SAVE_AND_CHECK, 'submit'); |
||
| 210 | //$buttonTray->addElement($button_check); |
||
| 211 | $form->addElement($buttonTray); |
||
| 212 | |||
| 213 | return $form; |
||
| 214 | } |
||
| 249 |