api_recruitment.class.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. <?php
  2. /* Copyright (C) 2022 Thibault FOUCART <support@ptibogxiv.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. */
  17. use Luracast\Restler\RestException;
  18. dol_include_once('/recruitment/class/recruitmentjobposition.class.php');
  19. dol_include_once('/recruitment/class/recruitmentcandidature.class.php');
  20. /**
  21. * \file recruitment/class/api_recruitment.class.php
  22. * \ingroup recruitment
  23. * \brief File for API management of recruitment.
  24. */
  25. /**
  26. * API class for recruitment
  27. *
  28. * @access protected
  29. * @class DolibarrApiAccess {@requires user,external}
  30. */
  31. class Recruitment extends DolibarrApi
  32. {
  33. /**
  34. * @var RecruitmentJobPosition $jobposition {@type RecruitmentJobPosition}
  35. */
  36. public $jobposition;
  37. /**
  38. * @var RecruitmentCandidature $candidature {@type RecruitmentCandidature}
  39. */
  40. public $candidature;
  41. /**
  42. * Constructor
  43. *
  44. * @url GET /
  45. *
  46. */
  47. public function __construct()
  48. {
  49. global $db;
  50. $this->db = $db;
  51. $this->jobposition = new RecruitmentJobPosition($this->db);
  52. $this->candidature = new RecruitmentCandidature($this->db);
  53. }
  54. /**
  55. * Get properties of a jobposition object
  56. *
  57. * Return an array with jobposition informations
  58. *
  59. * @param int $id ID of jobposition
  60. * @return array|mixed data without useless information
  61. *
  62. * @url GET jobposition/{id}
  63. *
  64. * @throws RestException 401 Not allowed
  65. * @throws RestException 404 Not found
  66. */
  67. public function getJobPosition($id)
  68. {
  69. if (!DolibarrApiAccess::$user->rights->recruitment->recruitmentjobposition->read) {
  70. throw new RestException(401);
  71. }
  72. $result = $this->jobposition->fetch($id);
  73. if (!$result) {
  74. throw new RestException(404, 'JobPosition not found');
  75. }
  76. if (!DolibarrApi::_checkAccessToResource('recruitment', $this->jobposition->id, 'recruitment_recruitmentjobposition')) {
  77. throw new RestException(401, 'Access to instance id='.$this->jobposition->id.' of object not allowed for login '.DolibarrApiAccess::$user->login);
  78. }
  79. return $this->_cleanObjectDatas($this->jobposition);
  80. }
  81. /**
  82. * Get properties of a candidature object
  83. *
  84. * Return an array with candidature informations
  85. *
  86. * @param int $id ID of candidature
  87. * @return array|mixed data without useless information
  88. *
  89. * @url GET candidature/{id}
  90. *
  91. * @throws RestException 401 Not allowed
  92. * @throws RestException 404 Not found
  93. */
  94. public function getCandidature($id)
  95. {
  96. if (!DolibarrApiAccess::$user->rights->recruitment->recruitmentjobposition->read) {
  97. throw new RestException(401);
  98. }
  99. $result = $this->candidature->fetch($id);
  100. if (!$result) {
  101. throw new RestException(404, 'Candidature not found');
  102. }
  103. if (!DolibarrApi::_checkAccessToResource('recruitment', $this->candidature->id, 'recruitment_recruitmentcandidature')) {
  104. throw new RestException(401, 'Access to instance id='.$this->candidature->id.' of object not allowed for login '.DolibarrApiAccess::$user->login);
  105. }
  106. return $this->_cleanObjectDatas($this->candidature);
  107. }
  108. /**
  109. * List jobpositions
  110. *
  111. * Get a list of jobpositions
  112. *
  113. * @param string $sortfield Sort field
  114. * @param string $sortorder Sort order
  115. * @param int $limit Limit for list
  116. * @param int $page Page number
  117. * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')"
  118. * @return array Array of order objects
  119. *
  120. * @throws RestException
  121. *
  122. * @url GET /jobposition/
  123. */
  124. public function indexJobPosition($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $sqlfilters = '')
  125. {
  126. global $db, $conf;
  127. $obj_ret = array();
  128. $tmpobject = new RecruitmentJobPosition($this->db);
  129. if (!DolibarrApiAccess::$user->rights->recruitment->recruitmentjobposition->read) {
  130. throw new RestException(401);
  131. }
  132. $socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : '';
  133. $restrictonsocid = 0; // Set to 1 if there is a field socid in table of object
  134. // If the internal user must only see his customers, force searching by him
  135. $search_sale = 0;
  136. if ($restrictonsocid && !DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) {
  137. $search_sale = DolibarrApiAccess::$user->id;
  138. }
  139. $sql = "SELECT t.rowid";
  140. if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
  141. $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
  142. }
  143. $sql .= " FROM ".MAIN_DB_PREFIX.$tmpobject->table_element." as t";
  144. if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
  145. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
  146. }
  147. $sql .= " WHERE 1 = 1";
  148. // Example of use $mode
  149. //if ($mode == 1) $sql.= " AND s.client IN (1, 3)";
  150. //if ($mode == 2) $sql.= " AND s.client IN (2, 3)";
  151. if ($tmpobject->ismultientitymanaged) {
  152. $sql .= ' AND t.entity IN ('.getEntity($tmpobject->element).')';
  153. }
  154. if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
  155. $sql .= " AND t.fk_soc = sc.fk_soc";
  156. }
  157. if ($restrictonsocid && $socid) {
  158. $sql .= " AND t.fk_soc = ".((int) $socid);
  159. }
  160. if ($restrictonsocid && $search_sale > 0) {
  161. $sql .= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
  162. }
  163. // Insert sale filter
  164. if ($restrictonsocid && $search_sale > 0) {
  165. $sql .= " AND sc.fk_user = ".((int) $search_sale);
  166. }
  167. if ($sqlfilters) {
  168. $errormessage = '';
  169. if (!DolibarrApi::_checkFilters($sqlfilters, $errormessage)) {
  170. throw new RestException(503, 'Error when validating parameter sqlfilters -> '.$errormessage);
  171. }
  172. $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^\(\)]+)\)';
  173. $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
  174. }
  175. $sql .= $this->db->order($sortfield, $sortorder);
  176. if ($limit) {
  177. if ($page < 0) {
  178. $page = 0;
  179. }
  180. $offset = $limit * $page;
  181. $sql .= $this->db->plimit($limit + 1, $offset);
  182. }
  183. $result = $this->db->query($sql);
  184. $i = 0;
  185. if ($result) {
  186. $num = $this->db->num_rows($result);
  187. while ($i < $num) {
  188. $obj = $this->db->fetch_object($result);
  189. $tmp_object = new RecruitmentJobPosition($this->db);
  190. if ($tmp_object->fetch($obj->rowid)) {
  191. $obj_ret[] = $this->_cleanObjectDatas($tmp_object);
  192. }
  193. $i++;
  194. }
  195. } else {
  196. throw new RestException(503, 'Error when retrieving jobposition list: '.$this->db->lasterror());
  197. }
  198. if (!count($obj_ret)) {
  199. throw new RestException(404, 'No jobposition found');
  200. }
  201. return $obj_ret;
  202. }
  203. /**
  204. * List candatures
  205. *
  206. * Get a list of candidatures
  207. *
  208. * @param string $sortfield Sort field
  209. * @param string $sortorder Sort order
  210. * @param int $limit Limit for list
  211. * @param int $page Page number
  212. * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')"
  213. * @return array Array of order objects
  214. *
  215. * @throws RestException
  216. *
  217. * @url GET /candidature/
  218. */
  219. public function indexCandidature($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $sqlfilters = '')
  220. {
  221. global $db, $conf;
  222. $obj_ret = array();
  223. $tmpobject = new RecruitmentCandidature($this->db);
  224. if (!DolibarrApiAccess::$user->rights->recruitment->recruitmentjobposition->read) {
  225. throw new RestException(401);
  226. }
  227. $socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : '';
  228. $restrictonsocid = 0; // Set to 1 if there is a field socid in table of object
  229. // If the internal user must only see his customers, force searching by him
  230. $search_sale = 0;
  231. if ($restrictonsocid && !DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) {
  232. $search_sale = DolibarrApiAccess::$user->id;
  233. }
  234. $sql = "SELECT t.rowid";
  235. if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
  236. $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
  237. }
  238. $sql .= " FROM ".MAIN_DB_PREFIX.$tmpobject->table_element." as t";
  239. if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
  240. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
  241. }
  242. $sql .= " WHERE 1 = 1";
  243. // Example of use $mode
  244. //if ($mode == 1) $sql.= " AND s.client IN (1, 3)";
  245. //if ($mode == 2) $sql.= " AND s.client IN (2, 3)";
  246. if ($tmpobject->ismultientitymanaged) {
  247. $sql .= ' AND t.entity IN ('.getEntity($tmpobject->element).')';
  248. }
  249. if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
  250. $sql .= " AND t.fk_soc = sc.fk_soc";
  251. }
  252. if ($restrictonsocid && $socid) {
  253. $sql .= " AND t.fk_soc = ".((int) $socid);
  254. }
  255. if ($restrictonsocid && $search_sale > 0) {
  256. $sql .= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
  257. }
  258. // Insert sale filter
  259. if ($restrictonsocid && $search_sale > 0) {
  260. $sql .= " AND sc.fk_user = ".((int) $search_sale);
  261. }
  262. if ($sqlfilters) {
  263. $errormessage = '';
  264. if (!DolibarrApi::_checkFilters($sqlfilters, $errormessage)) {
  265. throw new RestException(503, 'Error when validating parameter sqlfilters -> '.$errormessage);
  266. }
  267. $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^\(\)]+)\)';
  268. $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
  269. }
  270. $sql .= $this->db->order($sortfield, $sortorder);
  271. if ($limit) {
  272. if ($page < 0) {
  273. $page = 0;
  274. }
  275. $offset = $limit * $page;
  276. $sql .= $this->db->plimit($limit + 1, $offset);
  277. }
  278. $result = $this->db->query($sql);
  279. $i = 0;
  280. if ($result) {
  281. $num = $this->db->num_rows($result);
  282. while ($i < $num) {
  283. $obj = $this->db->fetch_object($result);
  284. $tmp_object = new RecruitmentCandidature($this->db);
  285. if ($tmp_object->fetch($obj->rowid)) {
  286. $obj_ret[] = $this->_cleanObjectDatas($tmp_object);
  287. }
  288. $i++;
  289. }
  290. } else {
  291. throw new RestException(503, 'Error when retrieving candidature list: '.$this->db->lasterror());
  292. }
  293. if (!count($obj_ret)) {
  294. throw new RestException(404, 'No candidature found');
  295. }
  296. return $obj_ret;
  297. }
  298. /**
  299. * Create jobposition object
  300. *
  301. * @param array $request_data Request datas
  302. * @return int ID of jobposition
  303. *
  304. * @throws RestException
  305. *
  306. * @url POST jobposition/
  307. */
  308. public function postJobPosition($request_data = null)
  309. {
  310. if (!DolibarrApiAccess::$user->rights->recruitment->recruitmentjobposition->write) {
  311. throw new RestException(401);
  312. }
  313. // Check mandatory fields
  314. $result = $this->_validate($request_data);
  315. foreach ($request_data as $field => $value) {
  316. $this->jobposition->$field = $this->_checkValForAPI($field, $value, $this->jobposition);
  317. }
  318. // Clean data
  319. // $this->jobposition->abc = sanitizeVal($this->jobposition->abc, 'alphanohtml');
  320. if ($this->jobposition->create(DolibarrApiAccess::$user)<0) {
  321. throw new RestException(500, "Error creating jobposition", array_merge(array($this->jobposition->error), $this->jobposition->errors));
  322. }
  323. return $this->jobposition->id;
  324. }
  325. /**
  326. * Create candidature object
  327. *
  328. * @param array $request_data Request datas
  329. * @return int ID of candidature
  330. *
  331. * @throws RestException
  332. *
  333. * @url POST candidature/
  334. */
  335. public function postCandidature($request_data = null)
  336. {
  337. if (!DolibarrApiAccess::$user->rights->recruitment->recruitmentjobposition->write) {
  338. throw new RestException(401);
  339. }
  340. // Check mandatory fields
  341. $result = $this->_validate($request_data);
  342. foreach ($request_data as $field => $value) {
  343. $this->jobposition->$field = $this->_checkValForAPI($field, $value, $this->jobposition);
  344. }
  345. // Clean data
  346. // $this->jobposition->abc = sanitizeVal($this->jobposition->abc, 'alphanohtml');
  347. if ($this->candidature->create(DolibarrApiAccess::$user)<0) {
  348. throw new RestException(500, "Error creating candidature", array_merge(array($this->candidature->error), $this->candidature->errors));
  349. }
  350. return $this->candidature->id;
  351. }
  352. /**
  353. * Update jobposition
  354. *
  355. * @param int $id Id of jobposition to update
  356. * @param array $request_data Datas
  357. * @return int
  358. *
  359. * @throws RestException
  360. *
  361. * @url PUT jobposition/{id}
  362. */
  363. public function putJobPosition($id, $request_data = null)
  364. {
  365. if (!DolibarrApiAccess::$user->rights->recruitment->recruitmentjobposition->write) {
  366. throw new RestException(401);
  367. }
  368. $result = $this->jobposition->fetch($id);
  369. if (!$result) {
  370. throw new RestException(404, 'jobposition not found');
  371. }
  372. if (!DolibarrApi::_checkAccessToResource('recruitment', $this->jobposition->id, 'recruitment_recruitmentjobposition')) {
  373. throw new RestException(401, 'Access to instance id='.$this->jobposition->id.' of object not allowed for login '.DolibarrApiAccess::$user->login);
  374. }
  375. foreach ($request_data as $field => $value) {
  376. if ($field == 'id') {
  377. continue;
  378. }
  379. $this->jobposition->$field = $this->_checkValForAPI($field, $value, $this->jobposition);
  380. }
  381. // Clean data
  382. // $this->jobposition->abc = sanitizeVal($this->jobposition->abc, 'alphanohtml');
  383. if ($this->jobposition->update(DolibarrApiAccess::$user, false) > 0) {
  384. return $this->get($id);
  385. } else {
  386. throw new RestException(500, $this->jobposition->error);
  387. }
  388. }
  389. /**
  390. * Update candidature
  391. *
  392. * @param int $id Id of candidature to update
  393. * @param array $request_data Datas
  394. * @return int
  395. *
  396. * @throws RestException
  397. *
  398. * @url PUT candidature/{id}
  399. */
  400. public function putCandidature($id, $request_data = null)
  401. {
  402. if (!DolibarrApiAccess::$user->rights->recruitment->recruitmentjobposition->write) {
  403. throw new RestException(401);
  404. }
  405. $result = $this->candidature->fetch($id);
  406. if (!$result) {
  407. throw new RestException(404, 'candidature not found');
  408. }
  409. if (!DolibarrApi::_checkAccessToResource('recruitment', $this->candidature->id, 'recruitment_recruitmentcandidature')) {
  410. throw new RestException(401, 'Access to instance id='.$this->candidature->id.' of object not allowed for login '.DolibarrApiAccess::$user->login);
  411. }
  412. foreach ($request_data as $field => $value) {
  413. if ($field == 'id') {
  414. continue;
  415. }
  416. $this->candidature->$field = $this->_checkValForAPI($field, $value, $this->candidature);
  417. }
  418. // Clean data
  419. // $this->jobposition->abc = sanitizeVal($this->jobposition->abc, 'alphanohtml');
  420. if ($this->candidature->update(DolibarrApiAccess::$user, false) > 0) {
  421. return $this->get($id);
  422. } else {
  423. throw new RestException(500, $this->candidature->error);
  424. }
  425. }
  426. /**
  427. * Delete jobposition
  428. *
  429. * @param int $id jobposition ID
  430. * @return array
  431. *
  432. * @throws RestException
  433. *
  434. * @url DELETE jobposition/{id}
  435. */
  436. public function deleteJobPosition($id)
  437. {
  438. if (!DolibarrApiAccess::$user->rights->recruitment->recruitmentjobposition->delete) {
  439. throw new RestException(401);
  440. }
  441. $result = $this->jobposition->fetch($id);
  442. if (!$result) {
  443. throw new RestException(404, 'jobposition not found');
  444. }
  445. if (!DolibarrApi::_checkAccessToResource('recruitment', $this->jobposition->id, 'recruitment_recruitmentjobposition')) {
  446. throw new RestException(401, 'Access to instance id='.$this->jobposition->id.' of object not allowed for login '.DolibarrApiAccess::$user->login);
  447. }
  448. if (!$this->jobposition->delete(DolibarrApiAccess::$user)) {
  449. throw new RestException(500, 'Error when deleting jobposition : '.$this->jobposition->error);
  450. }
  451. return array(
  452. 'success' => array(
  453. 'code' => 200,
  454. 'message' => 'jobposition deleted'
  455. )
  456. );
  457. }
  458. /**
  459. * Delete candidature
  460. *
  461. * @param int $id candidature ID
  462. * @return array
  463. *
  464. * @throws RestException
  465. *
  466. * @url DELETE candidature/{id}
  467. */
  468. public function deleteCandidature($id)
  469. {
  470. if (!DolibarrApiAccess::$user->rights->recruitment->recruitmentjobposition->delete) {
  471. throw new RestException(401);
  472. }
  473. $result = $this->candidature->fetch($id);
  474. if (!$result) {
  475. throw new RestException(404, 'candidature not found');
  476. }
  477. if (!DolibarrApi::_checkAccessToResource('recruitment', $this->candidature->id, 'recruitment_recruitmentcandidature')) {
  478. throw new RestException(401, 'Access to instance id='.$this->candidature->id.' of object not allowed for login '.DolibarrApiAccess::$user->login);
  479. }
  480. if (!$this->candidature->delete(DolibarrApiAccess::$user)) {
  481. throw new RestException(500, 'Error when deleting candidature : '.$this->candidature->error);
  482. }
  483. return array(
  484. 'success' => array(
  485. 'code' => 200,
  486. 'message' => 'candidature deleted'
  487. )
  488. );
  489. }
  490. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  491. /**
  492. * Clean sensible object datas
  493. *
  494. * @param Object $object Object to clean
  495. * @return Object Object with cleaned properties
  496. */
  497. protected function _cleanObjectDatas($object)
  498. {
  499. // phpcs:enable
  500. $object = parent::_cleanObjectDatas($object);
  501. unset($object->rowid);
  502. unset($object->canvas);
  503. /*unset($object->name);
  504. unset($object->lastname);
  505. unset($object->firstname);
  506. unset($object->civility_id);
  507. unset($object->statut);
  508. unset($object->state);
  509. unset($object->state_id);
  510. unset($object->state_code);
  511. unset($object->region);
  512. unset($object->region_code);
  513. unset($object->country);
  514. unset($object->country_id);
  515. unset($object->country_code);
  516. unset($object->barcode_type);
  517. unset($object->barcode_type_code);
  518. unset($object->barcode_type_label);
  519. unset($object->barcode_type_coder);
  520. unset($object->total_ht);
  521. unset($object->total_tva);
  522. unset($object->total_localtax1);
  523. unset($object->total_localtax2);
  524. unset($object->total_ttc);
  525. unset($object->fk_account);
  526. unset($object->comments);
  527. unset($object->note);
  528. unset($object->mode_reglement_id);
  529. unset($object->cond_reglement_id);
  530. unset($object->cond_reglement);
  531. unset($object->shipping_method_id);
  532. unset($object->fk_incoterms);
  533. unset($object->label_incoterms);
  534. unset($object->location_incoterms);
  535. */
  536. // If object has lines, remove $db property
  537. if (isset($object->lines) && is_array($object->lines) && count($object->lines) > 0) {
  538. $nboflines = count($object->lines);
  539. for ($i = 0; $i < $nboflines; $i++) {
  540. $this->_cleanObjectDatas($object->lines[$i]);
  541. unset($object->lines[$i]->lines);
  542. unset($object->lines[$i]->note);
  543. }
  544. }
  545. return $object;
  546. }
  547. /**
  548. * Validate fields before create or update object
  549. *
  550. * @param array $data Array of data to validate
  551. * @return array
  552. *
  553. * @throws RestException
  554. */
  555. private function _validate($data)
  556. {
  557. $jobposition = array();
  558. foreach ($this->jobposition->fields as $field => $propfield) {
  559. if (in_array($field, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat')) || $propfield['notnull'] != 1) {
  560. continue; // Not a mandatory field
  561. }
  562. if (!isset($data[$field])) {
  563. throw new RestException(400, "$field field missing");
  564. }
  565. $jobposition[$field] = $data[$field];
  566. }
  567. return $jobposition;
  568. }
  569. }