64 public function get($id)
66 if (!DolibarrApiAccess::$user->rights->agenda->myactions->read) {
67 throw new RestException(401,
"Insufficient rights to read an event");
70 $result = $this->actioncomm->initAsSpecimen();
72 $result = $this->actioncomm->fetch($id);
74 $this->actioncomm->fetch_optionals();
75 $this->actioncomm->fetchObjectLinked();
79 throw new RestException(404,
'Agenda Events not found');
82 if (!DolibarrApiAccess::$user->rights->agenda->allactions->read && $this->actioncomm->userownerid != DolibarrApiAccess::$user->id) {
83 throw new RestException(401,
'Insufficient rights to read event of this owner id. Your id is '.DolibarrApiAccess::$user->
id);
87 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 =
'', $sqlfilters =
'', $properties =
'')
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());
205 public function post($request_data =
null)
207 if (!DolibarrApiAccess::$user->rights->agenda->myactions->create) {
208 throw new RestException(401,
"Insufficient rights to create your Agenda Event");
210 if (!DolibarrApiAccess::$user->hasRight(
'agenda',
'allactions',
'create') && DolibarrApiAccess::$user->
id != $request_data[
'userownerid']) {
211 throw new RestException(401,
"Insufficient rights to create an Agenda Event for owner id ".$request_data[
'userownerid'].
' Your id is '.DolibarrApiAccess::$user->
id);
215 $result = $this->
_validate($request_data);
217 foreach ($request_data as $field => $value) {
218 if ($field ===
'caller') {
220 $this->actioncomm->context[
'caller'] = $request_data[
'caller'];
224 $this->actioncomm->$field = $this->
_checkValForAPI($field, $value, $this->actioncomm);
234 if ($this->actioncomm->create(DolibarrApiAccess::$user) < 0) {
235 throw new RestException(500,
"Error creating event", array_merge(array($this->actioncomm->error), $this->actioncomm->errors));
238 return $this->actioncomm->id;
250 public function put($id, $request_data =
null)
252 if (!DolibarrApiAccess::$user->rights->agenda->myactions->create) {
253 throw new RestException(401,
"Insufficient rights to create your Agenda Event");
255 if (!DolibarrApiAccess::$user->hasRight(
'agenda',
'allactions',
'create') && DolibarrApiAccess::$user->
id != $request_data[
'userownerid']) {
256 throw new RestException(401,
"Insufficient rights to create an Agenda Event for owner id ".$request_data[
'userownerid'].
' Your id is '.DolibarrApiAccess::$user->
id);
259 $result = $this->actioncomm->fetch($id);
261 $this->actioncomm->fetch_optionals();
262 $this->actioncomm->fetch_userassigned();
263 $this->actioncomm->oldcopy = clone $this->actioncomm;
266 throw new RestException(404,
'actioncomm not found');
270 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
272 foreach ($request_data as $field => $value) {
273 if ($field ==
'id') {
276 if ($field ===
'caller') {
278 $this->actioncomm->context[
'caller'] = $request_data[
'caller'];
282 $this->actioncomm->$field = $this->
_checkValForAPI($field, $value, $this->actioncomm);
285 if ($this->actioncomm->update(DolibarrApiAccess::$user, 1) > 0) {
286 return $this->
get($id);
299 public function delete($id)
301 if (!DolibarrApiAccess::$user->hasRight(
'agenda',
'myactions',
'delete')) {
302 throw new RestException(401,
"Insufficient rights to delete your Agenda Event");
305 $result = $this->actioncomm->fetch($id);
307 $this->actioncomm->fetch_optionals();
308 $this->actioncomm->fetch_userassigned();
309 $this->actioncomm->oldcopy = clone $this->actioncomm;
312 if (!DolibarrApiAccess::$user->rights->agenda->allactions->delete && DolibarrApiAccess::$user->id != $this->actioncomm->userownerid) {
313 throw new RestException(401,
"Insufficient rights to delete an Agenda Event of owner id ".$this->actioncomm->userownerid.
' Your id is '.DolibarrApiAccess::$user->id);
317 throw new RestException(404,
'Agenda Event not found');
321 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
324 if (!$this->actioncomm->delete(DolibarrApiAccess::$user)) {
325 throw new RestException(500,
'Error when delete Agenda Event : '.$this->actioncomm->error);
331 'message' =>
'Agenda Event deleted'
365 $object = parent::_cleanObjectDatas($object);
367 unset($object->note);
368 unset($object->usermod);
369 unset($object->libelle);
370 unset($object->context);
371 unset($object->canvas);
372 unset($object->contact);
373 unset($object->contact_id);
374 unset($object->thirdparty);
375 unset($object->user);
376 unset($object->origin);
377 unset($object->origin_id);
378 unset($object->ref_ext);
379 unset($object->statut);
380 unset($object->state_code);
381 unset($object->state_id);
382 unset($object->state);
383 unset($object->region);
384 unset($object->region_code);
385 unset($object->country);
386 unset($object->country_id);
387 unset($object->country_code);
388 unset($object->barcode_type);
389 unset($object->barcode_type_code);
390 unset($object->barcode_type_label);
391 unset($object->barcode_type_coder);
392 unset($object->mode_reglement_id);
393 unset($object->cond_reglement_id);
394 unset($object->cond_reglement);
395 unset($object->fk_delivery_address);
396 unset($object->shipping_method_id);
397 unset($object->fk_account);
398 unset($object->total_ht);
399 unset($object->total_tva);
400 unset($object->total_localtax1);
401 unset($object->total_localtax2);
402 unset($object->total_ttc);
403 unset($object->fk_incoterms);
404 unset($object->label_incoterms);
405 unset($object->location_incoterms);
406 unset($object->name);
407 unset($object->lastname);
408 unset($object->firstname);
409 unset($object->civility_id);
410 unset($object->contact);
411 unset($object->societe);
412 unset($object->demand_reason_id);
413 unset($object->transport_mode_id);
414 unset($object->region_id);
415 unset($object->actions);
416 unset($object->lines);