api_recruitments.class.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  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 Recruitments 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 Object Object with cleaned properties
  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->hasRight('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 Object Object with cleaned properties
  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->hasRight('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. * @param string $properties Restrict the data returned to theses properties. Ignored if empty. Comma separated list of properties names
  119. * @return array Array of order objects
  120. *
  121. * @throws RestException
  122. *
  123. * @url GET /jobposition/
  124. */
  125. public function indexJobPosition($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $sqlfilters = '', $properties = '')
  126. {
  127. global $db, $conf;
  128. $obj_ret = array();
  129. $tmpobject = new RecruitmentJobPosition($this->db);
  130. if (!DolibarrApiAccess::$user->hasRight('recruitment', 'recruitmentjobposition', 'read')) {
  131. throw new RestException(401);
  132. }
  133. $socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : '';
  134. $restrictonsocid = 0; // Set to 1 if there is a field socid in table of object
  135. // If the internal user must only see his customers, force searching by him
  136. $search_sale = 0;
  137. if ($restrictonsocid && !DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) {
  138. $search_sale = DolibarrApiAccess::$user->id;
  139. }
  140. $sql = "SELECT t.rowid";
  141. if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
  142. $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)
  143. }
  144. $sql .= " FROM ".MAIN_DB_PREFIX.$tmpobject->table_element." AS t LEFT JOIN ".MAIN_DB_PREFIX.$tmpobject->table_element."_extrafields AS ef ON (ef.fk_object = t.rowid)"; // Modification VMR Global Solutions to include extrafields as search parameters in the API GET call, so we will be able to filter on extrafields
  145. if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
  146. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
  147. }
  148. $sql .= " WHERE 1 = 1";
  149. // Example of use $mode
  150. //if ($mode == 1) $sql.= " AND s.client IN (1, 3)";
  151. //if ($mode == 2) $sql.= " AND s.client IN (2, 3)";
  152. if ($tmpobject->ismultientitymanaged) {
  153. $sql .= ' AND t.entity IN ('.getEntity($tmpobject->element).')';
  154. }
  155. if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
  156. $sql .= " AND t.fk_soc = sc.fk_soc";
  157. }
  158. if ($restrictonsocid && $socid) {
  159. $sql .= " AND t.fk_soc = ".((int) $socid);
  160. }
  161. if ($restrictonsocid && $search_sale > 0) {
  162. $sql .= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
  163. }
  164. // Insert sale filter
  165. if ($restrictonsocid && $search_sale > 0) {
  166. $sql .= " AND sc.fk_user = ".((int) $search_sale);
  167. }
  168. if ($sqlfilters) {
  169. $errormessage = '';
  170. $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
  171. if ($errormessage) {
  172. throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
  173. }
  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->_filterObjectProperties($this->_cleanObjectDatas($tmp_object), $properties);
  192. }
  193. $i++;
  194. }
  195. } else {
  196. throw new RestException(503, 'Error when retrieving jobposition list: '.$this->db->lasterror());
  197. }
  198. return $obj_ret;
  199. }
  200. /**
  201. * List candatures
  202. *
  203. * Get a list of candidatures
  204. *
  205. * @param string $sortfield Sort field
  206. * @param string $sortorder Sort order
  207. * @param int $limit Limit for list
  208. * @param int $page Page number
  209. * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')"
  210. * @return array Array of order objects
  211. *
  212. * @throws RestException
  213. *
  214. * @url GET /candidature/
  215. */
  216. public function indexCandidature($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $sqlfilters = '')
  217. {
  218. global $db, $conf;
  219. $obj_ret = array();
  220. $tmpobject = new RecruitmentCandidature($this->db);
  221. if (!DolibarrApiAccess::$user->hasRight('recruitment', 'recruitmentjobposition', 'read')) {
  222. throw new RestException(401);
  223. }
  224. $socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : '';
  225. $restrictonsocid = 0; // Set to 1 if there is a field socid in table of object
  226. // If the internal user must only see his customers, force searching by him
  227. $search_sale = 0;
  228. if ($restrictonsocid && !DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) {
  229. $search_sale = DolibarrApiAccess::$user->id;
  230. }
  231. $sql = "SELECT t.rowid";
  232. if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
  233. $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)
  234. }
  235. $sql .= " FROM ".MAIN_DB_PREFIX.$tmpobject->table_element." AS t LEFT JOIN ".MAIN_DB_PREFIX.$tmpobject->table_element."_extrafields AS ef ON (ef.fk_object = t.rowid)"; // Modification VMR Global Solutions to include extrafields as search parameters in the API GET call, so we will be able to filter on extrafields
  236. if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
  237. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
  238. }
  239. $sql .= " WHERE 1 = 1";
  240. // Example of use $mode
  241. //if ($mode == 1) $sql.= " AND s.client IN (1, 3)";
  242. //if ($mode == 2) $sql.= " AND s.client IN (2, 3)";
  243. if ($tmpobject->ismultientitymanaged) {
  244. $sql .= ' AND t.entity IN ('.getEntity($tmpobject->element).')';
  245. }
  246. if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
  247. $sql .= " AND t.fk_soc = sc.fk_soc";
  248. }
  249. if ($restrictonsocid && $socid) {
  250. $sql .= " AND t.fk_soc = ".((int) $socid);
  251. }
  252. if ($restrictonsocid && $search_sale > 0) {
  253. $sql .= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
  254. }
  255. // Insert sale filter
  256. if ($restrictonsocid && $search_sale > 0) {
  257. $sql .= " AND sc.fk_user = ".((int) $search_sale);
  258. }
  259. if ($sqlfilters) {
  260. $errormessage = '';
  261. $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
  262. if ($errormessage) {
  263. throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
  264. }
  265. }
  266. $sql .= $this->db->order($sortfield, $sortorder);
  267. if ($limit) {
  268. if ($page < 0) {
  269. $page = 0;
  270. }
  271. $offset = $limit * $page;
  272. $sql .= $this->db->plimit($limit + 1, $offset);
  273. }
  274. $result = $this->db->query($sql);
  275. $i = 0;
  276. if ($result) {
  277. $num = $this->db->num_rows($result);
  278. while ($i < $num) {
  279. $obj = $this->db->fetch_object($result);
  280. $tmp_object = new RecruitmentCandidature($this->db);
  281. if ($tmp_object->fetch($obj->rowid)) {
  282. $obj_ret[] = $this->_cleanObjectDatas($tmp_object);
  283. }
  284. $i++;
  285. }
  286. } else {
  287. throw new RestException(503, 'Error when retrieving candidature list: '.$this->db->lasterror());
  288. }
  289. return $obj_ret;
  290. }
  291. /**
  292. * Create jobposition object
  293. *
  294. * @param array $request_data Request datas
  295. * @return int ID of jobposition
  296. *
  297. * @throws RestException
  298. *
  299. * @url POST jobposition/
  300. */
  301. public function postJobPosition($request_data = null)
  302. {
  303. if (!DolibarrApiAccess::$user->hasRight('recruitment', 'recruitmentjobposition', 'write')) {
  304. throw new RestException(401);
  305. }
  306. // Check mandatory fields
  307. $result = $this->_validate($request_data);
  308. foreach ($request_data as $field => $value) {
  309. if ($field === 'caller') {
  310. // Add a mention of caller so on trigger called after action, we can filter to avoid a loop if we try to sync back again whith the caller
  311. $this->jobposition->context['caller'] = $request_data['caller'];
  312. continue;
  313. }
  314. $this->jobposition->$field = $this->_checkValForAPI($field, $value, $this->jobposition);
  315. }
  316. // Clean data
  317. // $this->jobposition->abc = sanitizeVal($this->jobposition->abc, 'alphanohtml');
  318. if ($this->jobposition->create(DolibarrApiAccess::$user)<0) {
  319. throw new RestException(500, "Error creating jobposition", array_merge(array($this->jobposition->error), $this->jobposition->errors));
  320. }
  321. return $this->jobposition->id;
  322. }
  323. /**
  324. * Create candidature object
  325. *
  326. * @param array $request_data Request datas
  327. * @return int ID of candidature
  328. *
  329. * @throws RestException
  330. *
  331. * @url POST candidature/
  332. */
  333. public function postCandidature($request_data = null)
  334. {
  335. if (!DolibarrApiAccess::$user->hasRight('recruitment', 'recruitmentjobposition', 'write')) {
  336. throw new RestException(401);
  337. }
  338. // Check mandatory fields
  339. $result = $this->_validate($request_data);
  340. foreach ($request_data as $field => $value) {
  341. if ($field === 'caller') {
  342. // Add a mention of caller so on trigger called after action, we can filter to avoid a loop if we try to sync back again whith the caller
  343. $this->jobposition->context['caller'] = $request_data['caller'];
  344. continue;
  345. }
  346. $this->jobposition->$field = $this->_checkValForAPI($field, $value, $this->jobposition);
  347. }
  348. // Clean data
  349. // $this->jobposition->abc = sanitizeVal($this->jobposition->abc, 'alphanohtml');
  350. if ($this->candidature->create(DolibarrApiAccess::$user)<0) {
  351. throw new RestException(500, "Error creating candidature", array_merge(array($this->candidature->error), $this->candidature->errors));
  352. }
  353. return $this->candidature->id;
  354. }
  355. /**
  356. * Update jobposition
  357. *
  358. * @param int $id Id of jobposition to update
  359. * @param array $request_data Datas
  360. * @return Object Object with cleaned properties
  361. *
  362. * @throws RestException
  363. *
  364. * @url PUT jobposition/{id}
  365. */
  366. public function putJobPosition($id, $request_data = null)
  367. {
  368. if (!DolibarrApiAccess::$user->hasRight('recruitment', 'recruitmentjobposition', 'write')) {
  369. throw new RestException(401);
  370. }
  371. $result = $this->jobposition->fetch($id);
  372. if (!$result) {
  373. throw new RestException(404, 'jobposition not found');
  374. }
  375. if (!DolibarrApi::_checkAccessToResource('recruitment', $this->jobposition->id, 'recruitment_recruitmentjobposition')) {
  376. throw new RestException(401, 'Access to instance id='.$this->jobposition->id.' of object not allowed for login '.DolibarrApiAccess::$user->login);
  377. }
  378. foreach ($request_data as $field => $value) {
  379. if ($field == 'id') {
  380. continue;
  381. }
  382. if ($field === 'caller') {
  383. // Add a mention of caller so on trigger called after action, we can filter to avoid a loop if we try to sync back again whith the caller
  384. $this->jobposition->context['caller'] = $request_data['caller'];
  385. continue;
  386. }
  387. $this->jobposition->$field = $this->_checkValForAPI($field, $value, $this->jobposition);
  388. }
  389. // Clean data
  390. // $this->jobposition->abc = sanitizeVal($this->jobposition->abc, 'alphanohtml');
  391. if ($this->jobposition->update(DolibarrApiAccess::$user, false) > 0) {
  392. return $this->getJobPosition($id);
  393. } else {
  394. throw new RestException(500, $this->jobposition->error);
  395. }
  396. }
  397. /**
  398. * Update candidature
  399. *
  400. * @param int $id Id of candidature to update
  401. * @param array $request_data Datas
  402. * @return Object Object with cleaned properties
  403. *
  404. * @throws RestException
  405. *
  406. * @url PUT candidature/{id}
  407. */
  408. public function putCandidature($id, $request_data = null)
  409. {
  410. if (!DolibarrApiAccess::$user->hasRight('recruitment', 'recruitmentjobposition', 'write')) {
  411. throw new RestException(401);
  412. }
  413. $result = $this->candidature->fetch($id);
  414. if (!$result) {
  415. throw new RestException(404, 'candidature not found');
  416. }
  417. if (!DolibarrApi::_checkAccessToResource('recruitment', $this->candidature->id, 'recruitment_recruitmentcandidature')) {
  418. throw new RestException(401, 'Access to instance id='.$this->candidature->id.' of object not allowed for login '.DolibarrApiAccess::$user->login);
  419. }
  420. foreach ($request_data as $field => $value) {
  421. if ($field == 'id') {
  422. continue;
  423. }
  424. if ($field === 'caller') {
  425. // Add a mention of caller so on trigger called after action, we can filter to avoid a loop if we try to sync back again whith the caller
  426. $this->candidature->context['caller'] = $request_data['caller'];
  427. continue;
  428. }
  429. $this->candidature->$field = $this->_checkValForAPI($field, $value, $this->candidature);
  430. }
  431. // Clean data
  432. // $this->jobposition->abc = sanitizeVal($this->jobposition->abc, 'alphanohtml');
  433. if ($this->candidature->update(DolibarrApiAccess::$user, false) > 0) {
  434. return $this->getCandidature($id);
  435. } else {
  436. throw new RestException(500, $this->candidature->error);
  437. }
  438. }
  439. /**
  440. * Delete jobposition
  441. *
  442. * @param int $id jobposition ID
  443. * @return array
  444. *
  445. * @throws RestException
  446. *
  447. * @url DELETE jobposition/{id}
  448. */
  449. public function deleteJobPosition($id)
  450. {
  451. if (!DolibarrApiAccess::$user->hasRight('recruitment', 'recruitmentjobposition', 'delete')) {
  452. throw new RestException(401);
  453. }
  454. $result = $this->jobposition->fetch($id);
  455. if (!$result) {
  456. throw new RestException(404, 'jobposition not found');
  457. }
  458. if (!DolibarrApi::_checkAccessToResource('recruitment', $this->jobposition->id, 'recruitment_recruitmentjobposition')) {
  459. throw new RestException(401, 'Access to instance id='.$this->jobposition->id.' of object not allowed for login '.DolibarrApiAccess::$user->login);
  460. }
  461. if (!$this->jobposition->delete(DolibarrApiAccess::$user)) {
  462. throw new RestException(500, 'Error when deleting jobposition : '.$this->jobposition->error);
  463. }
  464. return array(
  465. 'success' => array(
  466. 'code' => 200,
  467. 'message' => 'jobposition deleted'
  468. )
  469. );
  470. }
  471. /**
  472. * Delete candidature
  473. *
  474. * @param int $id candidature ID
  475. * @return array
  476. *
  477. * @throws RestException
  478. *
  479. * @url DELETE candidature/{id}
  480. */
  481. public function deleteCandidature($id)
  482. {
  483. if (!DolibarrApiAccess::$user->hasRight('recruitment', 'recruitmentjobposition', 'delete')) {
  484. throw new RestException(401);
  485. }
  486. $result = $this->candidature->fetch($id);
  487. if (!$result) {
  488. throw new RestException(404, 'candidature not found');
  489. }
  490. if (!DolibarrApi::_checkAccessToResource('recruitment', $this->candidature->id, 'recruitment_recruitmentcandidature')) {
  491. throw new RestException(401, 'Access to instance id='.$this->candidature->id.' of object not allowed for login '.DolibarrApiAccess::$user->login);
  492. }
  493. if (!$this->candidature->delete(DolibarrApiAccess::$user)) {
  494. throw new RestException(500, 'Error when deleting candidature : '.$this->candidature->error);
  495. }
  496. return array(
  497. 'success' => array(
  498. 'code' => 200,
  499. 'message' => 'candidature deleted'
  500. )
  501. );
  502. }
  503. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  504. /**
  505. * Clean sensible object datas
  506. *
  507. * @param Object $object Object to clean
  508. * @return Object Object with cleaned properties
  509. */
  510. protected function _cleanObjectDatas($object)
  511. {
  512. // phpcs:enable
  513. $object = parent::_cleanObjectDatas($object);
  514. unset($object->rowid);
  515. unset($object->canvas);
  516. /*unset($object->name);
  517. unset($object->lastname);
  518. unset($object->firstname);
  519. unset($object->civility_id);
  520. unset($object->statut);
  521. unset($object->state);
  522. unset($object->state_id);
  523. unset($object->state_code);
  524. unset($object->region);
  525. unset($object->region_code);
  526. unset($object->country);
  527. unset($object->country_id);
  528. unset($object->country_code);
  529. unset($object->barcode_type);
  530. unset($object->barcode_type_code);
  531. unset($object->barcode_type_label);
  532. unset($object->barcode_type_coder);
  533. unset($object->total_ht);
  534. unset($object->total_tva);
  535. unset($object->total_localtax1);
  536. unset($object->total_localtax2);
  537. unset($object->total_ttc);
  538. unset($object->fk_account);
  539. unset($object->comments);
  540. unset($object->note);
  541. unset($object->mode_reglement_id);
  542. unset($object->cond_reglement_id);
  543. unset($object->cond_reglement);
  544. unset($object->shipping_method_id);
  545. unset($object->fk_incoterms);
  546. unset($object->label_incoterms);
  547. unset($object->location_incoterms);
  548. */
  549. // If object has lines, remove $db property
  550. if (isset($object->lines) && is_array($object->lines) && count($object->lines) > 0) {
  551. $nboflines = count($object->lines);
  552. for ($i = 0; $i < $nboflines; $i++) {
  553. $this->_cleanObjectDatas($object->lines[$i]);
  554. unset($object->lines[$i]->lines);
  555. unset($object->lines[$i]->note);
  556. }
  557. }
  558. return $object;
  559. }
  560. /**
  561. * Validate fields before create or update object
  562. *
  563. * @param array $data Array of data to validate
  564. * @return array
  565. *
  566. * @throws RestException
  567. */
  568. private function _validate($data)
  569. {
  570. $jobposition = array();
  571. foreach ($this->jobposition->fields as $field => $propfield) {
  572. if (in_array($field, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat')) || $propfield['notnull'] != 1) {
  573. continue; // Not a mandatory field
  574. }
  575. if (!isset($data[$field])) {
  576. throw new RestException(400, "$field field missing");
  577. }
  578. $jobposition[$field] = $data[$field];
  579. }
  580. return $jobposition;
  581. }
  582. }