2020-12-17 13:18:40 +01:00
< ? php
2020-12-21 13:29:44 +01:00
/* Copyright ( C ) 2017 Laurent Destailleur < eldy @ users . sourceforge . net >
* Copyright ( C ) 2020 Gauthier VERDOL < gauthier . verdol @ atm - consulting . fr >
2024-03-11 17:40:41 +01:00
* Copyright ( C ) 2024 MDW < mdeweerd @ users . noreply . github . com >
2024-03-20 08:41:27 +01:00
* Copyright ( C ) 2024 Frédéric France < frederic . france @ free . fr >
2020-12-21 13:29:44 +01:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < https :// www . gnu . org / licenses />.
*/
/**
2024-03-20 08:41:27 +01:00
* \file htdocs / workstation / class / workstationresource . class . php
2020-12-21 13:29:44 +01:00
* \ingroup workstation
* \brief This file is a CRUD class file for WorkstationResource ( Create / Read / Update / Delete )
*/
2021-01-25 12:39:44 +01:00
2020-12-21 13:29:44 +01:00
/**
2021-01-25 12:39:44 +01:00
* Class to link resource with Workstations
2020-12-21 13:29:44 +01:00
*/
2020-12-17 13:18:40 +01:00
class WorkstationResource extends CommonObject
{
/** @var string $table_element Table name in SQL */
public $table_element = 'workstation_workstation_resource' ;
/** @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) */
public $element = 'workstationresource' ;
2021-01-25 12:39:44 +01:00
/**
2025-02-05 00:40:06 +01:00
* @ var array < string , array { type : string , label : string , enabled : int < 0 , 2 >| string , position : int , notnull ? : int , visible : int <- 6 , 6 >| string , alwayseditable ? : int < 0 , 1 > , noteditable ? : int < 0 , 1 > , default ? : string , index ? : int , foreignkey ? : string , searchall ? : int < 0 , 1 > , isameasure ? : int < 0 , 1 > , css ? : string , csslist ? : string , help ? : string , showoncombobox ? : int < 0 , 4 > , disabled ? : int < 0 , 1 > , arrayofkeyval ? : array < int | string , string > , autofocusoncreate ? : int < 0 , 1 > , comment ? : string , copytoclipboard ? : int < 1 , 2 > , validate ? : int < 0 , 1 > , showonheader ? : int < 0 , 1 > } > Array with all fields and their property . Do not use it as a static var . It may be modified by constructor .
2021-01-25 12:39:44 +01:00
*/
2021-01-25 16:23:09 +01:00
public $fields = array (
2024-03-20 08:41:27 +01:00
'fk_workstation' => array ( 'type' => 'integer' , 'label' => 'Workstation' , 'enabled' => 1 , 'position' => 10 , 'visible' => 1 ),
'fk_resource' => array ( 'type' => 'integer' , 'label' => 'UserGroup' , 'enabled' => 1 , 'position' => 20 , 'visible' => 1 ),
2020-12-17 13:18:40 +01:00
);
2021-01-25 16:24:27 +01:00
/**
* @ var int ID of workstation
*/
2021-01-25 16:23:09 +01:00
public $fk_workstation ;
2021-01-25 12:39:44 +01:00
2021-01-25 16:24:27 +01:00
/**
* @ var int ID of dolresource
*/
2021-01-25 16:23:09 +01:00
public $fk_resource ;
2021-01-25 12:39:44 +01:00
2020-12-17 13:18:40 +01:00
/**
* WorkstationResource constructor .
2021-01-25 12:39:44 +01:00
*
2020-12-17 13:18:40 +01:00
* @ param DoliDB $db Database connector
*/
public function __construct ( $db )
{
2021-01-25 12:39:44 +01:00
global $langs ;
2020-12-17 13:18:40 +01:00
$this -> db = $db ;
// Unset fields that are disabled
2021-02-22 18:50:45 +01:00
foreach ( $this -> fields as $key => $val ) {
if ( isset ( $val [ 'enabled' ]) && empty ( $val [ 'enabled' ])) {
2020-12-17 13:18:40 +01:00
unset ( $this -> fields [ $key ]);
}
}
// Translate some data of arrayofkeyval
2021-02-22 18:50:45 +01:00
if ( is_object ( $langs )) {
foreach ( $this -> fields as $key => $val ) {
if ( ! empty ( $val [ 'arrayofkeyval' ]) && is_array ( $val [ 'arrayofkeyval' ])) {
foreach ( $val [ 'arrayofkeyval' ] as $key2 => $val2 ) {
2020-12-17 13:18:40 +01:00
$this -> fields [ $key ][ 'arrayofkeyval' ][ $key2 ] = $langs -> trans ( $val2 );
}
}
}
}
}
2020-12-21 13:29:44 +01:00
/**
* Function used to get an array with all resources linked to a workstation
2021-01-25 12:39:44 +01:00
*
* @ param int $fk_workstation Id of workstation we need to get linked resources
2024-11-06 23:57:45 +01:00
* @ return int [] Array of record
2020-12-21 13:29:44 +01:00
*/
2021-02-22 18:50:45 +01:00
public static function getAllResourcesOfWorkstation ( $fk_workstation )
2020-12-21 12:34:51 +01:00
{
2020-12-17 13:18:40 +01:00
global $db ;
$obj = new self ( $db );
2021-01-11 11:36:19 +01:00
return parent :: getAllItemsLinkedByObjectID ( $fk_workstation , 'fk_resource' , 'fk_workstation' , $obj -> table_element );
2020-12-17 13:18:40 +01:00
}
2020-12-21 13:29:44 +01:00
/**
* Function used to remove all resources linked to a workstation
2021-01-25 12:39:44 +01:00
*
* @ param int $fk_workstation Id of workstation we need to remove linked resources
2023-12-06 15:46:39 +01:00
* @ return int Return integer < 0 if KO , 0 if nothing done , > 0 if OK and something done
2020-12-21 13:29:44 +01:00
*/
2021-02-22 18:50:45 +01:00
public static function deleteAllResourcesOfWorkstation ( $fk_workstation )
2020-12-21 12:34:51 +01:00
{
2020-12-17 13:18:40 +01:00
global $db ;
$obj = new self ( $db );
2021-01-11 11:36:19 +01:00
return parent :: deleteAllItemsLinkedByObjectID ( $fk_workstation , 'fk_workstation' , $obj -> table_element );
2020-12-17 13:18:40 +01:00
}
}