当前位置: 首页>>代码示例>>PHP>>正文


PHP get_course_and_cm_from_instance函数代码示例

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


在下文中一共展示了get_course_and_cm_from_instance函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: view_scorm

    /**
     * Trigger the course module viewed event.
     *
     * @param int $scormid the scorm instance id
     * @return array of warnings and status result
     * @since Moodle 3.0
     * @throws moodle_exception
     */
    public static function view_scorm($scormid) {
        global $DB, $CFG;
        require_once($CFG->dirroot . '/mod/scorm/lib.php');

        $params = self::validate_parameters(self::view_scorm_parameters(),
                                            array(
                                                'scormid' => $scormid
                                            ));
        $warnings = array();

        // Request and permission validation.
        $scorm = $DB->get_record('scorm', array('id' => $params['scormid']), '*', MUST_EXIST);
        list($course, $cm) = get_course_and_cm_from_instance($scorm, 'scorm');

        $context = context_module::instance($cm->id);
        self::validate_context($context);

        // Call the scorm/lib API.
        scorm_view($scorm, $course, $cm, $context);

        $result = array();
        $result['status'] = true;
        $result['warnings'] = $warnings;
        return $result;
    }
开发者ID:rsturley,项目名称:moodle,代码行数:33,代码来源:external.php

示例2: view_imscp

    /**
     * Simulate the imscp/view.php web interface page: trigger events, completion, etc...
     *
     * @param int $imscpid the imscp instance id
     * @return array of warnings and status result
     * @since Moodle 3.0
     * @throws moodle_exception
     */
    public static function view_imscp($imscpid) {
        global $DB, $CFG;
        require_once($CFG->dirroot . "/mod/imscp/lib.php");

        $params = self::validate_parameters(self::view_imscp_parameters(),
                                            array(
                                                'imscpid' => $imscpid
                                            ));
        $warnings = array();

        // Request and permission validation.
        $imscp = $DB->get_record('imscp', array('id' => $params['imscpid']), '*', MUST_EXIST);
        list($course, $cm) = get_course_and_cm_from_instance($imscp, 'imscp');

        $context = context_module::instance($cm->id);
        self::validate_context($context);

        require_capability('mod/imscp:view', $context);

        // Call the imscp/lib API.
        imscp_view($imscp, $course, $cm, $context);

        $result = array();
        $result['status'] = true;
        $result['warnings'] = $warnings;
        return $result;
    }
开发者ID:nickbert77,项目名称:moodle,代码行数:35,代码来源:external.php

示例3: get_submission_status

 /**
  * Search a list of modules.
  *
  * @param $modulecode
  * @return array [string]
  * @throws \invalid_parameter_exception
  */
 public static function get_submission_status($submissionid)
 {
     global $DB, $USER;
     $params = self::validate_parameters(self::get_submission_status_parameters(), array('submissionid' => $submissionid));
     $submissionid = $params['submissionid'];
     $submission = $DB->get_record('turnitintooltwo_submissions', array('id' => $submissionid));
     if (!$submission) {
         return array('status' => 'error');
     }
     // Grab more data.
     $turnitintooltwo = $DB->get_record('turnitintooltwo', array('id' => $submission->turnitintooltwoid));
     list($course, $cm) = get_course_and_cm_from_instance($turnitintooltwo, 'turnitintooltwo');
     // Check this is our submission.
     if ($USER->id !== $submission->userid && !has_capability('mod/turnitintooltwo:grade', \context_module::instance($cm->id))) {
         return array('status' => 'nopermission');
     }
     // What is the status?
     $status = $DB->get_record('turnitintooltwo_sub_status', array('submissionid' => $submissionid));
     if (!$status) {
         return array('status' => 'queued');
     }
     // Decode the receipt.
     $digitalreceipt = (array) json_decode($status->receipt);
     // Woo!
     if ($status->status == \mod_turnitintooltwo\task\submit_assignment::STATUS_SUCCESS) {
         $turnitintooltwoview = new \turnitintooltwo_view();
         $digitalreceipt = $turnitintooltwoview->show_digital_receipt($digitalreceipt);
         $digitalreceipt = \html_writer::tag("div", $digitalreceipt, array("id" => "box_receipt"));
         return array('status' => 'success', 'message' => $digitalreceipt);
     }
     return array('status' => 'failed', 'message' => \html_writer::tag("div", $digitalreceipt["message"], array("class" => "alert alert-danger")));
 }
