89 public function index($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $sqlfilters =
'')
95 if (!DolibarrApiAccess::$user->hasRight(
'adherent',
'lire')) {
96 throw new RestException(401);
99 $sql =
"SELECT t.rowid";
100 $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)";
101 $sql .=
' WHERE t.entity IN ('.getEntity(
'member_type').
')';
108 throw new RestException(503,
'Error when validating parameter sqlfilters -> '.$errormessage);
112 $sql .= $this->db->order($sortfield, $sortorder);
117 $offset = $limit * $page;
119 $sql .= $this->db->plimit($limit + 1, $offset);
122 $result = $this->db->query($sql);
125 $num = $this->db->num_rows($result);
126 $min = min($num, ($limit <= 0 ? $num : $limit));
128 $obj = $this->db->fetch_object($result);
130 if ($membertype->fetch($obj->rowid)) {
136 throw new RestException(503,
'Error when retrieve member type list : '.$this->db->lasterror());
138 if (!count($obj_ret)) {
139 throw new RestException(404,
'No member type found');
151 public function post($request_data =
null)
153 if (!DolibarrApiAccess::$user->hasRight(
'adherent',
'configurer')) {
154 throw new RestException(401);
157 $result = $this->
_validate($request_data);
160 foreach ($request_data as $field => $value) {
161 $membertype->$field = $value;
163 if ($membertype->create(DolibarrApiAccess::$user) < 0) {
164 throw new RestException(500,
'Error creating member type', array_merge(array($membertype->error), $membertype->errors));
166 return $membertype->id;
176 public function put($id, $request_data =
null)
178 if (!DolibarrApiAccess::$user->hasRight(
'adherent',
'configurer')) {
179 throw new RestException(401);
183 $result = $membertype->fetch($id);
185 throw new RestException(404,
'member type not found');
189 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
192 foreach ($request_data as $field => $value) {
193 if ($field ==
'id') {
198 $membertype->$field = $value;
203 if ($membertype->update(DolibarrApiAccess::$user) >= 0) {
204 return $this->
get($id);
206 throw new RestException(500,
'Error when updating member type: '.$membertype->error);
276 $object = parent::_cleanObjectDatas($object);
278 unset($object->array_options);
279 unset($object->linkedObjectsIds);
280 unset($object->context);
281 unset($object->canvas);
282 unset($object->fk_project);
283 unset($object->contact);
284 unset($object->contact_id);
285 unset($object->thirdparty);
286 unset($object->user);
287 unset($object->origin);
288 unset($object->origin_id);
289 unset($object->ref_ext);
290 unset($object->country);
291 unset($object->country_id);
292 unset($object->country_code);
293 unset($object->barcode_type);
294 unset($object->barcode_type_code);
295 unset($object->barcode_type_label);
296 unset($object->barcode_type_coder);
297 unset($object->mode_reglement_id);
298 unset($object->cond_reglement_id);
299 unset($object->cond_reglement);
300 unset($object->fk_delivery_address);
301 unset($object->shipping_method_id);
302 unset($object->model_pdf);
303 unset($object->fk_account);
304 unset($object->note_public);
305 unset($object->note_private);
306 unset($object->fk_incoterms);
307 unset($object->label_incoterms);
308 unset($object->location_incoterms);
309 unset($object->name);
310 unset($object->lastname);
311 unset($object->firstname);
312 unset($object->civility_id);
313 unset($object->total_ht);
314 unset($object->total_tva);
315 unset($object->total_localtax1);
316 unset($object->total_localtax2);
317 unset($object->total_ttc);