Merge pull request #24086 from lamrani002/apiForModule
NEW comment in api_mymodule for seperate methods
This commit is contained in:
commit
dd1a9d91fc
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user