65 public function get($id)
67 if (!DolibarrApiAccess::$user->rights->agenda->myactions->read) {
68 throw new RestException(401,
"Insufficient rights to read an event");
71 $result = $this->actioncomm->initAsSpecimen();
73 $result = $this->actioncomm->fetch($id);
75 $this->actioncomm->fetch_optionals();
76 $this->actioncomm->fetchObjectLinked();
80 throw new RestException(404,
'Agenda Events not found');
83 if (!DolibarrApiAccess::$user->rights->agenda->allactions->read && $this->actioncomm->userownerid != DolibarrApiAccess::$user->id) {
84 throw new RestException(401,
"Insufficient rights to read event for owner id ".$request_data[
'userownerid'].
' Your id is '.DolibarrApiAccess::$user->
id);
88 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
106 public function index($sortfield =
"t.id", $sortorder =
'ASC', $limit = 100, $page = 0, $user_ids = 0, $sqlfilters =
'')
112 if (!DolibarrApiAccess::$user->rights->agenda->myactions->read) {
113 throw new RestException(401,
"Insufficient rights to read events");
118 if (!empty(DolibarrApiAccess::$user->socid)) {
119 $socid = DolibarrApiAccess::$user->socid;
124 if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) {
125 $search_sale = DolibarrApiAccess::$user->id;
127 if (!isModEnabled(
'societe')) {
131 $sql =
"SELECT t.id as rowid";
132 if (isModEnabled(
"societe")) {
133 if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
134 $sql .=
", sc.fk_soc, sc.fk_user";
137 $sql .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm AS t LEFT JOIN ".MAIN_DB_PREFIX.
"actioncomm_extrafields AS ef ON (ef.fk_object = t.id)";
138 if (isModEnabled(
"societe")) {
139 if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
140 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
143 $sql .=
' WHERE t.entity IN ('.getEntity(
'agenda').
')';
144 if (isModEnabled(
"societe")) {
145 if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) {
146 $sql .=
" AND t.fk_soc = sc.fk_soc";
150 $sql .=
" AND t.fk_user_action IN (".$this->db->sanitize($user_ids).
")";
153 $sql .=
" AND t.fk_soc = ".((int) $socid);
156 if ($search_sale > 0) {
157 $sql .=
" AND sc.fk_user = ".((int) $search_sale);
164 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
168 $sql .= $this->db->order($sortfield, $sortorder);
173 $offset = $limit * $page;
175 $sql .= $this->db->plimit($limit + 1, $offset);
178 $result = $this->db->query($sql);
182 $num = $this->db->num_rows($result);
183 $min = min($num, ($limit <= 0 ? $num : $limit));
185 $obj = $this->db->fetch_object($result);
186 $actioncomm_static =
new ActionComm($this->db);
187 if ($actioncomm_static->fetch($obj->rowid)) {
193 throw new RestException(503,
'Error when retrieve Agenda Event list : '.$this->db->lasterror());
195 if (!count($obj_ret)) {
196 throw new RestException(404,
'No Agenda Event found');
207 public function post($request_data =
null)
209 if (!DolibarrApiAccess::$user->rights->agenda->myactions->create) {
210 throw new RestException(401,
"Insufficient rights to create your Agenda Event");
212 if (!DolibarrApiAccess::$user->hasRight(
'agenda',
'allactions',
'create') && DolibarrApiAccess::$user->
id != $request_data[
'userownerid']) {
213 throw new RestException(401,
"Insufficient rights to create an Agenda Event for owner id ".$request_data[
'userownerid'].
' Your id is '.DolibarrApiAccess::$user->
id);
217 $result = $this->
_validate($request_data);
219 foreach ($request_data as $field => $value) {
220 $this->actioncomm->$field = $this->
_checkValForAPI($field, $value, $this->actioncomm);
230 if ($this->actioncomm->create(DolibarrApiAccess::$user) < 0) {
231 throw new RestException(500,
"Error creating event", array_merge(array($this->actioncomm->error), $this->actioncomm->errors));
234 return $this->actioncomm->id;
246 public function put($id, $request_data =
null)
248 if (!DolibarrApiAccess::$user->rights->agenda->myactions->create) {
249 throw new RestException(401,
"Insufficient rights to create your Agenda Event");
251 if (!DolibarrApiAccess::$user->hasRight(
'agenda',
'allactions',
'create') && DolibarrApiAccess::$user->
id != $request_data[
'userownerid']) {
252 throw new RestException(401,
"Insufficient rights to create an Agenda Event for owner id ".$request_data[
'userownerid'].
' Your id is '.DolibarrApiAccess::$user->
id);
255 $result = $this->actioncomm->fetch($id);
257 $this->actioncomm->fetch_optionals();
258 $this->actioncomm->fetch_userassigned();
259 $this->actioncomm->oldcopy = clone $this->actioncomm;
262 throw new RestException(404,
'actioncomm not found');
266 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
268 foreach ($request_data as $field => $value) {
269 if ($field ==
'id') {
273 if ($field ==
'array_options' && is_array($value)) {
274 foreach ($value as $index => $val) {
275 $this->actioncomm->array_options[$index] = $this->
_checkValForAPI($field, $val, $this->actioncomm);
279 $this->actioncomm->$field = $this->
_checkValForAPI($field, $value, $this->actioncomm);
282 if ($this->actioncomm->update(DolibarrApiAccess::$user, 1) > 0) {
283 return $this->
get($id);
296 public function delete($id)
298 if (!DolibarrApiAccess::$user->hasRight(
'agenda',
'myactions',
'delete')) {
299 throw new RestException(401,
"Insufficient rights to delete your Agenda Event");
302 $result = $this->actioncomm->fetch($id);
304 $this->actioncomm->fetch_optionals();
305 $this->actioncomm->fetch_userassigned();
306 $this->actioncomm->oldcopy = clone $this->actioncomm;
309 if (!DolibarrApiAccess::$user->rights->agenda->allactions->delete && DolibarrApiAccess::$user->id != $this->actioncomm->userownerid) {
310 throw new RestException(401,
"Insufficient rights to delete an Agenda Event of owner id ".$this->actioncomm->userownerid.
' Your id is '.DolibarrApiAccess::$user->id);
314 throw new RestException(404,
'Agenda Event not found');
318 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
321 if (!$this->actioncomm->delete(DolibarrApiAccess::$user)) {
322 throw new RestException(500,
'Error when delete Agenda Event : '.$this->actioncomm->error);
328 'message' =>
'Agenda Event deleted'
362 $object = parent::_cleanObjectDatas($object);
364 unset($object->note);
365 unset($object->usermod);
366 unset($object->libelle);
367 unset($object->context);
368 unset($object->canvas);
369 unset($object->contact);
370 unset($object->contact_id);
371 unset($object->thirdparty);
372 unset($object->user);
373 unset($object->origin);
374 unset($object->origin_id);
375 unset($object->ref_ext);
376 unset($object->statut);
377 unset($object->state_code);
378 unset($object->state_id);
379 unset($object->state);
380 unset($object->region);
381 unset($object->region_code);
382 unset($object->country);
383 unset($object->country_id);
384 unset($object->country_code);
385 unset($object->barcode_type);
386 unset($object->barcode_type_code);
387 unset($object->barcode_type_label);
388 unset($object->barcode_type_coder);
389 unset($object->mode_reglement_id);
390 unset($object->cond_reglement_id);
391 unset($object->cond_reglement);
392 unset($object->fk_delivery_address);
393 unset($object->shipping_method_id);
394 unset($object->fk_account);
395 unset($object->total_ht);
396 unset($object->total_tva);
397 unset($object->total_localtax1);
398 unset($object->total_localtax2);
399 unset($object->total_ttc);
400 unset($object->fk_incoterms);
401 unset($object->label_incoterms);
402 unset($object->location_incoterms);
403 unset($object->name);
404 unset($object->lastname);
405 unset($object->firstname);
406 unset($object->civility_id);
407 unset($object->contact);
408 unset($object->societe);
409 unset($object->demand_reason_id);
410 unset($object->transport_mode_id);
411 unset($object->region_id);
412 unset($object->actions);
413 unset($object->lines);
414 unset($object->modelpdf);