|
1
|
|
|
<?php |
|
2
|
|
|
/* Copyright (C) 2017 Laurent Destailleur <[email protected]> |
|
3
|
|
|
* Copyright (C) 2020 Gauthier VERDOL <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* This program is free software; you can redistribute it and/or modify |
|
6
|
|
|
* it under the terms of the GNU General Public License as published by |
|
7
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
|
8
|
|
|
* (at your option) any later version. |
|
9
|
|
|
* |
|
10
|
|
|
* This program is distributed in the hope that it will be useful, |
|
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13
|
|
|
* GNU General Public License for more details. |
|
14
|
|
|
* |
|
15
|
|
|
* You should have received a copy of the GNU General Public License |
|
16
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* \file class/workstationusergroup.class.php |
|
21
|
|
|
* \ingroup workstation |
|
22
|
|
|
* \brief This file is a CRUD class file for WorkstationUserGroup (Create/Read/Update/Delete) |
|
23
|
|
|
*/ |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Class for WorkstationUserGroup |
|
27
|
|
|
*/ |
|
28
|
|
|
|
|
29
|
|
|
class WorkstationUserGroup extends CommonObject |
|
30
|
|
|
{ |
|
31
|
|
|
/** @var string $table_element Table name in SQL */ |
|
32
|
|
|
public $table_element = 'workstation_workstation_usergroup'; |
|
33
|
|
|
|
|
34
|
|
|
/** @var string $element Name of the element (tip for better integration in Dolibarr: this value should be the reflection of the class name with ucfirst() function) */ |
|
35
|
|
|
public $element = 'workstationusergroup'; |
|
36
|
|
|
|
|
37
|
|
|
public $fields = array( |
|
38
|
|
|
'fk_workstation' => array ('type' => 'integer'), |
|
39
|
|
|
'fk_usergroup' => array ('type' => 'integer') |
|
40
|
|
|
); |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* WorkstationUserGroup constructor. |
|
44
|
|
|
* @param DoliDB $db Database connector |
|
45
|
|
|
*/ |
|
46
|
|
|
public function __construct($db) |
|
47
|
|
|
{ |
|
48
|
|
|
$this->db = $db; |
|
49
|
|
|
|
|
50
|
|
|
// Unset fields that are disabled |
|
51
|
|
|
foreach ($this->fields as $key => $val) |
|
52
|
|
|
{ |
|
53
|
|
|
if (isset($val['enabled']) && empty($val['enabled'])) |
|
54
|
|
|
{ |
|
55
|
|
|
unset($this->fields[$key]); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
// Translate some data of arrayofkeyval |
|
60
|
|
|
if (is_object($langs)) |
|
|
|
|
|
|
61
|
|
|
{ |
|
62
|
|
|
foreach ($this->fields as $key => $val) |
|
63
|
|
|
{ |
|
64
|
|
|
if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) |
|
65
|
|
|
{ |
|
66
|
|
|
foreach ($val['arrayofkeyval'] as $key2 => $val2) |
|
67
|
|
|
{ |
|
68
|
|
|
$this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Function used to get an array with all usergroups linked to a workstation |
|
77
|
|
|
* @param int $fk_workstation id of workstation we need to get linked usergroups |
|
78
|
|
|
* @return array |
|
79
|
|
|
*/ |
|
80
|
|
|
static public function getAllGroupsOfWorkstation($fk_workstation) |
|
81
|
|
|
{ |
|
82
|
|
|
global $db; |
|
83
|
|
|
$obj = new self($db); |
|
84
|
|
|
return parent::getAllItemsLinkedByObjectID($fk_workstation, 'fk_usergroup', 'fk_workstation', $obj->table_element); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Function used to remove all usergroups linked to a workstation |
|
89
|
|
|
* @param int $fk_workstation id of workstation we need to remove linked usergroups |
|
90
|
|
|
* @return int |
|
91
|
|
|
*/ |
|
92
|
|
|
static public function deleteAllGroupsOfWorkstation($fk_workstation) |
|
93
|
|
|
{ |
|
94
|
|
|
global $db; |
|
95
|
|
|
$obj = new self($db); |
|
96
|
|
|
return parent::deleteAllItemsLinkedByObjectID($fk_workstation, 'fk_workstation', $obj->table_element); |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|