• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

PHP get_coursemodule_from_instance函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中get_coursemodule_from_instance函数的典型用法代码示例。如果您正苦于以下问题:PHP get_coursemodule_from_instance函数的具体用法?PHP get_coursemodule_from_instance怎么用?PHP get_coursemodule_from_instance使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_coursemodule_from_instance函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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');
    }
开发者ID:narasimhaeabyas,项目名称:tataaiapro,代码行数:34,代码来源:workflow_facetoface.php


示例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;
}
开发者ID:evltuma,项目名称:moodle,代码行数:30,代码来源:lib.php


示例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);
 }
开发者ID:evltuma,项目名称:moodle,代码行数:35,代码来源:lib_test.php


示例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);
 }
开发者ID:EmmanuelYupit,项目名称:educursos,代码行数:30,代码来源:events_test.php


示例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);
 }
开发者ID:agarnav,项目名称:moodle-mod_activequiz,代码行数:40,代码来源:responses.php


示例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;
 }
开发者ID:jerab,项目名称:moodle-mod-praxe,代码行数:41,代码来源:mailing.php


示例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);
    }
}
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:33,代码来源:lib.php


示例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;
     }
 }
开发者ID:njorth,项目名称:marginalia,代码行数:37,代码来源:annotate.php


示例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();
    }
开发者ID:nicusX,项目名称:moodle,代码行数:40,代码来源:cronlib.php


示例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);
 }
开发者ID:ULCC-QMUL,项目名称:moodle-mod_forumng,代码行数:28,代码来源:generator_test.php


示例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());
 }
开发者ID:evltuma,项目名称:moodle,代码行数:46,代码来源:output_email_test.php


示例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);
 }
开发者ID:covex-nn,项目名称:moodle,代码行数:35,代码来源:events_test.php


示例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);
 }
开发者ID:bgao-ca,项目名称:moodle-local_mr,代码行数:36,代码来源:mod.php


示例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);
}
开发者ID:uofr,项目名称:moodle-mod_zoom,代码行数:30,代码来源:locallib.php


示例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);
 }
开发者ID:agarnav,项目名称:moodle-mod_activequiz,代码行数:42,代码来源:edit.php


示例16: test_get_forum

 /**
  * Tests getting forum object from id and cmid, inc clones.
  */
 public function test_get_forum()
 {
     $this->resetAfterTest();
     $course = $this->get_new_course();
     // Test get_from_id using test lib.
     $forum = $this->get_new_forumng($course->id, array('name' => 'TEST', 'intro' => 'abc123'));
     $cm = get_coursemodule_from_instance('forumng', $forum->get_id());
     // Check.
     $this->check_forum_settings($forum, $course, $cm);
     // Check get_from_cmid also works.
     $forum = mod_forumng::get_from_cmid($cm->id, mod_forumng::CLONE_DIRECT);
     $this->check_forum_settings($forum, $course, $cm);
     // Check clone.
     $forum1 = $this->get_new_forumng($course->id, array('name' => 'TEST', 'intro' => 'abc123', 'shared' => true, 'cmidnumber' => 'SF1'));
     $this->assertEmpty($forum1->get_clone_details());
     $this->assertTrue($forum1->is_shared());
     $course2 = $this->get_new_course();
     $forum2 = $this->get_new_forumng($course2->id, array('name' => 'TEST', 'usesharedgroup' => array('useshared' => true, 'originalcmidnumber' => 'SF1')));
     $this->assertTrue($forum2->is_shared());
     $this->assertEquals($forum1->get_course_module_id(), $forum2->get_course_module_id(true));
     $this->assertEquals($forum1->get_context()->id, $forum2->get_context(true)->id);
     $this->assertEquals($course2->id, $forum2->get_course()->id);
     $this->assertEquals($course->id, $forum2->get_course(true)->id);
     // Discrepancy between get_course_id() [returns original] and get_course()[returns clone].
     $this->assertEquals($course->id, $forum2->get_course_id());
     // Use another instance without clone set to test it knows it is a clone.
     $forum3 = mod_forumng::get_from_cmid($forum2->get_course_module_id(), mod_forumng::CLONE_DIRECT);
     $this->assertTrue($forum3->is_clone());
     $this->assertArrayHasKey($forum3->get_context()->id, $forum1->get_clone_details());
     $this->assertEquals($course2->id, $forum3->get_course_id());
 }
开发者ID:nadavkav,项目名称:moodle-mod_forumng,代码行数:34,代码来源:forumng_test.php


