|
1
|
|
|
<?php |
|
2
|
|
|
/* Copyright (C) 2007-2017 Laurent Destailleur <[email protected]> |
|
3
|
|
|
* Copyright (C) 2014-2016 Juanjo Menent <[email protected]> |
|
4
|
|
|
* Copyright (C) 2015 Florian Henry <[email protected]> |
|
5
|
|
|
* Copyright (C) 2015 Raphaël Doursenaud <[email protected]> |
|
6
|
|
|
* Copyright (C) ---Put here your own copyright and developer email--- |
|
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 <http://www.gnu.org/licenses/>. |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* \file htdocs/modulebuilder/template/class/myobject.class.php |
|
24
|
|
|
* \ingroup mymodule |
|
25
|
|
|
* \brief This file is a CRUD class file for MyObject (Create/Read/Update/Delete) |
|
26
|
|
|
*/ |
|
27
|
|
|
|
|
28
|
|
|
// Put here all includes required by your class file |
|
29
|
|
|
require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php'; |
|
30
|
|
|
//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php'; |
|
31
|
|
|
//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php'; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Class for MyObject |
|
35
|
|
|
*/ |
|
36
|
|
|
class MyObject extends CommonObject |
|
37
|
|
|
{ |
|
38
|
|
|
/** |
|
39
|
|
|
* @var string ID to identify managed object |
|
40
|
|
|
*/ |
|
41
|
|
|
public $element = 'myobject'; |
|
42
|
|
|
/** |
|
43
|
|
|
* @var string Name of table without prefix where object is stored |
|
44
|
|
|
*/ |
|
45
|
|
|
public $table_element = 'myobject'; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @var array Does this field is linked to a thirdparty ? |
|
49
|
|
|
*/ |
|
50
|
|
|
protected $isnolinkedbythird = 1; |
|
51
|
|
|
/** |
|
52
|
|
|
* @var array Does myobject support multicompany module ? 0=No test on entity, 1=Test with field entity, 2=Test with link by societe |
|
53
|
|
|
*/ |
|
54
|
|
|
protected $ismultientitymanaged = 1; |
|
55
|
|
|
/** |
|
56
|
|
|
* @var string String with name of icon for myobject |
|
57
|
|
|
*/ |
|
58
|
|
|
public $picto = 'myobject@mymodule'; |
|
59
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* 'type' if the field format, 'label' the translation key, 'enabled' is a condition when the filed must be managed, |
|
63
|
|
|
* 'visible' says if field is visible in list (-1 means not shown by default but can be aded into list to be viewed) |
|
64
|
|
|
* 'notnull' if not null in database |
|
65
|
|
|
* 'index' if we want an index in database |
|
66
|
|
|
* 'position' is the sort order of field |
|
67
|
|
|
* 'searchall' is 1 if we want to search in this field when making a search from the quick search button |
|
68
|
|
|
* '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). |
|
69
|
|
|
* 'comment' is not used. You can store here any text of your choice. |
|
70
|
|
|
*/ |
|
71
|
|
|
|
|
72
|
|
|
// BEGIN MODULEBUILDER PROPERTIES |
|
73
|
|
|
/** |
|
74
|
|
|
* @var array Array with all fields and their property |
|
75
|
|
|
*/ |
|
76
|
|
|
public $fields=array( |
|
77
|
|
|
'rowid' =>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-1, 'notnull'=>true, 'index'=>true, 'position'=>1, 'comment'=>'Id'), |
|
78
|
|
|
'ref' =>array('type'=>'varchar(64)', 'label'=>'Ref', 'enabled'=>1, 'visible'=>1, 'notnull'=>true, 'index'=>true, 'position'=>10, 'searchall'=>1, 'comment'=>'Reference of object'), |
|
79
|
|
|
'entity' =>array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'notnull'=>true, 'index'=>true, 'position'=>20), |
|
80
|
|
|
'label' =>array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>1, 'visible'=>1, 'position'=>30, 'searchall'=>1), |
|
81
|
|
|
'amount' =>array('type'=>'double(24,8)', 'label'=>'Amount', 'enabled'=>1, 'visible'=>1, 'position'=>40, 'searchall'=>0, 'isameasure'=>1), |
|
82
|
|
|
'status' =>array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'index'=>true, 'position'=>1000), |
|
83
|
|
|
'date_creation' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-1, 'notnull'=>true, 'position'=>500), |
|
84
|
|
|
'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-1, 'notnull'=>true, 'position'=>500), |
|
85
|
|
|
//'date_valid' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-1, 'position'=>500), |
|
86
|
|
|
'fk_user_creat' =>array('type'=>'integer', 'label'=>'UserAuthor', 'enabled'=>1, 'visible'=>-1, 'notnull'=>true, 'position'=>500), |
|
87
|
|
|
'fk_user_modif' =>array('type'=>'integer', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>-1, 'position'=>500), |
|
88
|
|
|
//'fk_user_valid' =>array('type'=>'integer', 'label'=>'UserValid', 'enabled'=>1, 'visible'=>-1, 'position'=>500), |
|
89
|
|
|
'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-1, 'notnull'=>true, 'position'=>500), |
|
90
|
|
|
'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-1, 'index'=>true, 'position'=>1000, 'nullifempty'=>1), |
|
91
|
|
|
); |
|
92
|
|
|
// END MODULEBUILDER PROPERTIES |
|
93
|
|
|
|
|
94
|
|
|
|
|
95
|
|
|
|
|
96
|
|
|
// If this object has a subtable with lines |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @var int Name of subtable line |
|
100
|
|
|
*/ |
|
101
|
|
|
//public $table_element_line = 'myobjectdet'; |
|
102
|
|
|
/** |
|
103
|
|
|
* @var int Field with ID of parent key if this field has a parent |
|
104
|
|
|
*/ |
|
105
|
|
|
//public $fk_element = 'fk_myobject'; |
|
106
|
|
|
/** |
|
107
|
|
|
* @var int Name of subtable class that manage subtable lines |
|
108
|
|
|
*/ |
|
109
|
|
|
//public $class_element_line = 'MyObjectline'; |
|
110
|
|
|
/** |
|
111
|
|
|
* @var array Array of child tables (child tables to delete before deleting a record) |
|
112
|
|
|
*/ |
|
113
|
|
|
//protected $childtables=array('myobjectdet'); |
|
114
|
|
|
/** |
|
115
|
|
|
* @var MyObjectLine[] Array of subtable lines |
|
116
|
|
|
*/ |
|
117
|
|
|
//public $lines = array(); |
|
118
|
|
|
|
|
119
|
|
|
|
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* Constructor |
|
123
|
|
|
* |
|
124
|
|
|
* @param DoliDb $db Database handler |
|
125
|
|
|
*/ |
|
126
|
|
|
public function __construct(DoliDB $db) |
|
127
|
|
|
{ |
|
128
|
|
|
$this->db = $db; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* Create object into database |
|
133
|
|
|
* |
|
134
|
|
|
* @param User $user User that creates |
|
135
|
|
|
* @param bool $notrigger false=launch triggers after, true=disable triggers |
|
136
|
|
|
* @return int <0 if KO, Id of created object if OK |
|
137
|
|
|
*/ |
|
138
|
|
|
public function create(User $user, $notrigger = false) |
|
139
|
|
|
{ |
|
140
|
|
|
return $this->createCommon($user, $notrigger); |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* Load object in memory from the database |
|
145
|
|
|
* |
|
146
|
|
|
* @param int $id Id object |
|
147
|
|
|
* @param string $ref Ref |
|
148
|
|
|
* @return int <0 if KO, 0 if not found, >0 if OK |
|
149
|
|
|
*/ |
|
150
|
|
|
public function fetch($id, $ref = null) |
|
151
|
|
|
{ |
|
152
|
|
|
return $this->fetchCommon($id, $ref); |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* Update object into database |
|
157
|
|
|
* |
|
158
|
|
|
* @param User $user User that modifies |
|
159
|
|
|
* @param bool $notrigger false=launch triggers after, true=disable triggers |
|
160
|
|
|
* @return int <0 if KO, >0 if OK |
|
161
|
|
|
*/ |
|
162
|
|
|
public function update(User $user, $notrigger = false) |
|
163
|
|
|
{ |
|
164
|
|
|
return $this->updateCommon($user, $notrigger); |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* Delete object in database |
|
169
|
|
|
* |
|
170
|
|
|
* @param User $user User that deletes |
|
171
|
|
|
* @param bool $notrigger false=launch triggers after, true=disable triggers |
|
172
|
|
|
* @return int <0 if KO, >0 if OK |
|
173
|
|
|
*/ |
|
174
|
|
|
public function delete(User $user, $notrigger = false) |
|
175
|
|
|
{ |
|
176
|
|
|
return $this->deleteCommon($user, $trigger); |
|
|
|
|
|
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* Return a link to the object card (with optionaly the picto) |
|
181
|
|
|
* |
|
182
|
|
|
* @param int $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto) |
|
183
|
|
|
* @param string $option On what the link point to |
|
184
|
|
|
* @param int $notooltip 1=Disable tooltip |
|
185
|
|
|
* @param string $morecss Add more css on link |
|
186
|
|
|
* @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking |
|
187
|
|
|
* @return string String with URL |
|
188
|
|
|
*/ |
|
189
|
|
|
function getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1) |
|
190
|
|
|
{ |
|
191
|
|
|
global $db, $conf, $langs; |
|
192
|
|
|
global $dolibarr_main_authentication, $dolibarr_main_demo; |
|
193
|
|
|
global $menumanager; |
|
194
|
|
|
|
|
195
|
|
|
if (! empty($conf->dol_no_mouse_hover)) $notooltip=1; // Force disable tooltips |
|
196
|
|
|
|
|
197
|
|
|
$result = ''; |
|
198
|
|
|
$companylink = ''; |
|
199
|
|
|
|
|
200
|
|
|
$label = '<u>' . $langs->trans("MyObject") . '</u>'; |
|
201
|
|
|
$label.= '<br>'; |
|
202
|
|
|
$label.= '<b>' . $langs->trans('Ref') . ':</b> ' . $this->ref; |
|
203
|
|
|
|
|
204
|
|
|
$url=''; |
|
205
|
|
|
if ($option != 'nolink') |
|
206
|
|
|
{ |
|
207
|
|
|
$url = dol_buildpath('/mymodule/myobject_card.php',1).'?id='.$this->id; |
|
208
|
|
|
|
|
209
|
|
|
// Add param to save lastsearch_values or not |
|
210
|
|
|
$add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0); |
|
211
|
|
|
if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1; |
|
212
|
|
|
if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1'; |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
$linkclose=''; |
|
216
|
|
|
if (empty($notooltip)) |
|
217
|
|
|
{ |
|
218
|
|
|
if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) |
|
219
|
|
|
{ |
|
220
|
|
|
$label=$langs->trans("ShowMyObject"); |
|
221
|
|
|
$linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"'; |
|
222
|
|
|
} |
|
223
|
|
|
$linkclose.=' title="'.dol_escape_htmltag($label, 1).'"'; |
|
224
|
|
|
$linkclose.=' class="classfortooltip'.($morecss?' '.$morecss:'').'"'; |
|
225
|
|
|
} |
|
226
|
|
|
else $linkclose = ($morecss?' class="'.$morecss.'"':''); |
|
227
|
|
|
|
|
228
|
|
|
$linkstart = '<a href="'.$url.'"'; |
|
229
|
|
|
$linkstart.=$linkclose.'>'; |
|
230
|
|
|
$linkend='</a>'; |
|
231
|
|
|
|
|
232
|
|
|
if ($withpicto) |
|
233
|
|
|
{ |
|
234
|
|
|
$result.=($linkstart.img_object(($notooltip?'':$label), 'label', ($notooltip?'':'class="classfortooltip"')).$linkend); |
|
235
|
|
|
if ($withpicto != 2) $result.=' '; |
|
236
|
|
|
} |
|
237
|
|
|
$result.= $linkstart . $this->ref . $linkend; |
|
238
|
|
|
return $result; |
|
239
|
|
|
} |
|
240
|
|
|
|
|
241
|
|
|
/** |
|
242
|
|
|
* Retourne le libelle du status d'un user (actif, inactif) |
|
243
|
|
|
* |
|
244
|
|
|
* @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto |
|
245
|
|
|
* @return string Label of status |
|
246
|
|
|
*/ |
|
247
|
|
|
function getLibStatut($mode=0) |
|
248
|
|
|
{ |
|
249
|
|
|
return $this->LibStatut($this->status,$mode); |
|
250
|
|
|
} |
|
251
|
|
|
|
|
252
|
|
|
/** |
|
253
|
|
|
* Return the status |
|
254
|
|
|
* |
|
255
|
|
|
* @param int $status Id status |
|
256
|
|
|
* @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 5=Long label + Picto |
|
257
|
|
|
* @return string Label of status |
|
258
|
|
|
*/ |
|
259
|
|
|
static function LibStatut($status,$mode=0) |
|
260
|
|
|
{ |
|
261
|
|
|
global $langs; |
|
262
|
|
|
|
|
263
|
|
|
if ($mode == 0) |
|
264
|
|
|
{ |
|
265
|
|
|
$prefix=''; |
|
266
|
|
|
if ($status == 1) return $langs->trans('Enabled'); |
|
267
|
|
|
if ($status == 0) return $langs->trans('Disabled'); |
|
268
|
|
|
} |
|
269
|
|
|
if ($mode == 1) |
|
270
|
|
|
{ |
|
271
|
|
|
if ($status == 1) return $langs->trans('Enabled'); |
|
272
|
|
|
if ($status == 0) return $langs->trans('Disabled'); |
|
273
|
|
|
} |
|
274
|
|
|
if ($mode == 2) |
|
275
|
|
|
{ |
|
276
|
|
|
if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled'); |
|
277
|
|
|
if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled'); |
|
278
|
|
|
} |
|
279
|
|
|
if ($mode == 3) |
|
280
|
|
|
{ |
|
281
|
|
|
if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4'); |
|
282
|
|
|
if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5'); |
|
283
|
|
|
} |
|
284
|
|
|
if ($mode == 4) |
|
285
|
|
|
{ |
|
286
|
|
|
if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled'); |
|
287
|
|
|
if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled'); |
|
288
|
|
|
} |
|
289
|
|
|
if ($mode == 5) |
|
290
|
|
|
{ |
|
291
|
|
|
if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4'); |
|
292
|
|
|
if ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5'); |
|
293
|
|
|
} |
|
294
|
|
|
if ($mode == 6) |
|
295
|
|
|
{ |
|
296
|
|
|
if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4'); |
|
297
|
|
|
if ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5'); |
|
298
|
|
|
} |
|
299
|
|
|
} |
|
300
|
|
|
|
|
301
|
|
|
/** |
|
302
|
|
|
* Charge les informations d'ordre info dans l'objet commande |
|
303
|
|
|
* |
|
304
|
|
|
* @param int $id Id of order |
|
305
|
|
|
* @return void |
|
306
|
|
|
*/ |
|
307
|
|
|
function info($id) |
|
308
|
|
|
{ |
|
309
|
|
|
$sql = 'SELECT rowid, date_creation as datec, tms as datem,'; |
|
310
|
|
|
$sql.= ' fk_user_creat, fk_user_modif'; |
|
311
|
|
|
$sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; |
|
312
|
|
|
$sql.= ' WHERE t.rowid = '.$id; |
|
313
|
|
|
$result=$this->db->query($sql); |
|
314
|
|
|
if ($result) |
|
315
|
|
|
{ |
|
316
|
|
|
if ($this->db->num_rows($result)) |
|
317
|
|
|
{ |
|
318
|
|
|
$obj = $this->db->fetch_object($result); |
|
319
|
|
|
$this->id = $obj->rowid; |
|
320
|
|
|
if ($obj->fk_user_author) |
|
321
|
|
|
{ |
|
322
|
|
|
$cuser = new User($this->db); |
|
323
|
|
|
$cuser->fetch($obj->fk_user_author); |
|
324
|
|
|
$this->user_creation = $cuser; |
|
325
|
|
|
} |
|
326
|
|
|
|
|
327
|
|
|
if ($obj->fk_user_valid) |
|
328
|
|
|
{ |
|
329
|
|
|
$vuser = new User($this->db); |
|
330
|
|
|
$vuser->fetch($obj->fk_user_valid); |
|
331
|
|
|
$this->user_validation = $vuser; |
|
332
|
|
|
} |
|
333
|
|
|
|
|
334
|
|
|
if ($obj->fk_user_cloture) |
|
335
|
|
|
{ |
|
336
|
|
|
$cluser = new User($this->db); |
|
337
|
|
|
$cluser->fetch($obj->fk_user_cloture); |
|
338
|
|
|
$this->user_cloture = $cluser; |
|
339
|
|
|
} |
|
340
|
|
|
|
|
341
|
|
|
$this->date_creation = $this->db->jdate($obj->datec); |
|
342
|
|
|
$this->date_modification = $this->db->jdate($obj->datem); |
|
343
|
|
|
$this->date_validation = $this->db->jdate($obj->datev); |
|
344
|
|
|
} |
|
345
|
|
|
|
|
346
|
|
|
$this->db->free($result); |
|
347
|
|
|
|
|
348
|
|
|
} |
|
349
|
|
|
else |
|
350
|
|
|
{ |
|
351
|
|
|
dol_print_error($this->db); |
|
352
|
|
|
} |
|
353
|
|
|
} |
|
354
|
|
|
|
|
355
|
|
|
/** |
|
356
|
|
|
* Initialise object with example values |
|
357
|
|
|
* Id must be 0 if object instance is a specimen |
|
358
|
|
|
* |
|
359
|
|
|
* @return void |
|
360
|
|
|
*/ |
|
361
|
|
|
public function initAsSpecimen() |
|
362
|
|
|
{ |
|
363
|
|
|
$this->initAsSpecimenCommon(); |
|
364
|
|
|
} |
|
365
|
|
|
|
|
366
|
|
|
} |
|
367
|
|
|
|
|
368
|
|
|
/** |
|
369
|
|
|
* Class MyModuleObjectLine |
|
370
|
|
|
*/ |
|
371
|
|
|
class MyModuleObjectLine |
|
372
|
|
|
{ |
|
373
|
|
|
/** |
|
374
|
|
|
* @var int ID |
|
375
|
|
|
*/ |
|
376
|
|
|
public $id; |
|
377
|
|
|
/** |
|
378
|
|
|
* @var mixed Sample line property 1 |
|
379
|
|
|
*/ |
|
380
|
|
|
public $prop1; |
|
381
|
|
|
/** |
|
382
|
|
|
* @var mixed Sample line property 2 |
|
383
|
|
|
*/ |
|
384
|
|
|
public $prop2; |
|
385
|
|
|
} |
|
386
|
|
|
|
This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.
The variable may have been renamed without also renaming all references.