dolibarr  16.0.5
workstationresource.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2020 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
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 
30 {
32  public $table_element = 'workstation_workstation_resource';
33 
35  public $element = 'workstationresource';
36 
40  public $fields = array(
41  'fk_workstation' => array('type' => 'integer'),
42  'fk_resource' => array('type' => 'integer')
43  );
44 
48  public $fk_workstation;
49 
53  public $fk_resource;
54 
55 
61  public function __construct($db)
62  {
63  global $langs;
64 
65  $this->db = $db;
66 
67  // Unset fields that are disabled
68  foreach ($this->fields as $key => $val) {
69  if (isset($val['enabled']) && empty($val['enabled'])) {
70  unset($this->fields[$key]);
71  }
72  }
73 
74  // Translate some data of arrayofkeyval
75  if (is_object($langs)) {
76  foreach ($this->fields as $key => $val) {
77  if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
78  foreach ($val['arrayofkeyval'] as $key2 => $val2) {
79  $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
80  }
81  }
82  }
83  }
84  }
85 
92  public static function getAllResourcesOfWorkstation($fk_workstation)
93  {
94  global $db;
95  $obj = new self($db);
96  return parent::getAllItemsLinkedByObjectID($fk_workstation, 'fk_resource', 'fk_workstation', $obj->table_element);
97  }
98 
105  public static function deleteAllResourcesOfWorkstation($fk_workstation)
106  {
107  global $db;
108  $obj = new self($db);
109  return parent::deleteAllItemsLinkedByObjectID($fk_workstation, 'fk_workstation', $obj->table_element);
110  }
111 }
db
$conf db
API class for accounts.
Definition: inc.php:41
CommonObject
Parent class of all other business classes (invoices, contracts, proposals, orders,...
Definition: commonobject.class.php:44
WorkstationResource\deleteAllResourcesOfWorkstation
static deleteAllResourcesOfWorkstation($fk_workstation)
Function used to remove all resources linked to a workstation.
Definition: workstationresource.class.php:105
WorkstationResource
Class to link resource with Workstations.
Definition: workstationresource.class.php:29
WorkstationResource\getAllResourcesOfWorkstation
static getAllResourcesOfWorkstation($fk_workstation)
Function used to get an array with all resources linked to a workstation.
Definition: workstationresource.class.php:92
WorkstationResource\__construct
__construct($db)
WorkstationResource constructor.
Definition: workstationresource.class.php:61