dolibarr 21.0.3
partnership.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2021 NextGestion <contact@nextgestion.com>
4 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
28// Put here all includes required by your class file
29require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
30
31
36{
40 public $module = 'partnership';
41
45 public $element = 'partnership';
46
50 public $table_element = 'partnership';
51
55 public $picto = 'partnership';
56
60 public $type_code;
64 public $type_label;
65
66
67 const STATUS_DRAFT = 0;
68 const STATUS_VALIDATED = 1; // Validate (no more draft)
69 const STATUS_APPROVED = 2; // Approved
70 const STATUS_REFUSED = 3; // Refused
71 const STATUS_CANCELED = 9;
72
73
100 // BEGIN MODULEBUILDER PROPERTIES
104 public $fields = array(
105 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'position' => 1, 'notnull' => 1, 'visible' => 0, 'noteditable' => 1, 'index' => 1, 'css' => 'left', 'comment' => "Id"),
106 'ref' => array('type' => 'varchar(128)', 'label' => 'Ref', 'enabled' => 1, 'position' => 10, 'notnull' => 1, 'visible' => 4, 'noteditable' => 1, 'default' => '(PROV)', 'index' => 1, 'searchall' => 1, 'showoncombobox' => 1, 'comment' => "Reference of object", 'csslist' => 'tdoverflowmax150'),
107 'entity' => array('type' => 'integer', 'label' => 'Entity', 'enabled' => 'isModEnabled("multicompany")', 'position' => 15, 'notnull' => 1, 'visible' => -2, 'default' => '1', 'index' => 1,),
108 'fk_type' => array('type' => 'integer:PartnershipType:partnership/class/partnership_type.class.php:0:(active:=:1)', 'label' => 'Type', 'enabled' => 1, 'position' => 20, 'notnull' => 1, 'visible' => 1, 'csslist' => 'tdoverflowmax125'),
109 'fk_soc' => array('type' => 'integer:Societe:societe/class/societe.class.php:1:((status:=:1) AND (entity:IN:__SHARED_ENTITIES__))', 'label' => 'ThirdParty', 'picto' => 'company', 'enabled' => 1, 'position' => 50, 'notnull' => -1, 'visible' => 1, 'index' => 1, 'css' => 'maxwidth500', 'csslist' => 'tdoverflowmax125',),
110 'note_public' => array('type' => 'html', 'label' => 'NotePublic', 'enabled' => 1, 'position' => 61, 'notnull' => 0, 'visible' => 0,),
111 'note_private' => array('type' => 'html', 'label' => 'NotePrivate', 'enabled' => 1, 'position' => 62, 'notnull' => 0, 'visible' => 0,),
112 'date_creation' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'position' => 500, 'notnull' => 1, 'visible' => -2, 'csslist' => 'nowraponall'),
113 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'position' => 501, 'notnull' => 0, 'visible' => -2, 'csslist' => 'nowraponall'),
114 'fk_user_creat' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserAuthor', 'enabled' => 1, 'position' => 510, 'notnull' => 1, 'visible' => -2, 'foreignkey' => 'user.rowid', 'csslist' => 'tdoverflowmax125'),
115 'fk_user_modif' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModif', 'enabled' => 1, 'position' => 511, 'notnull' => -1, 'visible' => -2, 'csslist' => 'tdoverflowmax125'),
116 'last_main_doc' => array('type' => 'varchar(255)', 'label' => 'LastMainDoc', 'enabled' => 1, 'position' => 600, 'notnull' => 0, 'visible' => 0,),
117 'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'position' => 1000, 'notnull' => -1, 'visible' => -2,),
118 'model_pdf' => array('type' => 'varchar(255)', 'label' => 'Model pdf', 'enabled' => 1, 'position' => 1010, 'notnull' => -1, 'visible' => 0,),
119 'date_partnership_start' => array('type' => 'date', 'label' => 'DatePartnershipStart', 'enabled' => 1, 'position' => 52, 'notnull' => 1, 'visible' => 1,),
120 'date_partnership_end' => array('type' => 'date', 'label' => 'DatePartnershipEnd', 'enabled' => 1, 'position' => 53, 'notnull' => 0, 'visible' => 1,),
121 'url_to_check' => array('type' => 'url', 'label' => 'UrlToCheck', 'enabled' => 'getDolGlobalString("PARTNERSHIP_BACKLINKS_TO_CHECK")', 'position' => 70, 'notnull' => 0, 'visible' => -1, 'csslist' => 'tdoverflowmax150'),
122 'count_last_url_check_error' => array('type' => 'integer', 'label' => 'CountLastUrlCheckError', 'enabled' => 'getDolGlobalString("PARTNERSHIP_BACKLINKS_TO_CHECK")', 'position' => 71, 'notnull' => 0, 'visible' => -4, 'default' => '0',),
123 'last_check_backlink' => array('type' => 'datetime', 'label' => 'LastCheckBacklink', 'enabled' => 'getDolGlobalString("PARTNERSHIP_BACKLINKS_TO_CHECK")', 'position' => 72, 'notnull' => 0, 'visible' => -4, 'csslist' => 'nowraponall'),
124 'reason_decline_or_cancel' => array('type' => 'text', 'label' => 'ReasonDeclineOrCancel', 'enabled' => 1, 'position' => 73, 'notnull' => 0, 'visible' => -2,),
125 'ip' => array('type' => 'ip', 'label' => 'IPOfApplicant', 'enabled' => 1, 'position' => 74, 'notnull' => 0, 'visible' => -2,),
126 'status' => array('type' => 'smallint', 'label' => 'Status', 'enabled' => 1, 'position' => 2000, 'notnull' => 1, 'visible' => 2, 'default' => '0', 'index' => 1, 'arrayofkeyval' => array(0 => 'Draft', 1 => 'Validated', 2 => 'Approved', 3 => 'Refused', 9 => 'Terminated'),),
127 );
131 public $rowid;
135 public $ref;
139 public $entity;
143 public $fk_type;
147 public $note_public;
151 public $note_private;
155 public $fk_user_creat;
159 public $fk_user_modif;
163 public $last_main_doc;
167 public $import_key;
171 public $model_pdf;
175 public $date_partnership_start;
179 public $date_partnership_end;
183 public $url_to_check;
187 public $count_last_url_check_error;
191 public $last_check_backlink;
195 public $reason_decline_or_cancel;
199 public $fk_soc;
203 public $fk_member;
207 public $ip;
211 public $status;
212 // END MODULEBUILDER PROPERTIES
213
214
220 public function __construct(DoliDB $db)
221 {
222 global $langs;
223
224 $this->db = $db;
225
226 $this->ismultientitymanaged = 0;
227 $this->isextrafieldmanaged = 1;
228
229 if (getDolGlobalString('PARTNERSHIP_IS_MANAGED_FOR') == 'member') {
230 $this->fields['fk_member'] = array('type' => 'integer:Adherent:adherents/class/adherent.class.php:1', 'label' => 'Member', 'enabled' => '1', 'position' => 50, 'notnull' => -1, 'visible' => 1, 'index' => 1, 'picto' => 'member', 'css' => 'maxwidth500', 'csslist' => 'tdoverflowmax150');
231 unset($this->fields['fk_soc']);
232 } else {
233 $this->fields['fk_soc'] = array('type' => 'integer:Societe:societe/class/societe.class.php:1:((status:=:1) AND (entity:IN:__SHARED_ENTITIES__))', 'label' => 'ThirdParty', 'enabled' => '1', 'position' => 50, 'notnull' => -1, 'visible' => 1, 'index' => 1, 'picto' => 'company', 'css' => 'maxwidth500', 'csslist' => 'tdoverflowmax150');
234 unset($this->fields['fk_member']);
235 }
236
237 // @phan-suppress-next-line PhanTypeMismatchProperty
238 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid']) && !empty($this->fields['ref'])) {
239 $this->fields['rowid']['visible'] = 0;
240 }
241
242 // Unset fields that are disabled
243 foreach ($this->fields as $key => $val) {
244 if (isset($val['enabled']) && empty($val['enabled'])) {
245 unset($this->fields[$key]);
246 }
247 }
248
249 // Translate some data of arrayofkeyval
250 if (is_object($langs)) {
251 foreach ($this->fields as $key => $val) {
252 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
253 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
254 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
255 }
256 }
257 }
258 }
259 }
260
268 public function create(User $user, $notrigger = 0)
269 {
270 if ($this->fk_soc <= 0 && $this->fk_member <= 0) {
271 $this->errors[] = "ErrorThirpdartyOrMemberidIsMandatory";
272 return -1;
273 }
274
275 $this->status = 0;
276 return $this->createCommon($user, $notrigger);
277 }
278
286 public function createFromClone(User $user, $fromid)
287 {
288 global $langs, $extrafields;
289 $error = 0;
290
291 dol_syslog(__METHOD__, LOG_DEBUG);
292
293 $object = new self($this->db);
294
295 $this->db->begin();
296
297 // Load source object
298 $result = $object->fetchCommon($fromid);
299 if ($result > 0 && !empty($object->table_element_line)) {
300 $object->fetchLines();
301 }
302
303 // get lines so they will be clone
304 //foreach($this->lines as $line)
305 // $line->fetch_optionals();
306
307 // Reset some properties
308 unset($object->id);
309 unset($object->fk_user_creat);
310 unset($object->import_key);
311
312 // Clear fields
313 if (property_exists($object, 'ref')) {
314 // @phan-suppress-next-line PhanTypeMismatchProperty
315 $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
316 }
317 if (property_exists($object, 'label')) {
318 $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
319 }
320 if (property_exists($object, 'status')) {
321 $object->status = self::STATUS_DRAFT;
322 }
323 if (property_exists($object, 'date_creation')) {
324 $object->date_creation = dol_now();
325 }
326 if (property_exists($object, 'date_modification')) {
327 $object->date_modification = null;
328 }
329 // ...
330 // Clear extrafields that are unique
331 if (is_array($object->array_options) && count($object->array_options) > 0) {
332 $extrafields->fetch_name_optionals_label($this->table_element);
333 foreach ($object->array_options as $key => $option) {
334 $shortkey = preg_replace('/options_/', '', $key);
335 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
336 //var_dump($key);
337 //var_dump($clonedObj->array_options[$key]); exit;
338 unset($object->array_options[$key]);
339 }
340 }
341 }
342
343 // Create clone
344 $object->context['createfromclone'] = 'createfromclone';
345 $result = $object->createCommon($user);
346 if ($result < 0) {
347 $error++;
348 $this->error = $object->error;
349 $this->errors = $object->errors;
350 }
351
352 if (!$error) {
353 // copy internal contacts
354 if ($this->copy_linked_contact($object, 'internal') < 0) {
355 $error++;
356 }
357 }
358
359 if (!$error) {
360 // copy external contacts if same company
361 if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
362 if ($this->copy_linked_contact($object, 'external') < 0) {
363 $error++;
364 }
365 }
366 }
367
368 unset($object->context['createfromclone']);
369
370 // End
371 if (!$error) {
372 $this->db->commit();
373 return $object;
374 } else {
375 $this->db->rollback();
376 return -1;
377 }
378 }
379
390 public function fetch($id, $ref = null, $fk_member = null, $fk_soc = null)
391 {
392 // Check parameters
393 if (empty($id) && empty($ref) && empty($fk_member) && empty($fk_soc)) {
394 return -1;
395 }
396
397 $sql = 'SELECT p.rowid, p.ref, p.fk_type, p.fk_soc, p.fk_member, p.status';
398 $sql .= ', p.entity, p.date_partnership_start, p.date_partnership_end, p.date_creation';
399 $sql .= ', p.fk_user_creat, p.tms, p.fk_user_modif, p.fk_user_modif';
400 $sql .= ', p.note_private, p.note_public, p.url_to_check';
401 $sql .= ', p.last_main_doc, p.count_last_url_check_error, p.last_check_backlink, p.reason_decline_or_cancel';
402 $sql .= ', p.import_key, p.model_pdf';
403 $sql .= ', pt.code as type_code, pt.label as type_label';
404 $sql .= ' FROM '.MAIN_DB_PREFIX.'partnership as p';
405 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_partnership_type as pt ON p.fk_type = pt.rowid';
406
407 if ($id) {
408 $sql .= " WHERE p.rowid = ".((int) $id);
409 } else {
410 $sql .= " WHERE p.entity IN (0,".getEntity('partnership').")"; // Don't use entity if you use rowid
411 }
412
413 if ($ref) {
414 $sql .= " AND p.ref='".$this->db->escape($ref)."'";
415 }
416
417 if ($fk_member > 0) {
418 $sql .= ' AND p.fk_member = '.((int) $fk_member);
419 }
420 if ($fk_soc > 0) {
421 $sql .= ' AND p.fk_soc = '.((int) $fk_soc);
422 }
423 $sql .= ' ORDER BY p.date_partnership_end DESC';
424
425 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
426 $result = $this->db->query($sql);
427 if ($result) {
428 $obj = $this->db->fetch_object($result);
429 if ($obj) {
430 $this->id = $obj->rowid;
431 $this->entity = $obj->entity;
432 $this->ref = $obj->ref;
433
434 $this->fk_type = $obj->fk_type;
435 $this->type_code = $obj->type_code;
436 $this->type_label = $obj->type_label;
437
438 $this->fk_soc = $obj->fk_soc;
439 $this->fk_member = $obj->fk_member;
440 $this->status = $obj->status;
441 $this->date_partnership_start = $this->db->jdate($obj->date_partnership_start);
442 $this->date_partnership_end = $this->db->jdate($obj->date_partnership_end);
443 $this->date_creation = $this->db->jdate($obj->date_creation);
444 $this->fk_user_creat = $obj->fk_user_creat;
445 $this->tms = $obj->tms;
446 $this->fk_user_modif = $obj->fk_user_modif;
447 $this->note_private = $obj->note_private;
448 $this->note_public = $obj->note_public;
449 $this->last_main_doc = $obj->last_main_doc;
450 $this->count_last_url_check_error = $obj->count_last_url_check_error;
451 $this->last_check_backlink = $this->db->jdate($obj->last_check_backlink);
452 $this->reason_decline_or_cancel = $obj->reason_decline_or_cancel;
453 $this->import_key = $obj->import_key;
454 $this->model_pdf = $obj->model_pdf;
455 $this->url_to_check = $obj->url_to_check;
456
457 // Retrieve all extrafield
458 // fetch optionals attributes and labels
459 $this->fetch_optionals();
460
461 $this->db->free($result);
462
463 return 1;
464 } else {
465 // $this->error = 'Partnership with id '.$id.' not found sql='.$sql;
466 return 0;
467 }
468 } else {
469 $this->error = $this->db->error();
470 return -1;
471 }
472 }
473
474
480 public function fetchLines()
481 {
482 $this->lines = array();
483
484 $result = $this->fetchLinesCommon();
485 return $result;
486 }
487
488
500 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
501 {
502 dol_syslog(__METHOD__, LOG_DEBUG);
503
504 $records = array();
505
506 $sql = 'SELECT ';
507 $sql .= $this->getFieldList('t');
508 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
509 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
510 $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
511 } else {
512 $sql .= ' WHERE 1 = 1';
513 }
514
515 // Manage filter
516 if (is_array($filter)) {
517 $sqlwhere = array();
518 if (count($filter) > 0) {
519 foreach ($filter as $key => $value) {
520 if ($key == 't.rowid') {
521 $sqlwhere[] = $this->db->sanitize($key)." = ".((int) $value);
522 } elseif (array_key_exists($key, $this->fields) && in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
523 $sqlwhere[] = $this->db->sanitize($key)." = '".$this->db->idate($value)."'";
524 } elseif (strpos($value, '%') === false) {
525 $sqlwhere[] = $this->db->sanitize($key)." IN (".$this->db->sanitize($this->db->escape($value)).")";
526 } else {
527 $sqlwhere[] = $this->db->sanitize($key)." LIKE '%".$this->db->escape($this->db->escapeforlike($value))."%'";
528 }
529 }
530 }
531 if (count($sqlwhere) > 0) {
532 $sql .= ' AND ('.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
533 }
534
535 $filter = '';
536 }
537
538 // Manage filter
539 $errormessage = '';
540 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
541 if ($errormessage) {
542 $this->errors[] = $errormessage;
543 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
544 return -1;
545 }
546
547 if (!empty($sortfield)) {
548 $sql .= $this->db->order($sortfield, $sortorder);
549 }
550 if (!empty($limit)) {
551 $sql .= $this->db->plimit($limit, $offset);
552 }
553
554 $resql = $this->db->query($sql);
555 if ($resql) {
556 $num = $this->db->num_rows($resql);
557 $i = 0;
558 while ($i < ($limit ? min($limit, $num) : $num)) {
559 $obj = $this->db->fetch_object($resql);
560
561 $record = new self($this->db);
562 $record->setVarsFromFetchObj($obj);
563
564 $records[$record->id] = $record;
565
566 $i++;
567 }
568 $this->db->free($resql);
569
570 return $records;
571 } else {
572 $this->errors[] = 'Error '.$this->db->lasterror();
573 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
574
575 return -1;
576 }
577 }
578
586 public function update(User $user, $notrigger = 0)
587 {
588 if ($this->fk_soc <= 0 && $this->fk_member <= 0) {
589 $this->errors[] = "ErrorThirpdartyOrMemberidIsMandatory"; // Mistyping in key is in translations
590 return -1;
591 }
592 if (empty($this->fk_user_creat)) { // For the case the object was created with empty user (from public page).
593 $this->fk_user_creat = $user->id;
594 }
595
596 return $this->updateCommon($user, $notrigger);
597 }
598
606 public function delete(User $user, $notrigger = 0)
607 {
608 return $this->deleteCommon($user, $notrigger);
609 //return $this->deleteCommon($user, $notrigger, 1);
610 }
611
620 public function deleteLine(User $user, $idline, $notrigger = 0)
621 {
622 if ($this->status < 0) {
623 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
624 return -2;
625 }
626
627 return $this->deleteLineCommon($user, $idline, $notrigger);
628 }
629
630
638 public function validate($user, $notrigger = 0)
639 {
640 global $conf;
641
642 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
643
644 $error = 0;
645
646 // Protection
647 if ($this->status == self::STATUS_VALIDATED) {
648 dol_syslog(get_class($this)."::validate action abandoned: already validated", LOG_WARNING);
649 return 0;
650 }
651
652 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->partnership->write))
653 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->partnership->partnership_advance->validate))))
654 {
655 $this->error='NotEnoughPermissions';
656 dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
657 return -1;
658 }*/
659
660 $now = dol_now();
661
662 $this->db->begin();
663
664 // Define new ref
665 if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
666 $num = $this->getNextNumRef();
667 } else {
668 $num = $this->ref;
669 }
670 $this->newref = $num;
671
672 if (!empty($num)) {
673 // Validate
674 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
675 $sql .= " SET ref = '".$this->db->escape($num)."',";
676 $sql .= " status = ".self::STATUS_VALIDATED;
677 if (!empty($this->fields['date_validation'])) {
678 $sql .= ", date_validation = '".$this->db->idate($now)."'";
679 }
680 if (!empty($this->fields['fk_user_valid'])) { // @phan-suppress-current-line PhanTypeMismatchProperty
681 $sql .= ", fk_user_valid = ".((int) $user->id);
682 }
683 $sql .= " WHERE rowid = ".((int) $this->id);
684
685 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
686 $resql = $this->db->query($sql);
687 if (!$resql) {
688 dol_print_error($this->db);
689 $this->error = $this->db->lasterror();
690 $error++;
691 }
692
693 if (!$error && !$notrigger) {
694 // Call trigger
695 $result = $this->call_trigger('PARTNERSHIP_VALIDATE', $user);
696 if ($result < 0) {
697 $error++;
698 }
699 // End call triggers
700 }
701 }
702
703 if (!$error) {
704 $this->oldref = $this->ref;
705
706 // Rename directory if dir was a temporary ref
707 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
708 // Now we rename also files into index
709 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'partnership/".$this->db->escape($this->newref)."'";
710 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'partnership/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
711 $resql = $this->db->query($sql);
712 if (!$resql) {
713 $error++;
714 $this->error = $this->db->lasterror();
715 }
716 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'partnership/".$this->db->escape($this->newref)."'";
717 $sql .= " WHERE filepath = 'partnership/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
718 $resql = $this->db->query($sql);
719 if (!$resql) {
720 $error++;
721 $this->error = $this->db->lasterror();
722 }
723
724 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
725 $oldref = dol_sanitizeFileName($this->ref);
726 $newref = dol_sanitizeFileName($num);
727 $dirsource = $conf->partnership->dir_output.'/partnership/'.$oldref;
728 $dirdest = $conf->partnership->dir_output.'/partnership/'.$newref;
729 if (!$error && file_exists($dirsource)) {
730 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
731
732 if (@rename($dirsource, $dirdest)) {
733 dol_syslog("Rename ok");
734 // Rename docs starting with $oldref with $newref
735 $listoffiles = dol_dir_list($conf->partnership->dir_output.'/partnership/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
736 foreach ($listoffiles as $fileentry) {
737 $dirsource = $fileentry['name'];
738 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
739 $dirsource = $fileentry['path'].'/'.$dirsource;
740 $dirdest = $fileentry['path'].'/'.$dirdest;
741 @rename($dirsource, $dirdest);
742 }
743 }
744 }
745 }
746 }
747
748 // Set new ref and current status
749 if (!$error) {
750 $this->ref = $num;
751 $this->status = self::STATUS_VALIDATED;
752 }
753
754 if (!$error) {
755 $this->db->commit();
756 return 1;
757 } else {
758 $this->db->rollback();
759 return -1;
760 }
761 }
762
770 public function approve($user, $notrigger = 0)
771 {
772 global $conf;
773
774 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
775
776 $error = 0;
777
778 // Protection
779 if ($this->status == self::STATUS_APPROVED) {
780 dol_syslog(get_class($this)."::accept action abandoned: already acceptd", LOG_WARNING);
781 return 0;
782 }
783
784 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->partnership->write))
785 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->partnership->partnership_advance->accept))))
786 {
787 $this->error='NotEnoughPermissions';
788 dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
789 return -1;
790 }*/
791
792 $now = dol_now();
793
794 $this->db->begin();
795
796 // Define new ref
797 if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
798 $num = $this->getNextNumRef();
799 } else {
800 $num = $this->ref;
801 }
802 $this->newref = $num;
803
804 if (!empty($num)) {
805 // Accept
806 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
807 $sql .= " SET ref = '".$this->db->escape($num)."',";
808 $sql .= " status = ".self::STATUS_APPROVED;
809 $sql .= " WHERE rowid = ".((int) $this->id);
810
811 dol_syslog(get_class($this)."::accept()", LOG_DEBUG);
812 $resql = $this->db->query($sql);
813 if (!$resql) {
814 dol_print_error($this->db);
815 $this->error = $this->db->lasterror();
816 $error++;
817 }
818
819 if (!$error && !$notrigger) {
820 // Call trigger
821 $result = $this->call_trigger('PARTNERSHIP_ACCEPT', $user);
822 if ($result < 0) {
823 $error++;
824 }
825 // End call triggers
826 }
827 }
828
829 if (!$error) {
830 $this->oldref = $this->ref;
831
832 // Rename directory if dir was a temporary ref
833 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
834 // Now we rename also files into index
835 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'partnership/".$this->db->escape($this->newref)."'";
836 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'partnership/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
837 $resql = $this->db->query($sql);
838 if (!$resql) {
839 $error++;
840 $this->error = $this->db->lasterror();
841 }
842 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'partnership/".$this->db->escape($this->newref)."'";
843 $sql .= " WHERE filepath = 'partnership/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
844 $resql = $this->db->query($sql);
845 if (!$resql) {
846 $error++;
847 $this->error = $this->db->lasterror();
848 }
849
850 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
851 $oldref = dol_sanitizeFileName($this->ref);
852 $newref = dol_sanitizeFileName($num);
853 $dirsource = $conf->partnership->dir_output.'/partnership/'.$oldref;
854 $dirdest = $conf->partnership->dir_output.'/partnership/'.$newref;
855 if (!$error && file_exists($dirsource)) {
856 dol_syslog(get_class($this)."::accept() rename dir ".$dirsource." into ".$dirdest);
857
858 if (@rename($dirsource, $dirdest)) {
859 dol_syslog("Rename ok");
860 // Rename docs starting with $oldref with $newref
861 $listoffiles = dol_dir_list($conf->partnership->dir_output.'/partnership/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
862 foreach ($listoffiles as $fileentry) {
863 $dirsource = $fileentry['name'];
864 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
865 $dirsource = $fileentry['path'].'/'.$dirsource;
866 $dirdest = $fileentry['path'].'/'.$dirdest;
867 @rename($dirsource, $dirdest);
868 }
869 }
870 }
871 }
872 }
873
874 // Set new ref and current status
875 if (!$error) {
876 $this->ref = $num;
877 $this->status = self::STATUS_APPROVED;
878 }
879
880 if (!$error) {
881 $this->db->commit();
882 return 1;
883 } else {
884 $this->db->rollback();
885 return -1;
886 }
887 }
888
889
897 public function setDraft($user, $notrigger = 0)
898 {
899 // Protection
900 if ($this->status <= self::STATUS_DRAFT) {
901 return 0;
902 }
903
904 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->partnership->write))
905 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->partnership_advance->validate))))
906 {
907 $this->error='Permission denied';
908 return -1;
909 }*/
910
911 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'PARTNERSHIP_UNVALIDATE');
912 }
913
922 public function refused($user, $reasondeclinenote = '', $notrigger = 0)
923 {
924 // Protection
925 if ($this->status == self::STATUS_REFUSED) {
926 return 0;
927 }
928
929 $this->status = self::STATUS_REFUSED;
930 $this->reason_decline_or_cancel = $reasondeclinenote;
931
932 $result = $this->update($user);
933
934 if ($result) {
935 $this->reason_decline_or_cancel = $reasondeclinenote;
936 return 1;
937 }
938
939 return -1;
940 }
941
949 public function cancel($user, $notrigger = 0)
950 {
951 // Protection
952 if ($this->status != self::STATUS_APPROVED) {
953 return 0;
954 }
955
956 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->partnership->write))
957 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->partnership_advance->validate))))
958 {
959 $this->error='Permission denied';
960 return -1;
961 }*/
962
963 return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'PARTNERSHIP_CANCEL');
964 }
965
973 public function reopen($user, $notrigger = 0)
974 {
975 // Protection
976 if ($this->status != self::STATUS_CANCELED && $this->status != self::STATUS_REFUSED) {
977 return 0;
978 }
979
980 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->partnership->write))
981 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->partnership_advance->validate))))
982 {
983 $this->error='Permission denied';
984 return -1;
985 }*/
986
987 return $this->setStatusCommon($user, self::STATUS_APPROVED, $notrigger, 'PARTNERSHIP_REOPEN');
988 }
989
996 public function getTooltipContentArray($params)
997 {
998 global $langs;
999
1000 $langs->load('partnership');
1001
1002 $datas = [];
1003 $datas['picto'] = img_picto('', $this->picto).' <u>'.$langs->trans("Partnership").'</u>';
1004 if (isset($this->status)) {
1005 $datas['picto'] .= ' '.$this->getLibStatut(5);
1006 }
1007 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
1008
1009 return $datas;
1010 }
1011
1022 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
1023 {
1024 global $conf, $langs, $hookmanager;
1025
1026 if (!empty($conf->dol_no_mouse_hover)) {
1027 $notooltip = 1; // Force disable tooltips
1028 }
1029
1030 $result = '';
1031 $params = [
1032 'id' => $this->id,
1033 'objecttype' => $this->element,
1034 'option' => $option,
1035 ];
1036 $classfortooltip = 'classfortooltip';
1037 $dataparams = '';
1038 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
1039 $classfortooltip = 'classforajaxtooltip';
1040 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
1041 $label = '';
1042 } else {
1043 $label = implode($this->getTooltipContentArray($params));
1044 }
1045
1046 $url = DOL_URL_ROOT.'/partnership/partnership_card.php?id='.$this->id;
1047
1048 if ($option != 'nolink') {
1049 // Add param to save lastsearch_values or not
1050 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1051 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
1052 $add_save_lastsearch_values = 1;
1053 }
1054 if ($add_save_lastsearch_values) {
1055 $url .= '&save_lastsearch_values=1';
1056 }
1057 }
1058
1059 $linkclose = '';
1060 if (empty($notooltip)) {
1061 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
1062 $label = $langs->trans("ShowPartnership");
1063 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
1064 }
1065 $linkclose .= ($label ? ' title="'.dolPrintHTMLForAttribute($label).'"' : ' title="tocomplete"');
1066 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
1067 } else {
1068 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
1069 }
1070
1071 if ($option == 'nolink') {
1072 $linkstart = '<span';
1073 } else {
1074 $linkstart = '<a href="'.$url.'"';
1075 }
1076 $linkstart .= $linkclose.'>';
1077 if ($option == 'nolink') {
1078 $linkend = '</span>';
1079 } else {
1080 $linkend = '</a>';
1081 }
1082
1083 $result .= $linkstart;
1084
1085 if (empty($this->showphoto_on_popup)) {
1086 if ($withpicto) {
1087 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : $dataparams.' class="'.(($withpicto != 2) ? 'paddingright ' : '').$classfortooltip.'"'), 0, 0, $notooltip ? 0 : 1);
1088 }
1089 } else {
1090 if ($withpicto) {
1091 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1092
1093 list($class, $module) = explode('@', $this->picto);
1094 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
1095 $filearray = dol_dir_list($upload_dir, "files");
1096 $filename = $filearray[0]['name'];
1097 if (!empty($filename)) {
1098 $pospoint = strpos($filearray[0]['name'], '.');
1099
1100 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
1101 if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
1102 $result .= '<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref"><img class="photo'.$module.'" alt="No photo" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$module.'&entity='.$conf->entity.'&file='.urlencode($pathtophoto).'"></div></div>';
1103 } else {
1104 $result .= '<div class="floatleft inline-block valignmiddle divphotoref"><img class="photouserphoto userphoto" alt="No photo" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$module.'&entity='.$conf->entity.'&file='.urlencode($pathtophoto).'"></div>';
1105 }
1106
1107 $result .= '</div>';
1108 } else {
1109 $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);
1110 }
1111 }
1112 }
1113
1114 if ($withpicto != 2) {
1115 $result .= $this->ref;
1116 }
1117
1118 $result .= $linkend;
1119 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
1120
1121 global $action, $hookmanager;
1122 $hookmanager->initHooks(array('partnershipdao'));
1123 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
1124 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1125 if ($reshook > 0) {
1126 $result = $hookmanager->resPrint;
1127 } else {
1128 $result .= $hookmanager->resPrint;
1129 }
1130
1131 return $result;
1132 }
1133
1142 public static function replaceThirdparty($db, $origin_id, $dest_id)
1143 {
1144 $tables = array('partnership');
1145
1146 return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
1147 }
1148
1155 public function getLibStatut($mode = 0)
1156 {
1157 return $this->LibStatut($this->status, $mode);
1158 }
1159
1160 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1168 public function LibStatut($status, $mode = 0)
1169 {
1170 // phpcs:enable
1171 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
1172 global $langs;
1173 //$langs->load("partnership");
1174 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
1175 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
1176 $this->labelStatus[self::STATUS_APPROVED] = $langs->transnoentitiesnoconv('Approved');
1177 $this->labelStatus[self::STATUS_REFUSED] = $langs->transnoentitiesnoconv('Refused');
1178 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Terminated');
1179 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
1180 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
1181 $this->labelStatusShort[self::STATUS_APPROVED] = $langs->transnoentitiesnoconv('Approved');
1182 $this->labelStatusShort[self::STATUS_REFUSED] = $langs->transnoentitiesnoconv('Refused');
1183 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Terminated');
1184 }
1185
1186 $statusType = 'status'.$status;
1187 if ($status == self::STATUS_APPROVED) {
1188 $statusType = 'status4';
1189 }
1190 if ($status == self::STATUS_REFUSED) {
1191 $statusType = 'status9';
1192 }
1193 if ($status == self::STATUS_CANCELED) {
1194 $statusType = 'status6';
1195 }
1196
1197 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
1198 }
1199
1206 public function info($id)
1207 {
1208 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
1209 $sql .= ' fk_user_creat, fk_user_modif';
1210 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
1211 $sql .= ' WHERE t.rowid = '.((int) $id);
1212 $result = $this->db->query($sql);
1213 if ($result) {
1214 if ($this->db->num_rows($result)) {
1215 $obj = $this->db->fetch_object($result);
1216
1217 $this->id = $obj->rowid;
1218
1219 $this->user_creation_id = $obj->fk_user_creat;
1220 $this->user_modification_id = $obj->fk_user_modif;
1221 $this->date_creation = $this->db->jdate($obj->datec);
1222 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
1223 }
1224
1225 $this->db->free($result);
1226 } else {
1227 dol_print_error($this->db);
1228 }
1229 }
1230
1237 public function initAsSpecimen()
1238 {
1239 return $this->initAsSpecimenCommon();
1240 }
1241
1247 public function getLinesArray()
1248 {
1249 $this->lines = array();
1250
1251 $objectline = new PartnershipLine($this->db);
1252 $result = $objectline->fetchAll('ASC', 'position', 0, 0, '(fk_partnership:=:'.((int) $this->id).')');
1253
1254 if (is_numeric($result)) {
1255 $this->error = $objectline->error;
1256 $this->errors = $objectline->errors;
1257 return $result;
1258 } else {
1259 $this->lines = $result;
1260 // @phpstan-ignore-next-line
1261 return $result; // @phan-suppress-current-line PhanTypeMismatchReturn
1262 }
1263 }
1264
1270 public function getNextNumRef()
1271 {
1272 global $langs, $conf;
1273 $langs->load("partnership");
1274
1275 if (!getDolGlobalString('PARTNERSHIP_ADDON')) {
1276 $conf->global->PARTNERSHIP_ADDON = 'mod_partnership_standard';
1277 }
1278
1279 if (getDolGlobalString('PARTNERSHIP_ADDON')) {
1280 $mybool = false;
1281
1282 $file = getDolGlobalString('PARTNERSHIP_ADDON') . ".php";
1283 $classname = getDolGlobalString('PARTNERSHIP_ADDON');
1284
1285 // Include file with class
1286 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
1287 foreach ($dirmodels as $reldir) {
1288 $dir = dol_buildpath($reldir."core/modules/partnership/");
1289
1290 // Load file with numbering class (if found)
1291 $mybool = ((bool) @include_once $dir.$file) || $mybool;
1292 }
1293
1294 if (!$mybool) {
1295 dol_print_error(null, "Failed to include file ".$file);
1296 return '';
1297 }
1298
1299 if (class_exists($classname)) {
1300 $obj = new $classname();
1301 '@phan-var-force ModeleNumRefPartnership $obj';
1302 $numref = $obj->getNextValue($this);
1303
1304 if ($numref != '' && $numref != '-1') {
1305 return $numref;
1306 } else {
1307 $this->error = $obj->error;
1308 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
1309 return "";
1310 }
1311 } else {
1312 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
1313 return "";
1314 }
1315 } else {
1316 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
1317 return "";
1318 }
1319 }
1320
1332 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1333 {
1334 global $conf, $langs;
1335
1336 $result = 0;
1337 $includedocgeneration = 0;
1338
1339 $langs->load("partnership");
1340
1341 if (!dol_strlen($modele)) {
1342 $modele = 'standard_partnership';
1343
1344 if (!empty($this->model_pdf)) {
1345 $modele = $this->model_pdf;
1346 } elseif (getDolGlobalString('PARTNERSHIP_ADDON_PDF')) {
1347 $modele = getDolGlobalString('PARTNERSHIP_ADDON_PDF');
1348 }
1349 }
1350
1351 $modelpath = "core/modules/partnership/doc/";
1352
1353 if ($includedocgeneration && !empty($modele)) {
1354 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1355 }
1356
1357 return $result;
1358 }
1359
1367 public function doScheduledJob()
1368 {
1369 //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
1370
1371 $error = 0;
1372 $this->output = '';
1373 $this->error = '';
1374
1375 dol_syslog(__METHOD__, LOG_DEBUG);
1376
1377 //$now = dol_now();
1378
1379 $this->db->begin();
1380
1381 // ...
1382
1383 $this->db->commit();
1384
1385 return $error;
1386 }
1387
1395 public function getKanbanView($option = '', $arraydata = null)
1396 {
1397 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
1398
1399 $return = '<div class="box-flex-item box-flex-grow-zero">';
1400 $return .= '<div class="info-box info-box-sm">';
1401 $return .= '<span class="info-box-icon bg-infobox-action">';
1402 $return .= img_picto('', $this->picto);
1403 $return .= '</span>';
1404 $return .= '<div class="info-box-content">';
1405 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
1406 if ($selected >= 0) {
1407 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
1408 }
1409 if (property_exists($this, 'label')) {
1410 $return .= ' <div class="inline-block opacitymedium valignmiddle tdoverflowmax100">'.$this->label.'</div>';
1411 }
1412 if (property_exists($this, 'thirdparty') && is_object($this->thirdparty)) {
1413 $return .= '<br><div class="info-box-ref tdoverflowmax150">'.$this->thirdparty->getNomUrl(1).'</div>';
1414 }
1415 if (method_exists($this, 'getLibStatut')) {
1416 $return .= '<br><div class="info-box-status">'.$this->getLibStatut(3).'</div>';
1417 }
1418 $return .= '</div>';
1419 $return .= '</div>';
1420 $return .= '</div>';
1421
1422 return $return;
1423 }
1424}
1425
1426
1427require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
1428
1433{
1434 // To complete with content of an object PartnershipLine
1435 // We should have a field rowid, fk_partnership and position
1436
1437
1443 public function __construct(DoliDB $db)
1444 {
1445 $this->db = $db;
1446
1447 $this->isextrafieldmanaged = 0;
1448 }
1449}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
$object ref
Definition info.php:89
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
deleteLineCommon(User $user, $idline, $notrigger=0)
Delete a line of object in database.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
createCommon(User $user, $notrigger=0)
Create object in the database.
getFieldList($alias='', $excludefields=array())
Function to concat keys of fields.
updateCommon(User $user, $notrigger=0)
Update object into database.
setStatusCommon($user, $status, $notrigger=0, $triggercode='')
Set to a status.
initAsSpecimenCommon()
Initialise object with example values Id must be 0 if object instance is a specimen.
copy_linked_contact($objFrom, $source='internal')
Copy contact from one element to current.
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
fetchLinesCommon($morewhere='', $noextrafields=0)
Load object in memory from the database.
deleteCommon(User $user, $notrigger=0, $forcechilddeletion=0)
Delete object in database.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
Class to manage Dolibarr database access.
Class for Partnership.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
__construct(DoliDB $db)
Constructor.
getNextNumRef()
Returns the reference to the following non used object depending on the active numbering module.
validate($user, $notrigger=0)
Validate object.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionally the picto)
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
static replaceThirdparty($db, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
create(User $user, $notrigger=0)
Create object into database.
update(User $user, $notrigger=0)
Update object into database.
createFromClone(User $user, $fromid)
Clone an object into another one.
setDraft($user, $notrigger=0)
Set draft status.
refused($user, $reasondeclinenote='', $notrigger=0)
Set refused status.
fetch($id, $ref=null, $fk_member=null, $fk_soc=null)
Load object in memory from the database Get object from database.
getKanbanView($option='', $arraydata=null)
Return a thumb for kanban views.
getLinesArray()
Create an array of lines.
getTooltipContentArray($params)
getTooltipContentArray
cancel($user, $notrigger=0)
Set cancel status.
reopen($user, $notrigger=0)
Set back to validated status.
fetchLines()
Load object lines in memory from the database.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND')
Load list of objects in memory from the database.
doScheduledJob()
Action executed by scheduler CAN BE A CRON TASK.
getLibStatut($mode=0)
Return the label of the status.
LibStatut($status, $mode=0)
Return the status.
info($id)
Load the info information in the object.
approve($user, $notrigger=0)
Approve object.
deleteLine(User $user, $idline, $notrigger=0)
Delete a line of object in database.
Class PartnershipLine.
__construct(DoliDB $db)
Constructor.
Class to manage Dolibarr users.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition index.php:171
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:63
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79