示例17: test_generator

    public function test_generator() {
        global $DB, $SITE;

        $this->resetAfterTest(true);

        $this->assertEquals(0, $DB->count_records('assignment'));

        /** @var mod_assignment_generator $generator */
        $generator = $this->getDataGenerator()->get_plugin_generator('mod_assignment');
        $this->assertInstanceOf('mod_assignment_generator', $generator);
        $this->assertEquals('assignment', $generator->get_modulename());

        $generator->create_instance(array('course'=>$SITE->id));
        $generator->create_instance(array('course'=>$SITE->id));
        $assignment = $generator->create_instance(array('course'=>$SITE->id));
        $this->assertEquals(3, $DB->count_records('assignment'));

        $cm = get_coursemodule_from_instance('assignment', $assignment->id);
        $this->assertEquals($assignment->id, $cm->instance);
        $this->assertEquals('assignment', $cm->modname);
        $this->assertEquals($SITE->id, $cm->course);

        $context = context_module::instance($cm->id);
        $this->assertEquals($assignment->cmid, $context->instanceid);
    }
开发者ID:robadobdob,项目名称:moodle,代码行数:25,代码来源:generator_test.php


示例18: definition

 function definition()
 {
     global $CFG;
     $mform =& $this->_form;
     $mform->addElement('header', 'general', 'Enter Details');
     //		$mform->addElement('text', 'id', 'ID', 'maxlength="3"');
     $mform->addElement('text', 'name', 'Name', 'maxlength="20"');
     $mform->setType('name', PARAM_TEXT);
     $mform->addRule('name', "Please enter name", 'required', null, 'client');
     //		$mform->setHelpButton('name', array('admission', get_string('batchname')), true);
     $forum_id = optional_param('forum', 0, PARAM_INT);
     // id of forum (from URL)
     $cm = get_coursemodule_from_instance('forum', $forum_id, $course->id);
     $context = get_context_instance(CONTEXT_MODULE, $cm->id);
     $context = context_system::instance();
     //		$this->add_intro_editor();
     $mform->addElement('editor', 'text', 'Description', null, array('context' => $context));
     $mform->setType('text', PARAM_RAW);
     /*		$buttonarray=array();
     		$buttonarray[] =& $mform->createElement('submit', 'submitbutton', get_string('savechanges'));
     		$buttonarray[] =& $mform->createElement('submit', 'cancel', get_string('cancel'));
     		$buttonarray[] = &$mform->createElement('reset', 'resetbutton', 'Reset');
     		$mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
     		$mform->closeHeaderBefore('buttonar');   */
     $this->add_action_buttons();
     //		$mform->addElement('header','general', 'Additional Actions:');
     //		$mform->addElement('text', 'name1', 'Enter Name', 'maxlength="20"');
     //		$mform->addElement('button', 'delete', 'Delete a Record');
     //		$mform->addElement('button', 'update', 'Update a Record');
 }
开发者ID:saurabh947,项目名称:MoodleLearning,代码行数:30,代码来源:formdesign.php


示例19: forumng_delete_instance

function forumng_delete_instance($id)
{
    global $DB;
    require_once dirname(__FILE__) . '/mod_forumng.php';
    $cm = get_coursemodule_from_instance('forumng', $id);
    $forum = mod_forumng::get_from_id($id, mod_forumng::CLONE_DIRECT, true, $cm);
    $forum->delete_all_data();
    if (mod_forumng::search_installed()) {
        $cm = $forum->get_course_module();
        local_ousearch_document::delete_module_instance_data($cm);
    }
    if ($forum->is_shared()) {
        // Find all the clone instances.
        $clones = $forum->get_clone_details();
        $transaction = $DB->start_delegated_transaction();
        foreach ($clones as $clone) {
            if (!forumng_delete_instance($clone->cloneforumngid)) {
                notify("Could not delete the Clone forumng (id) {$clone->cloneforumngid} ");
                return false;
            }
            if (!delete_course_module($clone->context->instanceid)) {
                notify("Could not delete the Clone\n                        forumng (coursemoduleid) {$clone->context}->instanceid ");
                return false;
            }
            if (!delete_mod_from_section($clone->context->instanceid, $clone->sectionid)) {
                notify("Could not delete the sectionid {$clone->sectionid} from that section");
                return false;
            }
            rebuild_course_cache($clone->courseid, true);
        }
        $transaction->allow_commit();
    }
    return $DB->delete_records('forumng', array('id' => $id));
}
开发者ID:nadavkav,项目名称:Moodle2-Hebrew-plugins,代码行数:34,代码来源:lib.php


示例20: 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;
 }
开发者ID:andrewhancox,项目名称:moodle-mod_ratingallocate,代码行数:36,代码来源:cron_task.php



注:本文中的get_coursemodule_from_instance函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP get_coursemodules_in_course函数代码示例发布时间:2022-05-15
下一篇:
PHP get_coursemodule_from_id函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap