本文整理汇总了PHP中set_coursemodule_visible函数的典型用法代码示例。如果您正苦于以下问题:PHP set_coursemodule_visible函数的具体用法?PHP set_coursemodule_visible怎么用?PHP set_coursemodule_visible使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了set_coursemodule_visible函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ma_show_execute
function ma_show_execute($modids)
{
$message = "";
foreach ($modids as $modid) {
if (!set_coursemodule_visible($modid, 1)) {
$message .= "Could not show module {$modid}, ";
}
}
return $message;
}
示例2: test_search_user_accesses
/**
* Adding this test here as get_areas_user_accesses process is the same, results just depend on the context level.
*
* @return void
*/
public function test_search_user_accesses()
{
global $DB;
$this->resetAfterTest();
$frontpage = $DB->get_record('course', array('id' => SITEID));
$course1 = $this->getDataGenerator()->create_course();
$course1ctx = context_course::instance($course1->id);
$course2 = $this->getDataGenerator()->create_course();
$course2ctx = context_course::instance($course2->id);
$teacher = $this->getDataGenerator()->create_user();
$teacherctx = context_user::instance($teacher->id);
$student = $this->getDataGenerator()->create_user();
$studentctx = context_user::instance($student->id);
$noaccess = $this->getDataGenerator()->create_user();
$noaccessctx = context_user::instance($noaccess->id);
$this->getDataGenerator()->enrol_user($teacher->id, $course1->id, 'teacher');
$this->getDataGenerator()->enrol_user($student->id, $course1->id, 'student');
$frontpageforum = $this->getDataGenerator()->create_module('forum', array('course' => $frontpage->id));
$forum1 = $this->getDataGenerator()->create_module('forum', array('course' => $course1->id));
$forum2 = $this->getDataGenerator()->create_module('forum', array('course' => $course1->id));
$forum3 = $this->getDataGenerator()->create_module('forum', array('course' => $course2->id));
$frontpageforumcontext = context_module::instance($frontpageforum->cmid);
$context1 = context_module::instance($forum1->cmid);
$context2 = context_module::instance($forum2->cmid);
$context3 = context_module::instance($forum3->cmid);
$search = testable_core_search::instance();
$mockareaid = \core_search\manager::generate_areaid('core_mocksearch', 'mock_search_area');
$search->add_core_search_areas();
$search->add_search_area($mockareaid, new core_mocksearch\search\mock_search_area());
$this->setAdminUser();
$this->assertTrue($search->get_areas_user_accesses());
$sitectx = \context_course::instance(SITEID);
$systemctxid = \context_system::instance()->id;
// Can access the frontpage ones.
$this->setUser($noaccess);
$contexts = $search->get_areas_user_accesses();
$this->assertEquals(array($frontpageforumcontext->id => $frontpageforumcontext->id), $contexts[$this->forumpostareaid]);
$this->assertEquals(array($sitectx->id => $sitectx->id), $contexts[$this->mycoursesareaid]);
$mockctxs = array($noaccessctx->id => $noaccessctx->id, $systemctxid => $systemctxid);
$this->assertEquals($mockctxs, $contexts[$mockareaid]);
$this->setUser($teacher);
$contexts = $search->get_areas_user_accesses();
$frontpageandcourse1 = array($frontpageforumcontext->id => $frontpageforumcontext->id, $context1->id => $context1->id, $context2->id => $context2->id);
$this->assertEquals($frontpageandcourse1, $contexts[$this->forumpostareaid]);
$this->assertEquals(array($sitectx->id => $sitectx->id, $course1ctx->id => $course1ctx->id), $contexts[$this->mycoursesareaid]);
$mockctxs = array($teacherctx->id => $teacherctx->id, $systemctxid => $systemctxid);
$this->assertEquals($mockctxs, $contexts[$mockareaid]);
$this->setUser($student);
$contexts = $search->get_areas_user_accesses();
$this->assertEquals($frontpageandcourse1, $contexts[$this->forumpostareaid]);
$this->assertEquals(array($sitectx->id => $sitectx->id, $course1ctx->id => $course1ctx->id), $contexts[$this->mycoursesareaid]);
$mockctxs = array($studentctx->id => $studentctx->id, $systemctxid => $systemctxid);
$this->assertEquals($mockctxs, $contexts[$mockareaid]);
// Hide the activity.
set_coursemodule_visible($forum2->cmid, 0);
$contexts = $search->get_areas_user_accesses();
$this->assertEquals(array($frontpageforumcontext->id => $frontpageforumcontext->id, $context1->id => $context1->id), $contexts[$this->forumpostareaid]);
// Now test course limited searches.
set_coursemodule_visible($forum2->cmid, 1);
$this->getDataGenerator()->enrol_user($student->id, $course2->id, 'student');
$contexts = $search->get_areas_user_accesses();
$allcontexts = array($frontpageforumcontext->id => $frontpageforumcontext->id, $context1->id => $context1->id, $context2->id => $context2->id, $context3->id => $context3->id);
$this->assertEquals($allcontexts, $contexts[$this->forumpostareaid]);
$this->assertEquals(array($sitectx->id => $sitectx->id, $course1ctx->id => $course1ctx->id, $course2ctx->id => $course2ctx->id), $contexts[$this->mycoursesareaid]);
$contexts = $search->get_areas_user_accesses(array($course1->id, $course2->id));
$allcontexts = array($context1->id => $context1->id, $context2->id => $context2->id, $context3->id => $context3->id);
$this->assertEquals($allcontexts, $contexts[$this->forumpostareaid]);
$this->assertEquals(array($course1ctx->id => $course1ctx->id, $course2ctx->id => $course2ctx->id), $contexts[$this->mycoursesareaid]);
$contexts = $search->get_areas_user_accesses(array($course2->id));
$allcontexts = array($context3->id => $context3->id);
$this->assertEquals($allcontexts, $contexts[$this->forumpostareaid]);
$this->assertEquals(array($course2ctx->id => $course2ctx->id), $contexts[$this->mycoursesareaid]);
$contexts = $search->get_areas_user_accesses(array($course1->id));
$allcontexts = array($context1->id => $context1->id, $context2->id => $context2->id);
$this->assertEquals($allcontexts, $contexts[$this->forumpostareaid]);
$this->assertEquals(array($course1ctx->id => $course1ctx->id), $contexts[$this->mycoursesareaid]);
}
示例3: require_capability
case 'move':
require_capability('moodle/course:movesections', $coursecontext);
move_section_to($course, $id, $value);
// See if format wants to do something about it
$response = course_get_format($course)->ajax_section_move();
if ($response !== null) {
echo json_encode($response);
}
break;
}
break;
case 'resource':
switch ($field) {
case 'visible':
require_capability('moodle/course:activityvisibility', $modcontext);
set_coursemodule_visible($cm->id, $value);
\core\event\course_module_updated::create_from_cm($cm, $modcontext)->trigger();
break;
case 'duplicate':
require_capability('moodle/course:manageactivities', $modcontext);
require_capability('moodle/backup:backuptargetimport', $modcontext);
require_capability('moodle/restore:restoretargetimport', $modcontext);
if (!course_allowed_module($course, $cm->modname)) {
throw new moodle_exception('No permission to create that activity');
}
$sr = optional_param('sr', null, PARAM_INT);
$result = mod_duplicate_activity($course, $cm, $sr);
echo json_encode($result);
break;
case 'groupmode':
require_capability('moodle/course:manageactivities', $modcontext);
示例4: moveto_module
/**
* Move the module object $mod to the specified $section
* If $beforemod exists then that is the module
* before which $modid should be inserted
* All parameters are objects
*/
function moveto_module($mod, $section, $beforemod = NULL)
{
global $DB, $OUTPUT;
/// Remove original module from original section
if (!delete_mod_from_section($mod->id, $mod->section)) {
echo $OUTPUT->notification("Could not delete module from existing section");
}
/// Update module itself if necessary
if ($mod->section != $section->id) {
$mod->section = $section->id;
$DB->update_record("course_modules", $mod);
// if moving to a hidden section then hide module
if (!$section->visible) {
set_coursemodule_visible($mod->id, 0);
}
}
/// Add the module into the new section
$mod->course = $section->course;
$mod->section = $section->section;
// need relative reference
$mod->coursemodule = $mod->id;
if (!add_mod_to_section($mod, $beforemod)) {
return false;
}
return true;
}
示例5: test_blank_hidden_total_and_adjust_bounds
/**
* Tests grade_report::blank_hidden_total_and_adjust_bounds()
*/
public function test_blank_hidden_total_and_adjust_bounds()
{
global $DB;
$this->resetAfterTest(true);
$student = $this->getDataGenerator()->create_user();
$this->setUser($student);
// Create a course and two activities.
// One activity will be hidden.
$course = $this->getDataGenerator()->create_course();
$coursegradeitem = grade_item::fetch_course_item($course->id);
$coursecontext = context_course::instance($course->id);
$data = $this->getDataGenerator()->create_module('data', array('assessed' => 1, 'scale' => 100, 'course' => $course->id));
$datacm = get_coursemodule_from_id('data', $data->cmid);
$forum = $this->getDataGenerator()->create_module('forum', array('assessed' => 1, 'scale' => 100, 'course' => $course->id));
$forumcm = get_coursemodule_from_id('forum', $forum->cmid);
// Insert student grades for the two activities.
$gi = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => 'data', 'iteminstance' => $data->id, 'courseid' => $course->id));
$datagrade = 50;
$grade_grade = new grade_grade();
$grade_grade->itemid = $gi->id;
$grade_grade->userid = $student->id;
$grade_grade->rawgrade = $datagrade;
$grade_grade->finalgrade = $datagrade;
$grade_grade->rawgrademax = 100;
$grade_grade->rawgrademin = 0;
$grade_grade->timecreated = time();
$grade_grade->timemodified = time();
$grade_grade->insert();
$gi = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => 'forum', 'iteminstance' => $forum->id, 'courseid' => $course->id));
$forumgrade = 70;
$grade_grade = new grade_grade();
$grade_grade->itemid = $gi->id;
$grade_grade->userid = $student->id;
$grade_grade->rawgrade = $forumgrade;
$grade_grade->finalgrade = $forumgrade;
$grade_grade->rawgrademax = 100;
$grade_grade->rawgrademin = 0;
$grade_grade->timecreated = time();
$grade_grade->timemodified = time();
$grade_grade->insert();
// Hide the database activity.
set_coursemodule_visible($datacm->id, 0);
$gpr = new grade_plugin_return(array('type' => 'report', 'courseid' => $course->id));
$report = new grade_report_test($course->id, $gpr, $coursecontext, $student);
// Should return the supplied student total grade regardless of hiding.
$report->showtotalsifcontainhidden = array($course->id => GRADE_REPORT_SHOW_REAL_TOTAL_IF_CONTAINS_HIDDEN);
$result = $report->blank_hidden_total_and_adjust_bounds($course->id, $coursegradeitem, $datagrade + $forumgrade);
$this->assertEquals(array('grade' => $datagrade + $forumgrade, 'grademax' => $coursegradeitem->grademax, 'grademin' => $coursegradeitem->grademin, 'aggregationstatus' => 'unknown', 'aggregationweight' => null), $result);
// Should blank the student total as course grade depends on a hidden item.
$report->showtotalsifcontainhidden = array($course->id => GRADE_REPORT_HIDE_TOTAL_IF_CONTAINS_HIDDEN);
$result = $report->blank_hidden_total_and_adjust_bounds($course->id, $coursegradeitem, $datagrade + $forumgrade);
$this->assertEquals(array('grade' => null, 'grademax' => $coursegradeitem->grademax, 'grademin' => $coursegradeitem->grademin, 'aggregationstatus' => 'unknown', 'aggregationweight' => null), $result);
// Should return the course total minus the hidden database activity grade.
$report->showtotalsifcontainhidden = array($course->id => GRADE_REPORT_SHOW_TOTAL_IF_CONTAINS_HIDDEN);
$result = $report->blank_hidden_total_and_adjust_bounds($course->id, $coursegradeitem, $datagrade + $forumgrade);
$this->assertEquals(array('grade' => floatval($forumgrade), 'grademax' => $coursegradeitem->grademax, 'grademin' => $coursegradeitem->grademin, 'aggregationstatus' => 'unknown', 'aggregationweight' => null), $result);
// Note: we cannot simply hide modules and call $report->blank_hidden_total() again.
// It stores grades in a static variable so $report->blank_hidden_total() will return incorrect totals
// In practice this isn't a problem. Grade visibility isn't altered mid-request outside of the unit tests.
// Add a second course to test:
// 1) How a course with no visible activities behaves.
// 2) That $report->blank_hidden_total() correctly moves on to the new course.
$course = $this->getDataGenerator()->create_course();
$coursegradeitem = grade_item::fetch_course_item($course->id);
$coursecontext = context_course::instance($course->id);
$data = $this->getDataGenerator()->create_module('data', array('assessed' => 1, 'scale' => 100, 'course' => $course->id));
$datacm = get_coursemodule_from_id('data', $data->cmid);
$forum = $this->getDataGenerator()->create_module('forum', array('assessed' => 1, 'scale' => 100, 'course' => $course->id));
$forumcm = get_coursemodule_from_id('forum', $forum->cmid);
$gi = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => 'data', 'iteminstance' => $data->id, 'courseid' => $course->id));
$datagrade = 50;
$grade_grade = new grade_grade();
$grade_grade->itemid = $gi->id;
$grade_grade->userid = $student->id;
$grade_grade->rawgrade = $datagrade;
$grade_grade->finalgrade = $datagrade;
$grade_grade->rawgrademax = 100;
$grade_grade->rawgrademin = 0;
$grade_grade->timecreated = time();
$grade_grade->timemodified = time();
$grade_grade->insert();
$gi = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => 'forum', 'iteminstance' => $forum->id, 'courseid' => $course->id));
$forumgrade = 70;
$grade_grade = new grade_grade();
$grade_grade->itemid = $gi->id;
$grade_grade->userid = $student->id;
$grade_grade->rawgrade = $forumgrade;
$grade_grade->finalgrade = $forumgrade;
$grade_grade->rawgrademax = 100;
$grade_grade->rawgrademin = 0;
$grade_grade->timecreated = time();
$grade_grade->timemodified = time();
$grade_grade->insert();
// Hide both activities.
set_coursemodule_visible($datacm->id, 0);
set_coursemodule_visible($forumcm->id, 0);
$gpr = new grade_plugin_return(array('type' => 'report', 'courseid' => $course->id));
//.........这里部分代码省略.........
示例6: moveto_module
/**
* Move the module object $mod to the specified $section
* If $beforemod exists then that is the module
* before which $modid should be inserted
*
* @param stdClass|cm_info $mod
* @param stdClass|section_info $section
* @param int|stdClass $beforemod id or object with field id corresponding to the module
* before which the module needs to be included. Null for inserting in the
* end of the section
* @return int new value for module visibility (0 or 1)
*/
function moveto_module($mod, $section, $beforemod = NULL)
{
global $OUTPUT, $DB;
// Current module visibility state - return value of this function.
$modvisible = $mod->visible;
// Remove original module from original section.
if (!delete_mod_from_section($mod->id, $mod->section)) {
echo $OUTPUT->notification("Could not delete module from existing section");
}
// If moving to a hidden section then hide module.
if ($mod->section != $section->id) {
if (!$section->visible && $mod->visible) {
// Module was visible but must become hidden after moving to hidden section.
$modvisible = 0;
set_coursemodule_visible($mod->id, 0);
// Set visibleold to 1 so module will be visible when section is made visible.
$DB->set_field('course_modules', 'visibleold', 1, array('id' => $mod->id));
}
if ($section->visible && !$mod->visible) {
// Hidden module was moved to the visible section, restore the module visibility from visibleold.
set_coursemodule_visible($mod->id, $mod->visibleold);
$modvisible = $mod->visibleold;
}
}
// Add the module into the new section.
course_add_cm_to_section($section->course, $mod->id, $section->section, $beforemod);
return $modvisible;
}
示例7: link_to_gdoc
//.........这里部分代码省略.........
$fromform->groupmode = 0;
// do not set groupmode
}
if (!course_allowed_module($course, $fromform->modulename)) {
print_error('moduledisable', '', '', $fromform->modulename);
}
// first add course_module record because we need the context
$newcm = new stdClass();
$newcm->course = $course->id;
$newcm->module = $fromform->module;
$newcm->instance = 0;
// not known yet, will be updated later (this is similar to restore code)
$newcm->visible = $fromform->visible;
$newcm->groupmode = $fromform->groupmode;
$newcm->groupingid = $fromform->groupingid;
$newcm->groupmembersonly = $fromform->groupmembersonly;
$completion = new completion_info($course);
if ($completion->is_enabled()) {
$newcm->completion = $fromform->completion;
$newcm->completiongradeitemnumber = $fromform->completiongradeitemnumber;
$newcm->completionview = $fromform->completionview;
$newcm->completionexpected = $fromform->completionexpected;
}
if (!empty($CFG->enableavailability)) {
$newcm->availablefrom = $fromform->availablefrom;
$newcm->availableuntil = $fromform->availableuntil;
$newcm->showavailability = $fromform->showavailability;
}
if (isset($fromform->showdescription)) {
$newcm->showdescription = $fromform->showdescription;
} else {
$newcm->showdescription = 0;
}
if (!($fromform->coursemodule = add_course_module($newcm))) {
print_error('cannotaddcoursemodule');
}
if (plugin_supports('mod', $fromform->modulename, FEATURE_MOD_INTRO, true)) {
$draftid_editor = file_get_submitted_draft_itemid('introeditor');
file_prepare_draft_area($draftid_editor, null, null, null, null);
$fromform->introeditor = array('text' => '', 'format' => FORMAT_HTML, 'itemid' => $draftid_editor);
// TODO: add better default
}
if (plugin_supports('mod', $fromform->modulename, FEATURE_MOD_INTRO, true)) {
$introeditor = $fromform->introeditor;
unset($fromform->introeditor);
$fromform->intro = $introeditor['text'];
$fromform->introformat = $introeditor['format'];
}
$addinstancefunction = $fromform->modulename . "_add_instance";
$updateinstancefunction = $fromform->modulename . "_update_instance";
$returnfromfunc = $addinstancefunction($fromform, $mform);
// $returnfromfunc = url_add_instance($fromform, $mform);
if (!$returnfromfunc or !is_number($returnfromfunc)) {
// undo everything we can
$modcontext = get_context_instance(CONTEXT_MODULE, $fromform->coursemodule);
delete_context(CONTEXT_MODULE, $fromform->coursemodule);
$DB->delete_records('course_modules', array('id' => $fromform->coursemodule));
if (!is_number($returnfromfunc)) {
print_error('invalidfunction', '', course_get_url($course, $cw->section));
} else {
print_error('cannotaddnewmodule', '', course_get_url($course, $cw->section), $fromform->modulename);
}
}
$fromform->instance = $returnfromfunc;
$DB->set_field('course_modules', 'instance', $returnfromfunc, array('id' => $fromform->coursemodule));
// update embedded links and save files
$modcontext = get_context_instance(CONTEXT_MODULE, $fromform->coursemodule);
if (!empty($introeditor)) {
$fromform->intro = file_save_draft_area_files($introeditor['itemid'], $modcontext->id, 'mod_' . $fromform->modulename, 'intro', 0, array('subdirs' => true), $introeditor['text']);
$DB->set_field($fromform->modulename, 'intro', $fromform->intro, array('id' => $fromform->instance));
}
// course_modules and course_sections each contain a reference
// to each other, so we have to update one of them twice.
$sectionid = add_mod_to_section($fromform);
$DB->set_field('course_modules', 'section', $sectionid, array('id' => $fromform->coursemodule));
// make sure visibility is set correctly (in particular in calendar)
set_coursemodule_visible($fromform->coursemodule, $fromform->visible);
if (isset($fromform->cmidnumber)) {
//label
// set cm idnumber
set_coursemodule_idnumber($fromform->coursemodule, $fromform->cmidnumber);
}
// Set up conditions
if ($CFG->enableavailability) {
condition_info::update_cm_from_form((object) array('id' => $fromform->coursemodule), $fromform, false);
}
$eventname = 'mod_created';
add_to_log($course->id, "course", "add mod", "../mod/{$fromform->modulename}/view.php?id={$fromform->coursemodule}", "{$fromform->modulename} {$fromform->instance}");
add_to_log($course->id, $fromform->modulename, "add", "view.php?id={$fromform->coursemodule}", "{$fromform->instance}", $fromform->coursemodule);
// Trigger mod_created/mod_updated event with information about this module.
$eventdata = new stdClass();
$eventdata->modulename = $fromform->modulename;
$eventdata->name = $fromform->name;
$eventdata->cmid = $fromform->coursemodule;
$eventdata->courseid = $course->id;
$eventdata->userid = $USER->id;
events_trigger($eventname, $eventdata);
rebuild_course_cache($course->id);
return 1;
}
示例8: test_get_course_module_by_instance
/**
* Test get_course_module_by_instance
*/
public function test_get_course_module_by_instance()
{
global $DB;
$this->resetAfterTest(true);
$this->setAdminUser();
$course = self::getDataGenerator()->create_course();
$record = array('course' => $course->id, 'name' => 'First Chat');
$options = array('idnumber' => 'ABC', 'visible' => 0);
// Hidden activity.
$chat = self::getDataGenerator()->create_module('chat', $record, $options);
// Test admin user can see the complete hidden activity.
$result = core_course_external::get_course_module_by_instance('chat', $chat->id);
$result = external_api::clean_returnvalue(core_course_external::get_course_module_by_instance_returns(), $result);
$this->assertCount(0, $result['warnings']);
// Test we retrieve all the fields.
$this->assertCount(22, $result['cm']);
$this->assertEquals($record['name'], $result['cm']['name']);
$this->assertEquals($options['idnumber'], $result['cm']['idnumber']);
$student = $this->getDataGenerator()->create_user();
$studentrole = $DB->get_record('role', array('shortname' => 'student'));
self::getDataGenerator()->enrol_user($student->id, $course->id, $studentrole->id);
$this->setUser($student);
// The user shouldn't be able to see the activity.
try {
core_course_external::get_course_module_by_instance('chat', $chat->id);
$this->fail('Exception expected due to invalid permissions.');
} catch (moodle_exception $e) {
$this->assertEquals('requireloginerror', $e->errorcode);
}
// Make module visible.
set_coursemodule_visible($chat->cmid, 1);
// Test student user.
$result = core_course_external::get_course_module_by_instance('chat', $chat->id);
$result = external_api::clean_returnvalue(core_course_external::get_course_module_by_instance_returns(), $result);
$this->assertCount(0, $result['warnings']);
// Test we retrieve only the few files we can see.
$this->assertCount(11, $result['cm']);
$this->assertEquals($chat->cmid, $result['cm']['id']);
$this->assertEquals($course->id, $result['cm']['course']);
$this->assertEquals('chat', $result['cm']['modname']);
$this->assertEquals($chat->id, $result['cm']['instance']);
// Try with an invalid module name.
try {
core_course_external::get_course_module_by_instance('abc', $chat->id);
$this->fail('Exception expected due to invalid module name.');
} catch (dml_read_exception $e) {
$this->assertEquals('dmlreadexception', $e->errorcode);
}
}
示例9: moveto_module
function moveto_module($mod, $section, $beforemod = NULL)
{
/// All parameters are objects
/// Move the module object $mod to the specified $section
/// If $beforemod exists then that is the module
/// before which $modid should be inserted
/// Remove original module from original section
if (!delete_mod_from_section($mod->id, $mod->section)) {
notify("Could not delete module from existing section");
}
/// Update module itself if necessary
if ($mod->section != $section->id) {
$mod->section = $section->id;
if (!update_record("course_modules", $mod)) {
return false;
}
// if moving to a hidden section then hide module
if (!$section->visible) {
set_coursemodule_visible($mod->id, 0);
}
}
/// Add the module into the new section
$mod->course = $section->course;
$mod->section = $section->section;
// need relative reference
$mod->coursemodule = $mod->id;
if (!add_mod_to_section($mod, $beforemod)) {
return false;
}
return true;
}
示例10: test_posts_access
/**
* Document accesses.
*
* @return void
*/
public function test_posts_access()
{
global $DB;
// Returns the instance as long as the area is supported.
$searcharea = \core_search\manager::get_search_area($this->forumpostareaid);
$user1 = self::getDataGenerator()->create_user();
$user2 = self::getDataGenerator()->create_user();
$course1 = self::getDataGenerator()->create_course();
$course2 = self::getDataGenerator()->create_course();
$this->getDataGenerator()->enrol_user($user1->id, $course1->id, 'teacher');
$this->getDataGenerator()->enrol_user($user2->id, $course1->id, 'student');
$record = new stdClass();
$record->course = $course1->id;
// Available for both student and teacher.
$forum1 = self::getDataGenerator()->create_module('forum', $record);
// Teacher only.
$forum2 = self::getDataGenerator()->create_module('forum', $record);
set_coursemodule_visible($forum2->cmid, 0);
// Create discussion1.
$record = new stdClass();
$record->course = $course1->id;
$record->userid = $user1->id;
$record->forum = $forum1->id;
$record->message = 'discussion';
$discussion1 = self::getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($record);
// Create post1 in discussion1.
$record = new stdClass();
$record->discussion = $discussion1->id;
$record->parent = $discussion1->firstpost;
$record->userid = $user2->id;
$record->message = 'post1';
$discussion1reply1 = self::getDataGenerator()->get_plugin_generator('mod_forum')->create_post($record);
// Create discussion2 only visible to teacher.
$record = new stdClass();
$record->course = $course1->id;
$record->userid = $user1->id;
$record->forum = $forum2->id;
$record->message = 'discussion';
$discussion2 = self::getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($record);
// Create post2 in discussion2.
$record = new stdClass();
$record->discussion = $discussion2->id;
$record->parent = $discussion2->firstpost;
$record->userid = $user1->id;
$record->message = 'post2';
$discussion2reply1 = self::getDataGenerator()->get_plugin_generator('mod_forum')->create_post($record);
$this->setUser($user2);
$this->assertEquals(\core_search\manager::ACCESS_GRANTED, $searcharea->check_access($discussion1reply1->id));
$this->assertEquals(\core_search\manager::ACCESS_DENIED, $searcharea->check_access($discussion2reply1->id));
}
示例11: update_moduleinfo
/**
* Update the module info.
* This function doesn't check the user capabilities. It updates the course module and the module instance.
* Then execute common action to create/update module process (trigger event, rebuild cache, save plagiarism settings...).
*
* @param object $cm course module
* @param object $moduleinfo module info
* @param object $course course of the module
* @param object $mform - the mform is required by some specific module in the function MODULE_update_instance(). This is due to a hack in this function.
* @return array list of course module and module info.
*/
function update_moduleinfo($cm, $moduleinfo, $course, $mform = null)
{
global $DB, $CFG;
// Attempt to include module library before we make any changes to DB.
include_modulelib($moduleinfo->modulename);
$moduleinfo->course = $course->id;
$moduleinfo = set_moduleinfo_defaults($moduleinfo);
if (!empty($course->groupmodeforce) or !isset($moduleinfo->groupmode)) {
$moduleinfo->groupmode = $cm->groupmode;
// Keep original.
}
// Update course module first.
$cm->groupmode = $moduleinfo->groupmode;
if (isset($moduleinfo->groupingid)) {
$cm->groupingid = $moduleinfo->groupingid;
}
if (isset($moduleinfo->groupmembersonly)) {
$cm->groupmembersonly = $moduleinfo->groupmembersonly;
}
$completion = new completion_info($course);
if ($completion->is_enabled() && !empty($moduleinfo->completionunlocked)) {
// Update completion settings.
$cm->completion = $moduleinfo->completion;
$cm->completiongradeitemnumber = $moduleinfo->completiongradeitemnumber;
$cm->completionview = $moduleinfo->completionview;
$cm->completionexpected = $moduleinfo->completionexpected;
}
if (!empty($CFG->enableavailability)) {
$cm->availablefrom = $moduleinfo->availablefrom;
$cm->availableuntil = $moduleinfo->availableuntil;
$cm->showavailability = $moduleinfo->showavailability;
condition_info::update_cm_from_form($cm, $moduleinfo, true);
}
if (isset($moduleinfo->showdescription)) {
$cm->showdescription = $moduleinfo->showdescription;
} else {
$cm->showdescription = 0;
}
$DB->update_record('course_modules', $cm);
$modcontext = context_module::instance($moduleinfo->coursemodule);
// Update embedded links and save files.
if (plugin_supports('mod', $moduleinfo->modulename, FEATURE_MOD_INTRO, true)) {
$moduleinfo->intro = file_save_draft_area_files($moduleinfo->introeditor['itemid'], $modcontext->id, 'mod_' . $moduleinfo->modulename, 'intro', 0, array('subdirs' => true), $moduleinfo->introeditor['text']);
$moduleinfo->introformat = $moduleinfo->introeditor['format'];
unset($moduleinfo->introeditor);
}
$updateinstancefunction = $moduleinfo->modulename . "_update_instance";
if (!$updateinstancefunction($moduleinfo, $mform)) {
print_error('cannotupdatemod', '', course_get_url($course, $cw->section), $moduleinfo->modulename);
}
// Make sure visibility is set correctly (in particular in calendar).
if (has_capability('moodle/course:activityvisibility', $modcontext)) {
set_coursemodule_visible($moduleinfo->coursemodule, $moduleinfo->visible);
}
if (isset($moduleinfo->cmidnumber)) {
// Label.
// Set cm idnumber - uniqueness is already verified by form validation.
set_coursemodule_idnumber($moduleinfo->coursemodule, $moduleinfo->cmidnumber);
}
// Now that module is fully updated, also update completion data if required.
// (this will wipe all user completion data and recalculate it)
if ($completion->is_enabled() && !empty($moduleinfo->completionunlocked)) {
$completion->reset_all_state($cm);
}
// Trigger event based on the action we did.
$event = \core\event\course_module_updated::create(array('courseid' => $course->id, 'context' => $modcontext, 'objectid' => $moduleinfo->coursemodule, 'other' => array('modulename' => $moduleinfo->modulename, 'name' => $moduleinfo->name, 'instanceid' => $moduleinfo->instance)));
$event->trigger();
add_to_log($course->id, $moduleinfo->modulename, "update", "view.php?id={$moduleinfo->coursemodule}", "{$moduleinfo->instance}", $moduleinfo->coursemodule);
$moduleinfo = edit_module_post_actions($moduleinfo, $course);
return array($cm, $moduleinfo);
}
示例12: local_ltiprovider_add_moduleinfo
/**
* Add course module.
*
* The function does not check user capabilities.
* The function creates course module, module instance, add the module to the correct section.
* It also trigger common action that need to be done after adding/updating a module.
*
* @param object $moduleinfo the moudle data
* @param object $course the course of the module
* @param object $mform this is required by an existing hack to deal with files during MODULENAME_add_instance()
* @return object the updated module info
*/
function local_ltiprovider_add_moduleinfo($moduleinfo, $course, $mform = null)
{
global $DB, $CFG;
$moduleinfo->course = $course->id;
$moduleinfo = local_ltiprovider_set_moduleinfo_defaults($moduleinfo);
if (!empty($course->groupmodeforce) or !isset($moduleinfo->groupmode)) {
$moduleinfo->groupmode = 0;
// Do not set groupmode.
}
if (!course_allowed_module($course, $moduleinfo->modulename)) {
print_error('moduledisable', '', '', $moduleinfo->modulename);
}
// First add course_module record because we need the context.
$newcm = new stdClass();
$newcm->course = $course->id;
$newcm->module = $moduleinfo->module;
$newcm->instance = 0;
// Not known yet, will be updated later (this is similar to restore code).
$newcm->visible = $moduleinfo->visible;
$newcm->visibleold = $moduleinfo->visible;
$newcm->groupmode = $moduleinfo->groupmode;
$newcm->groupingid = $moduleinfo->groupingid;
$newcm->groupmembersonly = $moduleinfo->groupmembersonly;
$completion = new completion_info($course);
if ($completion->is_enabled()) {
$newcm->completion = $moduleinfo->completion;
$newcm->completiongradeitemnumber = $moduleinfo->completiongradeitemnumber;
$newcm->completionview = $moduleinfo->completionview;
$newcm->completionexpected = $moduleinfo->completionexpected;
}
if (!empty($CFG->enableavailability)) {
$newcm->availablefrom = $moduleinfo->availablefrom;
$newcm->availableuntil = $moduleinfo->availableuntil;
$newcm->showavailability = $moduleinfo->showavailability;
}
if (isset($moduleinfo->showdescription)) {
$newcm->showdescription = $moduleinfo->showdescription;
} else {
$newcm->showdescription = 0;
}
if (!($moduleinfo->coursemodule = add_course_module($newcm))) {
print_error('cannotaddcoursemodule');
}
if (plugin_supports('mod', $moduleinfo->modulename, FEATURE_MOD_INTRO, true)) {
$introeditor = $moduleinfo->introeditor;
unset($moduleinfo->introeditor);
$moduleinfo->intro = $introeditor['text'];
$moduleinfo->introformat = $introeditor['format'];
}
$addinstancefunction = $moduleinfo->modulename . "_add_instance";
$returnfromfunc = $addinstancefunction($moduleinfo, $mform);
if (!$returnfromfunc or !is_number($returnfromfunc)) {
// Undo everything we can.
$modcontext = context_module::instance($moduleinfo->coursemodule);
delete_context(CONTEXT_MODULE, $moduleinfo->coursemodule);
$DB->delete_records('course_modules', array('id' => $moduleinfo->coursemodule));
if (!is_number($returnfromfunc)) {
print_error('invalidfunction', '', course_get_url($course, $cw->section));
} else {
print_error('cannotaddnewmodule', '', course_get_url($course, $cw->section), $moduleinfo->modulename);
}
}
$moduleinfo->instance = $returnfromfunc;
$DB->set_field('course_modules', 'instance', $returnfromfunc, array('id' => $moduleinfo->coursemodule));
// Update embedded links and save files.
$modcontext = context_module::instance($moduleinfo->coursemodule);
if (!empty($introeditor)) {
$moduleinfo->intro = file_save_draft_area_files($introeditor['itemid'], $modcontext->id, 'mod_' . $moduleinfo->modulename, 'intro', 0, array('subdirs' => true), $introeditor['text']);
$DB->set_field($moduleinfo->modulename, 'intro', $moduleinfo->intro, array('id' => $moduleinfo->instance));
}
// Course_modules and course_sections each contain a reference to each other.
// So we have to update one of them twice.
$sectionid = course_add_cm_to_section($course, $moduleinfo->coursemodule, $moduleinfo->section);
// Make sure visibility is set correctly (in particular in calendar).
// Note: allow them to set it even without moodle/course:activityvisibility.
set_coursemodule_visible($moduleinfo->coursemodule, $moduleinfo->visible);
if (isset($moduleinfo->cmidnumber)) {
// Label.
// Set cm idnumber - uniqueness is already verified by form validation.
set_coursemodule_idnumber($moduleinfo->coursemodule, $moduleinfo->cmidnumber);
}
// Set up conditions.
if ($CFG->enableavailability) {
condition_info::update_cm_from_form((object) array('id' => $moduleinfo->coursemodule), $moduleinfo, false);
}
$eventname = 'mod_created';
add_to_log($course->id, "course", "add mod", "../mod/{$moduleinfo->modulename}/view.php?id={$moduleinfo->coursemodule}", "{$moduleinfo->modulename} {$moduleinfo->instance}");
add_to_log($course->id, $moduleinfo->modulename, "add", "view.php?id={$moduleinfo->coursemodule}", "{$moduleinfo->instance}", $moduleinfo->coursemodule);
//.........这里部分代码省略.........
示例13: RWSAUQuiz
//.........这里部分代码省略.........
$r_qiz->groupingid = $r_cmod->groupingid;
$r_qiz->groupmembersonly = $r_cmod->groupmembersonly;
$r_qiz->course = $r_cid;
$r_qiz->module = $r_mr->id;
$r_qiz->modulename = $r_mr->name;
$r_qiz->instance = $r_cmod->instance;
if (respondusws_floatcompare($CFG->version, 2011120500.0, 2) >= 0) {
$r_qiz->showdescription = 0;
}
$r_cpl = new completion_info($r_crs);
if ($r_cpl->is_enabled()) {
$r_qiz->completion = $r_cmod->completion;
$r_qiz->completionview = $r_cmod->completionview;
$r_qiz->completionexpected = $r_cmod->completionexpected;
$r_qiz->completionusegrade = is_null($r_cmod->completiongradeitemnumber) ? 0 : 1;
}
if ($CFG->enableavailability) {
$r_qiz->availablefrom = $r_cmod->availablefrom;
$r_qiz->availableuntil = $r_cmod->availableuntil;
if ($r_qiz->availableuntil) {
$r_qiz->availableuntil = strtotime("23:59:59", $r_qiz->availableuntil);
}
$r_qiz->showavailability = $r_cmod->showavailability;
}
$r_its = grade_item::fetch_all(array('itemtype' => 'mod', 'itemmodule' => $r_qiz->modulename, 'iteminstance' => $r_qiz->instance, 'courseid' => $r_cid));
if ($r_its) {
foreach ($r_its as $r_it) {
if (!empty($r_it->outcomeid)) {
$r_qiz->{'outcome_' . $r_it->outcomeid} = 1;
}
}
$r_gc = false;
foreach ($r_its as $r_it) {
if ($r_gc === false) {
$r_gc = $r_it->categoryid;
continue;
}
if ($r_gc != $r_it->categoryid) {
$r_gc = false;
break;
}
}
if ($r_gc !== false) {
$r_qiz->gradecat = $r_gc;
}
}
if ($r_imp) {
RWSIQSet($r_qiz, $r_sn, $r_sd, $r_ecd);
}
$DB->update_record("course_modules", $r_qiz);
if (is_null($r_qiz->quizpassword) && !is_null($r_qiz->password)) {
$r_qiz->quizpassword = $r_qiz->password;
}
$r_res = quiz_update_instance($r_qiz);
if (!$r_res || is_string($r_res)) {
RWSSErr("2081");
}
RWSSLBSet($r_qiz);
set_coursemodule_visible($r_qzmi, $r_qiz->visible);
if (isset($r_qiz->cmidnumber)) {
set_coursemodule_idnumber($r_qzmi, $r_qiz->cmidnumber);
}
RWSUQGrades($r_qiz);
if ($r_cpl->is_enabled() && !empty($r_qiz->completionunlocked)) {
$r_cpl->reset_all_state($r_qiz);
}
if (respondusws_floatcompare($CFG->version, 2014051200, 2) >= 0) {
$r_qiz->modname = $r_qiz->modulename;
$r_qiz->id = $r_qiz->coursemodule;
\core\event\course_module_updated::create_from_cm($r_qiz)->trigger();
} else {
$r_evt = new stdClass();
$r_evt->modulename = $r_qiz->modulename;
$r_evt->name = $r_qiz->name;
$r_evt->cmid = $r_qiz->coursemodule;
$r_evt->courseid = $r_qiz->course;
$r_evt->userid = $RWSUID;
events_trigger("mod_updated", $r_evt);
}
rebuild_course_cache($r_cid);
grade_regrade_final_grades($r_cid);
if ($RWSLB->mex || $RWSLB->bex) {
if ($RWSLB->mok) {
if ($RWSLB->perr) {
RWSSWarn("3003");
}
} else {
if ($RWSLB->bok) {
if ($RWSLB->perr) {
RWSSWarn("3003");
}
} else {
RWSSWarn("3001");
}
}
} else {
RWSSWarn("3000");
}
RWSSStat("1004");
}
示例14: test_get_calendar_events
//.........这里部分代码省略.........
foreach ($events['events'] as $event) {
if (!empty($event['description'])) {
$withdescription++;
$this->assertContains($expectedurl, $event['description']);
}
}
$this->assertEquals(2, $withdescription);
// Let's play around with caps.
$this->setUser($user);
$events = core_calendar_external::get_calendar_events($paramevents, $options);
$events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
$this->assertEquals(2, count($events['events']));
// site, user.
$this->assertEquals(2, count($events['warnings']));
// course, group.
$role = $DB->get_record('role', array('shortname' => 'student'));
$this->getDataGenerator()->enrol_user($user->id, $course->id, $role->id);
$events = core_calendar_external::get_calendar_events($paramevents, $options);
$events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
$this->assertEquals(4, count($events['events']));
// site, user, both course events.
$this->assertEquals(1, count($events['warnings']));
// group.
$options = array('siteevents' => true, 'userevents' => true, 'timeend' => time() + HOURSECS);
$events = core_calendar_external::get_calendar_events($paramevents, $options);
$events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
$this->assertEquals(3, count($events['events']));
// site, user, one course event.
$this->assertEquals(1, count($events['warnings']));
// group.
groups_add_member($group, $user);
$events = core_calendar_external::get_calendar_events($paramevents, $options);
$events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
$this->assertEquals(4, count($events['events']));
// site, user, group, one course event.
$this->assertEquals(0, count($events['warnings']));
$paramevents = array('courseids' => array($course->id), 'groupids' => array($group->id));
$events = core_calendar_external::get_calendar_events($paramevents, $options);
$events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
$this->assertEquals(4, count($events['events']));
// site, user, group, one course event.
$this->assertEquals(0, count($events['warnings']));
$paramevents = array('groupids' => array($group->id, 23));
$events = core_calendar_external::get_calendar_events($paramevents, $options);
$events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
$this->assertEquals(3, count($events['events']));
// site, user, group.
$this->assertEquals(1, count($events['warnings']));
$paramevents = array('courseids' => array(23));
$events = core_calendar_external::get_calendar_events($paramevents, $options);
$events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
$this->assertEquals(2, count($events['events']));
// site, user.
$this->assertEquals(1, count($events['warnings']));
$paramevents = array();
$options = array('siteevents' => false, 'userevents' => false, 'timeend' => time() + 7 * WEEKSECS);
$events = core_calendar_external::get_calendar_events($paramevents, $options);
$events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
$this->assertEquals(0, count($events['events']));
// nothing returned.
$this->assertEquals(0, count($events['warnings']));
$paramevents = array('eventids' => array($siteevent->id, $groupevent->id));
$options = array('siteevents' => false, 'userevents' => false, 'timeend' => time() + 7 * WEEKSECS);
$events = core_calendar_external::get_calendar_events($paramevents, $options);
$events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
$this->assertEquals(2, count($events['events']));
// site, group.
$this->assertEquals(0, count($events['warnings']));
$paramevents = array('eventids' => array($siteevent->id));
$events = core_calendar_external::get_calendar_events($paramevents, $options);
$events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
$this->assertEquals(1, count($events['events']));
// site.
$this->assertEquals(0, count($events['warnings']));
// Try getting a course event by its id.
$paramevents = array('eventids' => array($courseevent->id));
$events = core_calendar_external::get_calendar_events($paramevents, $options);
$events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
$this->assertEquals(1, count($events['events']));
$this->assertEquals(0, count($events['warnings']));
// Now, create an activity event.
$this->setAdminUser();
$nexttime = time() + DAYSECS;
$assign = $this->getDataGenerator()->create_module('assign', array('course' => $course->id, 'duedate' => $nexttime));
$this->setUser($user);
$paramevents = array('courseids' => array($course->id));
$options = array('siteevents' => true, 'userevents' => true, 'timeend' => time() + WEEKSECS);
$events = core_calendar_external::get_calendar_events($paramevents, $options);
$events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
$this->assertCount(5, $events['events']);
// Hide the assignment.
set_coursemodule_visible($assign->cmid, 0);
// Empty all the caches that may be affected by this change.
accesslib_clear_all_caches_for_unit_testing();
course_modinfo::clear_instance_cache();
$events = core_calendar_external::get_calendar_events($paramevents, $options);
$events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
// Expect one less.
$this->assertCount(4, $events['events']);
}
示例15: test_inject_rowspans
/**
* Tests grade_report_user::inject_rowspans()
*
* inject_rowspans() returns the count of the number of elements, sets maxdepth on the
* report object and sets the rowspan property on any element that has children.
*/
public function test_inject_rowspans()
{
global $CFG, $USER, $DB;
parent::setUp();
$this->resetAfterTest(true);
$CFG->enableavailability = 1;
$CFG->enablecompletion = 1;
// Create a course.
$course = $this->getDataGenerator()->create_course();
$coursecategory = grade_category::fetch_course_category($course->id);
$coursecontext = context_course::instance($course->id);
// Create and enrol test users.
$student = $this->getDataGenerator()->create_user(array('username' => 'Student Sam'));
$role = $DB->get_record('role', array('shortname' => 'student'), '*', MUST_EXIST);
$this->getDataGenerator()->enrol_user($student->id, $course->id, $role->id);
$teacher = $this->getDataGenerator()->create_user(array('username' => 'Teacher T'));
$role = $DB->get_record('role', array('shortname' => 'editingteacher'), '*', MUST_EXIST);
$this->getDataGenerator()->enrol_user($teacher->id, $course->id, $role->id);
// An array so we can test with both users in a loop.
$users = array($student, $teacher);
// Make the student the current user.
$this->setUser($student);
// Test an empty course.
$report = $this->create_report($course, $student, $coursecontext);
// a lead column that spans all children + course grade item = 2
$this->assertEquals(2, $report->inject_rowspans($report->gtree->top_element));
$this->assertEquals(2, $report->gtree->top_element['rowspan']);
$this->assertEquals(2, $report->maxdepth);
// Only elements with children should have rowspan set.
if (array_key_exists('rowspan', $report->gtree->top_element['children'][1])) {
$this->fail('Elements without children should not have rowspan set');
}
// Add 2 activities.
$data1 = $this->getDataGenerator()->create_module('data', array('assessed' => 1, 'scale' => 100, 'course' => $course->id));
$forum1 = $this->getDataGenerator()->create_module('forum', array('assessed' => 1, 'scale' => 100, 'course' => $course->id));
$forum1cm = get_coursemodule_from_id('forum', $forum1->cmid);
// Switch the stdClass instance for a grade item instance so grade_item::set_parent() is available.
$forum1 = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => 'forum', 'iteminstance' => $forum1->id, 'courseid' => $course->id));
$report = $this->create_report($course, $student, $coursecontext);
// Lead column + course + (2 x activity) = 4
$this->assertEquals(4, $report->inject_rowspans($report->gtree->top_element));
$this->assertEquals(4, $report->gtree->top_element['rowspan']);
// Lead column + 1 level (course + 2 activities) = 2
$this->assertEquals(2, $report->maxdepth);
// Only elements with children should have rowspan set.
if (array_key_exists('rowspan', $report->gtree->top_element['children'][1])) {
$this->fail('Elements without children should not have rowspan set');
}
// Hide the forum activity.
set_coursemodule_visible($forum1cm->id, 0);
foreach ($users as $user) {
$this->setUser($user);
$message = 'Testing with ' . $user->username;
accesslib_clear_all_caches_for_unit_testing();
$report = $this->create_report($course, $user, $coursecontext);
// Lead column + course + (2 x activity) = 4 (element count isn't affected by hiding)
$this->assertEquals(4, $report->inject_rowspans($report->gtree->top_element), $message);
$this->assertEquals(4, $report->gtree->top_element['rowspan'], $message);
// Lead column -> 1 level containing the course + 2 activities = 2
$this->assertEquals(2, $report->maxdepth, $message);
}
// Unhide the forum activity.
set_coursemodule_visible($forum1cm->id, 1);
// Create a category and put the forum in it.
$params = new stdClass();
$params->courseid = $course->id;
$params->fullname = 'unittestcategory';
$params->parent = $coursecategory->id;
$gradecategory = new grade_category($params, false);
$gradecategory->insert();
$forum1->set_parent($gradecategory->id);
$report = $this->create_report($course, $student, $coursecontext);
// Lead column + course + (category + category grade item) + (2 x activity) = 6
$this->assertEquals(6, $report->inject_rowspans($report->gtree->top_element));
$this->assertEquals(6, $report->gtree->top_element['rowspan']);
// Lead column -> the category -> the forum activity = 3
$this->assertEquals(3, $report->maxdepth);
// Check rowspan on the category. The category itself + category grade item + forum = 3
$this->assertEquals(3, $report->gtree->top_element['children'][4]['rowspan']);
// check the forum doesn't have rowspan set
if (array_key_exists('rowspan', $report->gtree->top_element['children'][4]['children'][3])) {
$this->fail('The forum has no children so should not have rowspan set');
}
// Conditional activity tests.
$DB->insert_record('course_modules_availability', (object) array('coursemoduleid' => $forum1cm->id, 'gradeitemid' => 37, 'grademin' => 5.5));
$cm = (object) array('id' => $forum1cm->id);
$test = new condition_info($cm, CONDITION_MISSING_EVERYTHING);
$fullcm = $test->get_full_course_module();
foreach ($users as $user) {
$this->setUser($user);
$message = 'Testing with ' . $user->username;
accesslib_clear_all_caches_for_unit_testing();
$report = $this->create_report($course, $user, $coursecontext);
// Lead column + course + (category + category grade item) + (2 x activity) = 6
//.........这里部分代码省略.........