本文整理汇总了PHP中get_coursemodule_from_instance函数的典型用法代码示例。如果您正苦于以下问题:PHP get_coursemodule_from_instance函数的具体用法?PHP get_coursemodule_from_instance怎么用?PHP get_coursemodule_from_instance使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_coursemodule_from_instance函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onreject
/**
* Action called on reject of a face to face action
*
* @param array $eventdata
* @param object $msg
*/
function onreject($eventdata, $msg) {
global $DB;
// can manipulate the language by setting $SESSION->lang temporarily
// Load course
$userid = $eventdata['userid'];
$session = $eventdata['session'];
$facetoface = $eventdata['facetoface'];
if (!$course = $DB->get_record('course', array('id' => $facetoface->course))) {
print_error('error:coursemisconfigured', 'facetoface');
return false;
}
if (!$cm = get_coursemodule_from_instance('facetoface', $facetoface->id, $course->id)) {
print_error('error:incorrectcoursemodule', 'facetoface');
return false;
}
$form = new stdClass();
$form->s = $session->id;
$form->requests = array($userid => 1); // 2 = approve, 1 = decline
error_log(var_export($form, true));
// Decline requests
if (facetoface_approve_requests($form)) {
add_to_log($course->id, 'facetoface', 'approve requests', "view.php?id=$cm->id", $facetoface->id, $cm->id);
}
// issue notification that registration has been declined
return $this->acceptreject_notification($userid, $facetoface, $session, 'status_declined');
}
示例2: assignment_delete_instance
/**
* Deletes an assignment instance
*
* @param $id
*/
function assignment_delete_instance($id)
{
global $CFG, $DB;
if (!($assignment = $DB->get_record('assignment', array('id' => $id)))) {
return false;
}
$result = true;
// Now get rid of all files
$fs = get_file_storage();
if ($cm = get_coursemodule_from_instance('assignment', $assignment->id)) {
$context = context_module::instance($cm->id);
$fs->delete_area_files($context->id);
}
if (!$DB->delete_records('assignment_submissions', array('assignment' => $assignment->id))) {
$result = false;
}
if (!$DB->delete_records('event', array('modulename' => 'assignment', 'instance' => $assignment->id))) {
$result = false;
}
if (!$DB->delete_records('assignment', array('id' => $assignment->id))) {
$result = false;
}
grade_update('mod/assignment', $assignment->course, 'mod', 'assignment', $assignment->id, 0, NULL, array('deleted' => 1));
return $result;
}
示例3: test_survey_view
/**
* Test survey_view
* @return void
*/
public function test_survey_view()
{
global $CFG;
$CFG->enablecompletion = 1;
$this->resetAfterTest();
$this->setAdminUser();
// Setup test data.
$course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1));
$survey = $this->getDataGenerator()->create_module('survey', array('course' => $course->id), array('completion' => 2, 'completionview' => 1));
$context = context_module::instance($survey->cmid);
$cm = get_coursemodule_from_instance('survey', $survey->id);
// Trigger and capture the event.
$sink = $this->redirectEvents();
survey_view($survey, $course, $cm, $context, 'form');
$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_survey\\event\\course_module_viewed', $event);
$this->assertEquals($context, $event->get_context());
$moodleurl = new \moodle_url('/mod/survey/view.php', array('id' => $cm->id));
$this->assertEquals($moodleurl, $event->get_url());
$this->assertEquals('form', $event->other['viewed']);
$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);
}
示例4: prepare_quiz_data
protected function prepare_quiz_data()
{
$this->resetAfterTest(true);
// Create a course
$course = $this->getDataGenerator()->create_course();
// Make a quiz.
$quizgenerator = $this->getDataGenerator()->get_plugin_generator('mod_quiz');
$quiz = $quizgenerator->create_instance(array('course' => $course->id, 'questionsperpage' => 0, 'grade' => 100.0, 'sumgrades' => 2));
$cm = get_coursemodule_from_instance('quiz', $quiz->id, $course->id);
// Create a couple of questions.
$questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
$cat = $questiongenerator->create_question_category();
$saq = $questiongenerator->create_question('shortanswer', null, array('category' => $cat->id));
$numq = $questiongenerator->create_question('numerical', null, array('category' => $cat->id));
// Add them to the quiz.
quiz_add_quiz_question($saq->id, $quiz);
quiz_add_quiz_question($numq->id, $quiz);
// Make a user to do the quiz.
$user1 = $this->getDataGenerator()->create_user();
$this->setUser($user1);
$quizobj = quiz::create($quiz->id, $user1->id);
// Start the attempt.
$quba = question_engine::make_questions_usage_by_activity('mod_quiz', $quizobj->get_context());
$quba->set_preferred_behaviour($quizobj->get_quiz()->preferredbehaviour);
$timenow = time();
$attempt = quiz_create_attempt($quizobj, 1, false, $timenow);
quiz_start_new_attempt($quizobj, $quba, $attempt, 1, $timenow);
quiz_attempt_save_started($quizobj, $quba, $attempt);
return array($quizobj, $quba, $attempt);
}
示例5: setup_page
/**
* set up the class for the view page
*
* @param string $baseurl the base url of the page
*/
public function setup_page($baseurl)
{
global $PAGE, $CFG, $DB;
$this->pagevars = array();
$this->pageurl = new \moodle_url($baseurl);
$this->pageurl->remove_all_params();
$id = optional_param('id', false, PARAM_INT);
$quizid = optional_param('quizid', false, PARAM_INT);
// get necessary records from the DB
if ($id) {
$cm = get_coursemodule_from_id('activequiz', $id, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$quiz = $DB->get_record('activequiz', array('id' => $cm->instance), '*', MUST_EXIST);
} else {
$quiz = $DB->get_record('activequiz', array('id' => $quizid), '*', MUST_EXIST);
$course = $DB->get_record('course', array('id' => $quiz->course), '*', MUST_EXIST);
$cm = get_coursemodule_from_instance('activequiz', $quiz->id, $course->id, false, MUST_EXIST);
}
$this->get_parameters();
// get the rest of the parameters and set them in the class
require_login($course->id, false, $cm);
$this->pageurl->param('id', $cm->id);
$this->pageurl->param('quizid', $quiz->id);
$this->pageurl->param('action', $this->pagevars['action']);
$this->pagevars['pageurl'] = $this->pageurl;
$this->RTQ = new \mod_activequiz\activequiz($cm, $course, $quiz, $this->pagevars);
$this->RTQ->require_capability('mod/activequiz:seeresponses');
// set up renderer
$this->RTQ->get_renderer()->init($this->RTQ, $this->pageurl, $this->pagevars);
$PAGE->set_pagelayout('incourse');
$PAGE->set_context($this->RTQ->getContext());
$PAGE->set_title(strip_tags($course->shortname . ': ' . get_string("modulename", "activequiz") . ': ' . format_string($quiz->name, true)));
$PAGE->set_heading($course->fullname);
$PAGE->set_url($this->pageurl);
}
示例6: makeMailText
/**
* Builds and returns the body of the email notification in plain text.
*
* @param object $post
* @param object $userto
* @return string The email body in plain text format.
*/
public function makeMailText($post, $userto)
{
global $CFG, $cm;
$praxe = praxe_record::getData();
if (!isset($userto->viewfullnames[$praxe->id])) {
if (!($cm = get_coursemodule_from_instance('praxe', $praxe->id, $this->course->id))) {
print_error('Course Module ID was incorrect');
}
$modcontext = context_module::instance($cm->id);
$viewfullnames = has_capability('moodle/site:viewfullnames', $modcontext, $userto->id);
} else {
$viewfullnames = $userto->viewfullnames[$praxe->id];
}
//$by = New stdClass;
//$by->name = fullname($userfrom, $viewfullnames);
//$by->date = userdate($post->modified, "", $userto->timezone);
//$strbynameondate = get_string('bynameondate', 'forum', $by);
$strpraxes = get_string('modulenameplural', 'praxe');
$posttext = '';
$posttext = $this->course->shortname . " -> " . $strpraxes . " -> " . format_string($praxe->name, true);
$posttext .= "\n---------------------------------------------------------------------\n";
$posttext .= format_string($this->subject, true);
//$posttext .= "\n".$strbynameondate."\n";
$posttext .= "\n---------------------------------------------------------------------\n";
$posttext .= format_text_email(trusttext_strip($post), FORMAT_PLAIN);
$posttext .= "\n\n---------------------------------------------------------------------\n";
$site = get_site();
foreach ($this->linkstofoot as $link) {
$posttext .= $link->text . ": " . $link->link . "\t";
//$posttext .= get_string('confirmorrefusestudent','praxe').": ".$CFG->wwwroot.'/course/view.php?id='.$cm->id."\n\n";
}
$posttext .= "\n\n" . $site->shortname . ": " . $CFG->wwwroot . "\n";
return $posttext;
}
示例7: qcreate_student_q_access_sync
/**
* Called from cron and update_instance. Not called from add_instance as the contexts are not set up yet.
*/
function qcreate_student_q_access_sync($qcreate, $cmcontext = null, $course = null, $forcesync = false)
{
//check if a check is needed
$timenow = time();
$activityopen = ($qcreate->timeopen == 0 || $qcreate->timeopen < $timenow) && ($qcreate->timeclose == 0 || $qcreate->timeclose > $timenow);
$activitywasopen = ($qcreate->timeopen == 0 || $qcreate->timeopen < $qcreate->timesync) && ($qcreate->timeclose == 0 || $qcreate->timeclose > $qcreate->timesync);
$needsync = empty($qcreate->timesync) || $activitywasopen != $activityopen;
if ($forcesync || $needsync) {
if ($cmcontext == null) {
$cm = get_coursemodule_from_instance('qcreate', $qcreate->id);
$cmcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
}
if ($course == null) {
$course = get_record('course', 'id', $qcreate->course);
}
$studentrole = get_default_course_role($course);
if ($activityopen) {
$capabilitiestoassign = array(0 => array('moodle/question:add' => 1, 'moodle/question:usemine' => -1, 'moodle/question:viewmine' => -1, 'moodle/question:editmine' => -1), 1 => array('moodle/question:add' => 1, 'moodle/question:usemine' => 1, 'moodle/question:viewmine' => -1, 'moodle/question:editmine' => -1), 2 => array('moodle/question:add' => 1, 'moodle/question:usemine' => 1, 'moodle/question:viewmine' => 1, 'moodle/question:editmine' => -1), 3 => array('moodle/question:add' => 1, 'moodle/question:usemine' => 1, 'moodle/question:viewmine' => 1, 'moodle/question:editmine' => 1));
foreach ($capabilitiestoassign[$qcreate->studentqaccess] as $capability => $permission) {
assign_capability($capability, $permission, $studentrole->id, $cmcontext->id, true);
}
} else {
$capabilitiestounassign = array('moodle/question:add', 'moodle/question:usemine', 'moodle/question:viewmine', 'moodle/question:editmine');
foreach ($capabilitiestounassign as $capability) {
unassign_capability($capability, $studentrole->id, $cmcontext->id);
}
}
set_field('qcreate', 'timesync', $timenow, 'id', $qcreate->id);
}
}
示例8: can_annotate
/**
* Figure out whether annotation is permitted here
*/
function can_annotate($url)
{
global $USER, $miagloberror;
$miagloberror = "none";
if (isguestuser() or !isloggedin()) {
$miagloberror = "not logged in";
return false;
}
$handler = annotation_summary_query::handler_for_url($url);
if (!$handler) {
$miagloberror = "not on this page " . $url;
return false;
}
$handler->fetch_metadata();
if ($handler->modulename && $handler->courseid) {
$cm = get_coursemodule_from_instance($handler->modulename, $handler->modinstanceid, $handler->courseid);
if ($cm) {
$modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
if (!$handler->capannotate) {
$miagloberror = "never on this resource";
return false;
// annotation of this resource is never permitted
} else {
return has_capability($handler->capannotate, $modcontext);
}
} else {
$miagloberror = "no cm";
return false;
}
} else {
$miagloberror = "no handler";
return false;
}
}
示例9: update_overdue_attempts
/**
* Do the processing required.
* @param int $timenow the time to consider as 'now' during the processing.
* @param int $processfrom the value of $processupto the last time update_overdue_attempts was
* called called and completed successfully.
* @param int $processto only process attempt modifed longer ago than this.
*/
public function update_overdue_attempts($timenow, $processfrom, $processto) {
global $DB;
$attemptstoprocess = $this->get_list_of_overdue_attempts($processfrom, $processto);
$course = null;
$quiz = null;
$cm = null;
foreach ($attemptstoprocess as $attempt) {
// If we have moved on to a different quiz, fetch the new data.
if (!$quiz || $attempt->quiz != $quiz->id) {
$quiz = $DB->get_record('quiz', array('id' => $attempt->quiz), '*', MUST_EXIST);
$cm = get_coursemodule_from_instance('quiz', $attempt->quiz);
}
// If we have moved on to a different course, fetch the new data.
if (!$course || $course->id != $quiz->course) {
$course = $DB->get_record('course', array('id' => $quiz->course), '*', MUST_EXIST);
}
// Make a specialised version of the quiz settings, with the relevant overrides.
$quizforuser = clone($quiz);
$quizforuser->timeclose = $attempt->usertimeclose;
$quizforuser->timelimit = $attempt->usertimelimit;
// Trigger any transitions that are required.
$attemptobj = new quiz_attempt($attempt, $quizforuser, $cm, $course);
$attemptobj->handle_if_time_expired($timenow, false);
}
$attemptstoprocess->close();
}
示例10: test_generator
public function test_generator()
{
global $DB, $SITE;
$this->resetAfterTest(true);
// Must be a non-guest user to create forums.
$this->setAdminUser();
// There are 0 forums initially.
$this->assertEquals(0, $DB->count_records('forumng'));
// Create a course.
$course = $this->getDataGenerator()->create_course();
// Create the generator object and do standard checks.
$generator = $this->getDataGenerator()->get_plugin_generator('mod_forumng');
$this->assertInstanceOf('mod_forumng_generator', $generator);
$this->assertEquals('forumng', $generator->get_modulename());
// Create three forum instances in the site course.
$generator->create_instance(array('course' => $SITE->id));
$generator->create_instance(array('course' => $SITE->id));
$forum = $generator->create_instance(array('course' => $SITE->id));
$this->assertEquals(3, $DB->count_records('forumng'));
// Check the course-module is correct.
$cm = get_coursemodule_from_instance('forumng', $forum->id);
$this->assertEquals($forum->id, $cm->instance);
$this->assertEquals('forumng', $cm->modname);
$this->assertEquals($SITE->id, $cm->course);
// Check the context is correct.
$context = context_module::instance($cm->id);
$this->assertEquals($forum->cmid, $context->instanceid);
}
示例11: test_postdate
/**
* Test for the forum email renderable postdate.
*
* @dataProvider postdate_provider
*
* @param array $globalconfig The configuration to set on $CFG
* @param array $forumconfig The configuration for this forum
* @param array $postconfig The configuration for this post
* @param array $discussionconfig The configuration for this discussion
* @param string $expectation The expected date
*/
public function test_postdate($globalconfig, $forumconfig, $postconfig, $discussionconfig, $expectation)
{
global $CFG, $DB;
$this->resetAfterTest(true);
// Apply the global configuration.
foreach ($globalconfig as $key => $value) {
$CFG->{$key} = $value;
}
// Create the fixture.
$user = $this->getDataGenerator()->create_user();
$course = $this->getDataGenerator()->create_course();
$forum = $this->getDataGenerator()->create_module('forum', (object) array('course' => $course->id));
$cm = get_coursemodule_from_instance('forum', $forum->id, $course->id, false, MUST_EXIST);
$this->getDataGenerator()->enrol_user($user->id, $course->id);
// Create a new discussion.
$discussion = $this->getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion((object) array_merge($discussionconfig, array('course' => $course->id, 'forum' => $forum->id, 'userid' => $user->id)));
// Apply the discussion configuration.
// Some settings are ignored by the generator and must be set manually.
$discussion = $DB->get_record('forum_discussions', array('id' => $discussion->id));
foreach ($discussionconfig as $key => $value) {
$discussion->{$key} = $value;
}
$DB->update_record('forum_discussions', $discussion);
// Apply the post configuration.
// Some settings are ignored by the generator and must be set manually.
$post = $DB->get_record('forum_posts', array('discussion' => $discussion->id));
foreach ($postconfig as $key => $value) {
$post->{$key} = $value;
}
$DB->update_record('forum_posts', $post);
// Create the renderable.
$renderable = new mod_forum\output\forum_post_email($course, $cm, $forum, $discussion, $post, $user, $user, true);
// Check the postdate matches our expectations.
$this->assertEquals(userdate($expectation, "", \core_date::get_user_timezone($user)), $renderable->get_postdate());
}
示例12: test_assessable_uploaded
public function test_assessable_uploaded()
{
$this->resetAfterTest();
$user = $this->getDataGenerator()->create_user();
$course = $this->getDataGenerator()->create_course();
$generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
$params['course'] = $course->id;
$instance = $generator->create_instance($params);
$cm = get_coursemodule_from_instance('assign', $instance->id);
$context = context_module::instance($cm->id);
$assign = new testable_assign($context, $cm, $course);
$this->setUser($user->id);
$submission = $assign->get_user_submission($user->id, true);
$data = new stdClass();
$data->onlinetext_editor = array('itemid' => file_get_unused_draft_itemid(), 'text' => 'Submission text', 'format' => FORMAT_PLAIN);
$plugin = $assign->get_submission_plugin_by_type('onlinetext');
$sink = $this->redirectEvents();
$plugin->save($submission, $data);
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
$this->assertInstanceOf('\\assignsubmission_onlinetext\\event\\assessable_uploaded', $event);
$this->assertEquals($context->id, $event->contextid);
$this->assertEquals($submission->id, $event->objectid);
$this->assertEquals(array(), $event->other['pathnamehashes']);
$this->assertEquals('Submission text', $event->other['content']);
$expected = new stdClass();
$expected->modulename = 'assign';
$expected->cmid = $cm->id;
$expected->itemid = $submission->id;
$expected->courseid = $course->id;
$expected->userid = $user->id;
$expected->content = 'Submission text';
$this->assertEventLegacyData($expected, $event);
}
示例13: setup
/**
* Controller setup
*
* Get $cm and $instance and perform
* proper call to require_login()
*
* @return void
* @see $cm, $instance
* @throws coding_exception
*/
public function setup()
{
global $DB, $COURSE, $PAGE;
// Course module ID or module instance ID
$id = optional_param('id', 0, PARAM_INT);
$a = optional_param('a', 0, PARAM_INT);
// Get required course module record
if ($id) {
$this->cm = get_coursemodule_from_id($this->component, $id, 0, false, MUST_EXIST);
} else {
if ($a) {
$this->cm = get_coursemodule_from_instance($this->component, $a, 0, false, MUST_EXIST);
} else {
throw new coding_exception('No Course Module or Instance ID was passed');
}
}
// Get the module instance
$this->instance = $DB->get_record($this->component, array('id' => $this->cm->instance), '*', MUST_EXIST);
require_login($this->cm->course, true, $this->cm);
$PAGE->set_title(format_string($this->instance->name));
$PAGE->set_heading(format_string($COURSE->fullname));
$PAGE->set_activity_record($this->instance);
$PAGE->set_context($this->get_context());
$PAGE->set_url($this->new_url(array('action' => $this->action)));
$this->heading->text = format_string($this->instance->name);
}
示例14: zoom_get_instance_setup
/**
* Get course/cm/zoom objects from url parameters, and check for login/permissions.
*
* @return array Array of ($course, $cm, $zoom)
*/
function zoom_get_instance_setup()
{
global $DB;
$id = optional_param('id', 0, PARAM_INT);
// Course_module ID, or
$n = optional_param('n', 0, PARAM_INT);
// ... zoom instance ID - it should be named as the first character of the module.
if ($id) {
$cm = get_coursemodule_from_id('zoom', $id, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$zoom = $DB->get_record('zoom', array('id' => $cm->instance), '*', MUST_EXIST);
} else {
if ($n) {
$zoom = $DB->get_record('zoom', array('id' => $n), '*', MUST_EXIST);
$course = $DB->get_record('course', array('id' => $zoom->course), '*', MUST_EXIST);
$cm = get_coursemodule_from_instance('zoom', $zoom->id, $course->id, false, MUST_EXIST);
} else {
print_error('You must specify a course_module ID or an instance ID');
}
}
require_login($course, true, $cm);
$context = context_module::instance($cm->id);
require_capability('mod/zoom:view', $context);
return array($course, $cm, $zoom);
}
示例15: setup_page
/**
* Sets up the edit page
*
* @param string $baseurl the base url of the
*
* @return array Array of variables that the page is set up with
*/
public function setup_page($baseurl)
{
global $PAGE, $CFG, $DB;
$this->pagevars = array();
$pageurl = new \moodle_url($baseurl);
$pageurl->remove_all_params();
$id = optional_param('cmid', false, PARAM_INT);
$quizid = optional_param('quizid', false, PARAM_INT);
// get necessary records from the DB
if ($id) {
$cm = get_coursemodule_from_id('activequiz', $id, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$quiz = $DB->get_record('activequiz', array('id' => $cm->instance), '*', MUST_EXIST);
} else {
$quiz = $DB->get_record('activequiz', array('id' => $quizid), '*', MUST_EXIST);
$course = $DB->get_record('course', array('id' => $quiz->course), '*', MUST_EXIST);
$cm = get_coursemodule_from_instance('activequiz', $quiz->id, $course->id, false, MUST_EXIST);
}
$this->get_parameters();
// get the rest of the parameters and set them in the class
if ($CFG->version < 2011120100) {
$this->context = get_context_instance(CONTEXT_MODULE, $cm->id);
} else {
$this->context = \context_module::instance($cm->id);
}
// set up question lib
list($this->pageurl, $this->contexts, $cmid, $cm, $quiz, $this->pagevars) = question_edit_setup('editq', '/mod/activequiz/edit.php', true);
$PAGE->set_url($this->pageurl);
$this->pagevars['pageurl'] = $this->pageurl;
$PAGE->set_title(strip_tags($course->shortname . ': ' . get_string("modulename", "activequiz") . ': ' . format_string($quiz->name, true)));
$PAGE->set_heading($course->fullname);
// setup classes needed for the edit page
$this->RTQ = new \mod_activequiz\activequiz($cm, $course, $quiz, $this->pagevars);
$this->RTQ->get_renderer()->init($this->RTQ, $this->pageurl, $this->pagevars);
}