/** * Gets a stored file for the backup course filearea directory. * * @param int $itemid item ID * @param string $filepath file path * @param string $filename file name * @return file_info|null file_info instance or null if not found or access not allowed */ protected function get_area_backup_course($itemid, $filepath, $filename) { global $CFG; if (!isloggedin()) { return null; } if (!has_any_capability(array('moodle/backup:backupcourse', 'moodle/restore:restorecourse'), $this->context)) { return null; } if (is_null($itemid)) { return $this; } $fs = get_file_storage(); $filepath = is_null($filepath) ? '/' : $filepath; $filename = is_null($filename) ? '.' : $filename; if (!($storedfile = $fs->get_file($this->context->id, 'backup', 'course', 0, $filepath, $filename))) { if ($filepath === '/' && $filename === '.') { $storedfile = new virtual_root_file($this->context->id, 'backup', 'course', 0); } else { // Not found. return null; } } $downloadable = has_capability('moodle/backup:downloadfile', $this->context); $uploadable = has_capability('moodle/restore:uploadfile', $this->context); $urlbase = $CFG->wwwroot . '/pluginfile.php'; return new file_info_stored($this->browser, $this->context, $storedfile, $urlbase, get_string('coursebackup', 'repository'), false, $downloadable, $uploadable, false); }
/** * Return array of rows where each row is an array of tab objects * taking into account permissions of current user */ public function get_tabs() { $toprow = array(); $context = $this->att->context; $capabilities = array('mod/attendance:manageattendances', 'mod/attendance:takeattendances', 'mod/attendance:changeattendances'); if (has_any_capability($capabilities, $context)) { $toprow[] = new tabobject(self::TAB_SESSIONS, $this->att->url_manage()->out(), get_string('sessions', 'attendance')); } if (has_capability('mod/attendance:manageattendances', $context)) { $toprow[] = new tabobject(self::TAB_ADD, $this->att->url_sessions()->out(true, array('action' => att_sessions_page_params::ACTION_ADD)), get_string('add', 'attendance')); } if (has_capability('mod/attendance:viewreports', $context)) { $toprow[] = new tabobject(self::TAB_REPORT, $this->att->url_report()->out(), get_string('report', 'attendance')); } if (has_capability('mod/attendance:export', $context)) { $toprow[] = new tabobject(self::TAB_EXPORT, $this->att->url_export()->out(), get_string('export', 'attendance')); } if (has_capability('mod/attendance:changepreferences', $context)) { $toprow[] = new tabobject(self::TAB_PREFERENCES, $this->att->url_preferences()->out(), get_string('settings', 'attendance')); } if (has_capability('mod/attendance:managetemporaryusers', $context)) { $toprow[] = new tabobject(self::TAB_TEMPORARYUSERS, $this->att->url_managetemp()->out(), get_string('tempusers', 'attendance')); } return array($toprow); }
protected function specific_definition($mform) { global $CFG, $DB, $USER; // Fields for editing block contents. $mform->addElement('header', 'configheader', get_string('blocksettings', 'block')); $mform->addElement('text', 'config_title', get_string('uploadlabel')); $mform->setType('config_title', PARAM_NOTAGS); $mform->addElement('text', 'config_shownumentries', get_string('shownumentrieslabel', 'block_rss_plus'), array('size' => 5)); $mform->setType('config_shownumentries', PARAM_INTEGER); $mform->addRule('config_shownumentries', null, 'numeric', null, 'client'); if (!empty($CFG->block_rss_plus_num_entries)) { $mform->setDefault('config_shownumentries', $CFG->block_rss_plus_num_entries); } else { $mform->setDefault('config_shownumentries', 5); } $rssfeeds = $DB->get_records_sql_menu(' SELECT id, CASE WHEN preferredtitle = ? THEN ' . $DB->sql_compare_text('title', 64) . ' ELSE preferredtitle END FROM {block_rss_plus} WHERE userid = ? OR shared = 1 ORDER BY CASE WHEN preferredtitle = ? THEN ' . $DB->sql_compare_text('title', 64) . ' ELSE preferredtitle END ', array($DB->sql_empty(), $USER->id, $DB->sql_empty())); if ($rssfeeds) { $select = $mform->addElement('select', 'config_rssid', get_string('choosefeedlabel', 'block_rss_plus'), $rssfeeds); $select->setMultiple(true); } else { $mform->addElement('static', 'config_rssid', get_string('choosefeedlabel', 'block_rss_plus'), get_string('nofeeds', 'block_rss_plus')); } if (has_any_capability(array('block/rss_plus:manageanyfeeds', 'block/rss_plus:manageownfeeds'), $this->block->context)) { $mform->addElement('static', 'nofeedmessage', '', '<div class="rssaddfeedlink"><a class="rssaddfeedlink" href="' . $CFG->wwwroot . '/blocks/rss_plus/managefeeds.php?courseid=' . $this->page->course->id . '">' . get_string('feedsaddedit', 'block_rss_plus') . '</a></div>'); } }
/** * Export the data. * * @param renderer_base $output * @return stdClass */ public function export_for_template(renderer_base $output) { global $CFG, $DB, $PAGE; $context = context_course::instance($this->courseid); $data = new stdClass(); $data->userid = $this->userid; $data->competencyid = $this->competencyid; $data->courseid = $this->courseid; $data->baseurl = $this->baseurl; $data->groupselector = ''; if (has_any_capability(array('moodle/competency:usercompetencyview', 'moodle/competency:coursecompetencymanage'), $context)) { $course = $DB->get_record('course', array('id' => $this->courseid)); $currentgroup = groups_get_course_group($course, true); if ($currentgroup !== false) { $select = groups_allgroups_course_menu($course, $PAGE->url, true, $currentgroup); $data->groupselector = $select; } // Fetch showactive. $defaultgradeshowactiveenrol = !empty($CFG->grade_report_showonlyactiveenrol); $showonlyactiveenrol = get_user_preferences('grade_report_showonlyactiveenrol', $defaultgradeshowactiveenrol); $showonlyactiveenrol = $showonlyactiveenrol || !has_capability('moodle/course:viewsuspendedusers', $context); $users = get_enrolled_users($context, 'moodle/competency:coursecompetencygradable', $currentgroup, 'u.*', null, 0, 0, $showonlyactiveenrol); $data->users = array(); foreach ($users as $user) { $exporter = new user_summary_exporter($user); $user = $exporter->export($output); if ($user->id == $this->userid) { $user->selected = true; } $data->users[] = $user; } $data->hasusers = true; } else { $data->users = array(); $data->hasusers = false; } $coursecompetencies = \core_competency\api::list_course_competencies($this->courseid); $data->competencies = array(); $contextcache = array(); foreach ($coursecompetencies as $coursecompetency) { $frameworkid = $coursecompetency['competency']->get_competencyframeworkid(); if (!isset($contextcache[$frameworkid])) { $contextcache[$frameworkid] = $coursecompetency['competency']->get_context(); } $context = $contextcache[$frameworkid]; $coursecompetencycontext = $context; $exporter = new competency_exporter($coursecompetency['competency'], array('context' => $coursecompetencycontext)); $competency = $exporter->export($output); if ($competency->id == $this->competencyid) { $competency->selected = true; } $data->competencies[] = $competency; } $data->hascompetencies = count($data->competencies); return $data; }
public function resolve_dependencies() { parent::resolve_dependencies(); if (!$this->usercanseegrades) { $this->slotmarks = false; } // We only want to show the checkbox to delete attempts // if the user has permissions and if the report mode is showing attempts. $this->checkboxcolumn = has_any_capability(array('mod/quiz:regrade', 'mod/quiz:deleteattempts'), context_module::instance($this->cm->id)) && $this->attempts != quiz_attempts_report::ENROLLED_WITHOUT; }
/** * Dictates that a user must have one of the given capabilities to view the current page * @param array $capabilities An array of capability names. * @param object $context The context to check the capability in. * @param integer $userid A user id. By default (null) checks the permissions of the current user. * @param bool $doanything If false, ignore effect of admin role assignment * @param string $errorstring The error string to to user. Defaults to 'nopermissions'. * @param string $stringfile The language file to load the error string from. Defaults to 'error'. * @return void Terminates with an error if the user does not have the given capability. * @version 2011080401 * @since 2011080401 */ public static function require_any_capability($capabilities, $context, $userid = null, $doanything = true, $errormessage = 'nopermissions', $stringfile = '') { if (!is_array($capabilities)) { $capabilities = array($capabilities); } if (!has_any_capability($capabilities, $context, $userid, $doanything)) { throw new required_capability_exception($context, $capabilities[0], $errormessage, $stringfile); } // Just use the top one }
function get_content() { global $USER, $CFG, $SESSION; $cal_m = optional_param('cal_m', 0, PARAM_INT); $cal_y = optional_param('cal_y', 0, PARAM_INT); require_once $CFG->dirroot . '/calendar/lib.php'; if ($this->content !== NULL) { return $this->content; } $this->content = new stdClass(); $this->content->text = ''; $filtercourse = array(); if (empty($this->instance)) { // Overrides: use no course at all $courseshown = false; $this->content->footer = ''; } else { $courseshown = $this->page->course->id; $this->content->footer = '<div class="gotocal"><a href="' . $CFG->wwwroot . '/calendar/view.php?view=upcoming&course=' . $courseshown . '">' . get_string('gotocalendar', 'calendar') . '</a>...</div>'; $context = context_course::instance($courseshown); if (has_any_capability(array('moodle/calendar:manageentries', 'moodle/calendar:manageownentries'), $context)) { $this->content->footer .= '<div class="newevent"><a href="' . $CFG->wwwroot . '/calendar/event.php?action=new&course=' . $courseshown . '">' . get_string('newevent', 'calendar') . '</a>...</div>'; } if ($courseshown == SITEID) { // Being displayed at site level. This will cause the filter to fall back to auto-detecting // the list of courses it will be grabbing events from. $filtercourse = calendar_get_default_courses(); } else { // Forcibly filter events to include only those from the particular course we are in. $filtercourse = array($courseshown => $this->page->course); } } list($courses, $group, $user) = calendar_set_filters($filtercourse); $defaultlookahead = CALENDAR_DEFAULT_UPCOMING_LOOKAHEAD; if (isset($CFG->calendar_lookahead)) { $defaultlookahead = intval($CFG->calendar_lookahead); } $lookahead = get_user_preferences('calendar_lookahead', $defaultlookahead); $defaultmaxevents = CALENDAR_DEFAULT_UPCOMING_MAXEVENTS; if (isset($CFG->calendar_maxevents)) { $defaultmaxevents = intval($CFG->calendar_maxevents); } $maxevents = get_user_preferences('calendar_maxevents', $defaultmaxevents); $events = calendar_get_upcoming($courses, $group, $user, $lookahead, $maxevents); if (!empty($this->instance)) { $this->content->text = calendar_get_block_upcoming($events, 'view.php?view=day&course=' . $courseshown . '&'); } if (empty($this->content->text)) { $this->content->text = '<div class="post">' . get_string('noupcomingevents', 'calendar') . '</div>'; } return $this->content; }
/** * @throws coding_exception */ public function __construct() { global $PAGE, $COURSE; // Page path blacklist for admin menu. $adminblockblacklist = ['/user/profile.php']; if (in_array(local::current_url_path(), $adminblockblacklist)) { return; } // Admin users always see the admin menu with the exception of blacklisted pages. // The admin menu shows up for other users if they are a teacher in the current course. if (!is_siteadmin()) { // We don't want students to see the admin menu ever. // Editing teachers are identified as people who can manage activities and non editing teachers as those who // can view the gradebook. As editing teachers are almost certain to also be able to view the gradebook, the // grader:view capability is checked first. $caps = ['gradereport/grader:view', 'moodle/course:manageactivities']; $canmanageacts = has_any_capability($caps, $PAGE->context); $isstudent = !$canmanageacts && !is_role_switched($COURSE->id); if ($isstudent) { return; } } if (!$PAGE->blocks->is_block_present('settings')) { // Throw error if on front page or course page. // (There are pages that don't have a settings block so we shouldn't throw an error on those pages). if (strpos($PAGE->pagetype, 'course-view') === 0 || $PAGE->pagetype === 'site-index') { debugging('Settings block was not found on this page', DEBUG_DEVELOPER); } return; } // Core Moodle API appears to be missing a 'get block by name' function. // Cycle through all regions and block instances until we find settings. foreach ($PAGE->blocks->get_regions() as $region) { foreach ($PAGE->blocks->get_blocks_for_region($region) as $block) { if (isset($block->instance) && $block->instance->blockname == 'settings') { $this->instanceid = $block->instance->id; break 2; } } } if (!has_capability('moodle/block:view', \context_block::instance($this->instanceid))) { return; } $this->output = true; }
/** * This function extends the course navigation * * @param navigation_node $navigation The navigation node to extend * @param stdClass $course The course to object for the tool * @param context $coursecontext The context of the course */ function tool_lp_extend_navigation_course($navigation, $course, $coursecontext) { if (!get_config('core_competency', 'enabled')) { return; } // Check access to the course and competencies page. $capabilities = array('moodle/competency:coursecompetencyview', 'moodle/competency:coursecompetencymanage'); $context = context_course::instance($course->id); if (!has_any_capability($capabilities, $context) || !can_access_course($course)) { return; } // Just a link to course competency. $title = get_string('competencies', 'core_competency'); $path = new moodle_url("/admin/tool/lp/coursecompetencies.php", array('courseid' => $course->id)); $settingsnode = navigation_node::create($title, $path, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/competencies', '')); if (isset($settingsnode)) { $navigation->add_node($settingsnode); } }
protected function specific_definition($mform) { global $CFG, $DB, $USER; // Fields for editing block contents. $mform->addElement('header', 'configheader', get_string('blocksettings', 'block')); $mform->addElement('selectyesno', 'config_display_description', get_string('displaydescriptionlabel', 'block_rss_client')); $mform->setDefault('config_display_description', 0); $mform->addElement('text', 'config_shownumentries', get_string('shownumentrieslabel', 'block_rss_client'), array('size' => 5)); $mform->setType('config_shownumentries', PARAM_INT); $mform->addRule('config_shownumentries', null, 'numeric', null, 'client'); if (!empty($CFG->block_rss_client_num_entries)) { $mform->setDefault('config_shownumentries', $CFG->block_rss_client_num_entries); } else { $mform->setDefault('config_shownumentries', 5); } $insql = ''; $params = array('userid' => $USER->id); $rssconfig = unserialize(base64_decode($this->block->instance->configdata)); if ($rssconfig && !empty($rssconfig->rssid)) { list($insql, $inparams) = $DB->get_in_or_equal($rssconfig->rssid, SQL_PARAMS_NAMED); $insql = "OR id {$insql} "; $params += $inparams; } $titlesql = "CASE WHEN preferredtitle = '' THEN {$DB->sql_compare_text('title', 64)} ELSE preferredtitle END"; $rssfeeds = $DB->get_records_sql_menu("\n SELECT id, {$titlesql}\n FROM {block_rss_client}\n WHERE userid = :userid OR shared = 1 {$insql}\n ORDER BY {$titlesql}", $params); if ($rssfeeds) { $select = $mform->addElement('select', 'config_rssid', get_string('choosefeedlabel', 'block_rss_client'), $rssfeeds); $select->setMultiple(true); } else { $mform->addElement('static', 'config_rssid_no_feeds', get_string('choosefeedlabel', 'block_rss_client'), get_string('nofeeds', 'block_rss_client')); } if (has_any_capability(array('block/rss_client:manageanyfeeds', 'block/rss_client:manageownfeeds'), $this->block->context)) { $mform->addElement('static', 'nofeedmessage', '', '<a href="' . $CFG->wwwroot . '/blocks/rss_client/managefeeds.php?courseid=' . $this->page->course->id . '">' . get_string('feedsaddedit', 'block_rss_client') . '</a>'); } $mform->addElement('text', 'config_title', get_string('uploadlabel')); $mform->setType('config_title', PARAM_NOTAGS); $mform->addElement('selectyesno', 'config_block_rss_client_show_channel_link', get_string('clientshowchannellinklabel', 'block_rss_client')); $mform->setDefault('config_block_rss_client_show_channel_link', 0); $mform->addElement('selectyesno', 'config_block_rss_client_show_channel_image', get_string('clientshowimagelabel', 'block_rss_client')); $mform->setDefault('config_block_rss_client_show_channel_image', 0); }
protected function specific_definition($mform) { global $CFG, $DB, $USER; // Fields for editing block contents. $mform->addElement('header', 'configheader', get_string('blocksettings', 'block')); $mform->addElement('selectyesno', 'config_display_description', get_string('displaydescriptionlabel', 'block_rss_client')); $mform->setDefault('config_display_description', 0); $mform->addElement('text', 'config_shownumentries', get_string('shownumentrieslabel', 'block_rss_client'), array('size' => 5)); $mform->setType('config_shownumentries', PARAM_INTEGER); $mform->addRule('config_shownumentries', null, 'numeric', null, 'client'); if (!empty($CFG->block_rss_client_num_entries)) { $mform->setDefault('config_shownumentries', $CFG->block_rss_client_num_entries); } else { $mform->setDefault('config_shownumentries', 5); } $rssfeeds = $DB->get_records_sql_menu(' SELECT id, CASE WHEN preferredtitle = ? THEN title ELSE preferredtitle END AS acutaltitle FROM {block_rss_client} WHERE userid = ? OR shared = 1 ORDER BY acutaltitle', array($DB->sql_empty(), $USER->id)); if ($rssfeeds) { $select = $mform->addElement('select', 'config_rssid', get_string('choosefeedlabel', 'block_rss_client'), $rssfeeds); $select->setMultiple(true); } else { $mform->addElement('static', 'config_rssid', get_string('choosefeedlabel', 'block_rss_client'), get_string('nofeeds', 'block_rss_client')); } if (has_any_capability(array('block/rss_client:manageanyfeeds', 'block/rss_client:manageownfeeds'), $this->block->context)) { $mform->addElement('static', 'nofeedmessage', '', '<a href="' . $CFG->wwwroot . '/blocks/rss_client/managefeeds.php?courseid=' . $this->page->course->id . '">' . get_string('feedsaddedit', 'block_rss_client') . '</a>'); } $mform->addElement('text', 'config_title', get_string('uploadlabel')); $mform->setType('config_title', PARAM_NOTAGS); $mform->addElement('selectyesno', 'config_block_rss_client_show_channel_link', get_string('clientshowchannellinklabel', 'block_rss_client')); $mform->setDefault('config_block_rss_client_show_channel_link', 0); $mform->addElement('selectyesno', 'config_block_rss_client_show_channel_image', get_string('clientshowimagelabel', 'block_rss_client')); $mform->setDefault('config_block_rss_client_show_channel_image', 0); }
/** * Returns the list of all editing actions that current user can perform on the module * * @param cm_info $mod The module to produce editing buttons for * @param int $indent The current indenting (default -1 means no move left-right actions) * @param int $sr The section to link back to (used for creating the links) * @return array array of action_link or pix_icon objects */ function course_get_cm_edit_actions_reduced(cm_info $mod, $indent = -1, $sr = null) { global $COURSE, $SITE; static $str; $coursecontext = context_course::instance($mod->course); $modcontext = context_module::instance($mod->id); $editcaps = array('moodle/course:manageactivities', 'moodle/course:activityvisibility', 'moodle/role:assign'); $dupecaps = array('moodle/backup:backuptargetimport', 'moodle/restore:restoretargetimport'); //No permission to edit anything. if (!has_any_capability($editcaps, $modcontext) and !has_all_capabilities($dupecaps, $coursecontext)) { return array(); } $hasmanageactivities = has_capability('moodle/course:manageactivities', $modcontext); if (!isset($str)) { $str = get_strings(array('delete', 'move', 'moveright', 'moveleft', 'editsettings', 'duplicate', 'hide', 'show'), 'moodle'); $str->assign = get_string('assignroles', 'role'); $str->groupsnone = get_string('clicktochangeinbrackets', 'moodle', get_string("groupsnone")); $str->groupsseparate = get_string('clicktochangeinbrackets', 'moodle', get_string("groupsseparate")); $str->groupsvisible = get_string('clicktochangeinbrackets', 'moodle', get_string("groupsvisible")); } $baseurl = new moodle_url('/course/mod.php', array('sesskey' => sesskey())); if ($sr !== null) { $baseurl->param('sr', $sr); } $actions = array(); // Duplicate (require both target import caps to be able to duplicate and backup2 support, see modduplicate.php) // Note that restoring on front page is never allowed. if ($mod->course != SITEID && has_all_capabilities($dupecaps, $coursecontext) && plugin_supports('mod', $mod->modname, FEATURE_BACKUP_MOODLE2)) { $actions['duplicate'] = new action_menu_link_secondary(new moodle_url($baseurl, array('duplicate' => $mod->id)), new pix_icon('t/copy', $str->duplicate, 'moodle', array('class' => 'iconsmall', 'title' => '')), $str->duplicate, array('class' => 'editing_duplicate', 'data-action' => 'duplicate', 'data-sr' => $sr)); } // Delete. if ($hasmanageactivities) { $actions['delete'] = new action_menu_link_secondary(new moodle_url($baseurl, array('delete' => $mod->id)), new pix_icon('t/delete', $str->delete, 'moodle', array('class' => 'iconsmall', 'title' => '')), $str->delete, array('class' => 'editing_delete', 'data-action' => 'delete')); } return $actions; }
/** * Can the current user send a user's competency for review? * * Note that the status 'review' is not meant to be used for student to self-assess * themselves, then to ask the teacher to review their assessment. It is more intended * for a student to provide evidence of prior learning and request their review. * * @param int $userid The user ID the competency belongs to. * @return bool */ public static function can_request_review_user($userid) { global $USER; $capabilities = array('moodle/competency:usercompetencyrequestreview'); if ($USER->id == $userid) { $capabilities[] = 'moodle/competency:usercompetencyrequestreviewown'; } if (has_any_capability($capabilities, context_user::instance($userid))) { return true; } return false; }
/** * Loads category specific settings in the navigation * * @return navigation_node */ protected function load_category_settings() { global $CFG; // We can land here while being in the context of a block, in which case we // should get the parent context which should be the category one. See self::initialise(). if ($this->context->contextlevel == CONTEXT_BLOCK) { $catcontext = $this->context->get_parent_context(); } else { $catcontext = $this->context; } // Let's make sure that we always have the right context when getting here. if ($catcontext->contextlevel != CONTEXT_COURSECAT) { throw new coding_exception('Unexpected context while loading category settings.'); } $categorynode = $this->add($catcontext->get_context_name(), null, null, null, 'categorysettings'); $categorynode->nodetype = navigation_node::NODETYPE_BRANCH; $categorynode->force_open(); if (can_edit_in_category($catcontext->instanceid)) { $url = new moodle_url('/course/management.php', array('categoryid' => $catcontext->instanceid)); $editstring = get_string('managecategorythis'); $categorynode->add($editstring, $url, self::TYPE_SETTING, null, null, new pix_icon('i/edit', '')); } if (has_capability('moodle/category:manage', $catcontext)) { $editurl = new moodle_url('/course/editcategory.php', array('id' => $catcontext->instanceid)); $categorynode->add(get_string('editcategorythis'), $editurl, self::TYPE_SETTING, null, 'edit', new pix_icon('i/edit', '')); $addsubcaturl = new moodle_url('/course/editcategory.php', array('parent' => $catcontext->instanceid)); $categorynode->add(get_string('addsubcategory'), $addsubcaturl, self::TYPE_SETTING, null, 'addsubcat', new pix_icon('i/withsubcat', '')); } // Assign local roles $assignableroles = get_assignable_roles($catcontext); if (!empty($assignableroles)) { $assignurl = new moodle_url('/' . $CFG->admin . '/roles/assign.php', array('contextid' => $catcontext->id)); $categorynode->add(get_string('assignroles', 'role'), $assignurl, self::TYPE_SETTING, null, 'roles', new pix_icon('i/assignroles', '')); } // Override roles if (has_capability('moodle/role:review', $catcontext) or count(get_overridable_roles($catcontext)) > 0) { $url = new moodle_url('/' . $CFG->admin . '/roles/permissions.php', array('contextid' => $catcontext->id)); $categorynode->add(get_string('permissions', 'role'), $url, self::TYPE_SETTING, null, 'permissions', new pix_icon('i/permissions', '')); } // Check role permissions if (has_any_capability(array('moodle/role:assign', 'moodle/role:safeoverride', 'moodle/role:override', 'moodle/role:assign'), $catcontext)) { $url = new moodle_url('/' . $CFG->admin . '/roles/check.php', array('contextid' => $catcontext->id)); $categorynode->add(get_string('checkpermissions', 'role'), $url, self::TYPE_SETTING, null, 'checkpermissions', new pix_icon('i/checkpermissions', '')); } // Cohorts if (has_any_capability(array('moodle/cohort:view', 'moodle/cohort:manage'), $catcontext)) { $categorynode->add(get_string('cohorts', 'cohort'), new moodle_url('/cohort/index.php', array('contextid' => $catcontext->id)), self::TYPE_SETTING, null, 'cohort', new pix_icon('i/cohort', '')); } // Manage filters if (has_capability('moodle/filter:manage', $catcontext) && count(filter_get_available_in_context($catcontext)) > 0) { $url = new moodle_url('/filter/manage.php', array('contextid' => $catcontext->id)); $categorynode->add(get_string('filters', 'admin'), $url, self::TYPE_SETTING, null, 'filters', new pix_icon('i/filter', '')); } // Restore. if (has_capability('moodle/restore:restorecourse', $catcontext)) { $url = new moodle_url('/backup/restorefile.php', array('contextid' => $catcontext->id)); $categorynode->add(get_string('restorecourse', 'admin'), $url, self::TYPE_SETTING, null, 'restorecourse', new pix_icon('i/restore', '')); } // Let plugins hook into category settings navigation. $pluginsfunction = get_plugins_with_function('extend_navigation_category_settings', 'lib.php'); foreach ($pluginsfunction as $plugintype => $plugins) { foreach ($plugins as $pluginfunction) { $pluginfunction($categorynode, $catcontext); } } return $categorynode; }
/** * Get the list of marking_workflow states the current user has permission to transition a grade to. * * @return array of state => description */ public function get_marking_workflow_states_for_current_user() { if (!empty($this->markingworkflowstates)) { return $this->markingworkflowstates; } $states = array(); if (has_capability('mod/assign:grade', $this->context)) { $states[ASSIGN_MARKING_WORKFLOW_STATE_INMARKING] = get_string('markingworkflowstateinmarking', 'assign'); $states[ASSIGN_MARKING_WORKFLOW_STATE_READYFORREVIEW] = get_string('markingworkflowstatereadyforreview', 'assign'); } if (has_any_capability(array('mod/assign:reviewgrades', 'mod/assign:managegrades'), $this->context)) { $states[ASSIGN_MARKING_WORKFLOW_STATE_INREVIEW] = get_string('markingworkflowstateinreview', 'assign'); $states[ASSIGN_MARKING_WORKFLOW_STATE_READYFORRELEASE] = get_string('markingworkflowstatereadyforrelease', 'assign'); } if (has_any_capability(array('mod/assign:releasegrades', 'mod/assign:managegrades'), $this->context)) { $states[ASSIGN_MARKING_WORKFLOW_STATE_RELEASED] = get_string('markingworkflowstatereleased', 'assign'); } $this->markingworkflowstates = $states; return $this->markingworkflowstates; }
/** * Gets a list of roles that this user can override in this context. * * @param context $context the context. * @param int $rolenamedisplay the type of role name to display. One of the * ROLENAME_X constants. Default ROLENAME_ALIAS. * @param bool $withcounts if true, count the number of overrides that are set for each role. * @return array if $withcounts is false, then an array $roleid => $rolename. * if $withusercounts is true, returns a list of three arrays, * $rolenames, $rolecounts, and $nameswithcounts. */ function get_overridable_roles(context $context, $rolenamedisplay = ROLENAME_ALIAS, $withcounts = false) { global $USER, $DB; if (!has_any_capability(array('moodle/role:safeoverride', 'moodle/role:override'), $context)) { if ($withcounts) { return array(array(), array(), array()); } else { return array(); } } $parents = $context->get_parent_context_ids(true); $contexts = implode(',' , $parents); $params = array(); $extrafields = ''; $params['userid'] = $USER->id; if ($withcounts) { $extrafields = ', (SELECT COUNT(rc.id) FROM {role_capabilities} rc WHERE rc.roleid = ro.id AND rc.contextid = :conid) AS overridecount'; $params['conid'] = $context->id; } if ($coursecontext = $context->get_course_context(false)) { $params['coursecontext'] = $coursecontext->id; } else { $params['coursecontext'] = 0; // no course aliases $coursecontext = null; } if (is_siteadmin()) { // show all roles to admins $roles = $DB->get_records_sql(" SELECT ro.id, ro.name, ro.shortname, rn.name AS coursealias $extrafields FROM {role} ro LEFT JOIN {role_names} rn ON (rn.contextid = :coursecontext AND rn.roleid = ro.id) ORDER BY ro.sortorder ASC", $params); } else { $roles = $DB->get_records_sql(" SELECT ro.id, ro.name, ro.shortname, rn.name AS coursealias $extrafields FROM {role} ro JOIN (SELECT DISTINCT r.id FROM {role} r JOIN {role_allow_override} rao ON r.id = rao.allowoverride JOIN {role_assignments} ra ON rao.roleid = ra.roleid WHERE ra.userid = :userid AND ra.contextid IN ($contexts) ) inline_view ON ro.id = inline_view.id LEFT JOIN {role_names} rn ON (rn.contextid = :coursecontext AND rn.roleid = ro.id) ORDER BY ro.sortorder ASC", $params); } $rolenames = role_fix_names($roles, $context, $rolenamedisplay, true); if (!$withcounts) { return $rolenames; } $rolecounts = array(); $nameswithcounts = array(); foreach ($roles as $role) { $nameswithcounts[$role->id] = $rolenames[$role->id] . ' (' . $roles[$role->id]->overridecount . ')'; $rolecounts[$role->id] = $roles[$role->id]->overridecount; } return array($rolenames, $rolecounts, $nameswithcounts); }
$mysemester = semesters::getInstance(); $systemcontext =context_system::instance(); //get the admin layout $PAGE->set_pagelayout('admin'); //check the context level of the user and check weather the user is login to the system or not $PAGE->set_context($systemcontext); require_login(); if ($CFG->forcelogin) { require_login(); } else { user_accesstime_log(); } $capabilities_array = $mysemester->semester_capabilities(); if (!has_any_capability($capabilities_array, $systemcontext)) { print_error('You dont have permissions'); } $PAGE->set_url('/local/semesters/report.php'); $PAGE->set_title(get_string('semesters', 'local_semesters') . ': ' . get_string('report', 'local_semesters')); //Header and the navigation bar $PAGE->set_heading(get_string('semesters', 'local_semesters')); $PAGE->navbar->add(get_string('pluginname', 'local_semesters'), new moodle_url('/local/semesters/index.php')); $PAGE->navbar->add(get_string('report', 'local_semesters')); echo $OUTPUT->header(); //Heading of the page echo $OUTPUT->heading(get_string('pluginname', 'local_semesters')); $currenttab = 'report'; $mysemester->createtabview($currenttab); $hierarchy = new hierarchy(); $schoollist = $hierarchy->get_assignedschools();
/** * Called when viewing course page. * * @param cm_info $coursemodule */ function facetoface_cm_info_view(cm_info $coursemodule) { global $USER, $DB; if (!($facetoface = $DB->get_record('facetoface', array('id' => $coursemodule->instance)))) { return null; } $coursemodule->set_name($facetoface->name); $contextmodule = context_module::instance($coursemodule->id); if (!has_capability('mod/facetoface:view', $contextmodule)) { return null; // Not allowed to view this activity. } $contextcourse = context_course::instance($coursemodule->course); // Can view attendees. $viewattendees = has_capability('mod/facetoface:viewattendees', $contextcourse); // Can see "view all sessions" link even if activity is hidden/currently unavailable. $iseditor = has_any_capability(array('mod/facetoface:viewattendees', 'mod/facetoface:editsessions', 'mod/facetoface:addattendees', 'mod/facetoface:addattendees', 'mod/facetoface:takeattendance'), $contextcourse); $table = html_writer::start_tag('table', array('class' => 'table90 inlinetable')); $timenow = time(); $strviewallsessions = get_string('viewallsessions', 'facetoface'); $sessions_url = new moodle_url('/mod/facetoface/view.php', array('f' => $facetoface->id)); $htmlviewallsessions = html_writer::link($sessions_url, $strviewallsessions, array('class' => 'f2fsessionlinks f2fviewallsessions', 'title' => $strviewallsessions)); if ($submissions = facetoface_get_user_submissions($facetoface->id, $USER->id)) { // User has signedup for the instance. if (!$facetoface->multiplesessions) { // First submission only. $submissions = array(array_shift($submissions)); } foreach ($submissions as $submission) { if ($session = facetoface_get_session($submission->sessionid)) { $allowcancellation = false; if ($session->datetimeknown && facetoface_has_session_started($session, $timenow) && facetoface_is_session_in_progress($session, $timenow)) { $status = get_string('sessioninprogress', 'facetoface'); if ($submission->statuscode == MDL_F2F_STATUS_WAITLISTED) { $allowcancellation = true; } } else if ($session->datetimeknown && facetoface_has_session_started($session, $timenow)) { $status = get_string('sessionover', 'facetoface'); if ($submission->statuscode == MDL_F2F_STATUS_WAITLISTED) { $allowcancellation = true; } } else { $status = get_string('bookingstatus', 'facetoface'); } $sessiondates = ''; if ($session->datetimeknown) { foreach ($session->sessiondates as $date) { if (!empty($sessiondates)) { $sessiondates .= html_writer::empty_tag('br'); } $sessionobj = facetoface_format_session_times($date->timestart, $date->timefinish, $date->sessiontimezone); if ($sessionobj->startdate == $sessionobj->enddate) { $sessiondates .= get_string('sessionstartdateandtime', 'facetoface', $sessionobj); } else { $sessiondates .= get_string('sessionstartfinishdateandtime', 'facetoface', $sessionobj); } } } else { $sessiondates = get_string('wait-listed', 'facetoface'); } $span = html_writer::tag('span', get_string('options', 'facetoface').':', array('class' => 'f2fsessionnotice')); $options = html_writer::tag('tr', html_writer::tag('td', ' ')); // Don't include the link to cancel a session if it has already occurred. $moreinfolink = ''; $cancellink = ''; $strcancelbooking = get_string('cancelbooking', 'facetoface'); $cancel_url = new moodle_url('/mod/facetoface/cancelsignup.php', array('s' => $session->id)); if (!facetoface_has_session_started($session, $timenow)) { $strmoreinfo = get_string('moreinfo', 'facetoface'); $signup_url = new moodle_url('/mod/facetoface/signup.php', array('s' => $session->id)); $moreinfolink = html_writer::tag('tr', html_writer::tag('td', html_writer::link($signup_url, $strmoreinfo, array('class' => 'f2fsessionlinks f2fsessioninfolink', 'title' => $strmoreinfo)))); $cancellink = html_writer::tag('tr', html_writer::tag('td', html_writer::link($cancel_url, $strcancelbooking, array('class' => 'f2fsessionlinks f2fviewallsessions', 'title' => $strcancelbooking)))); $options = html_writer::tag('tr', html_writer::tag('td', $span)); } else { // Session is started. if ($allowcancellation) { $cancellink = html_writer::tag('tr', html_writer::tag('td', html_writer::link($cancel_url, $strcancelbooking, array('class' => 'f2fsessionlinks f2fviewallsessions', 'title' => $strcancelbooking)))); } } // Get room data. $roomtext = ''; $roomdata = $DB->get_record('facetoface_room', array('id' => $session->roomid)); if (!empty($roomdata)) { $roomtext = isset($roomdata->name) ? format_string($roomdata->name) .', '.html_writer::empty_tag('br') : ''; $roomtext .= isset($roomdata->building) ? format_string($roomdata->building).', '.html_writer::empty_tag('br') : ''; $roomtext .= isset($roomdata->address) ? format_string($roomdata->address) .', '.html_writer::empty_tag('br') : ''; } // Don't include the link to view attendees if user is lacking capability. $attendeeslink = ''; if ($viewattendees) { $strseeattendees = get_string('seeattendees', 'facetoface'); $attendees_url = new moodle_url('/mod/facetoface/attendees.php', array('s' => $session->id)); $attendeeslink = html_writer::tag('tr', html_writer::tag('td', html_writer::link($attendees_url, $strseeattendees, array('class' => 'f2fsessionlinks f2fviewattendees', 'title' => $strseeattendees)))); $options = html_writer::tag('tr', html_writer::tag('td', $span)); } $table .= html_writer::start_tag('tr') .html_writer::tag('td', $status, array('class' => 'f2fsessionnotice', 'colspan' => '2')) .html_writer::end_tag('tr') .html_writer::start_tag('tr', array('class' => 'f2fsessioninfo')) .html_writer::tag('td', $roomtext . $sessiondates . html_writer::empty_tag('br'), array('class' => 'f2fwidth')) .html_writer::tag('td', html_writer::start_tag('table')) .$options .$moreinfolink .$attendeeslink .$cancellink .html_writer::end_tag('table') .html_writer::end_tag('td') .html_writer::end_tag('tr'); } } // Add closing "view all sessions" row to table. $table .= html_writer::start_tag('tr') .html_writer::tag('td', $htmlviewallsessions, array('colspan' => '2')) .html_writer::end_tag('tr') .html_writer::end_tag('table'); } else if ($sessions = facetoface_get_sessions($facetoface->id)) { if ($facetoface->display > 0) { $j=1; $sessionsinprogress = array(); $futuresessions = array(); foreach ($sessions as $session) { if (!facetoface_session_has_capacity($session, $contextmodule, MDL_F2F_STATUS_WAITLISTED) && !$session->allowoverbook) { continue; } if ($session->datetimeknown && facetoface_has_session_started($session, $timenow) && !facetoface_is_session_in_progress($session, $timenow)) { // Finished session, don't display. continue; } else { $signup = get_string('signup', 'facetoface'); $signup_url = new moodle_url('/mod/facetoface/signup.php', array('s' => $session->id)); $moreinfolink = html_writer::tag('tr', html_writer::tag('td', html_writer::link($signup_url, $signup, array('class' => 'f2fsessionlinks f2fsessioninfolink', 'title' => $signup)))); $span = html_writer::tag('span', get_string('options', 'facetoface').':', array('class' => 'f2fsessionnotice')); $options = html_writer::tag('tr', html_writer::tag('td', $span)); } $multidate = ''; $sessiondate = ''; $sessiontime = ''; if ($session->datetimeknown) { if (empty($session->sessiondates)) { $sessiondate = get_string('unknowndate', 'facetoface'); $sessiontime = get_string('unknowntime', 'facetoface'); } else { $sessionobj = facetoface_format_session_times($session->sessiondates[0]->timestart, $session->sessiondates[0]->timefinish, $session->sessiondates[0]->sessiontimezone); if ($sessionobj->startdate == $sessionobj->enddate) { $sessiondate = get_string('sessionstartdateandtime', 'facetoface', $sessionobj); } else { $sessiondate .= get_string('sessionstartfinishdateandtime', 'facetoface', $sessionobj); } if (count($session->sessiondates) > 1) { $multidate = html_writer::start_tag('br') . get_string('multidate', 'facetoface'); } } } else { $sessiondate = get_string('wait-listed', 'facetoface'); } $locationstring = ''; $roomdata = $DB->get_record('facetoface_room', array('id' => $session->roomid)); if (!empty($roomdata)) { $locationstring = isset($roomdata->name) ? format_string($roomdata->name) .', '.html_writer::empty_tag('br') : ''; $locationstring .= isset($roomdata->building) ? format_string($roomdata->building).', '.html_writer::empty_tag('br') : ''; $locationstring .= isset($roomdata->address) ? format_string($roomdata->address) .', '.html_writer::empty_tag('br') : ''; } $sessionobject = new stdClass(); $sessionobject->location = $locationstring; $sessionobject->date = $sessiondate; $sessionobject->multidate = $multidate; if ($session->datetimeknown && (facetoface_has_session_started($session, $timenow)) && facetoface_is_session_in_progress($session, $timenow)) { $sessionsinprogress[] = $sessionobject; } else { $sessionobject->options = $options; $sessionobject->moreinfolink = $moreinfolink; $futuresessions[] = $sessionobject; } $j++; if ($j > $facetoface->display) { break; } } if (!empty($sessionsinprogress)) { $table .= html_writer::start_tag('tr') . html_writer::tag('td', get_string('sessioninprogress', 'facetoface'), array('class' => 'f2fsessionnotice', 'colspan' => '2')) . html_writer::end_tag('tr'); foreach ($sessionsinprogress as $session) { $table .= html_writer::start_tag('tr') .html_writer::tag('td', html_writer::tag('span', $session->location.$session->date.$session->multidate, array('class' => 'f2fsessiontime')), array('class' => 'f2fwidth')) .html_writer::tag('td', html_writer::start_tag('table')) .html_writer::tag('tr', html_writer::tag('td', ' ')) .html_writer::end_tag('table') .html_writer::end_tag('td') .html_writer::end_tag('tr'); } } if (!empty($futuresessions)) { $table .= html_writer::start_tag('tr') . html_writer::tag('td', get_string('signupforsession', 'facetoface'), array('class' => 'f2fsessionnotice', 'colspan' => '2')) . html_writer::end_tag('tr'); foreach ($futuresessions as $session) { $table .= html_writer::start_tag('tr') .html_writer::tag('td', html_writer::tag('span', $session->location.$session->date.$session->multidate, array('class' => 'f2fsessiontime')), array('class' => 'f2fwidth')) .html_writer::tag('td', html_writer::start_tag('table')) .$session->options .$session->moreinfolink .html_writer::end_tag('table') .html_writer::end_tag('td') .html_writer::end_tag('tr'); } } $table .= html_writer::start_tag('tr') .html_writer::tag('td', ($iseditor || ($coursemodule->visible && $coursemodule->available)) ? $htmlviewallsessions : $strviewallsessions, array('colspan' => '2')) .html_writer::end_tag('tr') .html_writer::end_tag('table'); } else { // Show only name if session display is set to zero. $content = html_writer::tag('span', $htmlviewallsessions, array('class' => 'f2fsessionnotice f2factivityname f2fonepointfive')); $coursemodule->set_content($content); return; } } else if (has_capability('mod/facetoface:viewemptyactivities', $contextmodule)) { $content = html_writer::tag('span', $htmlviewallsessions, array('class' => 'f2fsessionnotice f2factivityname f2fonepointfive')); $coursemodule->set_content($content); return; } else { // Nothing to display to this user. $coursemodule->set_content(''); return; } $coursemodule->set_content($table); }
/** * @return boolean does the user have permission to see this page in editing mode. */ public function user_allowed_editing() { if ($this->_legacypageobject) { return $this->_legacypageobject->user_allowed_editing(); } return has_any_capability($this->all_editing_caps(), $this->_context); }
/** * Does the user have permission to see this page in editing mode. * @return bool */ public function user_allowed_editing() { return has_any_capability($this->all_editing_caps(), $this->_context); }
/** * Gets a list of roles that this user can override in this context. * * @param context $context the context. * @param int $rolenamedisplay the type of role name to display. One of the * ROLENAME_X constants. Default ROLENAME_ALIAS. * @param bool $withcounts if true, count the number of overrides that are set for each role. * @return array if $withcounts is false, then an array $roleid => $rolename. * if $withusercounts is true, returns a list of three arrays, * $rolenames, $rolecounts, and $nameswithcounts. */ function get_overridable_roles(context $context, $rolenamedisplay = ROLENAME_ALIAS, $withcounts = false) { global $USER, $DB; if (!has_any_capability(array('moodle/role:safeoverride', 'moodle/role:override'), $context)) { if ($withcounts) { return array(array(), array(), array()); } else { return array(); } } $parents = $context->get_parent_context_ids(true); $contexts = implode(',', $parents); $params = array(); $extrafields = ''; if ($rolenamedisplay == ROLENAME_ORIGINALANDSHORT) { $extrafields .= ', ro.shortname'; } $params['userid'] = $USER->id; if ($withcounts) { $extrafields = ', (SELECT COUNT(rc.id) FROM {role_capabilities} rc WHERE rc.roleid = ro.id AND rc.contextid = :conid) AS overridecount'; $params['conid'] = $context->id; } if (is_siteadmin()) { // show all roles to admins $roles = $DB->get_records_sql("\n SELECT ro.id, ro.name{$extrafields}\n FROM {role} ro\n ORDER BY ro.sortorder ASC", $params); } else { $roles = $DB->get_records_sql("\n SELECT ro.id, ro.name{$extrafields}\n FROM {role} ro\n JOIN (SELECT DISTINCT r.id\n FROM {role} r\n JOIN {role_allow_override} rao ON r.id = rao.allowoverride\n JOIN {role_assignments} ra ON rao.roleid = ra.roleid\n WHERE ra.userid = :userid AND ra.contextid IN ({$contexts})\n ) inline_view ON ro.id = inline_view.id\n ORDER BY ro.sortorder ASC", $params); } $rolenames = array(); foreach ($roles as $role) { $rolenames[$role->id] = $role->name; if ($rolenamedisplay == ROLENAME_ORIGINALANDSHORT) { $rolenames[$role->id] .= ' (' . $role->shortname . ')'; } } if ($rolenamedisplay != ROLENAME_ORIGINALANDSHORT) { $rolenames = role_fix_names($rolenames, $context, $rolenamedisplay); } if (!$withcounts) { return $rolenames; } $rolecounts = array(); $nameswithcounts = array(); foreach ($roles as $role) { $nameswithcounts[$role->id] = $rolenames[$role->id] . ' (' . $roles[$role->id]->overridecount . ')'; $rolecounts[$role->id] = $roles[$role->id]->overridecount; } return array($rolenames, $rolecounts, $nameswithcounts); }
/** * Prepares data object with all workshop grades to be rendered * * @param int $userid the user we are preparing the report for * @param mixed $groups single group or array of groups - only show users who are in one of these group(s). Defaults to all * @param int $page the current page (for the pagination) * @param int $perpage participants per page (for the pagination) * @param string $sortby lastname|firstname|submissiontitle|submissiongrade|gradinggrade * @param string $sorthow ASC|DESC * @return stdclass data for the renderer */ public function prepare_grading_report_data($userid, $groups, $page, $perpage, $sortby, $sorthow) { global $DB; $canviewall = has_capability('mod/workshop:viewallassessments', $this->context, $userid); $isparticipant = has_any_capability(array('mod/workshop:submit', 'mod/workshop:peerassess'), $this->context, $userid); if (!$canviewall and !$isparticipant) { // who the hell is this? return array(); } if (!in_array($sortby, array('lastname','firstname','submissiontitle','submissiongrade','gradinggrade'))) { $sortby = 'lastname'; } if (!($sorthow === 'ASC' or $sorthow === 'DESC')) { $sorthow = 'ASC'; } // get the list of user ids to be displayed if ($canviewall) { // fetch the list of ids of all workshop participants - this may get really long so fetch just id $participants = get_users_by_capability($this->context, array('mod/workshop:submit', 'mod/workshop:peerassess'), 'u.id', '', '', '', $groups, '', false, false, true); } else { // this is an ordinary workshop participant (aka student) - display the report just for him/her $participants = array($userid => (object)array('id' => $userid)); } // we will need to know the number of all records later for the pagination purposes $numofparticipants = count($participants); if ($numofparticipants > 0) { // load all fields which can be used for sorting and paginate the records list($participantids, $params) = $DB->get_in_or_equal(array_keys($participants), SQL_PARAMS_NAMED); $params['workshopid1'] = $this->id; $params['workshopid2'] = $this->id; $sqlsort = $sortby . ' ' . $sorthow . ',u.lastname,u.firstname,u.id'; $sql = "SELECT u.id AS userid,u.firstname,u.lastname,u.picture,u.imagealt,u.email, s.title AS submissiontitle, s.grade AS submissiongrade, ag.gradinggrade FROM {user} u LEFT JOIN {workshop_submissions} s ON (s.authorid = u.id AND s.workshopid = :workshopid1 AND s.example = 0) LEFT JOIN {workshop_aggregations} ag ON (ag.userid = u.id AND ag.workshopid = :workshopid2) WHERE u.id $participantids ORDER BY $sqlsort"; $participants = $DB->get_records_sql($sql, $params, $page * $perpage, $perpage); } else { $participants = array(); } // this will hold the information needed to display user names and pictures $userinfo = array(); // get the user details for all participants to display foreach ($participants as $participant) { if (!isset($userinfo[$participant->userid])) { $userinfo[$participant->userid] = new stdclass(); $userinfo[$participant->userid]->id = $participant->userid; $userinfo[$participant->userid]->firstname = $participant->firstname; $userinfo[$participant->userid]->lastname = $participant->lastname; $userinfo[$participant->userid]->picture = $participant->picture; $userinfo[$participant->userid]->imagealt = $participant->imagealt; $userinfo[$participant->userid]->email = $participant->email; } } // load the submissions details $submissions = $this->get_submissions(array_keys($participants)); // get the user details for all moderators (teachers) that have overridden a submission grade foreach ($submissions as $submission) { if (!isset($userinfo[$submission->gradeoverby])) { $userinfo[$submission->gradeoverby] = new stdclass(); $userinfo[$submission->gradeoverby]->id = $submission->gradeoverby; $userinfo[$submission->gradeoverby]->firstname = $submission->overfirstname; $userinfo[$submission->gradeoverby]->lastname = $submission->overlastname; $userinfo[$submission->gradeoverby]->picture = $submission->overpicture; $userinfo[$submission->gradeoverby]->imagealt = $submission->overimagealt; $userinfo[$submission->gradeoverby]->email = $submission->overemail; } } // get the user details for all reviewers of the displayed participants $reviewers = array(); if ($submissions) { list($submissionids, $params) = $DB->get_in_or_equal(array_keys($submissions), SQL_PARAMS_NAMED); $sql = "SELECT a.id AS assessmentid, a.submissionid, a.grade, a.gradinggrade, a.gradinggradeover, a.weight, r.id AS reviewerid, r.lastname, r.firstname, r.picture, r.imagealt, r.email, s.id AS submissionid, s.authorid FROM {workshop_assessments} a JOIN {user} r ON (a.reviewerid = r.id) JOIN {workshop_submissions} s ON (a.submissionid = s.id AND s.example = 0) WHERE a.submissionid $submissionids ORDER BY a.weight DESC, r.lastname, r.firstname"; $reviewers = $DB->get_records_sql($sql, $params); foreach ($reviewers as $reviewer) { if (!isset($userinfo[$reviewer->reviewerid])) { $userinfo[$reviewer->reviewerid] = new stdclass(); $userinfo[$reviewer->reviewerid]->id = $reviewer->reviewerid; $userinfo[$reviewer->reviewerid]->firstname = $reviewer->firstname; $userinfo[$reviewer->reviewerid]->lastname = $reviewer->lastname; $userinfo[$reviewer->reviewerid]->picture = $reviewer->picture; $userinfo[$reviewer->reviewerid]->imagealt = $reviewer->imagealt; $userinfo[$reviewer->reviewerid]->email = $reviewer->email; } } } // get the user details for all reviewees of the displayed participants $reviewees = array(); if ($participants) { list($participantids, $params) = $DB->get_in_or_equal(array_keys($participants), SQL_PARAMS_NAMED); $params['workshopid'] = $this->id; $sql = "SELECT a.id AS assessmentid, a.submissionid, a.grade, a.gradinggrade, a.gradinggradeover, a.reviewerid, a.weight, s.id AS submissionid, e.id AS authorid, e.lastname, e.firstname, e.picture, e.imagealt, e.email FROM {user} u JOIN {workshop_assessments} a ON (a.reviewerid = u.id) JOIN {workshop_submissions} s ON (a.submissionid = s.id AND s.example = 0) JOIN {user} e ON (s.authorid = e.id) WHERE u.id $participantids AND s.workshopid = :workshopid ORDER BY a.weight DESC, e.lastname, e.firstname"; $reviewees = $DB->get_records_sql($sql, $params); foreach ($reviewees as $reviewee) { if (!isset($userinfo[$reviewee->authorid])) { $userinfo[$reviewee->authorid] = new stdclass(); $userinfo[$reviewee->authorid]->id = $reviewee->authorid; $userinfo[$reviewee->authorid]->firstname = $reviewee->firstname; $userinfo[$reviewee->authorid]->lastname = $reviewee->lastname; $userinfo[$reviewee->authorid]->picture = $reviewee->picture; $userinfo[$reviewee->authorid]->imagealt = $reviewee->imagealt; $userinfo[$reviewee->authorid]->email = $reviewee->email; } } } // finally populate the object to be rendered $grades = $participants; foreach ($participants as $participant) { // set up default (null) values $grades[$participant->userid]->submissionid = null; $grades[$participant->userid]->submissiontitle = null; $grades[$participant->userid]->submissiongrade = null; $grades[$participant->userid]->submissiongradeover = null; $grades[$participant->userid]->submissiongradeoverby = null; $grades[$participant->userid]->submissionpublished = null; $grades[$participant->userid]->reviewedby = array(); $grades[$participant->userid]->reviewerof = array(); } unset($participants); unset($participant); foreach ($submissions as $submission) { $grades[$submission->authorid]->submissionid = $submission->id; $grades[$submission->authorid]->submissiontitle = $submission->title; $grades[$submission->authorid]->submissiongrade = $this->real_grade($submission->grade); $grades[$submission->authorid]->submissiongradeover = $this->real_grade($submission->gradeover); $grades[$submission->authorid]->submissiongradeoverby = $submission->gradeoverby; $grades[$submission->authorid]->submissionpublished = $submission->published; } unset($submissions); unset($submission); foreach($reviewers as $reviewer) { $info = new stdclass(); $info->userid = $reviewer->reviewerid; $info->assessmentid = $reviewer->assessmentid; $info->submissionid = $reviewer->submissionid; $info->grade = $this->real_grade($reviewer->grade); $info->gradinggrade = $this->real_grading_grade($reviewer->gradinggrade); $info->gradinggradeover = $this->real_grading_grade($reviewer->gradinggradeover); $info->weight = $reviewer->weight; $grades[$reviewer->authorid]->reviewedby[$reviewer->reviewerid] = $info; } unset($reviewers); unset($reviewer); foreach($reviewees as $reviewee) { $info = new stdclass(); $info->userid = $reviewee->authorid; $info->assessmentid = $reviewee->assessmentid; $info->submissionid = $reviewee->submissionid; $info->grade = $this->real_grade($reviewee->grade); $info->gradinggrade = $this->real_grading_grade($reviewee->gradinggrade); $info->gradinggradeover = $this->real_grading_grade($reviewee->gradinggradeover); $info->weight = $reviewee->weight; $grades[$reviewee->reviewerid]->reviewerof[$reviewee->authorid] = $info; } unset($reviewees); unset($reviewee); foreach ($grades as $grade) { $grade->gradinggrade = $this->real_grading_grade($grade->gradinggrade); } $data = new stdclass(); $data->grades = $grades; $data->userinfo = $userinfo; $data->totalcount = $numofparticipants; $data->maxgrade = $this->real_grade(100); $data->maxgradinggrade = $this->real_grading_grade(100); return $data; }
$headings = array(get_string('name'), get_string('quizcloses', 'quiz')); $align = array('left', 'left'); if ($course->format == 'weeks' or $course->format == 'weekscss') { array_unshift($headings, get_string('week')); } else { array_unshift($headings, get_string('section')); } array_unshift($align, 'center'); $showing = ''; // default if (has_capability('mod/quiz:viewreports', $coursecontext)) { array_push($headings, get_string('attempts', 'quiz')); array_push($align, 'left'); $showing = 'stats'; } else { if (has_any_capability(array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'), $coursecontext)) { array_push($headings, get_string('bestgrade', 'quiz'), get_string('feedback', 'quiz')); array_push($align, 'left', 'left'); $showing = 'scores'; // default } } $table->head = $headings; $table->align = $align; /// Populate the table with the list of instances. $currentsection = ''; foreach ($quizzes as $quiz) { $cm = get_coursemodule_from_instance('quiz', $quiz->id); $context = get_context_instance(CONTEXT_MODULE, $cm->id); $data = array(); // Section number if necessary.
/** * Returns true if the current user can review cohorts for this category. * @return bool */ public function can_review_cohorts() { return has_any_capability(array('moodle/cohort:view', 'moodle/cohort:manage'), $this->get_context()); }
/** * Returns the courses to load events for, the * * @param array $courseeventsfrom An array of courses to load calendar events for * @param bool $ignorefilters specify the use of filters, false is set as default * @return array An array of courses, groups, and user to load calendar events for based upon filters */ function calendar_set_filters(array $courseeventsfrom, $ignorefilters = false) { global $USER, $CFG, $DB; // For backwards compatability we have to check whether the courses array contains // just id's in which case we need to load course objects. $coursestoload = array(); foreach ($courseeventsfrom as $id => $something) { if (!is_object($something)) { $coursestoload[] = $id; unset($courseeventsfrom[$id]); } } if (!empty($coursestoload)) { // TODO remove this in 2.2 debugging('calendar_set_filters now preferes an array of course objects with preloaded contexts', DEBUG_DEVELOPER); $courseeventsfrom = array_merge($courseeventsfrom, $DB->get_records_list('course', 'id', $coursestoload)); } $courses = array(); $user = false; $group = false; // capabilities that allow seeing group events from all groups // TODO: rewrite so that moodle/calendar:manageentries is not necessary here $allgroupscaps = array('moodle/site:accessallgroups', 'moodle/calendar:manageentries'); $isloggedin = isloggedin(); if ($ignorefilters || calendar_show_event_type(CALENDAR_EVENT_COURSE)) { $courses = array_keys($courseeventsfrom); } if ($ignorefilters || calendar_show_event_type(CALENDAR_EVENT_GLOBAL)) { $courses[] = SITEID; } $courses = array_unique($courses); sort($courses); if (!empty($courses) && in_array(SITEID, $courses)) { // Sort courses for consistent colour highlighting // Effectively ignoring SITEID as setting as last course id $key = array_search(SITEID, $courses); unset($courses[$key]); $courses[] = SITEID; } if ($ignorefilters || $isloggedin && calendar_show_event_type(CALENDAR_EVENT_USER)) { $user = $USER->id; } if (!empty($courseeventsfrom) && (calendar_show_event_type(CALENDAR_EVENT_GROUP) || $ignorefilters)) { if (count($courseeventsfrom) == 1) { $course = reset($courseeventsfrom); if (has_any_capability($allgroupscaps, context_course::instance($course->id))) { $coursegroups = groups_get_all_groups($course->id, 0, 0, 'g.id'); $group = array_keys($coursegroups); } } if ($group === false) { if (!empty($CFG->calendar_adminseesall) && has_any_capability($allgroupscaps, context_system::instance())) { $group = true; } else { if ($isloggedin) { $groupids = array(); // We already have the courses to examine in $courses // For each course... foreach ($courseeventsfrom as $courseid => $course) { // If the user is an editing teacher in there, if (!empty($USER->groupmember[$course->id])) { // We've already cached the users groups for this course so we can just use that $groupids = array_merge($groupids, $USER->groupmember[$course->id]); } else { if ($course->groupmode != NOGROUPS || !$course->groupmodeforce) { // If this course has groups, show events from all of those related to the current user $coursegroups = groups_get_user_groups($course->id, $USER->id); $groupids = array_merge($groupids, $coursegroups['0']); } } } if (!empty($groupids)) { $group = $groupids; } } } } } if (empty($courses)) { $courses = false; } return array($courses, $group, $user); }
/** * Returns the list of all editing actions that current user can perform on the module * * @param cm_info $mod The module to produce editing buttons for * @param int $indent The current indenting (default -1 means no move left-right actions) * @param int $sr The section to link back to (used for creating the links) * @return array array of action_link or pix_icon objects */ function course_get_cm_edit_actions(cm_info $mod, $indent = -1, $sr = null) { global $COURSE, $SITE; static $str; $coursecontext = context_course::instance($mod->course); $modcontext = context_module::instance($mod->id); $editcaps = array('moodle/course:manageactivities', 'moodle/course:activityvisibility', 'moodle/role:assign'); $dupecaps = array('moodle/backup:backuptargetimport', 'moodle/restore:restoretargetimport'); // No permission to edit anything. if (!has_any_capability($editcaps, $modcontext) and !has_all_capabilities($dupecaps, $coursecontext)) { return array(); } $hasmanageactivities = has_capability('moodle/course:manageactivities', $modcontext); if (!isset($str)) { $str = get_strings(array('delete', 'move', 'moveright', 'moveleft', 'editsettings', 'duplicate', 'hide', 'show'), 'moodle'); $str->assign = get_string('assignroles', 'role'); $str->groupsnone = get_string('clicktochangeinbrackets', 'moodle', get_string("groupsnone")); $str->groupsseparate = get_string('clicktochangeinbrackets', 'moodle', get_string("groupsseparate")); $str->groupsvisible = get_string('clicktochangeinbrackets', 'moodle', get_string("groupsvisible")); } $baseurl = new moodle_url('/course/mod.php', array('sesskey' => sesskey())); if ($sr !== null) { $baseurl->param('sr', $sr); } $actions = array(); // Update. if ($hasmanageactivities) { $actions['update'] = new action_menu_link_secondary(new moodle_url($baseurl, array('update' => $mod->id)), new pix_icon('t/edit', $str->editsettings, 'moodle', array('class' => 'iconsmall', 'title' => '')), $str->editsettings, array('class' => 'editing_update', 'data-action' => 'update')); } // Indent. if ($hasmanageactivities && $indent >= 0) { $indentlimits = new stdClass(); $indentlimits->min = 0; $indentlimits->max = 16; if (right_to_left()) { // Exchange arrows on RTL $rightarrow = 't/left'; $leftarrow = 't/right'; } else { $rightarrow = 't/right'; $leftarrow = 't/left'; } if ($indent >= $indentlimits->max) { $enabledclass = 'hidden'; } else { $enabledclass = ''; } $actions['moveright'] = new action_menu_link_secondary(new moodle_url($baseurl, array('id' => $mod->id, 'indent' => '1')), new pix_icon($rightarrow, $str->moveright, 'moodle', array('class' => 'iconsmall', 'title' => '')), $str->moveright, array('class' => 'editing_moveright ' . $enabledclass, 'data-action' => 'moveright', 'data-keepopen' => true)); if ($indent <= $indentlimits->min) { $enabledclass = 'hidden'; } else { $enabledclass = ''; } $actions['moveleft'] = new action_menu_link_secondary(new moodle_url($baseurl, array('id' => $mod->id, 'indent' => '-1')), new pix_icon($leftarrow, $str->moveleft, 'moodle', array('class' => 'iconsmall', 'title' => '')), $str->moveleft, array('class' => 'editing_moveleft ' . $enabledclass, 'data-action' => 'moveleft', 'data-keepopen' => true)); } // Hide/Show. if (has_capability('moodle/course:activityvisibility', $modcontext)) { if ($mod->visible) { $actions['hide'] = new action_menu_link_secondary(new moodle_url($baseurl, array('hide' => $mod->id)), new pix_icon('t/hide', $str->hide, 'moodle', array('class' => 'iconsmall', 'title' => '')), $str->hide, array('class' => 'editing_hide', 'data-action' => 'hide')); } else { $actions['show'] = new action_menu_link_secondary(new moodle_url($baseurl, array('show' => $mod->id)), new pix_icon('t/show', $str->show, 'moodle', array('class' => 'iconsmall', 'title' => '')), $str->show, array('class' => 'editing_show', 'data-action' => 'show')); } } // Duplicate (require both target import caps to be able to duplicate and backup2 support, see modduplicate.php) // Note that restoring on front page is never allowed. if ($mod->course != SITEID && has_all_capabilities($dupecaps, $coursecontext) && plugin_supports('mod', $mod->modname, FEATURE_BACKUP_MOODLE2)) { $actions['duplicate'] = new action_menu_link_secondary(new moodle_url($baseurl, array('duplicate' => $mod->id)), new pix_icon('t/copy', $str->duplicate, 'moodle', array('class' => 'iconsmall', 'title' => '')), $str->duplicate, array('class' => 'editing_duplicate', 'data-action' => 'duplicate', 'data-sr' => $sr)); } // Groupmode. if ($hasmanageactivities && !$mod->coursegroupmodeforce) { if (plugin_supports('mod', $mod->modname, FEATURE_GROUPS, 0)) { if ($mod->effectivegroupmode == SEPARATEGROUPS) { $nextgroupmode = VISIBLEGROUPS; $grouptitle = $str->groupsseparate; $actionname = 'groupsseparate'; $groupimage = 'i/groups'; } else { if ($mod->effectivegroupmode == VISIBLEGROUPS) { $nextgroupmode = NOGROUPS; $grouptitle = $str->groupsvisible; $actionname = 'groupsvisible'; $groupimage = 'i/groupv'; } else { $nextgroupmode = SEPARATEGROUPS; $grouptitle = $str->groupsnone; $actionname = 'groupsnone'; $groupimage = 'i/groupn'; } } $actions[$actionname] = new action_menu_link_primary(new moodle_url($baseurl, array('id' => $mod->id, 'groupmode' => $nextgroupmode)), new pix_icon($groupimage, null, 'moodle', array('class' => 'iconsmall')), $grouptitle, array('class' => 'editing_' . $actionname, 'data-action' => $actionname, 'data-nextgroupmode' => $nextgroupmode, 'aria-live' => 'assertive')); } else { $actions['nogroupsupport'] = new action_menu_filler(); } } // Assign. if (has_capability('moodle/role:assign', $modcontext)) { $actions['assign'] = new action_menu_link_secondary(new moodle_url('/admin/roles/assign.php', array('contextid' => $modcontext->id)), new pix_icon('t/assignroles', $str->assign, 'moodle', array('class' => 'iconsmall', 'title' => '')), $str->assign, array('class' => 'editing_assign', 'data-action' => 'assignroles')); } // Delete. if ($hasmanageactivities) { $actions['delete'] = new action_menu_link_secondary(new moodle_url($baseurl, array('delete' => $mod->id)), new pix_icon('t/delete', $str->delete, 'moodle', array('class' => 'iconsmall', 'title' => '')), $str->delete, array('class' => 'editing_delete', 'data-action' => 'delete')); } return $actions; }
/** * This function loads all of the front page settings into the settings navigation. * This function is called when the user is on the front page, or $COURSE==$SITE * @return navigation_node */ protected function load_front_page_settings($forceopen = false) { global $SITE, $CFG; $course = clone $SITE; $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); // Course context $frontpage = $this->add(get_string('frontpagesettings'), null, self::TYPE_SETTING, null, 'frontpage'); if ($forceopen) { $frontpage->force_open(); } $frontpage->id = 'frontpagesettings'; if (has_capability('moodle/course:update', $coursecontext)) { // Add the turn on/off settings $url = new moodle_url('/course/view.php', array('id' => $course->id, 'sesskey' => sesskey())); if ($this->page->user_is_editing()) { $url->param('edit', 'off'); $editstring = get_string('turneditingoff'); } else { $url->param('edit', 'on'); $editstring = get_string('turneditingon'); } $frontpage->add($editstring, $url, self::TYPE_SETTING, null, null, new pix_icon('i/edit', '')); // Add the course settings link $url = new moodle_url('/admin/settings.php', array('section' => 'frontpagesettings')); $frontpage->add(get_string('editsettings'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/settings', '')); } // add enrol nodes enrol_add_course_navigation($frontpage, $course); // Manage filters if (has_capability('moodle/filter:manage', $coursecontext) && count(filter_get_available_in_context($coursecontext)) > 0) { $url = new moodle_url('/filter/manage.php', array('contextid' => $coursecontext->id)); $frontpage->add(get_string('filters', 'admin'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/filter', '')); } // Backup this course if (has_capability('moodle/backup:backupcourse', $coursecontext)) { $url = new moodle_url('/backup/backup.php', array('id' => $course->id)); $frontpage->add(get_string('backup'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/backup', '')); } // Restore to this course if (has_capability('moodle/restore:restorecourse', $coursecontext)) { $url = new moodle_url('/backup/restorefile.php', array('contextid' => $coursecontext->id)); $frontpage->add(get_string('restore'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/restore', '')); } // Manage questions $questioncaps = array('moodle/question:add', 'moodle/question:editmine', 'moodle/question:editall', 'moodle/question:viewmine', 'moodle/question:viewall', 'moodle/question:movemine', 'moodle/question:moveall'); if (has_any_capability($questioncaps, $this->context)) { $questionlink = $CFG->wwwroot . '/question/edit.php'; } else { if (has_capability('moodle/question:managecategory', $this->context)) { $questionlink = $CFG->wwwroot . '/question/category.php'; } } if (isset($questionlink)) { $url = new moodle_url($questionlink, array('courseid' => $course->id)); $frontpage->add(get_string('questions', 'quiz'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/questions', '')); } // Manage files if ($course->legacyfiles == 2 and has_capability('moodle/course:managefiles', $this->context)) { //hiden in new installs $url = new moodle_url('/files/index.php', array('contextid' => $coursecontext->id, 'itemid' => 0, 'component' => 'course', 'filearea' => 'legacy')); $frontpage->add(get_string('sitelegacyfiles'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/files', '')); } return $frontpage; }
$PAGE->set_url($returnurl); if ($type == BADGE_TYPE_SITE) { $title = get_string('sitebadges', 'badges'); $PAGE->set_context(context_system::instance()); $PAGE->set_pagelayout('admin'); $PAGE->set_heading($title . ': ' . $hdr); navigation_node::override_active_url(new moodle_url('/badges/index.php', array('type' => BADGE_TYPE_SITE))); } else { require_login($course); $title = get_string('coursebadges', 'badges'); $PAGE->set_context(context_course::instance($course->id)); $PAGE->set_pagelayout('course'); $PAGE->set_heading($course->fullname . ': ' . $hdr); navigation_node::override_active_url(new moodle_url('/badges/index.php', array('type' => BADGE_TYPE_COURSE, 'id' => $course->id))); } if (!has_any_capability(array('moodle/badges:viewawarded', 'moodle/badges:createbadge', 'moodle/badges:awardbadge', 'moodle/badges:configuremessages', 'moodle/badges:configuredetails', 'moodle/badges:deletebadge'), $PAGE->context)) { redirect($CFG->wwwroot); } $PAGE->set_title($hdr); $PAGE->requires->js('/badges/backpack.js'); $PAGE->requires->js_init_call('check_site_access', null, false); $output = $PAGE->get_renderer('core', 'badges'); if ($delete && has_capability('moodle/badges:deletebadge', $PAGE->context)) { $badge = new badge($delete); if (!$confirm) { echo $output->header(); echo $output->confirm(get_string('delconfirm', 'badges', $badge->name), new moodle_url($PAGE->url, array('delete' => $badge->id, 'confirm' => 1)), $returnurl); echo $output->footer(); die; } else { require_sesskey();
/** * Loads category specific settings in the navigation * * @return navigation_node */ protected function load_category_settings() { global $CFG; $categorynode = $this->add(print_context_name($this->context), null, null, null, 'categorysettings'); $categorynode->force_open(); if (has_any_capability(array('moodle/category:manage', 'moodle/course:create'), $this->context)) { $url = new moodle_url('/course/category.php', array('id' => $this->context->instanceid, 'sesskey' => sesskey())); if ($this->page->user_is_editing()) { $url->param('categoryedit', '0'); $editstring = get_string('turneditingoff'); } else { $url->param('categoryedit', '1'); $editstring = get_string('turneditingon'); } $categorynode->add($editstring, $url, self::TYPE_SETTING, null, null, new pix_icon('i/edit', '')); } if ($this->page->user_is_editing() && has_capability('moodle/category:manage', $this->context)) { $editurl = new moodle_url('/course/editcategory.php', array('id' => $this->context->instanceid)); $categorynode->add(get_string('editcategorythis'), $editurl, self::TYPE_SETTING, null, 'edit', new pix_icon('i/edit', '')); $addsubcaturl = new moodle_url('/course/editcategory.php', array('parent' => $this->context->instanceid)); $categorynode->add(get_string('addsubcategory'), $addsubcaturl, self::TYPE_SETTING, null, 'addsubcat', new pix_icon('i/withsubcat', '')); } // Assign local roles if (has_capability('moodle/role:assign', $this->context)) { $assignurl = new moodle_url('/' . $CFG->admin . '/roles/assign.php', array('contextid' => $this->context->id)); $categorynode->add(get_string('assignroles', 'role'), $assignurl, self::TYPE_SETTING, null, 'roles', new pix_icon('i/roles', '')); } // Override roles if (has_capability('moodle/role:review', $this->context) or count(get_overridable_roles($this->context)) > 0) { $url = new moodle_url('/' . $CFG->admin . '/roles/permissions.php', array('contextid' => $this->context->id)); $categorynode->add(get_string('permissions', 'role'), $url, self::TYPE_SETTING, null, 'permissions', new pix_icon('i/permissions', '')); } // Check role permissions if (has_any_capability(array('moodle/role:assign', 'moodle/role:safeoverride', 'moodle/role:override', 'moodle/role:assign'), $this->context)) { $url = new moodle_url('/' . $CFG->admin . '/roles/check.php', array('contextid' => $this->context->id)); $categorynode->add(get_string('checkpermissions', 'role'), $url, self::TYPE_SETTING, null, 'checkpermissions', new pix_icon('i/checkpermissions', '')); } // Cohorts if (has_capability('moodle/cohort:manage', $this->context) or has_capability('moodle/cohort:view', $this->context)) { $categorynode->add(get_string('cohorts', 'cohort'), new moodle_url('/cohort/index.php', array('contextid' => $this->context->id)), self::TYPE_SETTING, null, 'cohort', new pix_icon('i/cohort', '')); } // Manage filters if (has_capability('moodle/filter:manage', $this->context) && count(filter_get_available_in_context($this->context)) > 0) { $url = new moodle_url('/filter/manage.php', array('contextid' => $this->context->id)); $categorynode->add(get_string('filters', 'admin'), $url, self::TYPE_SETTING, null, 'filters', new pix_icon('i/filter', '')); } return $categorynode; }
/** * Produces the editing buttons for a module * * @global core_renderer $OUTPUT * @staticvar type $str * @param stdClass $mod The module to produce editing buttons for * @param bool $absolute_ignored ignored - all links are absolute * @param bool $moveselect If true a move seleciton process is used (default true) * @param int $indent The current indenting * @param int $section The section to link back to * @return string XHTML for the editing buttons */ function make_editing_buttons(stdClass $mod, $absolute_ignored = true, $moveselect = true, $indent = -1, $section = -1) { global $CFG, $OUTPUT; static $str; $coursecontext = get_context_instance(CONTEXT_COURSE, $mod->course); $modcontext = get_context_instance(CONTEXT_MODULE, $mod->id); $editcaps = array('moodle/course:manageactivities', 'moodle/course:activityvisibility', 'moodle/role:assign'); $dupecaps = array('moodle/backup:backuptargetimport', 'moodle/restore:restoretargetimport'); // no permission to edit anything if (!has_any_capability($editcaps, $modcontext) and !has_all_capabilities($dupecaps, $coursecontext)) { return false; } $hasmanageactivities = has_capability('moodle/course:manageactivities', $modcontext); if (!isset($str)) { $str = new stdClass(); $str->assign = get_string("assignroles", 'role'); $str->delete = get_string("delete"); $str->move = get_string("move"); $str->moveup = get_string("moveup"); $str->movedown = get_string("movedown"); $str->moveright = get_string("moveright"); $str->moveleft = get_string("moveleft"); $str->update = get_string("update"); $str->duplicate = get_string("duplicate"); $str->hide = get_string("hide"); $str->show = get_string("show"); $str->groupsnone = get_string('clicktochangeinbrackets', 'moodle', get_string("groupsnone")); $str->groupsseparate = get_string('clicktochangeinbrackets', 'moodle', get_string("groupsseparate")); $str->groupsvisible = get_string('clicktochangeinbrackets', 'moodle', get_string("groupsvisible")); $str->forcedgroupsnone = get_string('forcedmodeinbrackets', 'moodle', get_string("groupsnone")); $str->forcedgroupsseparate = get_string('forcedmodeinbrackets', 'moodle', get_string("groupsseparate")); $str->forcedgroupsvisible = get_string('forcedmodeinbrackets', 'moodle', get_string("groupsvisible")); } $baseurl = new moodle_url('/course/mod.php', array('sesskey' => sesskey())); if ($section >= 0) { $baseurl->param('sr', $section); } $actions = array(); // leftright if ($hasmanageactivities) { if (right_to_left()) { // Exchange arrows on RTL $rightarrow = 't/left'; $leftarrow = 't/right'; } else { $rightarrow = 't/right'; $leftarrow = 't/left'; } if ($indent > 0) { $actions[] = new action_link(new moodle_url($baseurl, array('id' => $mod->id, 'indent' => '-1')), new pix_icon($leftarrow, $str->moveleft, 'moodle', array('class' => 'iconsmall')), null, array('class' => 'editing_moveleft', 'title' => $str->moveleft)); } if ($indent >= 0) { $actions[] = new action_link(new moodle_url($baseurl, array('id' => $mod->id, 'indent' => '1')), new pix_icon($rightarrow, $str->moveright, 'moodle', array('class' => 'iconsmall')), null, array('class' => 'editing_moveright', 'title' => $str->moveright)); } } // move if ($hasmanageactivities) { if ($moveselect) { $actions[] = new action_link(new moodle_url($baseurl, array('copy' => $mod->id)), new pix_icon('t/move', $str->move, 'moodle', array('class' => 'iconsmall')), null, array('class' => 'editing_move', 'title' => $str->move)); } else { $actions[] = new action_link(new moodle_url($baseurl, array('id' => $mod->id, 'move' => '-1')), new pix_icon('t/up', $str->moveup, 'moodle', array('class' => 'iconsmall')), null, array('class' => 'editing_moveup', 'title' => $str->moveup)); $actions[] = new action_link(new moodle_url($baseurl, array('id' => $mod->id, 'move' => '1')), new pix_icon('t/down', $str->movedown, 'moodle', array('class' => 'iconsmall')), null, array('class' => 'editing_movedown', 'title' => $str->movedown)); } } // Update if ($hasmanageactivities) { $actions[] = new action_link(new moodle_url($baseurl, array('update' => $mod->id)), new pix_icon('t/edit', $str->update, 'moodle', array('class' => 'iconsmall')), null, array('class' => 'editing_update', 'title' => $str->update)); } // Duplicate (require both target import caps to be able to duplicate, see modduplicate.php) if (has_all_capabilities($dupecaps, $coursecontext)) { $actions[] = new action_link(new moodle_url($baseurl, array('duplicate' => $mod->id)), new pix_icon('t/copy', $str->duplicate, 'moodle', array('class' => 'iconsmall')), null, array('class' => 'editing_duplicate', 'title' => $str->duplicate)); } // Delete if ($hasmanageactivities) { $actions[] = new action_link(new moodle_url($baseurl, array('delete' => $mod->id)), new pix_icon('t/delete', $str->delete, 'moodle', array('class' => 'iconsmall')), null, array('class' => 'editing_delete', 'title' => $str->delete)); } // hideshow if (has_capability('moodle/course:activityvisibility', $modcontext)) { if ($mod->visible) { $actions[] = new action_link(new moodle_url($baseurl, array('hide' => $mod->id)), new pix_icon('t/hide', $str->hide, 'moodle', array('class' => 'iconsmall')), null, array('class' => 'editing_hide', 'title' => $str->hide)); } else { $actions[] = new action_link(new moodle_url($baseurl, array('show' => $mod->id)), new pix_icon('t/show', $str->show, 'moodle', array('class' => 'iconsmall')), null, array('class' => 'editing_show', 'title' => $str->show)); } } // groupmode if ($hasmanageactivities and $mod->groupmode !== false) { if ($mod->groupmode == SEPARATEGROUPS) { $groupmode = 0; $grouptitle = $str->groupsseparate; $forcedgrouptitle = $str->forcedgroupsseparate; $groupclass = 'editing_groupsseparate'; $groupimage = 't/groups'; } else { if ($mod->groupmode == VISIBLEGROUPS) { $groupmode = 1; $grouptitle = $str->groupsvisible; $forcedgrouptitle = $str->forcedgroupsvisible; $groupclass = 'editing_groupsvisible'; $groupimage = 't/groupv'; } else { $groupmode = 2; $grouptitle = $str->groupsnone; $forcedgrouptitle = $str->forcedgroupsnone; $groupclass = 'editing_groupsnone'; $groupimage = 't/groupn'; } } if ($mod->groupmodelink) { $actions[] = new action_link(new moodle_url($baseurl, array('id' => $mod->id, 'groupmode' => $groupmode)), new pix_icon($groupimage, $grouptitle, 'moodle', array('class' => 'iconsmall')), null, array('class' => $groupclass, 'title' => $grouptitle)); } else { $actions[] = new pix_icon($groupimage, $forcedgrouptitle, 'moodle', array('title' => $forcedgrouptitle, 'class' => 'iconsmall')); } } // Assign if (has_capability('moodle/role:assign', $modcontext)) { $actions[] = new action_link(new moodle_url('/' . $CFG->admin . '/roles/assign.php', array('contextid' => $modcontext->id)), new pix_icon('i/roles', $str->assign, 'moodle', array('class' => 'iconsmall')), null, array('class' => 'editing_assign', 'title' => $str->assign)); } $output = html_writer::start_tag('span', array('class' => 'commands')); foreach ($actions as $action) { if ($action instanceof renderable) { $output .= $OUTPUT->render($action); } else { $output .= $action; } } $output .= html_writer::end_tag('span'); return $output; }