本文整理汇总了PHP中get_coursemodule_from_id函数的典型用法代码示例。如果您正苦于以下问题:PHP get_coursemodule_from_id函数的具体用法?PHP get_coursemodule_from_id怎么用?PHP get_coursemodule_from_id使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_coursemodule_from_id函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct(\mod_mediagallery\collection $collection, array $galleries)
{
global $CFG, $DB;
$this->collection = $collection;
$this->galleries = $galleries;
if ($collection->user_can_add_children()) {
$this->maxreached = false;
}
if ($this->isassessable = $collection->is_assessable()) {
$this->hassubmitted = $collection->has_submitted();
if ($this->linkedassigncmid = $collection->get_linked_assignid()) {
require_once $CFG->dirroot . '/mod/assign/locallib.php';
$context = \context_module::instance($this->linkedassigncmid);
$cm = get_coursemodule_from_id('assign', $this->linkedassigncmid, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$assign = new \assign($context, $cm, $course);
$this->submissionsopen = $assign->submissions_open();
}
}
$this->readonly = $collection->is_read_only();
$this->tags = $collection->get_tags();
$mygalleries = $collection->get_my_galleries();
$this->userorgrouphasgallery = !empty($mygalleries);
foreach (array('id', 'mode', 'thumbnailsperrow', 'thumbnailsperpage') as $opt) {
if (isset($collection->{$opt})) {
$this->{$opt} = $collection->{$opt};
}
}
}
示例2: resource_base
/**
* Constructor for the base resource class
*
* Constructor for the base resource class.
* If cmid is set create the cm, course, resource objects.
* and do some checks to make sure people can be here, and so on.
*
* @param cmid integer, the current course module id - not set for new resources
*/
function resource_base($cmid = 0)
{
global $CFG, $COURSE;
if ($cmid) {
if (!($this->cm = get_coursemodule_from_id('resource', $cmid))) {
error("Course Module ID was incorrect");
}
if (!($this->course = get_record("course", "id", $this->cm->course))) {
error("Course is misconfigured");
}
if (!($this->resource = get_record("resource", "id", $this->cm->instance))) {
error("Resource ID was incorrect");
}
$this->strresource = get_string("modulename", "resource");
$this->strresources = get_string("modulenameplural", "resource");
if ($this->course->id != SITEID) {
$this->navigation = "<a {$CFG->frametarget} onclick=\"this.target='{$CFG->framename}'\" href=\"{$CFG->wwwroot}/course/view.php?id={$this->course->id}\">{$this->course->shortname}</a> -> " . "<a {$CFG->frametarget} onclick=\"this.target='{$CFG->framename}'\" href=\"index.php?id={$this->course->id}\">{$this->strresources}</a> ->";
} else {
$this->navigation = "<a {$CFG->frametarget} onclick=\"this.target='{$CFG->framename}'\" href=\"index.php?id={$this->course->id}\">{$this->strresources}</a> ->";
}
if (!$this->cm->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $this->cm->id))) {
$pagetitle = strip_tags($this->course->shortname . ': ' . $this->strresource);
print_header($pagetitle, $this->course->fullname, "{$this->navigation} {$this->strresource}", "", "", true, '', navmenu($this->course, $this->cm));
notice(get_string("activityiscurrentlyhidden"), "{$CFG->wwwroot}/course/view.php?id={$this->course->id}");
}
} else {
$this->course = $COURSE;
}
}
示例3: load
/**
* Loads data from the database.
* Note: even if the function fails, it may still have overwritten some or all existing data in the object.
* @param mixed $id The site-wide unique identifier for all modules. Type depends on VLE. On Moodle, it is an integer course module identifier ('id' field of 'course_modules' table)
* @return bool True if successful, or false otherwise
*/
function load($id)
{
// Make sure the ID is valid
$id = (int) $id;
if ($id <= 0) {
return false;
}
// Fetch the course module data
if (!($this->cm = get_coursemodule_from_id('sloodle', $id))) {
sloodle_debug("Failed to load controler course module.<br>");
return false;
}
// Load from the primary table: Sloodle instance
if (!($this->sloodle_module_instance = get_record('sloodle', 'id', $this->cm->instance))) {
sloodle_debug("Failed to load controller Sloodle module instance.<br>");
return false;
}
// Check that it is the correct type
if ($this->sloodle_module_instance->type != SLOODLE_TYPE_CTRL) {
sloodle_debug("Loaded Sloodle module instance is not a controller.<br>");
return false;
}
// Load from the secondary table: Controller instance
if (!($this->sloodle_controller_instance = get_record('sloodle_controller', 'sloodleid', $this->cm->instance))) {
sloodle_debug("Failed to load controller secondary data table.<br>");
return false;
}
return true;
}
示例4: pagemenu_get_basics
/**
* Returns course module, course and module instance.
*
* @param int $cmid Course module ID
* @param int $pagemenuid pagemenu module ID
* @return array of objects
**/
function pagemenu_get_basics($cmid = 0, $pagemenuid = 0)
{
if ($cmid) {
if (!($cm = get_coursemodule_from_id('pagemenu', $cmid))) {
error('Course Module ID was incorrect');
}
if (!($course = get_record('course', 'id', $cm->course))) {
error('Course is misconfigured');
}
if (!($pagemenu = get_record('pagemenu', 'id', $cm->instance))) {
error('Course module is incorrect');
}
} else {
if ($pagemenuid) {
if (!($pagemenu = get_record('pagemenu', 'id', $pagemenuid))) {
error('Course module is incorrect');
}
if (!($course = get_record('course', 'id', $pagemenu->course))) {
error('Course is misconfigured');
}
if (!($cm = get_coursemodule_from_instance('pagemenu', $pagemenu->id, $course->id))) {
error('Course Module ID was incorrect');
}
} else {
error('No course module ID or pagemenu ID were passed');
}
}
return array($cm, $course, $pagemenu);
}
示例5: __ScormUpdate
public static function __ScormUpdate($uid, $request)
{
$courseid = $request->courseid;
$cmid = $request->modid;
if (!($cm = get_coursemodule_from_id('scorm', $cmid, $courseid))) {
print_error('invalidcoursemodule');
}
$data = self::scorm_data_array($cmid, $courseid);
$reqdata = $uid . $courseid . $cmid;
// $uid.$courseid.$cmid userid + courseid + modid
$data_submitted = $request->data[0]->organizations->Turnaround_Revitalizing_Resource_ORG->cmi->{$reqdata};
$result = true;
$attempts = $data_submitted->attempts->value;
$starttime = $data_submitted->starttime->value;
self::scorm_start_time($uid, $data['scormid'], $data['scoid'], $attempts, $starttime);
foreach ($data_submitted as $element => $value) {
$element = str_replace('__', '.', $element);
if (substr($element, 0, 3) == 'cmi') {
$netelement = preg_replace('/\\.N(\\d+)\\./', "\\.\$1\\.", $element);
if ($value->setbysco === true) {
$result = scorm_insert_track($uid, $data['scormid'], $data['scoid'], $attempts, $element, $value->value, true) && $result;
//$scormid, $scoid
}
}
}
$response = new CliniqueServiceResponce();
if (!empty($result)) {
$response->response(false, 'Recorded inserted successfully');
} else {
$response->response(true, 'Invalid ID');
}
die;
}
示例6: set_properties
/**
* Set class properties from params.
*
* @throws \coding_exception
* @throws \moodle_exception
*/
protected function set_properties()
{
global $DB;
// Set class properties from params.
$id = optional_param('id', 0, PARAM_INT);
// Course_module ID, or
$n = optional_param('n', 0, PARAM_INT);
// collaborate instance ID.
if ($id) {
$cm = get_coursemodule_from_id('collaborate', $id, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$collaborate = $DB->get_record('collaborate', array('id' => $cm->instance), '*', MUST_EXIST);
} else {
if ($n) {
$collaborate = $DB->get_record('collaborate', array('id' => $n), '*', MUST_EXIST);
$course = $DB->get_record('course', array('id' => $collaborate->course), '*', MUST_EXIST);
$cm = get_coursemodule_from_instance('collaborate', $collaborate->id, $course->id, false, MUST_EXIST);
} else {
print_error('error:invalidmoduleid', 'mod_collaborate');
}
}
$this->cm = $cm;
$this->course = $course;
$this->collaborate = $collaborate;
}
示例7: 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);
}
示例8: 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);
}
示例9: definition
function definition()
{
global $DB, $PAGE, $OUTPUT;
$id = required_param('id', PARAM_INT);
// course module
if (!($cm = get_coursemodule_from_id('blended', $id))) {
error("Course Module ID was incorrect");
}
if (!($course = get_course($cm->course))) {
error("Course is misconfigured");
}
if (!($blended = $DB->get_record('blended', array('id' => $cm->instance)))) {
error("Course module is incorrect");
}
$form =& $this->_form;
$calificables = new grade_tree($course->id);
$items = $calificables->items;
$ins = array();
$assignmentname = array();
// Obtenemos las referencias a toda la informaci�n sobre los modulos dentro del curso
$modinfo = get_fast_modinfo($course->id);
foreach ($modinfo->instances as $abc) {
foreach ($abc as $cmd) {
foreach ($items as $r => $ite) {
$ins[$r] = $ite->iteminstance;
if ($cmd->instance == $ins[$r]) {
$assignmentname[$r] = $cmd->name;
}
}
}
}
$form->addElement('select', 'activities', 'Selecciona la Tarea', $assignmentname);
}
示例10: load
/**
* Loads data from the database.
* Note: even if the function fails, it may still have overwritten some or all existing data in the object.
* @param mixed $id The site-wide unique identifier for all modules. Type depends on VLE. On Moodle, it is an integer course module identifier ('id' field of 'course_modules' table)
* @return bool True if successful, or false otherwise
*/
function load($id)
{
// Make sure the ID is valid
$id = (int) $id;
if ($id <= 0) {
return false;
}
// Fetch the course module data
if (!($this->cm = get_coursemodule_from_id('sloodle', $id))) {
sloodle_debug("Failed to load course module instance #{$id}.<br/>");
return false;
}
// Make sure the module is visible
if ($this->cm->visible == 0) {
sloodle_debug("Error: course module instance #{$id} not visible.<br/>");
return false;
}
// Load from the primary table: sloodle instance
if (!($this->sloodle_instance = get_record('sloodle', 'id', $this->cm->instance))) {
sloodle_debug("Failed to load Sloodle module with instance ID #{$cm->instance}.<br/>");
return false;
}
// Load from the secondary table: sloodle_presenter
if (!($this->presenter = get_record('sloodle_presenter', 'sloodleid', $this->cm->instance))) {
sloodle_debug("Failed to load secondary module table with instance ID #{$this->cm->instance}.<br/>");
return false;
}
return true;
}
示例11: __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 = get_context_instance(CONTEXT_BLOCK, $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 = get_context_instance(CONTEXT_MODULE, $this->moduleid)->id;
}
parent::__construct($name, $plan);
}
示例12: test_update_activity_completion_status_manually
/**
* Test update_activity_completion_status_manually
*/
public function test_update_activity_completion_status_manually()
{
global $DB, $CFG;
$this->resetAfterTest(true);
$CFG->enablecompletion = true;
$user = $this->getDataGenerator()->create_user();
$course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1));
$data = $this->getDataGenerator()->create_module('data', array('course' => $course->id), array('completion' => 1));
$cm = get_coursemodule_from_id('data', $data->cmid);
$studentrole = $DB->get_record('role', array('shortname' => 'student'));
$this->getDataGenerator()->enrol_user($user->id, $course->id, $studentrole->id);
$this->setUser($user);
$result = core_completion_external::update_activity_completion_status_manually($data->cmid, true);
// We need to execute the return values cleaning process to simulate the web service server.
$result = external_api::clean_returnvalue(core_completion_external::update_activity_completion_status_manually_returns(), $result);
// Check in DB.
$this->assertEquals(1, $DB->get_field('course_modules_completion', 'completionstate', array('coursemoduleid' => $data->cmid)));
// Check using the API.
$completion = new completion_info($course);
$completiondata = $completion->get_data($cm);
$this->assertEquals(1, $completiondata->completionstate);
$this->assertTrue($result['status']);
$result = core_completion_external::update_activity_completion_status_manually($data->cmid, false);
// We need to execute the return values cleaning process to simulate the web service server.
$result = external_api::clean_returnvalue(core_completion_external::update_activity_completion_status_manually_returns(), $result);
$this->assertEquals(0, $DB->get_field('course_modules_completion', 'completionstate', array('coursemoduleid' => $data->cmid)));
$completiondata = $completion->get_data($cm);
$this->assertEquals(0, $completiondata->completionstate);
$this->assertTrue($result['status']);
}
示例13: load
/**
* Loads data from the database.
* Note: even if the function fails, it may still have overwritten some or all existing data in the object.
* @param mixed $id The site-wide unique identifier for all modules. Type depends on VLE. On Moodle, it is an integer course module identifier ('id' field of 'course_modules' table)
* @return bool True if successful, or false otherwise
*/
function load($id)
{
// Make sure the ID is valid
if (!is_int($id) || $id <= 0) {
echo "<hr><pre>ID = ";
print_r($id);
echo "</pre><hr>";
return false;
}
// Fetch the course module data
if (!($this->cm = get_coursemodule_from_id('sloodle', $id))) {
return false;
}
// Load from the primary table: Sloodle instance
if (!($this->sloodle_module_instance = get_record('sloodle', 'id', $this->cm->instance))) {
return false;
}
// Check that it is the correct type
if ($this->sloodle_module_instance->type != SLOODLE_TYPE_CTRL) {
return false;
}
// Load from the secondary table: Distributor instance
if (!($this->sloodle_controller_instance = get_record('sloodle_controller', 'sloodleid', $this->cm->instance))) {
return false;
}
return true;
}
示例14: get_owning_activity
/**
* If this block belongs to a activity context, then return that activity's id.
* Otherwise, return 0.
* @return stdclass the activity record.
*/
public function get_owning_activity()
{
global $DB;
// Set some defaults.
$result = new stdClass();
$result->id = 0;
if (empty($this->instance->parentcontextid)) {
return $result;
}
$parentcontext = context::instance_by_id($this->instance->parentcontextid);
if ($parentcontext->contextlevel != CONTEXT_MODULE) {
return $result;
}
$cm = get_coursemodule_from_id($this->page->cm->modname, $parentcontext->instanceid);
if (!$cm) {
return $result;
}
// Get the grade_items id.
$rec = $DB->get_record('grade_items', array('iteminstance' => $cm->instance, 'itemmodule' => $this->page->cm->modname));
if (!$rec) {
return $result;
}
// See if it is a gradable activity.
if ($rec->gradetype != GRADE_TYPE_VALUE && $rec->gradetype != GRADE_TYPE_SCALE) {
return $result;
}
return $rec;
}
示例15: delete
private static function delete($modulename, $course, $title, $section)
{
global $DB, $CFG;
$sql = 'SELECT cm.id FROM {course_sections} AS cs JOIN {course_modules} AS cm ON cm.section = cs.id JOIN {modules} AS ms ON ms.id = cm.module JOIN {' . $modulename . '} AS m ON m.id = cm.instance WHERE cs.course = ? AND cs.section = ? AND m.name = ? AND ms.name = ?';
$instances = $DB->get_records_sql($sql, array($course->id, $section, $title, $modulename));
foreach ($instances as $instance) {
$cm = get_coursemodule_from_id('', $instance->id);
$modlib = "{$CFG->dirroot}/mod/{$cm->modname}/lib.php";
if (file_exists($modlib)) {
require_once $modlib;
} else {
return false;
}
$deleteinstancefunction = $cm->modname . "_delete_instance";
if (!$deleteinstancefunction($cm->instance)) {
return false;
}
if (!delete_course_module($cm->id)) {
return false;
}
if (!delete_mod_from_section($cm->id, $cm->section)) {
return false;
}
// Trigger a mod_deleted event with information about this module.
$eventdata = new stdClass();
$eventdata->modulename = $cm->modname;
$eventdata->cmid = $cm->id;
$eventdata->courseid = $course->id;
$eventdata->userid = 0;
events_trigger('mod_deleted', $eventdata);
}
return true;
}