/** * 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; $this->navlinks = array(); 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->cm->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $this->cm->id))) { $pagetitle = strip_tags($this->course->shortname . ': ' . $this->strresource); $navigation = build_navigation($this->navlinks, $this->cm); print_header($pagetitle, $this->course->fullname, $navigation, "", "", true, '', navmenu($this->course, $this->cm)); notice(get_string("activityiscurrentlyhidden"), "{$CFG->wwwroot}/course/view.php?id={$this->course->id}"); } } else { $this->course = $COURSE; } }
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}; } } }
/** * 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; } }
/** * 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; }
/** * 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); }
/** * 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; }
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; }
/** * 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); }
/** * 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); }
/** * 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; }
/** * 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); }
/** * 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']); }
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; }
public function test_export_contents() { global $DB; $this->resetAfterTest(true); $user = $this->getDataGenerator()->create_user(); $course = $this->getDataGenerator()->create_course(array('enablecomment' => 1)); $studentrole = $DB->get_record('role', array('shortname' => 'student')); $this->getDataGenerator()->enrol_user($user->id, $course->id, $studentrole->id); // Test book with 3 chapters. $book = $this->getDataGenerator()->create_module('book', array('course' => $course->id)); $cm = get_coursemodule_from_id('book', $book->cmid); $bookgenerator = $this->getDataGenerator()->get_plugin_generator('mod_book'); $chapter1 = $bookgenerator->create_chapter(array('bookid' => $book->id, "pagenum" => 1)); $chapter2 = $bookgenerator->create_chapter(array('bookid' => $book->id, "pagenum" => 2)); $subchapter = $bookgenerator->create_chapter(array('bookid' => $book->id, "pagenum" => 3, "subchapter" => 1)); $chapter3 = $bookgenerator->create_chapter(array('bookid' => $book->id, "pagenum" => 4, "hidden" => 1)); $this->setUser($user); $contents = book_export_contents($cm, ''); // The hidden chapter must not be included, and additional page with the structure must be included. $this->assertCount(4, $contents); $this->assertEquals('structure', $contents[0]['filename']); $this->assertEquals('index.html', $contents[1]['filename']); $this->assertEquals('Chapter 1', $contents[1]['content']); $this->assertEquals('index.html', $contents[2]['filename']); $this->assertEquals('Chapter 2', $contents[2]['content']); $this->assertEquals('index.html', $contents[3]['filename']); $this->assertEquals('Chapter 3', $contents[3]['content']); // Test empty book. $emptybook = $this->getDataGenerator()->create_module('book', array('course' => $course->id)); $cm = get_coursemodule_from_id('book', $emptybook->cmid); $contents = book_export_contents($cm, ''); $this->assertCount(1, $contents); $this->assertEquals('structure', $contents[0]['filename']); $this->assertEquals(json_encode(array()), $contents[0]['content']); }
/** * 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; }
/** * Load data needed for the portfolio export * * If the assignment type implements portfolio_load_data(), the processing is delegated * to it. Otherwise, the caller must provide either fileid (to export single file) or * submissionid (to export all data attached to the given submission) via callback arguments. */ public function load_data() { global $DB, $CFG; if (!($this->cm = get_coursemodule_from_id('assignment', $this->id))) { throw new portfolio_caller_exception('invalidcoursemodule'); } if (!($assignment = $DB->get_record("assignment", array("id" => $this->cm->instance)))) { throw new portfolio_caller_exception('invalidid', 'assignment'); } $this->assignmentfile = '/mod/assignment/type/' . $assignment->assignmenttype . '/assignment.class.php'; require_once $CFG->dirroot . $this->assignmentfile; $assignmentclass = "assignment_{$assignment->assignmenttype}"; $this->assignment = new $assignmentclass($this->cm->id, $assignment, $this->cm); if (!$this->assignment->portfolio_exportable()) { throw new portfolio_caller_exception('notexportable', 'portfolio', $this->get_return_url()); } if (is_callable(array($this->assignment, 'portfolio_load_data'))) { return $this->assignment->portfolio_load_data($this); } if (empty($this->fileid)) { if (empty($this->submissionid)) { throw new portfolio_caller_exception('invalidfileandsubmissionid', 'mod_assignment'); } if (!($submission = $DB->get_record('assignment_submissions', array('assignment' => $assignment->id, 'id' => $this->submissionid)))) { throw new portfolio_caller_exception('invalidsubmissionid', 'mod_assignment'); } $submissionid = $submission->id; } else { // once we know the file id, we do not need the submission $submissionid = null; } $this->set_file_and_format_data($this->fileid, $this->assignment->context->id, 'mod_assignment', 'submission', $submissionid, 'timemodified', false); }
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); }
/** * 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('assignment', $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: assignment instance if (!($this->moodle_assignment_instance = get_record('assignment', 'id', $this->cm->instance))) { sloodle_debug("Failed to load assignment with instance ID #{$cm->instance}.<br/>"); return false; } // Make sure this assignment is of the correct type if ($this->moodle_assignment_instance->assignmenttype != 'sloodleobject') { sloodle_debug("ERROR assignment \"{$this->moodle_assignment_instance->name}\" is not of type 'sloodleobject' (actual type: '{$this->moodle_assignment_instance->assignmenttype}')."); return false; } // Attempt to construct the assignment object $this->assignment = new assignment_sloodleobject($this->cm->id, $this->moodle_assignment_instance, $this->cm); return true; }
/** * 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); }
/** * Explicit constructor to set the properties declared by the parent class. * * Firstly we call the parent's constructor to set the $this->id property * from the passed argument. Then we populate the $this->cm so that the * default parent class methods work well. * * @param array $callbackargs */ public function __construct($callbackargs) { // Let the parent class set the $this->id property. parent::__construct($callbackargs); // Populate the $this->cm property. $this->cm = get_coursemodule_from_id('workshop', $this->id, 0, false, MUST_EXIST); }
function showListOfLinks($id, $resop) { global $OUTPUT, $DB; //need it to check capability $cm = get_coursemodule_from_id('resop', $id, 0, false, MUST_EXIST); $context = context_module::instance($cm->id); echo $OUTPUT->heading(get_string('entries', 'resop'), 4); echo $OUTPUT->action_link(new moodle_url('view.php', array('id' => $id, 'action' => 'showAll')), get_string('showall', 'resop')); // Required //linkliste Klassen/Resources - specific for this resop instance $text = $resop->type == 'typeexam' ? get_string('resExam', 'resop') : get_string('resFree', 'resop'); echo $OUTPUT->heading($text, 4); $resources = $DB->get_records_sql('SELECT DISTINCT name FROM {resop_resource_user} ru JOIN {resop_resource} rr ' . " ON ru.resid=rr.id WHERE ru.actid={$resop->id} ORDER BY name"); //ok, should only be the resources which are handled in this resop instance foreach ($resources as $key => $value) { echo $OUTPUT->action_link(new moodle_url('view.php', array('id' => $id, 'action' => 'showClass', 'class' => $key)), $key); // Required echo " "; } //link list owner over all instances of resop modul if (has_capability('mod/resop:book', $context)) { echo $OUTPUT->heading(get_string('bookedby_header', 'resop'), 4); $resources = $DB->get_records_sql('SELECT DISTINCT name FROM {resop_resource_user} ru JOIN {resop_resop_user} rru ' . 'on ru.uid = rru.uid JOIN {resop_user} u on ru.uid=u.id ORDER BY name'); foreach ($resources as $key => $value) { echo $OUTPUT->action_link(new moodle_url('view.php', array('id' => $id, 'action' => 'showBooker', 'name' => $key)), $key); echo " "; } } }
/** * 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; }
/** * 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); }
function quizcopy_add_instance(&$quizcopy) { $cmid = $quizcopy->quiz; $name = $quizcopy->name; $cm = get_coursemodule_from_id('quiz', $cmid); if (!($quiz = get_record('quiz', 'id', $cm->instance))) { print_error('error', 'quizcopy'); } $origquiz = $quiz->id; unset($quiz->id); // remove single quote to prevent SQL errors (nadavkav 11-6-11) $quiz->name = str_replace("'", '', $name); $quiz->intro = str_replace("'", '', $quiz->intro); if (!($quiz->id = insert_record('quiz', $quiz))) { print_error('error', 'quizcopy'); } $newquestions = array(); if (!is_null($quiz->questions) && !empty($quiz->questions)) { $questions = explode(',', $quiz->questions); foreach ($questions as $question) { $newquestions[] = $question; if ($question != 0) { if (!($instance_object = get_record('quiz_question_instances', 'quiz', $origquiz, 'question', $question))) { print_error('error', 'quizcopy'); } unset($instance_object->id); $instance_object->quiz = $quiz->id; if (!insert_record('quiz_question_instances', $instance_object)) { print_error('error', 'quizcopy'); } } } } if ($feedbacks = get_records('quiz_feedback', 'quizid', $origquiz, 'maxgrade DESC')) { $i = 0; $quiz->feedbacktext = array(); $quiz->feedbackboundaries = array(); foreach ($feedbacks as $feedback) { $quiz->feedbacktext[$i] = $feedback->feedbacktext; $quiz->feedbackboundaries[$i] = $feedback->mingrade; $quiz->feedbackboundaries[$i - 1] = $feedback->maxgrade; $i++; } $quiz->feedbackboundarycount = $i - 1; } $quiz->questions = implode(',', $newquestions); if (!update_record('quiz', $quiz)) { print_error('error', 'quizcopy'); } $quizcopy->timecreated = time(); $quizcopy->module = $cm->module; $quizcopy->modulename = 'quiz'; $quizcopy->visible = $cm->visible; $quizcopy->groupmode = $cm->groupmode; $quizcopy->groupmembersonly = $cm->groupmembersonly; $quizcopy->module = $cm->module; quiz_after_add_or_update($quiz); return $quiz->id; }
/** * Obtains full cm, subpage and course records and constructs a subpage object. * * @param int $cmid the course module id * @return class mod_subpage */ public static function get_from_cmid($cmid) { global $DB; $cm = get_coursemodule_from_id('subpage', $cmid, 0, false, MUST_EXIST); $subpage = $DB->get_record('subpage', array('id' => $cm->instance), '*', MUST_EXIST); $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); return new mod_subpage($subpage, $cm, $course); }
public function __construct($id, $data = array()) { global $DB; $this->id = $id; $this->data = $data; $this->submissiondata = $DB->get_record('plagiarism_turnitin_files', array('id' => $id)); $this->cm = get_coursemodule_from_id('', $this->submissiondata->cm); }
public function __construct($cmid, $roundid = -1) { global $DB; $this->cm = get_coursemodule_from_id('hotquestion', $cmid, 0, false, MUST_EXIST); $this->course = $DB->get_record('course', array('id' => $this->cm->course), '*', MUST_EXIST); $this->instance = $DB->get_record('hotquestion', array('id' => $this->cm->instance), '*', MUST_EXIST); $this->set_current_round($roundid); }
/** * Save file recorded during congrea session when local file is * serving for virtual class * * @package mod_congrea * @copyright 2016 Suman Bogati * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ function record_file_save($getdata, $postdata, $valparams, $DB) { global $CFG; list($cmid, $userid, $filenum, $vmsession, $data) = $valparams; if ($cmid) { $cm = get_coursemodule_from_id('congrea', $cmid, 0, false, MUST_EXIST); $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); $congrea = $DB->get_record('congrea', array('id' => $cm->instance), '*', MUST_EXIST); } else { echo 'VCE6'; exit; //'Course module ID missing.'; } require_login($course, true, $cm); $context = context_module::instance($cm->id); $basefilepath = $CFG->dataroot . "/congrea"; // Place to save recording files. if (has_capability('mod/congrea:dorecording', $context)) { if ($data) { $filepath = $basefilepath . "/" . $course->id . "/" . $congrea->id . "/" . $vmsession; // Create folder if not exist if (!file_exists($filepath)) { mkdir($filepath, 0777, true); } $filename = "vc." . $filenum; if (file_put_contents($filepath . '/' . $filename, $data) != false) { //save file record in database if ($filenum > 1) { //update record $vcfile = $DB->get_record('congrea_files', array('vcid' => $congrea->id, 'vcsessionkey' => $vmsession)); $vcfile->numoffiles = $filenum; $DB->update_record('congrea_files', $vcfile); } else { $vcfile = new stdClass(); $vcfile->courseid = $course->id; $vcfile->vcid = $congrea->id; $vcfile->userid = $userid; $vcfile->vcsessionkey = $vmsession; $vcfile->vcsessionname = 'vc-' . $course->shortname . '-' . $congrea->name . $cm->id . '-' . date("Ymd") . '-' . date('Hi'); $vcfile->numoffiles = $filenum; $vcfile->timecreated = time(); //print_r($vcfile);exit; $DB->insert_record('congrea_files', $vcfile); } echo "done"; } else { echo 'VCE5'; //'Unable to record data.';exit; } } else { echo 'VCE4'; //'No data for recording.'; } } else { echo 'VCE2'; //'Permission denied'; } }
public function test_grade_get_grade_items_for_activity() { $this->resetAfterTest(true); $course = $this->getDataGenerator()->create_course(); $forum = $this->getDataGenerator()->create_module('forum', array('course' => $course->id)); $cm = get_coursemodule_from_id('forum', $forum->cmid, $forum->course); unset($cm->modname); $grade = grade_get_grade_items_for_activity($cm); }
/** * Constructor for the base assignment class * * Constructor for the base assignment class. * If cmid is set create the cm, course, assignment objects. * If the assignment is hidden and the user is not a teacher then * this prints a page header and notice. * * @param cmid integer, the current course module id - not set for new assignments * @param assignment object, usually null, but if we have it we pass it to save db access * @param cm object, usually null, but if we have it we pass it to save db access * @param course object, usually null, but if we have it we pass it to save db access */ function assignment_base($cmid = 'staticonly', $assignment = NULL, $cm = NULL, $course = NULL) { if ($cmid == 'staticonly') { //use static functions only! return; } global $CFG; if ($cm) { $this->cm = $cm; } else { if (!($this->cm = get_coursemodule_from_id('assignment', $cmid))) { error('Course Module ID was incorrect'); } } $this->context = get_context_instance(CONTEXT_MODULE, $this->cm->id); if ($course) { $this->course = $course; } else { if (!($this->course = get_record('course', 'id', $this->cm->course))) { error('Course is misconfigured'); } } if ($assignment) { $this->assignment = $assignment; } else { if (!($this->assignment = get_record('assignment', 'id', $this->cm->instance))) { error('assignment ID was incorrect'); } } $this->assignment->cmidnumber = $this->cm->id; // compatibility with modedit assignment obj $this->assignment->courseid = $this->course->id; // compatibility with modedit assignment obj $this->strassignment = get_string('modulename', 'assignment'); $this->strassignments = get_string('modulenameplural', 'assignment'); $this->strsubmissions = get_string('submissions', 'assignment'); $this->strlastmodified = get_string('lastmodified'); $this->navigation[] = array('name' => $this->strassignments, 'link' => "index.php?id={$this->course->id}", 'type' => 'activity'); $this->pagetitle = strip_tags($this->course->shortname . ': ' . $this->strassignment . ': ' . format_string($this->assignment->name, true)); // visibility $context = get_context_instance(CONTEXT_MODULE, $cmid); if (!$this->cm->visible and !has_capability('moodle/course:viewhiddenactivities', $context)) { $pagetitle = strip_tags($this->course->shortname . ': ' . $this->strassignment); $this->navigation[] = array('name' => $this->strassignment, 'link' => '', 'type' => 'activityinstance'); $navigation = build_navigation($this->navigation); print_header($pagetitle, $this->course->fullname, $this->navigation, "", "", true, '', navmenu($this->course, $this->cm)); notice(get_string("activityiscurrentlyhidden"), "{$CFG->wwwroot}/course/view.php?id={$this->course->id}"); } $this->currentgroup = groups_get_activity_group($this->cm); /// Set up things for a HTML editor if it's needed if ($this->usehtmleditor = can_use_html_editor()) { $this->defaultformat = FORMAT_HTML; } else { $this->defaultformat = FORMAT_MOODLE; } }