90 public function index($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $sqlfilters =
'', $properties =
'')
96 if (!DolibarrApiAccess::$user->hasRight(
'adherent',
'lire')) {
97 throw new RestException(401);
100 $sql =
"SELECT t.rowid";
101 $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)";
102 $sql .=
' WHERE t.entity IN ('.getEntity(
'member_type').
')';
109 throw new RestException(503,
'Error when validating parameter sqlfilters -> '.$errormessage);
113 $sql .= $this->db->order($sortfield, $sortorder);
118 $offset = $limit * $page;
120 $sql .= $this->db->plimit($limit + 1, $offset);
123 $result = $this->db->query($sql);
126 $num = $this->db->num_rows($result);
127 $min = min($num, ($limit <= 0 ? $num : $limit));
129 $obj = $this->db->fetch_object($result);
131 if ($membertype->fetch($obj->rowid)) {
137 throw new RestException(503,
'Error when retrieve member type list : '.$this->db->lasterror());
149 public function post($request_data =
null)
151 if (!DolibarrApiAccess::$user->hasRight(
'adherent',
'configurer')) {
152 throw new RestException(401);
155 $result = $this->
_validate($request_data);
158 foreach ($request_data as $field => $value) {
159 if ($field ===
'caller') {
161 $membertype->context[
'caller'] = $request_data[
'caller'];
165 $membertype->$field = $value;
167 if ($membertype->create(DolibarrApiAccess::$user) < 0) {
168 throw new RestException(500,
'Error creating member type', array_merge(array($membertype->error), $membertype->errors));
170 return $membertype->id;
180 public function put($id, $request_data =
null)
182 if (!DolibarrApiAccess::$user->hasRight(
'adherent',
'configurer')) {
183 throw new RestException(401);
187 $result = $membertype->fetch($id);
189 throw new RestException(404,
'member type not found');
193 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
196 foreach ($request_data as $field => $value) {
197 if ($field ==
'id') {
200 if ($field ===
'caller') {
202 $membertype->context[
'caller'] = $request_data[
'caller'];
208 $membertype->$field = $value;
213 if ($membertype->update(DolibarrApiAccess::$user) >= 0) {
214 return $this->
get($id);
216 throw new RestException(500,
'Error when updating member type: '.$membertype->error);
286 $object = parent::_cleanObjectDatas($object);
288 unset($object->array_options);
289 unset($object->linkedObjectsIds);
290 unset($object->context);
291 unset($object->canvas);
292 unset($object->fk_project);
293 unset($object->contact);
294 unset($object->contact_id);
295 unset($object->thirdparty);
296 unset($object->user);
297 unset($object->origin);
298 unset($object->origin_id);
299 unset($object->ref_ext);
300 unset($object->country);
301 unset($object->country_id);
302 unset($object->country_code);
303 unset($object->barcode_type);
304 unset($object->barcode_type_code);
305 unset($object->barcode_type_label);
306 unset($object->barcode_type_coder);
307 unset($object->mode_reglement_id);
308 unset($object->cond_reglement_id);
309 unset($object->cond_reglement);
310 unset($object->fk_delivery_address);
311 unset($object->shipping_method_id);
312 unset($object->model_pdf);
313 unset($object->fk_account);
314 unset($object->note_public);
315 unset($object->note_private);
316 unset($object->fk_incoterms);
317 unset($object->label_incoterms);
318 unset($object->location_incoterms);
319 unset($object->name);
320 unset($object->lastname);
321 unset($object->firstname);
322 unset($object->civility_id);
323 unset($object->total_ht);
324 unset($object->total_tva);
325 unset($object->total_localtax1);
326 unset($object->total_localtax2);
327 unset($object->total_ttc);