public static function fix_page($pages) { //Don't forget to set it as static global $CFG, $DB; $params = self::validate_parameters(self::fix_page_parameters(), array('pages' => $pages)); $transaction = $DB->start_delegated_transaction(); //If an exception is thrown in the below code, all DB queries in this code will be rollback. $newpages = array(); foreach ($params['pages'] as $page) { $page = (object) $page; if (!($student = $DB->get_record('user', array('id' => $page->studentid)))) { throw new invalid_parameter_exception('No student with the specified id'); } list($cm, $emarking, $course, $context) = emarking_get_cm_course_instance_by_id($page->cmid); // now security checks self::validate_context($context); require_capability('mod/emarking:uploadexam', $context); // finally fix the page $page->id = emarking_fix_page($page->fileid, $student, $emarking, $context, $page->pagenumber); if ($page->id > 0) { $newpages[] = array('id' => $page->id); } } $transaction->allow_commit(); return $newpages; }
/** * Obtains course module ($cm), course, emarking and context * objects from cm id in the URL * * @return multitype:stdClass context_module unknown mixed */ function emarking_get_cm_course_instance() { global $DB; // Course module id. $cmid = required_param('id', PARAM_INT); return emarking_get_cm_course_instance_by_id($cmid); }