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());
292 public function post($request_data =
null)
294 if (!DolibarrApiAccess::$user->hasRight(
'adherent',
'creer')) {
295 throw new RestException(403);
298 $result = $this->
_validate($request_data);
301 foreach ($request_data as $field => $value) {
302 if ($field ===
'caller') {
304 $member->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
310 if ($member->create(DolibarrApiAccess::$user) < 0) {
311 throw new RestException(500,
'Error creating member', array_merge(array($member->error), $member->errors));
327 public function put($id, $request_data =
null)
329 if (!DolibarrApiAccess::$user->hasRight(
'adherent',
'creer')) {
330 throw new RestException(403);
334 $result = $member->fetch($id);
336 throw new RestException(404,
'member not found');
340 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
343 foreach ($request_data as $field => $value) {
344 if ($field ==
'id') {
347 if ($field ===
'caller') {
349 $member->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
352 if ($field ==
'array_options' && is_array($value)) {
353 foreach ($value as $index => $val) {
354 $member->array_options[$index] = $val;
360 if ($field ==
'statut') {
362 $result = $member->resiliate(DolibarrApiAccess::$user);
364 throw new RestException(500,
'Error when resiliating member: '.$member->error);
366 } elseif ($value ==
'1') {
367 $result = $member->validate(DolibarrApiAccess::$user);
369 throw new RestException(500,
'Error when validating member: '.$member->error);
371 } elseif ($value ==
'-2') {
372 $result = $member->exclude(DolibarrApiAccess::$user);
374 throw new RestException(500,
'Error when excluding member: '.$member->error);
384 if ($member->update(DolibarrApiAccess::$user) >= 0) {
385 return $this->
get($id);
387 throw new RestException(500,
'Error when updating member: '.$member->error);
401 public function delete($id)
403 if (!DolibarrApiAccess::$user->hasRight(
'adherent',
'supprimer')) {
404 throw new RestException(403);
407 $result = $member->fetch($id);
409 throw new RestException(404,
'member not found');
413 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
417 $res = $member->delete(DolibarrApiAccess::$user);
419 throw new RestException(500,
"Can't delete, error occurs");
425 'message' =>
'Member deleted'
442 $mandatoryfields = array(
446 foreach ($mandatoryfields as $field) {
447 if (!isset($data[$field])) {
448 throw new RestException(400,
"$field field missing");
450 $member[$field] = $data[$field];
471 unset(
$object->label_incoterms);
472 unset(
$object->location_incoterms);
473 unset(
$object->fk_delivery_address);
474 unset(
$object->shipping_method_id);
479 unset(
$object->total_localtax1);
480 unset(
$object->total_localtax2);
484 unset(
$object->linkedObjectsIds);
499 unset(
$object->barcode_type_code);
500 unset(
$object->barcode_type_label);
501 unset(
$object->barcode_type_coder);
502 unset(
$object->mode_reglement_id);
503 unset(
$object->cond_reglement_id);
504 unset(
$object->cond_reglement);
505 unset(
$object->fk_delivery_address);
506 unset(
$object->shipping_method_id);
512 unset(
$object->label_incoterms);
513 unset(
$object->location_incoterms);
520 unset(
$object->total_localtax1);
521 unset(
$object->total_localtax2);
543 if (!DolibarrApiAccess::$user->hasRight(
'adherent',
'cotisation',
'lire')) {
544 throw new RestException(403);
548 $result = $member->fetch($id);
550 throw new RestException(404,
'member not found');
554 foreach ($member->subscriptions as $subscription) {
577 if (!DolibarrApiAccess::$user->hasRight(
'adherent',
'cotisation',
'creer')) {
578 throw new RestException(403);
582 $result = $member->fetch($id);
584 throw new RestException(404,
'member not found');
587 return $member->subscription($start_date, $amount, 0,
'', $label,
'',
'',
'', $end_date);
607 public function getCategories($id, $sortfield =
"s.rowid", $sortorder =
'ASC', $limit = 0, $page = 0)
609 if (!DolibarrApiAccess::$user->hasRight(
'categorie',
'lire')) {
610 throw new RestException(403);
615 $result = $categories->getListForItem($id,
'member', $sortfield, $sortorder, $limit, $page);
618 throw new RestException(503,
'Error when retrieve category list : '.$categories->error);
642 if (!DolibarrApiAccess::$user->hasRight(
'adherent',
'lire')) {
643 throw new RestException(403);
647 $result = $membertype->fetch($id);
649 throw new RestException(404,
'member type not found');
653 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
678 public function indexType($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $sqlfilters =
'', $properties =
'')
682 if (!DolibarrApiAccess::$user->hasRight(
'adherent',
'lire')) {
683 throw new RestException(403);
686 $sql =
"SELECT t.rowid";
687 $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)";
688 $sql .=
' WHERE t.entity IN ('.getEntity(
'member_type').
')';
695 throw new RestException(503,
'Error when validating parameter sqlfilters -> '.$errormessage);
699 $sql .= $this->db->order($sortfield, $sortorder);
704 $offset = $limit * $page;
706 $sql .= $this->db->plimit($limit + 1, $offset);
709 $result = $this->db->query($sql);
712 $num = $this->db->num_rows($result);
713 $min = min($num, ($limit <= 0 ? $num : $limit));
715 $obj = $this->db->fetch_object($result);
717 if ($membertype->fetch($obj->rowid)) {
723 throw new RestException(503,
'Error when retrieve member type list : '.$this->db->lasterror());
742 if (!DolibarrApiAccess::$user->hasRight(
'adherent',
'configurer')) {
743 throw new RestException(403);
749 foreach ($request_data as $field => $value) {
750 if ($field ===
'caller') {
752 $membertype->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
756 $membertype->$field = $this->
_checkValForAPI($field, $value, $membertype);
758 if ($membertype->create(DolibarrApiAccess::$user) < 0) {
759 throw new RestException(500,
'Error creating member type', array_merge(array($membertype->error), $membertype->errors));
761 return $membertype->id;
777 public function putType($id, $request_data =
null)
779 if (!DolibarrApiAccess::$user->hasRight(
'adherent',
'configurer')) {
780 throw new RestException(403);
784 $result = $membertype->fetch($id);
786 throw new RestException(404,
'member type not found');
790 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
793 foreach ($request_data as $field => $value) {
794 if ($field ==
'id') {
797 if ($field ===
'caller') {
799 $membertype->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
802 if ($field ==
'array_options' && is_array($value)) {
803 foreach ($value as $index => $val) {
804 $membertype->array_options[$index] = $val;
810 $membertype->$field = $this->
_checkValForAPI($field, $value, $membertype);
815 if ($membertype->update(DolibarrApiAccess::$user) >= 0) {
816 return $this->
get($id);
818 throw new RestException(500,
'Error when updating member type: '.$membertype->error);
836 if (!DolibarrApiAccess::$user->hasRight(
'adherent',
'configurer')) {
837 throw new RestException(403);
840 $result = $membertype->fetch($id);
842 throw new RestException(404,
'member type not found');
846 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
849 $res = $membertype->delete(DolibarrApiAccess::$user);
851 throw new RestException(500,
"Can't delete, error occurs");
857 'message' =>
'Member type deleted'
872 $membertype = array();
874 $mandatoryfields = array(
'label');
876 foreach ($mandatoryfields as $field) {
877 if (!isset($data[$field])) {
878 throw new RestException(400,
"$field field missing");
880 $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.