20use Luracast\Restler\RestException;
22require_once DOL_DOCUMENT_ROOT.
'/api/class/api.class.php';
23require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions.lib.php';
24require_once DOL_DOCUMENT_ROOT.
'/eventorganization/class/conferenceorboothattendee.class.php';
37 public static $FIELDS = array(
44 public static $INTFIELDS = array(
55 public $event_attendees;
60 public $table_element =
'eventorganization_conferenceorboothattendee';
89 throw new RestException(400,
'No eventattendee with id<1 can exist');
93 throw new RestException(403,
'denied read access to Event attendees');
96 $result = $this->event_attendees->fetch(
$id,
'');
98 throw new RestException(404,
'Event attendee with id '.
$id.
' not found');
101 if (!$this->event_attendees->delete(DolibarrApiAccess::$user)) {
102 throw new RestException(500,
'Error when delete event attendee : '.$this->event_attendees->error);
108 'message' =>
'event attendee deleted'
131 throw new RestException(403,
'denied read access to Event attendees');
134 $result = $this->event_attendees->fetch(0, $ref);
136 throw new RestException(404,
"Event attendee with ref ".$ref.
" not found");
139 if (!$this->event_attendees->delete(DolibarrApiAccess::$user)) {
140 throw new RestException(500,
'Error when delete event attendee : '.$this->event_attendees->error);
146 'message' =>
'event attendee deleted'
188 return $this->
_fetch(0, $ref);
213 public function index($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $sqlfilters =
'', $properties =
'', $pagination_data =
false, $loadlinkedobjects = 0)
217 throw new RestException(403,
'denied read access to Event attendees');
221 $entity = (int) DolibarrApiAccess::$user->entity;
224 $sql =
"SELECT t.rowid";
225 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" AS t";
226 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet AS p ON t.fk_project = p.rowid";
228 $sql .=
' WHERE p.entity = '.((int) $entity);
230 $sql .=
' WHERE 1 = 1';
235 if (!DolibarrApiAccess::$user->hasRight(
'project',
'all',
'read')) {
236 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
237 $projectstatic =
new Project($this->db);
238 $projectsListId = $projectstatic->getProjectsAuthorizedForUser(DolibarrApiAccess::$user, 0, 1, 0);
239 $sql .=
' AND t.fk_project IN ('.$this->db->sanitize($projectsListId).
')';
248 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
253 $sqlTotals = str_replace(
'SELECT t.rowid',
'SELECT count(t.rowid) as total', $sql);
255 $sql .= $this->db->order($sortfield, $sortorder);
260 $offset = $limit * $page;
262 $sql .= $this->db->plimit($limit + 1, $offset);
265 dol_syslog(get_class($this).
"::index", LOG_DEBUG);
266 $result = $this->db->query($sql);
269 $num = $this->db->num_rows($result);
270 $min = min($num, ($limit <= 0 ? $num : $limit));
273 $obj = $this->db->fetch_object($result);
275 if ($event_attendees_static->fetch($obj->rowid) > 0) {
277 $rowallowaccess = $this->
_checkAccessRights(
'read', $event_attendees_static->fk_project);
278 }
catch (RestException $e) {
280 $rowallowaccess =
false;
282 if ($rowallowaccess) {
283 if ($loadlinkedobjects) {
285 $event_attendees_static->fetchObjectLinked();
293 throw new RestException(503,
'Error when retrieve event attendee list : '.$this->db->lasterror());
297 if ($pagination_data) {
298 $totalsResult = $this->db->query($sqlTotals);
299 $total = $this->db->fetch_object($totalsResult)->total;
304 $obj_ret[
'data'] = $tmp;
305 $obj_ret[
'pagination'] = [
306 'total' => (int) $total,
308 'page_count' => ceil((
int) $total / $limit),
334 public function post($request_data =
null)
338 throw new RestException(403,
'denied create access to Event attendees');
342 $result = $this->
_validate($request_data);
344 foreach ($request_data as $field => $value) {
345 if ($field ===
'caller') {
347 $this->event_attendees->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
351 $this->event_attendees->$field = $this->
_checkValForAPI($field, $value, $this->event_attendees);
354 if ($this->event_attendees->create(DolibarrApiAccess::$user) < 0) {
355 throw new RestException(500,
"Error creating event attendee", array_merge(array($this->event_attendees->error), $this->event_attendees->errors));
358 return ((
int) $this->event_attendees->id);
383 throw new RestException(400,
'No eventattendee with id<1 can exist');
387 throw new RestException(403,
'denied update access to Event attendees');
390 $result = $this->event_attendees->fetch(
$id,
'');
392 throw new RestException(404,
'event attendee not found');
395 foreach ($request_data as $field => $value) {
396 if ($field ==
'id') {
399 if ($field ===
'caller') {
401 $this->event_attendees->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
405 $this->event_attendees->$field = $this->
_checkValForAPI($field, $value, $this->event_attendees);
408 if ($this->event_attendees->update(DolibarrApiAccess::$user) > 0) {
411 throw new RestException(500, end($this->event_attendees->errors));
434 public function putByRef($ref, $request_data =
null)
438 throw new RestException(403,
'denied update access to Event attendees');
441 $result = $this->event_attendees->fetch(0, $ref);
443 throw new RestException(404,
'event attendee not found');
447 foreach ($request_data as $field => $value) {
448 if ($field ==
'id') {
451 if ($field ==
'ref') {
452 $newref = $this->
_checkValForAPI($field, $value, $this->event_attendees);
454 if ($field ===
'caller') {
456 $this->event_attendees->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
460 $this->event_attendees->$field = $this->
_checkValForAPI($field, $value, $this->event_attendees);
463 if ($this->event_attendees->update(DolibarrApiAccess::$user) > 0) {
464 return $this->
_fetch(0, $newref);
466 throw new RestException(500, end($this->event_attendees->errors));
486 if (
$id < 1 && empty($ref)) {
487 throw new RestException(400,
'No eventattendee with id<1 can exist');
489 if (empty(
$id) && empty($ref)) {
490 throw new RestException(400,
'No eventattendee can be found with no criteria');
494 throw new RestException(403,
'denied read access to Event attendees');
497 $result = $this->event_attendees->fetch(
$id, $ref);
500 throw new RestException(404,
'Event attendee with id '.((
string)
$id).
' not found');
503 throw new RestException(404,
'Event attendee with ref '.$ref.
' not found');
505 throw new RestException(404,
'Event attendee not found');
507 $project_id = $this->event_attendees->fk_project;
510 throw new RestException(403,
'denied read access to Event attendees');
513 $this->event_attendees->fetchObjectLinked();
536 unset(
$object->array_languages);
551 unset(
$object->barcode_type_coder);
552 unset(
$object->mode_reglement_id);
553 unset(
$object->cond_reglement_id);
554 unset(
$object->demand_reason_id);
555 unset(
$object->transport_mode_id);
556 unset(
$object->shipping_method_id);
557 unset(
$object->shipping_method);
558 unset(
$object->fk_multicurrency);
559 unset(
$object->multicurrency_code);
560 unset(
$object->multicurrency_tx);
561 unset(
$object->multicurrency_total_ht);
562 unset(
$object->multicurrency_total_tva);
563 unset(
$object->multicurrency_total_ttc);
564 unset(
$object->multicurrency_total_localtax1);
565 unset(
$object->multicurrency_total_localtax2);
569 unset(
$object->total_localtax1);
570 unset(
$object->total_localtax2);
573 unset(
$object->actiontypecode);
576 unset(
$object->user_creation_id);
577 unset(
$object->user_validation_id);
578 unset(
$object->user_closing_id);
579 unset(
$object->user_modification_id);
582 unset(
$object->cond_reglement_supplier_id);
583 unset(
$object->deposit_percent);
584 unset(
$object->retained_warranty_fk_cond_reglement);
589 unset(
$object->date_validation);
590 unset(
$object->date_modification);
611 $event_attendees = array();
612 foreach (EventAttendees::$FIELDS as $field) {
613 if (!isset($data[$field])) {
614 throw new RestException(400, $field.
" field missing");
616 $event_attendees[$field] = $data[$field];
618 return $event_attendees;
635 $moduleaccess =
false;
636 if (
isModEnabled(
"eventorganization") && DolibarrApiAccess::$user->hasRight(
'project', $accesstype)) {
637 $moduleaccess =
true;
639 $fullprojectaccess =
false;
640 if (DolibarrApiAccess::$user->hasRight(
'project',
'all', $accesstype)) {
641 $fullprojectaccess =
true;
644 if ($moduleaccess && $fullprojectaccess) {
647 $singleprojectaccess =
false;
648 if (0 < $project_id) {
650 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
651 $event_project =
new Project($this->db);
652 $result = $event_project->fetch($project_id);
654 $public = $event_project->public;
656 $singleprojectaccess =
true;
658 $userProjectAccessListId = $event_project->getProjectsAuthorizedForUser(DolibarrApiAccess::$user, 0, 0);
659 $project_title = $event_project->title;
660 if (in_array($project_title, $userProjectAccessListId)) {
661 $singleprojectaccess =
true;
663 dol_syslog(
"project_title ".$project_title.
" is NOT in array from getProjectsAuthorizedForUser()", LOG_DEBUG);
667 } elseif (0 == $result) {
668 throw new RestException(500,
'Project id '.$project_id.
' not found');
670 throw new RestException(500,
'Error during fetch project '.$project_id.
': '.$this->db->lasterror());
672 } elseif ($moduleaccess && ($project_id == 0)) {
676 if ($moduleaccess && $singleprojectaccess) {
678 } elseif ($moduleaccess) {
679 throw new RestException(403,
'Event attendees access granted, but denied access to the project');
680 } elseif ($singleprojectaccess) {
681 throw new RestException(403,
'project access granted, but denied access to Event attendees');
683 throw new RestException(403,
'denied access both Event attendees and the project');
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
Class for ConferenceOrBoothAttendee.
_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.
_validate($data)
Validate fields before create or update object.
putByRef($ref, $request_data=null)
Update an event attendee.
_checkAccessRights($accesstype, $project_id=0)
function to check for access rights - should probably have 1.
index($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $sqlfilters='', $properties='', $pagination_data=false, $loadlinkedobjects=0)
List Event attendees.
getById($id)
Get properties of a event attendee by id.
deleteByRef($ref)
Delete an event attendee.
_fetch($id, $ref='')
Get properties of an event attendee.
_cleanObjectDatas($object)
Clean sensible object datas @phpstan-template T.
getByRef($ref)
Get properties of an event attendee by ref.
__construct()
Constructor of the class.
putById($id, $request_data=null)
Update an event attendee.
deleteById($id)
Delete an event attendee.
post($request_data=null)
Create an event attendee.
Class to manage projects.
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.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.