From 0d3a4d68b2281332611edf0314b9faca6c2e0ca6 Mon Sep 17 00:00:00 2001 From: Lamrani Abdel Date: Wed, 1 Mar 2023 23:20:42 +0100 Subject: [PATCH] add comment in api_mymodule for seperate methods --- .../template/class/api_mymodule.class.php | 50 ++++++++++--------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/htdocs/modulebuilder/template/class/api_mymodule.class.php b/htdocs/modulebuilder/template/class/api_mymodule.class.php index fdb56ff3c67..a48b2f5010b 100644 --- a/htdocs/modulebuilder/template/class/api_mymodule.class.php +++ b/htdocs/modulebuilder/template/class/api_mymodule.class.php @@ -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; - } }