ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilAppointmentPresentationConsultationHoursGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
11 {
12  public function collectPropertiesAndActions(): void
13  {
14  $a_app = $this->appointment;
15 
16  $cat_id = $this->getCatId($a_app['event']->getEntryId());
17  $cat_info = $this->getCatInfo();
18  $context_id = $a_app['event']->getContextId();
19 
20  $this->addCommonSection($a_app, $cat_info['obj_id']);
21 
22  //objects
23  $booking = new ilBookingEntry($context_id);
24 
25  if ($manager = ilConsultationHourAppointments::getManager(true, true, $booking->getObjId())) {
26  $this->addInfoProperty($this->lng->txt("cal_ch_manager"), $manager);
27  }
28 
29  if ($booking->isOwner($this->user->getId())) {
30  $buttons = array();
31  foreach ($booking->getTargetObjIds() as $obj_id) {
32  //$this->addObjectLinks($obj_id, $this->appointment);
33 
35  $refs = $this->getReadableRefIds($obj_id);
36  reset($refs);
37 
38  foreach ($refs as $ref_id) {
39  $link_title = $title;
40  if (count($refs) > 1) {
41  $par_ref = $this->tree->getParentId($ref_id);
42  $link_title .= " (" . ilObject::_lookupTitle(ilObject::_lookupObjId($par_ref)) . ")";
43  }
44  $buttons[] = $this->ui->renderer()->render(
45  $this->ui->factory()->button()->shy($link_title, ilLink::_getStaticLink($ref_id))
46  );
47  }
48  }
49  if (count($buttons) > 0) {
50  $this->addInfoProperty($this->lng->txt("cal_repo_obj"), implode("<br>", $buttons));
51  }
52  }
53 
54  // owner
55  $this->addInfoProperty(
56  $this->lng->txt('cal_ch_booking_owner'),
57  ilObjUser::_lookupFullname($booking->getObjId())
58  );
59 
60  if ($deadline = $booking->getDeadlineHours()) {
61  $limit = $a_app['dstart'] - ($deadline * 60 * 60);
62 
63  if (time() > $limit) {
64  $this->addInfoProperty($this->lng->txt("cal_ch_deadline"), $this->lng->txt("exc_time_over_short"));
65  //$this->addListItemProperty($this->lng->txt("cal_ch_deadline"),$this->lng->txt("exc_time_over_short"));
66  } else {
67  //appointment starts at -> $a_app['dstart']
68  //limit registration -> $a_app['dstart'] - $deadline
69 
70  //$string = ilUtil::period2String(new ilDateTime($limit, IL_CAL_UNIX));
72 
73  $this->addInfoProperty($this->lng->txt("cal_ch_deadline"), $string);
74  $this->addListItemProperty($this->lng->txt("cal_ch_deadline"), $string);
75  }
76  }
77 
78  $free = $booking->getNumberOfBookings() - $booking->getCurrentNumberOfBookings($a_app['event']->getEntryId());
79  $this->addInfoProperty(
80  $this->lng->txt('cal_ch_booking_num_available'),
81  sprintf($this->lng->txt('cal_ch_free_of_available'), $free, $booking->getNumberOfBookings())
82  );
83  $this->addListItemProperty(
84  $this->lng->txt('cal_ch_booking_num_available'),
85  sprintf($this->lng->txt('cal_ch_free_of_available'), $free, $booking->getNumberOfBookings())
86  );
87 
88  // for the following code
89  // see ilCalendarAppointmentPanelGUI in ILIAS 5.2 (getHTML())
90  $is_owner = $booking->isOwner($this->user->getId());
91  $user_entry = ($cat_info['obj_id'] == $this->user->getId());
92 
93  if ($user_entry && !$is_owner) {
94  // find source calendar entry in owner calendar
96  $booking->getObjId(),
97  $a_app['event']->getContextId(),
98  $a_app['event']->getStart()
99  );
100  $ref_event = $apps[0];
101  } else {
102  $ref_event = $a_app['event']->getEntryId();
103  }
104 
105  $cb = $booking->getCurrentNumberOfBookings($ref_event);
106  if (!$is_owner) {
107  if ($booking->hasBooked($ref_event)) {
108  if (ilDateTime::_after($a_app['event']->getStart(), new ilDateTime(time(), IL_CAL_UNIX))) {
109  $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'app_id', $ref_event);
110  //$this->ctrl->setParameterByClass('ilcalendarappointmentgui','seed',$this->getSeed()->get(IL_CAL_DATE));
111  $this->addAction(
112  $this->lng->txt('cal_ch_cancel_booking'),
113  $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'cancelBooking')
114  );
115  }
116  } elseif ($booking->isAppointmentBookableForUser($ref_event, $GLOBALS['DIC']['ilUser']->getId())) {
117  $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'app_id', $ref_event);
118  //$this->ctrl->setParameterByClass('ilcalendarappointmentgui','seed',$this->getSeed()->get(IL_CAL_DATE));
119  $this->addAction(
120  $this->lng->txt('cal_ch_book'),
121  $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'book')
122  );
123  }
124  } else {
125  // current user is owner of booking
126  if (ilDateTime::_after($a_app['event']->getStart(), new ilDateTime(time(), IL_CAL_UNIX))) {
127  $this->ctrl->setParameterByClass('ilcalendarappointmentgui', 'app_id', $a_app['event']->getEntryId());
128  $this->addAction(
129  $this->lng->txt('cal_ch_cancel_booking'),
130  $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'cancelBooking')
131  );
132  $this->addAction(
133  $this->lng->txt('cal_ch_delete_booking'),
134  $this->ctrl->getLinkTargetByClass('ilcalendarappointmentgui', 'deleteBooking')
135  );
136  }
137  $link_users = true;
139  $link_users = false;
140  }
141  $users = [];
142  $booking_comments = [];
143  foreach ($booking->getCurrentBookings($a_app['event']->getEntryId()) as $user_id) {
144 
145  $booking_comments[$user_id] = ilBookingEntry::lookupBookingMessage(
146  $a_app['event']->getEntryId(),
147  $user_id
148  );
149  if ($link_users) {
150  $users[$user_id] = $this->getUserName($user_id);
151  } else {
152  $users[$user_id] = ilObjUser::_lookupFullname($user_id);
153  }
154  }
155  if ($users) {
156  foreach ($booking_comments as $user_id => $comment) {
157  $this->addInfoProperty($this->lng->txt('cal_ch_current_bookings'), $users[$user_id]);
158  $this->addInfoProperty($this->lng->txt('cal_ch_current_booking_comment'), $comment);
159  }
160  $this->addListItemProperty($this->lng->txt('cal_ch_current_bookings'), implode(' ', $users));
161  }
162  }
163  }
164 }
static getManager(bool $a_as_name=false, bool $a_full_name=false, int $a_user_id=null)
Get consultation hour manager for current user or specific user.
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ilObjUser $user=null,)
addListItemProperty(string $a_txt, string $a_val)
Add list item property.
static _lookupFullname(int $a_user_id)
const IL_CAL_UNIX
addInfoProperty(string $a_txt, string $a_val)
Add info property.
static _lookupObjId(int $ref_id)
static getAppointmentIds(int $a_user_id, int $a_context_id=null, ?ilDateTime $a_start=null, ?int $a_type=null, bool $a_check_owner=true)
$ref_id
Definition: ltiauth.php:66
static _lookupTitle(int $obj_id)
$GLOBALS["DIC"]
Definition: wac.php:30
static _after(ilDateTime $start, ilDateTime $end, string $a_compare_field='', string $a_tz='')
compare two dates and check start is after end This method does not consider tz offsets.
getUserName(int $a_user_id, bool $a_force_name=false)
Get (linked if possible) user name.
static _getInstance($a_usr_id=0)
get singleton instance
$comment
Definition: buildRTE.php:72
addCommonSection(array $a_app, int $a_obj_id=0, ?array $cat_info=null, bool $a_container_info=false)
addAction(string $a_txt, string $a_link)
Add action.
static lookupBookingMessage(int $a_entry_id, int $a_usr_id)