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; }
/** * Distribute mail notifications * @return */ protected function distributeNotifications($a_cat_id, $app_id, $a_new_appointment = true) { include_once './Services/Calendar/classes/class.ilCalendarCategory.php'; $cat_info = ilCalendarCategories::_getInstance()->getCategoryInfo($a_cat_id); include_once './Services/Calendar/classes/class.ilCalendarMailNotification.php'; $notification = new ilCalendarMailNotification(); $notification->setAppointmentId($app_id); switch ($cat_info['type']) { case ilCalendarCategory::TYPE_OBJ: switch ($cat_info['obj_type']) { case 'crs': $ref_ids = ilObject::_getAllReferences($cat_info['obj_id']); $ref_id = current($ref_ids); $notification->setRefId($ref_id); $notification->setType($a_new_appointment ? ilCalendarMailNotification::TYPE_CRS_NEW_NOTIFICATION : ilCalendarMailNotification::TYPE_CRS_NOTIFICATION); break; case 'grp': $ref_ids = ilObject::_getAllReferences($cat_info['obj_id']); $ref_id = current($ref_ids); $notification->setRefId($ref_id); $notification->setType($a_new_appointment ? ilCalendarMailNotification::TYPE_GRP_NEW_NOTIFICATION : ilCalendarMailNotification::TYPE_GRP_NOTIFICATION); break; } 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; }
/** * 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; }