Clean code

This commit is contained in:
Laurent Destailleur 2021-01-25 12:39:44 +01:00
parent 4b248263c8
commit 470cd5c682
3 changed files with 56 additions and 17 deletions

View File

@ -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]);

View File

@ -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)
{

View File

@ -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);
}