/**
  * Adds all the standard elements to a form to edit the settings for an activity module.
  */
 function standard_coursemodule_elements()
 {
     global $COURSE, $CFG, $DB;
     $mform =& $this->_form;
     $this->_outcomesused = false;
     if ($this->_features->outcomes) {
         if ($outcomes = grade_outcome::fetch_all_available($COURSE->id)) {
             $this->_outcomesused = true;
             $mform->addElement('header', 'modoutcomes', get_string('outcomes', 'grades'));
             foreach ($outcomes as $outcome) {
                 $mform->addElement('advcheckbox', 'outcome_' . $outcome->id, $outcome->get_name());
             }
         }
     }
     if ($this->_features->rating) {
         require_once $CFG->dirroot . '/rating/lib.php';
         $rm = new rating_manager();
         $mform->addElement('header', 'modstandardratings', get_string('ratings', 'rating'));
         $permission = CAP_ALLOW;
         $rolenamestring = null;
         if (!empty($this->_cm)) {
             $context = context_module::instance($this->_cm->id);
             $rolenames = get_role_names_with_caps_in_context($context, array('moodle/rating:rate', 'mod/' . $this->_cm->modname . ':rate'));
             $rolenamestring = implode(', ', $rolenames);
         } else {
             $rolenamestring = get_string('capabilitychecknotavailable', 'rating');
         }
         $mform->addElement('static', 'rolewarning', get_string('rolewarning', 'rating'), $rolenamestring);
         $mform->addHelpButton('rolewarning', 'rolewarning', 'rating');
         $mform->addElement('select', 'assessed', get_string('aggregatetype', 'rating'), $rm->get_aggregate_types());
         $mform->setDefault('assessed', 0);
         $mform->addHelpButton('assessed', 'aggregatetype', 'rating');
         $mform->addElement('modgrade', 'scale', get_string('scale'), false);
         $mform->disabledIf('scale', 'assessed', 'eq', 0);
         $mform->addHelpButton('scale', 'modgrade', 'grades');
         $mform->setDefault('scale', $CFG->gradepointdefault);
         $mform->addElement('checkbox', 'ratingtime', get_string('ratingtime', 'rating'));
         $mform->disabledIf('ratingtime', 'assessed', 'eq', 0);
         $mform->addElement('date_time_selector', 'assesstimestart', get_string('from'));
         $mform->disabledIf('assesstimestart', 'assessed', 'eq', 0);
         $mform->disabledIf('assesstimestart', 'ratingtime');
         $mform->addElement('date_time_selector', 'assesstimefinish', get_string('to'));
         $mform->disabledIf('assesstimefinish', 'assessed', 'eq', 0);
         $mform->disabledIf('assesstimefinish', 'ratingtime');
     }
     //doing this here means splitting up the grade related settings on the lesson settings page
     //$this->standard_grading_coursemodule_elements();
     $mform->addElement('header', 'modstandardelshdr', get_string('modstandardels', 'form'));
     $mform->addElement('modvisible', 'visible', get_string('visible'));
     if (!empty($this->_cm)) {
         $context = context_module::instance($this->_cm->id);
         if (!has_capability('moodle/course:activityvisibility', $context)) {
             $mform->hardFreeze('visible');
         }
     }
     if ($this->_features->idnumber) {
         $mform->addElement('text', 'cmidnumber', get_string('idnumbermod'));
         $mform->setType('cmidnumber', PARAM_RAW);
         $mform->addHelpButton('cmidnumber', 'idnumbermod');
     }
     if ($this->_features->groups) {
         $options = array(NOGROUPS => get_string('groupsnone'), SEPARATEGROUPS => get_string('groupsseparate'), VISIBLEGROUPS => get_string('groupsvisible'));
         $mform->addElement('select', 'groupmode', get_string('groupmode', 'group'), $options, NOGROUPS);
         $mform->addHelpButton('groupmode', 'groupmode', 'group');
     }
     if ($this->_features->groupings) {
         // Groupings selector - used to select grouping for groups in activity.
         $options = array();
         if ($groupings = $DB->get_records('groupings', array('courseid' => $COURSE->id))) {
             foreach ($groupings as $grouping) {
                 $options[$grouping->id] = format_string($grouping->name);
             }
         }
         core_collator::asort($options);
         $options = array(0 => get_string('none')) + $options;
         $mform->addElement('select', 'groupingid', get_string('grouping', 'group'), $options);
         $mform->addHelpButton('groupingid', 'grouping', 'group');
     }
     if (!empty($CFG->enableavailability)) {
         // Add special button to end of previous section if groups/groupings
         // are enabled.
         if ($this->_features->groups || $this->_features->groupings) {
             $mform->addElement('static', 'restrictgroupbutton', '', html_writer::tag('button', get_string('restrictbygroup', 'availability'), array('id' => 'restrictbygroup', 'disabled' => 'disabled')));
         }
         // Availability field. This is just a textarea; the user interface
         // interaction is all implemented in JavaScript.
         $mform->addElement('header', 'availabilityconditionsheader', get_string('restrictaccess', 'availability'));
         // Note: This field cannot be named 'availability' because that
         // conflicts with fields in existing modules (such as assign).
         // So it uses a long name that will not conflict.
         $mform->addElement('textarea', 'availabilityconditionsjson', get_string('accessrestrictions', 'availability'));
         // The _cm variable may not be a proper cm_info, so get one from modinfo.
         if ($this->_cm) {
             $modinfo = get_fast_modinfo($COURSE);
             $cm = $modinfo->get_cm($this->_cm->id);
         } else {
             $cm = null;
         }
         \core_availability\frontend::include_all_javascript($COURSE, $cm);
     }
     // Conditional activities: completion tracking section
     if (!isset($completion)) {
         $completion = new completion_info($COURSE);
     }
     if ($completion->is_enabled()) {
         $mform->addElement('header', 'activitycompletionheader', get_string('activitycompletion', 'completion'));
         // Unlock button for if people have completed it (will
         // be removed in definition_after_data if they haven't)
         $mform->addElement('submit', 'unlockcompletion', get_string('unlockcompletion', 'completion'));
         $mform->registerNoSubmitButton('unlockcompletion');
         $mform->addElement('hidden', 'completionunlocked', 0);
         $mform->setType('completionunlocked', PARAM_INT);
         $trackingdefault = COMPLETION_TRACKING_NONE;
         // If system and activity default is on, set it.
         if ($CFG->completiondefault && $this->_features->defaultcompletion) {
             $trackingdefault = COMPLETION_TRACKING_MANUAL;
         }
         $mform->addElement('select', 'completion', get_string('completion', 'completion'), array(COMPLETION_TRACKING_NONE => get_string('completion_none', 'completion'), COMPLETION_TRACKING_MANUAL => get_string('completion_manual', 'completion')));
         $mform->setDefault('completion', $trackingdefault);
         $mform->addHelpButton('completion', 'completion', 'completion');
         // Automatic completion once you view it
         $gotcompletionoptions = false;
         if (plugin_supports('mod', $this->_modname, FEATURE_COMPLETION_TRACKS_VIEWS, false)) {
             $mform->addElement('checkbox', 'completionview', get_string('completionview', 'completion'), get_string('completionview_desc', 'completion'));
             $mform->disabledIf('completionview', 'completion', 'ne', COMPLETION_TRACKING_AUTOMATIC);
             $gotcompletionoptions = true;
         }
         // Automatic completion once it's graded
         if (plugin_supports('mod', $this->_modname, FEATURE_GRADE_HAS_GRADE, false)) {
             $mform->addElement('checkbox', 'completionusegrade', get_string('completionusegrade', 'completion'), get_string('completionusegrade_desc', 'completion'));
             $mform->disabledIf('completionusegrade', 'completion', 'ne', COMPLETION_TRACKING_AUTOMATIC);
             $mform->addHelpButton('completionusegrade', 'completionusegrade', 'completion');
             $gotcompletionoptions = true;
             // If using the rating system, there is no grade unless ratings are enabled.
             if ($this->_features->rating) {
                 $mform->disabledIf('completionusegrade', 'assessed', 'eq', 0);
             }
         }
         // Automatic completion according to module-specific rules
         $this->_customcompletionelements = $this->add_completion_rules();
         foreach ($this->_customcompletionelements as $element) {
             $mform->disabledIf($element, 'completion', 'ne', COMPLETION_TRACKING_AUTOMATIC);
         }
         $gotcompletionoptions = $gotcompletionoptions || count($this->_customcompletionelements) > 0;
         // Automatic option only appears if possible
         if ($gotcompletionoptions) {
             $mform->getElement('completion')->addOption(get_string('completion_automatic', 'completion'), COMPLETION_TRACKING_AUTOMATIC);
         }
         // Completion expected at particular date? (For progress tracking)
         $mform->addElement('date_selector', 'completionexpected', get_string('completionexpected', 'completion'), array('optional' => true));
         $mform->addHelpButton('completionexpected', 'completionexpected', 'completion');
         $mform->disabledIf('completionexpected', 'completion', 'eq', COMPLETION_TRACKING_NONE);
     }
     $this->standard_hidden_coursemodule_elements();
 }
 /**
  * This function tests the teacher searching when no course category or course is selected.
  */
 public function test_teachersquery_no_filter()
 {
     global $CFG;
     $this->resetAfterTest(true);
     require_once $CFG->dirroot . '/report/ncccscensus/lib.php';
     $data = $this->createdata_for_teacherfilter();
     // Assign role and remove capability.
     $coursecontext = context_course::instance($data['course1']->id);
     $roles = get_role_names_with_caps_in_context($coursecontext, array('moodle/grade:edit'));
     $roleid = 0;
     foreach ($roles as $rid => $role) {
         $roleid = $rid;
         $this->getDataGenerator()->enrol_user($data['user1']->id, $data['course1']->id, $roleid);
         break;
     }
     // Test: one user is returned.
     $results = report_ncccscensus_teacher_search('teacher', array(), array());
     $this->assertEquals(1, count($results));
     $this->assertArrayHasKey('name', $results[0]);
     $this->assertArrayHasKey('id', $results[0]);
     $this->assertEquals($data['user1']->id, $results[0]['id']);
     // Remove the capability from the user's role in the course.
     role_change_permission($roleid, $coursecontext, 'moodle/grade:edit', CAP_PREVENT);
     // Test: no user is returned
     $results = report_ncccscensus_teacher_search('teacher', array(), array());
     $this->assertEquals(1, count($results));
     $this->assertArrayHasKey('name', $results[0]);
     $this->assertArrayNotHasKey('id', $results[0]);
     // Test: one of two users are returned.
     $this->getDataGenerator()->enrol_user($data['user2']->id, $data['course3']->id, $roleid);
     $results = report_ncccscensus_teacher_search('teacher', array(), array());
     $this->assertEquals(1, count($results));
     $this->assertArrayHasKey('name', $results[0]);
     $this->assertArrayHasKey('id', $results[0]);
     $this->assertEquals($data['user2']->id, $results[0]['id']);
 }
