22use Luracast\Restler\RestException;
24require_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
25require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
41 public static $FIELDS = array(
74 public function get(
$id)
76 if (!DolibarrApiAccess::$user->hasRight(
'agenda',
'myactions',
'read')) {
77 throw new RestException(403,
"Insufficient rights to read an event");
80 $result = $this->actioncomm->initAsSpecimen();
82 $result = $this->actioncomm->fetch(
$id);
84 $this->actioncomm->fetch_optionals();
85 $this->actioncomm->fetchObjectLinked();
89 throw new RestException(404,
'Agenda Events not found');
92 if (!DolibarrApiAccess::$user->hasRight(
'agenda',
'allactions',
'read') && $this->actioncomm->userownerid != DolibarrApiAccess::$user->id) {
93 throw new RestException(403,
'Insufficient rights to read event of this owner id. Your id is '.DolibarrApiAccess::$user->
id);
97 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
124 public function index($sortfield =
"t.id", $sortorder =
'ASC', $limit = 100, $page = 0, $user_ids =
'', $sqlfilters =
'', $properties =
'', $pagination_data =
false)
128 if (!DolibarrApiAccess::$user->hasRight(
'agenda',
'myactions',
'read')) {
129 throw new RestException(403,
"Insufficient rights to read events");
133 $socid = DolibarrApiAccess::$user->socid ?: 0;
137 if (!DolibarrApiAccess::$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
138 $search_sale = DolibarrApiAccess::$user->id;
144 $sql =
"SELECT t.id";
145 $sql .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm AS t";
146 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"actioncomm_extrafields AS ef ON (ef.fk_object = t.id)";
147 $sql .=
' WHERE t.entity IN ('.getEntity(
'agenda').
')';
149 $sql .=
" AND t.fk_user_action IN (".$this->db->sanitize($user_ids).
")";
153 if (!DolibarrApiAccess::$user->hasRight(
'agenda',
'allactions',
'read')) {
154 $childids = DolibarrApiAccess::$user->getAllChildIds(1);
155 $sql .=
" AND t.fk_user_action IN (".$this->db->sanitize(implode(
',', $childids)).
")";
158 $sql .=
" AND t.fk_soc = ".((int) $socid);
161 if ($search_sale && $search_sale !=
'-1') {
162 if ($search_sale == -2) {
163 $sql .=
" AND ".getSalesRepresentativeSqlFilter(
't.fk_soc', 0, 1);
164 } elseif ($search_sale > 0) {
165 $sql .=
" AND (t.fk_soc IS NULL OR ".getSalesRepresentativeSqlFilter(
't.fk_soc', (
int) $search_sale).
")";
173 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
178 $sqlTotals = str_replace(
'SELECT t.id',
'SELECT count(t.id) as total', $sql);
180 $sql .= $this->db->order($sortfield, $sortorder);
185 $offset = $limit * $page;
187 $sql .= $this->db->plimit($limit + 1, $offset);
190 $result = $this->db->query($sql);
194 $num = $this->db->num_rows($result);
195 $min = min($num, ($limit <= 0 ? $num : $limit));
197 $obj = $this->db->fetch_object($result);
198 $actioncomm_static =
new ActionComm($this->db);
199 if ($actioncomm_static->fetch($obj->id)) {
205 throw new RestException(503,
'Error when retrieve Agenda Event list : '.$this->db->lasterror());
209 if ($pagination_data) {
210 $totalsResult = $this->db->query($sqlTotals);
211 $total = $this->db->fetch_object($totalsResult)->total;
216 $obj_ret[
'data'] = $tmp;
217 $obj_ret[
'pagination'] = [
218 'total' => (int) $total,
220 'page_count' => (
int) ceil((
int) $total / $limit),
240 public function post($request_data =
null)
242 if (!DolibarrApiAccess::$user->hasRight(
'agenda',
'myactions',
'create')) {
243 throw new RestException(403,
"Insufficient rights to create your Agenda Event");
245 if (!DolibarrApiAccess::$user->hasRight(
'agenda',
'allactions',
'create') && DolibarrApiAccess::$user->
id != $request_data[
'userownerid']) {
246 throw new RestException(403,
"Insufficient rights to create an Agenda Event for owner id ".$request_data[
'userownerid'].
' Your id is '.DolibarrApiAccess::$user->
id);
250 $result = $this->
_validate($request_data);
252 foreach ($request_data as $field => $value) {
253 if ($field ===
'caller') {
255 $this->actioncomm->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
259 $this->actioncomm->$field = $this->
_checkValForAPI($field, $value, $this->actioncomm);
269 if ($this->actioncomm->create(DolibarrApiAccess::$user) < 0) {
270 throw new RestException(500,
"Error creating event", array_merge(array($this->actioncomm->error), $this->actioncomm->errors));
273 return $this->actioncomm->id;
290 public function put(
$id, $request_data =
null)
292 if (!DolibarrApiAccess::$user->hasRight(
'agenda',
'myactions',
'create')) {
293 throw new RestException(403,
"Insufficient rights to create your Agenda Event");
295 if (!DolibarrApiAccess::$user->hasRight(
'agenda',
'allactions',
'create') && DolibarrApiAccess::$user->
id != $request_data[
'userownerid']) {
296 throw new RestException(403,
"Insufficient rights to create an Agenda Event for owner id ".$request_data[
'userownerid'].
' Your id is '.DolibarrApiAccess::$user->
id);
299 $result = $this->actioncomm->fetch(
$id);
301 $this->actioncomm->fetch_optionals();
302 $this->actioncomm->fetch_userassigned();
303 $this->actioncomm->oldcopy = clone $this->actioncomm;
306 throw new RestException(404,
'actioncomm not found');
310 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
315 if (!DolibarrApiAccess::$user->hasRight(
'agenda',
'allactions',
'read') && $this->actioncomm->userownerid != DolibarrApiAccess::$user->id) {
316 throw new RestException(403,
'Insufficient rights to update event of this owner id. Your id is '.DolibarrApiAccess::$user->
id);
318 foreach ($request_data as $field => $value) {
319 if ($field ==
'id') {
322 if ($field ===
'caller') {
324 $this->actioncomm->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
328 if ($field ==
'array_options' && is_array($value)) {
329 foreach ($value as $index => $val) {
334 $this->actioncomm->$field = $this->
_checkValForAPI($field, $value, $this->actioncomm);
337 if ($this->actioncomm->update(DolibarrApiAccess::$user, 1) > 0) {
338 return $this->
get(
$id);
357 public function delete(
$id)
359 if (!DolibarrApiAccess::$user->hasRight(
'agenda',
'myactions',
'delete')) {
360 throw new RestException(403,
"Insufficient rights to delete your Agenda Event");
363 $result = $this->actioncomm->fetch(
$id);
365 $this->actioncomm->fetch_optionals();
366 $this->actioncomm->fetch_userassigned();
367 $this->actioncomm->oldcopy = clone $this->actioncomm;
370 if (!DolibarrApiAccess::$user->hasRight(
'agenda',
'allactions',
'delete') && DolibarrApiAccess::$user->
id != $this->actioncomm->userownerid) {
371 throw new RestException(403,
"Insufficient rights to delete an Agenda Event of owner id ".$this->actioncomm->userownerid.
' Your id is '.DolibarrApiAccess::$user->id);
375 throw new RestException(404,
'Agenda Event not found');
379 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
382 if (!$this->actioncomm->delete(DolibarrApiAccess::$user)) {
383 throw new RestException(500,
'Error when delete Agenda Event : '.$this->actioncomm->errorsToString());
389 'message' =>
'Agenda Event deleted'
403 if ($data ===
null) {
407 foreach (AgendaEvents::$FIELDS as $field) {
408 if (!isset($data[$field])) {
409 throw new RestException(400,
"$field field missing");
411 $event[$field] = $data[$field];
453 unset(
$object->barcode_type_code);
454 unset(
$object->barcode_type_label);
455 unset(
$object->barcode_type_coder);
456 unset(
$object->mode_reglement_id);
457 unset(
$object->cond_reglement_id);
458 unset(
$object->cond_reglement);
459 unset(
$object->fk_delivery_address);
460 unset(
$object->shipping_method_id);
464 unset(
$object->total_localtax1);
465 unset(
$object->total_localtax2);
468 unset(
$object->label_incoterms);
469 unset(
$object->location_incoterms);
476 unset(
$object->demand_reason_id);
477 unset(
$object->transport_mode_id);
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage agenda events (actions)
_cleanObjectDatas($object)
Clean sensible object datas @phpstan-template T.
_validate($data)
Validate fields before create or update object.
__construct()
Constructor.
put($id, $request_data=null)
Update an agenda event.
index($sortfield="t.id", $sortorder='ASC', $limit=100, $page=0, $user_ids='', $sqlfilters='', $properties='', $pagination_data=false)
List agenda events.
post($request_data=null)
Create an agenda event.
_checkValExtrafieldsForAPI($field, $value, $object)
Check and convert a string depending on its type/name.
_filterObjectProperties($object, $properties)
Filter properties that will be returned on object.
_checkValForAPI($field, $value, $object)
Check and convert a string depending on its type/name.
static _checkAccessToResource($resource, $resource_id=0, $dbtablename='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $parenttableforentity='')
Check access by user to a given resource.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0, $forbiddenfields=array())
forgeSQLFromUniversalSearchCriteria
sanitizeVal($out='', $check='alphanohtml', $filter=null, $options=null)
Return a sanitized or empty value after checking value against a rule.
isModEnabled($module)
Is Dolibarr module enabled.