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->error);
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->error);
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)
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';
238 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
243 $sqlTotals = str_replace(
'SELECT t.rowid',
'SELECT count(t.rowid) as total', $sql);
245 $sql .= $this->db->order($sortfield, $sortorder);
250 $offset = $limit * $page;
252 $sql .= $this->db->plimit($limit + 1, $offset);
255 dol_syslog(get_class($this).
"::index", LOG_DEBUG);
256 $result = $this->db->query($sql);
259 $num = $this->db->num_rows($result);
260 $min = min($num, ($limit <= 0 ? $num : $limit));
262 $onerowaccessgranted =
false;
264 $obj = $this->db->fetch_object($result);
266 if ($event_attendees_static->fetch($obj->rowid) > 0) {
267 $rowallowaccess = $this->
_checkAccessRights(
'read', $event_attendees_static->fk_project);
268 if ($rowallowaccess) {
269 if ($loadlinkedobjects) {
271 $event_attendees_static->fetchObjectLinked();
274 $onerowaccessgranted = $rowallowaccess;
279 if (($num > 0) && !$onerowaccessgranted) {
280 throw new RestException(403,
'No access granted for even a single of the rows found');
283 throw new RestException(503,
'Error when retrieve event attendee list : '.$this->db->lasterror());
287 if ($pagination_data) {
288 $totalsResult = $this->db->query($sqlTotals);
289 $total = $this->db->fetch_object($totalsResult)->total;
294 $obj_ret[
'data'] = $tmp;
295 $obj_ret[
'pagination'] = [
296 'total' => (int) $total,
298 'page_count' => ceil((
int) $total / $limit),
324 public function post($request_data =
null)
328 throw new RestException(403,
'denied create access to Event attendees');
332 $result = $this->
_validate($request_data);
334 foreach ($request_data as $field => $value) {
335 if ($field ===
'caller') {
337 $this->event_attendees->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
341 $this->event_attendees->$field = $this->
_checkValForAPI($field, $value, $this->event_attendees);
344 if ($this->event_attendees->create(DolibarrApiAccess::$user) < 0) {
345 throw new RestException(500,
"Error creating event attendee", array_merge(array($this->event_attendees->error), $this->event_attendees->errors));
348 return ((
int) $this->event_attendees->id);
373 throw new RestException(400,
'No eventattendee with id<1 can exist');
377 throw new RestException(403,
'denied update access to Event attendees');
380 $result = $this->event_attendees->fetch(
$id,
'');
382 throw new RestException(404,
'event attendee not found');
385 foreach ($request_data as $field => $value) {
386 if ($field ==
'id') {
389 if ($field ===
'caller') {
391 $this->event_attendees->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
395 $this->event_attendees->$field = $this->
_checkValForAPI($field, $value, $this->event_attendees);
398 if ($this->event_attendees->update(DolibarrApiAccess::$user) > 0) {
401 throw new RestException(500, end($this->event_attendees->errors));
424 public function putByRef($ref, $request_data =
null)
428 throw new RestException(403,
'denied update access to Event attendees');
431 $result = $this->event_attendees->fetch(0, $ref);
433 throw new RestException(404,
'event attendee not found');
437 foreach ($request_data as $field => $value) {
438 if ($field ==
'id') {
441 if ($field ==
'ref') {
442 $newref = $this->
_checkValForAPI($field, $value, $this->event_attendees);
444 if ($field ===
'caller') {
446 $this->event_attendees->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
450 $this->event_attendees->$field = $this->
_checkValForAPI($field, $value, $this->event_attendees);
453 if ($this->event_attendees->update(DolibarrApiAccess::$user) > 0) {
454 return $this->
_fetch(0, $newref);
456 throw new RestException(500, end($this->event_attendees->errors));
476 if (
$id < 1 && empty($ref)) {
477 throw new RestException(400,
'No eventattendee with id<1 can exist');
479 if (empty(
$id) && empty($ref)) {
480 throw new RestException(400,
'No eventattendee can be found with no criteria');
483 $result = $this->event_attendees->fetch(
$id, $ref);
486 throw new RestException(404,
'Event attendee with id '.((
string)
$id).
' not found');
489 throw new RestException(404,
'Event attendee with ref '.$ref.
' not found');
491 throw new RestException(404,
'Event attendee not found');
493 $project_id = $this->event_attendees->fk_project;
496 throw new RestException(403,
'denied read access to Event attendees');
499 $this->event_attendees->fetchObjectLinked();
522 unset(
$object->array_languages);
537 unset(
$object->barcode_type_coder);
538 unset(
$object->mode_reglement_id);
539 unset(
$object->cond_reglement_id);
540 unset(
$object->demand_reason_id);
541 unset(
$object->transport_mode_id);
542 unset(
$object->shipping_method_id);
543 unset(
$object->shipping_method);
544 unset(
$object->fk_multicurrency);
545 unset(
$object->multicurrency_code);
546 unset(
$object->multicurrency_tx);
547 unset(
$object->multicurrency_total_ht);
548 unset(
$object->multicurrency_total_tva);
549 unset(
$object->multicurrency_total_ttc);
550 unset(
$object->multicurrency_total_localtax1);
551 unset(
$object->multicurrency_total_localtax2);
555 unset(
$object->total_localtax1);
556 unset(
$object->total_localtax2);
559 unset(
$object->actiontypecode);
562 unset(
$object->user_creation_id);
563 unset(
$object->user_validation_id);
564 unset(
$object->user_closing_id);
565 unset(
$object->user_modification_id);
568 unset(
$object->cond_reglement_supplier_id);
569 unset(
$object->deposit_percent);
570 unset(
$object->retained_warranty_fk_cond_reglement);
575 unset(
$object->date_validation);
576 unset(
$object->date_modification);
597 $event_attendees = array();
598 foreach (EventAttendees::$FIELDS as $field) {
599 if (!isset($data[$field])) {
600 throw new RestException(400, $field.
" field missing");
602 $event_attendees[$field] = $data[$field];
604 return $event_attendees;
621 $moduleaccess =
false;
622 if (
isModEnabled(
"eventorganization") && DolibarrApiAccess::$user->hasRight(
'project', $accesstype)) {
623 $moduleaccess =
true;
625 $fullprojectaccess =
false;
626 if (DolibarrApiAccess::$user->hasRight(
'project',
'all', $accesstype)) {
627 $fullprojectaccess =
true;
630 if ($moduleaccess && $fullprojectaccess) {
633 $singleprojectaccess =
false;
634 if (0 < $project_id) {
636 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
637 $event_project =
new Project($this->db);
638 $result = $event_project->fetch($project_id);
640 $public = $event_project->public;
642 $singleprojectaccess =
true;
644 $userProjectAccessListId = $event_project->getProjectsAuthorizedForUser(DolibarrApiAccess::$user, 0, 0);
645 $project_title = $event_project->title;
646 if (in_array($project_title, $userProjectAccessListId)) {
647 $singleprojectaccess =
true;
649 dol_syslog(
"project_title ".$project_title.
" is NOT in array from getProjectsAuthorizedForUser()", LOG_DEBUG);
653 } elseif (0 == $result) {
654 throw new RestException(500,
'Project id '.$project_id.
' not found');
656 throw new RestException(500,
'Error during fetch project '.$project_id.
': '.$this->db->lasterror());
658 } elseif ($moduleaccess && ($project_id == 0)) {
662 if ($moduleaccess && $singleprojectaccess) {
664 } elseif ($moduleaccess) {
665 throw new RestException(403,
'Event attendees access granted, but denied access to the project');
666 } elseif ($singleprojectaccess) {
667 throw new RestException(403,
'project access granted, but denied access to Event attendees');
669 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.