dolibarr 22.0.5
api_members.class.php
1<?php
2/* Copyright (C) 2016 Xebax Christy <xebax@wanadoo.fr>
3 * Copyright (C) 2017 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2020 Thibault FOUCART <support@ptibogxiv.net>
5 * Copyright (C) 2020-2024 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22use Luracast\Restler\RestException;
23
24require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
25require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
26require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
27require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
28require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
29
30
37class Members extends DolibarrApi
38{
42 public static $FIELDS = array(
43 'morphy',
44 'typeid'
45 );
46
50 public function __construct()
51 {
52 global $db;
53 $this->db = $db;
54 }
55
67 public function get($id)
68 {
69 if (!DolibarrApiAccess::$user->hasRight('adherent', 'lire')) {
70 throw new RestException(403);
71 }
72
73 $member = new Adherent($this->db);
74 if ($id == 0) {
75 $result = $member->initAsSpecimen();
76 } else {
77 $result = $member->fetch($id);
78 }
79 if (!$result) {
80 throw new RestException(404, 'member not found');
81 }
82
83 if (!DolibarrApi::_checkAccessToResource('adherent', $member->id) && $id > 0) {
84 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
85 }
86
87 return $this->_cleanObjectDatas($member);
88 }
89
104 public function getByThirdparty($thirdparty)
105 {
106 if (!DolibarrApiAccess::$user->hasRight('adherent', 'lire')) {
107 throw new RestException(403);
108 }
109
110 $member = new Adherent($this->db);
111 $result = $member->fetch(0, '', $thirdparty);
112 if (!$result) {
113 throw new RestException(404, 'member not found');
114 }
115
116 if (!DolibarrApi::_checkAccessToResource('adherent', $member->id)) {
117 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
118 }
119
120 return $this->_cleanObjectDatas($member);
121 }
122
135 public function getByThirdpartyAccounts($site, $key_account)
136 {
137 if (!DolibarrApiAccess::$user->hasRight('societe', 'lire')) {
138 throw new RestException(403);
139 }
140
141 $sql = "SELECT rowid, fk_soc, key_account, site, date_creation, tms FROM ".MAIN_DB_PREFIX."societe_account";
142 $sql .= " WHERE site = '".$this->db->escape($site)."' AND key_account = '".$this->db->escape($key_account)."'";
143 $sql .= " AND entity IN (".getEntity('adherent').")";
144
145 $result = $this->db->query($sql);
146
147 if ($result && $this->db->num_rows($result) == 1) {
148 $obj = $this->db->fetch_object($result);
149 $thirdparty = new Societe($this->db);
150 $result = $thirdparty->fetch($obj->fk_soc);
151
152 if ($result <= 0) {
153 throw new RestException(404, 'thirdparty not found');
154 }
155
156 $member = new Adherent($this->db);
157 $result = $member->fetch(0, '', $thirdparty->id);
158 if (!$result) {
159 throw new RestException(404, 'member not found');
160 }
161 } else {
162 throw new RestException(404, 'This account have many thirdparties attached or does not exist.');
163 }
164
165 if (!DolibarrApi::_checkAccessToResource('adherent', $member->id)) {
166 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
167 }
168
169 return $this->_cleanObjectDatas($member);
170 }
171
186 public function getByThirdpartyEmail($email)
187 {
188 if (!DolibarrApiAccess::$user->hasRight('adherent', 'lire')) {
189 throw new RestException(403);
190 }
191
192 $thirdparty = new Societe($this->db);
193 $result = $thirdparty->fetch(0, '', '', '', '', '', '', '', '', '', $email);
194 if (!$result) {
195 throw new RestException(404, 'thirdparty not found');
196 }
197
198 $member = new Adherent($this->db);
199 $result = $member->fetch(0, '', $thirdparty->id);
200 if (!$result) {
201 throw new RestException(404, 'member not found');
202 }
203
204 if (!DolibarrApi::_checkAccessToResource('adherent', $member->id)) {
205 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
206 }
207
208 return $this->_cleanObjectDatas($member);
209 }
210
225 public function getByThirdpartyBarcode($barcode)
226 {
227 if (!DolibarrApiAccess::$user->hasRight('adherent', 'lire')) {
228 throw new RestException(403);
229 }
230
231 $thirdparty = new Societe($this->db);
232 $result = $thirdparty->fetch(0, '', '', $barcode);
233 if (!$result) {
234 throw new RestException(404, 'thirdparty not found');
235 }
236
237 $member = new Adherent($this->db);
238 $result = $member->fetch(0, '', $thirdparty->id);
239 if (!$result) {
240 throw new RestException(404, 'member not found');
241 }
242
243 if (!DolibarrApi::_checkAccessToResource('adherent', $member->id)) {
244 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
245 }
246
247 return $this->_cleanObjectDatas($member);
248 }
249
274 public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $typeid = '', $category = 0, $sqlfilters = '', $properties = '', $pagination_data = false)
275 {
276 $obj_ret = array();
277
278 if (!DolibarrApiAccess::$user->hasRight('adherent', 'lire')) {
279 throw new RestException(403);
280 }
281
282 $sql = "SELECT t.rowid";
283 $sql .= " FROM ".MAIN_DB_PREFIX."adherent AS t LEFT JOIN ".MAIN_DB_PREFIX."adherent_extrafields AS ef ON (ef.fk_object = t.rowid)"; // Modification VMR Global Solutions to include extrafields as search parameters in the API GET call
284 if ($category > 0) {
285 $sql .= ", ".MAIN_DB_PREFIX."categorie_member as c";
286 }
287 $sql .= ' WHERE t.entity IN ('.getEntity('adherent').')';
288 if (!empty($typeid)) {
289 $sql .= ' AND t.fk_adherent_type='.((int) $typeid);
290 }
291 // Select members of given category
292 if ($category > 0) {
293 $sql .= " AND c.fk_categorie = ".((int) $category);
294 $sql .= " AND c.fk_member = t.rowid";
295 }
296 // Add sql filters
297 if ($sqlfilters) {
298 $errormessage = '';
299 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
300 if ($errormessage) {
301 throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
302 }
303 }
304
305 //this query will return total orders with the filters given
306 $sqlTotals = str_replace('SELECT t.rowid', 'SELECT count(t.rowid) as total', $sql);
307
308 $sql .= $this->db->order($sortfield, $sortorder);
309 if ($limit) {
310 if ($page < 0) {
311 $page = 0;
312 }
313 $offset = $limit * $page;
314
315 $sql .= $this->db->plimit($limit + 1, $offset);
316 }
317
318 $result = $this->db->query($sql);
319 if ($result) {
320 $i = 0;
321 $num = $this->db->num_rows($result);
322 $min = min($num, ($limit <= 0 ? $num : $limit));
323 while ($i < $min) {
324 $obj = $this->db->fetch_object($result);
325 $member = new Adherent($this->db);
326 if ($member->fetch($obj->rowid)) {
327 $obj_ret[] = $this->_filterObjectProperties($this->_cleanObjectDatas($member), $properties);
328 }
329 $i++;
330 }
331 } else {
332 throw new RestException(503, 'Error when retrieve member list : '.$this->db->lasterror());
333 }
334
335 //if $pagination_data is true the response will contain element data with all values and element pagination with pagination data(total,page,limit)
336 if ($pagination_data) {
337 $totalsResult = $this->db->query($sqlTotals);
338 $total = $this->db->fetch_object($totalsResult)->total;
339
340 $tmp = $obj_ret;
341 $obj_ret = [];
342
343 $obj_ret['data'] = $tmp;
344 $obj_ret['pagination'] = [
345 'total' => (int) $total,
346 'page' => $page, //count starts from 0
347 'page_count' => ceil((int) $total / $limit),
348 'limit' => $limit
349 ];
350 }
351
352 return $obj_ret;
353 }
354
366 public function post($request_data = null)
367 {
368 if (!DolibarrApiAccess::$user->hasRight('adherent', 'creer')) {
369 throw new RestException(403);
370 }
371 // Check mandatory fields
372 $result = $this->_validate($request_data);
373
374 $member = new Adherent($this->db);
375 foreach ($request_data as $field => $value) {
376 if ($field === 'caller') {
377 // 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
378 $member->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
379 continue;
380 }
381
382 $member->$field = $this->_checkValForAPI($field, $value, $member);
383 }
384 if ($member->create(DolibarrApiAccess::$user) < 0) {
385 throw new RestException(500, 'Error creating member', array_merge(array($member->error), $member->errors));
386 }
387 return $member->id;
388 }
389
403 public function put($id, $request_data = null)
404 {
405 if (!DolibarrApiAccess::$user->hasRight('adherent', 'creer')) {
406 throw new RestException(403);
407 }
408
409 $member = new Adherent($this->db);
410 $result = $member->fetch($id);
411 if (!$result) {
412 throw new RestException(404, 'member not found');
413 }
414
415 if (!DolibarrApi::_checkAccessToResource('member', $member->id)) {
416 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
417 }
418
419 foreach ($request_data as $field => $value) {
420 if ($field == 'id') {
421 continue;
422 }
423 if ($field === 'caller') {
424 // 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
425 $member->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
426 continue;
427 }
428 if ($field == 'array_options' && is_array($value)) {
429 foreach ($value as $index => $val) {
430 $member->array_options[$index] = $this->_checkValForAPI($field, $val, $member);
431 }
432 continue;
433 }
434 // Process the status separately because it must be updated using
435 // the validate(), resiliate() and exclude() methods of the class Adherent.
436 if ($field == 'statut') {
437 if ($value == '0') {
438 $result = $member->resiliate(DolibarrApiAccess::$user);
439 if ($result < 0) {
440 throw new RestException(500, 'Error when resiliating member: '.$member->error);
441 }
442 } elseif ($value == '1') {
443 $result = $member->validate(DolibarrApiAccess::$user);
444 if ($result < 0) {
445 throw new RestException(500, 'Error when validating member: '.$member->error);
446 }
447 } elseif ($value == '-2') {
448 $result = $member->exclude(DolibarrApiAccess::$user);
449 if ($result < 0) {
450 throw new RestException(500, 'Error when excluding member: '.$member->error);
451 }
452 }
453 } else {
454 $member->$field = $this->_checkValForAPI($field, $value, $member);
455 }
456 }
457
458 // If there is no error, update() returns the number of affected rows
459 // so if the update is a no op, the return value is zero.
460 if ($member->update(DolibarrApiAccess::$user) >= 0) {
461 return $this->get($id);
462 } else {
463 throw new RestException(500, 'Error when updating member: '.$member->error);
464 }
465 }
466
479 public function delete($id)
480 {
481 if (!DolibarrApiAccess::$user->hasRight('adherent', 'supprimer')) {
482 throw new RestException(403);
483 }
484 $member = new Adherent($this->db);
485 $result = $member->fetch($id);
486 if (!$result) {
487 throw new RestException(404, 'member not found');
488 }
489
490 if (!DolibarrApi::_checkAccessToResource('member', $member->id)) {
491 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
492 }
493
494
495 $res = $member->delete(DolibarrApiAccess::$user);
496 if ($res < 0) {
497 throw new RestException(500, "Can't delete, error occurs");
498 }
499
500 return array(
501 'success' => array(
502 'code' => 200,
503 'message' => 'Member deleted'
504 )
505 );
506 }
507
517 private function _validate($data)
518 {
519 if ($data === null) {
520 $data = array();
521 }
522 $member = array();
523
524 $mandatoryfields = array(
525 'morphy',
526 'typeid'
527 );
528 foreach ($mandatoryfields as $field) {
529 if (!isset($data[$field])) {
530 throw new RestException(400, "$field field missing");
531 }
532 $member[$field] = $data[$field];
533 }
534 return $member;
535 }
536
537 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
544 public function _cleanObjectDatas($object)
545 {
546 // phpcs:enable
547 $object = parent::_cleanObjectDatas($object);
548
549 // Remove the subscriptions because they are handled as a subresource.
550 if ($object instanceof Adherent) {
551 unset($object->subscriptions);
552 unset($object->fk_incoterms);
553 unset($object->label_incoterms);
554 unset($object->location_incoterms);
555 unset($object->fk_delivery_address);
556 unset($object->shipping_method_id);
557
558 unset($object->total_ht);
559 unset($object->total_ttc);
560 unset($object->total_tva);
561 unset($object->total_localtax1);
562 unset($object->total_localtax2);
563 }
564
565 if ($object instanceof AdherentType) {
566 unset($object->linkedObjectsIds);
567 unset($object->context);
568 unset($object->canvas);
569 unset($object->fk_project);
570 unset($object->contact);
571 unset($object->contact_id);
572 unset($object->thirdparty);
573 unset($object->user);
574 unset($object->origin);
575 unset($object->origin_id);
576 unset($object->ref_ext);
577 unset($object->country);
578 unset($object->country_id);
579 unset($object->country_code);
580 unset($object->barcode_type);
581 unset($object->barcode_type_code);
582 unset($object->barcode_type_label);
583 unset($object->barcode_type_coder);
584 unset($object->mode_reglement_id);
585 unset($object->cond_reglement_id);
586 unset($object->cond_reglement);
587 unset($object->fk_delivery_address);
588 unset($object->shipping_method_id);
589 unset($object->model_pdf);
590 unset($object->fk_account);
591 unset($object->note_public);
592 unset($object->note_private);
593 unset($object->fk_incoterms);
594 unset($object->label_incoterms);
595 unset($object->location_incoterms);
596 unset($object->name);
597 unset($object->lastname);
598 unset($object->firstname);
599 unset($object->civility_id);
600 unset($object->total_ht);
601 unset($object->total_tva);
602 unset($object->total_localtax1);
603 unset($object->total_localtax2);
604 unset($object->total_ttc);
605 }
606
607 return $object;
608 }
609
625 public function getSubscriptions($id)
626 {
627 if (!DolibarrApiAccess::$user->hasRight('adherent', 'cotisation', 'lire')) {
628 throw new RestException(403);
629 }
630
631 $member = new Adherent($this->db);
632 $result = $member->fetch($id);
633 if (!$result) {
634 throw new RestException(404, 'member not found');
635 }
636
637 $obj_ret = array();
638 foreach ($member->subscriptions as $subscription) {
639 $obj_ret[] = $this->_cleanObjectDatas($subscription);
640 }
641 return $obj_ret;
642 }
643
661 public function createSubscription($id, $start_date, $end_date, $amount, $label = '')
662 {
663 if (!DolibarrApiAccess::$user->hasRight('adherent', 'cotisation', 'creer')) {
664 throw new RestException(403);
665 }
666 if (!is_numeric($start_date) || !is_numeric($end_date) || !is_numeric($amount)) {
667 throw new RestException(422, 'Malformed data: subscription start or end date, or subscription amount, is not numeric');
668 }
669 if ($start_date > $end_date) {
670 throw new RestException(422, 'Malformed data: subscription start is not larger than end date');
671 }
672
673 $member = new Adherent($this->db);
674 $result = $member->fetch($id);
675 if (!$result) {
676 throw new RestException(404, 'member not found');
677 }
678
679 $result = $member->subscription((int) $start_date, (float) $amount, 0, '', $label, '', '', '', (int) $end_date);
680 if ($result < 1) {
681 throw new RestException(500, $member->error);
682 } else {
683 return $result;
684 }
685 }
686
704 public function getCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0)
705 {
706 if (!DolibarrApiAccess::$user->hasRight('categorie', 'lire')) {
707 throw new RestException(403);
708 }
709
710 $member = new Adherent($this->db);
711 $result = $member->fetch($id);
712 if (0 === $result) {
713 throw new RestException(404, 'Member not found');
714 }
715
716 $categories = new Categorie($this->db);
717
718 $result = $categories->getListForItem($id, 'member', $sortfield, $sortorder, $limit, $page);
719
720 if ($result < 0) {
721 throw new RestException(503, 'Error when retrieve category list : '.$categories->error);
722 }
723
724 return $result;
725 }
726
727
728
729
743 public function getType($id)
744 {
745 if (!DolibarrApiAccess::$user->hasRight('adherent', 'lire')) {
746 throw new RestException(403);
747 }
748
749 $membertype = new AdherentType($this->db);
750 $result = $membertype->fetch($id);
751 if (!$result) {
752 throw new RestException(404, 'member type not found');
753 }
754
755 if (!DolibarrApi::_checkAccessToResource('member', $membertype->id, 'adherent_type')) {
756 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
757 }
758
759 return $this->_cleanObjectDatas($membertype);
760 }
761
784 public function indexType($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $sqlfilters = '', $properties = '', $pagination_data = false)
785 {
786 $obj_ret = array();
787
788 if (!DolibarrApiAccess::$user->hasRight('adherent', 'lire')) {
789 throw new RestException(403);
790 }
791
792 $sql = "SELECT t.rowid";
793 $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type AS t LEFT JOIN ".MAIN_DB_PREFIX."adherent_type_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
794 $sql .= ' WHERE t.entity IN ('.getEntity('member_type').')';
795
796 // Add sql filters
797 if ($sqlfilters) {
798 $errormessage = '';
799 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
800 if ($errormessage) {
801 throw new RestException(503, 'Error when validating parameter sqlfilters -> '.$errormessage);
802 }
803 }
804
805 //this query will return total orders with the filters given
806 $sqlTotals = str_replace('SELECT t.rowid', 'SELECT count(t.rowid) as total', $sql);
807
808 $sql .= $this->db->order($sortfield, $sortorder);
809 if ($limit) {
810 if ($page < 0) {
811 $page = 0;
812 }
813 $offset = $limit * $page;
814
815 $sql .= $this->db->plimit($limit + 1, $offset);
816 }
817
818 $result = $this->db->query($sql);
819 if ($result) {
820 $i = 0;
821 $num = $this->db->num_rows($result);
822 $min = min($num, ($limit <= 0 ? $num : $limit));
823 while ($i < $min) {
824 $obj = $this->db->fetch_object($result);
825 $membertype = new AdherentType($this->db);
826 if ($membertype->fetch($obj->rowid)) {
827 $obj_ret[] = $this->_filterObjectProperties($this->_cleanObjectDatas($membertype), $properties);
828 }
829 $i++;
830 }
831 } else {
832 throw new RestException(503, 'Error when retrieve member type list : '.$this->db->lasterror());
833 }
834
835 //if $pagination_data is true the response will contain element data with all values and element pagination with pagination data(total,page,limit)
836 if ($pagination_data) {
837 $totalsResult = $this->db->query($sqlTotals);
838 $total = $this->db->fetch_object($totalsResult)->total;
839
840 $tmp = $obj_ret;
841 $obj_ret = [];
842
843 $obj_ret['data'] = $tmp;
844 $obj_ret['pagination'] = [
845 'total' => (int) $total,
846 'page' => $page, //count starts from 0
847 'page_count' => ceil((int) $total / $limit),
848 'limit' => $limit
849 ];
850 }
851
852 return $obj_ret;
853 }
854
868 public function postType($request_data = null)
869 {
870 if (!DolibarrApiAccess::$user->hasRight('adherent', 'configurer')) {
871 throw new RestException(403);
872 }
873 // Check mandatory fields
874 $result = $this->_validateType($request_data);
875
876 $membertype = new AdherentType($this->db);
877 foreach ($request_data as $field => $value) {
878 if ($field === 'caller') {
879 // 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
880 $membertype->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
881 continue;
882 }
883
884 $membertype->$field = $this->_checkValForAPI($field, $value, $membertype);
885 }
886 if ($membertype->create(DolibarrApiAccess::$user) < 0) {
887 throw new RestException(500, 'Error creating member type', array_merge(array($membertype->error), $membertype->errors));
888 }
889 return $membertype->id;
890 }
891
907 public function putType($id, $request_data = null)
908 {
909 if (!DolibarrApiAccess::$user->hasRight('adherent', 'configurer')) {
910 throw new RestException(403);
911 }
912
913 $membertype = new AdherentType($this->db);
914 $result = $membertype->fetch($id);
915 if (!$result) {
916 throw new RestException(404, 'member type not found');
917 }
918
919 if (!DolibarrApi::_checkAccessToResource('member', $membertype->id, 'adherent_type')) {
920 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
921 }
922
923 foreach ($request_data as $field => $value) {
924 if ($field == 'id') {
925 continue;
926 }
927 if ($field === 'caller') {
928 // 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
929 $membertype->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
930 continue;
931 }
932 if ($field == 'array_options' && is_array($value)) {
933 foreach ($value as $index => $val) {
934 $membertype->array_options[$index] = $val;
935 }
936 continue;
937 }
938 // Process the status separately because it must be updated using
939 // the validate(), resiliate() and exclude() methods of the class AdherentType.
940 $membertype->$field = $this->_checkValForAPI($field, $value, $membertype);
941 }
942
943 // If there is no error, update() returns the number of affected rows
944 // so if the update is a no op, the return value is zero.
945 if ($membertype->update(DolibarrApiAccess::$user) >= 0) {
946 return $this->get($id);
947 } else {
948 throw new RestException(500, 'Error when updating member type: '.$membertype->error);
949 }
950 }
951
966 public function deleteType($id)
967 {
968 if (!DolibarrApiAccess::$user->hasRight('adherent', 'configurer')) {
969 throw new RestException(403);
970 }
971 $membertype = new AdherentType($this->db);
972 $result = $membertype->fetch($id);
973 if ($result < 1) {
974 throw new RestException(404, 'member type not found');
975 }
976
977 if (!DolibarrApi::_checkAccessToResource('member', $membertype->id, 'adherent_type')) {
978 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
979 }
980
981 $res = $membertype->delete(DolibarrApiAccess::$user);
982 if ($res < 0) {
983 throw new RestException(500, "Can't delete, error occurs");
984 }
985
986 return array(
987 'success' => array(
988 'code' => 200,
989 'message' => 'Member type deleted'
990 )
991 );
992 }
993
1002 private function _validateType($data)
1003 {
1004 $membertype = array();
1005
1006 $mandatoryfields = array('label');
1007
1008 foreach ($mandatoryfields as $field) {
1009 if (!isset($data[$field])) {
1010 throw new RestException(400, "$field field missing");
1011 }
1012 $membertype[$field] = $data[$field];
1013 }
1014 return $membertype;
1015 }
1016}
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
Class to manage members of a foundation.
Class to manage members type.
Class to manage categories.
Class for API REST v1.
Definition api.class.php:33
_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:98
put($id, $request_data=null)
Update member.
getType($id)
Get properties of a member type object.
createSubscription($id, $start_date, $end_date, $amount, $label='')
Add a subscription for a member.
indexType($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $sqlfilters='', $properties='', $pagination_data=false)
List members types.
_validate($data)
Validate fields before creating an object.
getByThirdparty($thirdparty)
Get properties of a member object by linked thirdparty.
getByThirdpartyBarcode($barcode)
Get properties of a member object by linked thirdparty barcode.
deleteType($id)
Delete member type.
index($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $typeid='', $category=0, $sqlfilters='', $properties='', $pagination_data=false)
List members.
__construct()
Constructor.
getCategories($id, $sortfield="s.rowid", $sortorder='ASC', $limit=0, $page=0)
Get categories for a member.
getByThirdpartyEmail($email)
Get properties of a member object by linked thirdparty email.
_cleanObjectDatas($object)
Clean sensible object datas.
_validateType($data)
Validate fields before creating an object.
putType($id, $request_data=null)
Update member type.
getSubscriptions($id)
List subscriptions of a member.
post($request_data=null)
Create member object.
getByThirdpartyAccounts($site, $key_account)
Get properties of a member object by linked thirdparty account.
postType($request_data=null)
Create member type object.
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.