function get_content() { global $CFG, $COURSE; $context = get_context_instance(CONTEXT_COURSE, $COURSE->id); $sitecontext = get_context_instance(CONTEXT_COURSE, SITEID); if (!has_capability('moodle/local:viewcoursestatus', $context) && !has_capability('moodle/local:canselfassignheadeditor', $sitecontext)) { $this->content = NULL; return $this->content; } if ($this->content !== NULL) { return $this->content; } if (empty($this->instance)) { return ''; } $this->content = new stdClass(); $this->content->text = tao_get_course_status_desc($COURSE); if (has_capability('moodle/local:canselfassignheadeditor', $sitecontext)) { // check if this needs an editor $editors = tao_get_headeditors($context); if (empty($editors)) { $this->content->text .= '<br /><br />' . get_string('needseditor', 'block_tao_course_status') . '<br />'; $this->content->text .= '<a href="' . $CFG->wwwroot . '/local/lp/selfassignedit.php?id=' . $COURSE->id . '">' . get_string('editlearningpath', 'block_tao_course_status') . '</a>'; } } // footer $footer = ""; if (has_capability('moodle/local:updatecoursestatus', get_context_instance(CONTEXT_COURSE, $COURSE->id))) { $footer = '<a href="' . $CFG->wwwroot . '/course/view.php?id=' . $COURSE->id . '&action=changestatus">' . get_string('change', 'block_tao_course_status') . '...</a><br/>'; } $footer .= '<a href="' . $CFG->wwwroot . '/course/view.php?id=' . $COURSE->id . '&action=statushistory">' . get_string('history', 'block_tao_course_status') . '...</a><br/>'; $this->content->footer = "<br/>{$footer}"; return $this->content; }
/** * Event handling for when a learning path is submitted for approval. * Currently just handles notifications to the appropriate editors. */ function tao_handle_learning_path_submission_event($eventdata) { global $CFG; require_once $CFG->dirroot . '/local/lib/messagelib.php'; require_once $CFG->dirroot . '/message/lib.php'; // load our user $user = get_record('user', 'id', $eventdata['userid']); if (empty($user)) { mtrace("Invalid user"); return; } // load our course $course = get_record('course', 'id', $eventdata['courseid']); if (empty($course)) { mtrace("Invalid course"); return; } $format = FORMAT_HTML; // compose message body $body = get_string('lpsubmitted', 'local') . '.<br />'; $body .= '<a href="' . $CFG->wwwroot . '/course/view.php?id=' . $course->id . '" target="_blank">' . $course->fullname . '</a> '; $body .= get_string('submittedby', 'local') . ' ' . $user->firstname . ' ' . $user->lastname . '.<br />'; $body .= '"' . $eventdata['reason'] . '"'; // look for any head editors for this course that might already exist $editors = tao_get_headeditors(get_context_instance(CONTEXT_COURSE, $course->id)); if (!empty($editors)) { // Notify existing editors of the learning path that it is ready for review foreach ($editors as $editor) { if ($editor->id == $user->id) { continue; } message_post_message($user, $editor, $body, $format, 'direct'); } } else { // Notify ALL editors that the learning path needs an editor $site = get_record('course', 'id', SITEID); // use the targetted messaging api for tao $targetobject = (object) tao_message_target_get(TM_ALL_HEADEDITORS, $site); if ($count = tao_message_count_recipients_by_target($targetobject, $site)) { $targetobject->key = TM_ALL_HEADEDITORS; $eventdata = array('body' => $body, 'from' => $user->id, 'format' => $format, 'course' => $site, 'target' => $targetobject); events_trigger('tao_message_role', $eventdata); echo get_string('messagequeued', 'local'); } } return true; }