dolibarr 21.0.0-beta
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 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
364 public function post($request_data = null)
365 {
366 if (!DolibarrApiAccess::$user->hasRight('adherent', 'creer')) {
367 throw new RestException(403);
368 }
369 // Check mandatory fields
370 $result = $this->_validate($request_data);
371
372 $member = new Adherent($this->db);
373 foreach ($request_data as $field => $value) {
374 if ($field === 'caller') {
375 // 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
376 $member->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
377 continue;
378 }
379
380 $member->$field = $this->_checkValForAPI($field, $value, $member);
381 }
382 if ($member->create(DolibarrApiAccess::$user) < 0) {
383 throw new RestException(500, 'Error creating member', array_merge(array($member->error), $member->errors));
384 }
385 return $member->id;
386 }
387
401 public function put($id, $request_data = null)
402 {
403 if (!DolibarrApiAccess::$user->hasRight('adherent', 'creer')) {
404 throw new RestException(403);
405 }
406
407 $member = new Adherent($this->db);
408 $result = $member->fetch($id);
409 if (!$result) {
410 throw new RestException(404, 'member not found');
411 }
412
413 if (!DolibarrApi::_checkAccessToResource('member', $member->id)) {
414 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
415 }
416
417 foreach ($request_data as $field => $value) {
418 if ($field == 'id') {
419 continue;
420 }
421 if ($field === 'caller') {
422 // 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
423 $member->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
424 continue;
425 }
426 if ($field == 'array_options' && is_array($value)) {
427 foreach ($value as $index => $val) {
428 $member->array_options[$index] = $val;
429 }
430 continue;
431 }
432 // Process the status separately because it must be updated using
433 // the validate(), resiliate() and exclude() methods of the class Adherent.
434 if ($field == 'statut') {
435 if ($value == '0') {
436 $result = $member->resiliate(DolibarrApiAccess::$user);
437 if ($result < 0) {
438 throw new RestException(500, 'Error when resiliating member: '.$member->error);
439 }
440 } elseif ($value == '1') {
441 $result = $member->validate(DolibarrApiAccess::$user);
442 if ($result < 0) {
443 throw new RestException(500, 'Error when validating member: '.$member->error);
444 }
445 } elseif ($value == '-2') {
446 $result = $member->exclude(DolibarrApiAccess::$user);
447 if ($result < 0) {
448 throw new RestException(500, 'Error when excluding member: '.$member->error);
449 }
450 }
451 } else {
452 $member->$field = $this->_checkValForAPI($field, $value, $member);
453 }
454 }
455
456 // If there is no error, update() returns the number of affected rows
457 // so if the update is a no op, the return value is zero.
458 if ($member->update(DolibarrApiAccess::$user) >= 0) {
459 return $this->get($id);
460 } else {
461 throw new RestException(500, 'Error when updating member: '.$member->error);
462 }
463 }
464
477 public function delete($id)
478 {
479 if (!DolibarrApiAccess::$user->hasRight('adherent', 'supprimer')) {
480 throw new RestException(403);
481 }
482 $member = new Adherent($this->db);
483 $result = $member->fetch($id);
484 if (!$result) {
485 throw new RestException(404, 'member not found');
486 }
487
488 if (!DolibarrApi::_checkAccessToResource('member', $member->id)) {
489 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
490 }
491
492
493 $res = $member->delete(DolibarrApiAccess::$user);
494 if ($res < 0) {
495 throw new RestException(500, "Can't delete, error occurs");
496 }
497
498 return array(
499 'success' => array(
500 'code' => 200,
501 'message' => 'Member deleted'
502 )
503 );
504 }
505
515 private function _validate($data)
516 {
517 $member = array();
518
519 $mandatoryfields = array(
520 'morphy',
521 'typeid'
522 );
523 foreach ($mandatoryfields as $field) {
524 if (!isset($data[$field])) {
525 throw new RestException(400, "$field field missing");
526 }
527 $member[$field] = $data[$field];
528 }
529 return $member;
530 }
531
532 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
539 protected function _cleanObjectDatas($object)
540 {
541 // phpcs:enable
542 $object = parent::_cleanObjectDatas($object);
543
544 // Remove the subscriptions because they are handled as a subresource.
545 if ($object instanceof Adherent) {
546 unset($object->subscriptions);
547 unset($object->fk_incoterms);
548 unset($object->label_incoterms);
549 unset($object->location_incoterms);
550 unset($object->fk_delivery_address);
551 unset($object->shipping_method_id);
552
553 unset($object->total_ht);
554 unset($object->total_ttc);
555 unset($object->total_tva);
556 unset($object->total_localtax1);
557 unset($object->total_localtax2);
558 }
559
560 if ($object instanceof AdherentType) {
561 unset($object->linkedObjectsIds);
562 unset($object->context);
563 unset($object->canvas);
564 unset($object->fk_project);
565 unset($object->contact);
566 unset($object->contact_id);
567 unset($object->thirdparty);
568 unset($object->user);
569 unset($object->origin);
570 unset($object->origin_id);
571 unset($object->ref_ext);
572 unset($object->country);
573 unset($object->country_id);
574 unset($object->country_code);
575 unset($object->barcode_type);
576 unset($object->barcode_type_code);
577 unset($object->barcode_type_label);
578 unset($object->barcode_type_coder);
579 unset($object->mode_reglement_id);
580 unset($object->cond_reglement_id);
581 unset($object->cond_reglement);
582 unset($object->fk_delivery_address);
583 unset($object->shipping_method_id);
584 unset($object->model_pdf);
585 unset($object->fk_account);
586 unset($object->note_public);
587 unset($object->note_private);
588 unset($object->fk_incoterms);
589 unset($object->label_incoterms);
590 unset($object->location_incoterms);
591 unset($object->name);
592 unset($object->lastname);
593 unset($object->firstname);
594 unset($object->civility_id);
595 unset($object->total_ht);
596 unset($object->total_tva);
597 unset($object->total_localtax1);
598 unset($object->total_localtax2);
599 unset($object->total_ttc);
600 }
601
602 return $object;
603 }
604
620 public function getSubscriptions($id)
621 {
622 if (!DolibarrApiAccess::$user->hasRight('adherent', 'cotisation', 'lire')) {
623 throw new RestException(403);
624 }
625
626 $member = new Adherent($this->db);
627 $result = $member->fetch($id);
628 if (!$result) {
629 throw new RestException(404, 'member not found');
630 }
631
632 $obj_ret = array();
633 foreach ($member->subscriptions as $subscription) {
634 $obj_ret[] = $this->_cleanObjectDatas($subscription);
635 }
636 return $obj_ret;
637 }
638
654 public function createSubscription($id, $start_date, $end_date, $amount, $label = '')
655 {
656 if (!DolibarrApiAccess::$user->hasRight('adherent', 'cotisation', 'creer')) {
657 throw new RestException(403);
658 }
659
660 $member = new Adherent($this->db);
661 $result = $member->fetch($id);
662 if (!$result) {
663 throw new RestException(404, 'member not found');
664 }
665
666 return $member->subscription($start_date, $amount, 0, '', $label, '', '', '', $end_date);
667 }
668
686 public function getCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0)
687 {
688 if (!DolibarrApiAccess::$user->hasRight('categorie', 'lire')) {
689 throw new RestException(403);
690 }
691
692 $member = new Adherent($this->db);
693 $result = $member->fetch($id);
694 if (0 === $result) {
695 throw new RestException(404, 'Member not found');
696 }
697
698 $categories = new Categorie($this->db);
699
700 $result = $categories->getListForItem($id, 'member', $sortfield, $sortorder, $limit, $page);
701
702 if ($result < 0) {
703 throw new RestException(503, 'Error when retrieve category list : '.$categories->error);
704 }
705
706 return $result;
707 }
708
709
710
711
725 public function getType($id)
726 {
727 if (!DolibarrApiAccess::$user->hasRight('adherent', 'lire')) {
728 throw new RestException(403);
729 }
730
731 $membertype = new AdherentType($this->db);
732 $result = $membertype->fetch($id);
733 if (!$result) {
734 throw new RestException(404, 'member type not found');
735 }
736
737 if (!DolibarrApi::_checkAccessToResource('member', $membertype->id, 'adherent_type')) {
738 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
739 }
740
741 return $this->_cleanObjectDatas($membertype);
742 }
743
766 public function indexType($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $sqlfilters = '', $properties = '', $pagination_data = false)
767 {
768 $obj_ret = array();
769
770 if (!DolibarrApiAccess::$user->hasRight('adherent', 'lire')) {
771 throw new RestException(403);
772 }
773
774 $sql = "SELECT t.rowid";
775 $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
776 $sql .= ' WHERE t.entity IN ('.getEntity('member_type').')';
777
778 // Add sql filters
779 if ($sqlfilters) {
780 $errormessage = '';
781 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
782 if ($errormessage) {
783 throw new RestException(503, 'Error when validating parameter sqlfilters -> '.$errormessage);
784 }
785 }
786
787 //this query will return total orders with the filters given
788 $sqlTotals = str_replace('SELECT t.rowid', 'SELECT count(t.rowid) as total', $sql);
789
790 $sql .= $this->db->order($sortfield, $sortorder);
791 if ($limit) {
792 if ($page < 0) {
793 $page = 0;
794 }
795 $offset = $limit * $page;
796
797 $sql .= $this->db->plimit($limit + 1, $offset);
798 }
799
800 $result = $this->db->query($sql);
801 if ($result) {
802 $i = 0;
803 $num = $this->db->num_rows($result);
804 $min = min($num, ($limit <= 0 ? $num : $limit));
805 while ($i < $min) {
806 $obj = $this->db->fetch_object($result);
807 $membertype = new AdherentType($this->db);
808 if ($membertype->fetch($obj->rowid)) {
809 $obj_ret[] = $this->_filterObjectProperties($this->_cleanObjectDatas($membertype), $properties);
810 }
811 $i++;
812 }
813 } else {
814 throw new RestException(503, 'Error when retrieve member type list : '.$this->db->lasterror());
815 }
816
817 //if $pagination_data is true the response will contain element data with all values and element pagination with pagination data(total,page,limit)
818 if ($pagination_data) {
819 $totalsResult = $this->db->query($sqlTotals);
820 $total = $this->db->fetch_object($totalsResult)->total;
821
822 $tmp = $obj_ret;
823 $obj_ret = [];
824
825 $obj_ret['data'] = $tmp;
826 $obj_ret['pagination'] = [
827 'total' => (int) $total,
828 'page' => $page, //count starts from 0
829 'page_count' => ceil((int) $total / $limit),
830 'limit' => $limit
831 ];
832 }
833
834 return $obj_ret;
835 }
836
850 public function postType($request_data = null)
851 {
852 if (!DolibarrApiAccess::$user->hasRight('adherent', 'configurer')) {
853 throw new RestException(403);
854 }
855 // Check mandatory fields
856 $result = $this->_validateType($request_data);
857
858 $membertype = new AdherentType($this->db);
859 foreach ($request_data as $field => $value) {
860 if ($field === 'caller') {
861 // 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
862 $membertype->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
863 continue;
864 }
865
866 $membertype->$field = $this->_checkValForAPI($field, $value, $membertype);
867 }
868 if ($membertype->create(DolibarrApiAccess::$user) < 0) {
869 throw new RestException(500, 'Error creating member type', array_merge(array($membertype->error), $membertype->errors));
870 }
871 return $membertype->id;
872 }
873
889 public function putType($id, $request_data = null)
890 {
891 if (!DolibarrApiAccess::$user->hasRight('adherent', 'configurer')) {
892 throw new RestException(403);
893 }
894
895 $membertype = new AdherentType($this->db);
896 $result = $membertype->fetch($id);
897 if (!$result) {
898 throw new RestException(404, 'member type not found');
899 }
900
901 if (!DolibarrApi::_checkAccessToResource('member', $membertype->id, 'adherent_type')) {
902 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
903 }
904
905 foreach ($request_data as $field => $value) {
906 if ($field == 'id') {
907 continue;
908 }
909 if ($field === 'caller') {
910 // 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
911 $membertype->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
912 continue;
913 }
914 if ($field == 'array_options' && is_array($value)) {
915 foreach ($value as $index => $val) {
916 $membertype->array_options[$index] = $val;
917 }
918 continue;
919 }
920 // Process the status separately because it must be updated using
921 // the validate(), resiliate() and exclude() methods of the class AdherentType.
922 $membertype->$field = $this->_checkValForAPI($field, $value, $membertype);
923 }
924
925 // If there is no error, update() returns the number of affected rows
926 // so if the update is a no op, the return value is zero.
927 if ($membertype->update(DolibarrApiAccess::$user) >= 0) {
928 return $this->get($id);
929 } else {
930 throw new RestException(500, 'Error when updating member type: '.$membertype->error);
931 }
932 }
933
948 public function deleteType($id)
949 {
950 if (!DolibarrApiAccess::$user->hasRight('adherent', 'configurer')) {
951 throw new RestException(403);
952 }
953 $membertype = new AdherentType($this->db);
954 $result = $membertype->fetch($id);
955 if ($result < 1) {
956 throw new RestException(404, 'member type not found');
957 }
958
959 if (!DolibarrApi::_checkAccessToResource('member', $membertype->id, 'adherent_type')) {
960 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
961 }
962
963 $res = $membertype->delete(DolibarrApiAccess::$user);
964 if ($res < 0) {
965 throw new RestException(500, "Can't delete, error occurs");
966 }
967
968 return array(
969 'success' => array(
970 'code' => 200,
971 'message' => 'Member type deleted'
972 )
973 );
974 }
975
984 private function _validateType($data)
985 {
986 $membertype = array();
987
988 $mandatoryfields = array('label');
989
990 foreach ($mandatoryfields as $field) {
991 if (!isset($data[$field])) {
992 throw new RestException(400, "$field field missing");
993 }
994 $membertype[$field] = $data[$field];
995 }
996 return $membertype;
997 }
998}
$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: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
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.