19 use Luracast\Restler\RestException;
21 require_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
36 static $FIELDS = array(
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;
131 $sql =
"SELECT t.id as rowid";
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";
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').
')';
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);
163 throw new RestException(503,
'Error when validating parameter sqlfilters -> '.$errormessage);
165 $regexstring =
'\(([^:\'\(\)]+:[^:\'\(\)]+:[^\(\)]+)\)';
166 $sql .=
" AND (".preg_replace_callback(
'/'.$regexstring.
'/',
'DolibarrApi::_forge_criteria_callback', $sqlfilters).
")";
169 $sql .= $this->
db->order($sortfield, $sortorder);
174 $offset = $limit * $page;
176 $sql .= $this->
db->plimit($limit + 1, $offset);
179 $result = $this->
db->query($sql);
183 $num = $this->
db->num_rows($result);
184 $min = min($num, ($limit <= 0 ? $num : $limit));
186 $obj = $this->
db->fetch_object($result);
188 if ($actioncomm_static->fetch($obj->rowid)) {
194 throw new RestException(503,
'Error when retrieve Agenda Event list : '.$this->
db->lasterror());
196 if (!count($obj_ret)) {
197 throw new RestException(404,
'No Agenda Event found');
208 public function post($request_data =
null)
210 if (!DolibarrApiAccess::$user->rights->agenda->myactions->create) {
211 throw new RestException(401,
"Insufficient rights to create your Agenda Event");
213 if (!DolibarrApiAccess::$user->hasRight(
'agenda',
'allactions',
'create') && DolibarrApiAccess::$user->
id != $request_data[
'userownerid']) {
214 throw new RestException(401,
"Insufficient rights to create an Agenda Event for owner id ".$request_data[
'userownerid'].
' Your id is '.DolibarrApiAccess::$user->
id);
218 $result = $this->
_validate($request_data);
220 foreach ($request_data as $field => $value) {
221 $this->actioncomm->$field = $this->
_checkValForAPI($field, $value, $this->actioncomm);
231 if ($this->actioncomm->create(DolibarrApiAccess::$user) < 0) {
232 throw new RestException(500,
"Error creating event", array_merge(array($this->actioncomm->error), $this->actioncomm->errors));
235 return $this->actioncomm->id;
247 public function put($id, $request_data =
null)
249 if (!DolibarrApiAccess::$user->rights->agenda->myactions->create) {
250 throw new RestException(401,
"Insufficient rights to create your Agenda Event");
252 if (!DolibarrApiAccess::$user->hasRight(
'agenda',
'allactions',
'create') && DolibarrApiAccess::$user->
id != $request_data[
'userownerid']) {
253 throw new RestException(401,
"Insufficient rights to create an Agenda Event for owner id ".$request_data[
'userownerid'].
' Your id is '.DolibarrApiAccess::$user->
id);
256 $result = $this->actioncomm->fetch($id);
258 $this->actioncomm->fetch_optionals();
259 $this->actioncomm->fetch_userassigned();
260 $this->actioncomm->oldcopy = clone $this->actioncomm;
263 throw new RestException(404,
'actioncomm not found');
267 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
269 foreach ($request_data as $field => $value) {
270 if ($field ==
'id') {
274 $this->actioncomm->$field = $this->
_checkValForAPI($field, $value, $this->actioncomm);
277 if ($this->actioncomm->update(DolibarrApiAccess::$user, 1) > 0) {
278 return $this->
get($id);
291 public function delete($id)
293 if (!DolibarrApiAccess::$user->rights->agenda->myactions->delete) {
294 throw new RestException(401,
"Insufficient rights to delete your Agenda Event");
297 $result = $this->actioncomm->fetch($id);
299 $this->actioncomm->fetch_optionals();
300 $this->actioncomm->fetch_userassigned();
301 $this->actioncomm->oldcopy = clone $this->actioncomm;
304 if (!DolibarrApiAccess::$user->rights->agenda->allactions->delete && DolibarrApiAccess::$user->id != $this->actioncomm->userownerid) {
305 throw new RestException(401,
"Insufficient rights to delete an Agenda Event of owner id ".$this->actioncomm->userownerid.
' Your id is '.DolibarrApiAccess::$user->id);
309 throw new RestException(404,
'Agenda Event not found');
313 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
316 if (!$this->actioncomm->delete(DolibarrApiAccess::$user)) {
317 throw new RestException(500,
'Error when delete Agenda Event : '.$this->actioncomm->error);
323 'message' =>
'Agenda Event deleted'
338 foreach (AgendaEvents::$FIELDS as $field) {
339 if (!isset($data[$field])) {
340 throw new RestException(400,
"$field field missing");
342 $event[$field] = $data[$field];
357 $object = parent::_cleanObjectDatas($object);
359 unset($object->note);
360 unset($object->usermod);
361 unset($object->libelle);
362 unset($object->context);
363 unset($object->canvas);
364 unset($object->contact);
365 unset($object->contact_id);
366 unset($object->thirdparty);
367 unset($object->user);
368 unset($object->origin);
369 unset($object->origin_id);
370 unset($object->ref_ext);
371 unset($object->statut);
372 unset($object->state_code);
373 unset($object->state_id);
374 unset($object->state);
375 unset($object->region);
376 unset($object->region_code);
377 unset($object->country);
378 unset($object->country_id);
379 unset($object->country_code);
380 unset($object->barcode_type);
381 unset($object->barcode_type_code);
382 unset($object->barcode_type_label);
383 unset($object->barcode_type_coder);
384 unset($object->mode_reglement_id);
385 unset($object->cond_reglement_id);
386 unset($object->cond_reglement);
387 unset($object->fk_delivery_address);
388 unset($object->shipping_method_id);
389 unset($object->fk_account);
390 unset($object->total_ht);
391 unset($object->total_tva);
392 unset($object->total_localtax1);
393 unset($object->total_localtax2);
394 unset($object->total_ttc);
395 unset($object->fk_incoterms);
396 unset($object->label_incoterms);
397 unset($object->location_incoterms);
398 unset($object->name);
399 unset($object->lastname);
400 unset($object->firstname);
401 unset($object->civility_id);
402 unset($object->contact);
403 unset($object->societe);
404 unset($object->demand_reason_id);
405 unset($object->transport_mode_id);
406 unset($object->region_id);
407 unset($object->actions);
408 unset($object->lines);
409 unset($object->modelpdf);
Class to manage agenda events (actions)
_cleanObjectDatas($object)
Clean sensible object datas.
index($sortfield="t.id", $sortorder='ASC', $limit=100, $page=0, $user_ids=0, $sqlfilters='')
List Agenda Events.
_validate($data)
Validate fields before create or update object.
__construct()
Constructor.
put($id, $request_data=null)
Update Agenda Event general fields.
post($request_data=null)
Create Agenda Event object.
static _checkAccessToResource($resource, $resource_id=0, $dbtablename='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid')
Check access by user to a given resource.
_checkFilters($sqlfilters, &$error='')
Return if a $sqlfilters parameter is valid.
_checkValForAPI($field, $value, $object)
Check and convert a string depending on its type/name.
isModEnabled($module)
Is Dolibarr module enabled.
$conf db
API class for accounts.