function report_comments_getcoursecomments($courseid, $sort = 'date') { global $CFG, $DB; $formatoptions = array('overflowdiv' => true); $strftimeformat = get_string('strftimerecentfull', 'langconfig'); $context = context_course::instance($courseid); $comments = $DB->get_records('comments', array('contextid' => $context->id)); foreach ($comments as $comment) { $user = $DB->get_record('user', array('id' => $comment->userid), 'firstname, lastname'); $url = new moodle_url('/report/comments/index.php', array('id' => $comment->userid, 'course' => $courseid)); $comment->fullname = html_writer::link($url, $user->firstname . ' ' . $user->lastname); $comment->time = userdate($comment->timecreated, $strftimeformat); $url = new moodle_url('/course/view.php', array('id' => $courseid)); $comment->content = html_writer::link($url, format_text($comment->content, $comment->format, $formatoptions)); } $rawmods = get_course_mods($courseid); foreach ($rawmods as $mod) { if ($context = $DB->get_record('context', array('instanceid' => $mod->id, 'contextlevel' => CONTEXT_MODULE))) { if ($modcomments = $DB->get_records('comments', array('contextid' => $context->id))) { foreach ($modcomments as $comment) { $user = $DB->get_record('user', array('id' => $comment->userid), 'firstname, lastname'); $url = new moodle_url('/report/comments/index.php', array('course' => $courseid, 'id' => $comment->userid)); $comment->fullname = html_writer::link($url, $user->firstname . ' ' . $user->lastname); $comment->time = userdate($comment->timecreated, $strftimeformat); $base = core_component::get_component_directory('mod_' . $mod->modname); if (file_exists("{$base}/view.php")) { $base = substr($base, strlen($CFG->dirroot)); $url = new moodle_url("{$base}/view.php", array('id' => $mod->id)); $comment->content = html_writer::link($url, format_text($comment->content, $comment->format, $formatoptions)); } else { $comment->content = format_text($comment->content, $comment->format, $formatoptions); } $comments[] = $comment; } } } } switch ($sort) { case 'date': usort($comments, "cmpdate"); break; case 'content': usort($comments, "cmpcontent"); break; case 'author': usort($comments, "cmpid"); break; } return $comments; }
/** * Returns true if a scale is in use in the given course. * * @param int $courseid The course to be checked. * @param int $scaleid The scale to be checked. * @return boolean * @todo Finish documenting this function */ function course_scale_used($courseid, $scaleid) { global $CFG; $return = 0; if (!empty($scaleid)) { if ($cms = get_course_mods($courseid)) { foreach ($cms as $cm) { //Check cm->name/lib.php exists if (file_exists($CFG->dirroot . '/mod/' . $cm->modname . '/lib.php')) { include_once $CFG->dirroot . '/mod/' . $cm->modname . '/lib.php'; $function_name = $cm->modname . '_scale_used'; if (function_exists($function_name)) { if ($function_name($cm->instance, $scaleid)) { return true; } } } } } } return false; }
function get_course_mods($id, $username = '') { global $CFG, $DB; $username = utf8_decode($username); $username = strtolower($username); if ($username) { $user = get_complete_user_data('username', $username); } $modinfo = get_fast_modinfo($id); $sections = $modinfo->get_section_info_all(); $forum = forum_get_course_forum($id, 'news'); $news_forum_id = $forum->id; $mods = get_fast_modinfo($id)->get_cms(); $modnames = get_module_types_names(); $modnamesplural = get_module_types_names(true); $modnamesused = get_fast_modinfo($id)->get_used_module_names(); $rawmods = get_course_mods($id); $context = context_course::instance($id); // Kludge to use username param to get non visible sections and modules $username_orig = $username; if ($username_orig == 'joomdle_get_not_visible') { $username = ''; } $e = array(); foreach ($sections as $section) { if ($username_orig != 'joomdle_get_not_visible') { if (!$section->visible) { continue; } } $sectionmods = explode(",", $section->sequence); foreach ($sectionmods as $modnumber) { if (empty($mods[$modnumber])) { continue; } $mod = $mods[$modnumber]; if ($username_orig != 'joomdle_get_not_visible') { if (!$mod->visible) { continue; } } $resource['completion_info'] = ''; if ($username) { $cm = get_coursemodule_from_id(false, $mod->id); if (!\core_availability\info_module::is_user_visible($cm, $user->id)) { if (empty($mod->availableinfo)) { // Mod not visible, and no completion info to show continue; } $resource['available'] = 0; $ci = new condition_info($mod); $resource['completion_info'] = $ci->get_full_information(); } else { $resource['available'] = 1; } } else { $resource['available'] = 1; } $e[$section->section]['section'] = $section->section; $e[$section->section]['name'] = $section->name; $e[$section->section]['summary'] = file_rewrite_pluginfile_urls($section->summary, 'pluginfile.php', $context->id, 'course', 'section', $section->id); $e[$section->section]['summary'] = str_replace('pluginfile.php', '/auth/joomdle/pluginfile_joomdle.php', $e[$section->section]['summary']); $resource['id'] = $mod->id; $resource['name'] = $mod->name; $resource['mod'] = $mod->modname; // Get content $resource['content'] = ''; $modname = $mod->modname; $functionname = $modname . "_get_coursemodule_info"; if (file_exists("{$CFG->dirroot}/mod/{$modname}/lib.php")) { include_once "{$CFG->dirroot}/mod/{$modname}/lib.php"; if ($hasfunction = function_exists($functionname)) { if ($info = $functionname($rawmods[$modnumber])) { $resource['content'] = $info->content; } } } // Format for mod->icon is: f/type-24 $type = substr($mod->icon, 2); $parts = explode('-', $type); $type = $parts[0]; $resource['type'] = $type; //In forum, type is unused, so we use it for forum type: news/general if ($mod->modname == 'forum') { $cm = get_coursemodule_from_id('forum', $mod->id); if ($cm->instance == $news_forum_id) { $resource['type'] = 'news'; } } /* if ($mod->modname == 'resource') { // Get display options for resource $params = array ($mod->instance); $query = "SELECT display from {$CFG->prefix}resource where id = ?"; $record = $DB->get_record_sql ($query, $params); $resource['display'] = $record->display; } else $resource['display'] = 0; */ $resource['display'] = $this->get_display($mod->modname, $mod->instance); $e[$section->section]['mods'][] = $resource; } } return $e; }
public function test_cm_info_properties() { global $DB, $CFG; $this->resetAfterTest(); $oldcfgenableavailability = $CFG->enableavailability; $oldcfgenablecompletion = $CFG->enablecompletion; set_config('enableavailability', 1); set_config('enablecompletion', 1); $this->setAdminUser(); // Generate the course and pre-requisite module. $course = $this->getDataGenerator()->create_course(array('format' => 'topics', 'numsections' => 3, 'enablecompletion' => 1, 'groupmode' => SEPARATEGROUPS, 'forcegroupmode' => 0), array('createsections' => true)); $coursecontext = context_course::instance($course->id); $prereqforum = $this->getDataGenerator()->create_module('forum', array('course' => $course->id), array('completion' => 1)); // Generate module and add availability conditions. $availability = '{"op":"&","showc":[true,true,true],"c":[' . '{"type":"completion","cm":' . $prereqforum->cmid . ',"e":"' . COMPLETION_COMPLETE . '"},' . '{"type":"grade","id":666,"min":0.4},' . '{"type":"profile","op":"contains","sf":"email","v":"test"}' . ']}'; $assign = $this->getDataGenerator()->create_module('assign', array('course' => $course->id), array('idnumber' => 123, 'groupmode' => VISIBLEGROUPS, 'availability' => $availability)); rebuild_course_cache($course->id, true); // Retrieve all related records from DB. $assigndb = $DB->get_record('assign', array('id' => $assign->id)); $moduletypedb = $DB->get_record('modules', array('name' => 'assign')); $moduledb = $DB->get_record('course_modules', array('module' => $moduletypedb->id, 'instance' => $assign->id)); $sectiondb = $DB->get_record('course_sections', array('id' => $moduledb->section)); $modnamessingular = get_module_types_names(false); $modnamesplural = get_module_types_names(true); // Create and enrol a student. $studentrole = $DB->get_record('role', array('shortname' => 'student'), '*', MUST_EXIST); $student = $this->getDataGenerator()->create_user(); role_assign($studentrole->id, $student->id, $coursecontext); $enrolplugin = enrol_get_plugin('manual'); $enrolinstance = $DB->get_record('enrol', array('courseid' => $course->id, 'enrol' => 'manual')); $enrolplugin->enrol_user($enrolinstance, $student->id); $this->setUser($student); // Emulate data used in building course cache to receive the same instance of cached_cm_info as was used in building modinfo. $rawmods = get_course_mods($course->id); $cachedcminfo = assign_get_coursemodule_info($rawmods[$moduledb->id]); // Get modinfo. $modinfo = get_fast_modinfo($course->id); $cm = $modinfo->instances['assign'][$assign->id]; $this->assertEquals($moduledb->id, $cm->id); $this->assertEquals($assigndb->id, $cm->instance); $this->assertEquals($moduledb->course, $cm->course); $this->assertEquals($moduledb->idnumber, $cm->idnumber); $this->assertEquals($moduledb->added, $cm->added); $this->assertEquals($moduledb->visible, $cm->visible); $this->assertEquals($moduledb->visibleold, $cm->visibleold); $this->assertEquals($moduledb->groupmode, $cm->groupmode); $this->assertEquals(VISIBLEGROUPS, $cm->groupmode); $this->assertEquals($moduledb->groupingid, $cm->groupingid); $this->assertEquals($course->groupmodeforce, $cm->coursegroupmodeforce); $this->assertEquals($course->groupmode, $cm->coursegroupmode); $this->assertEquals(SEPARATEGROUPS, $cm->coursegroupmode); $this->assertEquals($course->groupmodeforce ? $course->groupmode : $moduledb->groupmode, $cm->effectivegroupmode); // (since mod_assign supports groups). $this->assertEquals(VISIBLEGROUPS, $cm->effectivegroupmode); $this->assertEquals($moduledb->indent, $cm->indent); $this->assertEquals($moduledb->completion, $cm->completion); $this->assertEquals($moduledb->completiongradeitemnumber, $cm->completiongradeitemnumber); $this->assertEquals($moduledb->completionview, $cm->completionview); $this->assertEquals($moduledb->completionexpected, $cm->completionexpected); $this->assertEquals($moduledb->showdescription, $cm->showdescription); $this->assertEquals(null, $cm->extra); // Deprecated field. Used in module types that don't return cached_cm_info. $this->assertEquals($cachedcminfo->icon, $cm->icon); $this->assertEquals($cachedcminfo->iconcomponent, $cm->iconcomponent); $this->assertEquals('assign', $cm->modname); $this->assertEquals($moduledb->module, $cm->module); $this->assertEquals($cachedcminfo->name, $cm->name); $this->assertEquals($sectiondb->section, $cm->sectionnum); $this->assertEquals($moduledb->section, $cm->section); $this->assertEquals($availability, $cm->availability); $this->assertEquals(context_module::instance($moduledb->id), $cm->context); $this->assertEquals($modnamessingular['assign'], $cm->modfullname); $this->assertEquals($modnamesplural['assign'], $cm->modplural); $this->assertEquals(new moodle_url('/mod/assign/view.php', array('id' => $moduledb->id)), $cm->url); $this->assertEquals($cachedcminfo->customdata, $cm->customdata); // Deprecated field. $this->assertEquals(0, $cm->groupmembersonly); $this->assertDebuggingCalled(); // Dynamic fields, just test that they can be retrieved (must be carefully tested in each activity type). $this->assertNotEmpty($cm->availableinfo); // Lists all unmet availability conditions. $this->assertEquals(0, $cm->uservisible); $this->assertEquals('', $cm->extraclasses); $this->assertEquals('', $cm->onclick); $this->assertEquals(null, $cm->afterlink); $this->assertEquals(null, $cm->afterediticons); $this->assertEquals('', $cm->content); // Attempt to access and set non-existing field. $this->assertTrue(empty($modinfo->somefield)); $this->assertFalse(isset($modinfo->somefield)); $cm->somefield; $this->assertDebuggingCalled(); $cm->somefield = 'Some value'; $this->assertDebuggingCalled(); $this->assertEmpty($cm->somefield); $this->assertDebuggingCalled(); // Attempt to overwrite an existing field. $prevvalue = $cm->name; $this->assertNotEmpty($cm->name); $this->assertFalse(empty($cm->name)); $this->assertTrue(isset($cm->name)); $cm->name = 'Illegal overwriting'; $this->assertDebuggingCalled(); $this->assertEquals($prevvalue, $cm->name); $this->assertDebuggingNotCalled(); // Restore settings. set_config('enableavailability', $oldcfgenableavailability); set_config('enablecompletion', $oldcfgenablecompletion); }
function definition() { global $CFG, $COURSE, $DB; $mform = $this->_form; $config = get_config('lesson'); $mform->addElement('header', 'general', get_string('general', 'form')); /** Legacy slideshow width element to maintain backwards compatibility */ $mform->addElement('hidden', 'width'); $mform->setType('width', PARAM_INT); $mform->setDefault('width', $CFG->lesson_slideshowwidth); /** Legacy slideshow height element to maintain backwards compatibility */ $mform->addElement('hidden', 'height'); $mform->setType('height', PARAM_INT); $mform->setDefault('height', $CFG->lesson_slideshowheight); /** Legacy slideshow background color element to maintain backwards compatibility */ $mform->addElement('hidden', 'bgcolor'); $mform->setType('bgcolor', PARAM_TEXT); $mform->setDefault('bgcolor', $CFG->lesson_slideshowbgcolor); /** Legacy media popup width element to maintain backwards compatibility */ $mform->addElement('hidden', 'mediawidth'); $mform->setType('mediawidth', PARAM_INT); $mform->setDefault('mediawidth', $CFG->lesson_mediawidth); /** Legacy media popup height element to maintain backwards compatibility */ $mform->addElement('hidden', 'mediaheight'); $mform->setType('mediaheight', PARAM_INT); $mform->setDefault('mediaheight', $CFG->lesson_mediaheight); /** Legacy media popup close button element to maintain backwards compatibility */ $mform->addElement('hidden', 'mediaclose'); $mform->setType('mediaclose', PARAM_BOOL); $mform->setDefault('mediaclose', $CFG->lesson_mediaclose); $mform->addElement('text', 'name', get_string('name'), array('size' => '64')); if (!empty($CFG->formatstringstriptags)) { $mform->setType('name', PARAM_TEXT); } else { $mform->setType('name', PARAM_CLEANHTML); } $mform->addRule('name', null, 'required', null, 'client'); $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); $this->standard_intro_elements(); // Appearance. $mform->addElement('header', 'appearancehdr', get_string('appearance')); $filemanageroptions = array(); $filemanageroptions['filetypes'] = '*'; $filemanageroptions['maxbytes'] = $this->course->maxbytes; $filemanageroptions['subdirs'] = 0; $filemanageroptions['maxfiles'] = 1; $mform->addElement('filemanager', 'mediafile', get_string('mediafile', 'lesson'), null, $filemanageroptions); $mform->addHelpButton('mediafile', 'mediafile', 'lesson'); $mform->addElement('selectyesno', 'progressbar', get_string('progressbar', 'lesson')); $mform->addHelpButton('progressbar', 'progressbar', 'lesson'); $mform->setDefault('progressbar', 0); $mform->addElement('selectyesno', 'ongoing', get_string('ongoing', 'lesson')); $mform->addHelpButton('ongoing', 'ongoing', 'lesson'); $mform->setDefault('ongoing', 0); $mform->addElement('selectyesno', 'displayleft', get_string('displayleftmenu', 'lesson')); $mform->addHelpButton('displayleft', 'displayleftmenu', 'lesson'); $mform->setDefault('displayleft', 0); $options = array(); for ($i = 100; $i >= 0; $i--) { $options[$i] = $i . '%'; } $mform->addElement('select', 'displayleftif', get_string('displayleftif', 'lesson'), $options); $mform->addHelpButton('displayleftif', 'displayleftif', 'lesson'); $mform->setDefault('displayleftif', 0); $mform->addElement('selectyesno', 'slideshow', get_string('slideshow', 'lesson')); $mform->addHelpButton('slideshow', 'slideshow', 'lesson'); $mform->setDefault('slideshow', 0); $numbers = array(); for ($i = 20; $i > 1; $i--) { $numbers[$i] = $i; } $mform->addElement('select', 'maxanswers', get_string('maximumnumberofanswersbranches', 'lesson'), $numbers); $mform->setDefault('maxanswers', $CFG->lesson_maxanswers); $mform->setType('maxanswers', PARAM_INT); $mform->addHelpButton('maxanswers', 'maximumnumberofanswersbranches', 'lesson'); $mform->addElement('selectyesno', 'feedback', get_string('displaydefaultfeedback', 'lesson')); $mform->addHelpButton('feedback', 'displaydefaultfeedback', 'lesson'); $mform->setDefault('feedback', 0); // Get the modules. if ($mods = get_course_mods($COURSE->id)) { $modinstances = array(); foreach ($mods as $mod) { // Get the module name and then store it in a new array. if ($module = get_coursemodule_from_instance($mod->modname, $mod->instance, $COURSE->id)) { // Exclude this lesson, if it's already been saved. if (!isset($this->_cm->id) || $this->_cm->id != $mod->id) { $modinstances[$mod->id] = $mod->modname . ' - ' . $module->name; } } } asort($modinstances); // Sort by module name. $modinstances = array(0 => get_string('none')) + $modinstances; $mform->addElement('select', 'activitylink', get_string('activitylink', 'lesson'), $modinstances); $mform->addHelpButton('activitylink', 'activitylink', 'lesson'); $mform->setDefault('activitylink', 0); } // Availability. $mform->addElement('header', 'availabilityhdr', get_string('availability')); $mform->addElement('date_time_selector', 'available', get_string('available', 'lesson'), array('optional' => true)); $mform->setDefault('available', 0); $mform->addElement('date_time_selector', 'deadline', get_string('deadline', 'lesson'), array('optional' => true)); $mform->setDefault('deadline', 0); // Time limit. $mform->addElement('duration', 'timelimit', get_string('timelimit', 'lesson'), array('optional' => true)); $mform->addHelpButton('timelimit', 'timelimit', 'lesson'); $mform->addElement('selectyesno', 'usepassword', get_string('usepassword', 'lesson')); $mform->addHelpButton('usepassword', 'usepassword', 'lesson'); $mform->setDefault('usepassword', 0); $mform->addElement('passwordunmask', 'password', get_string('password', 'lesson')); $mform->setDefault('password', ''); $mform->setType('password', PARAM_RAW); $mform->disabledIf('password', 'usepassword', 'eq', 0); $mform->disabledIf('passwordunmask', 'usepassword', 'eq', 0); // Dependent on. if ($this->current && isset($this->current->dependency) && $this->current->dependency) { $mform->addElement('header', 'dependencyon', get_string('prerequisitelesson', 'lesson')); $mform->addElement('static', 'warningobsolete', get_string('warning', 'lesson'), get_string('prerequisiteisobsolete', 'lesson')); $options = array(0 => get_string('none')); if ($lessons = get_all_instances_in_course('lesson', $COURSE)) { foreach ($lessons as $lesson) { if ($lesson->id != $this->_instance) { $options[$lesson->id] = format_string($lesson->name, true); } } } $mform->addElement('select', 'dependency', get_string('dependencyon', 'lesson'), $options); $mform->addHelpButton('dependency', 'dependencyon', 'lesson'); $mform->setDefault('dependency', 0); $mform->addElement('text', 'timespent', get_string('timespentminutes', 'lesson')); $mform->setDefault('timespent', 0); $mform->setType('timespent', PARAM_INT); $mform->disabledIf('timespent', 'dependency', 'eq', 0); $mform->addElement('checkbox', 'completed', get_string('completed', 'lesson')); $mform->setDefault('completed', 0); $mform->disabledIf('completed', 'dependency', 'eq', 0); $mform->addElement('text', 'gradebetterthan', get_string('gradebetterthan', 'lesson')); $mform->setDefault('gradebetterthan', 0); $mform->setType('gradebetterthan', PARAM_INT); $mform->disabledIf('gradebetterthan', 'dependency', 'eq', 0); } else { $mform->addElement('hidden', 'dependency', 0); $mform->setType('dependency', PARAM_INT); $mform->addElement('hidden', 'timespent', 0); $mform->setType('timespent', PARAM_INT); $mform->addElement('hidden', 'completed', 0); $mform->setType('completed', PARAM_INT); $mform->addElement('hidden', 'gradebetterthan', 0); $mform->setType('gradebetterthan', PARAM_INT); $mform->setConstants(array('dependency' => 0, 'timespent' => 0, 'completed' => 0, 'gradebetterthan' => 0)); } // Flow control. $mform->addElement('header', 'flowcontrol', get_string('flowcontrol', 'lesson')); $mform->addElement('selectyesno', 'modattempts', get_string('modattempts', 'lesson')); $mform->addHelpButton('modattempts', 'modattempts', 'lesson'); $mform->setDefault('modattempts', 0); $mform->addElement('selectyesno', 'review', get_string('displayreview', 'lesson')); $mform->addHelpButton('review', 'displayreview', 'lesson'); $mform->setDefault('review', 0); $numbers = array(); for ($i = 10; $i > 0; $i--) { $numbers[$i] = $i; } $mform->addElement('select', 'maxattempts', get_string('maximumnumberofattempts', 'lesson'), $numbers); $mform->addHelpButton('maxattempts', 'maximumnumberofattempts', 'lesson'); $mform->setDefault('maxattempts', 1); $defaultnextpages = array(); $defaultnextpages[0] = get_string('normal', 'lesson'); $defaultnextpages[LESSON_UNSEENPAGE] = get_string('showanunseenpage', 'lesson'); $defaultnextpages[LESSON_UNANSWEREDPAGE] = get_string('showanunansweredpage', 'lesson'); $mform->addElement('select', 'nextpagedefault', get_string('actionaftercorrectanswer', 'lesson'), $defaultnextpages); $mform->addHelpButton('nextpagedefault', 'actionaftercorrectanswer', 'lesson'); $mform->setDefault('nextpagedefault', $CFG->lesson_defaultnextpage); $numbers = array(); for ($i = 100; $i >= 0; $i--) { $numbers[$i] = $i; } $mform->addElement('select', 'maxpages', get_string('numberofpagestoshow', 'lesson'), $numbers); $mform->addHelpButton('maxpages', 'numberofpagestoshow', 'lesson'); $mform->setDefault('maxpages', 0); // Grade. $this->standard_grading_coursemodule_elements(); // No header here, so that the following settings are displayed in the grade section. $mform->addElement('selectyesno', 'practice', get_string('practice', 'lesson')); $mform->addHelpButton('practice', 'practice', 'lesson'); $mform->setDefault('practice', 0); $mform->addElement('selectyesno', 'custom', get_string('customscoring', 'lesson')); $mform->addHelpButton('custom', 'customscoring', 'lesson'); $mform->setDefault('custom', 1); $mform->addElement('selectyesno', 'retake', get_string('retakesallowed', 'lesson')); $mform->addHelpButton('retake', 'retakesallowed', 'lesson'); $mform->setDefault('retake', 0); $options = array(); $options[0] = get_string('usemean', 'lesson'); $options[1] = get_string('usemaximum', 'lesson'); $mform->addElement('select', 'usemaxgrade', get_string('handlingofretakes', 'lesson'), $options); $mform->addHelpButton('usemaxgrade', 'handlingofretakes', 'lesson'); $mform->setDefault('usemaxgrade', 0); $mform->disabledIf('usemaxgrade', 'retake', 'eq', '0'); $numbers = array(); for ($i = 100; $i >= 0; $i--) { $numbers[$i] = $i; } $mform->addElement('select', 'minquestions', get_string('minimumnumberofquestions', 'lesson'), $numbers); $mform->addHelpButton('minquestions', 'minimumnumberofquestions', 'lesson'); $mform->setDefault('minquestions', 0); //------------------------------------------------------------------------------- $this->standard_coursemodule_elements(); //------------------------------------------------------------------------------- // buttons $this->add_action_buttons(); }
function course_scale_used($courseid, $scaleid) { global $CFG, $DB; debugging('course_scale_used() is deprecated and never used, plugins can implement <modname>_scale_used_anywhere, ' . 'all implementations of <modname>_scale_used are now ignored', DEBUG_DEVELOPER); $return = 0; if (!empty($scaleid)) { if ($cms = get_course_mods($courseid)) { foreach ($cms as $cm) { // Check cm->name/lib.php exists. if (file_exists($CFG->dirroot . '/mod/' . $cm->modname . '/lib.php')) { include_once $CFG->dirroot . '/mod/' . $cm->modname . '/lib.php'; $functionname = $cm->modname . '_scale_used'; if (function_exists($functionname)) { if ($functionname($cm->instance, $scaleid)) { $return++; } } } } } // Check if any course grade item makes use of the scale. $return += $DB->count_records('grade_items', array('courseid' => $courseid, 'scaleid' => $scaleid)); // Check if any outcome in the course makes use of the scale. $return += $DB->count_records_sql("SELECT COUNT('x')\n FROM {grade_outcomes_courses} goc,\n {grade_outcomes} go\n WHERE go.id = goc.outcomeid\n AND go.scaleid = ? AND goc.courseid = ?", array($scaleid, $courseid)); } return $return; }
function definition() { global $LESSON_NEXTPAGE_ACTION, $COURSE; $mform =& $this->_form; //------------------------------------------------------------------------------- $mform->addElement('header', 'general', get_string('general', 'form')); $mform->addElement('text', 'name', get_string('name'), array('size' => '64')); $mform->setType('name', PARAM_TEXT); $mform->addRule('name', null, 'required', null, 'client'); $mform->addElement('selectyesno', 'timed', get_string('timed', 'lesson')); $mform->setDefault('timed', 0); $mform->setHelpButton('timed', array('timed', get_string('timed', 'lesson'), 'lesson')); $mform->addElement('text', 'maxtime', get_string('maxtime', 'lesson')); $mform->setDefault('maxtime', 20); $mform->addRule('maxtime', null, 'required', null, 'client'); $mform->addRule('maxtime', null, 'numeric', null, 'client'); $mform->setType('maxtime', PARAM_INT); $numbers = array(); for ($i = 20; $i > 1; $i--) { $numbers[$i] = $i; } $mform->addElement('select', 'maxanswers', get_string('maximumnumberofanswersbranches', 'lesson'), $numbers); $mform->setDefault('maxanswers', 4); $mform->setHelpButton('maxanswers', array('maxanswers', get_string('displayformat', 'lesson'), 'lesson')); //------------------------------------------------------------------------------- $mform->addElement('header', '', get_string('gradeoptions', 'lesson')); $mform->addElement('selectyesno', 'practice', get_string('practice', 'lesson')); $mform->setHelpButton('practice', array('practice', get_string('practice', 'lesson'), 'lesson')); $mform->setDefault('practice', 0); $mform->addElement('selectyesno', 'custom', get_string('customscoring', 'lesson')); $mform->setHelpButton('custom', array('custom', get_string('customscoring', 'lesson'), 'lesson')); $mform->setDefault('custom', 1); $grades = array(); for ($i = 100; $i >= 0; $i--) { $grades[$i] = $i; } $mform->addElement('select', 'grade', get_string('maximumgrade'), $grades); $mform->setDefault('grade', 0); $mform->setHelpButton('grade', array('grade', get_string('maximumgrade', 'lesson'), 'lesson')); $mform->addElement('selectyesno', 'retake', get_string('canretake', 'lesson', $COURSE->student)); $mform->setHelpButton('retake', array('retake', get_string('canretake', 'lesson', $COURSE->student), 'lesson')); $mform->setDefault('retake', 0); $options = array(); $options[0] = get_string('usemean', 'lesson'); $options[1] = get_string('usemaximum', 'lesson'); $mform->addElement('select', 'usemaxgrade', get_string('handlingofretakes', 'lesson'), $options); $mform->setHelpButton('usemaxgrade', array('handlingofretakes', get_string('handlingofretakes', 'lesson'), 'lesson')); $mform->setDefault('usemaxgrade', 0); $mform->addElement('selectyesno', 'ongoing', get_string('ongoing', 'lesson')); $mform->setHelpButton('ongoing', array('ongoing', get_string('ongoing', 'lesson'), 'lesson')); $mform->setDefault('ongoing', 0); //------------------------------------------------------------------------------- $mform->addElement('header', '', get_string('flowcontrol', 'lesson')); $mform->addElement('selectyesno', 'modattempts', get_string('modattempts', 'lesson')); $mform->setHelpButton('modattempts', array('modattempts', get_string('modattempts', 'lesson'), 'lesson')); $mform->setDefault('modattempts', 0); $mform->addElement('selectyesno', 'review', get_string('displayreview', 'lesson')); $mform->setHelpButton('review', array('review', get_string('displayreview', 'lesson'), 'lesson')); $mform->setDefault('review', 0); $numbers = array(); for ($i = 10; $i > 0; $i--) { $numbers[$i] = $i; } $mform->addElement('select', 'maxattempts', get_string('maximumnumberofattempts', 'lesson'), $numbers); $mform->setHelpButton('maxattempts', array('maxattempts', get_string('maximumnumberofattempts', 'lesson'), 'lesson')); $mform->setDefault('maxattempts', 1); $mform->addElement('select', 'nextpagedefault', get_string('actionaftercorrectanswer', 'lesson'), $LESSON_NEXTPAGE_ACTION); $mform->setHelpButton('nextpagedefault', array('nextpageaction', get_string('actionaftercorrectanswer', 'lesson'), 'lesson')); $mform->setDefault('nextpagedefault', 0); $mform->addElement('selectyesno', 'feedback', get_string('displaydefaultfeedback', 'lesson')); $mform->setHelpButton('feedback', array('feedback', get_string('displaydefaultfeedback', 'lesson'), 'lesson')); $mform->setDefault('feedback', 0); $numbers = array(); for ($i = 100; $i >= 0; $i--) { $numbers[$i] = $i; } $mform->addElement('select', 'minquestions', get_string('minimumnumberofquestions', 'lesson'), $numbers); $mform->setHelpButton('minquestions', array('minquestions', get_string('minimumnumberofquestions', 'lesson'), 'lesson')); $mform->setDefault('minquestions', 0); $numbers = array(); for ($i = 100; $i >= 0; $i--) { $numbers[$i] = $i; } $mform->addElement('select', 'maxpages', get_string('numberofpagestoshow', 'lesson'), $numbers); $mform->setHelpButton('maxpages', array('maxpages', get_string('numberofpagestoshow', 'lesson'), 'lesson')); $mform->setDefault('maxpages', 0); //------------------------------------------------------------------------------- $mform->addElement('header', '', get_string('lessonformating', 'lesson')); $mform->addElement('selectyesno', 'slideshow', get_string('slideshow', 'lesson')); $mform->setHelpButton('slideshow', array('slideshow', get_string('slideshow', 'lesson'), 'lesson')); $mform->setDefault('slideshow', 0); $mform->addElement('text', 'width', get_string('slideshowwidth', 'lesson')); $mform->setDefault('width', 640); $mform->addRule('width', null, 'required', null, 'client'); $mform->addRule('width', null, 'numeric', null, 'client'); $mform->setHelpButton('width', array('width', get_string('slideshowwidth', 'lesson'), 'lesson')); $mform->setType('width', PARAM_INT); $mform->addElement('text', 'height', get_string('slideshowheight', 'lesson')); $mform->setDefault('height', 480); $mform->addRule('height', null, 'required', null, 'client'); $mform->addRule('height', null, 'numeric', null, 'client'); $mform->setHelpButton('height', array('height', get_string('slideshowheight', 'lesson'), 'lesson')); $mform->setType('height', PARAM_INT); $mform->addElement('text', 'bgcolor', get_string('slideshowbgcolor', 'lesson')); $mform->setDefault('bgcolor', '#FFFFFF'); $mform->addRule('bgcolor', null, 'required', null, 'client'); $mform->setHelpButton('bgcolor', array('bgcolor', get_string('slideshowbgcolor', 'lesson'), 'lesson')); $mform->setType('bgcolor', PARAM_TEXT); $mform->addElement('selectyesno', 'displayleft', get_string('displayleftmenu', 'lesson')); $mform->setHelpButton('displayleft', array('displayleft', get_string('displayleftmenu', 'lesson'), 'lesson')); $mform->setDefault('displayleft', 0); $options = array(); for ($i = 100; $i >= 0; $i--) { $options[$i] = $i . '%'; } $mform->addElement('select', 'displayleftif', get_string('displayleftif', 'lesson'), $options); $mform->setDefault('displayleftif', 0); $mform->addElement('selectyesno', 'progressbar', get_string('progressbar', 'lesson')); $mform->setHelpButton('progressbar', array('progressbar', get_string('progressbar', 'lesson'), 'lesson')); $mform->setDefault('progressbar', 0); //------------------------------------------------------------------------------- $mform->addElement('header', '', get_string('accesscontrol', 'lesson')); $mform->addElement('selectyesno', 'usepassword', get_string('usepassword', 'lesson')); $mform->setHelpButton('usepassword', array('usepassword', get_string('usepassword', 'lesson'), 'lesson')); $mform->setDefault('usepassword', 0); $mform->addElement('text', 'password', get_string('password', 'lesson')); $mform->setHelpButton('password', array('password', get_string('password', 'lesson'), 'lesson')); $mform->setDefault('password', ''); //never displayed converted to md5 $mform->setType('password', PARAM_RAW); $mform->addElement('date_time_selector', 'available', get_string('available', 'lesson')); $mform->setDefault('available', 0); $mform->addElement('date_time_selector', 'deadline', get_string('deadline', 'lesson')); $mform->setDefault('deadline', 0); //------------------------------------------------------------------------------- $mform->addElement('header', '', get_string('dependencyon', 'lesson')); $options = array(0 => get_string('none')); if ($lessons = get_all_instances_in_course('lesson', $COURSE)) { foreach ($lessons as $lesson) { if ($lesson->id != $this->_instance) { $options[$lesson->id] = format_string($lesson->name, true); } } } $mform->addElement('select', 'dependency', get_string('dependencyon', 'lesson'), $options); $mform->setHelpButton('dependency', array('dependency', get_string('dependency', 'lesson'), 'lesson')); $mform->setDefault('dependency', 0); $mform->addElement('text', 'timespent', get_string('timespentminutes', 'lesson')); $mform->setDefault('timespent', 0); $mform->setType('timespent', PARAM_INT); $mform->addElement('checkbox', 'completed', get_string('completed', 'lesson')); $mform->setDefault('completed', 0); $mform->addElement('text', 'gradebetterthan', get_string('gradebetterthan', 'lesson')); $mform->setDefault('gradebetterthan', 0); $mform->setType('gradebetterthan', PARAM_INT); //------------------------------------------------------------------------------- $mform->addElement('header', '', get_string('mediafile', 'lesson')); $mform->addElement('choosecoursefile', 'mediafile', get_string('mediafile', 'lesson'), array('courseid' => $COURSE->id)); $mform->setHelpButton('mediafile', array('mediafile', get_string('mediafile', 'lesson'), 'lesson')); $mform->setDefault('mediafile', ''); $mform->setType('mediafile', PARAM_RAW); $mform->addElement('selectyesno', 'mediaclose', get_string('mediaclose', 'lesson')); $mform->setDefault('mediaclose', 0); $mform->addElement('text', 'mediaheight', get_string('mediaheight', 'lesson')); $mform->setHelpButton('mediaheight', array('mediaheight', get_string('mediaheight', 'lesson'), 'lesson')); $mform->setDefault('mediaheight', 100); $mform->addRule('mediaheight', null, 'required', null, 'client'); $mform->addRule('mediaheight', null, 'numeric', null, 'client'); $mform->setType('mediaheight', PARAM_INT); $mform->addElement('text', 'mediawidth', get_string('mediawidth', 'lesson')); $mform->setHelpButton('mediawidth', array('mediawidth', get_string('mediawidth', 'lesson'), 'lesson')); $mform->setDefault('mediawidth', 650); $mform->addRule('mediawidth', null, 'required', null, 'client'); $mform->addRule('mediawidth', null, 'numeric', null, 'client'); $mform->setType('mediawidth', PARAM_INT); //------------------------------------------------------------------------------- $mform->addElement('header', '', get_string('other', 'lesson')); // get the modules if ($mods = get_course_mods($COURSE->id)) { $modinstances = array(); foreach ($mods as $mod) { // get the module name and then store it in a new array if ($module = get_coursemodule_from_instance($mod->modname, $mod->instance, $COURSE->id)) { if (isset($this->_cm->id) and $this->_cm->id != $mod->id) { $modinstances[$mod->id] = $mod->modname . ' - ' . $module->name; } } } asort($modinstances); // sort by module name $modinstances = array(0 => get_string('none')) + $modinstances; $mform->addElement('select', 'activitylink', get_string('activitylink', 'lesson'), $modinstances); $mform->setHelpButton('activitylink', array('activitylink', get_string('activitylink', 'lesson'), 'lesson')); $mform->setDefault('activitylink', 0); } $mform->addElement('text', 'maxhighscores', get_string('maxhighscores', 'lesson')); $mform->setHelpButton('maxhighscores', array('maxhighscores', get_string('maxhighscores', 'lesson'), 'lesson')); $mform->setDefault('maxhighscores', 10); $mform->addRule('maxhighscores', null, 'required', null, 'client'); $mform->addRule('maxhighscores', null, 'numeric', null, 'client'); $mform->setType('maxhighscores', PARAM_INT); $mform->addElement('selectyesno', 'lessondefault', get_string('lessondefault', 'lesson')); $mform->setHelpButton('lessondefault', array('lessondefault', get_string('lessondefault', 'lesson'), 'lesson')); $mform->setDefault('lessondefault', 0); //------------------------------------------------------------------------------- $this->standard_coursemodule_elements(false); //------------------------------------------------------------------------------- // buttons $this->add_action_buttons(); }
public function test_cm_info_properties() { global $DB, $CFG; $this->resetAfterTest(); $oldcfgenableavailability = $CFG->enableavailability; $oldcfgenablecompletion = $CFG->enablecompletion; set_config('enableavailability', 1); set_config('enablecompletion', 1); $this->setAdminUser(); // Generate the course and pre-requisite module. $course = $this->getDataGenerator()->create_course(array('format' => 'topics', 'numsections' => 3, 'enablecompletion' => 1, 'groupmode' => SEPARATEGROUPS, 'forcegroupmode' => 0), array('createsections' => true)); $coursecontext = context_course::instance($course->id); $prereqforum = $this->getDataGenerator()->create_module('forum', array('course' => $course->id), array('completion' => 1)); // Generate the module and add availability conditions. $conditionscompletion = array($prereqforum->cmid => COMPLETION_COMPLETE); $conditionsgrade = array(666 => (object) array('min' => 0.4, 'max' => null, 'name' => '!missing')); $conditionsfield = array('email' => (object) array('fieldname' => 'email', 'operator' => 'contains', 'value' => 'test')); $assign = $this->getDataGenerator()->create_module('assign', array('course' => $course->id), array('idnumber' => 123, 'groupmode' => VISIBLEGROUPS, 'availablefrom' => time() + 3600, 'availableuntil' => time() + 5 * 3600)); $ci = new condition_info((object) array('id' => $assign->cmid), CONDITION_MISSING_EVERYTHING); foreach ($conditionscompletion as $cmid => $requiredcompletion) { $ci->add_completion_condition($cmid, $requiredcompletion); } foreach ($conditionsgrade as $gradeid => $conditiongrade) { $ci->add_grade_condition($gradeid, $conditiongrade->min, $conditiongrade->max, true); } foreach ($conditionsfield as $conditionfield) { $ci->add_user_field_condition($conditionfield->fieldname, $conditionfield->operator, $conditionfield->value); } // Direct access to condition_info functions does not reset course cache, do it manually. rebuild_course_cache($course->id, true); // Retrieve all related records from DB. $assigndb = $DB->get_record('assign', array('id' => $assign->id)); $moduletypedb = $DB->get_record('modules', array('name' => 'assign')); $moduledb = $DB->get_record('course_modules', array('module' => $moduletypedb->id, 'instance' => $assign->id)); $sectiondb = $DB->get_record('course_sections', array('id' => $moduledb->section)); $modnamessingular = get_module_types_names(false); $modnamesplural = get_module_types_names(true); // Create and enrol a student. $studentrole = $DB->get_record('role', array('shortname' => 'student'), '*', MUST_EXIST); $student = $this->getDataGenerator()->create_user(); role_assign($studentrole->id, $student->id, $coursecontext); $enrolplugin = enrol_get_plugin('manual'); $enrolinstance = $DB->get_record('enrol', array('courseid' => $course->id, 'enrol' => 'manual')); $enrolplugin->enrol_user($enrolinstance, $student->id); $this->setUser($student); // Emulate data used in building course cache to receive the same instance of cached_cm_info as was used in building modinfo. $rawmods = get_course_mods($course->id); $cachedcminfo = assign_get_coursemodule_info($rawmods[$moduledb->id]); // Get modinfo. $modinfo = get_fast_modinfo($course->id); $cm = $modinfo->instances['assign'][$assign->id]; $this->assertEquals($moduledb->id, $cm->id); $this->assertEquals($assigndb->id, $cm->instance); $this->assertEquals($moduledb->course, $cm->course); $this->assertEquals($moduledb->idnumber, $cm->idnumber); $this->assertEquals($moduledb->added, $cm->added); $this->assertEquals($moduledb->visible, $cm->visible); $this->assertEquals($moduledb->visibleold, $cm->visibleold); $this->assertEquals($moduledb->groupmode, $cm->groupmode); $this->assertEquals(VISIBLEGROUPS, $cm->groupmode); $this->assertEquals($moduledb->groupingid, $cm->groupingid); $this->assertEquals($moduledb->groupmembersonly, $cm->groupmembersonly); $this->assertEquals($course->groupmodeforce, $cm->coursegroupmodeforce); $this->assertEquals($course->groupmode, $cm->coursegroupmode); $this->assertEquals(SEPARATEGROUPS, $cm->coursegroupmode); $this->assertEquals($course->groupmodeforce ? $course->groupmode : $moduledb->groupmode, $cm->effectivegroupmode); // (since mod_assign supports groups). $this->assertEquals(VISIBLEGROUPS, $cm->effectivegroupmode); $this->assertEquals($moduledb->indent, $cm->indent); $this->assertEquals($moduledb->completion, $cm->completion); $this->assertEquals($moduledb->completiongradeitemnumber, $cm->completiongradeitemnumber); $this->assertEquals($moduledb->completionview, $cm->completionview); $this->assertEquals($moduledb->completionexpected, $cm->completionexpected); $this->assertEquals($moduledb->availablefrom, $cm->availablefrom); $this->assertEquals($moduledb->availableuntil, $cm->availableuntil); $this->assertEquals($moduledb->showavailability, $cm->showavailability); $this->assertEquals($moduledb->showdescription, $cm->showdescription); $this->assertEquals(null, $cm->extra); // Deprecated field. Used in module types that don't return cached_cm_info. $this->assertEquals($cachedcminfo->icon, $cm->icon); $this->assertEquals($cachedcminfo->iconcomponent, $cm->iconcomponent); $this->assertEquals('assign', $cm->modname); $this->assertEquals($moduledb->module, $cm->module); $this->assertEquals($cachedcminfo->name, $cm->name); $this->assertEquals($sectiondb->section, $cm->sectionnum); $this->assertEquals($moduledb->section, $cm->section); $this->assertEquals($conditionscompletion, $cm->conditionscompletion); $this->assertEquals($conditionsgrade, $cm->conditionsgrade); $this->assertEquals($conditionsfield, $cm->conditionsfield); $this->assertEquals(context_module::instance($moduledb->id), $cm->context); $this->assertEquals($modnamessingular['assign'], $cm->modfullname); $this->assertEquals($modnamesplural['assign'], $cm->modplural); $this->assertEquals(new moodle_url('/mod/assign/view.php', array('id' => $moduledb->id)), $cm->url); $this->assertEquals($cachedcminfo->customdata, $cm->customdata); // Dynamic fields, just test that they can be retrieved (must be carefully tested in each activity type). $this->assertNotEmpty($cm->availableinfo); // Lists all unmet availability conditions. $this->assertEquals(0, $cm->uservisible); $this->assertEquals('', $cm->extraclasses); $this->assertEquals('', $cm->onclick); $this->assertEquals(null, $cm->afterlink); $this->assertEquals(null, $cm->afterediticons); $this->assertEquals('', $cm->content); // Attempt to access and set non-existing field. $this->assertTrue(empty($modinfo->somefield)); $this->assertFalse(isset($modinfo->somefield)); $cm->somefield; $this->assertDebuggingCalled(); $cm->somefield = 'Some value'; $this->assertDebuggingCalled(); $this->assertEmpty($cm->somefield); $this->assertDebuggingCalled(); // Attempt to overwrite an existing field. $prevvalue = $cm->name; $this->assertNotEmpty($cm->name); $this->assertFalse(empty($cm->name)); $this->assertTrue(isset($cm->name)); $cm->name = 'Illegal overwriting'; $this->assertDebuggingCalled(); $this->assertEquals($prevvalue, $cm->name); $this->assertDebuggingNotCalled(); // Restore settings. set_config('enableavailability', $oldcfgenableavailability); set_config('enablecompletion', $oldcfgenablecompletion); }
/** * Previous incarnations of this plugin did not store the turnitin course id so we have to get this using the assignment id, * If that wasn't linked with turnitin then we have to check all the modules on this course. */ public function get_previous_course_id($cmid, $courseid) { global $DB; $tiicourseid = 0; if ($tiiassignment = $DB->get_record('plagiarism_turnitin_config', array('cm' => $cmid, 'name' => 'turnitin_assignid'))) { $tiicourseid = $this->get_course_id_from_assignment_id($tiiassignment->value); } else { $coursemods = get_course_mods($courseid); foreach ($coursemods as $coursemod) { if ($coursemod->modname != 'turnitintooltwo') { if ($tiiassignment = $DB->get_record('plagiarism_turnitin_config', array('cm' => $coursemod->id, 'name' => 'turnitin_assignid'))) { $tiicourseid = $this->get_course_id_from_assignment_id($tiiassignment->value); } } } } return $tiicourseid > 0 ? $tiicourseid : false; }
/** * Returns list of currently used mods with legacy grading in course * @param $courseid int * @return array of modname=>modulenamestring mods with legacy grading */ function grade_get_legacy_modules($courseid) { global $CFG; if (!($mods = get_course_mods($courseid))) { return array(); } $legacy = array(); foreach ($mods as $mod) { $modname = $mod->modname; $modlib = "{$CFG->dirroot}/mod/{$modname}/lib.php"; if (!$modlib) { continue; } include_once $modlib; $gradefunc = $modname . '_grades'; if (!function_exists($gradefunc)) { continue; } $legacy[$modname] = get_string('modulename', $modname); } return $legacy; }
/** * This function returns the nummber of activities * using scaleid in a courseid * * @param int $courseid ? * @param int $scaleid ? * @return int * @todo Finish documenting this function */ function course_scale_used($courseid, $scaleid) { global $CFG; $return = 0; if (!empty($scaleid)) { if ($cms = get_course_mods($courseid)) { foreach ($cms as $cm) { //Check cm->name/lib.php exists if (file_exists($CFG->dirroot . '/mod/' . $cm->modname . '/lib.php')) { include_once $CFG->dirroot . '/mod/' . $cm->modname . '/lib.php'; $function_name = $cm->modname . '_scale_used'; if (function_exists($function_name)) { if ($function_name($cm->instance, $scaleid)) { $return++; } } } } } // check if any course grade item makes use of the scale $return += count_records('grade_items', 'courseid', $courseid, 'scaleid', $scaleid); } return $return; }
/** * For a given course, returns an array of course activity objects * Each item in the array contains he following properties: */ function get_array_of_activities($courseid) { // cm - course module id // mod - name of the module (eg forum) // section - the number of the section (eg week or topic) // name - the name of the instance // visible - is the instance visible or not // groupingid - grouping id // groupmembersonly - is this instance visible to group members only // extra - contains extra string to include in any link global $CFG, $DB; if (!empty($CFG->enableavailability)) { require_once $CFG->libdir . '/conditionlib.php'; } $course = $DB->get_record('course', array('id' => $courseid)); if (empty($course)) { throw new moodle_exception('courseidnotfound'); } $mod = array(); $rawmods = get_course_mods($courseid); if (empty($rawmods)) { return $mod; // always return array } if ($sections = $DB->get_records("course_sections", array("course" => $courseid), "section ASC")) { foreach ($sections as $section) { if (!empty($section->sequence)) { $sequence = explode(",", $section->sequence); foreach ($sequence as $seq) { if (empty($rawmods[$seq])) { continue; } $mod[$seq]->id = $rawmods[$seq]->instance; $mod[$seq]->cm = $rawmods[$seq]->id; $mod[$seq]->mod = $rawmods[$seq]->modname; $mod[$seq]->section = $section->section; $mod[$seq]->idnumber = $rawmods[$seq]->idnumber; $mod[$seq]->visible = $rawmods[$seq]->visible; $mod[$seq]->groupmode = $rawmods[$seq]->groupmode; $mod[$seq]->groupingid = $rawmods[$seq]->groupingid; $mod[$seq]->groupmembersonly = $rawmods[$seq]->groupmembersonly; $mod[$seq]->indent = $rawmods[$seq]->indent; $mod[$seq]->completion = $rawmods[$seq]->completion; $mod[$seq]->extra = ""; if (!empty($CFG->enableavailability)) { condition_info::fill_availability_conditions($rawmods[$seq]); $mod[$seq]->availablefrom = $rawmods[$seq]->availablefrom; $mod[$seq]->availableuntil = $rawmods[$seq]->availableuntil; $mod[$seq]->showavailability = $rawmods[$seq]->showavailability; $mod[$seq]->conditionscompletion = $rawmods[$seq]->conditionscompletion; $mod[$seq]->conditionsgrade = $rawmods[$seq]->conditionsgrade; } $modname = $mod[$seq]->mod; $functionname = $modname . "_get_coursemodule_info"; if (!file_exists("{$CFG->dirroot}/mod/{$modname}/lib.php")) { continue; } include_once "{$CFG->dirroot}/mod/{$modname}/lib.php"; if (function_exists($functionname)) { if ($info = $functionname($rawmods[$seq])) { if (!empty($info->extra)) { $mod[$seq]->extra = $info->extra; } if (!empty($info->icon)) { $mod[$seq]->icon = $info->icon; } if (!empty($info->iconcomponent)) { $mod[$seq]->iconcomponent = $info->iconcomponent; } if (!empty($info->name)) { $mod[$seq]->name = $info->name; } } } if (!isset($mod[$seq]->name)) { $mod[$seq]->name = $DB->get_field($rawmods[$seq]->modname, "name", array("id" => $rawmods[$seq]->instance)); } } } } } return $mod; }
protected function specific_definition($mform) { global $DB, $CFG, $PAGE; $BLOCKNAME = "block_semantic_web"; $context = get_context_instance(CONTEXT_COURSE, $this->page->course->id); //$context = get_context_instance(CONTEXT_MODULE, $PAGE->course->id); $jsmodule = array('name' => 'block_semantic_web', 'fullpath' => '/blocks/semantic_web/semantic_web.js', 'requires' => array('node', 'event', 'io')); $PAGE->requires->js_init_call('M.block_semantic_web.init_configblock_actions', null, false, $jsmodule); // set the wwwroot in a hidden field to get it's value via javascript //$mform->addElement("hidden", "wwwroot", $CFG->wwwroot); //set the current url for redirect after database actions $mform->addElement("hidden", "currenturl", ""); // set the bundle connection id $mform->addElement("hidden", "bcid", ""); // set the courseida to current course $mform->addElement("hidden", "courseid", $this->page->course->id); // set header of specific configuration $mform->addElement('header', 'config_semantic_web', get_string("semanticweb_settings", $BLOCKNAME)); // set a select element to add a new course $allCourses = get_courses($categoryid = "all", $sort = "c.fullname ASC", $fields = "c.id, c.fullname"); // build a table for semantic web prefs $webPrefs = $DB->get_record("dasis_semantic_web_prefs", array("block_id" => required_param("bui_editid", PARAM_NUMBER))); $mform->addElement("html", "<table><tr><td>"); // set the depth of semantic web (how many connections should be shown?) $mform->addElement("html", get_string('depth', $BLOCKNAME)); $mform->addElement("html", "<select name=\"depth\" id=\"id_depth\">"); for ($i = 1; $i <= 5; $i++) { if ($i == $webPrefs->depth) { $mform->addElement("html", "<option value=\"{$i}\" selected=\"selected\">{$i}</option>"); } else { $mform->addElement("html", "<option value=\"{$i}\">{$i}</option>"); } } $mform->addElement("html", "</select>"); $mform->addElement("html", "</td><td>"); // switch adaption on/off $mform->addElement("html", get_string("pluginname", "block_case_repository")); if (!$webPrefs->adaption) { $adaptionStatus = ""; } else { $adaptionStatus = "checked"; } $mform->addElement("html", " <input name=\"adaption_check\" value=\"1\" type=\"checkbox\" id=\"id_adaption_checkbox\" {$adaptionStatus}/>"); $mform->addElement("html", "</td><td>"); // switch case collection on/off $mform->addElement("html", get_string("case_collection", "block_semantic_web")); if (!$webPrefs->case_collection) { $collectStatus = ""; } else { $collectStatus = "checked"; } $mform->addElement("html", " <input name=\"case_collection_check\" value=\"1\" type=\"checkbox\" id=\"id_case_collection_checkbox\" {$collectStatus}/>"); $mform->addElement("html", "</td><td>"); // switch web animation on/off $mform->addElement("html", get_string("web_animation", "block_semantic_web")); if (!$webPrefs->web_animation) { $collectStatus = ""; } else { $collectStatus = "checked"; } $mform->addElement("html", " <input name=\"web_animation_check\" value=\"1\" type=\"checkbox\" id=\"id_web_animation_checkbox\" {$collectStatus}/>"); $mform->addElement("html", "</td></tr></table>"); /** * bundle configuration */ $mform->addElement('header', 'config_semantic_web', get_string("bundle_settings", $BLOCKNAME)); //header $mform->addElement("hidden", "enlarge_string", get_string("click_enlarge", $BLOCKNAME)); $mform->addElement("hidden", "hide_string", get_string("click_hide", $BLOCKNAME)); //get all bundles $allBundles = $DB->get_records("dasis_bundles"); //get current bundle connections $bundleConnections = $DB->get_records("dasis_bundle_connections", array("course_id" => $this->page->course->id)); //put an array of connections to bundleConnections foreach ($allBundles as $oneBundle) { $cob = $DB->get_records("dasis_bundle_connections", array("bundle_id" => $oneBundle->id)); // connections of bundle foreach ($cob as $oneCob) { $allBundles[$oneBundle->id]->connections[] = $allCourses[$oneCob->course_id]->fullname; } } $mform->addElement("html", "<table>"); //beginn table // list of bundles containing the course $mform->addElement("html", "<tr>"); //begin row $mform->addElement("html", "<td style=\"vertical-align:top;\">"); //begin cell $mform->addElement("html", get_string("bundles_containing_the_course", $BLOCKNAME)); $mform->addElement("html", "</td>"); //close cell $mform->addElement("html", "<td>"); //beginn cell $mform->addElement("html", "<ul class=\"connectionlist\">"); //beginn unordered list //list of all bundles containing the course foreach ($bundleConnections as $connection) { $mform->addElement("html", "<li style=\"cursor:s-resize\" id=\"" . $connection->id . "\" title=\"" . get_string("click_enlarge", $BLOCKNAME) . "\"><B>" . $allBundles[$connection->bundle_id]->name . "</B> "); $mform->addElement("html", "<a href=# name=\"" . $connection->id . "\">[" . get_string("remove", $BLOCKNAME) . "]</a>"); $mform->addElement("html", "<div id=\"id_description_" . $connection->id . "\" style=\"display:none;\"><I>" . get_string("description", $BLOCKNAME) . "</I><br />" . $allBundles[$connection->bundle_id]->description . "</div>"); $mform->addElement("html", "<div id=\"id_contained_courses_" . $connection->id . "\" style=\"display:none;\"><I>" . get_string("contained_courses", $BLOCKNAME) . "</I><ul class=\"bundleconnections\">"); foreach ($allBundles[$connection->bundle_id]->connections as $courseconnection) { $mform->addElement("html", "<li>" . $courseconnection . "</li>"); } $mform->addElement("html", "</ul></div>"); } $mform->addElement("html", "</ul>"); //close unordered list $mform->addElement("html", "</td>"); //close cell $mform->addElement("html", "</tr>"); //close row // select element to add course to bundle $mform->addElement("html", "<tr>"); //begin row $mform->addElement("html", "<td>"); //begin cell $mform->addElement("html", get_string("add_course_to_bundle", $BLOCKNAME)); $mform->addElement("html", "</td>"); //close cell $mform->addElement("html", "<td>"); //beginn cell $mform->addElement("html", "<select id=\"id_addToBundle\" name=\"addToBundle\">"); //beginn select element $mform->addElement("html", "<option value=\"0\" selected=\"selected\">" . get_string("pleaseselect", $BLOCKNAME) . "</option>"); //set default option //list of all bundles foreach ($allBundles as $bundle) { if (!$DB->record_exists("dasis_bundle_connections", array("bundle_id" => $bundle->id, "course_id" => $this->page->course->id))) { $mform->addElement("html", "<option value=\"{$bundle->id}\">{$bundle->name}</option>"); //set bundles as options } } $mform->addElement("html", "<option value=\"-1\">" . get_string("newbundle", $BLOCKNAME) . "</option>"); $mform->addElement("html", "</select>"); //close select element $mform->addElement("html", "</td>"); //close cell $mform->addElement("html", "</tr>"); //close row $mform->addElement("html", "</table>"); //close table // create new bundle $bundleId = optional_param("bundleId", 0, PARAM_INT); $mform->addElement("hidden", "bundleId", $bundleId); if ($bundleId) { $currentBundle = $DB->get_record("dasis_bundles", array("id" => $bundleId)); } $mform->addElement("html", "<table id=\"id_new_bundle_table\">"); $mform->addElement("html", "<tr>"); $mform->addElement("html", "<td>"); $mform->addElement("html", get_string("name_of_bundle", $BLOCKNAME)); $mform->addElement("html", "</td>"); $mform->addElement("html", "<td>"); if (!$bundleId) { $mform->addElement("html", "<input type=\"text\" name=\"name_of_bundle\" id=\"id_name_of_bundle\" placeholder=\"" . get_string("name_of_bundle", $BLOCKNAME) . "\" size=\"50\"/>"); } else { $mform->addElement("html", "<input type=\"text\" name=\"name_of_bundle\" id=\"id_name_of_bundle\" size=\"50\" value=\"" . $currentBundle->name . "\" placeholder=\"" . get_string("name_of_bundle", $BLOCKNAME) . "\"/>"); } $mform->addElement("html", "</td>"); $mform->addElement("html", "</tr>"); $mform->addElement("html", "<tr>"); $mform->addElement("html", "<td style=\"vertical-align:top;\">"); $mform->addElement("html", get_string("description", $BLOCKNAME)); $mform->addElement("html", "</td>"); $mform->addElement("html", "<td>"); if (!$bundleId) { $mform->addElement("html", "<textarea name=\"description_of_bundle\" id=\"id_description_of_bundle\" placeholder=\"" . get_string("description", $BLOCKNAME) . "\" rows=\"5\" cols=\"50\">" . $BLOCKNAME . "</textarea>"); } else { $mform->addElement("html", "<textarea name=\"description_of_bundle\" id=\"id_description_of_bundle\" rows=\"5\" cols=\"50\" placeholder=\"" . get_string("description", $BLOCKNAME) . "\">" . $currentBundle->description . "</textarea>"); } $mform->addElement("html", "</td>"); $mform->addElement("html", "</tr>"); $mform->addElement("html", "<tr><td>"); $mform->addElement("html", "<input type=\"button\" id=\"id_bundle_submit\" value=\"" . get_string("create_bundle", $BLOCKNAME) . "\"/>"); $mform->addElement("html", "</td></tr>"); $mform->addElement("html", "<tr>"); $mform->addElement("html", "<td style=\"vertical-align:top;\">"); $mform->addElement("html", get_string("contained_courses", $BLOCKNAME)); $mform->addElement("html", "</td>"); $mform->addElement("html", "<td>"); $mform->addElement("html", "<ul class=\"connectionlist\">"); //list of contained courses $connectionsOfBundle = $DB->get_records("dasis_bundle_connections", array("bundle_id" => $bundleId)); foreach ($connectionsOfBundle as $connection) { $mform->addElement("html", "<li>" . $allCourses[$connection->course_id]->fullname . " "); $mform->addElement('html', "<a href=# name=\"" . $connection->id . "\">[" . get_string("remove", $BLOCKNAME) . "]</a></li>"); } $mform->addElement("html", "</ul>"); $mform->addElement("html", "</td>"); $mform->addElement("html", "</tr>"); $mform->addElement("html", "<tr>"); $mform->addElement("html", "<td>"); $mform->addElement("html", get_string("add_course_to_this_bundle", $BLOCKNAME)); $mform->addElement("html", "</td>"); $mform->addElement("html", "<td>"); $mform->addElement("html", "<select id=\"id_addCourse\" name=\"addCourse\">"); $mform->addElement("html", "<option value=\"0\" selected=\"selected\">" . get_string("pleaseselect", $BLOCKNAME) . "</option>"); foreach ($allCourses as $course) { if ($course->id != 1 && $course->id != $this->page->course->id && !$DB->record_exists("dasis_bundle_connections", array("bundle_id" => $bundle->id, "course_id" => $course->id))) { $mform->addElement("html", "<option value=\"{$course->id}\">{$course->fullname}</option>"); } } $mform->addElement("html", "</select>"); $mform->addElement("html", "</td>"); $mform->addElement("html", "</tr>"); $mform->addElement("html", "</table>"); /** * bundle overview and delete */ $mform->addElement("html", "<br /><B id=\"id_toggle_bundle_management\" style=\"cursor:s-resize\" title=\"" . get_string("click_enlarge", $BLOCKNAME) . "\">" . get_string("bundle_overview", $BLOCKNAME) . "</B>"); $mform->addElement("html", "<table id=\"id_bundle_management\" style=\"display:none;\">"); $mform->addElement("html", "<tr><th>" . get_string("bundle", $BLOCKNAME) . "</th><th>" . get_string("description", $BLOCKNAME) . "</th><th>" . get_string("contained_courses", $BLOCKNAME) . "</th>"); if (has_capability("block/semantic_web:deletebundle", $context)) { // only people with permissions can remove bundles from database $mform->addElement("html", "<th></th>"); } $mform->addElement("html", "</tr>"); foreach ($allBundles as $oneBundle) { $mform->addElement("html", "<tr valign=\"top\"><td>" . $oneBundle->name . "</td><td>" . $oneBundle->description . "</td><td>"); $mform->addElement("html", "<ul>"); foreach ($oneBundle->connections as $courseconnection) { $mform->addElement("html", "<li>" . $courseconnection . "</li>"); } $mform->addElement("html", "</ul>"); $mform->addElement("html", "</td>"); if (has_capability("block/semantic_web:deletebundle", $context)) { $mform->addElement("html", "<td><a href=# name=\"" . $oneBundle->id . "\">[" . get_string("remove", $BLOCKNAME) . "]</a></td>"); } $mform->addElement("html", "</tr>"); } $mform->addElement("html", "</table>"); /** * learning path configuration */ $mform->addElement('header', 'config_semantic_web', get_string("learning_path_settings", $BLOCKNAME)); // needed parameters for this section $lpbid = optional_param("lpbid", 0, PARAM_INT); $mform->addElement("hidden", "lpbid", $lpbid); $pathId = optional_param("pathId", 0, PARAM_INT); $mform->addElement("hidden", "pathId", $pathId); // Ein Array mit den Kurs-Modulen als Objekte erstellen $modules = get_course_mods($this->page->course->id); // Zu diesem Array werden noch weitere Kurs-Module aus anderen Kursen im Bündel hinzugefügt $bundleconnections = $DB->get_records("dasis_bundle_connections", array("course_id" => $this->page->course->id)); foreach ($bundleconnections as $bundleconnection) { $bccourses = $DB->get_records("dasis_bundle_connections", array("bundle_id" => $bundleconnection->bundle_id)); foreach ($bccourses as $bccourse) { $newmods = get_course_mods($bccourse->course_id); $modules = array_merge($modules, $newmods); } } // Ein Array erstellen mit den Informationen: course module id, name $mods = array(); foreach ($modules as $module) { $mods[$module->id] = get_coursemodule_from_id($module->modname, $module->id, $module->course); $mods[$module->id]->coursename = $DB->get_field("course", "fullname", array("id" => $module->course)); } $mform->addElement("html", "<table>"); // select a bundle to view or edit paths for $mform->addElement("html", "<tr>"); $mform->addElement("html", "<td>" . get_string("bundle", $BLOCKNAME) . "</td>"); $mform->addElement("html", "<td><select id=\"id_learning_path_bundle_select\">"); $mform->addElement("html", "<option value=\"0\">" . get_string("pleaseselect", $BLOCKNAME) . "</option>"); foreach ($allBundles as $oneBundle) { if ($DB->record_exists("dasis_bundle_connections", array("bundle_id" => $oneBundle->id, "course_id" => $this->page->course->id))) { if ($lpbid == $oneBundle->id) { $mform->addElement("html", "<option selected=\"selected\" value=\"" . $oneBundle->id . "\">" . $oneBundle->name . "</option>"); } else { $mform->addElement("html", "<option value=\"" . $oneBundle->id . "\">" . $oneBundle->name . "</option>"); } } } $mform->addElement("html", "</select></td>"); $mform->addElement("html", "</tr>"); // select a learning path or create a new one $mform->addElement("html", "<tr>"); $mform->addElement("html", "<td>" . get_string("learning_pathname", $BLOCKNAME) . "</td>"); $mform->addElement("html", "<td><div id=\"id_div_learning_path_select\"><select name=\"learning_path_select\" id=\"id_learning_path_select\">"); $mform->addElement("html", "<option value=\"0\">" . get_string("pleaseselect", $BLOCKNAME) . "</option>"); foreach ($DB->get_records("dasis_learning_paths", array("bundle_id" => $lpbid)) as $path) { if ($pathId == $path->id) { $mform->addElement("html", "<option selected=\"selected\" value=\"" . $path->id . "\">" . $path->name . "</option>"); } else { $mform->addElement("html", "<option value=\"" . $path->id . "\">" . $path->name . "</option>"); } } if (has_capability("block/semantic_web:managepaths", $context)) { $mform->addElement("html", "<option value=\"-1\">" . get_string("create_new_path", $BLOCKNAME) . "</option>"); } $mform->addElement("html", "</select>"); if (has_capability("block/semantic_web:managepaths", $context)) { $mform->addElement("html", "<a id=\"id_delete_path\" href=\"#\"> [" . get_string("remove", $BLOCKNAME) . "]</a>"); } $mform->addElement("html", "</div>"); $newPathDiv = "<div id=\"id_new_path\" style=\"display:none;\"><input type=\"text\" name=\"path_name\" id=\"id_path_name\" placeholder=\"" . get_string("path_name", $BLOCKNAME) . "\"/>"; $colorPicker = "<select id=\"id_color_picker\" name=\"pathColor\">"; $colorPicker .= "<option value=\"none\">" . get_string("color", $BLOCKNAME) . "</option>"; $colorPicker .= "<option value=\"red\" style=\"background-color:red;\">" . get_string("red", $BLOCKNAME) . "</option>"; $colorPicker .= "<option value=\"orange\" style=\"background-color:orange;\">" . get_string("orange", $BLOCKNAME) . "</option>"; $colorPicker .= "<option value=\"yellow\" style=\"background-color:yellow;\">" . get_string("yellow", $BLOCKNAME) . "</option>"; $colorPicker .= "<option value=\"green\" style=\"background-color:green;\">" . get_string("green", $BLOCKNAME) . "</option>"; $colorPicker .= "<option value=\"blue\" style=\"background-color:blue;\">" . get_string("blue", $BLOCKNAME) . "</option>"; $colorPicker .= "<option value=\"purple\" style=\"background-color:purple;\">" . get_string("purple", $BLOCKNAME) . "</option>"; $colorPicker .= "</select>"; $newPathDiv .= $colorPicker; $newPathDiv .= "<input type=\"button\" id=\"id_button_new_path\" name=\"button_new_path\" value=\"" . get_string("create_new_path", $BLOCKNAME) . "\"/></div>"; $mform->addElement("html", $newPathDiv); $mform->addElement("html", "</tr>"); $mform->addElement("html", "<tr style=\"vertical-align:top;\">"); $mform->addElement("html", "<td>" . get_string("learning_path", $BLOCKNAME) . "</td>"); $mform->addElement("html", "<td>"); $pathArray = unserialize($DB->get_field("dasis_learning_paths", "path", array("id" => $pathId))); if (count($pathArray) > 1 && is_array($pathArray)) { $mform->addElement("html", "<ol id=\"id_path_node_list\">"); while ($pathNode = current($pathArray)) { $mform->addElement("html", "<li>" . $mods[$pathNode]->coursename . ": " . $mods[$pathNode]->name . " "); if (has_capability("block/semantic_web:managepaths", $context)) { $mform->addElement('html', "<a href=# name=\"" . key($pathArray) . "\">[" . get_string("remove", $BLOCKNAME) . "]</a>"); } $mform->addElement("html", "</li>"); next($pathArray); } $mform->addElement("html", "</ol>"); } if (has_capability("block/semantic_web:managepaths", $context)) { $mform->addElement("html", "<select id=\"id_select_add_pathnode\" name=\"new_path_node\" style=\"width:100%\">"); $mform->addElement("html", "<option value=-1>" . get_string("new_pathnode", $BLOCKNAME) . "</option>"); foreach ($mods as $mod) { $mform->addElement("html", "<option value=\"" . $mod->id . "\">" . $mod->coursename . ": " . $mod->name . "</option>"); } $mform->addElement("html", "</select>"); } $mform->addElement("html", "</td>"); $mform->addElement("html", "</tr>"); $mform->addElement("html", "</table>"); }
function get_array_of_activities1($courseid) { // For a given course, returns an array of course activity objects // Each item in the array contains he following properties: // cm - course module id // mod - name of the module (eg forum) // section - the number of the section (eg week or topic) // name - the name of the instance // visible - is the instance visible or not // groupingid - grouping id // groupmembersonly - is this instance visible to group members only // extra - contains extra string to include in any link global $CFG; $mod = array(); if (!($rawmods = get_course_mods($courseid))) { return $mod; // always return array } if ($sections = get_records("course_sections", "course", $courseid, "section ASC")) { foreach ($sections as $section) { if (!empty($section->sequence)) { $sequence = explode(",", $section->sequence); foreach ($sequence as $seq) { if (empty($rawmods[$seq])) { continue; } $mod[$seq]->id = $rawmods[$seq]->instance; $mod[$seq]->cm = $rawmods[$seq]->id; $mod[$seq]->mod = $rawmods[$seq]->modname; $mod[$seq]->section = $section->section; $mod[$seq]->visible = $rawmods[$seq]->visible; $mod[$seq]->groupmode = $rawmods[$seq]->groupmode; $mod[$seq]->groupingid = $rawmods[$seq]->groupingid; $mod[$seq]->groupmembersonly = $rawmods[$seq]->groupmembersonly; $mod[$seq]->extra = ""; $modname = $mod[$seq]->mod; $functionname = $modname . "_get_coursemodule_info"; if (!file_exists("{$CFG->dirroot}/mod/{$modname}/lib.php")) { continue; } include_once "{$CFG->dirroot}/mod/{$modname}/lib.php"; if (function_exists($functionname)) { if ($info = $functionname($rawmods[$seq])) { if (!empty($info->extra)) { $mod[$seq]->extra = $info->extra; } if (!empty($info->icon)) { $mod[$seq]->icon = $info->icon; } if (!empty($info->name)) { $mod[$seq]->name = urlencode($info->name); } } } if (!isset($mod[$seq]->name)) { $mod[$seq]->name = urlencode(get_field($rawmods[$seq]->modname, "name", "id", $rawmods[$seq]->instance)); } } } } } return $mod; }
/** * This function returns the nummber of activities * using scaleid in a courseid * * @param int $courseid ? * @param int $scaleid ? * @return int * @todo Finish documenting this function */ function course_scale_used($courseid, $scaleid) { global $CFG; $return = 0; if (!empty($scaleid)) { if ($cms = get_course_mods($courseid)) { foreach ($cms as $cm) { //Check cm->name/lib.php exists if (file_exists($CFG->dirroot . '/mod/' . $cm->modname . '/lib.php')) { include_once $CFG->dirroot . '/mod/' . $cm->modname . '/lib.php'; $function_name = $cm->modname . '_scale_used'; if (function_exists($function_name)) { if ($function_name($cm->instance, $scaleid)) { $return++; } } } } } // check if any course grade item makes use of the scale $return += count_records('grade_items', 'courseid', $courseid, 'scaleid', $scaleid); // check if any outcome in the course makes use of the scale $return += count_records_sql("SELECT COUNT(*)\n FROM {$CFG->prefix}grade_outcomes_courses goc,\n {$CFG->prefix}grade_outcomes go\n WHERE go.id = goc.outcomeid\n AND go.scaleid = {$scaleid}\n AND goc.courseid = {$courseid}"); } return $return; }
function blended_crear_nuevo_agrupamiento_por_alumno($course, $name_team, $mem, $id_assignment, $blended, $currentuserid) { global $DB; //Pongo el nombre al agrupamiento el mismo que posee la actividad $modulos = get_course_mods($course->id); foreach ($modulos as $modulo) { if ($modulo->id == $id_assignment) { $curse_modulos = get_coursemodule_from_instance($modulo->modname, $modulo->instance); $name = $curse_modulos->name; } } //Creaci�n del agrupamiento $data = new object(); $data->name = $name; $data->courseid = $course->id; $data->description_editor['text'] = ' '; $data->description_editor['format'] = 1; $groupingid = groups_create_grouping($data); $groupid = blended_add_new_group($course->id, $name_team, $mem, $groupingid); $DB->insert_record_raw('blended_assign_grouping', array('id_assign' => $id_assignment, 'id_grouping' => $groupingid)); //Actualizo las tablas de blended dependiendo del tipo de creación de equipos: if ($blended->teammethod == 1) { blended_update_teams_by_groups($course->id, $id_assignment, 0, $groupid); } else { blended_update_teams_by_groups($course->id, $id_assignment, 1, $groupid, $currentuserid); } }
function schedule_inc_backup_course_configure($course, $starttime = 0) { global $CFG; $status = true; backup_add_to_log($starttime, $course->id, " checking parameters", 'incrementalbackup'); //Check the required variable if (empty($course->id)) { $status = false; } //Get scheduled backup preferences $incremental_config = backup_get_config(); //Checks backup_config pairs exist if ($status) { if (!isset($incremental_config->backup_inc_modules)) { $incremental_config->backup_inc_modules = 1; } if (!isset($incremental_config->backup_inc_withuserdata)) { $incremental_config->backup_inc_withuserdata = 1; } if (!isset($incremental_config->backup_inc_metacourse)) { $incremental_config->backup_inc_metacourse = 1; } if (!isset($incremental_config->backup_inc_users)) { $incremental_config->backup_inc_users = 1; } if (!isset($incremental_config->backup_inc_logs)) { $incremental_config->backup_inc_logs = 0; } if (!isset($incremental_config->backup_inc_userfiles)) { $incremental_config->backup_inc_userfiles = 1; } if (!isset($incremental_config->backup_inc_coursefiles)) { $incremental_config->backup_inc_coursefiles = 1; } if (!isset($incremental_config->backup_inc_sitefiles)) { $incremental_config->backup_inc_sitefiles = 1; } if (!isset($incremental_config->backup_inc_messages)) { $incremental_config->backup_inc_messages = 0; } if (!isset($incremental_config->backup_inc_weekdays)) { $incremental_config->backup_inc_weekdays = "0000000"; } if (!isset($incremental_config->backup_inc_hour)) { $incremental_config->backup_inc_hour = 00; } if (!isset($incremental_config->backup_inc_minute)) { $incremental_config->backup_inc_minute = 00; } if (!isset($incremental_config->backup_inc_destination)) { $incremental_config->backup_inc_destination = ""; } if (!isset($incremental_config->backup_inc_keep)) { $incremental_config->backup_inc_keep = 1; } if (!isset($incremental_config->backup_sche_incrementals)) { $incremental_config->backup_sche_incrementals = 0; } if (!isset($incremental_config->backup_inc_privatedata)) { $incremental_config->backup_inc_privatedata = 0; } } if ($status) { //Checks for the required files/functions to backup every mod //And check if there is data about it //use the configured modules to backup. $count = 0; if (!empty($incremental_config->backup_inc_modules)) { $moduleselect = 'id=' . str_replace(',', ' OR id=', $incremental_config->backup_inc_modules); if ($allmods = get_records_select("modules", $moduleselect)) { foreach ($allmods as $mod) { $modname = $mod->name; $modfile = "{$CFG->dirroot}/mod/{$modname}/backuplib.php"; $modbackup = $modname . "_backup_mods"; $modcheckbackup = $modname . "_check_backup_mods"; if (file_exists($modfile)) { include_once $modfile; if (function_exists($modbackup) and function_exists($modcheckbackup)) { $var = "exists_" . $modname; ${$var} = true; $count++; // PENNY NOTES: I have moved from here to the closing brace inside // by two sets of ifs() // to avoid the backup failing on a non existant backup. // If the file/function/whatever doesn't exist, we don't want to set this // this module in backup preferences at all. //Check data //Check module info $var = "backup_" . $modname; if (!isset(${$var})) { ${$var} = $incremental_config->backup_inc_modules; } //Now stores all the mods preferences into an array into preferences $preferences->mods[$modname]->backup = ${$var}; //Check include user info $var = "backup_user_info_" . $modname; if (!isset(${$var})) { ${$var} = $incremental_config->backup_inc_withuserdata; } //Now stores all the mods preferences into an array into preferences $preferences->mods[$modname]->userinfo = ${$var}; //And the name of the mod $preferences->mods[$modname]->name = $modname; } } } } } // now set instances if ($coursemods = get_course_mods($course->id)) { foreach ($coursemods as $mod) { if (array_key_exists($mod->modname, $preferences->mods)) { // we are to backup this module if (empty($preferences->mods[$mod->modname]->instances)) { $preferences->mods[$mod->modname]->instances = array(); // avoid warnings } $preferences->mods[$mod->modname]->instances[$mod->instance]->backup = $preferences->mods[$mod->modname]->backup; $preferences->mods[$mod->modname]->instances[$mod->instance]->userinfo = $preferences->mods[$mod->modname]->userinfo; // there isn't really a nice way to do this... $preferences->mods[$mod->modname]->instances[$mod->instance]->name = get_field($mod->modname, 'name', 'id', $mod->instance); } } } // finally, clean all the $preferences->mods[] not having instances. Nothing to backup about them if (!empty($preferences->mods)) { foreach ($preferences->mods as $modname => $mod) { if (!isset($mod->instances)) { unset($preferences->mods[$modname]); } } } } //Convert other parameters if ($status) { $preferences->backup_metacourse = $incremental_config->backup_inc_metacourse; $preferences->backup_users = $incremental_config->backup_inc_users; $preferences->backup_logs = $incremental_config->backup_inc_logs; $preferences->backup_user_files = $incremental_config->backup_inc_userfiles; $preferences->backup_course_files = $incremental_config->backup_inc_coursefiles; $preferences->backup_site_files = $incremental_config->backup_inc_sitefiles; $preferences->backup_messages = $incremental_config->backup_inc_messages; $preferences->backup_gradebook_history = 1; $preferences->backup_course = $course->id; $preferences->backup_private_user_data = $incremental_config->backup_inc_privatedata; if (!empty($incremental_config->backup_inc_destination)) { if (!check_dir_exists($incremental_config->backup_inc_destination . '/' . $course->id, true, true)) { error('failed to create backup destination directory'); } else { $preferences->backup_destination = $incremental_config->backup_inc_destination . '/' . $course->id; } } $preferences->backup_keep = $incremental_config->backup_inc_keep; $preferences->backup_sche_incrementals = $incremental_config->backup_sche_incrementals; } //Calculate various backup preferences if ($status) { backup_add_to_log($starttime, $course->id, " calculating backup name", 'incrementalbackup'); //Calculate the backup file name $backup_name = backup_get_zipfile_name($course); //Calculate the string to match the keep preference $keep_name = backup_get_keep_name($course); //Set them $preferences->backup_name = $backup_name; $preferences->keep_name = $keep_name; //Roleasignments $roles = get_records('role', '', '', 'sortorder'); foreach ($roles as $role) { $preferences->backuproleassignments[$role->id] = $role; } //Another Info backup_add_static_preferences($preferences); } //Calculate the backup unique code to allow simultaneus backups (to define //the temp-directory name and records in backup temp tables if ($status) { $backup_unique_code = time(); $preferences->backup_unique_code = $backup_unique_code; } //Calculate necesary info to backup modules if ($status) { backup_add_to_log($starttime, $course->id, " calculating modules data", 'incrementalbackup'); if ($allmods = get_records("modules")) { foreach ($allmods as $mod) { $modname = $mod->name; $modbackup = $modname . "_backup_mods"; //If exists the lib & function $var = "exists_" . $modname; if (isset(${$var}) && ${$var}) { //Add hidden fields $var = "backup_" . $modname; //Only if selected if (${$var} == 1) { $var = "backup_user_info_" . $modname; //Call the check function to show more info $modcheckbackup = $modname . "_check_backup_mods"; backup_add_to_log($starttime, $course->id, " {$modname}", 'incrementalbackup'); $modcheckbackup($course->id, ${$var}, $backup_unique_code); } } } } } //Now calculate the users if ($status) { backup_add_to_log($starttime, $course->id, " calculating users", 'incrementalbackup'); //Decide about include users with messages, based on SITEID if ($preferences->backup_messages && $preferences->backup_course == SITEID) { $include_message_users = true; } else { $include_message_users = false; } //Decide about include users with blogs, based on SITEID if (isset($preferences->backup_blogs) && isset($preferences->backup_course) && $preferences->backup_blogs && $preferences->backup_course == SITEID) { $include_blog_users = true; } else { $include_blog_users = false; } user_check_backup($course->id, $backup_unique_code, $preferences->backup_users, $include_message_users, $include_blog_users); } //Now calculate the logs if ($status) { if ($preferences->backup_logs) { backup_add_to_log($starttime, $course->id, " calculating logs", 'incrementalbackup'); log_check_backup($course->id); } } //Now calculate the userfiles if ($status) { if ($preferences->backup_user_files) { backup_add_to_log($starttime, $course->id, " calculating user files", 'incrementalbackup'); user_files_check_backup($course->id, $preferences->backup_unique_code); } } //Now calculate the coursefiles if ($status) { if ($preferences->backup_course_files) { backup_add_to_log($starttime, $course->id, " calculating course files", 'incrementalbackup'); course_files_check_backup($course->id, $preferences->backup_unique_code); } } //Now calculate the sitefiles if ($status) { if ($preferences->backup_site_files) { backup_add_to_log($starttime, $course->id, " calculating site files", 'incrementalbackup'); site_files_check_backup($course->id, $preferences->backup_unique_code); } } //If everything is ok, return calculated preferences if ($status) { $status = $preferences; } return $status; }
function schedule_backup_course_configure($course, $starttime = 0) { global $CFG; $status = true; schedule_backup_log($starttime, $course->id, " checking parameters"); //Check the required variable if (empty($course->id)) { $status = false; } //Get scheduled backup preferences $backup_config = backup_get_config(); //Checks backup_config pairs exist if ($status) { if (!isset($backup_config->backup_sche_modules)) { $backup_config->backup_sche_modules = 1; } if (!isset($backup_config->backup_sche_withuserdata)) { $backup_config->backup_sche_withuserdata = 1; } if (!isset($backup_config->backup_sche_metacourse)) { $backup_config->backup_sche_metacourse = 1; } if (!isset($backup_config->backup_sche_users)) { $backup_config->backup_sche_users = 1; } if (!isset($backup_config->backup_sche_logs)) { $backup_config->backup_sche_logs = 0; } if (!isset($backup_config->backup_sche_userfiles)) { $backup_config->backup_sche_userfiles = 1; } if (!isset($backup_config->backup_sche_coursefiles)) { $backup_config->backup_sche_coursefiles = 1; } if (!isset($backup_config->backup_sche_messages)) { $backup_config->backup_sche_messages = 0; } if (!isset($backup_config->backup_sche_active)) { $backup_config->backup_sche_active = 0; } if (!isset($backup_config->backup_sche_weekdays)) { $backup_config->backup_sche_weekdays = "0000000"; } if (!isset($backup_config->backup_sche_hour)) { $backup_config->backup_sche_hour = 00; } if (!isset($backup_config->backup_sche_minute)) { $backup_config->backup_sche_minute = 00; } if (!isset($backup_config->backup_sche_destination)) { $backup_config->backup_sche_destination = ""; } if (!isset($backup_config->backup_sche_keep)) { $backup_config->backup_sche_keep = 1; } } if ($status) { //Checks for the required files/functions to backup every mod //And check if there is data about it $count = 0; if ($allmods = get_records("modules")) { foreach ($allmods as $mod) { $modname = $mod->name; $modfile = "{$CFG->dirroot}/mod/{$modname}/backuplib.php"; $modbackup = $modname . "_backup_mods"; $modcheckbackup = $modname . "_check_backup_mods"; if (file_exists($modfile)) { include_once $modfile; if (function_exists($modbackup) and function_exists($modcheckbackup)) { $var = "exists_" . $modname; ${$var} = true; $count++; // PENNY NOTES: I have moved from here to the closing brace inside // by two sets of ifs() // to avoid the backup failing on a non existant backup. // If the file/function/whatever doesn't exist, we don't want to set this // this module in backup preferences at all. //Check data //Check module info $var = "backup_" . $modname; if (!isset(${$var})) { ${$var} = $backup_config->backup_sche_modules; } //Now stores all the mods preferences into an array into preferences $preferences->mods[$modname]->backup = ${$var}; //Check include user info $var = "backup_user_info_" . $modname; if (!isset(${$var})) { ${$var} = $backup_config->backup_sche_withuserdata; } //Now stores all the mods preferences into an array into preferences $preferences->mods[$modname]->userinfo = ${$var}; //And the name of the mod $preferences->mods[$modname]->name = $modname; } } } } // now set instances if ($coursemods = get_course_mods($course->id)) { foreach ($coursemods as $mod) { if (array_key_exists($mod->modname, $preferences->mods)) { // we are to backup this module if (empty($preferences->mods[$mod->modname]->instances)) { $preferences->mods[$mod->modname]->instances = array(); // avoid warnings } $preferences->mods[$mod->modname]->instances[$mod->instance]->backup = $preferences->mods[$mod->modname]->backup; $preferences->mods[$mod->modname]->instances[$mod->instance]->userinfo = $preferences->mods[$mod->modname]->userinfo; // there isn't really a nice way to do this... $preferences->mods[$mod->modname]->instances[$mod->instance]->name = get_field($mod->modname, 'name', 'id', $mod->instance); } } } // finally, clean all the $preferences->mods[] not having instances. Nothing to backup about them foreach ($preferences->mods as $modname => $mod) { if (!isset($mod->instances)) { unset($preferences->mods[$modname]); } } } //Convert other parameters if ($status) { $preferences->backup_metacourse = $backup_config->backup_sche_metacourse; $preferences->backup_users = $backup_config->backup_sche_users; $preferences->backup_logs = $backup_config->backup_sche_logs; $preferences->backup_user_files = $backup_config->backup_sche_userfiles; $preferences->backup_course_files = $backup_config->backup_sche_coursefiles; $preferences->backup_messages = $backup_config->backup_sche_messages; $preferences->backup_course = $course->id; $preferences->backup_destination = $backup_config->backup_sche_destination; $preferences->backup_keep = $backup_config->backup_sche_keep; } //Calculate the backup string if ($status) { schedule_backup_log($starttime, $course->id, " calculating backup name"); //Calculate the backup word //Take off some characters in the filename !! $takeoff = array(" ", ":", "/", "\\", "|"); $backup_word = str_replace($takeoff, "_", moodle_strtolower(get_string("backupfilename"))); //If non-translated, use "backup" if (substr($backup_word, 0, 1) == "[") { $backup_word = "backup"; } //Calculate the date format string $backup_date_format = str_replace(" ", "_", get_string("backupnameformat")); //If non-translated, use "%Y%m%d-%H%M" if (substr($backup_date_format, 0, 1) == "[") { $backup_date_format = "%%Y%%m%%d-%%H%%M"; } //Calculate the shortname $backup_shortname = clean_filename($course->shortname); if (empty($backup_shortname) or $backup_shortname == '_') { $backup_shortname = $course->id; } //Calculate the final backup filename //The backup word $backup_name = $backup_word . "-"; //The shortname $backup_name .= moodle_strtolower($backup_shortname) . "-"; //The date format $backup_name .= userdate(time(), $backup_date_format, 99, false); //The extension $backup_name .= ".zip"; //And finally, clean everything $backup_name = clean_filename($backup_name); //Calculate the string to match the keep preference $keep_name = $backup_word . "-"; //The shortname $keep_name .= moodle_strtolower($backup_shortname) . "-"; //And finally, clean everything $keep_name = clean_filename($keep_name); $preferences->backup_name = $backup_name; $preferences->keep_name = $keep_name; } //Calculate the backup unique code to allow simultaneus backups (to define //the temp-directory name and records in backup temp tables if ($status) { $backup_unique_code = time(); $preferences->backup_unique_code = $backup_unique_code; } //Calculate necesary info to backup modules if ($status) { schedule_backup_log($starttime, $course->id, " calculating modules data"); if ($allmods = get_records("modules")) { foreach ($allmods as $mod) { $modname = $mod->name; $modbackup = $modname . "_backup_mods"; //If exists the lib & function $var = "exists_" . $modname; if (isset(${$var}) && ${$var}) { //Add hidden fields $var = "backup_" . $modname; //Only if selected if (${$var} == 1) { $var = "backup_user_info_" . $modname; //Call the check function to show more info $modcheckbackup = $modname . "_check_backup_mods"; schedule_backup_log($starttime, $course->id, " {$modname}"); $modcheckbackup($course->id, ${$var}, $backup_unique_code); } } } } } //Now calculate the users if ($status) { schedule_backup_log($starttime, $course->id, " calculating users"); //Decide about include users with messages, based on SITEID if ($preferences->backup_messages && $preferences->backup_course == SITEID) { $include_message_users = true; } else { $include_message_users = false; } user_check_backup($course->id, $backup_unique_code, $preferences->backup_users, $include_message_users); } //Now calculate the logs if ($status) { if ($preferences->backup_logs) { schedule_backup_log($starttime, $course->id, " calculating logs"); log_check_backup($course->id); } } //Now calculate the userfiles if ($status) { if ($preferences->backup_user_files) { schedule_backup_log($starttime, $course->id, " calculating user files"); user_files_check_backup($course->id, $preferences->backup_unique_code); } } //Now calculate the coursefiles if ($status) { if ($preferences->backup_course_files) { schedule_backup_log($starttime, $course->id, " calculating course files"); course_files_check_backup($course->id, $preferences->backup_unique_code); } } //If everything is ok, return calculated preferences if ($status) { $status = $preferences; } return $status; }
} else { $courseid = $DB->get_field("course_modules", "course", array("id" => $id)); // In der Modul-Ansicht werden die zugehörigen Metadaten geladen. $metadata = new object(); if (!($metadata = $DB->get_record("dasis_modmeta", array("coursemoduleid" => $id)))) { $metadata = null; } } // Ein Array mit den Kurs-Modulen als Objekte erstellen $modules = get_course_mods($courseid); // Zu diesem Array werden noch weitere Kurs-Module aus anderen Kursen im Bündel hinzugefügt $bundleconnections = $DB->get_records("dasis_bundle_connections", array("course_id" => $courseid)); foreach ($bundleconnections as $bundleconnection) { $bccourses = $DB->get_records("dasis_bundle_connections", array("bundle_id" => $bundleconnection->bundle_id)); foreach ($bccourses as $bccourse) { $newmods = get_course_mods($bccourse->course_id); $modules = array_merge($modules, $newmods); } } // Ein Array erstellen mit den Informationen: course module id, name $mods = array(); foreach ($modules as $module) { $mods[$module->id] = get_coursemodule_from_id($module->modname, $module->id, $module->course); $mods[$module->id]->coursename = $DB->get_field("course", "fullname", array("id" => $module->course)); } // Feststellen, ob man die Rechte besitzt das Kursmodul zu verändern (wichtig, damit nicht jeder die Titel ändern kann) // (Moodle 1.9 = 2007101509; Moodle 2.0 = 2010112400; Moodle 2.1 = 2011070100; Moodle 2.2 = 2011120500; Moodle 2.3 = 2012062500) //$context = get_context_instance(CONTEXT_COURSE, $mods[$id]->course); if ($courseview) { if ($CFG->version >= 2011120500) { $context = context_course::instance($courseid);
function definition() { global $CFG, $COURSE, $DB; $mform = $this->_form; //------------------------------------------------------------------------------- $mform->addElement('header', 'general', get_string('general', 'form')); /** Legacy slideshow width element to maintain backwards compatibility */ $mform->addElement('hidden', 'width'); $mform->setType('width', PARAM_INT); $mform->setDefault('width', $CFG->lesson_slideshowwidth); /** Legacy slideshow height element to maintain backwards compatibility */ $mform->addElement('hidden', 'height'); $mform->setType('height', PARAM_INT); $mform->setDefault('height', $CFG->lesson_slideshowheight); /** Legacy slideshow background color element to maintain backwards compatibility */ $mform->addElement('hidden', 'bgcolor'); $mform->setType('bgcolor', PARAM_TEXT); $mform->setDefault('bgcolor', $CFG->lesson_slideshowbgcolor); /** Legacy media popup width element to maintain backwards compatibility */ $mform->addElement('hidden', 'mediawidth'); $mform->setType('mediawidth', PARAM_INT); $mform->setDefault('mediawidth', $CFG->lesson_mediawidth); /** Legacy media popup height element to maintain backwards compatibility */ $mform->addElement('hidden', 'mediaheight'); $mform->setType('mediaheight', PARAM_INT); $mform->setDefault('mediaheight', $CFG->lesson_mediaheight); /** Legacy media popup close button element to maintain backwards compatibility */ $mform->addElement('hidden', 'mediaclose'); $mform->setType('mediaclose', PARAM_BOOL); $mform->setDefault('mediaclose', $CFG->lesson_mediaclose); /** Legacy maximum highscores element to maintain backwards compatibility */ $mform->addElement('hidden', 'maxhighscores'); $mform->setType('maxhighscores', PARAM_INT); $mform->setDefault('maxhighscores', $CFG->lesson_maxhighscores); $mform->addElement('text', 'name', get_string('name'), array('size'=>'64')); if (!empty($CFG->formatstringstriptags)) { $mform->setType('name', PARAM_TEXT); } else { $mform->setType('name', PARAM_CLEANHTML); } $mform->addRule('name', null, 'required', null, 'client'); // Create a text box that can be enabled/disabled for lesson time limit $timedgrp = array(); $timedgrp[] = &$mform->createElement('text', 'maxtime'); $timedgrp[] = &$mform->createElement('checkbox', 'timed', '', get_string('enable')); $mform->addGroup($timedgrp, 'timedgrp', get_string('maxtime', 'lesson'), array(' '), false); $mform->disabledIf('timedgrp', 'timed'); // Add numeric rule to text field $timedgrprules = array(); $timedgrprules['maxtime'][] = array(null, 'numeric', null, 'client'); $mform->addGroupRule('timedgrp', $timedgrprules); // Rest of group setup $mform->setDefault('timed', 0); $mform->setDefault('maxtime', 20); $mform->setType('maxtime', PARAM_INT); $numbers = array(); for ($i=20; $i>1; $i--) { $numbers[$i] = $i; } $mform->addElement('date_time_selector', 'available', get_string('available', 'lesson'), array('optional'=>true)); $mform->setDefault('available', 0); $mform->addElement('date_time_selector', 'deadline', get_string('deadline', 'lesson'), array('optional'=>true)); $mform->setDefault('deadline', 0); $mform->addElement('select', 'maxanswers', get_string('maximumnumberofanswersbranches', 'lesson'), $numbers); $mform->setDefault('maxanswers', $CFG->lesson_maxanswers); $mform->setType('maxanswers', PARAM_INT); $mform->addHelpButton('maxanswers', 'maximumnumberofanswersbranches', 'lesson'); $mform->addElement('selectyesno', 'usepassword', get_string('usepassword', 'lesson')); $mform->addHelpButton('usepassword', 'usepassword', 'lesson'); $mform->setDefault('usepassword', 0); $mform->setAdvanced('usepassword'); $mform->addElement('passwordunmask', 'password', get_string('password', 'lesson')); $mform->setDefault('password', ''); $mform->setType('password', PARAM_RAW); $mform->setAdvanced('password'); $mform->disabledIf('password', 'usepassword', 'eq', 0); $this->standard_grading_coursemodule_elements(); //------------------------------------------------------------------------------- $mform->addElement('header', 'gradeoptions', get_string('gradeoptions', 'lesson')); $mform->addElement('selectyesno', 'practice', get_string('practice', 'lesson')); $mform->addHelpButton('practice', 'practice', 'lesson'); $mform->setDefault('practice', 0); $mform->addElement('selectyesno', 'custom', get_string('customscoring', 'lesson')); $mform->addHelpButton('custom', 'customscoring', 'lesson'); $mform->setDefault('custom', 1); $mform->addElement('selectyesno', 'retake', get_string('retakesallowed', 'lesson')); $mform->addHelpButton('retake', 'retakesallowed', 'lesson'); $mform->setDefault('retake', 0); $options = array(); $options[0] = get_string('usemean', 'lesson'); $options[1] = get_string('usemaximum', 'lesson'); $mform->addElement('select', 'usemaxgrade', get_string('handlingofretakes', 'lesson'), $options); $mform->addHelpButton('usemaxgrade', 'handlingofretakes', 'lesson'); $mform->setDefault('usemaxgrade', 0); $mform->disabledIf('usemaxgrade', 'retake', 'eq', '0'); $mform->addElement('selectyesno', 'ongoing', get_string('ongoing', 'lesson')); $mform->addHelpButton('ongoing', 'ongoing', 'lesson'); $mform->setDefault('ongoing', 0); //------------------------------------------------------------------------------- $mform->addElement('header', 'flowcontrol', get_string('flowcontrol', 'lesson')); $mform->addElement('selectyesno', 'modattempts', get_string('modattempts', 'lesson')); $mform->addHelpButton('modattempts', 'modattempts', 'lesson'); $mform->setDefault('modattempts', 0); $mform->addElement('selectyesno', 'review', get_string('displayreview', 'lesson')); $mform->addHelpButton('review', 'displayreview', 'lesson'); $mform->setDefault('review', 0); $numbers = array(); for ($i=10; $i>0; $i--) { $numbers[$i] = $i; } $mform->addElement('select', 'maxattempts', get_string('maximumnumberofattempts', 'lesson'), $numbers); $mform->addHelpButton('maxattempts', 'maximumnumberofattempts', 'lesson'); $mform->setDefault('maxattempts', 1); $defaultnextpages = array(); $defaultnextpages[0] = get_string('normal', 'lesson'); $defaultnextpages[LESSON_UNSEENPAGE] = get_string('showanunseenpage', 'lesson'); $defaultnextpages[LESSON_UNANSWEREDPAGE] = get_string('showanunansweredpage', 'lesson'); $mform->addElement('select', 'nextpagedefault', get_string('actionaftercorrectanswer', 'lesson'), $defaultnextpages); $mform->addHelpButton('nextpagedefault', 'actionaftercorrectanswer', 'lesson'); $mform->setDefault('nextpagedefault', $CFG->lesson_defaultnextpage); $mform->setAdvanced('nextpagedefault'); $mform->addElement('selectyesno', 'feedback', get_string('displaydefaultfeedback', 'lesson')); $mform->addHelpButton('feedback', 'displaydefaultfeedback', 'lesson'); $mform->setDefault('feedback', 0); $mform->addElement('selectyesno', 'progressbar', get_string('progressbar', 'lesson')); $mform->addHelpButton('progressbar', 'progressbar', 'lesson'); $mform->setDefault('progressbar', 0); $mform->addElement('selectyesno', 'displayleft', get_string('displayleftmenu', 'lesson')); $mform->addHelpButton('displayleft', 'displayleftmenu', 'lesson'); $mform->setDefault('displayleft', 0); $options = array(); for($i = 100; $i >= 0; $i--) { $options[$i] = $i.'%'; } $mform->addElement('select', 'displayleftif', get_string('displayleftif', 'lesson'), $options); $mform->addHelpButton('displayleftif', 'displayleftif', 'lesson'); $mform->setDefault('displayleftif', 0); $mform->setAdvanced('displayleftif'); $numbers = array(); for ($i = 100; $i >= 0; $i--) { $numbers[$i] = $i; } $mform->addElement('select', 'minquestions', get_string('minimumnumberofquestions', 'lesson'), $numbers); $mform->addHelpButton('minquestions', 'minimumnumberofquestions', 'lesson'); $mform->setDefault('minquestions', 0); $mform->setAdvanced('minquestions'); $numbers = array(); for ($i = 100; $i >= 0; $i--) { $numbers[$i] = $i; } $mform->addElement('select', 'maxpages', get_string('numberofpagestoshow', 'lesson'), $numbers); $mform->addHelpButton('maxpages', 'numberofpagestoshow', 'lesson'); $mform->setAdvanced('maxpages'); $mform->setDefault('maxpages', 0); $mform->addElement('selectyesno', 'slideshow', get_string('slideshow', 'lesson')); $mform->addHelpButton('slideshow', 'slideshow', 'lesson'); $mform->setDefault('slideshow', 0); $mform->setAdvanced('slideshow'); // get the modules if ($mods = get_course_mods($COURSE->id)) { $modinstances = array(); foreach ($mods as $mod) { // get the module name and then store it in a new array if ($module = get_coursemodule_from_instance($mod->modname, $mod->instance, $COURSE->id)) { if (isset($this->_cm->id) and $this->_cm->id != $mod->id){ $modinstances[$mod->id] = $mod->modname.' - '.$module->name; } } } asort($modinstances); // sort by module name $modinstances=array(0=>get_string('none'))+$modinstances; $mform->addElement('select', 'activitylink', get_string('activitylink', 'lesson'), $modinstances); $mform->addHelpButton('activitylink', 'activitylink', 'lesson'); $mform->setDefault('activitylink', 0); $mform->setAdvanced('activitylink'); } //------------------------------------------------------------------------------- $mform->addElement('header', 'mediafileheader', get_string('mediafile', 'lesson')); $filepickeroptions = array(); $filepickeroptions['filetypes'] = '*'; $filepickeroptions['maxbytes'] = $this->course->maxbytes; $mform->addElement('filepicker', 'mediafilepicker', get_string('mediafile', 'lesson'), null, $filepickeroptions); $mform->addHelpButton('mediafilepicker', 'mediafile', 'lesson'); //------------------------------------------------------------------------------- $mform->addElement('header', 'dependencyon', get_string('dependencyon', 'lesson')); $options = array(0=>get_string('none')); if ($lessons = get_all_instances_in_course('lesson', $COURSE)) { foreach($lessons as $lesson) { if ($lesson->id != $this->_instance){ $options[$lesson->id] = format_string($lesson->name, true); } } } $mform->addElement('select', 'dependency', get_string('dependencyon', 'lesson'), $options); $mform->addHelpButton('dependency', 'dependencyon', 'lesson'); $mform->setDefault('dependency', 0); $mform->addElement('text', 'timespent', get_string('timespentminutes', 'lesson')); $mform->setDefault('timespent', 0); $mform->setType('timespent', PARAM_INT); $mform->addElement('checkbox', 'completed', get_string('completed', 'lesson')); $mform->setDefault('completed', 0); $mform->addElement('text', 'gradebetterthan', get_string('gradebetterthan', 'lesson')); $mform->setDefault('gradebetterthan', 0); $mform->setType('gradebetterthan', PARAM_INT); //------------------------------------------------------------------------------- $this->standard_coursemodule_elements(); //------------------------------------------------------------------------------- // buttons $this->add_action_buttons(); }
/** * This function returns the number of activities using the given scale in the given course. * * @param int $courseid The course ID to check. * @param int $scaleid The scale ID to check * @return int */ function course_scale_used($courseid, $scaleid) { global $CFG, $DB; $return = 0; if (!empty($scaleid)) { if ($cms = get_course_mods($courseid)) { foreach ($cms as $cm) { // Check cm->name/lib.php exists. if (file_exists($CFG->dirroot . '/mod/' . $cm->modname . '/lib.php')) { include_once $CFG->dirroot . '/mod/' . $cm->modname . '/lib.php'; $functionname = $cm->modname . '_scale_used'; if (function_exists($functionname)) { if ($functionname($cm->instance, $scaleid)) { $return++; } } } } } // Check if any course grade item makes use of the scale. $return += $DB->count_records('grade_items', array('courseid' => $courseid, 'scaleid' => $scaleid)); // Check if any outcome in the course makes use of the scale. $return += $DB->count_records_sql("SELECT COUNT('x')\n FROM {grade_outcomes_courses} goc,\n {grade_outcomes} go\n WHERE go.id = goc.outcomeid\n AND go.scaleid = ? AND goc.courseid = ?", array($scaleid, $courseid)); } return $return; }
/** * For a given course, returns an array of course activity objects * Each item in the array contains he following properties: */ function get_array_of_activities($courseid) { // cm - course module id // mod - name of the module (eg forum) // section - the number of the section (eg week or topic) // name - the name of the instance // visible - is the instance visible or not // groupingid - grouping id // groupmembersonly - is this instance visible to group members only // extra - contains extra string to include in any link global $CFG, $DB; if (!empty($CFG->enableavailability)) { require_once $CFG->libdir . '/conditionlib.php'; } $course = $DB->get_record('course', array('id' => $courseid)); if (empty($course)) { throw new moodle_exception('courseidnotfound'); } $mod = array(); $rawmods = get_course_mods($courseid); if (empty($rawmods)) { return $mod; // always return array } if ($sections = $DB->get_records("course_sections", array("course" => $courseid), "section ASC")) { foreach ($sections as $section) { if (!empty($section->sequence)) { $sequence = explode(",", $section->sequence); foreach ($sequence as $seq) { if (empty($rawmods[$seq])) { continue; } $mod[$seq]->id = $rawmods[$seq]->instance; $mod[$seq]->cm = $rawmods[$seq]->id; $mod[$seq]->mod = $rawmods[$seq]->modname; $mod[$seq]->section = $section->section; $mod[$seq]->idnumber = $rawmods[$seq]->idnumber; $mod[$seq]->visible = $rawmods[$seq]->visible; $mod[$seq]->groupmode = $rawmods[$seq]->groupmode; $mod[$seq]->groupingid = $rawmods[$seq]->groupingid; $mod[$seq]->groupmembersonly = $rawmods[$seq]->groupmembersonly; $mod[$seq]->indent = $rawmods[$seq]->indent; $mod[$seq]->completion = $rawmods[$seq]->completion; $mod[$seq]->extra = ""; if (!empty($CFG->enableavailability)) { condition_info::fill_availability_conditions($rawmods[$seq]); $mod[$seq]->availablefrom = $rawmods[$seq]->availablefrom; $mod[$seq]->availableuntil = $rawmods[$seq]->availableuntil; $mod[$seq]->showavailability = $rawmods[$seq]->showavailability; $mod[$seq]->conditionscompletion = $rawmods[$seq]->conditionscompletion; $mod[$seq]->conditionsgrade = $rawmods[$seq]->conditionsgrade; } $modname = $mod[$seq]->mod; $functionname = $modname . "_get_coursemodule_info"; if (!file_exists("{$CFG->dirroot}/mod/{$modname}/lib.php")) { continue; } include_once "{$CFG->dirroot}/mod/{$modname}/lib.php"; if (function_exists($functionname)) { if ($info = $functionname($rawmods[$seq])) { if (!empty($info->icon)) { $mod[$seq]->icon = $info->icon; } if (!empty($info->iconcomponent)) { $mod[$seq]->iconcomponent = $info->iconcomponent; } if (!empty($info->name)) { $mod[$seq]->name = $info->name; } if ($info instanceof cached_cm_info) { // When using cached_cm_info you can include three new fields // that aren't available for legacy code if (!empty($info->content)) { $mod[$seq]->content = $info->content; } if (!empty($info->extraclasses)) { $mod[$seq]->extraclasses = $info->extraclasses; } if (!empty($info->onclick)) { $mod[$seq]->onclick = $info->onclick; } if (!empty($info->customdata)) { $mod[$seq]->customdata = $info->customdata; } } else { // When using a stdclass, the (horrible) deprecated ->extra field // is available for BC if (!empty($info->extra)) { $mod[$seq]->extra = $info->extra; } } } } if (!isset($mod[$seq]->name)) { $mod[$seq]->name = $DB->get_field($rawmods[$seq]->modname, "name", array("id" => $rawmods[$seq]->instance)); } // Minimise the database size by unsetting default options when they are // 'empty'. This list corresponds to code in the cm_info constructor. foreach (array('idnumber', 'groupmode', 'groupingid', 'groupmembersonly', 'indent', 'completion', 'extra', 'extraclasses', 'onclick', 'content', 'icon', 'iconcomponent', 'customdata', 'availablefrom', 'availableuntil', 'conditionscompletion', 'conditionsgrade') as $property) { if (property_exists($mod[$seq], $property) && empty($mod[$seq]->{$property})) { unset($mod[$seq]->{$property}); } } } } } } return $mod; }
/** * For a given course, returns an array of course activity objects * Each item in the array contains he following properties: */ function get_array_of_activities($courseid) { // cm - course module id // mod - name of the module (eg forum) // section - the number of the section (eg week or topic) // name - the name of the instance // visible - is the instance visible or not // groupingid - grouping id // groupmembersonly - is this instance visible to group members only // extra - contains extra string to include in any link global $CFG, $DB; if (!empty($CFG->enableavailability)) { require_once $CFG->libdir . '/conditionlib.php'; } $course = $DB->get_record('course', array('id' => $courseid)); if (empty($course)) { throw new moodle_exception('courseidnotfound'); } $mod = array(); $rawmods = get_course_mods($courseid); if (empty($rawmods)) { return $mod; // always return array } if ($sections = $DB->get_records("course_sections", array("course" => $courseid), "section ASC")) { foreach ($sections as $section) { if (!empty($section->sequence)) { $sequence = explode(",", $section->sequence); foreach ($sequence as $seq) { if (empty($rawmods[$seq])) { continue; } $mod[$seq] = new stdClass(); $mod[$seq]->id = $rawmods[$seq]->instance; $mod[$seq]->cm = $rawmods[$seq]->id; $mod[$seq]->mod = $rawmods[$seq]->modname; // Oh dear. Inconsistent names left here for backward compatibility. $mod[$seq]->section = $section->section; $mod[$seq]->sectionid = $rawmods[$seq]->section; $mod[$seq]->module = $rawmods[$seq]->module; $mod[$seq]->added = $rawmods[$seq]->added; $mod[$seq]->score = $rawmods[$seq]->score; $mod[$seq]->idnumber = $rawmods[$seq]->idnumber; $mod[$seq]->visible = $rawmods[$seq]->visible; $mod[$seq]->visibleold = $rawmods[$seq]->visibleold; $mod[$seq]->groupmode = $rawmods[$seq]->groupmode; $mod[$seq]->groupingid = $rawmods[$seq]->groupingid; $mod[$seq]->groupmembersonly = $rawmods[$seq]->groupmembersonly; $mod[$seq]->indent = $rawmods[$seq]->indent; $mod[$seq]->completion = $rawmods[$seq]->completion; $mod[$seq]->extra = ""; $mod[$seq]->completiongradeitemnumber = $rawmods[$seq]->completiongradeitemnumber; $mod[$seq]->completionview = $rawmods[$seq]->completionview; $mod[$seq]->completionexpected = $rawmods[$seq]->completionexpected; $mod[$seq]->availablefrom = $rawmods[$seq]->availablefrom; $mod[$seq]->availableuntil = $rawmods[$seq]->availableuntil; $mod[$seq]->showavailability = $rawmods[$seq]->showavailability; $mod[$seq]->showdescription = $rawmods[$seq]->showdescription; if (!empty($CFG->enableavailability)) { condition_info::fill_availability_conditions($rawmods[$seq]); $mod[$seq]->conditionscompletion = $rawmods[$seq]->conditionscompletion; $mod[$seq]->conditionsgrade = $rawmods[$seq]->conditionsgrade; } $modname = $mod[$seq]->mod; $functionname = $modname . "_get_coursemodule_info"; if (!file_exists("{$CFG->dirroot}/mod/{$modname}/lib.php")) { continue; } include_once "{$CFG->dirroot}/mod/{$modname}/lib.php"; if ($hasfunction = function_exists($functionname)) { if ($info = $functionname($rawmods[$seq])) { if (!empty($info->icon)) { $mod[$seq]->icon = $info->icon; } if (!empty($info->iconcomponent)) { $mod[$seq]->iconcomponent = $info->iconcomponent; } if (!empty($info->name)) { $mod[$seq]->name = $info->name; } if ($info instanceof cached_cm_info) { // When using cached_cm_info you can include three new fields // that aren't available for legacy code if (!empty($info->content)) { $mod[$seq]->content = $info->content; } if (!empty($info->extraclasses)) { $mod[$seq]->extraclasses = $info->extraclasses; } if (!empty($info->iconurl)) { $mod[$seq]->iconurl = $info->iconurl; } if (!empty($info->onclick)) { $mod[$seq]->onclick = $info->onclick; } if (!empty($info->customdata)) { $mod[$seq]->customdata = $info->customdata; } } else { // When using a stdclass, the (horrible) deprecated ->extra field // is available for BC if (!empty($info->extra)) { $mod[$seq]->extra = $info->extra; } } } } // When there is no modname_get_coursemodule_info function, // but showdescriptions is enabled, then we use the 'intro' // and 'introformat' fields in the module table if (!$hasfunction && $rawmods[$seq]->showdescription) { if ($modvalues = $DB->get_record($rawmods[$seq]->modname, array('id' => $rawmods[$seq]->instance), 'name, intro, introformat')) { // Set content from intro and introformat. Filters are disabled // because we filter it with format_text at display time $mod[$seq]->content = format_module_intro($rawmods[$seq]->modname, $modvalues, $rawmods[$seq]->id, false); // To save making another query just below, put name in here $mod[$seq]->name = $modvalues->name; } } if (!isset($mod[$seq]->name)) { $mod[$seq]->name = $DB->get_field($rawmods[$seq]->modname, "name", array("id" => $rawmods[$seq]->instance)); } // Minimise the database size by unsetting default options when they are // 'empty'. This list corresponds to code in the cm_info constructor. foreach (array('idnumber', 'groupmode', 'groupingid', 'groupmembersonly', 'indent', 'completion', 'extra', 'extraclasses', 'iconurl', 'onclick', 'content', 'icon', 'iconcomponent', 'customdata', 'showavailability', 'availablefrom', 'availableuntil', 'conditionscompletion', 'conditionsgrade', 'completionview', 'completionexpected', 'score', 'showdescription') as $property) { if (property_exists($mod[$seq], $property) && empty($mod[$seq]->{$property})) { unset($mod[$seq]->{$property}); } } // Special case: this value is usually set to null, but may be 0 if (property_exists($mod[$seq], 'completiongradeitemnumber') && is_null($mod[$seq]->completiongradeitemnumber)) { unset($mod[$seq]->completiongradeitemnumber); } } } } } return $mod; }
function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modnamesused) { // Returns a number of useful structures for course displays $mods = array(); // course modules indexed by id $modnames = array(); // all course module names (except resource!) $modnamesplural = array(); // all course module names (plural form) $modnamesused = array(); // course module names used if ($allmods = get_records("modules")) { foreach ($allmods as $mod) { if ($mod->visible) { $modnames[$mod->name] = get_string("modulename", "{$mod->name}"); $modnamesplural[$mod->name] = get_string("modulenameplural", "{$mod->name}"); } } asort($modnames, SORT_LOCALE_STRING); } else { error("No modules are installed!"); } if ($rawmods = get_course_mods($courseid)) { foreach ($rawmods as $mod) { // Index the mods if (empty($modnames[$mod->modname])) { continue; } $mods[$mod->id] = $mod; $mods[$mod->id]->modfullname = $modnames[$mod->modname]; if (!$mod->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_COURSE, $courseid))) { continue; } // Check groupings if (!groups_course_module_visible($mod)) { continue; } $modnamesused[$mod->modname] = $modnames[$mod->modname]; } if ($modnamesused) { asort($modnamesused, SORT_LOCALE_STRING); } } }
function definition() { global $COURSE, $CFG; $mform =& $this->_form; /// visible elements $mform->addElement('header', 'general', get_string('gradeoutcomeitem', 'grades')); $mform->addElement('text', 'itemname', get_string('itemname', 'grades')); $mform->addRule('itemname', get_string('required'), 'required', null, 'client'); $mform->addElement('text', 'iteminfo', get_string('iteminfo', 'grades')); $mform->setHelpButton('iteminfo', array('iteminfo', get_string('iteminfo', 'grades'), 'grade'), true); $mform->addElement('text', 'idnumber', get_string('idnumbermod')); $mform->setHelpButton('idnumber', array('idnumber', get_string('idnumber', 'grades'), 'grade'), true); // allow setting of outcomes on module items too $options = array(); if ($outcomes = grade_outcome::fetch_all_available($COURSE->id)) { foreach ($outcomes as $outcome) { $options[$outcome->id] = $outcome->get_name(); } } $mform->addElement('selectwithlink', 'outcomeid', get_string('outcome', 'grades'), $options, null, array('link' => $CFG->wwwroot . '/grade/edit/outcome/course.php?id=' . $COURSE->id, 'label' => get_string('outcomeassigntocourse', 'grades'))); $mform->setHelpButton('outcomeid', array('outcomeid', get_string('outcomeid', 'grades'), 'grade'), true); $mform->addRule('outcomeid', get_string('required'), 'required'); $options = array(0 => get_string('none')); if ($coursemods = get_course_mods($COURSE->id)) { foreach ($coursemods as $coursemod) { if ($mod = get_coursemodule_from_id($coursemod->modname, $coursemod->id)) { $options[$coursemod->id] = format_string($mod->name); } } } $mform->addElement('select', 'cmid', get_string('linkedactivity', 'grades'), $options); $mform->setHelpButton('cmid', array('linkedactivity', get_string('linkedactivity', 'grades'), 'grade'), true); $mform->setDefault('cmid', 0); /*$mform->addElement('text', 'gradepass', get_string('gradepass', 'grades')); $mform->setHelpButton('gradepass', array(false, get_string('gradepass', 'grades'), false, true, false, get_string('gradepasshelp', 'grades')));*/ /// hiding /// advcheckbox is not compatible with disabledIf !! $mform->addElement('checkbox', 'hidden', get_string('hidden', 'grades')); $mform->setHelpButton('hidden', array('hidden', get_string('hidden', 'grades'), 'grade')); $mform->addElement('date_time_selector', 'hiddenuntil', get_string('hiddenuntil', 'grades'), array('optional' => true)); $mform->setHelpButton('hiddenuntil', array('hiddenuntil', get_string('hiddenuntil', 'grades'), 'grade')); $mform->disabledIf('hidden', 'hiddenuntil[off]', 'notchecked'); //locking $mform->addElement('advcheckbox', 'locked', get_string('locked', 'grades')); $mform->setHelpButton('locked', array('locked', get_string('locked', 'grades'), 'grade')); $mform->addElement('date_time_selector', 'locktime', get_string('locktime', 'grades'), array('optional' => true)); $mform->setHelpButton('locktime', array('lockedafter', get_string('locktime', 'grades'), 'grade')); /// parent category related settings $mform->addElement('header', 'headerparent', get_string('parentcategory', 'grades')); $options = array(); $default = ''; $coefstring = ''; $categories = grade_category::fetch_all(array('courseid' => $COURSE->id)); foreach ($categories as $cat) { $cat->apply_forced_settings(); $options[$cat->id] = $cat->get_name(); if ($cat->is_course_category()) { $default = $cat->id; } if ($cat->is_aggregationcoef_used()) { if ($cat->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) { $coefstring = ($coefstring == '' or $coefstring == 'aggregationcoefweight') ? 'aggregationcoefweight' : 'aggregationcoef'; } else { if ($cat->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN2) { $coefstring = ($coefstring == '' or $coefstring == 'aggregationcoefextrasum') ? 'aggregationcoefextrasum' : 'aggregationcoef'; } else { if ($cat->aggregation == GRADE_AGGREGATE_EXTRACREDIT_MEAN) { $coefstring = ($coefstring == '' or $coefstring == 'aggregationcoefextra') ? 'aggregationcoefextra' : 'aggregationcoef'; } else { if ($cat->aggregation == GRADE_AGGREGATE_SUM) { $coefstring = ($coefstring == '' or $coefstring == 'aggregationcoefextrasum') ? 'aggregationcoefextrasum' : 'aggregationcoef'; } else { $coefstring = 'aggregationcoef'; } } } } } else { $mform->disabledIf('aggregationcoef', 'parentcategory', 'eq', $cat->id); } } if (count($categories) > 1) { $mform->addElement('select', 'parentcategory', get_string('gradecategory', 'grades'), $options); $mform->disabledIf('parentcategory', 'cmid', 'noteq', 0); } if ($coefstring !== '') { if ($coefstring == 'aggregationcoefextrasum') { // advcheckbox is not compatible with disabledIf! $mform->addElement('checkbox', 'aggregationcoef', get_string($coefstring, 'grades')); } else { $mform->addElement('text', 'aggregationcoef', get_string($coefstring, 'grades')); } $mform->setHelpButton('aggregationcoef', array($coefstring, get_string($coefstring, 'grades'), 'grade'), true); } /// hidden params $mform->addElement('hidden', 'id', 0); $mform->setType('id', PARAM_INT); $mform->addElement('hidden', 'courseid', $COURSE->id); $mform->setType('courseid', PARAM_INT); /// add return tracking info $gpr = $this->_customdata['gpr']; $gpr->add_mform_elements($mform); /// mark advanced according to site settings if (isset($CFG->grade_item_advanced)) { $advanced = explode(',', $CFG->grade_item_advanced); foreach ($advanced as $el) { if ($mform->elementExists($el)) { $mform->setAdvanced($el); } } } //------------------------------------------------------------------------------- // buttons $this->add_action_buttons(); }
function definition() { global $COURSE, $CFG; $mform =& $this->_form; /// visible elements $mform->addElement('header', 'general', get_string('gradeoutcomeitem', 'grades')); $mform->addElement('text', 'itemname', get_string('itemname', 'grades')); $mform->addRule('itemname', get_string('required'), 'required', null, 'client'); $mform->addElement('text', 'iteminfo', get_string('iteminfo', 'grades')); $mform->setHelpButton('iteminfo', array(false, get_string('iteminfo', 'grades'), false, true, false, get_string('iteminfohelp', 'grades'))); $mform->addElement('text', 'idnumber', get_string('idnumber')); $mform->setHelpButton('idnumber', array(false, get_string('idnumber'), false, true, false, get_string('idnumberhelp', 'grades'))); // allow setting of outcomes on module items too $options = array(); if ($outcomes = grade_outcome::fetch_all_available($COURSE->id)) { foreach ($outcomes as $outcome) { $options[$outcome->id] = $outcome->get_name(); } } $mform->addElement('select', 'outcomeid', get_string('outcome', 'grades'), $options); $mform->setHelpButton('outcomeid', array(false, get_string('outcomeid', 'grades'), false, true, false, get_string('outcomeidhelp', 'grades'))); $mform->addRule('outcomeid', get_string('required'), 'required'); $options = array(0 => get_string('none')); if ($coursemods = get_course_mods($COURSE->id)) { foreach ($coursemods as $coursemod) { $mod = get_coursemodule_from_id($coursemod->modname, $coursemod->id); $options[$coursemod->id] = format_string($mod->name); } } $mform->addElement('select', 'cmid', get_string('linkedactivity', 'grades'), $options); $mform->setHelpButton('cmid', array(false, get_string('linkedactivity', 'grades'), false, true, false, get_string('linkedactivityhelp', 'grades'))); $mform->setDefault('cmid', 0); //$mform->addElement('text', 'calculation', get_string('calculation', 'grades')); /*$mform->addElement('text', 'gradepass', get_string('gradepass', 'grades')); $mform->setHelpButton('gradepass', array(false, get_string('gradepass', 'grades'), false, true, false, get_string('gradepasshelp', 'grades')));*/ $mform->addElement('text', 'aggregationcoef', get_string('aggregationcoef', 'grades')); $mform->setHelpButton('aggregationcoef', array(false, get_string('aggregationcoef', 'grades'), false, true, false, get_string('aggregationcoefhelp', 'grades'))); /// hiding /// advcheckbox is not compatible with disabledIf !! $mform->addElement('checkbox', 'hidden', get_string('hidden', 'grades')); $mform->setHelpButton('hidden', array('hidden', get_string('hidden', 'grades'), 'grade')); $mform->addElement('date_time_selector', 'hiddenuntil', get_string('hiddenuntil', 'grades'), array('optional' => true)); $mform->setHelpButton('hiddenuntil', array('hiddenuntil', get_string('hiddenuntil', 'grades'), 'grade')); $mform->disabledIf('hidden', 'hiddenuntil[off]', 'notchecked'); //locking $mform->addElement('advcheckbox', 'locked', get_string('locked', 'grades')); $mform->setHelpButton('locked', array('locked', get_string('locked', 'grades'), 'grade')); $mform->addElement('date_time_selector', 'locktime', get_string('locktime', 'grades'), array('optional' => true)); $mform->setHelpButton('locktime', array('locktime', get_string('locktime', 'grades'), 'grade')); /// hidden params $mform->addElement('hidden', 'id', 0); $mform->setType('id', PARAM_INT); $mform->addElement('hidden', 'courseid', $COURSE->id); $mform->setType('courseid', PARAM_INT); /// add return tracking info $gpr = $this->_customdata['gpr']; $gpr->add_mform_elements($mform); //------------------------------------------------------------------------------- // buttons $this->add_action_buttons(); }