开发者ID:SkylarKelty,项目名称:moodle-mod_turnitintooltwo,代码行数:39,代码来源:external.php

示例4: get_cmid

 /**
  * Returns our CMID.
  */
 public function get_cmid()
 {
     if (!isset($this->cmid)) {
         list($course, $cm) = get_course_and_cm_from_instance($this->id, 'qa');
         $this->cmid = $cm->id;
     }
     return $this->cmid;
 }
开发者ID:unikent,项目名称:moodle-mod_qa,代码行数:11,代码来源:question.php

示例5: execute

 public function execute()
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . "/mod/turnitintooltwo/lib.php";
     require_once $CFG->dirroot . "/mod/turnitintooltwo/turnitintooltwo_view.class.php";
     $data = (array) $this->get_custom_data();
     // Make sure we are still wanted.
     $submission = $DB->get_record('turnitintooltwo_submissions', array('id' => $data['submissionid']));
     if (!$submission) {
         return true;
     }
     cli_writeln("Processing Turnitintooltwo submission: " . $data['submissionid']);
     $user = $DB->get_record('user', array('id' => $data['userid']));
     \core\session\manager::set_user($user);
     $turnitintooltwo = $DB->get_record('turnitintooltwo', array('id' => $data['tiiid']));
     list($course, $cm) = get_course_and_cm_from_instance($turnitintooltwo, 'turnitintooltwo');
     try {
         $turnitintooltwoassignment = new \turnitintooltwo_assignment($turnitintooltwo->id, $turnitintooltwo);
         $turnitintooltwosubmission = new \turnitintooltwo_submission($data['submissionid'], "moodle", $turnitintooltwoassignment);
         $parts = $turnitintooltwoassignment->get_parts();
         $tiisubmission = $turnitintooltwosubmission->do_tii_submission($cm, $turnitintooltwoassignment);
         // Update submission.
         $DB->update_record('turnitintooltwo_submissions', array('id' => $data['submissionid'], 'submission_modified' => $data['subtime']));
     } catch (\Exception $e) {
         $tiisubmission = array('success' => false, 'message' => $e->getMessage());
         cli_writeln($e->getMessage());
     }
     $digitalreceipt = $tiisubmission;
     $digitalreceipt['is_manual'] = 0;
     $digitalreceipt = json_encode($digitalreceipt);
     $this->update_sub_status($data['submissionid'], $tiisubmission['success'], $digitalreceipt);
     if ($tiisubmission['success'] === true) {
         $lockedassignment = new \stdClass();
         $lockedassignment->id = $turnitintooltwoassignment->turnitintooltwo->id;
         $lockedassignment->submitted = 1;
         $DB->update_record('turnitintooltwo', $lockedassignment);
         $lockedpart = new \stdClass();
         $lockedpart->id = $data['submissionpart'];
         $lockedpart->submitted = 1;
         // Disable anonymous marking if post date has passed.
         if ($parts[$data['submissionpart']]->dtpost <= time()) {
             $lockedpart->unanon = 1;
         }
         $DB->update_record('turnitintooltwo_parts', $lockedpart);
         cli_writeln("Finished processing successful submission: " . $data['submissionid']);
     } else {
         turnitintooltwo_add_to_log($course->id, "errored submission", 'view.php?id=' . $cm->id, "Failed to submit '" . $turnitintooltwosubmission->submission_title . "'", $cm->id, $user->id, array('submissionid' => $data['submissionid']));
         cli_writeln("Finished processing unsuccessful submission: " . $data['submissionid']);
     }
     \core\session\manager::set_user(get_admin());
     return $tiisubmission['success'];
 }
开发者ID:SkylarKelty,项目名称:moodle-mod_turnitintooltwo,代码行数:52,代码来源:submit_assignment.php

