add comment in api_mymodule for seperate methods

This commit is contained in:
Lamrani Abdel 2023-03-01 23:20:42 +01:00
parent a5703a9618
commit 0d3a4d68b2

View File

@ -54,6 +54,8 @@ class MyModuleApi extends DolibarrApi
$this->myobject = new MyObject($this->db);
}
/*begin methods CRUD*/
/**
* Get properties of a myobject object
*
@ -307,6 +309,31 @@ class MyModuleApi extends DolibarrApi
}
/**
* Validate fields before create or update object
*
* @param array $data Array of data to validate
* @return array
*
* @throws RestException
*/
private function _validate($data)
{
$myobject = array();
foreach ($this->myobject->fields as $field => $propfield) {
if (in_array($field, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat')) || $propfield['notnull'] != 1) {
continue; // Not a mandatory field
}
if (!isset($data[$field])) {
throw new RestException(400, "$field field missing");
}
$myobject[$field] = $data[$field];
}
return $myobject;
}
/*end methods CRUD*/
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
/**
* Clean sensible object datas
@ -369,27 +396,4 @@ class MyModuleApi extends DolibarrApi
return $object;
}
/**
* Validate fields before create or update object
*
* @param array $data Array of data to validate
* @return array
*
* @throws RestException
*/
private function _validate($data)
{
$myobject = array();
foreach ($this->myobject->fields as $field => $propfield) {
if (in_array($field, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat')) || $propfield['notnull'] != 1) {
continue; // Not a mandatory field
}
if (!isset($data[$field])) {
throw new RestException(400, "$field field missing");
}
$myobject[$field] = $data[$field];
}
return $myobject;
}
}