dolibarr 21.0.0-alpha
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 $langs->loadLangs(array('commercial'));
93 $this->signed_status = $status;
94 $this->context['signature'] = $status;
95 switch ($status) {
96 case 0:
97 $this->context['actionmsg2'] = $langs->transnoentitiesnoconv('UnsignedInDolibarr');
98 break;
99 case 1:
100 $this->context['actionmsg2'] = $langs->transnoentitiesnoconv('SignedSender');
101 break;
102 case 2:
103 $this->context['actionmsg2'] = $langs->transnoentitiesnoconv('SignedReceiver');
104 break;
105 case 3:
106 $this->context['actionmsg2'] = $langs->transnoentitiesnoconv('SignedReceiverOnline');
107 break;
108 case 9:
109 $this->context['actionmsg2'] = $langs->transnoentitiesnoconv('SignedAll');
110 break;
111 }
112 return $this->setSignedStatusCommon($user, $status, $notrigger, $triggercode);
113 }
114
124 public function setSignedStatusCommon(User $user, int $status, int $notrigger = 0, string $triggercode = ''): int
125 {
126 global $langs;
127 $langs->loadLangs(array('commercial'));
128
129 $error = 0;
130
131 if ($this instanceof CommonObject) {
132 $this->db->begin();
133 $statusfield = 'signed_status';
134
135 $sql = "UPDATE ".$this->db->prefix().$this->table_element;
136 $sql .= " SET ".$statusfield." = ".((int) $status);
137 $sql .= " WHERE rowid = ".((int) $this->id);
138
139 if ($this->db->query($sql)) {
140 if (!$error) {
141 $this->oldcopy = clone $this;
142 }
143
144 if (!$error && !$notrigger) {
145 // Call trigger
146 $result = $this->call_trigger($triggercode, $user);
147 if ($result < 0) {
148 $error++;
149 }
150 }
151
152 if (!$error) {
153 $this->signed_status = $status;
154 $this->db->commit();
155 setEventMessages($langs->transnoentitiesnoconv('DocumentSigned'), null, 'warnings');
156 return 1;
157 } else {
158 $this->db->rollback();
159 return -1;
160 }
161 } else {
162 $this->error = $this->db->error();
163 $this->db->rollback();
164 return -1;
165 }
166 } else {
167 return $error;
168 }
169 }
170
177 public function getLibSignedStatus(int $mode = 0): string
178 {
179 global $langs;
180 $langs->load("commercial");
181 $list_signed_status = $this->getSignedStatusLocalisedArray();
182 $signed_status_label = $this->signed_status != '' ? $list_signed_status[$this->signed_status] : '';
183 $signed_status_label_short = $this->signed_status != '' ? $list_signed_status[$this->signed_status] : '';
184 $signed_status_code = 'status'.$this->signed_status;
185 return dolGetStatus($signed_status_label, $signed_status_label_short, '', $signed_status_code, $mode);
186 }
187}
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.