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 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='.$typeid;
235 $sql .=
" AND c.fk_categorie = ".$this->db->escape($category);
236 $sql .=
" AND c.fk_member = t.rowid ";
241 throw new RestException(503,
'Error when validating parameter sqlfilters '.$sqlfilters);
243 $regexstring =
'\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
244 $sql .=
" AND (".preg_replace_callback(
'/'.$regexstring.
'/',
'DolibarrApi::_forge_criteria_callback', $sqlfilters).
")";
247 $sql .= $this->
db->order($sortfield, $sortorder);
252 $offset = $limit * $page;
254 $sql .= $this->
db->plimit($limit + 1, $offset);
257 $result = $this->
db->query($sql);
260 $num = $this->
db->num_rows($result);
261 $min = min($num, ($limit <= 0 ? $num : $limit));
263 $obj = $this->
db->fetch_object($result);
265 if ($member->fetch($obj->rowid)) {
271 throw new RestException(503,
'Error when retrieve member list : '.$this->
db->lasterror());
273 if (!count($obj_ret)) {
274 throw new RestException(404,
'No member found');
286 public function post($request_data = null)
288 if (!DolibarrApiAccess::$user->rights->adherent->creer) {
289 throw new RestException(401);
292 $result = $this->
_validate($request_data);
295 foreach ($request_data as $field => $value) {
296 $member->$field = $value;
298 if ($member->create(DolibarrApiAccess::$user) < 0) {
299 throw new RestException(500,
'Error creating member', array_merge(array($member->error), $member->errors));
311 public function put($id, $request_data = null)
313 if (!DolibarrApiAccess::$user->rights->adherent->creer) {
314 throw new RestException(401);
318 $result = $member->fetch($id);
320 throw new RestException(404,
'member not found');
324 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
327 foreach ($request_data as $field => $value) {
328 if ($field ==
'id')
continue;
331 if ($field ==
'statut') {
333 $result = $member->resiliate(DolibarrApiAccess::$user);
335 throw new RestException(500,
'Error when resiliating member: '.$member->error);
337 } elseif ($value ==
'1') {
338 $result = $member->validate(DolibarrApiAccess::$user);
340 throw new RestException(500,
'Error when validating member: '.$member->error);
344 $member->$field = $value;
350 if ($member->update(DolibarrApiAccess::$user) >= 0) {
351 return $this->
get($id);
353 throw new RestException(500, $member->error);
363 public function delete($id)
365 if (!DolibarrApiAccess::$user->rights->adherent->supprimer) {
366 throw new RestException(401);
369 $result = $member->fetch($id);
371 throw new RestException(404,
'member not found');
375 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
378 if (!$member->delete($member->id, DolibarrApiAccess::$user)) {
379 throw new RestException(401,
'error when deleting member');
385 'message' =>
'member deleted'
401 foreach (Members::$FIELDS as $field) {
402 if (!isset($data[$field]))
403 throw new RestException(400,
"$field field missing");
404 $member[$field] = $data[$field];
419 $object = parent::_cleanObjectDatas($object);
422 unset($object->subscriptions);
423 unset($object->fk_incoterms);
424 unset($object->label_incoterms);
425 unset($object->location_incoterms);
426 unset($object->fk_delivery_address);
427 unset($object->shipping_method_id);
429 unset($object->total_ht);
430 unset($object->total_ttc);
431 unset($object->total_tva);
432 unset($object->total_localtax1);
433 unset($object->total_localtax2);
454 if (!DolibarrApiAccess::$user->rights->adherent->cotisation->lire) {
455 throw new RestException(401);
459 $result = $member->fetch($id);
461 throw new RestException(404,
'member not found');
465 foreach ($member->subscriptions as $subscription) {
485 if (!DolibarrApiAccess::$user->rights->adherent->cotisation->creer) {
486 throw new RestException(401);
490 $result = $member->fetch($id);
492 throw new RestException(404,
'member not found');
495 return $member->subscription($start_date, $amount, 0,
'', $label,
'',
'',
'', $end_date);
511 public function getCategories($id, $sortfield =
"s.rowid", $sortorder =
'ASC', $limit = 0, $page = 0)
513 if (!DolibarrApiAccess::$user->rights->categorie->lire) {
514 throw new RestException(401);
519 $result = $categories->getListForItem($id,
'member', $sortfield, $sortorder, $limit, $page);
521 if (empty($result)) {
522 throw new RestException(404,
'No category found');
526 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.
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.
$conf db
API class for accounts.
_checkFilters($sqlfilters)
Return if a $sqlfilters parameter is valid.
getByThirdparty($thirdparty)
Get properties of a member object by linked thirdparty.
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 user access to a 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.