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 $this->actioncomm->$field = $this->
_checkValForAPI($field, $value, $this->actioncomm);
276 if ($this->actioncomm->update(DolibarrApiAccess::$user, 1) > 0) {
277 return $this->
get($id);
290 public function delete($id)
292 if (!DolibarrApiAccess::$user->hasRight(
'agenda',
'myactions',
'delete')) {
293 throw new RestException(401,
"Insufficient rights to delete your Agenda Event");
296 $result = $this->actioncomm->fetch($id);
298 $this->actioncomm->fetch_optionals();
299 $this->actioncomm->fetch_userassigned();
300 $this->actioncomm->oldcopy = clone $this->actioncomm;
303 if (!DolibarrApiAccess::$user->rights->agenda->allactions->delete && DolibarrApiAccess::$user->id != $this->actioncomm->userownerid) {
304 throw new RestException(401,
"Insufficient rights to delete an Agenda Event of owner id ".$this->actioncomm->userownerid.
' Your id is '.DolibarrApiAccess::$user->id);
308 throw new RestException(404,
'Agenda Event not found');
312 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
315 if (!$this->actioncomm->delete(DolibarrApiAccess::$user)) {
316 throw new RestException(500,
'Error when delete Agenda Event : '.$this->actioncomm->error);
322 'message' =>
'Agenda Event deleted'
356 $object = parent::_cleanObjectDatas($object);
358 unset($object->note);
359 unset($object->usermod);
360 unset($object->libelle);
361 unset($object->context);
362 unset($object->canvas);
363 unset($object->contact);
364 unset($object->contact_id);
365 unset($object->thirdparty);
366 unset($object->user);
367 unset($object->origin);
368 unset($object->origin_id);
369 unset($object->ref_ext);
370 unset($object->statut);
371 unset($object->state_code);
372 unset($object->state_id);
373 unset($object->state);
374 unset($object->region);
375 unset($object->region_code);
376 unset($object->country);
377 unset($object->country_id);
378 unset($object->country_code);
379 unset($object->barcode_type);
380 unset($object->barcode_type_code);
381 unset($object->barcode_type_label);
382 unset($object->barcode_type_coder);
383 unset($object->mode_reglement_id);
384 unset($object->cond_reglement_id);
385 unset($object->cond_reglement);
386 unset($object->fk_delivery_address);
387 unset($object->shipping_method_id);
388 unset($object->fk_account);
389 unset($object->total_ht);
390 unset($object->total_tva);
391 unset($object->total_localtax1);
392 unset($object->total_localtax2);
393 unset($object->total_ttc);
394 unset($object->fk_incoterms);
395 unset($object->label_incoterms);
396 unset($object->location_incoterms);
397 unset($object->name);
398 unset($object->lastname);
399 unset($object->firstname);
400 unset($object->civility_id);
401 unset($object->contact);
402 unset($object->societe);
403 unset($object->demand_reason_id);
404 unset($object->transport_mode_id);
405 unset($object->region_id);
406 unset($object->actions);
407 unset($object->lines);
408 unset($object->modelpdf);