21 use Luracast\Restler\RestException;
23 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
24 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
25 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/subscription.class.php';
26 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
39 public static $FIELDS = array(
63 public function get($id)
65 if (!DolibarrApiAccess::$user->rights->adherent->lire) {
66 throw new RestException(401);
71 $result = $member->initAsSpecimen();
73 $result = $member->fetch($id);
76 throw new RestException(404,
'member not found');
80 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
102 if (!DolibarrApiAccess::$user->rights->adherent->lire) {
103 throw new RestException(401);
107 $result = $member->fetch(
'',
'', $thirdparty);
109 throw new RestException(404,
'member not found');
113 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
135 if (!DolibarrApiAccess::$user->rights->adherent->lire) {
136 throw new RestException(401);
140 $result = $thirdparty->fetch(
'',
'',
'',
'',
'',
'',
'',
'',
'',
'', $email);
142 throw new RestException(404,
'thirdparty not found');
146 $result = $member->fetch(
'',
'', $thirdparty->id);
148 throw new RestException(404,
'member not found');
152 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
174 if (!DolibarrApiAccess::$user->rights->adherent->lire) {
175 throw new RestException(401);
179 $result = $thirdparty->fetch(
'',
'',
'', $barcode);
181 throw new RestException(404,
'thirdparty not found');
185 $result = $member->fetch(
'',
'', $thirdparty->id);
187 throw new RestException(404,
'member not found');
191 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
214 public function index($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $typeid =
'', $category = 0, $sqlfilters =
'')
220 if (!DolibarrApiAccess::$user->rights->adherent->lire) {
221 throw new RestException(401);
224 $sql =
"SELECT t.rowid";
225 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent as t";
227 $sql .=
", ".MAIN_DB_PREFIX.
"categorie_member as c";
229 $sql .=
' WHERE t.entity IN ('.getEntity(
'adherent').
')';
230 if (!empty($typeid)) {
231 $sql .=
' AND t.fk_adherent_type='.((int) $typeid);
235 $sql .=
" AND c.fk_categorie = ".((int) $category);
236 $sql .=
" AND c.fk_member = t.rowid";
242 throw new RestException(503,
'Error when validating parameter sqlfilters -> '.$errormessage);
244 $regexstring =
'\(([^:\'\(\)]+:[^:\'\(\)]+:[^\(\)]+)\)';
245 $sql .=
" AND (".preg_replace_callback(
'/'.$regexstring.
'/',
'DolibarrApi::_forge_criteria_callback', $sqlfilters).
")";
248 $sql .= $this->
db->order($sortfield, $sortorder);
253 $offset = $limit * $page;
255 $sql .= $this->
db->plimit($limit + 1, $offset);
258 $result = $this->
db->query($sql);
261 $num = $this->
db->num_rows($result);
262 $min = min($num, ($limit <= 0 ? $num : $limit));
264 $obj = $this->
db->fetch_object($result);
266 if ($member->fetch($obj->rowid)) {
272 throw new RestException(503,
'Error when retrieve member list : '.$this->
db->lasterror());
274 if (!count($obj_ret)) {
275 throw new RestException(404,
'No member found');
287 public function post($request_data = null)
289 if (!DolibarrApiAccess::$user->rights->adherent->creer) {
290 throw new RestException(401);
293 $result = $this->
_validate($request_data);
296 foreach ($request_data as $field => $value) {
297 $member->$field = $value;
299 if ($member->create(DolibarrApiAccess::$user) < 0) {
300 throw new RestException(500,
'Error creating member', array_merge(array($member->error), $member->errors));
312 public function put($id, $request_data = null)
314 if (!DolibarrApiAccess::$user->rights->adherent->creer) {
315 throw new RestException(401);
319 $result = $member->fetch($id);
321 throw new RestException(404,
'member not found');
325 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
328 foreach ($request_data as $field => $value) {
329 if ($field ==
'id') {
334 if ($field ==
'statut') {
336 $result = $member->resiliate(DolibarrApiAccess::$user);
338 throw new RestException(500,
'Error when resiliating member: '.$member->error);
340 } elseif ($value ==
'1') {
341 $result = $member->validate(DolibarrApiAccess::$user);
343 throw new RestException(500,
'Error when validating member: '.$member->error);
345 } elseif ($value ==
'-2') {
346 $result = $member->exclude(DolibarrApiAccess::$user);
348 throw new RestException(500,
'Error when excluding member: '.$member->error);
352 $member->$field = $value;
358 if ($member->update(DolibarrApiAccess::$user) >= 0) {
359 return $this->
get($id);
361 throw new RestException(500,
'Error when updating member: '.$member->error);
371 public function delete($id)
373 if (!DolibarrApiAccess::$user->rights->adherent->supprimer) {
374 throw new RestException(401);
377 $result = $member->fetch($id);
379 throw new RestException(404,
'member not found');
383 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
386 if (!$member->delete($member->id, DolibarrApiAccess::$user)) {
387 throw new RestException(401,
'error when deleting member');
393 'message' =>
'member deleted'
409 foreach (Members::$FIELDS as $field) {
410 if (!isset($data[$field])) {
411 throw new RestException(400,
"$field field missing");
413 $member[$field] = $data[$field];
428 $object = parent::_cleanObjectDatas($object);
431 unset($object->subscriptions);
432 unset($object->fk_incoterms);
433 unset($object->label_incoterms);
434 unset($object->location_incoterms);
435 unset($object->fk_delivery_address);
436 unset($object->shipping_method_id);
438 unset($object->total_ht);
439 unset($object->total_ttc);
440 unset($object->total_tva);
441 unset($object->total_localtax1);
442 unset($object->total_localtax2);
463 if (!DolibarrApiAccess::$user->rights->adherent->cotisation->lire) {
464 throw new RestException(401);
468 $result = $member->fetch($id);
470 throw new RestException(404,
'member not found');
474 foreach ($member->subscriptions as $subscription) {
494 if (!DolibarrApiAccess::$user->rights->adherent->cotisation->creer) {
495 throw new RestException(401);
499 $result = $member->fetch($id);
501 throw new RestException(404,
'member not found');
504 return $member->subscription($start_date, $amount, 0,
'', $label,
'',
'',
'', $end_date);
520 public function getCategories($id, $sortfield =
"s.rowid", $sortorder =
'ASC', $limit = 0, $page = 0)
522 if (!DolibarrApiAccess::$user->rights->categorie->lire) {
523 throw new RestException(401);
528 $result = $categories->getListForItem($id,
'member', $sortfield, $sortorder, $limit, $page);
530 if (empty($result)) {
531 throw new RestException(404,
'No category found');
535 throw new RestException(503,
'Error when retrieve category list : '.$categories->error);
post($request_data=null)
Create member object.
createSubscription($id, $start_date, $end_date, $amount, $label= '')
Add a subscription for a member.
$conf db
API class for accounts.
put($id, $request_data=null)
Update member.
_validate($data)
Validate fields before creating an object.
getByThirdpartyBarcode($barcode)
Get properties of a member object by linked thirdparty barcode.
getByThirdparty($thirdparty)
Get properties of a member object by linked thirdparty.
_checkFilters($sqlfilters, &$error= '')
Return if a $sqlfilters parameter is valid.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage categories.
getSubscriptions($id)
List subscriptions of a member.
getCategories($id, $sortfield="s.rowid", $sortorder= 'ASC', $limit=0, $page=0)
Get categories for a member.
Class to manage members of a foundation.
__construct()
Constructor.
static _checkAccessToResource($resource, $resource_id=0, $dbtablename= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid')
Check access by user to a given resource.
getByThirdpartyEmail($email)
Get properties of a member object by linked thirdparty email.
index($sortfield="t.rowid", $sortorder= 'ASC', $limit=100, $page=0, $typeid= '', $category=0, $sqlfilters= '')
List members.
_cleanObjectDatas($object)
Clean sensible object datas.