20use Luracast\Restler\RestException;
22require_once DOL_DOCUMENT_ROOT.
'/api/class/api.class.php';
23require_once DOL_DOCUMENT_ROOT.
'/eventorganization/class/conferenceorboothattendee.class.php';
36 public static $FIELDS = array(
43 public static $INTFIELDS = array(
54 public $event_attendees;
59 public $table_element =
'eventorganization_conferenceorboothattendee';
88 throw new RestException(400,
'No eventattendee with id<1 can exist');
92 throw new RestException(403,
'denied read access to Event attendees');
95 $result = $this->event_attendees->fetch(
$id,
'');
97 throw new RestException(404,
'Event attendee with id '.
$id.
' not found');
100 if (!$this->event_attendees->delete(DolibarrApiAccess::$user)) {
101 throw new RestException(500,
'Error when delete event attendee : '.$this->event_attendees->errorsToString());
107 'message' =>
'event attendee deleted'
130 throw new RestException(403,
'denied read access to Event attendees');
133 $result = $this->event_attendees->fetch(0, $ref);
135 throw new RestException(404,
"Event attendee with ref ".$ref.
" not found");
138 if (!$this->event_attendees->delete(DolibarrApiAccess::$user)) {
139 throw new RestException(500,
'Error when delete event attendee : '.$this->event_attendees->errorsToString());
145 'message' =>
'event attendee deleted'
187 return $this->
_fetch(0, $ref);
212 public function index($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $sqlfilters =
'', $properties =
'', $pagination_data =
false, $loadlinkedobjects = 0)
216 throw new RestException(403,
'denied read access to Event attendees');
220 $entity = (int) DolibarrApiAccess::$user->entity;
223 $sql =
"SELECT t.rowid";
224 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" AS t";
225 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet AS p ON t.fk_project = p.rowid";
227 $sql .=
' WHERE p.entity = '.((int) $entity);
229 $sql .=
' WHERE 1 = 1';
234 if (!DolibarrApiAccess::$user->hasRight(
'project',
'all',
'read')) {
235 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
236 $projectstatic =
new Project($this->db);
237 $projectsListId = $projectstatic->getProjectsAuthorizedForUser(DolibarrApiAccess::$user, 0, 1, 0);
238 $sql .=
' AND t.fk_project IN ('.$this->db->sanitize($projectsListId).
')';
247 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
252 $sqlTotals = str_replace(
'SELECT t.rowid',
'SELECT count(t.rowid) as total', $sql);
254 $sql .= $this->db->order($sortfield, $sortorder);
259 $offset = $limit * $page;
261 $sql .= $this->db->plimit($limit + 1, $offset);
264 dol_syslog(get_class($this).
"::index", LOG_DEBUG);
265 $result = $this->db->query($sql);
268 $num = $this->db->num_rows($result);
269 $min = min($num, ($limit <= 0 ? $num : $limit));
272 $obj = $this->db->fetch_object($result);
274 if ($event_attendees_static->fetch($obj->rowid) > 0) {
276 $rowallowaccess = $this->
_checkAccessRights(
'read', $event_attendees_static->fk_project);
277 }
catch (RestException $e) {
279 $rowallowaccess =
false;
281 if ($rowallowaccess) {
282 if ($loadlinkedobjects) {
284 $event_attendees_static->fetchObjectLinked();
292 throw new RestException(503,
'Error when retrieve event attendee list : '.$this->db->lasterror());
296 if ($pagination_data) {
297 $totalsResult = $this->db->query($sqlTotals);
298 $total = $this->db->fetch_object($totalsResult)->total;
303 $obj_ret[
'data'] = $tmp;
304 $obj_ret[
'pagination'] = [
305 'total' => (int) $total,
307 'page_count' => ceil((
int) $total / $limit),
333 public function post($request_data =
null)
337 throw new RestException(403,
'denied create access to Event attendees');
341 $result = $this->
_validate($request_data);
343 foreach ($request_data as $field => $value) {
344 if ($field ===
'caller') {
346 $this->event_attendees->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
350 $this->event_attendees->$field = $this->
_checkValForAPI($field, $value, $this->event_attendees);
353 if ($this->event_attendees->create(DolibarrApiAccess::$user) < 0) {
354 throw new RestException(500,
"Error creating event attendee", array_merge(array($this->event_attendees->error), $this->event_attendees->errors));
357 return ((
int) $this->event_attendees->id);
382 throw new RestException(400,
'No eventattendee with id<1 can exist');
386 throw new RestException(403,
'denied update access to Event attendees');
389 $result = $this->event_attendees->fetch(
$id,
'');
391 throw new RestException(404,
'event attendee not found');
394 foreach ($request_data as $field => $value) {
395 if ($field ==
'id') {
398 if ($field ===
'caller') {
400 $this->event_attendees->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
404 $this->event_attendees->$field = $this->
_checkValForAPI($field, $value, $this->event_attendees);
407 if ($this->event_attendees->update(DolibarrApiAccess::$user) > 0) {
410 throw new RestException(500, end($this->event_attendees->errors));
433 public function putByRef($ref, $request_data =
null)
437 throw new RestException(403,
'denied update access to Event attendees');
440 $result = $this->event_attendees->fetch(0, $ref);
442 throw new RestException(404,
'event attendee not found');
446 foreach ($request_data as $field => $value) {
447 if ($field ==
'id') {
450 if ($field ==
'ref') {
451 $newref = $this->
_checkValForAPI($field, $value, $this->event_attendees);
453 if ($field ===
'caller') {
455 $this->event_attendees->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
459 $this->event_attendees->$field = $this->
_checkValForAPI($field, $value, $this->event_attendees);
462 if ($this->event_attendees->update(DolibarrApiAccess::$user) > 0) {
463 return $this->
_fetch(0, $newref);
465 throw new RestException(500, end($this->event_attendees->errors));
485 if (
$id < 1 && empty($ref)) {
486 throw new RestException(400,
'No eventattendee with id<1 can exist');
488 if (empty(
$id) && empty($ref)) {
489 throw new RestException(400,
'No eventattendee can be found with no criteria');
493 throw new RestException(403,
'denied read access to Event attendees');
496 $result = $this->event_attendees->fetch(
$id, $ref);
499 throw new RestException(404,
'Event attendee with id '.((
string)
$id).
' not found');
502 throw new RestException(404,
'Event attendee with ref '.$ref.
' not found');
504 throw new RestException(404,
'Event attendee not found');
506 $project_id = $this->event_attendees->fk_project;
509 throw new RestException(403,
'denied read access to Event attendees');
512 $this->event_attendees->fetchObjectLinked();
535 unset(
$object->array_languages);
550 unset(
$object->barcode_type_coder);
551 unset(
$object->mode_reglement_id);
552 unset(
$object->cond_reglement_id);
553 unset(
$object->demand_reason_id);
554 unset(
$object->transport_mode_id);
555 unset(
$object->shipping_method_id);
556 unset(
$object->shipping_method);
557 unset(
$object->fk_multicurrency);
558 unset(
$object->multicurrency_code);
559 unset(
$object->multicurrency_tx);
560 unset(
$object->multicurrency_total_ht);
561 unset(
$object->multicurrency_total_tva);
562 unset(
$object->multicurrency_total_ttc);
563 unset(
$object->multicurrency_total_localtax1);
564 unset(
$object->multicurrency_total_localtax2);
568 unset(
$object->total_localtax1);
569 unset(
$object->total_localtax2);
572 unset(
$object->actiontypecode);
575 unset(
$object->user_creation_id);
576 unset(
$object->user_validation_id);
577 unset(
$object->user_closing_id);
578 unset(
$object->user_modification_id);
581 unset(
$object->cond_reglement_supplier_id);
582 unset(
$object->deposit_percent);
583 unset(
$object->retained_warranty_fk_cond_reglement);
588 unset(
$object->date_validation);
589 unset(
$object->date_modification);
610 $event_attendees = array();
611 foreach (EventAttendees::$FIELDS as $field) {
612 if (!isset($data[$field])) {
613 throw new RestException(400, $field.
" field missing");
615 $event_attendees[$field] = $data[$field];
617 return $event_attendees;
634 $moduleaccess =
false;
635 if (
isModEnabled(
"eventorganization") && DolibarrApiAccess::$user->hasRight(
'project', $accesstype)) {
636 $moduleaccess =
true;
638 $fullprojectaccess =
false;
639 if (DolibarrApiAccess::$user->hasRight(
'project',
'all', $accesstype)) {
640 $fullprojectaccess =
true;
643 if ($moduleaccess && $fullprojectaccess) {
646 $singleprojectaccess =
false;
647 if (0 < $project_id) {
649 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
650 $event_project =
new Project($this->db);
651 $result = $event_project->fetch($project_id);
653 $public = $event_project->public;
655 $singleprojectaccess =
true;
657 $userProjectAccessListId = $event_project->getProjectsAuthorizedForUser(DolibarrApiAccess::$user, 0, 0);
658 $project_title = $event_project->title;
659 if (in_array($project_title, $userProjectAccessListId)) {
660 $singleprojectaccess =
true;
662 dol_syslog(
"project_title ".$project_title.
" is NOT in array from getProjectsAuthorizedForUser()", LOG_DEBUG);
666 } elseif (0 == $result) {
667 throw new RestException(500,
'Project id '.$project_id.
' not found');
669 throw new RestException(500,
'Error during fetch project '.$project_id.
': '.$this->db->lasterror());
671 } elseif ($moduleaccess && ($project_id == 0)) {
675 if ($moduleaccess && $singleprojectaccess) {
677 } elseif ($moduleaccess) {
678 throw new RestException(403,
'Event attendees access granted, but denied access to the project');
679 } elseif ($singleprojectaccess) {
680 throw new RestException(403,
'project access granted, but denied access to Event attendees');
682 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.