示例6: view_book

 /**
  * Simulate the book/view.php web interface page: trigger events, completion, etc...
  *
  * @param int $bookid the book instance id
  * @param int $chapterid the book chapter id
  * @return array of warnings and status result
  * @since Moodle 3.0
  * @throws moodle_exception
  */
 public static function view_book($bookid, $chapterid = 0)
 {
     global $DB, $CFG;
     require_once $CFG->dirroot . "/mod/book/lib.php";
     require_once $CFG->dirroot . "/mod/book/locallib.php";
     $params = self::validate_parameters(self::view_book_parameters(), array('bookid' => $bookid, 'chapterid' => $chapterid));
     $bookid = $params['bookid'];
     $chapterid = $params['chapterid'];
     $warnings = array();
     // Request and permission validation.
     $book = $DB->get_record('book', array('id' => $bookid), '*', MUST_EXIST);
     list($course, $cm) = get_course_and_cm_from_instance($book, 'book');
     $context = context_module::instance($cm->id);
     self::validate_context($context);
     require_capability('mod/book:read', $context);
     $chapters = book_preload_chapters($book);
     $firstchapterid = 0;
     $lastchapterid = 0;
     foreach ($chapters as $ch) {
         if ($ch->hidden) {
             continue;
         }
         if (!$firstchapterid) {
             $firstchapterid = $ch->id;
         }
         $lastchapterid = $ch->id;
     }
     if (!$chapterid) {
         // Trigger the module viewed events since we are displaying the book.
         book_view($book, null, false, $course, $cm, $context);
         $chapterid = $firstchapterid;
     }
     // Check if book is empty (warning).
     if (!$chapterid) {
         $warnings[] = array('item' => 'book', 'itemid' => $book->id, 'warningcode' => '1', 'message' => get_string('nocontent', 'mod_book'));
     } else {
         $chapter = $DB->get_record('book_chapters', array('id' => $chapterid, 'bookid' => $book->id));
         $viewhidden = has_capability('mod/book:viewhiddenchapters', $context);
         if (!$chapter or $chapter->hidden and !$viewhidden) {
             throw new moodle_exception('errorchapter', 'mod_book');
         }
         // Trigger the chapter viewed event.
         $islastchapter = $chapter->id == $lastchapterid ? true : false;
         book_view($book, $chapter, $islastchapter, $course, $cm, $context);
     }
     $result = array();
     $result['status'] = true;
     $result['warnings'] = $warnings;
     return $result;
 }
开发者ID:pzhu2004,项目名称:moodle,代码行数:59,代码来源:external.php

示例7: view_folder

 /**
  * Simulate the folder/view.php web interface page: trigger events, completion, etc...
  *
  * @param int $folderid the folder instance id
  * @return array of warnings and status result
  * @since Moodle 3.0
  * @throws moodle_exception
  */
 public static function view_folder($folderid)
 {
     global $DB, $CFG;
     require_once $CFG->dirroot . "/mod/folder/lib.php";
     $params = self::validate_parameters(self::view_folder_parameters(), array('folderid' => $folderid));
     $warnings = array();
     // Request and permission validation.
     $folder = $DB->get_record('folder', array('id' => $params['folderid']), '*', MUST_EXIST);
     list($course, $cm) = get_course_and_cm_from_instance($folder, 'folder');
     $context = context_module::instance($cm->id);
     self::validate_context($context);
     require_capability('mod/folder:view', $context);
     // Call the page/lib API.
     folder_view($folder, $course, $cm, $context);
     $result = array();
     $result['status'] = true;
     $result['warnings'] = $warnings;
     return $result;
 }
开发者ID:pzhu2004,项目名称:moodle,代码行数:27,代码来源:external.php

示例8: optional_param

