19use Luracast\Restler\RestException;
21require_once DOL_DOCUMENT_ROOT.
'/api/class/api.class.php';
22require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions.lib.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';
89 throw new RestException(403,
'denied read access to Event attendees');
92 $result = $this->event_attendees->fetch(
$id,
'');
94 throw new RestException(404,
'Event attendee with id '.
$id.
' not found');
97 if (!$this->event_attendees->delete(DolibarrApiAccess::$user)) {
98 throw new RestException(500,
'Error when delete event attendee : '.$this->event_attendees->error);
104 'message' =>
'event attendee deleted'
127 throw new RestException(403,
'denied read access to Event attendees');
130 $result = $this->event_attendees->fetch(0, $ref);
132 throw new RestException(404,
"Event attendee with ref ".$ref.
" not found");
135 if (!$this->event_attendees->delete(DolibarrApiAccess::$user)) {
136 throw new RestException(500,
'Error when delete event attendee : '.$this->event_attendees->error);
142 'message' =>
'event attendee deleted'
184 return $this->
_fetch(0, $ref);
208 public function index($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $sqlfilters =
'', $properties =
'', $pagination_data =
false)
216 $entity = (int) DolibarrApiAccess::$user->entity;
219 $sql =
"SELECT t.rowid";
220 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" AS t";
221 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"projet AS p ON t.fk_project = p.rowid";
222 if (isModEnabled(
'multicompany')) {
223 $sql .=
' WHERE p.entity = '.((int) $entity);
225 $sql .=
' WHERE 1 = 1';
234 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
239 $sqlTotals = str_replace(
'SELECT t.rowid',
'SELECT count(t.rowid) as total', $sql);
241 $sql .= $this->db->order($sortfield, $sortorder);
246 $offset = $limit * $page;
248 $sql .= $this->db->plimit($limit + 1, $offset);
251 dol_syslog(get_class($this).
"::index", LOG_DEBUG);
252 $result = $this->db->query($sql);
255 $num = $this->db->num_rows($result);
256 $min = min($num, ($limit <= 0 ? $num : $limit));
258 $onerowaccessgranted =
false;
260 $obj = $this->db->fetch_object($result);
262 if ($event_attendees_static->fetch($obj->rowid,
'') > 0) {
263 $rowallowaccess = $this->
_checkAccessRights(
'read', $event_attendees_static->fk_project);
264 if ($rowallowaccess) {
266 $onerowaccessgranted = $rowallowaccess;
271 if (($num > 0) && !$onerowaccessgranted) {
272 throw new RestException(403,
'No access granted for even a single of the rows found');
275 throw new RestException(503,
'Error when retrieve event attendee list : '.$this->db->lasterror());
279 if ($pagination_data) {
280 $totalsResult = $this->db->query($sqlTotals);
281 $total = $this->db->fetch_object($totalsResult)->total;
286 $obj_ret[
'data'] = $tmp;
287 $obj_ret[
'pagination'] = [
288 'total' => (int) $total,
290 'page_count' => ceil((
int) $total / $limit),
316 public function post($request_data =
null)
320 throw new RestException(403,
'denied create access to Event attendees');
324 $result = $this->
_validate($request_data);
326 foreach ($request_data as $field => $value) {
327 if ($field ===
'caller') {
329 $this->event_attendees->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
333 $this->event_attendees->$field = $this->
_checkValForAPI($field, $value, $this->event_attendees);
336 if ($this->event_attendees->create(DolibarrApiAccess::$user) < 0) {
337 throw new RestException(500,
"Error creating event attendee", array_merge(array($this->event_attendees->error), $this->event_attendees->errors));
340 return ((
int) $this->event_attendees->id);
366 throw new RestException(403,
'denied update access to Event attendees');
369 $result = $this->event_attendees->fetch(
$id,
'');
371 throw new RestException(404,
'event attendee not found');
374 foreach ($request_data as $field => $value) {
375 if ($field ==
'id') {
378 if ($field ===
'caller') {
380 $this->event_attendees->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
384 $this->event_attendees->$field = $this->
_checkValForAPI($field, $value, $this->event_attendees);
387 if ($this->event_attendees->update(DolibarrApiAccess::$user) > 0) {
390 throw new RestException(500, end($this->event_attendees->errors));
413 public function putByRef($ref, $request_data =
null)
417 throw new RestException(403,
'denied update access to Event attendees');
420 $result = $this->event_attendees->fetch(0, $ref);
422 throw new RestException(404,
'event attendee not found');
426 foreach ($request_data as $field => $value) {
427 if ($field ==
'id') {
430 if ($field ==
'ref') {
431 $newref = $this->
_checkValForAPI($field, $value, $this->event_attendees);
433 if ($field ===
'caller') {
435 $this->event_attendees->context[
'caller'] =
sanitizeVal($request_data[
'caller'],
'aZ09');
439 $this->event_attendees->$field = $this->
_checkValForAPI($field, $value, $this->event_attendees);
442 if ($this->event_attendees->update(DolibarrApiAccess::$user) > 0) {
443 return $this->
_fetch(0, $newref);
445 throw new RestException(500, end($this->event_attendees->errors));
466 $result = $this->event_attendees->fetch(
$id, $ref);
469 throw new RestException(404,
'Event attendee with id '.((
string)
$id).
' not found');
472 throw new RestException(404,
'Event attendee with ref '.$ref.
' not found');
474 throw new RestException(404,
'Event attendee not found');
476 $project_id = $this->event_attendees->fk_project;
479 throw new RestException(403,
'denied read access to Event attendees');
502 unset(
$object->array_languages);
517 unset(
$object->barcode_type_coder);
518 unset(
$object->mode_reglement_id);
519 unset(
$object->cond_reglement_id);
520 unset(
$object->demand_reason_id);
521 unset(
$object->transport_mode_id);
522 unset(
$object->shipping_method_id);
523 unset(
$object->shipping_method);
524 unset(
$object->fk_multicurrency);
525 unset(
$object->multicurrency_code);
526 unset(
$object->multicurrency_tx);
527 unset(
$object->multicurrency_total_ht);
528 unset(
$object->multicurrency_total_tva);
529 unset(
$object->multicurrency_total_ttc);
530 unset(
$object->multicurrency_total_localtax1);
531 unset(
$object->multicurrency_total_localtax2);
535 unset(
$object->total_localtax1);
536 unset(
$object->total_localtax2);
539 unset(
$object->actiontypecode);
544 unset(
$object->user_creation_id);
546 unset(
$object->user_validation);
547 unset(
$object->user_validation_id);
548 unset(
$object->user_closing_id);
549 unset(
$object->user_modification);
550 unset(
$object->user_modification_id);
553 unset(
$object->cond_reglement_supplier_id);
554 unset(
$object->deposit_percent);
555 unset(
$object->retained_warranty_fk_cond_reglement);
560 unset(
$object->date_validation);
561 unset(
$object->date_modification);
582 $event_attendees = array();
583 foreach (EventAttendees::$FIELDS as $field) {
584 if (!isset($data[$field])) {
585 throw new RestException(400, $field.
" field missing");
587 $event_attendees[$field] = $data[$field];
589 return $event_attendees;
606 $moduleaccess =
false;
607 if (isModEnabled(
"eventorganization") && DolibarrApiAccess::$user->hasRight(
'eventorganization', $accesstype)) {
608 $moduleaccess =
true;
610 $fullprojectaccess =
false;
611 if (DolibarrApiAccess::$user->hasRight(
'projet',
'all', $accesstype)) {
612 $fullprojectaccess =
true;
615 if ($moduleaccess && $fullprojectaccess) {
618 $singleprojectaccess =
false;
619 if (0 < $project_id) {
621 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
622 $event_project =
new Project($this->db);
623 $result = $event_project->fetch($project_id);
625 $public = $event_project->public;
627 $singleprojectaccess =
true;
629 $userProjectAccessListId = $event_project->getProjectsAuthorizedForUser(DolibarrApiAccess::$user, 0, 0);
630 $project_title = $event_project->title;
631 if (in_array($project_title, $userProjectAccessListId)) {
632 $singleprojectaccess =
true;
634 dol_syslog(
"project_title ".$project_title.
" is NOT in array from getProjectsAuthorizedForUser()", LOG_DEBUG);
638 } elseif (0 == $result) {
639 throw new RestException(500,
'Project id '.$project_id.
' not found');
641 throw new RestException(500,
'Error during fetch project '.$project_id.
': '.$this->db->lasterror());
643 } elseif ($moduleaccess && ($project_id == 0)) {
647 if ($moduleaccess && $singleprojectaccess) {
649 } elseif ($moduleaccess) {
650 throw new RestException(403,
'Event attendees access granted, but denied access to the project');
651 } elseif ($singleprojectaccess) {
652 throw new RestException(403,
'project access granted, but denied access to Event attendees');
654 throw new RestException(403,
'denied access both Event attendees and the project');
$id
Support class for third parties, contacts, members, users or resources.
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $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.
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.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.