dolibarr 21.0.3
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 $member = array();
520
521 $mandatoryfields = array(
522 'morphy',
523 'typeid'
524 );
525 foreach ($mandatoryfields as $field) {
526 if (!isset($data[$field])) {
527 throw new RestException(400, "$field field missing");
528 }
529 $member[$field] = $data[$field];
530 }
531 return $member;
532 }
533
534 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
541 protected function _cleanObjectDatas($object)
542 {
543 // phpcs:enable
544 $object = parent::_cleanObjectDatas($object);
545
546 // Remove the subscriptions because they are handled as a subresource.
547 if ($object instanceof Adherent) {
548 unset($object->subscriptions);
549 unset($object->fk_incoterms);
550 unset($object->label_incoterms);
551 unset($object->location_incoterms);
552 unset($object->fk_delivery_address);
553 unset($object->shipping_method_id);
554
555 unset($object->total_ht);
556 unset($object->total_ttc);
557 unset($object->total_tva);
558 unset($object->total_localtax1);
559 unset($object->total_localtax2);
560 }
561
562 if ($object instanceof AdherentType) {
563 unset($object->linkedObjectsIds);
564 unset($object->context);
565 unset($object->canvas);
566 unset($object->fk_project);
567 unset($object->contact);
568 unset($object->contact_id);
569 unset($object->thirdparty);
570 unset($object->user);
571 unset($object->origin);
572 unset($object->origin_id);
573 unset($object->ref_ext);
574 unset($object->country);
575 unset($object->country_id);
576 unset($object->country_code);
577 unset($object->barcode_type);
578 unset($object->barcode_type_code);
579 unset($object->barcode_type_label);
580 unset($object->barcode_type_coder);
581 unset($object->mode_reglement_id);
582 unset($object->cond_reglement_id);
583 unset($object->cond_reglement);
584 unset($object->fk_delivery_address);
585 unset($object->shipping_method_id);
586 unset($object->model_pdf);
587 unset($object->fk_account);
588 unset($object->note_public);
589 unset($object->note_private);
590 unset($object->fk_incoterms);
591 unset($object->label_incoterms);
592 unset($object->location_incoterms);
593 unset($object->name);
594 unset($object->lastname);
595 unset($object->firstname);
596 unset($object->civility_id);
597 unset($object->total_ht);
598 unset($object->total_tva);
599 unset($object->total_localtax1);
600 unset($object->total_localtax2);
601 unset($object->total_ttc);
602 }
603
604 return $object;
605 }
606
622 public function getSubscriptions($id)
623 {
624 if (!DolibarrApiAccess::$user->hasRight('adherent', 'cotisation', 'lire')) {
625 throw new RestException(403);
626 }
627
628 $member = new Adherent($this->db);
629 $result = $member->fetch($id);
630 if (!$result) {
631 throw new RestException(404, 'member not found');
632 }
633
634 $obj_ret = array();
635 foreach ($member->subscriptions as $subscription) {
636 $obj_ret[] = $this->_cleanObjectDatas($subscription);
637 }
638 return $obj_ret;
639 }
640
656 public function createSubscription($id, $start_date, $end_date, $amount, $label = '')
657 {
658 if (!DolibarrApiAccess::$user->hasRight('adherent', 'cotisation', 'creer')) {
659 throw new RestException(403);
660 }
661
662 $member = new Adherent($this->db);
663 $result = $member->fetch($id);
664 if (!$result) {
665 throw new RestException(404, 'member not found');
666 }
667
668 return $member->subscription($start_date, $amount, 0, '', $label, '', '', '', $end_date);
669 }
670
688 public function getCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0)
689 {
690 if (!DolibarrApiAccess::$user->hasRight('categorie', 'lire')) {
691 throw new RestException(403);
692 }
693
694 $member = new Adherent($this->db);
695 $result = $member->fetch($id);
696 if (0 === $result) {
697 throw new RestException(404, 'Member not found');
698 }
699
700 $categories = new Categorie($this->db);
701
702 $result = $categories->getListForItem($id, 'member', $sortfield, $sortorder, $limit, $page);
703
704 if ($result < 0) {
705 throw new RestException(503, 'Error when retrieve category list : '.$categories->error);
706 }
707
708 return $result;
709 }
710
711
712
713
727 public function getType($id)
728 {
729 if (!DolibarrApiAccess::$user->hasRight('adherent', 'lire')) {
730 throw new RestException(403);
731 }
732
733 $membertype = new AdherentType($this->db);
734 $result = $membertype->fetch($id);
735 if (!$result) {
736 throw new RestException(404, 'member type not found');
737 }
738
739 if (!DolibarrApi::_checkAccessToResource('member', $membertype->id, 'adherent_type')) {
740 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
741 }
742
743 return $this->_cleanObjectDatas($membertype);
744 }
745
768 public function indexType($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $sqlfilters = '', $properties = '', $pagination_data = false)
769 {
770 $obj_ret = array();
771
772 if (!DolibarrApiAccess::$user->hasRight('adherent', 'lire')) {
773 throw new RestException(403);
774 }
775
776 $sql = "SELECT t.rowid";
777 $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
778 $sql .= ' WHERE t.entity IN ('.getEntity('member_type').')';
779
780 // Add sql filters
781 if ($sqlfilters) {
782 $errormessage = '';
783 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
784 if ($errormessage) {
785 throw new RestException(503, 'Error when validating parameter sqlfilters -> '.$errormessage);
786 }
787 }
788
789 //this query will return total orders with the filters given
790 $sqlTotals = str_replace('SELECT t.rowid', 'SELECT count(t.rowid) as total', $sql);
791
792 $sql .= $this->db->order($sortfield, $sortorder);
793 if ($limit) {
794 if ($page < 0) {
795 $page = 0;
796 }
797 $offset = $limit * $page;
798
799 $sql .= $this->db->plimit($limit + 1, $offset);
800 }
801
802 $result = $this->db->query($sql);
803 if ($result) {
804 $i = 0;
805 $num = $this->db->num_rows($result);
806 $min = min($num, ($limit <= 0 ? $num : $limit));
807 while ($i < $min) {
808 $obj = $this->db->fetch_object($result);
809 $membertype = new AdherentType($this->db);
810 if ($membertype->fetch($obj->rowid)) {
811 $obj_ret[] = $this->_filterObjectProperties($this->_cleanObjectDatas($membertype), $properties);
812 }
813 $i++;
814 }
815 } else {
816 throw new RestException(503, 'Error when retrieve member type list : '.$this->db->lasterror());
817 }
818
819 //if $pagination_data is true the response will contain element data with all values and element pagination with pagination data(total,page,limit)
820 if ($pagination_data) {
821 $totalsResult = $this->db->query($sqlTotals);
822 $total = $this->db->fetch_object($totalsResult)->total;
823
824 $tmp = $obj_ret;
825 $obj_ret = [];
826
827 $obj_ret['data'] = $tmp;
828 $obj_ret['pagination'] = [
829 'total' => (int) $total,
830 'page' => $page, //count starts from 0
831 'page_count' => ceil((int) $total / $limit),
832 'limit' => $limit
833 ];
834 }
835
836 return $obj_ret;
837 }
838
852 public function postType($request_data = null)
853 {
854 if (!DolibarrApiAccess::$user->hasRight('adherent', 'configurer')) {
855 throw new RestException(403);
856 }
857 // Check mandatory fields
858 $result = $this->_validateType($request_data);
859
860 $membertype = new AdherentType($this->db);
861 foreach ($request_data as $field => $value) {
862 if ($field === 'caller') {
863 // 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
864 $membertype->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
865 continue;
866 }
867
868 $membertype->$field = $this->_checkValForAPI($field, $value, $membertype);
869 }
870 if ($membertype->create(DolibarrApiAccess::$user) < 0) {
871 throw new RestException(500, 'Error creating member type', array_merge(array($membertype->error), $membertype->errors));
872 }
873 return $membertype->id;
874 }
875
891 public function putType($id, $request_data = null)
892 {
893 if (!DolibarrApiAccess::$user->hasRight('adherent', 'configurer')) {
894 throw new RestException(403);
895 }
896
897 $membertype = new AdherentType($this->db);
898 $result = $membertype->fetch($id);
899 if (!$result) {
900 throw new RestException(404, 'member type not found');
901 }
902
903 if (!DolibarrApi::_checkAccessToResource('member', $membertype->id, 'adherent_type')) {
904 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
905 }
906
907 foreach ($request_data as $field => $value) {
908 if ($field == 'id') {
909 continue;
910 }
911 if ($field === 'caller') {
912 // 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
913 $membertype->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
914 continue;
915 }
916 if ($field == 'array_options' && is_array($value)) {
917 foreach ($value as $index => $val) {
918 $membertype->array_options[$index] = $val;
919 }
920 continue;
921 }
922 // Process the status separately because it must be updated using
923 // the validate(), resiliate() and exclude() methods of the class AdherentType.
924 $membertype->$field = $this->_checkValForAPI($field, $value, $membertype);
925 }
926
927 // If there is no error, update() returns the number of affected rows
928 // so if the update is a no op, the return value is zero.
929 if ($membertype->update(DolibarrApiAccess::$user) >= 0) {
930 return $this->get($id);
931 } else {
932 throw new RestException(500, 'Error when updating member type: '.$membertype->error);
933 }
934 }
935
950 public function deleteType($id)
951 {
952 if (!DolibarrApiAccess::$user->hasRight('adherent', 'configurer')) {
953 throw new RestException(403);
954 }
955 $membertype = new AdherentType($this->db);
956 $result = $membertype->fetch($id);
957 if ($result < 1) {
958 throw new RestException(404, 'member type not found');
959 }
960
961 if (!DolibarrApi::_checkAccessToResource('member', $membertype->id, 'adherent_type')) {
962 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
963 }
964
965 $res = $membertype->delete(DolibarrApiAccess::$user);
966 if ($res < 0) {
967 throw new RestException(500, "Can't delete, error occurs");
968 }
969
970 return array(
971 'success' => array(
972 'code' => 200,
973 'message' => 'Member type deleted'
974 )
975 );
976 }
977
986 private function _validateType($data)
987 {
988 $membertype = array();
989
990 $mandatoryfields = array('label');
991
992 foreach ($mandatoryfields as $field) {
993 if (!isset($data[$field])) {
994 throw new RestException(400, "$field field missing");
995 }
996 $membertype[$field] = $data[$field];
997 }
998 return $membertype;
999 }
1000}
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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:31
_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:83
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.