本文整理汇总了PHP中core_availability\info_module::get_user_list_sql方法的典型用法代码示例。如果您正苦于以下问题:PHP info_module::get_user_list_sql方法的具体用法?PHP info_module::get_user_list_sql怎么用?PHP info_module::get_user_list_sql使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core_availability\info_module
的用法示例。
在下文中一共展示了info_module::get_user_list_sql方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_filter_user_list
/**
* Tests the filter_user_list() and get_user_list_sql() functions.
*/
public function test_filter_user_list()
{
global $CFG, $DB;
require_once $CFG->dirroot . '/course/lib.php';
$this->resetAfterTest();
$CFG->enableavailability = true;
// Create a course with 2 sections and 2 pages and 3 users.
// Availability is set up initially on the 'page/section 2' items.
$generator = $this->getDataGenerator();
$course = $generator->create_course(array('numsections' => 2), array('createsections' => true));
$u1 = $generator->create_user();
$u2 = $generator->create_user();
$u3 = $generator->create_user();
$allusers = array($u1->id => $u1, $u2->id => $u2, $u3->id => $u3);
$generator->enrol_user($u1->id, $course->id);
$generator->enrol_user($u2->id, $course->id);
$generator->enrol_user($u3->id, $course->id);
$pagegen = $generator->get_plugin_generator('mod_page');
$page = $pagegen->create_instance(array('course' => $course));
$page2 = $pagegen->create_instance(array('course' => $course, 'availability' => '{"op":"|","show":true,"c":[{"type":"mock","filter":[' . $u2->id . ',' . $u3->id . ']}]}'));
$modinfo = get_fast_modinfo($course);
$section = $modinfo->get_section_info(1);
$section2 = $modinfo->get_section_info(2);
$DB->set_field('course_sections', 'availability', '{"op":"|","show":true,"c":[{"type":"mock","filter":[' . $u1->id . ',' . $u2->id . ']}]}', array('id' => $section2->id));
moveto_module($modinfo->get_cm($page2->cmid), $section2);
// With no restrictions, returns full list.
$info = new info_module($modinfo->get_cm($page->cmid));
$this->assertEquals(array($u1->id, $u2->id, $u3->id), array_keys($info->filter_user_list($allusers)));
$this->assertEquals(array('', array()), $info->get_user_list_sql(true));
// Set an availability restriction in database for section 1.
// For the section we set it so it doesn't support filters; for the
// module we have a filter.
$DB->set_field('course_sections', 'availability', '{"op":"|","show":true,"c":[{"type":"mock","a":false}]}', array('id' => $section->id));
$DB->set_field('course_modules', 'availability', '{"op":"|","show":true,"c":[{"type":"mock","filter":[' . $u3->id . ']}]}', array('id' => $page->cmid));
rebuild_course_cache($course->id, true);
$modinfo = get_fast_modinfo($course);
// Now it should work (for the module).
$info = new info_module($modinfo->get_cm($page->cmid));
$expected = array($u3->id);
$this->assertEquals($expected, array_keys($info->filter_user_list($allusers)));
list($sql, $params) = $info->get_user_list_sql();
$result = $DB->get_fieldset_sql($sql, $params);
sort($result);
$this->assertEquals($expected, $result);
$info = new info_section($modinfo->get_section_info(1));
$this->assertEquals(array($u1->id, $u2->id, $u3->id), array_keys($info->filter_user_list($allusers)));
$this->assertEquals(array('', array()), $info->get_user_list_sql(true));
// With availability disabled, module returns full list too.
$CFG->enableavailability = false;
$info = new info_module($modinfo->get_cm($page->cmid));
$this->assertEquals(array($u1->id, $u2->id, $u3->id), array_keys($info->filter_user_list($allusers)));
$this->assertEquals(array('', array()), $info->get_user_list_sql(true));
// Check the other section...
$CFG->enableavailability = true;
$info = new info_section($modinfo->get_section_info(2));
$expected = array($u1->id, $u2->id);
$this->assertEquals($expected, array_keys($info->filter_user_list($allusers)));
list($sql, $params) = $info->get_user_list_sql(true);
$result = $DB->get_fieldset_sql($sql, $params);
sort($result);
$this->assertEquals($expected, $result);
// And the module in that section - which has combined the section and
// module restrictions.
$info = new info_module($modinfo->get_cm($page2->cmid));
$expected = array($u2->id);
$this->assertEquals($expected, array_keys($info->filter_user_list($allusers)));
list($sql, $params) = $info->get_user_list_sql(true);
$result = $DB->get_fieldset_sql($sql, $params);
sort($result);
$this->assertEquals($expected, $result);
}