| Conditions | 40 |
| Paths | > 20000 |
| Total Lines | 183 |
| Code Lines | 106 |
| 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 |
||
| 100 | public function assign_values(&$action, $id) |
||
| 101 | { |
||
| 102 | // phpcs:enable |
||
| 103 | global $conf, $langs, $user, $canvas; |
||
| 104 | global $form, $formcompany, $objsoc; |
||
| 105 | |||
| 106 | if ($action == 'add' || $action == 'update') { |
||
| 107 | $this->assign_post(); |
||
| 108 | } |
||
| 109 | |||
| 110 | foreach ($this->object as $key => $value) { |
||
| 111 | $this->tpl[$key] = $value; |
||
| 112 | } |
||
| 113 | |||
| 114 | $this->tpl['error'] = $this->error; |
||
| 115 | $this->tpl['errors'] = $this->errors; |
||
| 116 | |||
| 117 | if ($action == 'create' || $action == 'edit') { |
||
| 118 | if ($conf->use_javascript_ajax) { |
||
| 119 | $this->tpl['ajax_selectcountry'] = "\n" . '<script type="text/javascript"> |
||
| 120 | jQuery(document).ready(function () { |
||
| 121 | jQuery("#selectcountry_id").change(function() { |
||
| 122 | document.formsoc.action.value="' . $action . '"; |
||
| 123 | document.formsoc.canvas.value="' . $canvas . '"; |
||
| 124 | document.formsoc.submit(); |
||
| 125 | }); |
||
| 126 | }) |
||
| 127 | </script>' . "\n"; |
||
| 128 | } |
||
| 129 | |||
| 130 | if (is_object($objsoc) && $objsoc->id > 0) { |
||
| 131 | $this->tpl['company'] = $objsoc->getNomUrl(1); |
||
| 132 | $this->tpl['company_id'] = $objsoc->id; |
||
| 133 | } else { |
||
| 134 | $this->tpl['company'] = $form->select_company($this->object->socid, 'socid', '', 1); |
||
| 135 | } |
||
| 136 | |||
| 137 | // Civility |
||
| 138 | $this->tpl['select_civility'] = $formcompany->select_civility($this->object->civility_id); |
||
| 139 | |||
| 140 | // Predefined with third party |
||
| 141 | if ((isset($objsoc->typent_code) && $objsoc->typent_code == 'TE_PRIVATE') || getDolGlobalString('CONTACT_USE_COMPANY_ADDRESS')) { |
||
| 142 | if (dol_strlen(trim($this->object->address)) == 0) { |
||
| 143 | $this->tpl['address'] = $objsoc->address; |
||
| 144 | } |
||
| 145 | if (dol_strlen(trim($this->object->zip)) == 0) { |
||
| 146 | $this->object->zip = $objsoc->zip; |
||
| 147 | } |
||
| 148 | if (dol_strlen(trim($this->object->town)) == 0) { |
||
| 149 | $this->object->town = $objsoc->town; |
||
| 150 | } |
||
| 151 | if (dol_strlen(trim($this->object->phone_pro)) == 0) { |
||
| 152 | $this->object->phone_pro = $objsoc->phone; |
||
| 153 | } |
||
| 154 | if (dol_strlen(trim($this->object->fax)) == 0) { |
||
| 155 | $this->object->fax = $objsoc->fax; |
||
| 156 | } |
||
| 157 | if (dol_strlen(trim($this->object->email)) == 0) { |
||
| 158 | $this->object->email = $objsoc->email; |
||
| 159 | } |
||
| 160 | } |
||
| 161 | |||
| 162 | // Zip |
||
| 163 | $this->tpl['select_zip'] = $formcompany->select_ziptown($this->object->zip, 'zipcode', array('town', 'selectcountry_id', 'state_id'), 6); |
||
| 164 | |||
| 165 | // Town |
||
| 166 | $this->tpl['select_town'] = $formcompany->select_ziptown($this->object->town, 'town', array('zipcode', 'selectcountry_id', 'state_id')); |
||
| 167 | |||
| 168 | if (dol_strlen(trim((string)$this->object->country_id)) == 0) { |
||
| 169 | $this->object->country_id = $objsoc->country_id; |
||
| 170 | } |
||
| 171 | |||
| 172 | // Country |
||
| 173 | $this->tpl['select_country'] = $form->select_country($this->object->country_id, 'country_id'); |
||
| 174 | $countrynotdefined = $langs->trans("ErrorSetACountryFirst") . ' (' . $langs->trans("SeeAbove") . ')'; |
||
| 175 | |||
| 176 | if ($user->admin) { |
||
| 177 | $this->tpl['info_admin'] = info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); |
||
| 178 | } |
||
| 179 | |||
| 180 | // State |
||
| 181 | if ($this->object->country_id) { |
||
| 182 | $this->tpl['select_state'] = $formcompany->select_state($this->object->state_id, $this->object->country_code); |
||
| 183 | } else { |
||
| 184 | $this->tpl['select_state'] = $countrynotdefined; |
||
| 185 | } |
||
| 186 | |||
| 187 | // Public or private |
||
| 188 | $selectarray = array('0' => $langs->trans("ContactPublic"), '1' => $langs->trans("ContactPrivate")); |
||
| 189 | $this->tpl['select_visibility'] = $form->selectarray('priv', $selectarray, $this->object->priv, 0); |
||
| 190 | } |
||
| 191 | |||
| 192 | if ($action == 'view' || $action == 'edit' || $action == 'delete') { |
||
| 193 | // Emailing |
||
| 194 | if (isModEnabled('mailing')) { |
||
| 195 | $langs->load("mails"); |
||
| 196 | $this->tpl['nb_emailing'] = $this->object->getNbOfEMailings(); |
||
| 197 | } |
||
| 198 | |||
| 199 | // Linked element |
||
| 200 | $this->tpl['contact_element'] = array(); |
||
| 201 | $i = 0; |
||
| 202 | |||
| 203 | $this->object->load_ref_elements(); |
||
| 204 | |||
| 205 | if (isModEnabled('order')) { |
||
| 206 | $this->tpl['contact_element'][$i]['linked_element_label'] = $langs->trans("ContactForOrders"); |
||
| 207 | $this->tpl['contact_element'][$i]['linked_element_value'] = $this->object->ref_commande ? $this->object->ref_commande : $langs->trans("NoContactForAnyOrder"); |
||
| 208 | $i++; |
||
| 209 | } |
||
| 210 | if (isModEnabled("propal")) { |
||
| 211 | $this->tpl['contact_element'][$i]['linked_element_label'] = $langs->trans("ContactForProposals"); |
||
| 212 | $this->tpl['contact_element'][$i]['linked_element_value'] = $this->object->ref_propal ? $this->object->ref_propal : $langs->trans("NoContactForAnyProposal"); |
||
| 213 | $i++; |
||
| 214 | } |
||
| 215 | if (isModEnabled('contract')) { |
||
| 216 | $this->tpl['contact_element'][$i]['linked_element_label'] = $langs->trans("ContactForContracts"); |
||
| 217 | $this->tpl['contact_element'][$i]['linked_element_value'] = $this->object->ref_contrat ? $this->object->ref_contrat : $langs->trans("NoContactForAnyContract"); |
||
| 218 | $i++; |
||
| 219 | } |
||
| 220 | if (isModEnabled('invoice')) { |
||
| 221 | $this->tpl['contact_element'][$i]['linked_element_label'] = $langs->trans("ContactForInvoices"); |
||
| 222 | $this->tpl['contact_element'][$i]['linked_element_value'] = $this->object->ref_facturation ? $this->object->ref_facturation : $langs->trans("NoContactForAnyInvoice"); |
||
| 223 | $i++; |
||
| 224 | } |
||
| 225 | |||
| 226 | // Dolibarr user |
||
| 227 | if ($this->object->user_id) { |
||
| 228 | $dolibarr_user = new User($this->db); |
||
| 229 | $result = $dolibarr_user->fetch($this->object->user_id); |
||
| 230 | $this->tpl['dolibarr_user'] = $dolibarr_user->getLoginUrl(1); |
||
| 231 | } else { |
||
| 232 | $this->tpl['dolibarr_user'] = $langs->trans("NoDolibarrAccess"); |
||
| 233 | } |
||
| 234 | } |
||
| 235 | |||
| 236 | if ($action == 'view' || $action == 'delete') { |
||
| 237 | $this->tpl['showrefnav'] = $form->showrefnav($this->object, 'id'); |
||
| 238 | |||
| 239 | if ($this->object->socid > 0) { |
||
| 240 | $objsoc = new Societe($this->db); |
||
| 241 | |||
| 242 | $objsoc->fetch($this->object->socid); |
||
| 243 | $this->tpl['company'] = $objsoc->getNomUrl(1); |
||
| 244 | } else { |
||
| 245 | $this->tpl['company'] = $langs->trans("ContactNotLinkedToCompany"); |
||
| 246 | } |
||
| 247 | |||
| 248 | $this->tpl['civility'] = $this->object->getCivilityLabel(); |
||
| 249 | |||
| 250 | $this->tpl['address'] = dol_nl2br($this->object->address); |
||
| 251 | |||
| 252 | $this->tpl['zip'] = ($this->object->zip ? $this->object->zip . ' ' : ''); |
||
| 253 | |||
| 254 | $img = picto_from_langcode($this->object->country_code); |
||
| 255 | $this->tpl['country'] = ($img ? $img . ' ' : '') . $this->object->country; |
||
| 256 | |||
| 257 | $this->tpl['phone_pro'] = dol_print_phone($this->object->phone_pro, $this->object->country_code, 0, $this->object->id, 'AC_TEL'); |
||
| 258 | $this->tpl['phone_perso'] = dol_print_phone($this->object->phone_perso, $this->object->country_code, 0, $this->object->id, 'AC_TEL'); |
||
| 259 | $this->tpl['phone_mobile'] = dol_print_phone($this->object->phone_mobile, $this->object->country_code, 0, $this->object->id, 'AC_TEL'); |
||
| 260 | $this->tpl['fax'] = dol_print_phone($this->object->fax, $this->object->country_code, 0, $this->object->id, 'AC_FAX'); |
||
| 261 | $this->tpl['email'] = dol_print_email($this->object->email, 0, $this->object->id, 1); |
||
| 262 | |||
| 263 | $this->tpl['visibility'] = $this->object->LibPubPriv($this->object->priv); |
||
| 264 | |||
| 265 | $this->tpl['note'] = $this->object->note_private; |
||
| 266 | } |
||
| 267 | |||
| 268 | if ($action == 'create_user') { |
||
| 269 | // Full firstname and lastname separated with a dot : firstname.lastname |
||
| 270 | include_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php'; |
||
| 271 | require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/security2.lib.php'; |
||
| 272 | $login = dol_buildlogin($this->object->lastname, $this->object->firstname); |
||
| 273 | |||
| 274 | $generated_password = getRandomPassword(false); |
||
| 275 | $password = $generated_password; |
||
| 276 | |||
| 277 | // Create a form array |
||
| 278 | $formquestion = array( |
||
| 279 | array('label' => $langs->trans("LoginToCreate"), 'type' => 'text', 'name' => 'login', 'value' => $login), |
||
| 280 | array('label' => $langs->trans("Password"), 'type' => 'text', 'name' => 'password', 'value' => $password)); |
||
| 281 | |||
| 282 | $this->tpl['action_create_user'] = $form->formconfirm($_SERVER["PHP_SELF"] . "?id=" . $this->object->id, $langs->trans("CreateDolibarrLogin"), $langs->trans("ConfirmCreateContact"), "confirm_create_user", $formquestion, 'no'); |
||
| 283 | } |
||
| 332 |