dolibarr 20.0.5
api_categories.class.php
1<?php
2/* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
3 * Copyright (C) 2024 Jose MARTINEZ <jose.martinez@pichinov.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
19use Luracast\Restler\RestException;
20
21require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
22require_once DOL_DOCUMENT_ROOT.'/societe/class/client.class.php';
23require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
24
25require_once DOL_DOCUMENT_ROOT.'/adherents/class/api_members.class.php';
26require_once DOL_DOCUMENT_ROOT.'/product/class/api_products.class.php';
27require_once DOL_DOCUMENT_ROOT.'/societe/class/api_contacts.class.php';
28require_once DOL_DOCUMENT_ROOT.'/societe/class/api_thirdparties.class.php';
29require_once DOL_DOCUMENT_ROOT.'/projet/class/api_projects.class.php';
30
38{
42 public static $FIELDS = array(
43 'label',
44 'type'
45 );
46
47 public static $TYPES = array(
48 0 => 'product',
49 1 => 'supplier',
50 2 => 'customer',
51 3 => 'member',
52 4 => 'contact',
53 5 => 'account',
54 6 => 'project',
55 7 => 'user',
56 8 => 'bank_line',
57 9 => 'warehouse',
58 10 => 'actioncomm',
59 11 => 'website_page',
60 12 => 'ticket',
61 13 => 'knowledgemanagement'
62 );
63
67 public $category;
68
72 public function __construct()
73 {
74 global $db;
75
76 $this->db = $db;
77 $this->category = new Categorie($this->db);
78 }
79
91 public function get($id, $include_childs = false)
92 {
93 if (!DolibarrApiAccess::$user->hasRight('categorie', 'lire')) {
94 throw new RestException(403);
95 }
96
97 $result = $this->category->fetch($id);
98 if (!$result) {
99 throw new RestException(404, 'category not found');
100 }
101
102 if (!DolibarrApi::_checkAccessToResource('categorie', $this->category->id)) {
103 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
104 }
105
106 if ($include_childs) {
107 $cats = $this->category->get_filles();
108 if (!is_array($cats)) {
109 throw new RestException(500, 'Error when fetching child categories', array_merge(array($this->category->error), $this->category->errors));
110 }
111 $this->category->childs = array();
112 foreach ($cats as $cat) {
113 $this->category->childs[] = $this->_cleanObjectDatas($cat);
114 }
115 }
116
117 return $this->_cleanObjectDatas($this->category);
118 }
119
136 public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $type = '', $sqlfilters = '', $properties = '')
137 {
138 $obj_ret = array();
139
140 if (!DolibarrApiAccess::$user->hasRight('categorie', 'lire')) {
141 throw new RestException(403);
142 }
143
144 $sql = "SELECT t.rowid";
145 $sql .= " FROM ".MAIN_DB_PREFIX."categorie AS t LEFT JOIN ".MAIN_DB_PREFIX."categories_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
146 $sql .= ' WHERE t.entity IN ('.getEntity('category').')';
147 if (!empty($type)) {
148 $sql .= ' AND t.type='.array_search($type, Categories::$TYPES);
149 }
150 // Add sql filters
151 if ($sqlfilters) {
152 $errormessage = '';
153 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
154 if ($errormessage) {
155 throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
156 }
157 }
158
159 $sql .= $this->db->order($sortfield, $sortorder);
160 if ($limit) {
161 if ($page < 0) {
162 $page = 0;
163 }
164 $offset = $limit * $page;
165
166 $sql .= $this->db->plimit($limit + 1, $offset);
167 }
168
169 $result = $this->db->query($sql);
170 if ($result) {
171 $i = 0;
172 $num = $this->db->num_rows($result);
173 $min = min($num, ($limit <= 0 ? $num : $limit));
174 while ($i < $min) {
175 $obj = $this->db->fetch_object($result);
176 $category_static = new Categorie($this->db);
177 if ($category_static->fetch($obj->rowid)) {
178 $obj_ret[] = $this->_filterObjectProperties($this->_cleanObjectDatas($category_static), $properties);
179 }
180 $i++;
181 }
182 } else {
183 throw new RestException(503, 'Error when retrieve category list : '.$this->db->lasterror());
184 }
185
186 return $obj_ret;
187 }
188
195 public function post($request_data = null)
196 {
197 if (!DolibarrApiAccess::$user->hasRight('categorie', 'creer')) {
198 throw new RestException(403);
199 }
200
201 // Check mandatory fields (throw an exception if wrong)
202 $this->_validate($request_data);
203
204 foreach ($request_data as $field => $value) {
205 if ($field === 'caller') {
206 // 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 with the caller
207 $this->category->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
208 continue;
209 }
210
211 $this->category->$field = $this->_checkValForAPI($field, $value, $this->category);
212 }
213 if ($this->category->create(DolibarrApiAccess::$user) < 0) {
214 throw new RestException(500, 'Error when creating category', array_merge(array($this->category->error), $this->category->errors));
215 }
216 return $this->category->id;
217 }
218
226 public function put($id, $request_data = null)
227 {
228 if (!DolibarrApiAccess::$user->hasRight('categorie', 'creer')) {
229 throw new RestException(403);
230 }
231
232 $result = $this->category->fetch($id);
233 if (!$result) {
234 throw new RestException(404, 'category not found');
235 }
236
237 if (!DolibarrApi::_checkAccessToResource('categorie', $this->category->id)) {
238 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
239 }
240
241 foreach ($request_data as $field => $value) {
242 if ($field == 'id') {
243 continue;
244 }
245 if ($field === 'caller') {
246 // 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 with the caller
247 $this->category->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
248 continue;
249 }
250
251 if ($field == 'array_options' && is_array($value)) {
252 foreach ($value as $index => $val) {
253 $this->category->array_options[$index] = $this->_checkValForAPI($field, $val, $this->category);
254 }
255 continue;
256 }
257
258 $this->category->$field = $this->_checkValForAPI($field, $value, $this->category);
259 }
260
261 if ($this->category->update(DolibarrApiAccess::$user) > 0) {
262 return $this->get($id);
263 } else {
264 throw new RestException(500, $this->category->error);
265 }
266 }
267
274 public function delete($id)
275 {
276 if (!DolibarrApiAccess::$user->hasRight('categorie', 'supprimer')) {
277 throw new RestException(403);
278 }
279 $result = $this->category->fetch($id);
280 if (!$result) {
281 throw new RestException(404, 'category not found');
282 }
283
284 if (!DolibarrApi::_checkAccessToResource('categorie', $this->category->id)) {
285 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
286 }
287
288 if ($this->category->delete(DolibarrApiAccess::$user) <= 0) {
289 throw new RestException(500, 'Error when delete category : ' . $this->category->error);
290 }
291
292 return array(
293 'success' => array(
294 'code' => 200,
295 'message' => 'Category deleted'
296 )
297 );
298 }
299
317 public function getListForObject($id, $type, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0)
318 {
319 if (!in_array($type, [
320 Categorie::TYPE_PRODUCT,
321 Categorie::TYPE_CONTACT,
322 Categorie::TYPE_CUSTOMER,
323 Categorie::TYPE_SUPPLIER,
324 Categorie::TYPE_MEMBER,
325 Categorie::TYPE_PROJECT,
326 Categorie::TYPE_KNOWLEDGEMANAGEMENT,
327 Categorie::TYPE_ACTIONCOMM
328 ])) {
329 throw new RestException(403);
330 }
331
332 if ($type == Categorie::TYPE_PRODUCT && !DolibarrApiAccess::$user->hasRight('produit', 'lire') && !DolibarrApiAccess::$user->hasRight('service', 'lire')) {
333 throw new RestException(403);
334 } elseif ($type == Categorie::TYPE_CONTACT && !DolibarrApiAccess::$user->hasRight('contact', 'lire')) {
335 throw new RestException(403);
336 } elseif ($type == Categorie::TYPE_CUSTOMER && !DolibarrApiAccess::$user->hasRight('societe', 'lire')) {
337 throw new RestException(403);
338 } elseif ($type == Categorie::TYPE_SUPPLIER && !DolibarrApiAccess::$user->hasRight('fournisseur', 'lire')) {
339 throw new RestException(403);
340 } elseif ($type == Categorie::TYPE_MEMBER && !DolibarrApiAccess::$user->hasRight('adherent', 'lire')) {
341 throw new RestException(403);
342 } elseif ($type == Categorie::TYPE_PROJECT && !DolibarrApiAccess::$user->hasRight('projet', 'lire')) {
343 throw new RestException(403);
344 } elseif ($type == Categorie::TYPE_KNOWLEDGEMANAGEMENT && !DolibarrApiAccess::$user->hasRight('knowledgemanagement', 'knowledgerecord', 'read')) {
345 throw new RestException(403);
346 } elseif ($type == Categorie::TYPE_ACTIONCOMM && !DolibarrApiAccess::$user->hasRight('agenda', 'allactions', 'read')) {
347 throw new RestException(403);
348 }
349
350 $categories = $this->category->getListForItem($id, $type, $sortfield, $sortorder, $limit, $page);
351
352 if (!is_array($categories)) {
353 throw new RestException(600, 'Error when fetching object categories', array_merge(array($this->category->error), $this->category->errors));
354 }
355 return $categories;
356 }
357
370 public function linkObjectById($id, $type, $object_id)
371 {
372 if (empty($type) || empty($object_id)) {
373 throw new RestException(403);
374 }
375
376 if (!DolibarrApiAccess::$user->hasRight('categorie', 'lire')) {
377 throw new RestException(403);
378 }
379
380 $result = $this->category->fetch($id);
381 if (!$result) {
382 throw new RestException(404, 'category not found');
383 }
384
385 if ($type === Categorie::TYPE_PRODUCT) {
386 if (!DolibarrApiAccess::$user->hasRight('produit', 'creer') && !DolibarrApiAccess::$user->hasRight('service', 'creer')) {
387 throw new RestException(403);
388 }
389 $object = new Product($this->db);
390 } elseif ($type === Categorie::TYPE_CUSTOMER) {
391 if (!DolibarrApiAccess::$user->hasRight('societe', 'creer')) {
392 throw new RestException(403);
393 }
394 $object = new Societe($this->db);
395 } elseif ($type === Categorie::TYPE_SUPPLIER) {
396 if (!DolibarrApiAccess::$user->hasRight('societe', 'creer')) {
397 throw new RestException(403);
398 }
399 $object = new Societe($this->db);
400 } elseif ($type === Categorie::TYPE_CONTACT) {
401 if (!DolibarrApiAccess::$user->hasRight('societe', 'contact', 'creer')) {
402 throw new RestException(403);
403 }
404 $object = new Contact($this->db);
405 } elseif ($type === Categorie::TYPE_MEMBER) {
406 if (!DolibarrApiAccess::$user->hasRight('adherent', 'creer')) {
407 throw new RestException(403);
408 }
409 $object = new Adherent($this->db);
410 } elseif ($type === Categorie::TYPE_ACTIONCOMM) {
411 if (!DolibarrApiAccess::$user->hasRight('agenda', 'allactions', 'read')) {
412 throw new RestException(403);
413 }
414 $object = new ActionComm($this->db);
415 } else {
416 throw new RestException(400, "this type is not recognized yet.");
417 }
418
419 $result = $object->fetch($object_id);
420 if ($result > 0) {
421 $result = $this->category->add_type($object, $type);
422 if ($result < 0) {
423 if ($this->category->error != 'DB_ERROR_RECORD_ALREADY_EXISTS') {
424 throw new RestException(500, 'Error when linking object', array_merge(array($this->category->error), $this->category->errors));
425 }
426 }
427 } else {
428 throw new RestException(500, 'Error when fetching object', array_merge(array($object->error), $object->errors));
429 }
430
431 return array(
432 'success' => array(
433 'code' => 200,
434 'message' => 'Objects successfully linked to the category'
435 )
436 );
437 }
438
451 public function linkObjectByRef($id, $type, $object_ref)
452 {
453 if (empty($type) || empty($object_ref)) {
454 throw new RestException(403);
455 }
456
457 if (!DolibarrApiAccess::$user->hasRight('categorie', 'lire')) {
458 throw new RestException(403);
459 }
460
461 $result = $this->category->fetch($id);
462 if (!$result) {
463 throw new RestException(404, 'category not found');
464 }
465
466 if ($type === Categorie::TYPE_PRODUCT) {
467 if (!DolibarrApiAccess::$user->hasRight('produit', 'creer') && !DolibarrApiAccess::$user->hasRight('service', 'creer')) {
468 throw new RestException(403);
469 }
470 $object = new Product($this->db);
471 } elseif ($type === Categorie::TYPE_CUSTOMER) {
472 if (!DolibarrApiAccess::$user->hasRight('societe', 'creer')) {
473 throw new RestException(403);
474 }
475 $object = new Societe($this->db);
476 } elseif ($type === Categorie::TYPE_SUPPLIER) {
477 if (!DolibarrApiAccess::$user->hasRight('societe', 'creer')) {
478 throw new RestException(403);
479 }
480 $object = new Societe($this->db);
481 } elseif ($type === Categorie::TYPE_CONTACT) {
482 if (!DolibarrApiAccess::$user->hasRight('societe', 'contact', 'creer')) {
483 throw new RestException(403);
484 }
485 $object = new Contact($this->db);
486 } elseif ($type === Categorie::TYPE_MEMBER) {
487 if (!DolibarrApiAccess::$user->hasRight('adherent', 'creer')) {
488 throw new RestException(403);
489 }
490 $object = new Adherent($this->db);
491 } elseif ($type === Categorie::TYPE_ACTIONCOMM) {
492 if (!DolibarrApiAccess::$user->hasRight('agenda', 'allactions', 'read')) {
493 throw new RestException(403);
494 }
495 $object = new ActionComm($this->db);
496 } else {
497 throw new RestException(400, "this type is not recognized yet.");
498 }
499
500 $result = $object->fetch(0, $object_ref);
501 if ($result > 0) {
502 $result = $this->category->add_type($object, $type);
503 if ($result < 0) {
504 if ($this->category->error != 'DB_ERROR_RECORD_ALREADY_EXISTS') {
505 throw new RestException(500, 'Error when linking object', array_merge(array($this->category->error), $this->category->errors));
506 }
507 }
508 } else {
509 throw new RestException(500, 'Error when fetching object', array_merge(array($object->error), $object->errors));
510 }
511
512 return array(
513 'success' => array(
514 'code' => 200,
515 'message' => 'Objects successfully linked to the category'
516 )
517 );
518 }
519
532 public function unlinkObjectById($id, $type, $object_id)
533 {
534 if (empty($type) || empty($object_id)) {
535 throw new RestException(403);
536 }
537
538 if (!DolibarrApiAccess::$user->hasRight('categorie', 'lire')) {
539 throw new RestException(403);
540 }
541
542 $result = $this->category->fetch($id);
543 if (!$result) {
544 throw new RestException(404, 'category not found');
545 }
546
547 if ($type === Categorie::TYPE_PRODUCT) {
548 if (!DolibarrApiAccess::$user->hasRight('produit', 'creer') && !DolibarrApiAccess::$user->hasRight('service', 'creer')) {
549 throw new RestException(403);
550 }
551 $object = new Product($this->db);
552 } elseif ($type === Categorie::TYPE_CUSTOMER) {
553 if (!DolibarrApiAccess::$user->hasRight('societe', 'creer')) {
554 throw new RestException(403);
555 }
556 $object = new Societe($this->db);
557 } elseif ($type === Categorie::TYPE_SUPPLIER) {
558 if (!DolibarrApiAccess::$user->hasRight('societe', 'creer')) {
559 throw new RestException(403);
560 }
561 $object = new Societe($this->db);
562 } elseif ($type === Categorie::TYPE_CONTACT) {
563 if (!DolibarrApiAccess::$user->hasRight('societe', 'contact', 'creer')) {
564 throw new RestException(403);
565 }
566 $object = new Contact($this->db);
567 } elseif ($type === Categorie::TYPE_MEMBER) {
568 if (!DolibarrApiAccess::$user->hasRight('adherent', 'creer')) {
569 throw new RestException(403);
570 }
571 $object = new Adherent($this->db);
572 } elseif ($type === Categorie::TYPE_ACTIONCOMM) {
573 if (!DolibarrApiAccess::$user->hasRight('agenda', 'allactions', 'read')) {
574 throw new RestException(403);
575 }
576 $object = new ActionComm($this->db);
577 } else {
578 throw new RestException(400, "this type is not recognized yet.");
579 }
580
581 $result = $object->fetch((int) $object_id);
582 if ($result > 0) {
583 $result = $this->category->del_type($object, $type);
584 if ($result < 0) {
585 throw new RestException(500, 'Error when unlinking object', array_merge(array($this->category->error), $this->category->errors));
586 }
587 } else {
588 throw new RestException(500, 'Error when fetching object', array_merge(array($object->error), $object->errors));
589 }
590
591 return array(
592 'success' => array(
593 'code' => 200,
594 'message' => 'Objects successfully unlinked from the category'
595 )
596 );
597 }
598
611 public function unlinkObjectByRef($id, $type, $object_ref)
612 {
613 if (empty($type) || empty($object_ref)) {
614 throw new RestException(403);
615 }
616
617 if (!DolibarrApiAccess::$user->hasRight('categorie', 'lire')) {
618 throw new RestException(403);
619 }
620
621 $result = $this->category->fetch($id);
622 if (!$result) {
623 throw new RestException(404, 'category not found');
624 }
625
626 if ($type === Categorie::TYPE_PRODUCT) {
627 if (!DolibarrApiAccess::$user->hasRight('produit', 'creer') && !DolibarrApiAccess::$user->hasRight('service', 'creer')) {
628 throw new RestException(403);
629 }
630 $object = new Product($this->db);
631 } elseif ($type === Categorie::TYPE_CUSTOMER) {
632 if (!DolibarrApiAccess::$user->hasRight('societe', 'creer')) {
633 throw new RestException(403);
634 }
635 $object = new Societe($this->db);
636 } elseif ($type === Categorie::TYPE_SUPPLIER) {
637 if (!DolibarrApiAccess::$user->hasRight('societe', 'creer')) {
638 throw new RestException(403);
639 }
640 $object = new Societe($this->db);
641 } elseif ($type === Categorie::TYPE_CONTACT) {
642 if (!DolibarrApiAccess::$user->hasRight('societe', 'contact', 'creer')) {
643 throw new RestException(403);
644 }
645 $object = new Contact($this->db);
646 } elseif ($type === Categorie::TYPE_MEMBER) {
647 if (!DolibarrApiAccess::$user->hasRight('adherent', 'creer')) {
648 throw new RestException(403);
649 }
650 $object = new Adherent($this->db);
651 } elseif ($type === Categorie::TYPE_ACTIONCOMM) {
652 if (!DolibarrApiAccess::$user->hasRight('agenda', 'allactions', 'read')) {
653 throw new RestException(403);
654 }
655 $object = new ActionComm($this->db);
656 } else {
657 throw new RestException(400, "this type is not recognized yet.");
658 }
659
660 $result = $object->fetch(0, (string) $object_ref);
661 if ($result > 0) {
662 $result = $this->category->del_type($object, $type);
663 if ($result < 0) {
664 throw new RestException(500, 'Error when unlinking object', array_merge(array($this->category->error), $this->category->errors));
665 }
666 } else {
667 throw new RestException(500, 'Error when fetching object', array_merge(array($object->error), $object->errors));
668 }
669
670 return array(
671 'success' => array(
672 'code' => 200,
673 'message' => 'Objects successfully unlinked from the category'
674 )
675 );
676 }
677
678
679 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
686 protected function _cleanObjectDatas($object)
687 {
688 // phpcs:enable
689 $object = parent::_cleanObjectDatas($object);
690
691 // Remove fields not relevant to categories
692 unset($object->MAP_CAT_FK);
693 unset($object->MAP_CAT_TABLE);
694 unset($object->MAP_OBJ_CLASS);
695 unset($object->MAP_OBJ_TABLE);
696 unset($object->country);
697 unset($object->country_id);
698 unset($object->country_code);
699 unset($object->total_ht);
700 unset($object->total_ht);
701 unset($object->total_localtax1);
702 unset($object->total_localtax2);
703 unset($object->total_ttc);
704 unset($object->total_tva);
705 unset($object->lines);
706 unset($object->civility_id);
707 unset($object->name);
708 unset($object->lastname);
709 unset($object->firstname);
710 unset($object->shipping_method_id);
711 unset($object->fk_delivery_address);
712 unset($object->cond_reglement);
713 unset($object->cond_reglement_id);
714 unset($object->mode_reglement_id);
715 unset($object->barcode_type_coder);
716 unset($object->barcode_type_label);
717 unset($object->barcode_type_code);
718 unset($object->barcode_type);
719 unset($object->canvas);
720 unset($object->cats);
721 unset($object->motherof);
722 unset($object->context);
723 unset($object->socid);
724 unset($object->thirdparty);
725 unset($object->contact);
726 unset($object->contact_id);
727 unset($object->user);
728 unset($object->fk_account);
729 unset($object->fk_project);
730 unset($object->note);
731 unset($object->statut);
732
733 return $object;
734 }
735
744 private function _validate($data)
745 {
746 $category = array();
747 foreach (Categories::$FIELDS as $field) {
748 if (!isset($data[$field])) {
749 throw new RestException(400, "$field field missing");
750 }
751 $category[$field] = $data[$field];
752 }
753 return $category;
754 }
755
767 public function getObjects($id, $type, $onlyids = 0)
768 {
769 dol_syslog("getObjects($id, $type, $onlyids)", LOG_DEBUG);
770
771 if (!DolibarrApiAccess::$user->hasRight('categorie', 'lire')) {
772 throw new RestException(403);
773 }
774
775 if (empty($type)) {
776 throw new RestException(500, 'The "type" parameter is required.');
777 }
778
779 $result = $this->category->fetch($id);
780 if (!$result) {
781 throw new RestException(404, 'category not found');
782 }
783
784 if (!DolibarrApi::_checkAccessToResource('categorie', $this->category->id)) {
785 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
786 }
787
788 $result = $this->category->getObjectsInCateg($type, $onlyids);
789
790 if ($result < 0) {
791 throw new RestException(503, 'Error when retrieving objects list : '.$this->category->error);
792 }
793
794 $objects = $result;
795 $cleaned_objects = array();
796 $objects_api = null;
797 if ($type == 'member') {
798 $objects_api = new Members();
799 } elseif ($type == 'customer' || $type == 'supplier') {
800 $objects_api = new Thirdparties();
801 } elseif ($type == 'product') {
802 $objects_api = new Products();
803 } elseif ($type == 'contact') {
804 $objects_api = new Contacts();
805 } elseif ($type == 'project') {
806 $objects_api = new Projects();
807 }
808
809 if (is_object($objects_api)) {
810 foreach ($objects as $obj) {
811 $cleaned_objects[] = $objects_api->_cleanObjectDatas($obj);
812 }
813 }
814
815 return $cleaned_objects;
816 }
817}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
Class to manage agenda events (actions)
Class to manage members of a foundation.
Class to manage categories.
__construct()
Constructor.
put($id, $request_data=null)
Update category.
unlinkObjectById($id, $type, $object_id)
Unlink an object from a category by id.
unlinkObjectByRef($id, $type, $object_ref)
Unlink an object from a category by ref.
_validate($data)
Validate fields before create or update object.
post($request_data=null)
Create category object.
_cleanObjectDatas($object)
Clean sensible object datas.
getObjects($id, $type, $onlyids=0)
Get the list of objects in a category.
getListForObject($id, $type, $sortfield="s.rowid", $sortorder='ASC', $limit=0, $page=0)
List categories of an object.
linkObjectById($id, $type, $object_id)
Link an object to a category by id.
linkObjectByRef($id, $type, $object_ref)
Link an object to a category by ref.
index($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $type='', $sqlfilters='', $properties='')
List categories.
Class to manage contact/addresses.
Class for API REST v1.
Definition api.class.php:30
_filterObjectProperties($object, $properties)
Filter properties that will be returned on object.
static _checkAccessToResource($resource, $resource_id=0, $dbtablename='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid')
Check access by user to a given resource.
_checkValForAPI($field, $value, $object)
Check and convert a string depending on its type/name.
Definition api.class.php:82
Class to manage products or services.
Class to manage third parties objects (customers, suppliers, prospects...)
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
sanitizeVal($out='', $check='alphanohtml', $filter=null, $options=null)
Return a sanitized or empty value after checking value against a rule.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.