/** * Function to handle class not completed events. * * @param student $student The class enrolment / student object who is "not completed" * @uses $CFG * @uses $DB * @return boolean TRUE is successful, otherwise FALSE */ public static function class_notcompleted_handler($student) { global $CFG, $DB; require_once elispm::lib('notifications.php'); /// Does the user receive a notification? $sendtouser = elis::$config->local_elisprogram->notify_classnotcompleted_user; $sendtorole = elis::$config->local_elisprogram->notify_classnotcompleted_role; $sendtosupervisor = elis::$config->local_elisprogram->notify_classnotcompleted_supervisor; /// If nobody receives a notification, we're done. if (!$sendtouser && !$sendtorole && !$sendtosupervisor) { return true; } if (!empty($student->moodlecourseid)) { if (!($context = context_course::instance($student->moodlecourseid))) { if (in_cron()) { mtrace(get_string('invalidcontext')); } else { debugging(get_string('invalidcontext')); } return true; } } else { $context = context_system::instance(); } $message = new notification(); /// Set up the text of the message $text = empty(elis::$config->local_elisprogram->notify_classnotcompleted_message) ? get_string('notifyclassnotcompletedmessagedef', self::LANG_FILE) : elis::$config->local_elisprogram->notify_classnotcompleted_message; $search = array('%%userenrolname%%', '%%classname%%', '%%coursename%%'); $user = new user($student->userid); if (!$user) { if (in_cron()) { mtrace(get_string('nouser', 'local_elisprogram')); } else { debugging(get_string('nouser', 'local_elisprogram')); } return true; } $user->load(); // Get course info $pmcourse = $DB->get_record(course::TABLE, array('id' => $student->courseid)); $pmclass = $DB->get_record(pmclass::TABLE, array('id' => $student->classid)); $replace = array($user->moodle_fullname(), $pmclass->idnumber, $pmcourse->name); $text = str_replace($search, $replace, $text); $eventlog = new Object(); $eventlog->event = 'class_notcompleted'; $eventlog->instance = $student->classid; $eventlog->fromuserid = $user->id; if ($sendtouser) { $message->send_notification($text, $user, null, $eventlog); } $users = array(); if ($sendtorole) { /// Get all users with the notify_classnotcomplete capability. if ($roleusers = get_users_by_capability($context, 'local/elisprogram:notify_classnotcomplete')) { $users = $users + $roleusers; } } if ($sendtosupervisor) { /// Get parent-context users. if ($supervisors = pm_get_users_by_capability('user', $user->id, 'local/elisprogram:notify_classnotcomplete')) { $users = $users + $supervisors; } } // Send notifications to any users who need to receive them. foreach ($users as $touser) { $message->send_notification($text, $touser, $user, $eventlog); } return true; }
/** * Function to handle course recurrence events. * * @param user $user CM user object representing the user in the course * * @return boolean TRUE is successful, otherwise FALSE */ public static function course_recurrence_handler($user) { global $CFG, $CURMAN; require_once $CFG->dirroot . '/curriculum/lib/notifications.php'; /// Does the user receive a notification? $sendtouser = $CURMAN->config->notify_courserecurrence_user; $sendtorole = $CURMAN->config->notify_courserecurrence_role; $sendtosupervisor = $CURMAN->config->notify_courserecurrence_supervisor; /// If nobody receives a notification, we're done. if (!$sendtouser && !$sendtorole && !$sendtosupervisor) { return true; } $context = get_system_context(); /// Make sure this is a valid user. $enroluser = new user($user->id); if (empty($enroluser->id)) { print_error('nouser', 'block_curr_admin'); return true; } $message = new notification(); /// Set up the text of the message $text = empty($CURMAN->config->notify_courserecurrence_message) ? get_string('notifycourserecurrencemessagedef', 'block_curr_admin') : $CURMAN->config->notify_courserecurrence_message; $search = array('%%userenrolname%%', '%%coursename%%'); $replace = array(fullname($user), $user->coursename); $text = str_replace($search, $replace, $text); $eventlog = new Object(); $eventlog->event = 'course_recurrence'; $eventlog->instance = $user->enrolmentid; $eventlog->fromuserid = $user->id; if ($sendtouser) { $message->send_notification($text, $user, null, $eventlog); } $users = array(); if ($sendtorole) { /// Get all users with the notify_courserecurrence capability. if ($roleusers = get_users_by_capability($context, 'block/curr_admin:notify_courserecurrence')) { $users = $users + $roleusers; } } if ($sendtosupervisor) { /// Get parent-context users. if ($supervisors = cm_get_users_by_capability('user', $user->id, 'block/curr_admin:notify_courserecurrence')) { $users = $users + $supervisors; } } foreach ($users as $u) { $message->send_notification($text, $u, $enroluser, $eventlog); } return true; }
/** * Function to handle curriculum not completed events. * */ public static function curriculum_notcompleted_handler($curstudent) { global $CFG, $DB; require_once elispm::lib('notifications.php'); /// Does the user receive a notification? $sendtouser = elis::$config->local_elisprogram->notify_curriculumnotcompleted_user; $sendtorole = elis::$config->local_elisprogram->notify_curriculumnotcompleted_role; $sendtosupervisor = elis::$config->local_elisprogram->notify_curriculumnotcompleted_supervisor; /// If nobody receives a notification, we're done. if (!$sendtouser && !$sendtorole && !$sendtosupervisor) { return true; } $context = context_system::instance(); // Send notifications $message = new notification(); /// Set up the text of the message $text = empty(elis::$config->local_elisprogram->notify_curriculumnotcompleted_message) ? get_string('notifycurriculumnotcompletedmessagedef', 'local_elisprogram') : elis::$config->local_elisprogram->notify_curriculumnotcompleted_message; $user = new user($curstudent->userid); if (!$user) { return true; } $user->load(); // Get course info $program = $DB->get_record(curriculum::TABLE, array('id' => $curstudent->curriculumid)); $search = array('%%userenrolname%%', '%%programname%%'); $replace = array($user->moodle_fullname(), $program->name); $text = str_replace($search, $replace, $text); $eventlog = new Object(); $eventlog->event = 'curriculum_notcompleted'; $eventlog->instance = $curstudent->id; /// Store the assignment id. $eventlog->fromuserid = $user->id; if ($sendtouser) { $message->send_notification($text, $user, null, $eventlog); } $users = array(); if ($sendtorole) { /// Get all users with the notify_curriculumnotcomplete capability. if ($roleusers = get_users_by_capability($context, 'local/elisprogram:notify_programnotcomplete')) { $users = $users + $roleusers; } } if ($sendtosupervisor) { /// Get parent-context users. if ($supervisors = pm_get_users_by_capability('user', $user->id, 'local/elisprogram:notify_programnotcomplete')) { $users = $users + $supervisors; } } foreach ($users as $u) { $message->send_notification($text, $u, $user, $eventlog); } return true; }
public static function notify($text = '', $userto = null, $userfrom = null) { $message = new notification(); $message->send_notification($text, $userto, $userfrom); }
/** * Function to handle course recurrence events. * * @param user $user CM user object representing the user in the course * * @return boolean TRUE is successful, otherwise FALSE */ public static function course_recurrence_handler($user) { global $DB; require_once elispm::lib('notifications.php'); /// Does the user receive a notification? $sendtouser = elis::$config->local_elisprogram->notify_courserecurrence_user; $sendtorole = elis::$config->local_elisprogram->notify_courserecurrence_role; $sendtosupervisor = elis::$config->local_elisprogram->notify_courserecurrence_supervisor; /// If nobody receives a notification, we're done. if (!$sendtouser && !$sendtorole && !$sendtosupervisor) { return true; } $context = context_system::instance(); /// Make sure this is a valid user. $enroluser = new user($user->userid); if (!$enroluser) { if (in_cron()) { mtrace(get_string('nouser', 'local_elisprogram')); } else { print_error('nouser', 'local_elisprogram'); } return true; } // Due to lazy loading, we need to pre-load this object $enroluser->load(); if (empty($enroluser->id)) { if (in_cron()) { mtrace(get_string('nouser', 'local_elisprogram')); } else { print_error('nouser', 'local_elisprogram'); } return true; } /// Set up the text of the message $message = new notification(); $text = empty(elis::$config->local_elisprogram->notify_courserecurrence_message) ? get_string('notifycourserecurrencemessagedef', 'local_elisprogram') : elis::$config->local_elisprogram->notify_courserecurrence_message; $search = array('%%userenrolname%%', '%%coursename%%'); $replace = array($enroluser->moodle_fullname(), $user->coursename); $text = str_replace($search, $replace, $text); $eventlog = new Object(); $eventlog->event = 'course_recurrence'; $eventlog->instance = $user->enrolmentid; $eventlog->fromuserid = $enroluser->id; if ($sendtouser) { $message->send_notification($text, $enroluser, null, $eventlog); } $users = array(); if ($sendtorole) { /// Get all users with the notify_courserecurrence capability. if ($roleusers = get_users_by_capability($context, 'local/elisprogram:notify_courserecurrence')) { $users = $users + $roleusers; } } if ($sendtosupervisor) { /// Get parent-context users. if ($supervisors = pm_get_users_by_capability('user', $enroluser->id, 'local/elisprogram:notify_courserecurrence')) { $users = $users + $supervisors; } } foreach ($users as $u) { $message->send_notification($text, $u, $enroluser, $eventlog); } return true; }
function sent_notice($comment_id) { //data o knize $sql = sql_query("select id, name, orig_name from books\n where (id = '" . $this->item . "')"); $data = sql_fetch_object($sql); $url = "kniha"; $url_param = "-" . make_url($data->id . " " . $data->name . " " . $data->orig_name); $url_param .= "#" . $comment_id; $type = "new_book_comment"; $type_param = $data->name; $sql = sql_query("select user from follow\n where (book = '" . $this->item . "')"); while ($data = sql_fetch_object($sql)) { if ($data->user != $this->uid) { $n = new notification($data->user); $n->send_notification($type, $type_param, $url, $url_param); } } }
function add_rating() { $add_rating = clear("add_rating"); if ($add_rating == 'yes' && $this->uid != $this->id) { //zjisteni jestli ma uzivatel alespon 10 komentaru, jinak nejde bodovat $s = sql_query("select id from comments\n where (user = '******' and type='book')"); $num = sql_num_rows($s); if ($num < 10) { $this->msg->set_text($this->l->t("min_comments"), "error"); } //zjisteni jestli jsem j*z bodoval uzivatele $s = sql_query("select id from users_rating\n where (user = '******' and rated_user = '******')"); $d = sql_fetch_object($s); if (!$d->id && $this->msg->is_empty()) { $s = sql_query("insert into users_rating\n (user, rated_user)\n values\n ('" . $this->uid . "', '" . $this->id . "')"); if ($s) { $this->rating++; recount("user_rating", $this->id); //zasleme uzivateli info $sql = sql_query("select id, nick from users\n\t\t\t\t\t\t\t\t where (id = '" . $this->uid . "')"); $data = sql_fetch_object($sql); $url = "uzivatel"; $url_param = "-" . make_url($data->id . " " . $data->nick); $type = "user_add_rating"; $type_param = $data->nick; $n = new notification($this->id); $n->send_notification($type, $type_param, $url, $url_param); } } } }