Esempio n. 1
0
    }
    $navbaraddition = $pageheading;
} else {
    if (!empty($update)) {
        $url->param('update', $update);
        $PAGE->set_url($url);
        // Select the "Edit settings" from navigation.
        navigation_node::override_active_url(new moodle_url('/course/modedit.php', array('update' => $update, 'return' => 1)));
        // Check the course module exists.
        $cm = get_coursemodule_from_id('', $update, 0, false, MUST_EXIST);
        // Check the course exists.
        $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
        // require_login
        require_login($course, false, $cm);
        // needed to setup proper $COURSE
        list($cm, $context, $module, $data, $cw) = get_moduleinfo_data($cm, $course);
        $data->return = $return;
        $data->sr = $sectionreturn;
        $data->update = $update;
        $sectionname = get_section_name($course, $cw);
        $fullmodulename = get_string('modulename', $module->name);
        if ($data->section && $course->format != 'site') {
            $heading = new stdClass();
            $heading->what = $fullmodulename;
            $heading->in = $sectionname;
            $pageheading = get_string('updatingain', 'moodle', $heading);
        } else {
            $pageheading = get_string('updatinga', 'moodle', $fullmodulename);
        }
        $navbaraddition = null;
    } else {
Esempio n. 2
0
 /**
  * Return information about a course module.
  *
  * @param int $cmid the course module id
  * @return array of warnings and the course module
  * @since Moodle 3.0
  * @throws moodle_exception
  */
 public static function get_course_module($cmid)
 {
     global $CFG, $DB;
     $params = self::validate_parameters(self::get_course_module_parameters(), array('cmid' => $cmid));
     $warnings = array();
     $cm = get_coursemodule_from_id(null, $params['cmid'], 0, true, MUST_EXIST);
     $context = context_module::instance($cm->id);
     self::validate_context($context);
     // If the user has permissions to manage the activity, return all the information.
     if (has_capability('moodle/course:manageactivities', $context)) {
         require_once $CFG->dirroot . '/course/modlib.php';
         require_once $CFG->libdir . '/gradelib.php';
         $info = $cm;
         // Get the extra information: grade, advanced grading and outcomes data.
         $course = get_course($cm->course);
         list($newcm, $newcontext, $module, $extrainfo, $cw) = get_moduleinfo_data($cm, $course);
         // Grades.
         $gradeinfo = array('grade', 'gradepass', 'gradecat');
         foreach ($gradeinfo as $gfield) {
             if (isset($extrainfo->{$gfield})) {
                 $info->{$gfield} = $extrainfo->{$gfield};
             }
         }
         if (isset($extrainfo->grade) and $extrainfo->grade < 0) {
             $info->scale = $DB->get_field('scale', 'scale', array('id' => abs($extrainfo->grade)));
         }
         // Advanced grading.
         if (isset($extrainfo->_advancedgradingdata)) {
             $info->advancedgrading = array();
             foreach ($extrainfo as $key => $val) {
                 if (strpos($key, 'advancedgradingmethod_') === 0) {
                     $info->advancedgrading[] = array('area' => str_replace('advancedgradingmethod_', '', $key), 'method' => $val);
                 }
             }
         }
         // Outcomes.
         foreach ($extrainfo as $key => $val) {
             if (strpos($key, 'outcome_') === 0) {
                 if (!isset($info->outcomes)) {
                     $info->outcomes = array();
                 }
                 $id = str_replace('outcome_', '', $key);
                 $outcome = grade_outcome::fetch(array('id' => $id));
                 $scaleitems = $outcome->load_scale();
                 $info->outcomes[] = array('id' => $id, 'name' => external_format_string($outcome->get_name(), $context->id), 'scale' => $scaleitems->scale);
             }
         }
     } else {
         // Return information is safe to show to any user.
         $info = new stdClass();
         $info->id = $cm->id;
         $info->course = $cm->course;
         $info->module = $cm->module;
         $info->modname = $cm->modname;
         $info->instance = $cm->instance;
         $info->section = $cm->section;
         $info->sectionnum = $cm->sectionnum;
         $info->groupmode = $cm->groupmode;
         $info->groupingid = $cm->groupingid;
         $info->completion = $cm->completion;
     }
     // Format name.
     $info->name = external_format_string($cm->name, $context->id);
     $result = array();
     $result['cm'] = $info;
     $result['warnings'] = $warnings;
     return $result;
 }
Esempio n. 3
0
 /**
  * Test get_moduleinfo_data
  */
 public function test_get_moduleinfo_data()
 {
     global $DB;
     $this->resetAfterTest(true);
     $this->setAdminUser();
     $course = self::getDataGenerator()->create_course();
     $assignmodule = $DB->get_record('modules', array('name' => 'assign'), '*', MUST_EXIST);
     $assign = self::getDataGenerator()->create_module('assign', array('course' => $course->id));
     $assigncm = get_coursemodule_from_id('assign', $assign->cmid);
     $assigncontext = context_module::instance($assign->cmid);
     list($cm, $context, $module, $data, $cw) = get_moduleinfo_data($assigncm, $course);
     $this->assertEquals($assigncm, $cm);
     $this->assertEquals($assigncontext, $context);
     $this->assertEquals($assignmodule, $module);
     // Prepare expected data.
     $expecteddata = clone $assign;
     $expecteddata->coursemodule = $assigncm->id;
     $expecteddata->section = $cw->section;
     $expecteddata->visible = $assigncm->visible;
     $expecteddata->cmidnumber = $assigncm->idnumber;
     $expecteddata->groupmode = groups_get_activity_groupmode($cm);
     $expecteddata->groupingid = $assigncm->groupingid;
     $expecteddata->course = $course->id;
     $expecteddata->module = $module->id;
     $expecteddata->modulename = $module->name;
     $expecteddata->instance = $assigncm->instance;
     $expecteddata->completion = $assigncm->completion;
     $expecteddata->completionview = $assigncm->completionview;
     $expecteddata->completionexpected = $assigncm->completionexpected;
     $expecteddata->completionusegrade = is_null($assigncm->completiongradeitemnumber) ? 0 : 1;
     $expecteddata->showdescription = $assigncm->showdescription;
     $expecteddata->tags = core_tag_tag::get_item_tags_array('core', 'course_modules', $assigncm->id);
     $expecteddata->availabilityconditionsjson = null;
     $expecteddata->advancedgradingmethod_submissions = null;
     if ($items = grade_item::fetch_all(array('itemtype' => 'mod', 'itemmodule' => 'assign', 'iteminstance' => $assign->id, 'courseid' => $course->id))) {
         // set category if present
         $gradecat = false;
         foreach ($items as $item) {
             if ($gradecat === false) {
                 $gradecat = $item->categoryid;
                 continue;
             }
             if ($gradecat != $item->categoryid) {
                 //mixed categories
                 $gradecat = false;
                 break;
             }
         }
         if ($gradecat !== false) {
             // do not set if mixed categories present
             $expecteddata->gradecat = $gradecat;
         }
     }
     $expecteddata->gradepass = '******';
     // Unset untestable.
     unset($expecteddata->cmid);
     unset($data->introeditor);
     unset($data->_advancedgradingdata);
     $this->assertEquals($expecteddata, $data);
     // Create a viewer user. Not able to edit.
     $viewer = self::getDataGenerator()->create_user();
     $this->getDataGenerator()->enrol_user($viewer->id, $course->id);
     $this->setUser($viewer);
     $this->expectException('required_capability_exception');
     get_moduleinfo_data($assigncm, $course);
 }