From 470cd5c68225a90dace0bf622a384a4f8bc7ce43 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 25 Jan 2021 12:39:44 +0100 Subject: [PATCH] Clean code --- htdocs/core/class/commonobject.class.php | 6 ++-- .../class/workstationresource.class.php | 35 ++++++++++++++----- .../class/workstationusergroup.class.php | 32 +++++++++++++---- 3 files changed, 56 insertions(+), 17 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index c4ab884b6f7..42dc528aada 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -3668,7 +3668,7 @@ abstract class CommonObject * @param string $field_select name of field we need to get a list * @param string $field_where name of field of object we need to get linked items * @param string $table_element name of association table - * @return array + * @return array Array of record */ static public function getAllItemsLinkedByObjectID($fk_object_where, $field_select, $field_where, $table_element) { @@ -3697,7 +3697,7 @@ abstract class CommonObject * @param int $fk_object_where id of object we need to remove linked items * @param string $field_where name of field of object we need to delete linked items * @param string $table_element name of association table - * @return int + * @return int <0 if KO, 0 if nothing done, >0 if OK and something done */ static public function deleteAllItemsLinkedByObjectID($fk_object_where, $field_where, $table_element) { @@ -7143,7 +7143,7 @@ abstract class CommonObject $("#"+child_list).show() } }); - + //When we change parent list $("select[name=\""+parent_list+"\"]").change(function() { showOptions(child_list, parent_list, orig_select[child_list]); diff --git a/htdocs/workstation/class/workstationresource.class.php b/htdocs/workstation/class/workstationresource.class.php index 21398460eca..7b0dcf96002 100644 --- a/htdocs/workstation/class/workstationresource.class.php +++ b/htdocs/workstation/class/workstationresource.class.php @@ -22,10 +22,10 @@ * \brief This file is a CRUD class file for WorkstationResource (Create/Read/Update/Delete) */ -/** - * Class for WorkstationResource - */ +/** + * Class to link resource with Workstations + */ class WorkstationResource extends CommonObject { /** @var string $table_element Table name in SQL */ @@ -34,17 +34,34 @@ class WorkstationResource extends CommonObject /** @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'; - public $fields = array( + /** + * @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor. + */ + public $fields = array( 'fk_workstation' => array ('type' => 'integer'), 'fk_resource' => array ('type' => 'integer') ); + /** + * @var int ID of workstation + */ + public $fk_workstation; + + /** + * @var int ID of dolresource + */ + public $fk_resource; + + /** * WorkstationResource constructor. + * * @param DoliDB $db Database connector */ public function __construct($db) { + global $langs; + $this->db = $db; // Unset fields that are disabled @@ -74,8 +91,9 @@ class WorkstationResource extends CommonObject /** * Function used to get an array with all resources linked to a workstation - * @param int $fk_workstation id of workstation we need to get linked resources - * @return array + * + * @param int $fk_workstation Id of workstation we need to get linked resources + * @return array Array of record */ static public function getAllResourcesOfWorkstation($fk_workstation) { @@ -86,8 +104,9 @@ class WorkstationResource extends CommonObject /** * Function used to remove all resources linked to a workstation - * @param int $fk_workstation id of workstation we need to remove linked resources - * @return int + * + * @param int $fk_workstation Id of workstation we need to remove linked resources + * @return int <0 if KO, 0 if nothing done, >0 if OK and something done */ static public function deleteAllResourcesOfWorkstation($fk_workstation) { diff --git a/htdocs/workstation/class/workstationusergroup.class.php b/htdocs/workstation/class/workstationusergroup.class.php index b45d24c7c60..83ef89973c8 100644 --- a/htdocs/workstation/class/workstationusergroup.class.php +++ b/htdocs/workstation/class/workstationusergroup.class.php @@ -23,9 +23,8 @@ */ /** - * Class for WorkstationUserGroup + * Class to link User groups and Workstations */ - class WorkstationUserGroup extends CommonObject { /** @var string $table_element Table name in SQL */ @@ -34,17 +33,34 @@ class WorkstationUserGroup extends CommonObject /** @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 = 'workstationusergroup'; - public $fields = array( + /** + * @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor. + */ + public $fields = array( 'fk_workstation' => array ('type' => 'integer'), 'fk_usergroup' => array ('type' => 'integer') ); + /** + * @var int ID of workstation + */ + public $fk_workstation; + + /** + * @var int ID of user group + */ + public $fk_usergroup; + + /** * WorkstationUserGroup constructor. + * * @param DoliDB $db Database connector */ public function __construct($db) { + global $langs; + $this->db = $db; // Unset fields that are disabled @@ -74,24 +90,28 @@ class WorkstationUserGroup extends CommonObject /** * Function used to get an array with all usergroups linked to a workstation + * * @param int $fk_workstation id of workstation we need to get linked usergroups - * @return array + * @return array Array of record */ static public function getAllGroupsOfWorkstation($fk_workstation) { global $db; + $obj = new self($db); return parent::getAllItemsLinkedByObjectID($fk_workstation, 'fk_usergroup', 'fk_workstation', $obj->table_element); } /** * Function used to remove all usergroups linked to a workstation - * @param int $fk_workstation id of workstation we need to remove linked usergroups - * @return int + * + * @param int $fk_workstation Id of workstation we need to remove linked usergroups + * @return int <0 if KO, 0 if nothing done, >0 if OK and something done */ static public function deleteAllGroupsOfWorkstation($fk_workstation) { global $db; + $obj = new self($db); return parent::deleteAllItemsLinkedByObjectID($fk_workstation, 'fk_workstation', $obj->table_element); }