本文整理汇总了PHP中context_module类的典型用法代码示例。如果您正苦于以下问题:PHP context_module类的具体用法?PHP context_module怎么用?PHP context_module使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了context_module类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* Run forum cron.
*/
public function execute()
{
global $DB, $CFG;
$currenttime = time();
$statement = 'SELECT R.* FROM {ratingallocate} AS R
LEFT JOIN {ratingallocate_allocations} AS A
ON R.' . this_db\ratingallocate::ID . '=A.' . this_db\ratingallocate_allocations::RATINGALLOCATEID . '
WHERE A.' . this_db\ratingallocate_allocations::ID . ' IS NULL AND R.' . this_db\ratingallocate::ACCESSTIMESTOP . '<' . $currenttime;
$records = $DB->get_records_sql($statement);
$course = null;
foreach ($records as $record) {
$cm = get_coursemodule_from_instance(this_db\ratingallocate::TABLE, $record->{this_db\ratingallocate::ID});
// Fetch the data for the course, if is has changed
if (!$course || $course->id != $record->{this_db\ratingallocate::COURSE}) {
$course = $DB->get_record('course', array('id' => $record->{this_db\ratingallocate::COURSE}), '*', MUST_EXIST);
}
// Create ratingallocate instance from record
$ratingallocate = new \ratingallocate($record, $course, $cm, \context_module::instance($cm->id));
$currenttime = time();
$timetoterminate = $CFG->ratingallocate_algorithm_timeout + $ratingallocate->ratingallocate->algorithmstarttime;
// If last execution exeeds timeout limit assume failure of algorithm run.
if ($ratingallocate->ratingallocate->algorithmstarttime && $currenttime >= $timetoterminate && $ratingallocate->get_algorithm_status() === \mod_ratingallocate\algorithm_status::running) {
$ratingallocate->set_algorithm_failed();
return true;
}
// Only start the algorithm, if it should be run by the cron and hasn't been started somehow, yet.
if ($ratingallocate->ratingallocate->runalgorithmbycron === "1" && $ratingallocate->get_algorithm_status() === \mod_ratingallocate\algorithm_status::notstarted) {
// Run allocation.
$ratingallocate->distrubute_choices();
}
}
return true;
}
示例2: test_imscp_view
/**
* Test imscp_view
* @return void
*/
public function test_imscp_view()
{
global $CFG;
$CFG->enablecompletion = 1;
$this->resetAfterTest();
$this->setAdminUser();
// Setup test data.
$course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1));
$imscp = $this->getDataGenerator()->create_module('imscp', array('course' => $course->id), array('completion' => 2, 'completionview' => 1));
$context = context_module::instance($imscp->cmid);
$cm = get_coursemodule_from_instance('imscp', $imscp->id);
// Trigger and capture the event.
$sink = $this->redirectEvents();
imscp_view($imscp, $course, $cm, $context);
$events = $sink->get_events();
// 2 additional events thanks to completion.
$this->assertCount(3, $events);
$event = array_shift($events);
// Checking that the event contains the expected values.
$this->assertInstanceOf('\\mod_imscp\\event\\course_module_viewed', $event);
$this->assertEquals($context, $event->get_context());
$moodleurl = new \moodle_url('/mod/imscp/view.php', array('id' => $cm->id));
$this->assertEquals($moodleurl, $event->get_url());
$this->assertEventContextNotUsed($event);
$this->assertNotEmpty($event->get_name());
// Check completion status.
$completion = new completion_info($course);
$completiondata = $completion->get_data($cm);
$this->assertEquals(1, $completiondata->completionstate);
}
示例3: imscp_htmllize_item
/**
* Internal function - creates htmls structure suitable for YUI tree.
*/
function imscp_htmllize_item($item, $imscp, $cm)
{
global $CFG;
if ($item['href']) {
if (preg_match('|^https?://|', $item['href'])) {
$url = $item['href'];
} else {
$context = context_module::instance($cm->id);
$urlbase = "{$CFG->wwwroot}/pluginfile.php";
$path = '/' . $context->id . '/mod_imscp/content/' . $imscp->revision . '/' . $item['href'];
$url = file_encode_url($urlbase, $path, false);
}
$result = "<li><a href=\"{$url}\">" . $item['title'] . '</a>';
} else {
$result = '<li>' . $item['title'];
}
if ($item['subitems']) {
$result .= '<ul>';
foreach ($item['subitems'] as $subitem) {
$result .= imscp_htmllize_item($subitem, $imscp, $cm);
}
$result .= '</ul>';
}
$result .= '</li>';
return $result;
}
示例4: test_event_properties_guessing
public function test_event_properties_guessing()
{
global $USER;
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$forum = $this->getDataGenerator()->create_module('forum', array('course' => $course->id));
$context = context_module::instance($forum->cmid);
$event = \core_tests\event\unittest_executed::create(array('context' => $context, 'objectid' => 5));
// Check guessed course ID, and default properties.
$this->assertSame('\\core_tests\\event\\unittest_executed', $event->eventname);
$this->assertSame('core_tests', $event->component);
$this->assertSame('executed', $event->action);
$this->assertSame('unittest', $event->target);
$this->assertSame(5, $event->objectid);
$this->assertEquals($context, $event->get_context());
$this->assertEquals($course->id, $event->courseid);
$this->assertSame($USER->id, $event->userid);
$this->assertNull($event->relateduserid);
$user = $this->getDataGenerator()->create_user();
$context = context_user::instance($user->id);
$event = \core_tests\event\unittest_executed::create(array('contextid' => $context->id, 'objectid' => 5));
// Check guessing on contextid, and user context level.
$this->assertEquals($context, $event->get_context());
$this->assertEquals($context->id, $event->contextid);
$this->assertEquals($context->contextlevel, $event->contextlevel);
$this->assertSame(0, $event->courseid);
$this->assertSame($USER->id, $event->userid);
$this->assertSame($user->id, $event->relateduserid);
}
示例5: test_import_chapters_events
public function test_import_chapters_events()
{
$course = $this->getDataGenerator()->create_course();
$book = $this->getDataGenerator()->create_module('book', array('course' => $course->id));
$context = context_module::instance($book->cmid);
$record = new stdClass();
$record->contextid = $context->id;
$record->component = 'phpunit';
$record->filearea = 'test';
$record->itemid = 0;
$record->filepath = '/';
$record->filename = 'chapters.zip';
$fs = get_file_storage();
$file = $fs->create_file_from_pathname($record, __DIR__ . '/fixtures/chapters.zip');
// Importing the chapters.
$sink = $this->redirectEvents();
toolbook_importhtml_import_chapters($file, 2, $book, $context, false);
$events = $sink->get_events();
// Checking the results.
$this->assertCount(5, $events);
foreach ($events as $event) {
$this->assertInstanceOf('\\mod_book\\event\\chapter_created', $event);
$this->assertEquals($context, $event->get_context());
$chapter = $event->get_record_snapshot('book_chapters', $event->objectid);
$this->assertNotEmpty($chapter);
$this->assertEventContextNotUsed($event);
}
}
示例6: test_book_exported
public function test_book_exported() {
// There is no proper API to call to test the event, so what we are
// doing here is simply making sure that the events returns the right information.
$course = $this->getDataGenerator()->create_course();
$book = $this->getDataGenerator()->create_module('book', array('course' => $course->id));
$params = array(
'context' => context_module::instance($book->cmid),
'objectid' => $book->id
);
$event = \booktool_exportimscp\event\book_exported::create($params);
// Triggering and capturing the event.
$sink = $this->redirectEvents();
$event->trigger();
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
// Checking that the event contains the expected values.
$this->assertInstanceOf('\booktool_exportimscp\event\book_exported', $event);
$this->assertEquals(context_module::instance($book->cmid), $event->get_context());
$this->assertEquals($book->id, $event->objectid);
$expected = array($course->id, 'book', 'exportimscp', 'tool/exportimscp/index.php?id=' . $book->cmid,
$book->id, $book->cmid);
$this->assertEventLegacyLogData($expected, $event);
$this->assertEventContextNotUsed($event);
}
示例7: test_generator
public function test_generator()
{
global $DB;
$this->resetAfterTest(true);
$this->assertEquals(0, $DB->count_records('forum'));
$course = $this->getDataGenerator()->create_course();
/** @var mod_forum_generator $generator */
$generator = $this->getDataGenerator()->get_plugin_generator('mod_forum');
$this->assertInstanceOf('mod_forum_generator', $generator);
$this->assertEquals('forum', $generator->get_modulename());
$generator->create_instance(array('course' => $course->id));
$generator->create_instance(array('course' => $course->id));
$forum = $generator->create_instance(array('course' => $course->id));
$this->assertEquals(3, $DB->count_records('forum'));
$cm = get_coursemodule_from_instance('forum', $forum->id);
$this->assertEquals($forum->id, $cm->instance);
$this->assertEquals('forum', $cm->modname);
$this->assertEquals($course->id, $cm->course);
$context = context_module::instance($cm->id);
$this->assertEquals($forum->cmid, $context->instanceid);
// test gradebook integration using low level DB access - DO NOT USE IN PLUGIN CODE!
$forum = $generator->create_instance(array('course' => $course->id, 'assessed' => 1, 'scale' => 100));
$gitem = $DB->get_record('grade_items', array('courseid' => $course->id, 'itemtype' => 'mod', 'itemmodule' => 'forum', 'iteminstance' => $forum->id));
$this->assertNotEmpty($gitem);
$this->assertEquals(100, $gitem->grademax);
$this->assertEquals(0, $gitem->grademin);
$this->assertEquals(GRADE_TYPE_VALUE, $gitem->gradetype);
}
示例8: __construct
/**
* Constructor - instantiates one object of this class
*/
public function __construct($name, $blockid, $moduleid = null, $plan = null)
{
global $DB;
// Check blockid exists
if (!($block = $DB->get_record('block_instances', array('id' => $blockid)))) {
throw new backup_task_exception('block_task_block_instance_not_found', $blockid);
}
$this->blockid = $blockid;
$this->blockname = $block->blockname;
$this->contextid = context_block::instance($this->blockid)->id;
$this->moduleid = $moduleid;
$this->modulename = null;
$this->parentcontextid = null;
// If moduleid passed, check exists, supports moodle2 format and save info
// Check moduleid exists
if (!empty($moduleid)) {
if (!($coursemodule = get_coursemodule_from_id(false, $moduleid))) {
throw new backup_task_exception('block_task_coursemodule_not_found', $moduleid);
}
// Check activity supports this moodle2 backup format
if (!plugin_supports('mod', $coursemodule->modname, FEATURE_BACKUP_MOODLE2)) {
throw new backup_task_exception('block_task_activity_lacks_moodle2_backup_support', $coursemodule->modname);
}
$this->moduleid = $moduleid;
$this->modulename = $coursemodule->modname;
$this->parentcontextid = context_module::instance($this->moduleid)->id;
}
parent::__construct($name, $plan);
}
示例9: create_content
public function create_content($glossary, $record = array(), $aliases = array())
{
global $DB, $USER, $CFG;
$this->entrycount++;
$now = time();
$record = (array) $record + array('glossaryid' => $glossary->id, 'timecreated' => $now, 'timemodified' => $now, 'userid' => $USER->id, 'concept' => 'Glossary entry ' . $this->entrycount, 'definition' => 'Definition of glossary entry ' . $this->entrycount, 'definitionformat' => FORMAT_MOODLE, 'definitiontrust' => 0, 'usedynalink' => $CFG->glossary_linkentries, 'casesensitive' => $CFG->glossary_casesensitive, 'fullmatch' => $CFG->glossary_fullmatch);
if (!isset($record['teacherentry']) || !isset($record['approved'])) {
$context = context_module::instance($glossary->cmid);
if (!isset($record['teacherentry'])) {
$record['teacherentry'] = has_capability('mod/glossary:manageentries', $context, $record['userid']);
}
if (!isset($record['approved'])) {
$defaultapproval = $glossary->defaultapproval;
$record['approved'] = $defaultapproval || has_capability('mod/glossary:approve', $context);
}
}
$id = $DB->insert_record('glossary_entries', $record);
if ($aliases) {
foreach ($aliases as $alias) {
$ar = new stdClass();
$ar->entryid = $id;
$ar->alias = $alias;
$DB->insert_record('glossary_alias', $ar);
}
}
return $DB->get_record('glossary_entries', array('id' => $id), '*', MUST_EXIST);
}
示例10: test_generator
public function test_generator()
{
global $DB, $SITE;
$this->resetAfterTest(true);
// Must be a non-guest user to create resources.
$this->setAdminUser();
// There are 0 resources initially.
$this->assertEquals(0, $DB->count_records('resource'));
// Create the generator object and do standard checks.
$generator = $this->getDataGenerator()->get_plugin_generator('mod_resource');
$this->assertInstanceOf('mod_resource_generator', $generator);
$this->assertEquals('resource', $generator->get_modulename());
// Create three instances in the site course.
$generator->create_instance(array('course' => $SITE->id));
$generator->create_instance(array('course' => $SITE->id));
$resource = $generator->create_instance(array('course' => $SITE->id));
$this->assertEquals(3, $DB->count_records('resource'));
// Check the course-module is correct.
$cm = get_coursemodule_from_instance('resource', $resource->id);
$this->assertEquals($resource->id, $cm->instance);
$this->assertEquals('resource', $cm->modname);
$this->assertEquals($SITE->id, $cm->course);
// Check the context is correct.
$context = context_module::instance($cm->id);
$this->assertEquals($resource->cmid, $context->instanceid);
// Check that generated resource module contains a file.
$fs = get_file_storage();
$files = $fs->get_area_files($context->id, 'mod_resource', 'content', false, '', false);
$this->assertEquals(1, count($files));
}
示例11: showListOfLinks
function showListOfLinks($id, $resop)
{
global $OUTPUT, $DB;
//need it to check capability
$cm = get_coursemodule_from_id('resop', $id, 0, false, MUST_EXIST);
$context = context_module::instance($cm->id);
echo $OUTPUT->heading(get_string('entries', 'resop'), 4);
echo $OUTPUT->action_link(new moodle_url('view.php', array('id' => $id, 'action' => 'showAll')), get_string('showall', 'resop'));
// Required
//linkliste Klassen/Resources - specific for this resop instance
$text = $resop->type == 'typeexam' ? get_string('resExam', 'resop') : get_string('resFree', 'resop');
echo $OUTPUT->heading($text, 4);
$resources = $DB->get_records_sql('SELECT DISTINCT name FROM {resop_resource_user} ru JOIN {resop_resource} rr ' . " ON ru.resid=rr.id WHERE ru.actid={$resop->id} ORDER BY name");
//ok, should only be the resources which are handled in this resop instance
foreach ($resources as $key => $value) {
echo $OUTPUT->action_link(new moodle_url('view.php', array('id' => $id, 'action' => 'showClass', 'class' => $key)), $key);
// Required
echo " ";
}
//link list owner over all instances of resop modul
if (has_capability('mod/resop:book', $context)) {
echo $OUTPUT->heading(get_string('bookedby_header', 'resop'), 4);
$resources = $DB->get_records_sql('SELECT DISTINCT name FROM {resop_resource_user} ru JOIN {resop_resop_user} rru ' . 'on ru.uid = rru.uid JOIN {resop_user} u on ru.uid=u.id ORDER BY name');
foreach ($resources as $key => $value) {
echo $OUTPUT->action_link(new moodle_url('view.php', array('id' => $id, 'action' => 'showBooker', 'name' => $key)), $key);
echo " ";
}
}
}
示例12: create_without_groupid
/**
* Convenience method to create event object from data when grading group without knowledge of the groups id
*
* @param \stdClass $cm course module object
* @param \stdClass $data grading data to log
* @return \mod_grouptool\group_graded event object
*/
public static function create_without_groupid(\stdClass $cm, \stdClass $data)
{
// Trigger overview event.
$data->type = 'users';
$event = self::create(array('objectid' => $cm->instance, 'context' => \context_module::instance($cm->id), 'other' => (array) $data));
return $event;
}
示例13: test_create_instance
public function test_create_instance()
{
global $DB;
$this->resetAfterTest(true);
$course = $this->getDataGenerator()->create_course();
$this->assertFalse($DB->record_exists('questionnaire', array('course' => $course->id)));
/** @var mod_questionnaire_generator $generator */
$generator = $this->getDataGenerator()->get_plugin_generator('mod_questionnaire');
$this->assertInstanceOf('mod_questionnaire_generator', $generator);
$this->assertEquals('questionnaire', $generator->get_modulename());
$questionnaire = $generator->create_instance(array('course' => $course->id));
$this->assertEquals(1, $DB->count_records('questionnaire'));
$cm = get_coursemodule_from_instance('questionnaire', $questionnaire->id);
$this->assertEquals($questionnaire->id, $cm->instance);
$this->assertEquals('questionnaire', $cm->modname);
$this->assertEquals($course->id, $cm->course);
$context = context_module::instance($cm->id);
$this->assertEquals($questionnaire->cmid, $context->instanceid);
$survey = $DB->get_record('questionnaire_survey', array('id' => $questionnaire->sid));
$this->assertEquals($survey->id, $questionnaire->sid);
$this->assertEquals($questionnaire->name, $survey->name);
$this->assertEquals($questionnaire->name, $survey->title);
// Should test creating a public questionnaire, template questionnaire and creating one from a template.
// Should test event creation if open dates and close dates are specified?
}
示例14: definition
public function definition()
{
$mform = $this->_form;
$currententry = $this->_customdata['current'];
$publication = $this->_customdata['publication'];
$cm = $this->_customdata['cm'];
$definitionoptions = $this->_customdata['definitionoptions'];
$attachmentoptions = $this->_customdata['attachmentoptions'];
$context = context_module::instance($cm->id);
// Prepare format_string/text options.
$fmtoptions = array('context' => $context);
if ($publication->get_instance()->obtainteacherapproval) {
$text = get_string('published_aftercheck', 'publication');
} else {
$text = get_string('published_immediately', 'publication');
}
$mform->addElement('header', 'myfiles', get_string('myfiles', 'publication'));
$mform->addElement('static', 'guideline', get_string('guideline', 'publication'), $text);
$mform->addElement('filemanager', 'attachment_filemanager', '', null, $attachmentoptions);
// Hidden params.
$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);
$mform->addElement('hidden', 'cmid');
$mform->setType('cmid', PARAM_INT);
// Buttons.
$this->add_action_buttons(true, get_string('save_changes', 'publication'));
$this->set_data($currententry);
}
示例15: create_instance
function create_instance()
{
// Include module lib
$modlib = '../../mod/' . $this->module_name() . '/lib.php';
if (file_exists($modlib)) {
global $CFG;
require_once $modlib;
} else {
return array(false, 'Module lib not found');
}
$ret = $this->set_module_instance_params();
if (!$ret[0]) {
return $ret;
}
// Add instance and update course_modules DB row
$addinstancefunction = $this->module_name() . '_add_instance';
if ($this->get_num_instance_function_params() == 1) {
$returnfromfunc = $addinstancefunction($this->moduleobj);
} else {
$returnfromfunc = $addinstancefunction($this->moduleobj, true);
}
if (!$returnfromfunc or !is_number($returnfromfunc)) {
// undo everything we can
$modcontext = context_module::instance($this->moduleobj->coursemodule);
$modcontext->delete();
$DB->delete_records('course_modules', array('id' => $this->moduleobj->coursemodule));
if (!is_number($returnfromfunc)) {
return array(false, "{$addinstancefunction} is not a valid function");
} else {
return array(false, 'Cannot add new module');
}
}
$this->moduleobj->instance = $returnfromfunc;
return array(true, '');
}