19 use Luracast\Restler\RestException;
21 require_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
36 static $FIELDS = array(
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 for owner id ".$request_data[
'userownerid'].
' Your id is '.DolibarrApiAccess::$user->
id);
87 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
105 public function index($sortfield =
"t.id", $sortorder =
'ASC', $limit = 100, $page = 0, $user_ids = 0, $sqlfilters =
'')
111 if (!DolibarrApiAccess::$user->rights->agenda->myactions->read) {
112 throw new RestException(401,
"Insufficient rights to read events");
117 if (!empty(DolibarrApiAccess::$user->socid)) $socid = DolibarrApiAccess::$user->socid;
121 if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) $search_sale = DolibarrApiAccess::$user->id;
122 if (empty($conf->societe->enabled)) $search_sale = 0;
124 $sql =
"SELECT t.id as rowid";
125 if (!empty($conf->societe->enabled))
126 if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql .=
", sc.fk_soc, sc.fk_user";
127 $sql .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm as t";
128 if (!empty($conf->societe->enabled))
129 if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
130 $sql .=
' WHERE t.entity IN ('.getEntity(
'agenda').
')';
131 if (!empty($conf->societe->enabled))
132 if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql .=
" AND t.fk_soc = sc.fk_soc";
133 if ($user_ids) $sql .=
" AND t.fk_user_action IN (".$user_ids.
")";
134 if ($socid > 0) $sql .=
" AND t.fk_soc = ".$socid;
136 if ($search_sale > 0)
138 $sql .=
" AND sc.fk_user = ".$search_sale;
145 throw new RestException(503,
'Error when validating parameter sqlfilters '.$sqlfilters);
147 $regexstring =
'\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
148 $sql .=
" AND (".preg_replace_callback(
'/'.$regexstring.
'/',
'DolibarrApi::_forge_criteria_callback', $sqlfilters).
")";
151 $sql .= $this->
db->order($sortfield, $sortorder);
157 $offset = $limit * $page;
159 $sql .= $this->
db->plimit($limit + 1, $offset);
162 $result = $this->
db->query($sql);
167 $num = $this->
db->num_rows($result);
168 $min = min($num, ($limit <= 0 ? $num : $limit));
171 $obj = $this->
db->fetch_object($result);
173 if ($actioncomm_static->fetch($obj->rowid)) {
179 throw new RestException(503,
'Error when retrieve Agenda Event list : '.$this->
db->lasterror());
181 if (!count($obj_ret)) {
182 throw new RestException(404,
'No Agenda Event found');
193 public function post($request_data = null)
195 if (!DolibarrApiAccess::$user->rights->agenda->myactions->create) {
196 throw new RestException(401,
"Insufficient rights to create your Agenda Event");
198 if (!DolibarrApiAccess::$user->rights->agenda->allactions->create && DolibarrApiAccess::$user->id != $request_data[
'userownerid']) {
199 throw new RestException(401,
"Insufficient rights to create an Agenda Event for owner id ".$request_data[
'userownerid'].
' Your id is '.DolibarrApiAccess::$user->
id);
203 $result = $this->
_validate($request_data);
205 foreach ($request_data as $field => $value) {
206 $this->actioncomm->$field = $value;
215 if ($this->actioncomm->create(DolibarrApiAccess::$user) < 0) {
216 throw new RestException(500,
"Error creating event", array_merge(array($this->actioncomm->error), $this->actioncomm->errors));
219 return $this->actioncomm->id;
231 public function put($id, $request_data = null)
233 if (!DolibarrApiAccess::$user->rights->agenda->myactions->create) {
234 throw new RestException(401,
"Insufficient rights to create your Agenda Event");
236 if (!DolibarrApiAccess::$user->rights->agenda->allactions->create && DolibarrApiAccess::$user->id != $request_data[
'userownerid']) {
237 throw new RestException(401,
"Insufficient rights to create an Agenda Event for owner id ".$request_data[
'userownerid'].
' Your id is '.DolibarrApiAccess::$user->
id);
240 $result = $this->actioncomm->fetch($id);
242 $this->actioncomm->fetch_optionals();
243 $this->actioncomm->fetch_userassigned();
244 $this->actioncomm->oldcopy = clone $this->actioncomm;
247 throw new RestException(404,
'actioncomm not found');
251 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
253 foreach ($request_data as $field => $value) {
254 if ($field ==
'id')
continue;
255 $this->actioncomm->$field = $value;
258 if ($this->actioncomm->update(DolibarrApiAccess::$user, 1) > 0)
259 return $this->
get($id);
271 public function delete($id)
273 if (!DolibarrApiAccess::$user->rights->agenda->myactions->delete) {
274 throw new RestException(401,
"Insufficient rights to delete your Agenda Event");
277 $result = $this->actioncomm->fetch($id);
279 $this->actioncomm->fetch_optionals();
280 $this->actioncomm->fetch_userassigned();
281 $this->actioncomm->oldcopy = clone $this->actioncomm;
284 if (!DolibarrApiAccess::$user->rights->agenda->allactions->delete && DolibarrApiAccess::$user->id != $this->actioncomm->userownerid) {
285 throw new RestException(401,
"Insufficient rights to delete an Agenda Event of owner id ".$request_data[
'userownerid'].
' Your id is '.DolibarrApiAccess::$user->
id);
289 throw new RestException(404,
'Agenda Event not found');
293 throw new RestException(401,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
296 if (!$this->actioncomm->delete(DolibarrApiAccess::$user)) {
297 throw new RestException(500,
'Error when delete Agenda Event : '.$this->actioncomm->error);
303 'message' =>
'Agenda Event deleted'
318 foreach (AgendaEvents::$FIELDS as $field) {
319 if (!isset($data[$field]))
320 throw new RestException(400,
"$field field missing");
321 $event[$field] = $data[$field];
336 $object = parent::_cleanObjectDatas($object);
338 unset($object->note);
339 unset($object->usermod);
340 unset($object->libelle);
341 unset($object->context);
342 unset($object->canvas);
343 unset($object->contact);
344 unset($object->contact_id);
345 unset($object->thirdparty);
346 unset($object->user);
347 unset($object->origin);
348 unset($object->origin_id);
349 unset($object->ref_ext);
350 unset($object->statut);
351 unset($object->state_code);
352 unset($object->state_id);
353 unset($object->state);
354 unset($object->region);
355 unset($object->region_code);
356 unset($object->country);
357 unset($object->country_id);
358 unset($object->country_code);
359 unset($object->barcode_type);
360 unset($object->barcode_type_code);
361 unset($object->barcode_type_label);
362 unset($object->barcode_type_coder);
363 unset($object->mode_reglement_id);
364 unset($object->cond_reglement_id);
365 unset($object->cond_reglement);
366 unset($object->fk_delivery_address);
367 unset($object->shipping_method_id);
368 unset($object->fk_account);
369 unset($object->total_ht);
370 unset($object->total_tva);
371 unset($object->total_localtax1);
372 unset($object->total_localtax2);
373 unset($object->total_ttc);
374 unset($object->fk_incoterms);
375 unset($object->label_incoterms);
376 unset($object->location_incoterms);
377 unset($object->name);
378 unset($object->lastname);
379 unset($object->firstname);
380 unset($object->civility_id);
381 unset($object->contact);
382 unset($object->societe);
384 unset($object->actions);
385 unset($object->lines);
_validate($data)
Validate fields before create or update object.
Class to manage agenda events (actions)
index($sortfield="t.id", $sortorder= 'ASC', $limit=100, $page=0, $user_ids=0, $sqlfilters= '')
List Agenda Events.
_cleanObjectDatas($object)
Clean sensible object datas.
$conf db
API class for accounts.
_checkFilters($sqlfilters)
Return if a $sqlfilters parameter is valid.
post($request_data=null)
Create Agenda Event object.
put($id, $request_data=null)
Update Agenda Event general fields.
__construct()
Constructor.
static _checkAccessToResource($resource, $resource_id=0, $dbtablename= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid')
Check user access to a resource.