Test Failed
Push — main ( 29a1e7...86a642 )
by Rafael
61:24
created

ActionCommReminder::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/* Copyright (C) 2017       Laurent Destailleur     <[email protected]>
4
 * Copyright (C) 2024       Frédéric France         <[email protected]>
5
 * Copyright (C) 2024		MDW						<[email protected]>
6
 * Copyright (C) 2024       Rafael San José         <[email protected]>
7
 *
8
 * This program is free software; you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License as published by
10
 * the Free Software Foundation; either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20
 */
21
22
namespace DoliModules\Agenda\Model;
23
24
/**
25
 * \file        class/actioncommreminder.class.php
26
 * \ingroup     agenda
27
 * \brief       This file is a CRUD class file for ActionCommReminder (Create/Read/Update/Delete)
28
 */
29
30
use DoliCore\Base\GenericDocument;
31
32
/**
33
 * Class for ActionCommReminder
34
 */
35
class ActionCommReminder extends GenericDocument
36
{
37
    /**
38
     * @var string ID to identify managed object
39
     */
40
    public $element = 'actioncomm_reminder';
41
42
    /**
43
     * @var string Name of table without prefix where object is stored
44
     */
45
    public $table_element = 'actioncomm_reminder';
46
47
    /**
48
     * @var int  Does actioncommreminder support multicompany module ? 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
49
     */
50
    public $ismultientitymanaged = 0;
51
52
    /**
53
     * @var string String with name of icon for actioncommreminder. Must be the part after the 'object_' into object_actioncommreminder.png
54
     */
55
    public $picto = 'generic';
56
57
    const STATUS_TODO = 0;
58
    const STATUS_DONE = 1;
59
    const STATUS_ERROR = -1;
60
61
62
    /**
63
     *  'type' if the field format.
64
     *  'label' the translation key.
65
     *  'enabled' is a condition when the field must be managed.
66
     *  'visible' says if field is visible in list (Examples: 0=Not visible, 1=Visible on list and create/update/view forms, 2=Visible on list only. Using a negative value means field is not shown by default on list but can be selected for viewing)
67
     *  'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0).
68
     *  'index' if we want an index in database.
69
     *  'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommended to name the field fk_...).
70
     *  'position' is the sort order of field.
71
     *  'searchall' is 1 if we want to search in this field when making a search from the quick search button.
72
     *  'isameasure' must be set to 1 if you want to have a total on list for this field. Field type must be summable like integer or double(24,8).
73
     *  'help' is a string visible as a tooltip on field
74
     *  'comment' is not used. You can store here any text of your choice. It is not used by application.
75
     *  'default' is a default value for creation (can still be replaced by the global setup of default values)
76
     *  'showoncombobox' if field must be shown into the label of combobox
77
     */
78
79
    // BEGIN MODULEBUILDER PROPERTIES
80
    /**
81
     * @var array<string,array{type:string,label:string,enabled:int<0,2>|string,position:int,notnull:int,visible:int,noteditable?:int,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int,css?:string,csslist?:string,help?:string,showoncombobox?:int,disabled?:int,arrayofkeyval?:array<int,string>,comment?:string}>  Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<string,array{type:...ring>,comment?:string}> at position 16 could not be parsed: Expected '}' at position 16, but found 'int'.
Loading history...
82
     */
83
    public $fields = array(
84
        'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'visible' => -1, 'enabled' => 1, 'position' => 1, 'notnull' => 1, 'index' => 1, 'comment' => "Id",),
85
        'entity' => array('type' => 'integer', 'label' => 'Entity', 'visible' => 0, 'enabled' => 1, 'position' => 20, 'notnull' => 1, 'index' => 1,),
86
        'dateremind' => array('type' => 'datetime', 'label' => 'DateRemind', 'visible' => 1, 'enabled' => 1, 'position' => 60, 'notnull' => 1, 'index' => 1,),
87
        'typeremind' => array('type' => 'varchar(32)', 'label' => 'TypeRemind', 'visible' => -1, 'enabled' => 1, 'position' => 55, 'notnull' => 1, 'comment' => "email, browser, sms",),
88
        'fk_user' => array('type' => 'integer', 'label' => 'User', 'visible' => -1, 'enabled' => 1, 'position' => 65, 'notnull' => 1, 'index' => 1,),
89
        'offsetvalue' => array('type' => 'integer', 'label' => 'OffsetValue', 'visible' => 1, 'enabled' => 1, 'position' => 56, 'notnull' => 1,),
90
        'offsetunit' => array('type' => 'varchar(1)', 'label' => 'OffsetUnit', 'visible' => 1, 'enabled' => 1, 'position' => 57, 'notnull' => 1, 'comment' => "y, m, d, w, h, i",),
91
        'status' => array('type' => 'integer', 'label' => 'Status', 'visible' => 1, 'enabled' => 1, 'position' => 58, 'notnull' => 1, 'default' => '0', 'index' => 0, 'arrayofkeyval' => array('0' => 'ToDo', '1' => 'Done')),
92
        'lasterror' => array('type' => 'varchar(128)', 'label' => 'LastError', 'visible' => -1, 'enabled' => 1, 'position' => 59, 'index' => 0),
93
        'fk_actioncomm' => array('type' => 'integer', 'label' => 'Project', 'visible' => 1, 'enabled' => 1, 'position' => 70, 'notnull' => 1, 'index' => 1,),
94
        'fk_email_template' => array('type' => 'integer', 'label' => 'EmailTemplate', 'visible' => 1, 'enabled' => 1, 'position' => 80, 'notnull' => 0),
95
    );
96
97
    /**
98
     * @var int ID
99
     */
100
    public $rowid;
101
102
    /**
103
     * @var int Entity
104
     */
105
    public $entity;
106
107
    public $dateremind;
108
109
    /**
110
     * @var string reminder type email, browser, sms
111
     */
112
    public $typeremind;
113
114
    /**
115
     * @var int User ID
116
     */
117
    public $fk_user;
118
119
    /**
120
     * @var int offset value
121
     */
122
    public $offsetvalue;
123
124
    /**
125
     * @var string y, m, d, w, h, i
126
     */
127
    public $offsetunit;
128
129
    /**
130
     * @var int Status
131
     */
132
    public $status;
133
134
    /**
135
     * @var string Last error message
136
     */
137
    public $lasterror;
138
139
    /**
140
     * @var int Project
141
     */
142
    public $fk_actioncomm;
143
144
    /**
145
     * @var int Template Mail
146
     */
147
    public $fk_email_template;
148
    // END MODULEBUILDER PROPERTIES
149
150
    /**
151
     * Constructor
152
     *
153
     * @param DoliDB $db Database handler
154
     */
155
    public function __construct(DoliDB $db)
0 ignored issues
show
Bug introduced by
The type DoliModules\Agenda\Model\DoliDB was not found. Did you mean DoliDB? If so, make sure to prefix the type with \.
Loading history...
156
    {
157
        global $conf;
158
159
        $this->db = $db;
160
161
        if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID')) {
162
            $this->fields['rowid']['visible'] = 0;
163
        }
164
        if (!isModEnabled('multicompany')) {
165
            $this->fields['entity']['enabled'] = 0;
166
        }
167
    }
