public function run()
 {
     global $ilSetting, $ilDB;
     $status = ilCronJobResult::STATUS_NO_ACTION;
     $days_before = $ilSetting->get('ch_reminder_days');
     $now = new ilDateTime(time(), IL_CAL_UNIX);
     $limit = clone $now;
     $limit->increment(IL_CAL_DAY, $days_before);
     $counter = 0;
     $query = 'SELECT * FROM booking_user ' . 'JOIN cal_entries ON entry_id = cal_id ' . 'WHERE notification_sent = ' . $ilDB->quote(0, 'integer') . ' ' . 'AND starta > ' . $ilDB->quote($now->get(IL_CAL_DATETIME, '', ilTimeZone::UTC), 'timestamp') . ' ' . 'AND starta <= ' . $ilDB->quote($limit->get(IL_CAL_DATETIME, '', ilTimeZone::UTC), 'timestamp');
     $res = $ilDB->query($query);
     while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) {
         include_once 'Services/Calendar/classes/class.ilCalendarMailNotification.php';
         $mail = new ilCalendarMailNotification();
         $mail->setAppointmentId($row->entry_id);
         $mail->setRecipients(array($row->user_id));
         $mail->setType(ilCalendarMailNotification::TYPE_BOOKING_REMINDER);
         $mail->send();
         // update notification
         $query = 'UPDATE booking_user ' . 'SET notification_sent = ' . $ilDB->quote(1, 'integer') . ' ' . 'WHERE user_id = ' . $ilDB->quote($row->user_id, 'integer') . ' ' . 'AND entry_id = ' . $ilDB->quote($row->entry_id, 'integer');
         $ilDB->manipulate($query);
         $counter++;
     }
     if ($counter) {
         $status = ilCronJobResult::STATUS_OK;
     }
     $result = new ilCronJobResult();
     $result->setStatus($status);
     return $result;
 }
 /**
  * Send mail to selected users
  * @global ilObjUser $ilUser 
  */
 protected function distributeUserNotifications()
 {
     global $ilUser;
     include_once './Services/Calendar/classes/class.ilCalendarMailNotification.php';
     $notification = new ilCalendarMailNotification();
     $notification->setAppointmentId($this->app->getEntryId());
     foreach ($this->notification->getRecipients() as $rcp) {
         switch ($rcp['type']) {
             case ilCalendarUserNotification::TYPE_USER:
                 $notification->setSender(ANONYMOUS_USER_ID);
                 $notification->setRecipients(array($rcp['usr_id']));
                 $notification->setType(ilCalendarMailNotification::TYPE_USER);
                 break;
             case ilCalendarUserNotification::TYPE_EMAIL:
                 $notification->setSender(ANONYMOUS_USER_ID);
                 $notification->setRecipients(array($rcp['email']));
                 $notification->setType(ilCalendarMailNotification::TYPE_USER_ANONYMOUS);
                 break;
         }
         $notification->send();
     }
 }
 /**
  * cancel calendar booking for user
  * @param	int	$a_entry_id
  * @param	int	$a_user_id
  */
 public function cancelBooking($a_entry_id, $a_user_id = false)
 {
     global $ilUser, $ilDB;
     if (!$a_user_id) {
         $a_user_id = $ilUser->getId();
     }
     if ($this->hasBooked($a_entry_id, $a_user_id)) {
         include_once 'Services/Calendar/classes/class.ilCalendarMailNotification.php';
         $mail = new ilCalendarMailNotification();
         $mail->setAppointmentId($a_entry_id);
         $mail->setRecipients(array($a_user_id));
         $mail->setType(ilCalendarMailNotification::TYPE_BOOKING_CANCELLATION);
         $mail->send();
         $ilDB->manipulate('DELETE FROM booking_user' . ' WHERE entry_id = ' . $ilDB->quote($a_entry_id, 'integer') . ' AND user_id = ' . $ilDB->quote($a_user_id, 'integer'));
     }
     return true;
 }
Ejemplo n.º 4
0
 /**
  * cancel calendar booking for user
  * @param	int	$a_entry_id
  * @param	int	$a_user_id
  */
 public function cancelBooking($a_entry_id, $a_user_id = false)
 {
     global $ilUser, $ilDB;
     if (!$a_user_id) {
         $a_user_id = $ilUser->getId();
     }
     // @todo do not send mails about past consultation hours
     $entry = new ilCalendarEntry($a_entry_id);
     $past = ilDateTime::_before($entry->getStart(), new ilDateTime(time(), IL_CAL_UNIX));
     if ($this->hasBooked($a_entry_id, $a_user_id) && !$past) {
         include_once 'Services/Calendar/classes/class.ilCalendarMailNotification.php';
         $mail = new ilCalendarMailNotification();
         $mail->setAppointmentId($a_entry_id);
         $mail->setRecipients(array($a_user_id));
         $mail->setType(ilCalendarMailNotification::TYPE_BOOKING_CANCELLATION);
         $mail->send();
     }
     $this->deleteBooking($a_entry_id, $a_user_id);
     return true;
 }