Exemplo n.º 1
0
/**
 * This function extends the navigation with the tool items for user settings node.
 *
 * @param navigation_node $navigation  The navigation node to extend
 * @param stdClass        $user        The user object
 * @param context         $usercontext The context of the user
 * @param stdClass        $course      The course to object for the tool
 * @param context         $coursecontext     The context of the course
 */
function tool_monitor_extend_navigation_user_settings($navigation, $user, $usercontext, $course, $coursecontext)
{
    global $USER, $SITE;
    // Don't show the setting if the event monitor isn't turned on. No access to other peoples subscriptions.
    if (get_config('tool_monitor', 'enablemonitor') && $USER->id == $user->id) {
        // Now let's check to see if the user has any courses / site rules that they can subscribe to.
        if ($courses = tool_monitor_get_user_courses()) {
            $url = new moodle_url('/admin/tool/monitor/index.php');
            $subsnode = navigation_node::create(get_string('managesubscriptions', 'tool_monitor'), $url, navigation_node::TYPE_SETTING, null, 'monitor', new pix_icon('i/settings', ''));
            if (isset($subsnode) && !empty($navigation)) {
                $navigation->add_node($subsnode);
            }
        }
    }
}
Exemplo n.º 2
0
 /**
  * Gets a list of courses where the current user can subscribe to rules as a dropdown.
  *
  * @param bool $choose A flag for whether to show the 'choose...' option in the select box.
  * @return \single_select|bool returns the list of courses, or false if the select box
  *      should not be displayed.
  */
 public function get_user_courses_select($choose = false)
 {
     $options = tool_monitor_get_user_courses();
     // If we have no options then don't create a select element.
     if (!$options) {
         return false;
     }
     $selected = $this->courseid;
     $nothing = array();
     if ($choose) {
         $selected = null;
         $nothing = array('choosedots');
     }
     $url = new \moodle_url('/admin/tool/monitor/index.php');
     $select = new \single_select($url, 'courseid', $options, $selected, $nothing);
     $select->set_label(get_string('selectacourse', 'tool_monitor'));
     return $select;
 }
Exemplo n.º 3
0
require_once $CFG->dirroot . '/admin/tool/monitor/lib.php';
$courseid = optional_param('courseid', 0, PARAM_INT);
$action = optional_param('action', '', PARAM_ALPHA);
$cmid = optional_param('cmid', 0, PARAM_INT);
$ruleid = optional_param('ruleid', 0, PARAM_INT);
$subscriptionid = optional_param('subscriptionid', 0, PARAM_INT);
$confirm = optional_param('confirm', false, PARAM_BOOL);
$choose = false;
// Validate course id.
if (empty($courseid)) {
    require_login();
    $context = context_system::instance();
    // check system level capability.
    if (!has_capability('tool/monitor:subscribe', $context)) {
        // If not system level then check to see if they have access to any course level rules.
        if (tool_monitor_get_user_courses()) {
            // Make them choose a course.
            $choose = true;
        } else {
            // return error.
            print_error('rulenopermission', 'tool_monitor');
        }
    }
} else {
    // They might want to see rules for this course.
    $course = get_course($courseid);
    require_login($course);
    $context = context_course::instance($course->id);
    // Check for caps.
    require_capability('tool/monitor:subscribe', $context);
}