19use Luracast\Restler\RestException;
21require_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
35 public static $FIELDS = array(
64 public function get($id)
66 if (!DolibarrApiAccess::$user->hasRight(
'agenda',
'myactions',
'read')) {
67 throw new RestException(403,
"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->hasRight(
'agenda',
'allactions',
'read') && $this->actioncomm->userownerid != DolibarrApiAccess::$user->id) {
83 throw new RestException(403,
'Insufficient rights to read event of this owner id. Your id is '.DolibarrApiAccess::$user->
id);
87 throw new RestException(403,
'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->hasRight(
'agenda',
'myactions',
'read')) {
113 throw new RestException(403,
"Insufficient rights to read events");
117 $socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : 0;
121 if (!DolibarrApiAccess::$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
122 $search_sale = DolibarrApiAccess::$user->id;
124 if (!isModEnabled(
'societe')) {
128 $sql =
"SELECT t.id as rowid";
129 $sql .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm AS t";
130 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"actioncomm_extrafields AS ef ON (ef.fk_object = t.id)";
131 $sql .=
' WHERE t.entity IN ('.getEntity(
'agenda').
')';
133 $sql .=
" AND t.fk_user_action IN (".$this->db->sanitize($user_ids).
")";
136 $sql .=
" AND t.fk_soc = ".((int) $socid);
139 if ($search_sale && $search_sale !=
'-1') {
140 if ($search_sale == -2) {
141 $sql .=
" AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc WHERE sc.fk_soc = t.fk_soc)";
142 } elseif ($search_sale > 0) {
143 $sql .=
" AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc WHERE sc.fk_soc = t.fk_soc AND sc.fk_user = ".((int) $search_sale).
")";
151 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
155 $sql .= $this->db->order($sortfield, $sortorder);
160 $offset = $limit * $page;
162 $sql .= $this->db->plimit($limit + 1, $offset);
165 $result = $this->db->query($sql);
169 $num = $this->db->num_rows($result);
170 $min = min($num, ($limit <= 0 ? $num : $limit));
172 $obj = $this->db->fetch_object($result);
173 $actioncomm_static =
new ActionComm($this->db);
174 if ($actioncomm_static->fetch($obj->rowid)) {
180 throw new RestException(503,
'Error when retrieve Agenda Event list : '.$this->db->lasterror());
192 public function post($request_data =
null)
194 if (!DolibarrApiAccess::$user->hasRight(
'agenda',
'myactions',
'create')) {
195 throw new RestException(403,
"Insufficient rights to create your Agenda Event");
197 if (!DolibarrApiAccess::$user->hasRight(
'agenda',
'allactions',
'create') && DolibarrApiAccess::$user->
id != $request_data[
'userownerid']) {
198 throw new RestException(403,
"Insufficient rights to create an Agenda Event for owner id ".$request_data[
'userownerid'].
' Your id is '.DolibarrApiAccess::$user->
id);
202 $result = $this->
_validate($request_data);
204 foreach ($request_data as $field => $value) {
205 if ($field ===
'caller') {
207 $this->actioncomm->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
211 $this->actioncomm->$field = $this->
_checkValForAPI($field, $value, $this->actioncomm);
221 if ($this->actioncomm->create(DolibarrApiAccess::$user) < 0) {
222 throw new RestException(500,
"Error creating event", array_merge(array($this->actioncomm->error), $this->actioncomm->errors));
225 return $this->actioncomm->id;
236 public function put($id, $request_data =
null)
238 if (!DolibarrApiAccess::$user->hasRight(
'agenda',
'myactions',
'create')) {
239 throw new RestException(403,
"Insufficient rights to create your Agenda Event");
241 if (!DolibarrApiAccess::$user->hasRight(
'agenda',
'allactions',
'create') && DolibarrApiAccess::$user->
id != $request_data[
'userownerid']) {
242 throw new RestException(403,
"Insufficient rights to create an Agenda Event for owner id ".$request_data[
'userownerid'].
' Your id is '.DolibarrApiAccess::$user->
id);
245 $result = $this->actioncomm->fetch($id);
247 $this->actioncomm->fetch_optionals();
248 $this->actioncomm->fetch_userassigned();
249 $this->actioncomm->oldcopy = clone $this->actioncomm;
252 throw new RestException(404,
'actioncomm not found');
256 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
258 foreach ($request_data as $field => $value) {
259 if ($field ==
'id') {
262 if ($field ===
'caller') {
264 $this->actioncomm->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
268 $this->actioncomm->$field = $this->
_checkValForAPI($field, $value, $this->actioncomm);
271 if ($this->actioncomm->update(DolibarrApiAccess::$user, 1) > 0) {
272 return $this->
get($id);
285 public function delete($id)
287 if (!DolibarrApiAccess::$user->hasRight(
'agenda',
'myactions',
'delete')) {
288 throw new RestException(403,
"Insufficient rights to delete your Agenda Event");
291 $result = $this->actioncomm->fetch($id);
293 $this->actioncomm->fetch_optionals();
294 $this->actioncomm->fetch_userassigned();
295 $this->actioncomm->oldcopy = clone $this->actioncomm;
298 if (!DolibarrApiAccess::$user->hasRight(
'agenda',
'allactions',
'delete') && DolibarrApiAccess::$user->
id != $this->actioncomm->userownerid) {
299 throw new RestException(403,
"Insufficient rights to delete an Agenda Event of owner id ".$this->actioncomm->userownerid.
' Your id is '.DolibarrApiAccess::$user->id);
303 throw new RestException(404,
'Agenda Event not found');
307 throw new RestException(403,
'Access not allowed for login '.DolibarrApiAccess::$user->login);
310 if (!$this->actioncomm->delete(DolibarrApiAccess::$user)) {
311 throw new RestException(500,
'Error when delete Agenda Event : '.$this->actioncomm->error);
317 'message' =>
'Agenda Event deleted'
332 foreach (AgendaEvents::$FIELDS as $field) {
333 if (!isset($data[$field])) {
334 throw new RestException(400,
"$field field missing");
336 $event[$field] = $data[$field];
375 unset(
$object->barcode_type_code);
376 unset(
$object->barcode_type_label);
377 unset(
$object->barcode_type_coder);
378 unset(
$object->mode_reglement_id);
379 unset(
$object->cond_reglement_id);
380 unset(
$object->cond_reglement);
381 unset(
$object->fk_delivery_address);
382 unset(
$object->shipping_method_id);
386 unset(
$object->total_localtax1);
387 unset(
$object->total_localtax2);
390 unset(
$object->label_incoterms);
391 unset(
$object->location_incoterms);
398 unset(
$object->demand_reason_id);
399 unset(
$object->transport_mode_id);
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Class to manage agenda events (actions)
_cleanObjectDatas($object)
Clean sensible object datas.
_validate($data)
Validate fields before create or update object.
index($sortfield="t.id", $sortorder='ASC', $limit=100, $page=0, $user_ids='', $sqlfilters='', $properties='')
List Agenda Events.
__construct()
Constructor.
put($id, $request_data=null)
Update Agenda Event general fields.
post($request_data=null)
Create Agenda Event object.
_filterObjectProperties($object, $properties)
Filter properties that will be returned on object.
static _checkAccessToResource($resource, $resource_id=0, $dbtablename='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid')
Check access by user to a given resource.
_checkValForAPI($field, $value, $object)
Check and convert a string depending on its type/name.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
sanitizeVal($out='', $check='alphanohtml', $filter=null, $options=null)
Return a sanitized or empty value after checking value against a rule.