本文整理汇总了PHP中get_course_mods函数的典型用法代码示例。如果您正苦于以下问题:PHP get_course_mods函数的具体用法?PHP get_course_mods怎么用?PHP get_course_mods使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_course_mods函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: report_comments_getcoursecomments
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;
}
开发者ID:ewallah,项目名称:moodle-report_comments,代码行数:50,代码来源:lib.php
示例2: course_scale_used
/**
* 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;
}
开发者ID:veritech,项目名称:pare-project,代码行数:30,代码来源:moodlelib.php
示例3: get_course_mods
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;
//.........这里部分代码省略.........
开发者ID:anawu2006,项目名称:PeerLearning,代码行数:101,代码来源:auth.php
示例4: test_cm_info_properties
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));
//.........这里部分代码省略.........
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:101,代码来源:modinfolib_test.php
示例5: definition
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));
//.........这里部分代码省略.........
开发者ID:mongo0se,项目名称:moodle,代码行数:101,代码来源:mod_form.php
示例6: course_scale_used
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;
}
开发者ID:evltuma,项目名称:moodle,代码行数:27,代码来源:deprecatedlib.php
示例7: definition
//.........这里部分代码省略.........
$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();
}
开发者ID:veritech,项目名称:pare-project,代码行数:101,代码来源:mod_form.php
示例8: test_cm_info_properties
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);
//.........这里部分代码省略.........
开发者ID:EmmanuelYupit,项目名称:educursos,代码行数:101,代码来源:modinfolib_test.php
示例9: get_previous_course_id
/**
* 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;
}
开发者ID:jmcgettrick,项目名称:moodle-plagiarism_turnitin,代码行数:22,代码来源:lib.php
示例10: grade_get_legacy_modules
/**
* 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;
}
开发者ID:JackCanada,项目名称:moodle-hacks,代码行数:27,代码来源:gradelib.php
示例11: course_scale_used
/**
* 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;
}
开发者ID:BackupTheBerlios,项目名称:samouk-svn,代码行数:33,代码来源:moodlelib.php
示例12: get_array_of_activities
/**
* 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;
}
开发者ID:vuchannguyen,项目名称:web,代码行数:87,代码来源:lib.php
示例13: specific_definition
//.........这里部分代码省略.........
*/
$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_capab
|
请发表评论