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)
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';
237 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
239 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
244 $sqlTotals = str_replace(
'SELECT t.rowid',
'SELECT count(t.rowid) as total', $sql);
246 $sql .= $this->db->order($sortfield, $sortorder);
251 $offset = $limit * $page;
253 $sql .= $this->db->plimit($limit + 1, $offset);
256 dol_syslog(get_class($this).
"::index", LOG_DEBUG);
257 $result = $this->db->query($sql);
260 $num = $this->db->num_rows($result);
261 $min = min($num, ($limit <= 0 ? $num : $limit));
263 $onerowaccessgranted =
false;
265 $obj = $this->db->fetch_object($result);
267 if ($event_attendees_static->fetch($obj->rowid) > 0) {
268 $rowallowaccess = $this->
_checkAccessRights(
'read', $event_attendees_static->fk_project);
269 if ($rowallowaccess) {
270 if ($loadlinkedobjects) {
272 $event_attendees_static->fetchObjectLinked();
275 $onerowaccessgranted = $rowallowaccess;
280 if (($num > 0) && !$onerowaccessgranted) {
281 throw new RestException(403,
'No access granted for even a single of the rows found');
284 throw new RestException(503,
'Error when retrieve event attendee list : '.$this->db->lasterror());
288 if ($pagination_data) {
289 $totalsResult = $this->db->query($sqlTotals);
290 $total = $this->db->fetch_object($totalsResult)->total;
295 $obj_ret[
'data'] = $tmp;
296 $obj_ret[
'pagination'] = [
297 'total' => (int) $total,
299 'page_count' => ceil((
int) $total / $limit),
325 public function post($request_data =
null)
329 throw new RestException(403,
'denied create access to Event attendees');
333 $result = $this->
_validate($request_data);
335 foreach ($request_data as $field => $value) {
336 if ($field ===
'caller') {
338 $this->event_attendees->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
342 $this->event_attendees->$field = $this->
_checkValForAPI($field, $value, $this->event_attendees);
345 if ($this->event_attendees->create(DolibarrApiAccess::$user) < 0) {
346 throw new RestException(500,
"Error creating event attendee", array_merge(array($this->event_attendees->error), $this->event_attendees->errors));
349 return ((
int) $this->event_attendees->id);
374 throw new RestException(400,
'No eventattendee with id<1 can exist');
378 throw new RestException(403,
'denied update access to Event attendees');
381 $result = $this->event_attendees->fetch(
$id,
'');
383 throw new RestException(404,
'event attendee not found');
386 foreach ($request_data as $field => $value) {
387 if ($field ==
'id') {
390 if ($field ===
'caller') {
392 $this->event_attendees->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
396 $this->event_attendees->$field = $this->
_checkValForAPI($field, $value, $this->event_attendees);
399 if ($this->event_attendees->update(DolibarrApiAccess::$user) > 0) {
402 throw new RestException(500, end($this->event_attendees->errors));
425 public function putByRef($ref, $request_data =
null)
429 throw new RestException(403,
'denied update access to Event attendees');
432 $result = $this->event_attendees->fetch(0, $ref);
434 throw new RestException(404,
'event attendee not found');
438 foreach ($request_data as $field => $value) {
439 if ($field ==
'id') {
442 if ($field ==
'ref') {
443 $newref = $this->
_checkValForAPI($field, $value, $this->event_attendees);
445 if ($field ===
'caller') {
447 $this->event_attendees->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
451 $this->event_attendees->$field = $this->
_checkValForAPI($field, $value, $this->event_attendees);
454 if ($this->event_attendees->update(DolibarrApiAccess::$user) > 0) {
455 return $this->
_fetch(0, $newref);
457 throw new RestException(500, end($this->event_attendees->errors));
477 if (
$id < 1 && empty($ref)) {
478 throw new RestException(400,
'No eventattendee with id<1 can exist');
480 if (empty(
$id) && empty($ref)) {
481 throw new RestException(400,
'No eventattendee can be found with no criteria');
484 $result = $this->event_attendees->fetch(
$id, $ref);
487 throw new RestException(404,
'Event attendee with id '.((
string)
$id).
' not found');
490 throw new RestException(404,
'Event attendee with ref '.$ref.
' not found');
492 throw new RestException(404,
'Event attendee not found');
494 $project_id = $this->event_attendees->fk_project;
497 throw new RestException(403,
'denied read access to Event attendees');
500 $this->event_attendees->fetchObjectLinked();
523 unset(
$object->array_languages);
538 unset(
$object->barcode_type_coder);
539 unset(
$object->mode_reglement_id);
540 unset(
$object->cond_reglement_id);
541 unset(
$object->demand_reason_id);
542 unset(
$object->transport_mode_id);
543 unset(
$object->shipping_method_id);
544 unset(
$object->shipping_method);
545 unset(
$object->fk_multicurrency);
546 unset(
$object->multicurrency_code);
547 unset(
$object->multicurrency_tx);
548 unset(
$object->multicurrency_total_ht);
549 unset(
$object->multicurrency_total_tva);
550 unset(
$object->multicurrency_total_ttc);
551 unset(
$object->multicurrency_total_localtax1);
552 unset(
$object->multicurrency_total_localtax2);
556 unset(
$object->total_localtax1);
557 unset(
$object->total_localtax2);
560 unset(
$object->actiontypecode);
563 unset(
$object->user_creation_id);
564 unset(
$object->user_validation_id);
565 unset(
$object->user_closing_id);
566 unset(
$object->user_modification_id);
569 unset(
$object->cond_reglement_supplier_id);
570 unset(
$object->deposit_percent);
571 unset(
$object->retained_warranty_fk_cond_reglement);
576 unset(
$object->date_validation);
577 unset(
$object->date_modification);
598 $event_attendees = array();
599 foreach (EventAttendees::$FIELDS as $field) {
600 if (!isset($data[$field])) {
601 throw new RestException(400, $field.
" field missing");
603 $event_attendees[$field] = $data[$field];
605 return $event_attendees;
622 $moduleaccess =
false;
623 if (
isModEnabled(
"eventorganization") && DolibarrApiAccess::$user->hasRight(
'project', $accesstype)) {
624 $moduleaccess =
true;
626 $fullprojectaccess =
false;
627 if (DolibarrApiAccess::$user->hasRight(
'project',
'all', $accesstype)) {
628 $fullprojectaccess =
true;
631 if ($moduleaccess && $fullprojectaccess) {
634 $singleprojectaccess =
false;
635 if (0 < $project_id) {
637 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
638 $event_project =
new Project($this->db);
639 $result = $event_project->fetch($project_id);
641 $public = $event_project->public;
643 $singleprojectaccess =
true;
645 $userProjectAccessListId = $event_project->getProjectsAuthorizedForUser(DolibarrApiAccess::$user, 0, 0);
646 $project_title = $event_project->title;
647 if (in_array($project_title, $userProjectAccessListId)) {
648 $singleprojectaccess =
true;
650 dol_syslog(
"project_title ".$project_title.
" is NOT in array from getProjectsAuthorizedForUser()", LOG_DEBUG);
654 } elseif (0 == $result) {
655 throw new RestException(500,
'Project id '.$project_id.
' not found');
657 throw new RestException(500,
'Error during fetch project '.$project_id.
': '.$this->db->lasterror());
659 } elseif ($moduleaccess && ($project_id == 0)) {
663 if ($moduleaccess && $singleprojectaccess) {
665 } elseif ($moduleaccess) {
666 throw new RestException(403,
'Event attendees access granted, but denied access to the project');
667 } elseif ($singleprojectaccess) {
668 throw new RestException(403,
'project access granted, but denied access to Event attendees');
670 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.
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.