require_once $CFG->dirroot . '/mod/quiz/lib.php';
require_once $CFG->dirroot . '/mod/quiz/locallib.php';
require_once $CFG->dirroot . '/mod/quiz/override_form.php';
$cmid = optional_param('cmid', 0, PARAM_INT);
$overrideid = optional_param('id', 0, PARAM_INT);
$action = optional_param('action', null, PARAM_ALPHA);
$reset = optional_param('reset', false, PARAM_BOOL);
$override = null;
if ($overrideid) {
    if (!($override = $DB->get_record('quiz_overrides', array('id' => $overrideid)))) {
        print_error('invalidoverrideid', 'quiz');
    }
    if (!($quiz = $DB->get_record('quiz', array('id' => $override->quiz)))) {
        print_error('invalidcoursemodule');
    }
    list($course, $cm) = get_course_and_cm_from_instance($quiz, 'quiz');
} else {
    if ($cmid) {
        list($course, $cm) = get_course_and_cm_from_cmid($cmid, 'quiz');
        $quiz = $DB->get_record('quiz', array('id' => $cm->instance), '*', MUST_EXIST);
    } else {
        print_error('invalidcoursemodule');
    }
}
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$url = new moodle_url('/mod/quiz/overrideedit.php');
if ($action) {
    $url->param('action', $action);
}
if ($overrideid) {
    $url->param('id', $overrideid);
开发者ID:pzhu2004,项目名称:moodle,代码行数:31,代码来源:overrideedit.php

示例9: view_forum_discussion

 /**
  * Simulate the forum/discuss.php web interface page: trigger events
  *
  * @param int $discussionid the discussion id
  * @return array of warnings and status result
  * @since Moodle 2.9
  * @throws moodle_exception
  */
 public static function view_forum_discussion($discussionid)
 {
     global $DB, $CFG;
     require_once $CFG->dirroot . "/mod/forum/lib.php";
     $params = self::validate_parameters(self::view_forum_discussion_parameters(), array('discussionid' => $discussionid));
     $warnings = array();
     $discussion = $DB->get_record('forum_discussions', array('id' => $params['discussionid']), '*', MUST_EXIST);
     $forum = $DB->get_record('forum', array('id' => $discussion->forum), '*', MUST_EXIST);
     list($course, $cm) = get_course_and_cm_from_instance($forum, 'forum');
     // Validate the module context. It checks everything that affects the module visibility (including groupings, etc..).
     $modcontext = context_module::instance($cm->id);
     self::validate_context($modcontext);
     require_capability('mod/forum:viewdiscussion', $modcontext, null, true, 'noviewdiscussionspermission', 'forum');
     // Call the forum/lib API.
     forum_discussion_view($modcontext, $forum, $discussion);
     $result = array();
     $result['status'] = true;
     $result['warnings'] = $warnings;
     return $result;
 }
开发者ID:educakanchay,项目名称:campus,代码行数:28,代码来源:externallib.php

示例10: feedback_init_feedback_session

 *
 * @author Andreas Grabs
 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
 * @package mod_feedback
 */
require_once "../../config.php";
require_once "lib.php";
feedback_init_feedback_session();
$itemid = optional_param('id', false, PARAM_INT);
if (!$itemid) {
    $cmid = required_param('cmid', PARAM_INT);
    $typ = required_param('typ', PARAM_ALPHA);
}
if ($itemid) {
    $item = $DB->get_record('feedback_item', array('id' => $itemid), '*', MUST_EXIST);
    list($course, $cm) = get_course_and_cm_from_instance($item->feedback, 'feedback');
    $url = new moodle_url('/mod/feedback/edit_item.php', array('id' => $itemid));
    $typ = $item->typ;
} else {
    $item = null;
    list($course, $cm) = get_course_and_cm_from_cmid($cmid, 'feedback');
    $url = new moodle_url('/mod/feedback/edit_item.php', array('cmid' => $cm->id, 'typ' => $typ));
    $item = (object) ['id' => null, 'position' => -1, 'typ' => $typ, 'options' => ''];
}
require_login($course, true, $cm);
$context = context_module::instance($cm->id);
require_capability('mod/feedback:edititems', $context);
$feedback = $PAGE->activityrecord;
$editurl = new moodle_url('/mod/feedback/edit.php', array('id' => $cm->id));
$PAGE->set_url($url);
// If the typ is pagebreak so the item will be saved directly.
开发者ID:evltuma,项目名称:moodle,代码行数:31,代码来源:edit_item.php

示例11: validate_glossary

 /**
  * Validate a glossary via ID.
  *
  * @param  int $id The glossary ID.
  * @return array Contains glossary, context, course and cm.
  */
 protected static function validate_glossary($id)
 {
     global $DB;
     $glossary = $DB->get_record('glossary', array('id' => $id), '*', MUST_EXIST);
     list($course, $cm) = get_course_and_cm_from_instance($glossary, 'glossary');
     $context = context_module::instance($cm->id);
     self::validate_context($context);
     return array($glossary, $context, $course, $cm);
 }
开发者ID:janeklb,项目名称:moodle,代码行数:15,代码来源:external.php

示例12: view_quiz

 /**
  * Trigger the course module viewed event and update the module completion status.
  *
  * @param int $quizid quiz instance id
  * @return array of warnings and status result
  * @since Moodle 3.1
  * @throws moodle_exception
  */
 public static function view_quiz($quizid)
 {
     global $DB;
     $params = self::validate_parameters(self::view_quiz_parameters(), array('quizid' => $quizid));
     $warnings = array();
     // Request and permission validation.
     $quiz = $DB->get_record('quiz', array('id' => $params['quizid']), '*', MUST_EXIST);
     list($course, $cm) = get_course_and_cm_from_instance($quiz, 'quiz');
     $context = context_module::instance($cm->id);
     self::validate_context($context);
     // Trigger course_module_viewed event and completion.
     quiz_view($quiz, $course, $cm, $context);
     $result = array();
     $result['status'] = true;
     $result['warnings'] = $warnings;
     return $result;
 }
开发者ID:kevin-bruton,项目名称:moodle,代码行数:25,代码来源:external.php

示例13: add_discussion

    /**
     * Add a new discussion into an existing forum.
     *
     * @param int $forumid the forum instance id
     * @param string $subject new discussion subject
     * @param string $message new discussion message (only html format allowed)
     * @param int $groupid the user course group
     * @param array $options optional settings
     * @return array of warnings and the new discussion id
     * @since Moodle 3.0
     * @throws moodle_exception
     */
    public static function add_discussion($forumid, $subject, $message, $groupid = -1, $options = array()) {
        global $DB, $CFG;
        require_once($CFG->dirroot . "/mod/forum/lib.php");

        $params = self::validate_parameters(self::add_discussion_parameters(),
                                            array(
                                                'forumid' => $forumid,
                                                'subject' => $subject,
                                                'message' => $message,
                                                'groupid' => $groupid,
                                                'options' => $options
                                            ));
        // Validate options.
        $options = array(
            'discussionsubscribe' => true
        );
        foreach ($params['options'] as $option) {
            $name = trim($option['name']);
            switch ($name) {
                case 'discussionsubscribe':
                    $value = clean_param($option['value'], PARAM_BOOL);
                    break;
                default:
                    throw new moodle_exception('errorinvalidparam', 'webservice', '', $name);
            }
            $options[$name] = $value;
        }

        $warnings = array();

        // Request and permission validation.
        $forum = $DB->get_record('forum', array('id' => $params['forumid']), '*', MUST_EXIST);
        list($course, $cm) = get_course_and_cm_from_instance($forum, 'forum');

        $context = context_module::instance($cm->id);
        self::validate_context($context);

        // Normalize group.
        if (!groups_get_activity_groupmode($cm)) {
            // Groups not supported, force to -1.
            $groupid = -1;
        } else {
            // Check if we receive the default or and empty value for groupid,
            // in this case, get the group for the user in the activity.
            if ($groupid === -1 or empty($params['groupid'])) {
                $groupid = groups_get_activity_group($cm);
            } else {
                // Here we rely in the group passed, forum_user_can_post_discussion will validate the group.
                $groupid = $params['groupid'];
            }
        }

        if (!forum_user_can_post_discussion($forum, $groupid, -1, $cm, $context)) {
            throw new moodle_exception('cannotcreatediscussion', 'forum');
        }

        $thresholdwarning = forum_check_throttling($forum, $cm);
        forum_check_blocking_threshold($thresholdwarning);

        // Create the discussion.
        $discussion = new stdClass();
        $discussion->course = $course->id;
        $discussion->forum = $forum->id;
        $discussion->message = $params['message'];
        $discussion->messageformat = FORMAT_HTML;   // Force formatting for now.
        $discussion->messagetrust = trusttext_trusted($context);
        $discussion->itemid = 0;
        $discussion->groupid = $groupid;
        $discussion->mailnow = 0;
        $discussion->subject = $params['subject'];
        $discussion->name = $discussion->subject;
        $discussion->timestart = 0;
        $discussion->timeend = 0;

        if ($discussionid = forum_add_discussion($discussion)) {

            $discussion->id = $discussionid;

            // Trigger events and completion.

            $params = array(
                'context' => $context,
                'objectid' => $discussion->id,
                'other' => array(
                    'forumid' => $forum->id,
                )
            );
            $event = \mod_forum\event\discussion_created::create($params);
//.........这里部分代码省略.........
开发者ID:uniedpa,项目名称:moodle,代码行数:101,代码来源:externallib.php

示例14: can_add_discussion

 /**
  * Check if the current user can add discussions in the given forum (and optionally for the given group).
  *
  * @param int $forumid the forum instance id
  * @param int $groupid the group to check, default to active group. Use -1 to check if the user can post in all the groups.
  * @return array of warnings and the status (true if the user can add discussions)
  * @since Moodle 3.1
  * @throws moodle_exception
  */
 public static function can_add_discussion($forumid, $groupid = null)
 {
     global $DB, $CFG;
     require_once $CFG->dirroot . "/mod/forum/lib.php";
     $params = self::validate_parameters(self::can_add_discussion_parameters(), array('forumid' => $forumid, 'groupid' => $groupid));
     $warnings = array();
     // Request and permission validation.
     $forum = $DB->get_record('forum', array('id' => $params['forumid']), '*', MUST_EXIST);
     list($course, $cm) = get_course_and_cm_from_instance($forum, 'forum');
     $context = context_module::instance($cm->id);
     self::validate_context($context);
     $status = forum_user_can_post_discussion($forum, $params['groupid'], -1, $cm, $context);
     $result = array();
     $result['status'] = $status;
     $result['warnings'] = $warnings;
     return $result;
 }
开发者ID:lucaboesch,项目名称:moodle,代码行数:26,代码来源:externallib.php

示例15: test_useridlist_cache

 /**
  * Test that the useridlist cache will retive the correct values
  * when using assign::get_useridlist_key and assign::get_useridlist_key_id.
  */
 public function test_useridlist_cache()
 {
     // Create an assignment object, we will use this to test the key generation functions.
     $course = self::getDataGenerator()->create_course();
     $assign = self::getDataGenerator()->create_module('assign', array('course' => $course->id));
     list($courserecord, $cm) = get_course_and_cm_from_instance($assign->id, 'assign');
     $context = context_module::instance($cm->id);
     $assign = new assign($context, $cm, $courserecord);
     // Create the cache.
     $cache = cache::make_from_params(cache_store::MODE_SESSION, 'mod_assign', 'useridlist');
     // Create an entry that we will insert into the cache.
     $entry = array(0 => '5', 1 => '6325', 2 => '67783');
     // Insert the value into the cache.
     $cache->set($assign->get_useridlist_key(), $entry);
     // Now test we can retrive the entry.
     $this->assertEquals($entry, $cache->get($assign->get_useridlist_key()));
     $useridlistid = clean_param($assign->get_useridlist_key_id(), PARAM_ALPHANUM);
     $this->assertEquals($entry, $cache->get($assign->get_useridlist_key($useridlistid)));
     // Check it will not retrive anything on an invalid key.
     $this->assertFalse($cache->get($assign->get_useridlist_key('notvalid')));
 }
开发者ID:pzhu2004,项目名称:moodle,代码行数:25,代码来源:locallib_test.php


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