dolibarr 22.0.5
commonsignedobject.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2024 William Mead <william.mead@manchenumerique.fr>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
34trait CommonSignedObject
35{
40 public $signed_status = 0;
41
47 public static $SIGNED_STATUSES = [
48 'STATUS_NO_SIGNATURE' => 0,
49 'STATUS_SIGNED_SENDER' => 1,
50 'STATUS_SIGNED_RECEIVER' => 2,
51 'STATUS_SIGNED_RECEIVER_ONLINE' => 3,
52 'STATUS_SIGNED_ALL' => 9 // To handle future kind of signature (ex: tripartite contract)
53 ];
54
60 public function getSignedStatusLocalisedArray(): array
61 {
62 global $langs;
63 $langs->load("commercial");
64
65 $l10n_signed_status_labels = [
66 self::$SIGNED_STATUSES['STATUS_NO_SIGNATURE'] => 'NoSignature',
67 self::$SIGNED_STATUSES['STATUS_SIGNED_SENDER'] => 'SignedSender',
68 self::$SIGNED_STATUSES['STATUS_SIGNED_RECEIVER'] => 'SignedReceiver',
69 self::$SIGNED_STATUSES['STATUS_SIGNED_RECEIVER_ONLINE'] => 'SignedReceiverOnline',
70 self::$SIGNED_STATUSES['STATUS_SIGNED_ALL'] => 'SignedAll'
71 ];
72
73 $l10n_signed_status = [];
74 foreach (self::$SIGNED_STATUSES as $signed_status_code) {
75 $l10n_signed_status[$signed_status_code] = $langs->transnoentitiesnoconv($l10n_signed_status_labels[$signed_status_code]);
76 }
77 return $l10n_signed_status;
78 }
79
89 public function setSignedStatus(User $user, int $status = 0, int $notrigger = 0, string $triggercode = ''): int
90 {
91 global $langs;
92
93 $langs->loadLangs(array('commercial'));
94
95 $this->signed_status = $status;
96 $this->context['signature'] = $status;
97
98 switch ($status) {
99 case 0:
100 $this->context['actionmsg2'] = $langs->transnoentitiesnoconv('UnsignedInDolibarr');
101 break;
102 case 1:
103 $this->context['actionmsg2'] = $langs->transnoentitiesnoconv('SignedSender');
104 break;
105 case 2:
106 $this->context['actionmsg2'] = $langs->transnoentitiesnoconv('SignedReceiver');
107 break;
108 case 3:
109 $this->context['actionmsg2'] = $langs->transnoentitiesnoconv('SignedReceiverOnline');
110 break;
111 case 9:
112 $this->context['actionmsg2'] = $langs->transnoentitiesnoconv('SignedAll');
113 break;
114 }
115 return $this->setSignedStatusCommon($user, $status, $notrigger, $triggercode);
116 }
117
127 public function setSignedStatusCommon(User $user, int $status, int $notrigger = 0, string $triggercode = ''): int
128 {
129 global $langs;
130 $langs->loadLangs(array('commercial'));
131
132 $error = 0;
133
134 if ($this instanceof CommonObject) {
135 $this->db->begin();
136 $statusfield = 'signed_status';
137
138 $sql = "UPDATE ".$this->db->prefix().$this->table_element;
139 $sql .= " SET ".$statusfield." = ".((int) $status);
140 $sql .= " WHERE rowid = ".((int) $this->id);
141
142 if ($this->db->query($sql)) {
143 if (!$error) {
144 $this->oldcopy = clone $this;
145 }
146
147 if (!$error && !$notrigger) {
148 // Call trigger
149 $result = $this->call_trigger($triggercode, $user);
150 if ($result < 0) {
151 $error++;
152 }
153 }
154
155 if (!$error) {
156 $this->signed_status = $status;
157 $this->db->commit();
158
159 setEventMessages($langs->transnoentitiesnoconv($status == 0 ? 'DocumentUnsigned' : 'DocumentSigned'), null, 'warnings');
160 return 1;
161 } else {
162 $this->db->rollback();
163 return -1;
164 }
165 } else {
166 $this->error = $this->db->error();
167 $this->db->rollback();
168 return -1;
169 }
170 } else {
171 return $error;
172 }
173 }
174
181 public function getLibSignedStatus(int $mode = 0): string
182 {
183 global $langs;
184 $langs->load("commercial");
185 $list_signed_status = $this->getSignedStatusLocalisedArray();
186 $signed_status_label = $this->signed_status != '' ? $list_signed_status[$this->signed_status] : '';
187 $signed_status_label_short = $this->signed_status != '' ? $list_signed_status[$this->signed_status] : '';
188 $signed_status_code = 'status'.$this->signed_status;
189 return dolGetStatus($signed_status_label, $signed_status_label_short, '', $signed_status_code, $mode);
190 }
191}
Parent class of all other business classes (invoices, contracts, proposals, orders,...
Class to manage Dolibarr users.
setSignedStatusCommon(User $user, int $status, int $notrigger=0, string $triggercode='')
Set signed status & call trigger with context message.
setSignedStatus(User $user, int $status=0, int $notrigger=0, string $triggercode='')
Set signed status & object context.
getSignedStatusLocalisedArray()
Returns an array of signed statuses with associated localized labels.
getLibSignedStatus(int $mode=0)
Returns the label for signed status.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.