Exemple #3
0
 /**
  * Adds all the standard elements to a form to edit the settings for an activity module.
  */
 function standard_coursemodule_elements()
 {
     global $COURSE, $CFG, $DB;
     $mform =& $this->_form;
     $this->_outcomesused = false;
     if ($this->_features->outcomes) {
         if ($outcomes = grade_outcome::fetch_all_available($COURSE->id)) {
             $this->_outcomesused = true;
             $mform->addElement('header', 'modoutcomes', get_string('outcomes', 'grades'));
             foreach ($outcomes as $outcome) {
                 $mform->addElement('advcheckbox', 'outcome_' . $outcome->id, $outcome->get_name());
             }
         }
     }
     if ($this->_features->rating) {
         require_once $CFG->dirroot . '/rating/lib.php';
         $rm = new rating_manager();
         $mform->addElement('header', 'modstandardratings', get_string('ratings', 'rating'));
         $permission = CAP_ALLOW;
         $rolenamestring = null;
         if (!empty($this->_cm)) {
             $context = context_module::instance($this->_cm->id);
             $rolenames = get_role_names_with_caps_in_context($context, array('moodle/rating:rate', 'mod/' . $this->_cm->modname . ':rate'));
             $rolenamestring = implode(', ', $rolenames);
         } else {
             $rolenamestring = get_string('capabilitychecknotavailable', 'rating');
         }
         $mform->addElement('static', 'rolewarning', get_string('rolewarning', 'rating'), $rolenamestring);
         $mform->addHelpButton('rolewarning', 'rolewarning', 'rating');
         $mform->addElement('select', 'assessed', get_string('aggregatetype', 'rating'), $rm->get_aggregate_types());
         $mform->setDefault('assessed', 0);
         $mform->addHelpButton('assessed', 'aggregatetype', 'rating');
         $mform->addElement('modgrade', 'scale', get_string('scale'), false);
         $mform->disabledIf('scale', 'assessed', 'eq', 0);
         $mform->addElement('checkbox', 'ratingtime', get_string('ratingtime', 'rating'));
         $mform->disabledIf('ratingtime', 'assessed', 'eq', 0);
         $mform->addElement('date_time_selector', 'assesstimestart', get_string('from'));
         $mform->disabledIf('assesstimestart', 'assessed', 'eq', 0);
         $mform->disabledIf('assesstimestart', 'ratingtime');
         $mform->addElement('date_time_selector', 'assesstimefinish', get_string('to'));
         $mform->disabledIf('assesstimefinish', 'assessed', 'eq', 0);
         $mform->disabledIf('assesstimefinish', 'ratingtime');
     }
     //doing this here means splitting up the grade related settings on the lesson settings page
     //$this->standard_grading_coursemodule_elements();
     $mform->addElement('header', 'modstandardelshdr', get_string('modstandardels', 'form'));
     if ($this->_features->groups) {
         $options = array(NOGROUPS => get_string('groupsnone'), SEPARATEGROUPS => get_string('groupsseparate'), VISIBLEGROUPS => get_string('groupsvisible'));
         $mform->addElement('select', 'groupmode', get_string('groupmode', 'group'), $options, NOGROUPS);
         $mform->addHelpButton('groupmode', 'groupmode', 'group');
     }
     if ($this->_features->groupings or $this->_features->groupmembersonly) {
         //groupings selector - used for normal grouping mode or also when restricting access with groupmembersonly
         $options = array();
         $options[0] = get_string('none');
         if ($groupings = $DB->get_records('groupings', array('courseid' => $COURSE->id))) {
             foreach ($groupings as $grouping) {
                 $options[$grouping->id] = format_string($grouping->name);
             }
         }
         $mform->addElement('select', 'groupingid', get_string('grouping', 'group'), $options);
         $mform->addHelpButton('groupingid', 'grouping', 'group');
         $mform->setAdvanced('groupingid');
     }
     if ($this->_features->groupmembersonly) {
         $mform->addElement('checkbox', 'groupmembersonly', get_string('groupmembersonly', 'group'));
         $mform->addHelpButton('groupmembersonly', 'groupmembersonly', 'group');
         $mform->setAdvanced('groupmembersonly');
     }
     $mform->addElement('modvisible', 'visible', get_string('visible'));
     if (!empty($this->_cm)) {
         $context = context_module::instance($this->_cm->id);
         if (!has_capability('moodle/course:activityvisibility', $context)) {
             $mform->hardFreeze('visible');
         }
     }
     if ($this->_features->idnumber) {
         $mform->addElement('text', 'cmidnumber', get_string('idnumbermod'));
         $mform->addHelpButton('cmidnumber', 'idnumbermod');
     }
     if (!empty($CFG->enableavailability)) {
         // String used by conditions
         $strnone = get_string('none', 'condition');
         // Conditional availability
         // Available from/to defaults to midnight because then the display
         // will be nicer where it tells users when they can access it (it
         // shows only the date and not time).
         $date = usergetdate(time());
         $midnight = make_timestamp($date['year'], $date['mon'], $date['mday']);
         // From/until controls
         $mform->addElement('header', 'availabilityconditionsheader', get_string('availabilityconditions', 'condition'));
         $mform->addElement('date_time_selector', 'availablefrom', get_string('availablefrom', 'condition'), array('optional' => true, 'defaulttime' => $midnight));
         $mform->addHelpButton('availablefrom', 'availablefrom', 'condition');
         $mform->addElement('date_time_selector', 'availableuntil', get_string('availableuntil', 'condition'), array('optional' => true, 'defaulttime' => $midnight));
         // Conditions based on grades
         $gradeoptions = array();
         $items = grade_item::fetch_all(array('courseid' => $COURSE->id));
         $items = $items ? $items : array();
         foreach ($items as $id => $item) {
             // Do not include grades for current item
             if (!empty($this->_cm) && $this->_cm->instance == $item->iteminstance && $this->_cm->modname == $item->itemmodule && $item->itemtype == 'mod') {
                 continue;
             }
             $gradeoptions[$id] = $item->get_name();
         }
         asort($gradeoptions);
         $gradeoptions = array(0 => $strnone) + $gradeoptions;
         $grouparray = array();
         $grouparray[] =& $mform->createElement('select', 'conditiongradeitemid', '', $gradeoptions);
         $grouparray[] =& $mform->createElement('static', '', '', ' ' . get_string('grade_atleast', 'condition') . ' ');
         $grouparray[] =& $mform->createElement('text', 'conditiongrademin', '', array('size' => 3));
         $grouparray[] =& $mform->createElement('static', '', '', '% ' . get_string('grade_upto', 'condition') . ' ');
         $grouparray[] =& $mform->createElement('text', 'conditiongrademax', '', array('size' => 3));
         $grouparray[] =& $mform->createElement('static', '', '', '%');
         $group = $mform->createElement('group', 'conditiongradegroup', get_string('gradecondition', 'condition'), $grouparray);
         // Get version with condition info and store it so we don't ask
         // twice
         if (!empty($this->_cm)) {
             $ci = new condition_info($this->_cm, CONDITION_MISSING_EXTRATABLE);
             $this->_cm = $ci->get_full_course_module();
             $count = count($this->_cm->conditionsgrade) + 1;
             $fieldcount = count($this->_cm->conditionsfield) + 1;
         } else {
             $count = 1;
             $fieldcount = 1;
         }
         $this->repeat_elements(array($group), $count, array(), 'conditiongraderepeats', 'conditiongradeadds', 2, get_string('addgrades', 'condition'), true);
         $mform->addHelpButton('conditiongradegroup[0]', 'gradecondition', 'condition');
         // Conditions based on user fields
         $operators = condition_info::get_condition_user_field_operators();
         $useroptions = condition_info::get_condition_user_fields();
         asort($useroptions);
         $useroptions = array(0 => $strnone) + $useroptions;
         $grouparray = array();
         $grouparray[] =& $mform->createElement('select', 'conditionfield', '', $useroptions);
         $grouparray[] =& $mform->createElement('select', 'conditionfieldoperator', '', $operators);
         $grouparray[] =& $mform->createElement('text', 'conditionfieldvalue');
         $mform->setType('conditionfieldvalue', PARAM_RAW);
         $group = $mform->createElement('group', 'conditionfieldgroup', get_string('userfield', 'condition'), $grouparray);
         $this->repeat_elements(array($group), $fieldcount, array(), 'conditionfieldrepeats', 'conditionfieldadds', 2, get_string('adduserfields', 'condition'), true);
         $mform->addHelpButton('conditionfieldgroup[0]', 'userfield', 'condition');
         // Conditions based on completion
         $completion = new completion_info($COURSE);
         if ($completion->is_enabled()) {
             $completionoptions = array();
             $modinfo = get_fast_modinfo($COURSE);
             foreach ($modinfo->cms as $id => $cm) {
                 // Add each course-module if it:
                 // (a) has completion turned on
                 // (b) is not the same as current course-module
                 if ($cm->completion && (empty($this->_cm) || $this->_cm->id != $id)) {
                     $completionoptions[$id] = $cm->name;
                 }
             }
             asort($completionoptions);
             $completionoptions = array(0 => $strnone) + $completionoptions;
             $completionvalues = array(COMPLETION_COMPLETE => get_string('completion_complete', 'condition'), COMPLETION_INCOMPLETE => get_string('completion_incomplete', 'condition'), COMPLETION_COMPLETE_PASS => get_string('completion_pass', 'condition'), COMPLETION_COMPLETE_FAIL => get_string('completion_fail', 'condition'));
             $grouparray = array();
             $grouparray[] =& $mform->createElement('select', 'conditionsourcecmid', '', $completionoptions);
             $grouparray[] =& $mform->createElement('select', 'conditionrequiredcompletion', '', $completionvalues);
             $group = $mform->createElement('group', 'conditioncompletiongroup', get_string('completioncondition', 'condition'), $grouparray);
             $count = empty($this->_cm) ? 1 : count($this->_cm->conditionscompletion) + 1;
             $this->repeat_elements(array($group), $count, array(), 'conditioncompletionrepeats', 'conditioncompletionadds', 2, get_string('addcompletions', 'condition'), true);
             $mform->addHelpButton('conditioncompletiongroup[0]', 'completioncondition', 'condition');
         }
         // Do we display availability info to students?
         $mform->addElement('select', 'showavailability', get_string('showavailability', 'condition'), array(CONDITION_STUDENTVIEW_SHOW => get_string('showavailability_show', 'condition'), CONDITION_STUDENTVIEW_HIDE => get_string('showavailability_hide', 'condition')));
         $mform->setDefault('showavailability', CONDITION_STUDENTVIEW_SHOW);
     }
     // Conditional activities: completion tracking section
     if (!isset($completion)) {
         $completion = new completion_info($COURSE);
     }
     if ($completion->is_enabled()) {
         $mform->addElement('header', 'activitycompletionheader', get_string('activitycompletion', 'completion'));
         // Unlock button for if people have completed it (will
         // be removed in definition_after_data if they haven't)
         $mform->addElement('submit', 'unlockcompletion', get_string('unlockcompletion', 'completion'));
         $mform->registerNoSubmitButton('unlockcompletion');
         $mform->addElement('hidden', 'completionunlocked', 0);
         $mform->setType('completionunlocked', PARAM_INT);
         $mform->addElement('select', 'completion', get_string('completion', 'completion'), array(COMPLETION_TRACKING_NONE => get_string('completion_none', 'completion'), COMPLETION_TRACKING_MANUAL => get_string('completion_manual', 'completion')));
         $mform->setDefault('completion', $this->_features->defaultcompletion ? COMPLETION_TRACKING_MANUAL : COMPLETION_TRACKING_NONE);
         $mform->addHelpButton('completion', 'completion', 'completion');
         // Automatic completion once you view it
         $gotcompletionoptions = false;
         if (plugin_supports('mod', $this->_modname, FEATURE_COMPLETION_TRACKS_VIEWS, false)) {
             $mform->addElement('checkbox', 'completionview', get_string('completionview', 'completion'), get_string('completionview_desc', 'completion'));
             $mform->disabledIf('completionview', 'completion', 'ne', COMPLETION_TRACKING_AUTOMATIC);
             $gotcompletionoptions = true;
         }
         // Automatic completion once it's graded
         if (plugin_supports('mod', $this->_modname, FEATURE_GRADE_HAS_GRADE, false)) {
             $mform->addElement('checkbox', 'completionusegrade', get_string('completionusegrade', 'completion'), get_string('completionusegrade_desc', 'completion'));
             $mform->disabledIf('completionusegrade', 'completion', 'ne', COMPLETION_TRACKING_AUTOMATIC);
             $mform->addHelpButton('completionusegrade', 'completionusegrade', 'completion');
             $gotcompletionoptions = true;
         }
         // Automatic completion according to module-specific rules
         $this->_customcompletionelements = $this->add_completion_rules();
         foreach ($this->_customcompletionelements as $element) {
             $mform->disabledIf($element, 'completion', 'ne', COMPLETION_TRACKING_AUTOMATIC);
         }
         $gotcompletionoptions = $gotcompletionoptions || count($this->_customcompletionelements) > 0;
         // Automatic option only appears if possible
         if ($gotcompletionoptions) {
             $mform->getElement('completion')->addOption(get_string('completion_automatic', 'completion'), COMPLETION_TRACKING_AUTOMATIC);
         }
         // Completion expected at particular date? (For progress tracking)
         $mform->addElement('date_selector', 'completionexpected', get_string('completionexpected', 'completion'), array('optional' => true));
         $mform->addHelpButton('completionexpected', 'completionexpected', 'completion');
         $mform->disabledIf('completionexpected', 'completion', 'eq', COMPLETION_TRACKING_NONE);
     }
     $this->standard_hidden_coursemodule_elements();
 }
<?php

// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
// Moodle settings and security based on capability.
define("MOODLE_INTERNAL", true);
require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/config.php';
require_login();
require_capability('moodle/site:config', context_system::instance());
global $DB, $CFG;
// Cat id.
$coursecatid = required_param('categoryid', PARAM_INT);
$categorycontext = context_coursecat::instance($coursecatid);
$roleswith = get_role_names_with_caps_in_context($categorycontext, array('moodle/course:viewhiddencourses'));
$body = '';
foreach ($roleswith as $role) {
    $body .= "{$role}<br/>";
}
echo $body;