168
169
    /**
170
     * Create object into database
171
     *
172
     * @param  User $user      User that creates
173
     * @param  int  $notrigger 0=launch triggers after, 1=disable triggers
174
     * @return int             Return integer <0 if KO, Id of created object if OK
175
     */
176
    public function create(User $user, $notrigger = 0)
177
    {
178
        return $this->createCommon($user, $notrigger);
179
    }
180
181
182
    /**
183
     * Load object in memory from the database
184
     *
185
     * @param int    $id   Id object
186
     * @param string $ref  Ref
187
     * @return int         Return integer <0 if KO, 0 if not found, >0 if OK
188
     */
189
    public function fetch($id, $ref = null)
190
    {
191
        $result = $this->fetchCommon($id, $ref);
192
        return $result;
193
    }
194
195
    /**
196
     * Update object into database
197
     *
198
     * @param  User $user      User that modifies
199
     * @param  int  $notrigger 0=launch triggers after, 1=disable triggers
200
     * @return int             Return integer <0 if KO, >0 if OK
201
     */
202
    public function update(User $user, $notrigger = 0)
203
    {
204
        return $this->updateCommon($user, $notrigger);
205
    }
206
207
    /**
208
     * Delete object in database
209
     *
210
     * @param User  $user       User that deletes
211
     * @param int   $notrigger  0=launch triggers after, 1=disable triggers
212
     * @return int              Return integer <0 if KO, >0 if OK
213
     */
214
    public function delete(User $user, $notrigger = 0)
215
    {
216
        return $this->deleteCommon($user, $notrigger);
217
    }
218
219
    /**
220
     *  Return label of the status of a reminder
221
     *
222
     *  @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
223
     *  @return string                 Label of status
224
     */
225
    public function getLibStatut($mode = 0)
226
    {
227
        return $this->LibStatut($this->status, $mode);
228
    }
229
230
	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
231
    /**
232
     *  Return the status
233
     *
234
     *  @param  int     $status         Id status
235
     *  @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
236
     *  @return string                  Label of status
237
     */
238
    public static function LibStatut($status, $mode = 0)
239
    {
240
		// phpcs:enable
241
        global $langs;
242
243
        $labelStatus = $langs->transnoentitiesnoconv('ToDo');
244
        if ($status == 1) {
245
            $labelStatus = $langs->transnoentitiesnoconv('Done');
246
        } elseif ($status == -1) {
247
            $labelStatus = $langs->transnoentitiesnoconv('Error');
248
        }
249
250
        $labelStatusShort = $langs->transnoentitiesnoconv('ToDo');
251
        if ($status == 1) {
252
            $labelStatus = $langs->transnoentitiesnoconv('Done');
253
        } elseif ($status == -1) {
254
            $labelStatus = $langs->transnoentitiesnoconv('Error');
255
        }
256
257
        $statusType = 'status5';
258
        if ($status == 1) {
259
            $statusType = 'status4';
260
        } elseif ($status == -1) {
261
            $statusType = 'status8';
262
        }
263
264
        return dolGetStatus($labelStatus, $labelStatusShort, '', $statusType, $mode);
265
    }
266
267
    /**
268
     * Initialise object with example values
269
     * Id must be 0 if object instance is a specimen
270
     *
271
     * @return int
272
     */
273
    public function initAsSpecimen()
274
    {
275
        return $this->initAsSpecimenCommon();
276
    }
277
}
278