| Total Complexity | 122 |
| Total Lines | 936 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Complex classes like AdherentType often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use AdherentType, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 35 | class AdherentType extends CommonObject |
||
| 36 | { |
||
| 37 | /** |
||
| 38 | * @var string Name of table without prefix where object is stored |
||
| 39 | */ |
||
| 40 | public $table_element = 'adherent_type'; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @var string ID to identify managed object |
||
| 44 | */ |
||
| 45 | public $element = 'adherent_type'; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png |
||
| 49 | */ |
||
| 50 | public $picto = 'members'; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * 0=No test on entity, 1=Test with field entity, 2=Test with link by societe |
||
| 54 | * @var int |
||
| 55 | */ |
||
| 56 | public $ismultientitymanaged = 1; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @var string |
||
| 60 | * @deprecated Use label |
||
| 61 | * @see $label |
||
| 62 | */ |
||
| 63 | public $libelle; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @var string Adherent type label |
||
| 67 | */ |
||
| 68 | public $label; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @var string Adherent type nature |
||
| 72 | */ |
||
| 73 | public $morphy; |
||
| 74 | |||
| 75 | public $duration; |
||
| 76 | |||
| 77 | /* |
||
| 78 | * type expiration |
||
| 79 | */ |
||
| 80 | public $duration_value; |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Expiration unit |
||
| 84 | */ |
||
| 85 | public $duration_unit; |
||
| 86 | |||
| 87 | /** |
||
| 88 | * @var int Subsription required (0 or 1) |
||
| 89 | */ |
||
| 90 | public $subscription; |
||
| 91 | |||
| 92 | /** |
||
| 93 | * @var float|string Amount for subscription (null or '' means not defined) |
||
| 94 | */ |
||
| 95 | public $amount; |
||
| 96 | |||
| 97 | /** |
||
| 98 | * @var int Amount can be choosen by the visitor during subscription (0 or 1) |
||
| 99 | */ |
||
| 100 | public $caneditamount; |
||
| 101 | |||
| 102 | /** |
||
| 103 | * @var string Public note |
||
| 104 | * @deprecated |
||
| 105 | */ |
||
| 106 | public $note; |
||
| 107 | |||
| 108 | /** @var string Public note */ |
||
| 109 | public $note_public; |
||
| 110 | |||
| 111 | /** @var integer Can vote */ |
||
| 112 | public $vote; |
||
| 113 | |||
| 114 | /** @var string Email sent during validation of member */ |
||
| 115 | public $mail_valid; |
||
| 116 | |||
| 117 | /** @var string Email sent after recording a new subscription */ |
||
| 118 | public $mail_subscription = ''; |
||
| 119 | |||
| 120 | /** @var string Email sent after resiliation */ |
||
| 121 | public $mail_resiliate = ''; |
||
| 122 | |||
| 123 | /** @var string Email sent after exclude */ |
||
| 124 | public $mail_exclude = ''; |
||
| 125 | |||
| 126 | /** @var array Array of members */ |
||
| 127 | public $members = array(); |
||
| 128 | |||
| 129 | /** @var string string other */ |
||
| 130 | public $other = array(); |
||
| 131 | |||
| 132 | public $multilangs = array(); |
||
| 133 | |||
| 134 | |||
| 135 | /** |
||
| 136 | * Constructor |
||
| 137 | * |
||
| 138 | * @param DoliDB $db Database handler |
||
| 139 | */ |
||
| 140 | public function __construct($db) |
||
| 144 | } |
||
| 145 | |||
| 146 | /** |
||
| 147 | * Load array this->multilangs |
||
| 148 | * |
||
| 149 | * @return int <0 if KO, >0 if OK |
||
| 150 | */ |
||
| 151 | public function getMultiLangs() |
||
| 178 | } |
||
| 179 | } |
||
| 180 | |||
| 181 | /** |
||
| 182 | * Update or add a translation for this member type |
||
| 183 | * |
||
| 184 | * @param User $user Object user making update |
||
| 185 | * @return int <0 if KO, >0 if OK |
||
| 186 | */ |
||
| 187 | public function setMultiLangs($user) |
||
| 188 | { |
||
| 189 | global $conf, $langs; |
||
| 190 | |||
| 191 | $langs_available = $langs->get_available_languages(DOL_DOCUMENT_ROOT, 0, 2); |
||
| 192 | $current_lang = $langs->getDefaultLang(); |
||
| 193 | |||
| 194 | foreach ($langs_available as $key => $value) { |
||
| 195 | if ($key == $current_lang) { |
||
| 196 | $sql = "SELECT rowid"; |
||
| 197 | $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type_lang"; |
||
| 198 | $sql .= " WHERE fk_type = ".((int) $this->id); |
||
| 199 | $sql .= " AND lang = '".$this->db->escape($key)."'"; |
||
| 200 | |||
| 201 | $result = $this->db->query($sql); |
||
| 202 | |||
| 203 | if ($this->db->num_rows($result)) { // if there is already a description line for this language |
||
| 204 | $sql2 = "UPDATE ".MAIN_DB_PREFIX."adherent_type_lang"; |
||
| 205 | $sql2 .= " SET"; |
||
| 206 | $sql2 .= " label = '".$this->db->escape($this->label)."',"; |
||
| 207 | $sql2 .= " description = '".$this->db->escape($this->description)."'"; |
||
| 208 | $sql2 .= " WHERE fk_type = ".((int) $this->id)." AND lang='".$this->db->escape($key)."'"; |
||
| 209 | } else { |
||
| 210 | $sql2 = "INSERT INTO ".MAIN_DB_PREFIX."adherent_type_lang (fk_type, lang, label, description"; |
||
| 211 | $sql2 .= ")"; |
||
| 212 | $sql2 .= " VALUES(".((int) $this->id).",'".$this->db->escape($key)."','".$this->db->escape($this->label)."',"; |
||
| 213 | $sql2 .= " '".$this->db->escape($this->description)."'"; |
||
| 214 | $sql2 .= ")"; |
||
| 215 | } |
||
| 216 | dol_syslog(get_class($this).'::setMultiLangs key = current_lang = '.$key); |
||
| 217 | if (!$this->db->query($sql2)) { |
||
| 218 | $this->error = $this->db->lasterror(); |
||
| 219 | return -1; |
||
| 220 | } |
||
| 221 | } elseif (isset($this->multilangs[$key])) { |
||
| 222 | $sql = "SELECT rowid"; |
||
| 223 | $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type_lang"; |
||
| 224 | $sql .= " WHERE fk_type = ".((int) $this->id); |
||
| 225 | $sql .= " AND lang = '".$this->db->escape($key)."'"; |
||
| 226 | |||
| 227 | $result = $this->db->query($sql); |
||
| 228 | |||
| 229 | if ($this->db->num_rows($result)) { // if there is already a description line for this language |
||
| 230 | $sql2 = "UPDATE ".MAIN_DB_PREFIX."adherent_type_lang"; |
||
| 231 | $sql2 .= " SET "; |
||
| 232 | $sql2 .= " label = '".$this->db->escape($this->multilangs["$key"]["label"])."',"; |
||
| 233 | $sql2 .= " description = '".$this->db->escape($this->multilangs["$key"]["description"])."'"; |
||
| 234 | $sql2 .= " WHERE fk_type = ".((int) $this->id)." AND lang='".$this->db->escape($key)."'"; |
||
| 235 | } else { |
||
| 236 | $sql2 = "INSERT INTO ".MAIN_DB_PREFIX."adherent_type_lang (fk_type, lang, label, description"; |
||
| 237 | $sql2 .= ")"; |
||
| 238 | $sql2 .= " VALUES(".$this->id.",'".$this->db->escape($key)."','".$this->db->escape($this->multilangs["$key"]["label"])."',"; |
||
| 239 | $sql2 .= " '".$this->db->escape($this->multilangs["$key"]["description"])."'"; |
||
| 240 | $sql2 .= ")"; |
||
| 241 | } |
||
| 242 | |||
| 243 | // We do not save if main fields are empty |
||
| 244 | if ($this->multilangs["$key"]["label"] || $this->multilangs["$key"]["description"]) { |
||
| 245 | if (!$this->db->query($sql2)) { |
||
| 246 | $this->error = $this->db->lasterror(); |
||
| 247 | return -1; |
||
| 248 | } |
||
| 249 | } |
||
| 250 | } else { |
||
| 251 | // language is not current language and we didn't provide a multilang description for this language |
||
| 252 | } |
||
| 253 | } |
||
| 254 | |||
| 255 | // Call trigger |
||
| 256 | $result = $this->call_trigger('MEMBER_TYPE_SET_MULTILANGS', $user); |
||
| 257 | if ($result < 0) { |
||
| 258 | $this->error = $this->db->lasterror(); |
||
| 259 | return -1; |
||
| 260 | } |
||
| 261 | // End call triggers |
||
| 262 | |||
| 263 | return 1; |
||
| 264 | } |
||
| 265 | |||
| 266 | /** |
||
| 267 | * Delete a language for this member type |
||
| 268 | * |
||
| 269 | * @param string $langtodelete Language code to delete |
||
| 270 | * @param User $user Object user making delete |
||
| 271 | * @return int <0 if KO, >0 if OK |
||
| 272 | */ |
||
| 273 | public function delMultiLangs($langtodelete, $user) |
||
| 274 | { |
||
| 275 | $sql = "DELETE FROM ".MAIN_DB_PREFIX."adherent_type_lang"; |
||
| 276 | $sql .= " WHERE fk_type = ".((int) $this->id)." AND lang = '".$this->db->escape($langtodelete)."'"; |
||
| 277 | |||
| 278 | dol_syslog(get_class($this).'::delMultiLangs', LOG_DEBUG); |
||
| 279 | $result = $this->db->query($sql); |
||
| 280 | if ($result) { |
||
| 281 | // Call trigger |
||
| 282 | $result = $this->call_trigger('MEMBER_TYPE_DEL_MULTILANGS', $user); |
||
| 283 | if ($result < 0) { |
||
| 284 | $this->error = $this->db->lasterror(); |
||
| 285 | dol_syslog(get_class($this).'::delMultiLangs error='.$this->error, LOG_ERR); |
||
| 286 | return -1; |
||
| 287 | } |
||
| 288 | // End call triggers |
||
| 289 | return 1; |
||
| 290 | } else { |
||
| 291 | $this->error = $this->db->lasterror(); |
||
| 292 | dol_syslog(get_class($this).'::delMultiLangs error='.$this->error, LOG_ERR); |
||
| 293 | return -1; |
||
| 294 | } |
||
| 295 | } |
||
| 296 | |||
| 297 | /** |
||
| 298 | * Function to create the member type |
||
| 299 | * |
||
| 300 | * @param User $user User making creation |
||
| 301 | * @param int $notrigger 1=do not execute triggers, 0 otherwise |
||
| 302 | * @return int >0 if OK, < 0 if KO |
||
| 303 | */ |
||
| 304 | public function create($user, $notrigger = 0) |
||
| 305 | { |
||
| 306 | global $langs, $conf; |
||
| 307 | |||
| 308 | $error = 0; |
||
| 309 | |||
| 310 | $this->status = (int) $this->status; |
||
| 311 | $this->label = trim($this->label); |
||
| 312 | |||
| 313 | $this->db->begin(); |
||
| 314 | |||
| 315 | $sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent_type ("; |
||
| 316 | $sql .= " morphy"; |
||
| 317 | $sql .= ", libelle"; |
||
| 318 | $sql .= ", entity"; |
||
| 319 | $sql .= ") VALUES ("; |
||
| 320 | $sql .= "'".$this->db->escape($this->morphy)."'"; |
||
| 321 | $sql .= ", '".$this->db->escape($this->label)."'"; |
||
| 322 | $sql .= ", ".((int) $conf->entity); |
||
| 323 | $sql .= ")"; |
||
| 324 | |||
| 325 | dol_syslog("Adherent_type::create", LOG_DEBUG); |
||
| 326 | $result = $this->db->query($sql); |
||
| 327 | if ($result) { |
||
| 328 | $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."adherent_type"); |
||
| 329 | |||
| 330 | $result = $this->update($user, 1); |
||
| 331 | if ($result < 0) { |
||
| 332 | $this->db->rollback(); |
||
| 333 | return -3; |
||
| 334 | } |
||
| 335 | |||
| 336 | if (!$notrigger) { |
||
| 337 | // Call trigger |
||
| 338 | $result = $this->call_trigger('MEMBER_TYPE_CREATE', $user); |
||
| 339 | if ($result < 0) { |
||
| 340 | $error++; |
||
| 341 | } |
||
| 342 | // End call triggers |
||
| 343 | } |
||
| 344 | |||
| 345 | if (!$error) { |
||
| 346 | $this->db->commit(); |
||
| 347 | return $this->id; |
||
| 348 | } else { |
||
| 349 | dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR); |
||
| 350 | $this->db->rollback(); |
||
| 351 | return -2; |
||
| 352 | } |
||
| 353 | } else { |
||
| 354 | $this->error = $this->db->lasterror(); |
||
| 355 | $this->db->rollback(); |
||
| 356 | return -1; |
||
| 357 | } |
||
| 358 | } |
||
| 359 | |||
| 360 | /** |
||
| 361 | * Updating the type in the database |
||
| 362 | * |
||
| 363 | * @param User $user Object user making change |
||
| 364 | * @param int $notrigger 1=do not execute triggers, 0 otherwise |
||
| 365 | * @return int >0 if OK, < 0 if KO |
||
| 366 | */ |
||
| 367 | public function update($user, $notrigger = 0) |
||
| 438 | } |
||
| 439 | } |
||
| 440 | |||
| 441 | /** |
||
| 442 | * Function to delete the member's status |
||
| 443 | * TODO Add param "User $user" |
||
| 444 | * |
||
| 445 | * @return int > 0 if OK, 0 if not found, < 0 if KO |
||
| 446 | */ |
||
| 447 | public function delete() |
||
| 448 | { |
||
| 449 | global $user; |
||
| 450 | |||
| 451 | $error = 0; |
||
| 452 | |||
| 453 | $sql = "DELETE FROM ".MAIN_DB_PREFIX."adherent_type"; |
||
| 454 | $sql .= " WHERE rowid = ".((int) $this->id); |
||
| 455 | |||
| 456 | $resql = $this->db->query($sql); |
||
| 457 | if ($resql) { |
||
| 458 | // Call trigger |
||
| 459 | $result = $this->call_trigger('MEMBER_TYPE_DELETE', $user); |
||
| 460 | if ($result < 0) { |
||
| 461 | $error++; $this->db->rollback(); return -2; |
||
| 462 | } |
||
| 463 | // End call triggers |
||
| 464 | |||
| 465 | $this->db->commit(); |
||
| 466 | return 1; |
||
| 467 | } else { |
||
| 468 | $this->db->rollback(); |
||
| 469 | $this->error = $this->db->lasterror(); |
||
| 470 | return -1; |
||
| 471 | } |
||
| 472 | } |
||
| 473 | |||
| 474 | /** |
||
| 475 | * Function that retrieves the properties of a membership type |
||
| 476 | * |
||
| 477 | * @param int $rowid Id of member type to load |
||
| 478 | * @return int <0 if KO, >0 if OK |
||
| 479 | */ |
||
| 480 | public function fetch($rowid) |
||
| 481 | { |
||
| 482 | global $langs, $conf; |
||
| 483 | |||
| 484 | $sql = "SELECT d.rowid, d.libelle as label, d.morphy, d.statut as status, d.duration, d.subscription, d.amount, d.caneditamount, d.mail_valid, d.note as note_public, d.vote"; |
||
| 485 | $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as d"; |
||
| 486 | $sql .= " WHERE d.rowid = ".(int) $rowid; |
||
| 487 | |||
| 488 | dol_syslog("Adherent_type::fetch", LOG_DEBUG); |
||
| 489 | |||
| 490 | $resql = $this->db->query($sql); |
||
| 491 | if ($resql) { |
||
| 492 | if ($this->db->num_rows($resql)) { |
||
| 493 | $obj = $this->db->fetch_object($resql); |
||
| 494 | |||
| 495 | $this->id = $obj->rowid; |
||
| 496 | $this->ref = $obj->rowid; |
||
| 497 | $this->label = $obj->label; |
||
| 498 | $this->morphy = $obj->morphy; |
||
| 499 | $this->status = $obj->status; |
||
| 500 | $this->duration = $obj->duration; |
||
| 501 | $this->duration_value = substr($obj->duration, 0, dol_strlen($obj->duration) - 1); |
||
| 502 | $this->duration_unit = substr($obj->duration, -1); |
||
| 503 | $this->subscription = $obj->subscription; |
||
| 504 | $this->amount = $obj->amount; |
||
| 505 | $this->caneditamount = $obj->caneditamount; |
||
| 506 | $this->mail_valid = $obj->mail_valid; |
||
| 507 | $this->note = $obj->note_public; // deprecated |
||
| 508 | $this->note_public = $obj->note_public; |
||
| 509 | $this->vote = $obj->vote; |
||
| 510 | |||
| 511 | // multilangs |
||
| 512 | if (getDolGlobalInt('MAIN_MULTILANGS')) { |
||
| 513 | $this->getMultiLangs(); |
||
| 514 | } |
||
| 515 | |||
| 516 | // fetch optionals attributes and labels |
||
| 517 | $this->fetch_optionals(); |
||
| 518 | } |
||
| 519 | |||
| 520 | return 1; |
||
| 521 | } else { |
||
| 522 | $this->error = $this->db->lasterror(); |
||
| 523 | return -1; |
||
| 524 | } |
||
| 525 | } |
||
| 526 | |||
| 527 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 528 | /** |
||
| 529 | * Return list of members' type |
||
| 530 | * |
||
| 531 | * @param int $status Filter on status of type |
||
| 532 | * @return array List of types of members |
||
| 533 | */ |
||
| 534 | public function liste_array($status = -1) |
||
| 535 | { |
||
| 536 | // phpcs:enable |
||
| 537 | global $conf, $langs; |
||
| 538 | |||
| 539 | $adherenttypes = array(); |
||
| 540 | |||
| 541 | $sql = "SELECT rowid, libelle as label"; |
||
| 542 | $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type"; |
||
| 543 | $sql .= " WHERE entity IN (".getEntity('member_type').")"; |
||
| 544 | if ($status >= 0) { |
||
| 545 | $sql .= " AND statut = ".((int) $status); |
||
| 546 | } |
||
| 547 | |||
| 548 | $resql = $this->db->query($sql); |
||
| 549 | if ($resql) { |
||
| 550 | $nump = $this->db->num_rows($resql); |
||
| 551 | |||
| 552 | if ($nump) { |
||
| 553 | $i = 0; |
||
| 554 | while ($i < $nump) { |
||
| 555 | $obj = $this->db->fetch_object($resql); |
||
| 556 | |||
| 557 | $adherenttypes[$obj->rowid] = $langs->trans($obj->label); |
||
| 558 | $i++; |
||
| 559 | } |
||
| 560 | } |
||
| 561 | } else { |
||
| 562 | print $this->db->error(); |
||
| 563 | } |
||
| 564 | return $adherenttypes; |
||
| 565 | } |
||
| 566 | |||
| 567 | /** |
||
| 568 | * Return the array of all amounts per membership type id |
||
| 569 | * |
||
| 570 | * @param int $status Filter on status of type |
||
| 571 | * @return array Array of membership type |
||
| 572 | */ |
||
| 573 | public function amountByType($status = null) |
||
| 574 | { |
||
| 575 | global $conf, $langs; |
||
| 576 | |||
| 577 | $amountbytype = array(); |
||
| 578 | |||
| 579 | $sql = "SELECT rowid, amount"; |
||
| 580 | $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type"; |
||
| 581 | $sql .= " WHERE entity IN (".getEntity('member_type').")"; |
||
| 582 | if ($status !== null) { |
||
| 583 | $sql .= " AND statut = ".((int) $status); |
||
| 584 | } |
||
| 585 | |||
| 586 | $resql = $this->db->query($sql); |
||
| 587 | if ($resql) { |
||
| 588 | $nump = $this->db->num_rows($resql); |
||
| 589 | |||
| 590 | if ($nump) { |
||
| 591 | $i = 0; |
||
| 592 | while ($i < $nump) { |
||
| 593 | $obj = $this->db->fetch_object($resql); |
||
| 594 | |||
| 595 | $amountbytype[$obj->rowid] = $obj->amount; |
||
| 596 | $i++; |
||
| 597 | } |
||
| 598 | } |
||
| 599 | } else { |
||
| 600 | print $this->db->error(); |
||
| 601 | } |
||
| 602 | |||
| 603 | return $amountbytype; |
||
| 604 | } |
||
| 605 | |||
| 606 | /** |
||
| 607 | * Return array of Member objects for member type this->id (or all if this->id not defined) |
||
| 608 | * |
||
| 609 | * @param string $excludefilter Filter to exclude. This value must not come from a user input. |
||
| 610 | * @param int $mode 0=Return array of member instance |
||
| 611 | * 1=Return array of member instance without extra data |
||
| 612 | * 2=Return array of members id only |
||
| 613 | * @return mixed Array of members or -1 on error |
||
| 614 | */ |
||
| 615 | public function listMembersForMemberType($excludefilter = '', $mode = 0) |
||
| 616 | { |
||
| 617 | global $conf, $user; |
||
| 618 | |||
| 619 | $ret = array(); |
||
| 620 | |||
| 621 | $sql = "SELECT a.rowid"; |
||
| 622 | $sql .= " FROM ".MAIN_DB_PREFIX."adherent as a"; |
||
| 623 | $sql .= " WHERE a.entity IN (".getEntity('member').")"; |
||
| 624 | $sql .= " AND a.fk_adherent_type = ".((int) $this->id); |
||
| 625 | if (!empty($excludefilter)) { |
||
| 626 | $sql .= ' AND ('.$excludefilter.')'; |
||
| 627 | } |
||
| 628 | |||
| 629 | dol_syslog(get_class($this)."::listUsersForGroup", LOG_DEBUG); |
||
| 630 | $resql = $this->db->query($sql); |
||
| 631 | if ($resql) { |
||
| 632 | while ($obj = $this->db->fetch_object($resql)) { |
||
| 633 | if (!array_key_exists($obj->rowid, $ret)) { |
||
| 634 | if ($mode < 2) { |
||
| 635 | $memberstatic = new Adherent($this->db); |
||
| 636 | if ($mode == 1) { |
||
| 637 | $memberstatic->fetch($obj->rowid, '', '', '', false, false); |
||
| 638 | } else { |
||
| 639 | $memberstatic->fetch($obj->rowid); |
||
| 640 | } |
||
| 641 | $ret[$obj->rowid] = $memberstatic; |
||
| 642 | } else { |
||
| 643 | $ret[$obj->rowid] = $obj->rowid; |
||
| 644 | } |
||
| 645 | } |
||
| 646 | } |
||
| 647 | |||
| 648 | $this->db->free($resql); |
||
| 649 | |||
| 650 | $this->members = $ret; |
||
| 651 | |||
| 652 | return $ret; |
||
| 653 | } else { |
||
| 654 | $this->error = $this->db->lasterror(); |
||
| 655 | return -1; |
||
| 656 | } |
||
| 657 | } |
||
| 658 | |||
| 659 | /** |
||
| 660 | * Return translated label by the nature of a adherent (physical or moral) |
||
| 661 | * |
||
| 662 | * @param string $morphy Nature of the adherent (physical or moral) |
||
| 663 | * @return string Label |
||
| 664 | */ |
||
| 665 | public function getmorphylib($morphy = '') |
||
| 666 | { |
||
| 667 | global $langs; |
||
| 668 | if ($morphy == 'phy') { |
||
| 669 | return $langs->trans("Physical"); |
||
| 670 | } elseif ($morphy == 'mor') { |
||
| 671 | return $langs->trans("Moral"); |
||
| 672 | } else { |
||
| 673 | return $langs->trans("MorAndPhy"); |
||
| 674 | } |
||
| 675 | //return $morphy; |
||
| 676 | } |
||
| 677 | |||
| 678 | /** |
||
| 679 | * Return clicable name (with picto eventually) |
||
| 680 | * |
||
| 681 | * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto |
||
| 682 | * @param int $maxlen length max label |
||
| 683 | * @param int $notooltip 1=Disable tooltip |
||
| 684 | * @param string $morecss Add more css on link |
||
| 685 | * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking |
||
| 686 | * @return string String with URL |
||
| 687 | */ |
||
| 688 | public function getNomUrl($withpicto = 0, $maxlen = 0, $notooltip = 0, $morecss = '', $save_lastsearch_value = -1) |
||
| 689 | { |
||
| 690 | global $langs; |
||
| 691 | |||
| 692 | $result = ''; |
||
| 693 | |||
| 694 | $label = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("MemberType").'</u>'; |
||
| 695 | $label .= ' '.$this->getLibStatut(4); |
||
| 696 | $label .= '<br>'.$langs->trans("Label").': '.$this->label; |
||
| 697 | if (isset($this->subscription)) { |
||
| 698 | $label .= '<br>'.$langs->trans("SubscriptionRequired").': '.yn($this->subscription); |
||
| 699 | } |
||
| 700 | |||
| 701 | $option = ''; |
||
| 702 | |||
| 703 | $url = DOL_URL_ROOT.'/adherents/type.php?rowid='.((int) $this->id); |
||
| 704 | |||
| 705 | if ($option != 'nolink') { |
||
| 706 | // Add param to save lastsearch_values or not |
||
| 707 | $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0); |
||
| 708 | if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) { |
||
| 709 | $add_save_lastsearch_values = 1; |
||
| 710 | } |
||
| 711 | if ($add_save_lastsearch_values) { |
||
| 712 | $url .= '&save_lastsearch_values=1'; |
||
| 713 | } |
||
| 714 | } |
||
| 715 | |||
| 716 | $linkstart = '<a href="'.$url.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">'; |
||
| 717 | $linkend = '</a>'; |
||
| 718 | |||
| 719 | $result .= $linkstart; |
||
| 720 | if ($withpicto) { |
||
| 721 | $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); |
||
| 722 | } |
||
| 723 | if ($withpicto != 2) { |
||
| 724 | $result .= ($maxlen ?dol_trunc($this->label, $maxlen) : $this->label); |
||
| 725 | } |
||
| 726 | $result .= $linkend; |
||
| 727 | |||
| 728 | return $result; |
||
| 729 | } |
||
| 730 | |||
| 731 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 732 | /** |
||
| 733 | * Return label of status (activity, closed) |
||
| 734 | * |
||
| 735 | * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto |
||
| 736 | * @return string Label of status |
||
| 737 | */ |
||
| 738 | public function getLibStatut($mode = 0) |
||
| 739 | { |
||
| 740 | return $this->LibStatut($this->status, $mode); |
||
| 741 | } |
||
| 742 | |||
| 743 | /** |
||
| 744 | * Return the label of a given status |
||
| 745 | * |
||
| 746 | * @param int $status Status id |
||
| 747 | * @param int $mode 0=Long label, 1=Short label, 2=Picto + Short label, 3=Picto, 4=Picto + Long label, 5=Short label + Picto, 6=Long label + Picto |
||
| 748 | * @return string Status label |
||
| 749 | */ |
||
| 750 | public function LibStatut($status, $mode = 0) |
||
| 751 | { |
||
| 752 | // phpcs:enable |
||
| 753 | global $langs; |
||
| 754 | $langs->load('companies'); |
||
| 755 | |||
| 756 | $statusType = 'status4'; |
||
| 757 | if ($status == 0) { |
||
| 758 | $statusType = 'status5'; |
||
| 759 | } |
||
| 760 | |||
| 761 | if (empty($this->labelStatus) || empty($this->labelStatusShort)) { |
||
| 762 | $this->labelStatus[0] = $langs->transnoentitiesnoconv("ActivityCeased"); |
||
| 763 | $this->labelStatus[1] = $langs->transnoentitiesnoconv("InActivity"); |
||
| 764 | $this->labelStatusShort[0] = $langs->transnoentitiesnoconv("ActivityCeased"); |
||
| 765 | $this->labelStatusShort[1] = $langs->transnoentitiesnoconv("InActivity"); |
||
| 766 | } |
||
| 767 | |||
| 768 | return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode); |
||
| 769 | } |
||
| 770 | |||
| 771 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 772 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore |
||
| 773 | /** |
||
| 774 | * Retourne chaine DN complete dans l'annuaire LDAP pour l'objet |
||
| 775 | * |
||
| 776 | * @param array $info Info array loaded by _load_ldap_info |
||
| 777 | * @param int $mode 0=Return full DN (uid=qqq,ou=xxx,dc=aaa,dc=bbb) |
||
| 778 | * 1=Return DN without key inside (ou=xxx,dc=aaa,dc=bbb) |
||
| 779 | * 2=Return key only (uid=qqq) |
||
| 780 | * @return string DN |
||
| 781 | */ |
||
| 782 | public function _load_ldap_dn($info, $mode = 0) |
||
| 783 | { |
||
| 784 | // phpcs:enable |
||
| 785 | global $conf; |
||
| 786 | $dn = ''; |
||
| 787 | if ($mode == 0) { |
||
| 788 | $dn = $conf->global->LDAP_KEY_MEMBERS_TYPES."=".$info[$conf->global->LDAP_KEY_MEMBERS_TYPES].",".$conf->global->LDAP_MEMBER_TYPE_DN; |
||
| 789 | } |
||
| 790 | if ($mode == 1) { |
||
| 791 | $dn = $conf->global->LDAP_MEMBER_TYPE_DN; |
||
| 792 | } |
||
| 793 | if ($mode == 2) { |
||
| 794 | $dn = $conf->global->LDAP_KEY_MEMBERS_TYPES."=".$info[$conf->global->LDAP_KEY_MEMBERS_TYPES]; |
||
| 795 | } |
||
| 796 | return $dn; |
||
| 797 | } |
||
| 798 | |||
| 799 | |||
| 800 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 801 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore |
||
| 802 | /** |
||
| 803 | * Initialize the info array (array of LDAP values) that will be used to call LDAP functions |
||
| 804 | * |
||
| 805 | * @return array Tableau info des attributs |
||
| 806 | */ |
||
| 807 | public function _load_ldap_info() |
||
| 808 | { |
||
| 809 | // phpcs:enable |
||
| 810 | global $conf, $langs; |
||
| 811 | |||
| 812 | $info = array(); |
||
| 813 | |||
| 814 | // Object classes |
||
| 815 | $info["objectclass"] = explode(',', $conf->global->LDAP_MEMBER_TYPE_OBJECT_CLASS); |
||
| 816 | |||
| 817 | if (empty($this->note_public) && !empty($this->note)) { // For backward compatibility |
||
| 818 | $this->note_public = $this->note; |
||
| 819 | } |
||
| 820 | |||
| 821 | // Champs |
||
| 822 | if ($this->label && !empty($conf->global->LDAP_MEMBER_TYPE_FIELD_FULLNAME)) { |
||
| 823 | $info[$conf->global->LDAP_MEMBER_TYPE_FIELD_FULLNAME] = $this->label; |
||
| 824 | } |
||
| 825 | if ($this->note_public && !empty($conf->global->LDAP_MEMBER_TYPE_FIELD_DESCRIPTION)) { |
||
| 826 | $info[$conf->global->LDAP_MEMBER_TYPE_FIELD_DESCRIPTION] = dol_string_nohtmltag($this->note_public, 0, 'UTF-8', 1); |
||
| 827 | } |
||
| 828 | if (!empty($conf->global->LDAP_MEMBER_TYPE_FIELD_GROUPMEMBERS)) { |
||
| 829 | $valueofldapfield = array(); |
||
| 830 | foreach ($this->members as $key => $val) { // This is array of users for group into dolibarr database. |
||
| 831 | $member = new Adherent($this->db); |
||
| 832 | $member->fetch($val->id, '', '', '', false, false); |
||
| 833 | $info2 = $member->_load_ldap_info(); |
||
| 834 | $valueofldapfield[] = $member->_load_ldap_dn($info2); |
||
| 835 | } |
||
| 836 | $info[$conf->global->LDAP_MEMBER_TYPE_FIELD_GROUPMEMBERS] = (!empty($valueofldapfield) ? $valueofldapfield : ''); |
||
| 837 | } |
||
| 838 | return $info; |
||
| 839 | } |
||
| 840 | |||
| 841 | /** |
||
| 842 | * Initialise an instance with random values. |
||
| 843 | * Used to build previews or test instances. |
||
| 844 | * id must be 0 if object instance is a specimen. |
||
| 845 | * |
||
| 846 | * @return void |
||
| 847 | */ |
||
| 848 | public function initAsSpecimen() |
||
| 869 | ); |
||
| 870 | } |
||
| 871 | |||
| 872 | /** |
||
| 873 | * getMailOnValid |
||
| 874 | * |
||
| 875 | * @return string Return mail content of type or empty |
||
| 876 | */ |
||
| 877 | public function getMailOnValid() |
||
| 878 | { |
||
| 879 | if (!empty($this->mail_valid) && trim(dol_htmlentitiesbr_decode($this->mail_valid))) { |
||
| 880 | return $this->mail_valid; |
||
| 881 | } |
||
| 882 | |||
| 883 | return ''; |
||
| 884 | } |
||
| 885 | |||
| 886 | /** |
||
| 887 | * getMailOnSubscription |
||
| 888 | * |
||
| 889 | * @return string Return mail content of type or empty |
||
| 890 | */ |
||
| 891 | public function getMailOnSubscription() |
||
| 892 | { |
||
| 893 | // mail_subscription not defined so never used |
||
| 894 | if (!empty($this->mail_subscription) && trim(dol_htmlentitiesbr_decode($this->mail_subscription))) { // Property not yet defined |
||
| 895 | return $this->mail_subscription; |
||
| 896 | } |
||
| 897 | |||
| 898 | return ''; |
||
| 899 | } |
||
| 900 | |||
| 901 | /** |
||
| 902 | * getMailOnResiliate |
||
| 903 | * |
||
| 904 | * @return string Return mail model content of type or empty |
||
| 905 | */ |
||
| 906 | public function getMailOnResiliate() |
||
| 914 | } |
||
| 915 | |||
| 916 | /** |
||
| 917 | * getMailOnExclude |
||
| 918 | * |
||
| 919 | * @return string Return mail model content of type or empty |
||
| 920 | */ |
||
| 921 | public function getMailOnExclude() |
||
| 929 | } |
||
| 930 | |||
| 931 | |||
| 932 | /** |
||
| 933 | * Return clicable link of object (with eventually picto) |
||
| 934 | * |
||
| 935 | * @param string $option Where point the link (0=> main card, 1,2 => shipment, 'nolink'=>No link) |
||
| 936 | * @return string HTML Code for Kanban thumb. |
||
| 937 | */ |
||
| 938 | public function getKanbanView($option = '') |
||
| 939 | { |
||
| 940 | global $langs,$user; |
||
| 973 |