22use Luracast\Restler\RestException;
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';
42 public static $FIELDS = array(
67 public function get($id)
69 if (!DolibarrApiAccess::$user->hasRight(
'adherent',
'lire')) {
70 throw new RestException(403);
75 $result = $member->initAsSpecimen();
77 $result = $member->fetch($id);
80 throw new RestException(404,
'member not found');
84 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
106 if (!DolibarrApiAccess::$user->hasRight(
'adherent',
'lire')) {
107 throw new RestException(403);
111 $result = $member->fetch(
'',
'', $thirdparty);
113 throw new RestException(404,
'member not found');
117 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
139 if (!DolibarrApiAccess::$user->hasRight(
'adherent',
'lire')) {
140 throw new RestException(403);
143 $thirdparty =
new Societe($this->db);
144 $result = $thirdparty->fetch(
'',
'',
'',
'',
'',
'',
'',
'',
'',
'', $email);
146 throw new RestException(404,
'thirdparty not found');
150 $result = $member->fetch(
'',
'', $thirdparty->id);
152 throw new RestException(404,
'member not found');
156 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
178 if (!DolibarrApiAccess::$user->hasRight(
'adherent',
'lire')) {
179 throw new RestException(403);
182 $thirdparty =
new Societe($this->db);
183 $result = $thirdparty->fetch(
'',
'',
'', $barcode);
185 throw new RestException(404,
'thirdparty not found');
189 $result = $member->fetch(
'',
'', $thirdparty->id);
191 throw new RestException(404,
'member not found');
195 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
222 public function index($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $typeid =
'', $category = 0, $sqlfilters =
'', $properties =
'')
226 if (!DolibarrApiAccess::$user->hasRight(
'adherent',
'lire')) {
227 throw new RestException(403);
230 $sql =
"SELECT t.rowid";
231 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent AS t LEFT JOIN ".MAIN_DB_PREFIX.
"adherent_extrafields AS ef ON (ef.fk_object = t.rowid)";
233 $sql .=
", ".MAIN_DB_PREFIX.
"categorie_member as c";
235 $sql .=
' WHERE t.entity IN ('.getEntity(
'adherent').
')';
236 if (!empty($typeid)) {
237 $sql .=
' AND t.fk_adherent_type='.((int) $typeid);
241 $sql .=
" AND c.fk_categorie = ".((int) $category);
242 $sql .=
" AND c.fk_member = t.rowid";
249 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
253 $sql .= $this->db->order($sortfield, $sortorder);
258 $offset = $limit * $page;
260 $sql .= $this->db->plimit($limit + 1, $offset);
263 $result = $this->db->query($sql);
266 $num = $this->db->num_rows($result);
267 $min = min($num, ($limit <= 0 ? $num : $limit));
269 $obj = $this->db->fetch_object($result);
271 if ($member->fetch($obj->rowid)) {
277 throw new RestException(503,
'Error when retrieve member list : '.$this->db->lasterror());
294 public function post($request_data =
null)
296 if (!DolibarrApiAccess::$user->hasRight(
'adherent',
'creer')) {
297 throw new RestException(403);
300 $result = $this->
_validate($request_data);
303 foreach ($request_data as $field => $value) {
304 if ($field ===
'caller') {
306 $member->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
312 if ($member->create(DolibarrApiAccess::$user) < 0) {
313 throw new RestException(500,
'Error creating member', array_merge(array($member->error), $member->errors));
329 public function put($id, $request_data =
null)
331 if (!DolibarrApiAccess::$user->hasRight(
'adherent',
'creer')) {
332 throw new RestException(403);
336 $result = $member->fetch($id);
338 throw new RestException(404,
'member not found');
342 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
345 foreach ($request_data as $field => $value) {
346 if ($field ==
'id') {
349 if ($field ===
'caller') {
351 $member->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
354 if ($field ==
'array_options' && is_array($value)) {
355 foreach ($value as $index => $val) {
356 $member->array_options[$index] = $this->
_checkValForAPI($field, $val, $member);
362 if ($field ==
'statut') {
364 $result = $member->resiliate(DolibarrApiAccess::$user);
366 throw new RestException(500,
'Error when resiliating member: '.$member->error);
368 } elseif ($value ==
'1') {
369 $result = $member->validate(DolibarrApiAccess::$user);
371 throw new RestException(500,
'Error when validating member: '.$member->error);
373 } elseif ($value ==
'-2') {
374 $result = $member->exclude(DolibarrApiAccess::$user);
376 throw new RestException(500,
'Error when excluding member: '.$member->error);
386 if ($member->update(DolibarrApiAccess::$user) >= 0) {
387 return $this->
get($id);
389 throw new RestException(500,
'Error when updating member: '.$member->error);
403 public function delete($id)
405 if (!DolibarrApiAccess::$user->hasRight(
'adherent',
'supprimer')) {
406 throw new RestException(403);
409 $result = $member->fetch($id);
411 throw new RestException(404,
'member not found');
415 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
419 $res = $member->delete(DolibarrApiAccess::$user);
421 throw new RestException(500,
"Can't delete, error occurs");
427 'message' =>
'Member deleted'
444 $mandatoryfields = array(
448 foreach ($mandatoryfields as $field) {
449 if (!isset($data[$field])) {
450 throw new RestException(400,
"$field field missing");
452 $member[$field] = $data[$field];
473 unset(
$object->label_incoterms);
474 unset(
$object->location_incoterms);
475 unset(
$object->fk_delivery_address);
476 unset(
$object->shipping_method_id);
481 unset(
$object->total_localtax1);
482 unset(
$object->total_localtax2);
486 unset(
$object->linkedObjectsIds);
501 unset(
$object->barcode_type_code);
502 unset(
$object->barcode_type_label);
503 unset(
$object->barcode_type_coder);
504 unset(
$object->mode_reglement_id);
505 unset(
$object->cond_reglement_id);
506 unset(
$object->cond_reglement);
507 unset(
$object->fk_delivery_address);
508 unset(
$object->shipping_method_id);
514 unset(
$object->label_incoterms);
515 unset(
$object->location_incoterms);
522 unset(
$object->total_localtax1);
523 unset(
$object->total_localtax2);
545 if (!DolibarrApiAccess::$user->hasRight(
'adherent',
'cotisation',
'lire')) {
546 throw new RestException(403);
550 $result = $member->fetch($id);
552 throw new RestException(404,
'member not found');
556 foreach ($member->subscriptions as $subscription) {
579 if (!DolibarrApiAccess::$user->hasRight(
'adherent',
'cotisation',
'creer')) {
580 throw new RestException(403);
584 $result = $member->fetch($id);
586 throw new RestException(404,
'member not found');
589 return $member->subscription($start_date, $amount, 0,
'', $label,
'',
'',
'', $end_date);
609 public function getCategories($id, $sortfield =
"s.rowid", $sortorder =
'ASC', $limit = 0, $page = 0)
611 if (!DolibarrApiAccess::$user->hasRight(
'categorie',
'lire')) {
612 throw new RestException(403);
617 $result = $categories->getListForItem($id,
'member', $sortfield, $sortorder, $limit, $page);
620 throw new RestException(503,
'Error when retrieve category list : '.$categories->error);
644 if (!DolibarrApiAccess::$user->hasRight(
'adherent',
'lire')) {
645 throw new RestException(403);
649 $result = $membertype->fetch($id);
651 throw new RestException(404,
'member type not found');
655 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
680 public function indexType($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $sqlfilters =
'', $properties =
'')
684 if (!DolibarrApiAccess::$user->hasRight(
'adherent',
'lire')) {
685 throw new RestException(403);
688 $sql =
"SELECT t.rowid";
689 $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)";
690 $sql .=
' WHERE t.entity IN ('.getEntity(
'member_type').
')';
697 throw new RestException(503,
'Error when validating parameter sqlfilters -> '.$errormessage);
701 $sql .= $this->db->order($sortfield, $sortorder);
706 $offset = $limit * $page;
708 $sql .= $this->db->plimit($limit + 1, $offset);
711 $result = $this->db->query($sql);
714 $num = $this->db->num_rows($result);
715 $min = min($num, ($limit <= 0 ? $num : $limit));
717 $obj = $this->db->fetch_object($result);
719 if ($membertype->fetch($obj->rowid)) {
725 throw new RestException(503,
'Error when retrieve member type list : '.$this->db->lasterror());
744 if (!DolibarrApiAccess::$user->hasRight(
'adherent',
'configurer')) {
745 throw new RestException(403);
751 foreach ($request_data as $field => $value) {
752 if ($field ===
'caller') {
754 $membertype->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
758 $membertype->$field = $this->
_checkValForAPI($field, $value, $membertype);
760 if ($membertype->create(DolibarrApiAccess::$user) < 0) {
761 throw new RestException(500,
'Error creating member type', array_merge(array($membertype->error), $membertype->errors));
763 return $membertype->id;
779 public function putType($id, $request_data =
null)
781 if (!DolibarrApiAccess::$user->hasRight(
'adherent',
'configurer')) {
782 throw new RestException(403);
786 $result = $membertype->fetch($id);
788 throw new RestException(404,
'member type not found');
792 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
795 foreach ($request_data as $field => $value) {
796 if ($field ==
'id') {
799 if ($field ===
'caller') {
801 $membertype->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
804 if ($field ==
'array_options' && is_array($value)) {
805 foreach ($value as $index => $val) {
806 $membertype->array_options[$index] = $val;
812 $membertype->$field = $this->
_checkValForAPI($field, $value, $membertype);
817 if ($membertype->update(DolibarrApiAccess::$user) >= 0) {
818 return $this->
get($id);
820 throw new RestException(500,
'Error when updating member type: '.$membertype->error);
838 if (!DolibarrApiAccess::$user->hasRight(
'adherent',
'configurer')) {
839 throw new RestException(403);
842 $result = $membertype->fetch($id);
844 throw new RestException(404,
'member type not found');
848 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
851 $res = $membertype->delete(DolibarrApiAccess::$user);
853 throw new RestException(500,
"Can't delete, error occurs");
859 'message' =>
'Member type deleted'
874 $membertype = array();
876 $mandatoryfields = array(
'label');
878 foreach ($mandatoryfields as $field) {
879 if (!isset($data[$field])) {
880 throw new RestException(400,
"$field field missing");
882 $membertype[$field] = $data[$field];
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Class to manage members of a foundation.
Class to manage members type.
Class to manage categories.
_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.
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.
_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.
__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.
indexType($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $sqlfilters='', $properties='')
List members types.
getSubscriptions($id)
List subscriptions of a member.
post($request_data=null)
Create member object.
index($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $typeid='', $category=0, $sqlfilters='', $properties='')
List members.
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.