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';
90 throw new RestException(403,
'denied read access to Event attendees');
93 $result = $this->event_attendees->fetch(
$id,
'');
95 throw new RestException(404,
'Event attendee with id '.
$id.
' not found');
98 if (!$this->event_attendees->delete(DolibarrApiAccess::$user)) {
99 throw new RestException(500,
'Error when delete event attendee : '.$this->event_attendees->error);
105 'message' =>
'event attendee deleted'
128 throw new RestException(403,
'denied read access to Event attendees');
131 $result = $this->event_attendees->fetch(0, $ref);
133 throw new RestException(404,
"Event attendee with ref ".$ref.
" not found");
136 if (!$this->event_attendees->delete(DolibarrApiAccess::$user)) {
137 throw new RestException(500,
'Error when delete event attendee : '.$this->event_attendees->error);
143 'message' =>
'event attendee deleted'
185 return $this->
_fetch(0, $ref);
209 public function index($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $sqlfilters =
'', $properties =
'', $pagination_data =
false)
217 $entity = (int) DolibarrApiAccess::$user->entity;
220 $sql =
"SELECT t.rowid";
221 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" AS t";
222 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet AS p ON t.fk_project = p.rowid";
224 $sql .=
' WHERE p.entity = '.((int) $entity);
226 $sql .=
' WHERE 1 = 1';
235 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
240 $sqlTotals = str_replace(
'SELECT t.rowid',
'SELECT count(t.rowid) as total', $sql);
242 $sql .= $this->db->order($sortfield, $sortorder);
247 $offset = $limit * $page;
249 $sql .= $this->db->plimit($limit + 1, $offset);
252 dol_syslog(get_class($this).
"::index", LOG_DEBUG);
253 $result = $this->db->query($sql);
256 $num = $this->db->num_rows($result);
257 $min = min($num, ($limit <= 0 ? $num : $limit));
259 $onerowaccessgranted =
false;
261 $obj = $this->db->fetch_object($result);
263 if ($event_attendees_static->fetch($obj->rowid,
'') > 0) {
264 $rowallowaccess = $this->
_checkAccessRights(
'read', $event_attendees_static->fk_project);
265 if ($rowallowaccess) {
267 $onerowaccessgranted = $rowallowaccess;
272 if (($num > 0) && !$onerowaccessgranted) {
273 throw new RestException(403,
'No access granted for even a single of the rows found');
276 throw new RestException(503,
'Error when retrieve event attendee list : '.$this->db->lasterror());
280 if ($pagination_data) {
281 $totalsResult = $this->db->query($sqlTotals);
282 $total = $this->db->fetch_object($totalsResult)->total;
287 $obj_ret[
'data'] = $tmp;
288 $obj_ret[
'pagination'] = [
289 'total' => (int) $total,
291 'page_count' => ceil((
int) $total / $limit),
317 public function post($request_data =
null)
321 throw new RestException(403,
'denied create access to Event attendees');
325 $result = $this->
_validate($request_data);
327 foreach ($request_data as $field => $value) {
328 if ($field ===
'caller') {
330 $this->event_attendees->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
334 $this->event_attendees->$field = $this->
_checkValForAPI($field, $value, $this->event_attendees);
337 if ($this->event_attendees->create(DolibarrApiAccess::$user) < 0) {
338 throw new RestException(500,
"Error creating event attendee", array_merge(array($this->event_attendees->error), $this->event_attendees->errors));
341 return ((
int) $this->event_attendees->id);
367 throw new RestException(403,
'denied update access to Event attendees');
370 $result = $this->event_attendees->fetch(
$id,
'');
372 throw new RestException(404,
'event attendee not found');
375 foreach ($request_data as $field => $value) {
376 if ($field ==
'id') {
379 if ($field ===
'caller') {
381 $this->event_attendees->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
385 $this->event_attendees->$field = $this->
_checkValForAPI($field, $value, $this->event_attendees);
388 if ($this->event_attendees->update(DolibarrApiAccess::$user) > 0) {
391 throw new RestException(500, end($this->event_attendees->errors));
414 public function putByRef($ref, $request_data =
null)
418 throw new RestException(403,
'denied update access to Event attendees');
421 $result = $this->event_attendees->fetch(0, $ref);
423 throw new RestException(404,
'event attendee not found');
427 foreach ($request_data as $field => $value) {
428 if ($field ==
'id') {
431 if ($field ==
'ref') {
432 $newref = $this->
_checkValForAPI($field, $value, $this->event_attendees);
434 if ($field ===
'caller') {
436 $this->event_attendees->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
440 $this->event_attendees->$field = $this->
_checkValForAPI($field, $value, $this->event_attendees);
443 if ($this->event_attendees->update(DolibarrApiAccess::$user) > 0) {
444 return $this->
_fetch(0, $newref);
446 throw new RestException(500, end($this->event_attendees->errors));
467 $result = $this->event_attendees->fetch(
$id, $ref);
470 throw new RestException(404,
'Event attendee with id '.((
string)
$id).
' not found');
473 throw new RestException(404,
'Event attendee with ref '.$ref.
' not found');
475 throw new RestException(404,
'Event attendee not found');
477 $project_id = $this->event_attendees->fk_project;
480 throw new RestException(403,
'denied read access to Event attendees');
504 unset(
$object->array_languages);
519 unset(
$object->barcode_type_coder);
520 unset(
$object->mode_reglement_id);
521 unset(
$object->cond_reglement_id);
522 unset(
$object->demand_reason_id);
523 unset(
$object->transport_mode_id);
524 unset(
$object->shipping_method_id);
525 unset(
$object->shipping_method);
526 unset(
$object->fk_multicurrency);
527 unset(
$object->multicurrency_code);
528 unset(
$object->multicurrency_tx);
529 unset(
$object->multicurrency_total_ht);
530 unset(
$object->multicurrency_total_tva);
531 unset(
$object->multicurrency_total_ttc);
532 unset(
$object->multicurrency_total_localtax1);
533 unset(
$object->multicurrency_total_localtax2);
537 unset(
$object->total_localtax1);
538 unset(
$object->total_localtax2);
541 unset(
$object->actiontypecode);
544 unset(
$object->user_creation_id);
545 unset(
$object->user_validation_id);
546 unset(
$object->user_closing_id);
547 unset(
$object->user_modification_id);
550 unset(
$object->cond_reglement_supplier_id);
551 unset(
$object->deposit_percent);
552 unset(
$object->retained_warranty_fk_cond_reglement);
557 unset(
$object->date_validation);
558 unset(
$object->date_modification);
579 $event_attendees = array();
580 foreach (EventAttendees::$FIELDS as $field) {
581 if (!isset($data[$field])) {
582 throw new RestException(400, $field.
" field missing");
584 $event_attendees[$field] = $data[$field];
586 return $event_attendees;
603 $moduleaccess =
false;
604 if (
isModEnabled(
"eventorganization") && DolibarrApiAccess::$user->hasRight(
'project', $accesstype)) {
605 $moduleaccess =
true;
607 $fullprojectaccess =
false;
608 if (DolibarrApiAccess::$user->hasRight(
'project',
'all', $accesstype)) {
609 $fullprojectaccess =
true;
612 if ($moduleaccess && $fullprojectaccess) {
615 $singleprojectaccess =
false;
616 if (0 < $project_id) {
618 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
619 $event_project =
new Project($this->db);
620 $result = $event_project->fetch($project_id);
622 $public = $event_project->public;
624 $singleprojectaccess =
true;
626 $userProjectAccessListId = $event_project->getProjectsAuthorizedForUser(DolibarrApiAccess::$user, 0, 0);
627 $project_title = $event_project->title;
628 if (in_array($project_title, $userProjectAccessListId)) {
629 $singleprojectaccess =
true;
631 dol_syslog(
"project_title ".$project_title.
" is NOT in array from getProjectsAuthorizedForUser()", LOG_DEBUG);
635 } elseif (0 == $result) {
636 throw new RestException(500,
'Project id '.$project_id.
' not found');
638 throw new RestException(500,
'Error during fetch project '.$project_id.
': '.$this->db->lasterror());
640 } elseif ($moduleaccess && ($project_id == 0)) {
644 if ($moduleaccess && $singleprojectaccess) {
646 } elseif ($moduleaccess) {
647 throw new RestException(403,
'Event attendees access granted, but denied access to the project');
648 } elseif ($singleprojectaccess) {
649 throw new RestException(403,
'project access granted, but denied access to Event attendees');
651 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.
index($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $sqlfilters='', $properties='', $pagination_data=false)
List Event attendees.
_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.
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)
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.