| Total Complexity | 71 |
| Total Lines | 769 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
Complex classes like Mailing 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 Mailing, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 32 | class Mailing extends CommonObject |
||
| 33 | { |
||
| 34 | /** |
||
| 35 | * @var string ID to identify managed object |
||
| 36 | */ |
||
| 37 | public $element = 'mailing'; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @var string Name of table without prefix where object is stored |
||
| 41 | */ |
||
| 42 | public $table_element = 'mailing'; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png |
||
| 46 | */ |
||
| 47 | public $picto = 'email'; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @var string title |
||
| 51 | */ |
||
| 52 | public $title; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @var string subject |
||
| 56 | */ |
||
| 57 | public $sujet; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @var string body |
||
| 61 | */ |
||
| 62 | public $body; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @var int number of email |
||
| 66 | */ |
||
| 67 | public $nbemail; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @var string background color |
||
| 71 | */ |
||
| 72 | public $bgcolor; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @var string background image |
||
| 76 | */ |
||
| 77 | public $bgimage; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @var int status |
||
| 81 | */ |
||
| 82 | public $statut; // Status 0=Draft, 1=Validated, 2=Sent partially, 3=Sent completely |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @var string email from |
||
| 86 | */ |
||
| 87 | public $email_from; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @var string email reply to |
||
| 91 | */ |
||
| 92 | public $email_replyto; |
||
| 93 | |||
| 94 | /** |
||
| 95 | * @var string email errors to |
||
| 96 | */ |
||
| 97 | public $email_errorsto; |
||
| 98 | |||
| 99 | /** |
||
| 100 | * @var string first joined file |
||
| 101 | */ |
||
| 102 | public $joined_file1; |
||
| 103 | |||
| 104 | /** |
||
| 105 | * @var string second joined file |
||
| 106 | */ |
||
| 107 | public $joined_file2; |
||
| 108 | |||
| 109 | /** |
||
| 110 | * @var string third joined file |
||
| 111 | */ |
||
| 112 | public $joined_file3; |
||
| 113 | |||
| 114 | /** |
||
| 115 | * @var string fourth joined file |
||
| 116 | */ |
||
| 117 | public $joined_file4; |
||
| 118 | |||
| 119 | /** |
||
| 120 | * @var int id of user create |
||
| 121 | */ |
||
| 122 | public $user_creation; |
||
| 123 | |||
| 124 | /** |
||
| 125 | * @var int id of user create |
||
| 126 | * @deprecated |
||
| 127 | */ |
||
| 128 | public $user_creat; |
||
| 129 | |||
| 130 | /** |
||
| 131 | * @var int id of user validate |
||
| 132 | */ |
||
| 133 | public $user_validation; |
||
| 134 | |||
| 135 | /** |
||
| 136 | * @var int id of user validate |
||
| 137 | * @deprecated |
||
| 138 | */ |
||
| 139 | public $user_valid; |
||
| 140 | |||
| 141 | /** |
||
| 142 | * @var integer|string date_creation |
||
| 143 | * @deprecated |
||
| 144 | */ |
||
| 145 | public $date_creat; |
||
| 146 | |||
| 147 | /** |
||
| 148 | * @var integer|string date_creation |
||
| 149 | */ |
||
| 150 | public $date_creation; |
||
| 151 | |||
| 152 | /** |
||
| 153 | * @var int date validate |
||
| 154 | * @deprecated |
||
| 155 | */ |
||
| 156 | public $date_valid; |
||
| 157 | |||
| 158 | /** |
||
| 159 | * @var int date validate |
||
| 160 | */ |
||
| 161 | public $date_validation; |
||
| 162 | |||
| 163 | /** |
||
| 164 | * @var array extraparams |
||
| 165 | */ |
||
| 166 | public $extraparams = array(); |
||
| 167 | |||
| 168 | /** |
||
| 169 | * @var array statut dest |
||
| 170 | */ |
||
| 171 | public $statut_dest = array(); |
||
| 172 | |||
| 173 | /** |
||
| 174 | * @var array statuts |
||
| 175 | */ |
||
| 176 | public $statuts = array(); |
||
| 177 | |||
| 178 | |||
| 179 | /** |
||
| 180 | * Constructor |
||
| 181 | * |
||
| 182 | * @param DoliDb $db Database handler |
||
| 183 | */ |
||
| 184 | public function __construct($db) |
||
| 185 | { |
||
| 186 | $this->db = $db; |
||
| 187 | |||
| 188 | // List of language codes for status |
||
| 189 | $this->statuts[0] = 'MailingStatusDraft'; |
||
| 190 | $this->statuts[1] = 'MailingStatusValidated'; |
||
| 191 | $this->statuts[2] = 'MailingStatusSentPartialy'; |
||
| 192 | $this->statuts[3] = 'MailingStatusSentCompletely'; |
||
| 193 | |||
| 194 | $this->statut_dest[-1] = 'MailingStatusError'; |
||
| 195 | $this->statut_dest[0] = 'MailingStatusNotSent'; |
||
| 196 | $this->statut_dest[1] = 'MailingStatusSent'; |
||
| 197 | $this->statut_dest[2] = 'MailingStatusRead'; |
||
| 198 | $this->statut_dest[3] = 'MailingStatusReadAndUnsubscribe'; // Read but ask to not be contacted anymore |
||
| 199 | } |
||
| 200 | |||
| 201 | /** |
||
| 202 | * Create an EMailing |
||
| 203 | * |
||
| 204 | * @param User $user Object of user making creation |
||
| 205 | * @return int -1 if error, Id of created object if OK |
||
| 206 | */ |
||
| 207 | public function create($user) |
||
| 208 | { |
||
| 209 | global $conf, $langs; |
||
| 210 | |||
| 211 | $this->db->begin(); |
||
| 212 | |||
| 213 | $this->title = trim($this->title); |
||
| 214 | $this->email_from = trim($this->email_from); |
||
| 215 | |||
| 216 | if (!$this->email_from) { |
||
| 217 | $this->error = $langs->trans("ErrorMailFromRequired"); |
||
| 218 | return -1; |
||
| 219 | } |
||
| 220 | |||
| 221 | $now = dol_now(); |
||
| 222 | |||
| 223 | $sql = "INSERT INTO ".MAIN_DB_PREFIX."mailing"; |
||
| 224 | $sql .= " (date_creat, fk_user_creat, entity)"; |
||
| 225 | $sql .= " VALUES ('".$this->db->idate($now)."', ".$user->id.", ".$conf->entity.")"; |
||
| 226 | |||
| 227 | if (!$this->title) { |
||
| 228 | $this->title = $langs->trans("NoTitle"); |
||
| 229 | } |
||
| 230 | |||
| 231 | dol_syslog("Mailing::Create", LOG_DEBUG); |
||
| 232 | $result = $this->db->query($sql); |
||
| 233 | if ($result) { |
||
| 234 | $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."mailing"); |
||
| 235 | |||
| 236 | if ($this->update($user) > 0) { |
||
| 237 | $this->db->commit(); |
||
| 238 | } else { |
||
| 239 | $this->error = $this->db->lasterror(); |
||
| 240 | $this->db->rollback(); |
||
| 241 | return -1; |
||
| 242 | } |
||
| 243 | |||
| 244 | return $this->id; |
||
| 245 | } else { |
||
| 246 | $this->error = $this->db->lasterror(); |
||
| 247 | $this->db->rollback(); |
||
| 248 | return -1; |
||
| 249 | } |
||
| 250 | } |
||
| 251 | |||
| 252 | /** |
||
| 253 | * Update emailing record |
||
| 254 | * |
||
| 255 | * @param User $user Object of user making change |
||
| 256 | * @return int < 0 if KO, > 0 if OK |
||
| 257 | */ |
||
| 258 | public function update($user) |
||
| 259 | { |
||
| 260 | $sql = "UPDATE ".MAIN_DB_PREFIX."mailing "; |
||
| 261 | $sql .= " SET titre = '".$this->db->escape($this->title)."'"; |
||
| 262 | $sql .= ", sujet = '".$this->db->escape($this->sujet)."'"; |
||
| 263 | $sql .= ", body = '".$this->db->escape($this->body)."'"; |
||
| 264 | $sql .= ", email_from = '".$this->db->escape($this->email_from)."'"; |
||
| 265 | $sql .= ", email_replyto = '".$this->db->escape($this->email_replyto)."'"; |
||
| 266 | $sql .= ", email_errorsto = '".$this->db->escape($this->email_errorsto)."'"; |
||
| 267 | $sql .= ", bgcolor = '".($this->bgcolor ? $this->db->escape($this->bgcolor) : null)."'"; |
||
| 268 | $sql .= ", bgimage = '".($this->bgimage ? $this->db->escape($this->bgimage) : null)."'"; |
||
| 269 | $sql .= " WHERE rowid = ".(int) $this->id; |
||
| 270 | |||
| 271 | dol_syslog("Mailing::Update", LOG_DEBUG); |
||
| 272 | $result = $this->db->query($sql); |
||
| 273 | if ($result) { |
||
| 274 | return 1; |
||
| 275 | } else { |
||
| 276 | $this->error = $this->db->lasterror(); |
||
| 277 | return -1; |
||
| 278 | } |
||
| 279 | } |
||
| 280 | |||
| 281 | /** |
||
| 282 | * Get object from database |
||
| 283 | * |
||
| 284 | * @param int $rowid Id of emailing |
||
| 285 | * @return int <0 if KO, >0 if OK |
||
| 286 | */ |
||
| 287 | public function fetch($rowid) |
||
| 288 | { |
||
| 289 | global $conf; |
||
| 290 | |||
| 291 | $sql = "SELECT m.rowid, m.titre as title, m.sujet, m.body, m.bgcolor, m.bgimage"; |
||
| 292 | $sql .= ", m.email_from, m.email_replyto, m.email_errorsto"; |
||
| 293 | $sql .= ", m.statut, m.nbemail"; |
||
| 294 | $sql .= ", m.fk_user_creat, m.fk_user_valid"; |
||
| 295 | $sql .= ", m.date_creat"; |
||
| 296 | $sql .= ", m.date_valid"; |
||
| 297 | $sql .= ", m.date_envoi"; |
||
| 298 | $sql .= ", m.extraparams"; |
||
| 299 | $sql .= " FROM ".MAIN_DB_PREFIX."mailing as m"; |
||
| 300 | $sql .= " WHERE m.rowid = ".(int) $rowid; |
||
| 301 | |||
| 302 | dol_syslog(get_class($this)."::fetch", LOG_DEBUG); |
||
| 303 | $result = $this->db->query($sql); |
||
| 304 | if ($result) { |
||
| 305 | if ($this->db->num_rows($result)) { |
||
| 306 | $obj = $this->db->fetch_object($result); |
||
| 307 | |||
| 308 | $this->id = $obj->rowid; |
||
| 309 | $this->ref = $obj->rowid; |
||
| 310 | $this->statut = $obj->statut; |
||
| 311 | $this->nbemail = $obj->nbemail; |
||
| 312 | $this->title = $obj->title; |
||
| 313 | |||
| 314 | $this->sujet = $obj->sujet; |
||
| 315 | if (!empty($conf->global->FCKEDITOR_ENABLE_MAILING) && dol_textishtml(dol_html_entity_decode($obj->body, ENT_COMPAT | ENT_HTML5))) { |
||
| 316 | $this->body = dol_html_entity_decode($obj->body, ENT_COMPAT | ENT_HTML5); |
||
| 317 | } else { |
||
| 318 | $this->body = $obj->body; |
||
| 319 | } |
||
| 320 | |||
| 321 | $this->bgcolor = $obj->bgcolor; |
||
| 322 | $this->bgimage = $obj->bgimage; |
||
| 323 | |||
| 324 | $this->email_from = $obj->email_from; |
||
| 325 | $this->email_replyto = $obj->email_replyto; |
||
| 326 | $this->email_errorsto = $obj->email_errorsto; |
||
| 327 | |||
| 328 | $this->user_creat = $obj->fk_user_creat; |
||
| 329 | $this->user_creation = $obj->fk_user_creat; |
||
| 330 | $this->user_valid = $obj->fk_user_valid; |
||
| 331 | $this->user_validation = $obj->fk_user_valid; |
||
| 332 | |||
| 333 | $this->date_creat = $this->db->jdate($obj->date_creat); |
||
| 334 | $this->date_creation = $this->db->jdate($obj->date_creat); |
||
| 335 | $this->date_valid = $this->db->jdate($obj->date_valid); |
||
| 336 | $this->date_validation = $this->db->jdate($obj->date_valid); |
||
| 337 | $this->date_envoi = $this->db->jdate($obj->date_envoi); |
||
| 338 | |||
| 339 | $this->extraparams = (array) json_decode($obj->extraparams, true); |
||
| 340 | |||
| 341 | return 1; |
||
| 342 | } else { |
||
| 343 | dol_syslog(get_class($this)."::fetch Erreur -1"); |
||
| 344 | return -1; |
||
| 345 | } |
||
| 346 | } else { |
||
| 347 | dol_syslog(get_class($this)."::fetch Erreur -2"); |
||
| 348 | return -2; |
||
| 349 | } |
||
| 350 | } |
||
| 351 | |||
| 352 | |||
| 353 | /** |
||
| 354 | * Load an object from its id and create a new one in database |
||
| 355 | * |
||
| 356 | * @param User $user User making the clone |
||
| 357 | * @param int $fromid Id of object to clone |
||
| 358 | * @param int $option1 1=Clone content, 0=Forget content |
||
| 359 | * @param int $option2 1=Clone recipients |
||
| 360 | * @return int New id of clone |
||
| 361 | */ |
||
| 362 | public function createFromClone(User $user, $fromid, $option1, $option2) |
||
| 363 | { |
||
| 364 | global $langs; |
||
| 365 | |||
| 366 | $error = 0; |
||
| 367 | |||
| 368 | $object = new Mailing($this->db); |
||
| 369 | |||
| 370 | $this->db->begin(); |
||
| 371 | |||
| 372 | // Load source object |
||
| 373 | $object->fetch($fromid); |
||
| 374 | $object->id = 0; |
||
| 375 | $object->statut = 0; |
||
| 376 | |||
| 377 | // Clear fields |
||
| 378 | $object->title = $langs->trans("CopyOf").' '.$object->title.' '.dol_print_date(dol_now()); |
||
| 379 | |||
| 380 | // If no option copy content |
||
| 381 | if (empty($option1)) { |
||
| 382 | // Clear values |
||
| 383 | $object->nbemail = 0; |
||
| 384 | $object->sujet = ''; |
||
| 385 | $object->body = ''; |
||
| 386 | $object->bgcolor = ''; |
||
| 387 | $object->bgimage = ''; |
||
| 388 | |||
| 389 | //$object->email_from = ''; // We do not reset from email because it is a mandatory value |
||
| 390 | $object->email_replyto = ''; |
||
| 391 | $object->email_errorsto = ''; |
||
| 392 | |||
| 393 | $object->user_creat = $user->id; |
||
|
1 ignored issue
–
show
|
|||
| 394 | $object->user_valid = ''; |
||
|
1 ignored issue
–
show
|
|||
| 395 | |||
| 396 | $object->date_creat = ''; |
||
|
1 ignored issue
–
show
|
|||
| 397 | $object->date_valid = ''; |
||
|
1 ignored issue
–
show
|
|||
| 398 | $object->date_envoi = ''; |
||
| 399 | } |
||
| 400 | |||
| 401 | // Create clone |
||
| 402 | $object->context['createfromclone'] = 'createfromclone'; |
||
| 403 | $result = $object->create($user); |
||
| 404 | |||
| 405 | // Other options |
||
| 406 | if ($result < 0) { |
||
| 407 | $this->error = $object->error; |
||
| 408 | $this->errors = array_merge($this->errors, $object->errors); |
||
| 409 | $error++; |
||
| 410 | } |
||
| 411 | |||
| 412 | if (!$error) { |
||
| 413 | // Clone recipient targets |
||
| 414 | if (!empty($option2)) { |
||
| 415 | require_once DOL_DOCUMENT_ROOT.'/core/modules/mailings/modules_mailings.php'; |
||
| 416 | |||
| 417 | $mailing_target = new MailingTargets($this->db); |
||
| 418 | |||
| 419 | $target_array = array(); |
||
| 420 | |||
| 421 | $sql = "SELECT fk_contact,"; |
||
| 422 | $sql .= " lastname,"; |
||
| 423 | $sql .= " firstname,"; |
||
| 424 | $sql .= " email,"; |
||
| 425 | $sql .= " other,"; |
||
| 426 | $sql .= " source_url,"; |
||
| 427 | $sql .= " source_id ,"; |
||
| 428 | $sql .= " source_type"; |
||
| 429 | $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles"; |
||
| 430 | $sql .= " WHERE fk_mailing = ".$fromid; |
||
| 431 | |||
| 432 | $result = $this->db->query($sql); |
||
| 433 | if ($result) { |
||
| 434 | if ($this->db->num_rows($result)) { |
||
| 435 | while ($obj = $this->db->fetch_object($result)) { |
||
| 436 | $target_array[] = array( |
||
| 437 | 'fk_contact'=>$obj->fk_contact, |
||
| 438 | 'lastname'=>$obj->lastname, |
||
| 439 | 'firstname'=>$obj->firstname, |
||
| 440 | 'email'=>$obj->email, |
||
| 441 | 'other'=>$obj->other, |
||
| 442 | 'source_url'=>$obj->source_url, |
||
| 443 | 'source_id'=>$obj->source_id, |
||
| 444 | 'source_type'=>$obj->source_type |
||
| 445 | ); |
||
| 446 | } |
||
| 447 | } |
||
| 448 | } else { |
||
| 449 | $this->error = $this->db->lasterror(); |
||
| 450 | return -1; |
||
| 451 | } |
||
| 452 | |||
| 453 | $mailing_target->addTargetsToDatabase($object->id, $target_array); |
||
| 454 | } |
||
| 455 | } |
||
| 456 | |||
| 457 | unset($object->context['createfromclone']); |
||
| 458 | |||
| 459 | // End |
||
| 460 | if (!$error) { |
||
| 461 | $this->db->commit(); |
||
| 462 | return $object->id; |
||
| 463 | } else { |
||
| 464 | $this->db->rollback(); |
||
| 465 | return -1; |
||
| 466 | } |
||
| 467 | } |
||
| 468 | |||
| 469 | /** |
||
| 470 | * Validate emailing |
||
| 471 | * |
||
| 472 | * @param User $user Objet user qui valide |
||
| 473 | * @return int <0 if KO, >0 if OK |
||
| 474 | */ |
||
| 475 | public function valid($user) |
||
| 476 | { |
||
| 477 | $now = dol_now(); |
||
| 478 | |||
| 479 | $sql = "UPDATE ".MAIN_DB_PREFIX."mailing "; |
||
| 480 | $sql .= " SET statut = 1, date_valid = '".$this->db->idate($now)."', fk_user_valid=".$user->id; |
||
| 481 | $sql .= " WHERE rowid = ".$this->id; |
||
| 482 | |||
| 483 | dol_syslog("Mailing::valid", LOG_DEBUG); |
||
| 484 | if ($this->db->query($sql)) { |
||
| 485 | return 1; |
||
| 486 | } else { |
||
| 487 | $this->error = $this->db->lasterror(); |
||
| 488 | return -1; |
||
| 489 | } |
||
| 490 | } |
||
| 491 | |||
| 492 | |||
| 493 | /** |
||
| 494 | * Delete emailing |
||
| 495 | * |
||
| 496 | * @param int $rowid id du mailing a supprimer |
||
| 497 | * @return int 1 en cas de succes |
||
| 498 | */ |
||
| 499 | public function delete($rowid) |
||
| 500 | { |
||
| 501 | $sql = "DELETE FROM ".MAIN_DB_PREFIX."mailing"; |
||
| 502 | $sql .= " WHERE rowid = ".$rowid; |
||
| 503 | |||
| 504 | dol_syslog("Mailing::delete", LOG_DEBUG); |
||
| 505 | $resql = $this->db->query($sql); |
||
| 506 | if ($resql) { |
||
| 507 | return $this->delete_targets(); |
||
| 508 | } else { |
||
| 509 | $this->error = $this->db->lasterror(); |
||
| 510 | return -1; |
||
| 511 | } |
||
| 512 | } |
||
| 513 | |||
| 514 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 515 | /** |
||
| 516 | * Delete targets emailing |
||
| 517 | * |
||
| 518 | * @return int 1 if OK, 0 if error |
||
| 519 | */ |
||
| 520 | public function delete_targets() |
||
| 535 | } |
||
| 536 | } |
||
| 537 | |||
| 538 | |||
| 539 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 540 | /** |
||
| 541 | * Change status of each recipient |
||
| 542 | * |
||
| 543 | * @param User $user Objet user qui valide |
||
| 544 | * @return int <0 if KO, >0 if OK |
||
| 545 | */ |
||
| 546 | public function reset_targets_status($user) |
||
| 547 | { |
||
| 548 | // phpcs:enable |
||
| 549 | $sql = "UPDATE ".MAIN_DB_PREFIX."mailing_cibles"; |
||
| 550 | $sql .= " SET statut = 0"; |
||
| 551 | $sql .= " WHERE fk_mailing = ".$this->id; |
||
| 552 | |||
| 553 | dol_syslog("Mailing::reset_targets_status", LOG_DEBUG); |
||
| 554 | $resql = $this->db->query($sql); |
||
| 555 | if ($resql) { |
||
| 556 | return 1; |
||
| 557 | } else { |
||
| 558 | $this->error = $this->db->lasterror(); |
||
| 559 | return -1; |
||
| 560 | } |
||
| 561 | } |
||
| 562 | |||
| 563 | |||
| 564 | /** |
||
| 565 | * Count number of target with status |
||
| 566 | * |
||
| 567 | * @param string $mode Mode ('alreadysent' = Sent success or error, 'alreadysentok' = Sent success, 'alreadysentko' = Sent error) |
||
| 568 | * @return int Nb of target with status |
||
| 569 | */ |
||
| 570 | public function countNbOfTargets($mode) |
||
| 571 | { |
||
| 572 | $sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."mailing_cibles"; |
||
| 573 | $sql .= " WHERE fk_mailing = ".$this->id; |
||
| 574 | if ($mode == 'alreadysent') { |
||
| 575 | $sql .= " AND statut <> 0"; |
||
| 576 | } elseif ($mode == 'alreadysentok') { |
||
| 577 | $sql .= " AND statut > 0"; |
||
| 578 | } elseif ($mode == 'alreadysentko') { |
||
| 579 | $sql .= " AND statut = -1"; |
||
| 580 | } else { |
||
| 581 | $this->error = 'BadValueForParameterMode'; |
||
| 582 | return -2; |
||
| 583 | } |
||
| 584 | |||
| 585 | $resql = $this->db->query($sql); |
||
| 586 | if ($resql) { |
||
| 587 | $obj = $this->db->fetch_object($resql); |
||
| 588 | if ($obj) { |
||
| 589 | return $obj->nb; |
||
| 590 | } |
||
| 591 | } else { |
||
| 592 | $this->error = $this->db->lasterror(); |
||
| 593 | return -1; |
||
| 594 | } |
||
| 595 | return 0; |
||
| 596 | } |
||
| 597 | |||
| 598 | /** |
||
| 599 | * Refresh denormalized value ->nbemail into emailing record |
||
| 600 | * Note: There is also the method update_nb into modules_mailings that is used for this. |
||
| 601 | * |
||
| 602 | * @return int <0 if KO, >0 if OK |
||
| 603 | */ |
||
| 604 | public function refreshNbOfTargets() |
||
| 629 | } |
||
| 630 | |||
| 631 | /** |
||
| 632 | * Return a link to the object card (with optionally the picto) |
||
| 633 | * |
||
| 634 | * @param int $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto) |
||
| 635 | * @param string $option On what the link point to ('nolink', ...) |
||
| 636 | * @param int $notooltip 1=Disable tooltip |
||
| 637 | * @param string $morecss Add more css on link |
||
| 638 | * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking |
||
| 639 | * @return string String with URL |
||
| 640 | */ |
||
| 641 | public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1) |
||
| 642 | { |
||
| 643 | global $db, $conf, $langs, $hookmanager; |
||
| 644 | global $dolibarr_main_authentication, $dolibarr_main_demo; |
||
| 645 | global $menumanager; |
||
| 646 | |||
| 647 | if (!empty($conf->dol_no_mouse_hover)) { |
||
| 648 | $notooltip = 1; // Force disable tooltips |
||
| 649 | } |
||
| 650 | |||
| 651 | $result = ''; |
||
| 652 | $companylink = ''; |
||
| 653 | |||
| 654 | $label = '<u>'.$langs->trans("ShowEMailing").'</u>'; |
||
| 655 | $label .= '<br>'; |
||
| 656 | $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref; |
||
| 657 | |||
| 658 | $url = DOL_URL_ROOT.'/comm/mailing/card.php?id='.$this->id; |
||
| 659 | |||
| 660 | if ($option != 'nolink') { |
||
| 661 | // Add param to save lastsearch_values or not |
||
| 662 | $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0); |
||
| 663 | if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) { |
||
| 664 | $add_save_lastsearch_values = 1; |
||
| 665 | } |
||
| 666 | if ($add_save_lastsearch_values) { |
||
| 667 | $url .= '&save_lastsearch_values=1'; |
||
| 668 | } |
||
| 669 | } |
||
| 670 | |||
| 671 | $linkclose = ''; |
||
| 672 | if (empty($notooltip)) { |
||
| 673 | if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { |
||
| 674 | $label = $langs->trans("ShowEMailing"); |
||
| 675 | $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; |
||
| 676 | } |
||
| 677 | $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"'; |
||
| 678 | $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"'; |
||
| 679 | |||
| 680 | /* |
||
| 681 | $hookmanager->initHooks(array('myobjectdao')); |
||
| 682 | $parameters=array('id'=>$this->id); |
||
| 683 | $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
||
| 684 | if ($reshook > 0) $linkclose = $hookmanager->resPrint; |
||
| 685 | */ |
||
| 686 | } else { |
||
| 687 | $linkclose = ($morecss ? ' class="'.$morecss.'"' : ''); |
||
| 688 | } |
||
| 689 | |||
| 690 | $linkstart = '<a href="'.$url.'"'; |
||
| 691 | $linkstart .= $linkclose.'>'; |
||
| 692 | $linkend = '</a>'; |
||
| 693 | |||
| 694 | $result .= $linkstart; |
||
| 695 | if ($withpicto) { |
||
| 696 | $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); |
||
| 697 | } |
||
| 698 | if ($withpicto != 2) { |
||
| 699 | $result .= $this->ref; |
||
| 700 | } |
||
| 701 | $result .= $linkend; |
||
| 702 | //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : ''); |
||
| 703 | |||
| 704 | global $action; |
||
| 705 | $hookmanager->initHooks(array('emailingdao')); |
||
| 706 | $parameters = array('id'=>$this->id, 'getnomurl'=>$result); |
||
| 707 | $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
||
| 708 | if ($reshook > 0) { |
||
| 709 | $result = $hookmanager->resPrint; |
||
| 710 | } else { |
||
| 711 | $result .= $hookmanager->resPrint; |
||
| 712 | } |
||
| 713 | |||
| 714 | return $result; |
||
| 715 | } |
||
| 716 | |||
| 717 | /** |
||
| 718 | * Return label of status of emailing (draft, validated, ...) |
||
| 719 | * |
||
| 720 | * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long |
||
| 721 | * @return string Label |
||
| 722 | */ |
||
| 723 | public function getLibStatut($mode = 0) |
||
| 724 | { |
||
| 725 | return $this->LibStatut($this->statut, $mode); |
||
| 726 | } |
||
| 727 | |||
| 728 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 729 | /** |
||
| 730 | * Renvoi le libelle d'un statut donne |
||
| 731 | * |
||
| 732 | * @param int $status Id status |
||
| 733 | * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto |
||
| 734 | * @return string Label |
||
| 735 | */ |
||
| 736 | public function LibStatut($status, $mode = 0) |
||
| 754 | } |
||
| 755 | |||
| 756 | |||
| 757 | /** |
||
| 758 | * Renvoi le libelle d'un statut donne |
||
| 759 | * TODO Add class mailin_target.class.php |
||
| 760 | * |
||
| 761 | * @param int $status Id status |
||
| 762 | * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto |
||
| 763 | * @param string $desc Desc error |
||
| 764 | * @return string Label |
||
| 765 | */ |
||
| 766 | public static function libStatutDest($status, $mode = 0, $desc = '') |
||
| 801 | } |
||
| 802 | } |
||
| 803 |