/**
  * Parse Groups
  * @param array $groups
  */
 public function parse(array $groups)
 {
     $rows = array();
     $counter = 0;
     foreach ($groups as $group) {
         $rows[$counter]['id'] = $group->getGroupId();
         $rows[$counter]['title'] = $group->getTitle();
         $rows[$counter]['max_books'] = $group->getMaxAssignments();
         $rows[$counter]['assigned'] = count(ilConsultationHourAppointments::getAppointmentIdsByGroup($this->user_id, $group->getGroupId(), null));
         ++$counter;
     }
     $this->setData($rows);
 }
 /**
  * 
  * @param array $usr_ids
  * @param type $type
  */
 public function assignUsersToGroup(array $usr_ids)
 {
     global $ilCtrl;
     $group_id = (int) $_REQUEST['grp_id'];
     $tomorrow = new ilDateTime(time(), IL_CAL_UNIX);
     $tomorrow->increment(IL_CAL_DAY, 1);
     // Get all future consultation hours
     include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourAppointments.php';
     include_once './Services/Booking/classes/class.ilBookingEntry.php';
     $apps = ilConsultationHourAppointments::getAppointmentIdsByGroup($this->user_id, $group_id, $tomorrow);
     $users = $usr_ids;
     $assigned_users = array();
     foreach ($apps as $app) {
         $booking = ilBookingEntry::getInstanceByCalendarEntryId($app);
         foreach ($users as $user) {
             if ($booking->getCurrentNumberOfBookings($app) >= $booking->getNumberOfBookings()) {
                 break;
             }
             if (!ilBookingEntry::lookupBookingsOfUser($apps, $user)) {
                 include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourUtils.php';
                 ilConsultationHourUtils::bookAppointment($user, $app);
                 $assigned_users[] = $user;
             }
         }
     }
     $this->sendInfoAboutUnassignedUsers(array_diff($users, $assigned_users));
     $ilCtrl->redirect($this, 'bookingList');
 }
예제 #3
0
 /**
  * Check if a calendar appointment is bookable for a specific user
  * @param type $a_cal_entry_id
  * @param type $a_user_id
  * @return bool
  */
 public function isAppointmentBookableForUser($a_app_id, $a_user_id)
 {
     // #12025
     if ($a_user_id == ANONYMOUS_USER_ID) {
         return false;
     }
     // Check max bookings
     if ($this->getNumberOfBookings() <= $this->getCurrentNumberOfBookings($a_app_id)) {
         #$GLOBALS['ilLog']->write(__METHOD__.': Number of bookings exceeded');
         return false;
     }
     // Check deadline
     $dead_limit = new ilDateTime(time(), IL_CAL_UNIX);
     $dead_limit->increment(IL_CAL_HOUR, $this->getDeadlineHours());
     include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
     $entry = new ilCalendarEntry($a_app_id);
     if (ilDateTime::_after($dead_limit, $entry->getStart())) {
         #$GLOBALS['ilLog']->write(__METHOD__.': Deadline reached');
         return false;
     }
     // Check group restrictions
     if (!$this->getBookingGroup()) {
         #$GLOBALS['ilLog']->write(__METHOD__.': No booking group');
         return true;
     }
     include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourAppointments.php';
     $group_apps = ilConsultationHourAppointments::getAppointmentIdsByGroup($this->getObjId(), $this->getBookingGroup());
     // Number of bookings in group
     $bookings = self::lookupBookingsOfUser($group_apps, $a_user_id);
     include_once './Services/Calendar/classes/ConsultationHours/class.ilConsultationHourGroups.php';
     #$GLOBALS['ilLog']->write(__METHOD__.': '.ilConsultationHourGroups::lookupMaxBookings($this->getBookingGroup()));
     if (count($bookings) >= ilConsultationHourGroups::lookupMaxBookings($this->getBookingGroup())) {
         #$GLOBALS['ilLog']->write(__METHOD__.': Personal booking limit reached');
         return false;
     }
     #$GLOBALS['ilLog']->write(__METHOD__.': Is bookable!');
     return true;
 }