$section = required_param('section', PARAM_INT);
$course = required_param('course', PARAM_INT);
- if (! $course = get_record("course", "id", $course)) {
+ if (! $course = $DB->get_record("course", array("id"=>$course))) {
print_error("invalidcourseid");
}
$context = get_context_instance(CONTEXT_COURSE, $course->id);
require_capability('moodle/course:manageactivities', $context);
- if (! $module = get_record("modules", "name", $add)) {
+ if (! $module = $DB->get_record("modules", array("name"=>$add))) {
print_error("moduledoesnotexist");
}
$cm = null;
+ $form = new object();
$form->section = $section; // The section number itself - relative!!! (section column in course_sections)
$form->visible = $cw->visible;
$form->course = $course->id;
}
$navlinksinstancename = '';
+
} else if (!empty($update)) {
- if (! $cm = get_record("course_modules", "id", $update)) {
+ if (! $cm = $DB->get_record("course_modules", array("id"=>$update))) {
print_error("cmunknown");
}
- if (! $course = get_record("course", "id", $cm->course)) {
+ if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
print_error("invalidcourseid");
}
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
require_capability('moodle/course:manageactivities', $context);
- if (! $module = get_record("modules", "id", $cm->module)) {
+ if (! $module = $DB->get_record("modules", array("id"=>$cm->module))) {
print_error("moduledoesnotexist");
}
- if (! $form = get_record($module->name, "id", $cm->instance)) {
- print_error("moduleinstancedoesnotexist");
- }
-
- if (! $cw = get_record("course_sections", "id", $cm->section)) {
+ if (! $cw = $DB->get_record("course_sections", array("id"=>$cm->section))) {
print_error("sectionnotexist");
}
+ $form = clone($cm);
$form->coursemodule = $cm->id;
$form->section = $cw->section; // The section number itself - relative!!! (section column in course_sections)
$form->visible = $cm->visible; //?? $cw->visible ? $cm->visible : 0; // section hiding overrides
} else {
redirect("$CFG->wwwroot/course/view.php?id=$course->id#section-".$cw->section);
}
- } else if ($fromform = $mform->get_data()) {
+ } else if ($fromform = $mform->get_data(false)) {
if (empty($fromform->coursemodule)) { //add
$cm = null;
- if (! $course = get_record("course", "id", $fromform->course)) {
+ if (! $course = $DB->get_record("course", array("id"=>$fromform->course))) {
print_error("invalidcourseid");
}
$fromform->instance = '';
$fromform->coursemodule = '';
} else { //update
- if (! $cm = get_record("course_modules", "id", $fromform->coursemodule)) {
+ if (! $cm = $DB->get_record("course_modules", array("id"=>$fromform->coursemodule))) {
print_error("cmunknown");
}
- if (! $course = get_record("course", "id", $cm->course)) {
+ if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
print_error("invalidcourseid");
}
$fromform->instance = $cm->instance;
print_error("cannotaddcmtosection");
}
- if (! set_field("course_modules", "section", $sectionid, "id", $fromform->coursemodule)) {
+ if (! $DB->set_field("course_modules", "section", $sectionid, array("id"=>$fromform->coursemodule))) {
print_error("cannotupdatecm");
}
* @param mixed array or object describing supported features - groups, groupings, groupmembersonly, etc.
*/
function standard_coursemodule_elements($features=null){
- global $COURSE, $CFG;
+ global $COURSE, $CFG, $DB;
$mform =& $this->_form;
// deal with legacy $supportgroups param
//groupings selector - used for normal grouping mode or also when restricting access with groupmembersonly
$options = array();
$options[0] = get_string('none');
- if ($groupings = get_records('groupings', 'courseid', $COURSE->id)) {
+ if ($groupings = $DB->get_records('groupings', array('courseid'=>$COURSE->id))) {
foreach ($groupings as $grouping) {
$options[$grouping->id] = format_string($grouping->name);
}
* @return int The id of the assignment
*/
function add_instance($assignment) {
- global $COURSE;
+ global $COURSE, $DB;
$assignment->timemodified = time();
$assignment->courseid = $assignment->course;
- if ($returnid = insert_record("assignment", $assignment)) {
+ if ($returnid = $DB->insert_record("assignment", $assignment)) {
$assignment->id = $returnid;
if ($assignment->timedue) {
add_event($event);
}
- $assignment = stripslashes_recursive($assignment);
assignment_grade_item_update($assignment);
}
* @return boolean False indicates error
*/
function delete_instance($assignment) {
- global $CFG;
+ global $CFG, $DB;
$assignment->courseid = $assignment->course;
$result = true;
- if (! delete_records('assignment_submissions', 'assignment', $assignment->id)) {
+ if (! $DB->delete_records('assignment_submissions', array('assignment'=>$assignment->id))) {
$result = false;
}
- if (! delete_records('assignment', 'id', $assignment->id)) {
+ if (! $DB->delete_records('assignment', array('id'=>$assignment->id))) {
$result = false;
}
- if (! delete_records('event', 'modulename', 'assignment', 'instance', $assignment->id)) {
+ if (! $DB->delete_records('event', array('modulename'=>'assignment', 'instance'=>$assignment->id))) {
$result = false;
}
* @return int The assignment id
*/
function update_instance($assignment) {
- global $COURSE;
+ global $COURSE, $DB;
$assignment->timemodified = time();
$assignment->id = $assignment->instance;
$assignment->courseid = $assignment->course;
- if (!update_record('assignment', $assignment)) {
+ if (!$DB->update_record('assignment', $assignment)) {
return false;
}
if ($assignment->timedue) {
$event = new object();
- if ($event->id = get_field('event', 'id', 'modulename', 'assignment', 'instance', $assignment->id)) {
+ if ($event->id = $DB->get_field('event', 'id', array('modulename'=>'assignment', 'instance'=>$assignment->id))) {
$event->name = $assignment->name;
$event->description = $assignment->description;
add_event($event);
}
} else {
- delete_records('event', 'modulename', 'assignment', 'instance', $assignment->id);
+ $DB->delete_records('event', array('modulename'=>'assignment', 'instance'=>$assignment->id));
}
// get existing grade item
- $assignment = stripslashes_recursive($assignment);
-
assignment_grade_item_update($assignment);
return true;
* This is done by calling the delete_instance() method of the assignment type class
*/
function assignment_delete_instance($id){
- global $CFG;
+ global $CFG, $DB;
- if (! $assignment = get_record('assignment', 'id', $id)) {
+ if (! $assignment = $DB->get_record('assignment', array('id'=>$id))) {
return false;
}
class mod_assignment_mod_form extends moodleform_mod {
function definition() {
- global $CFG;
+ global $CFG, $DB;
$mform =& $this->_form;
// this hack is needed for different settings of each subtype
if (!empty($this->_instance)) {
- if($ass = get_record('assignment', 'id', (int)$this->_instance)) {
+ if($ass = $DB->get_record('assignment', array('id', $this->_instance))) {
$type = $ass->assignmenttype;
} else {
print_error('invalidassignment', 'assignment');
$CHAT_DUMMY_DATA = "<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n<!-- nix -->\n";
function chat_add_instance($chat) {
+ global $DB;
/// Given an object containing all the necessary data,
/// (defined by the form in mod_form.php) this function
/// will create a new instance and return the id number
$chat->timemodified = time();
- if ($returnid = insert_record("chat", $chat)) {
+ if ($returnid = $DB->insert_record("chat", $chat)) {
$event = NULL;
$event->name = $chat->name;
function chat_update_instance($chat) {
+ global $DB;
/// Given an object containing all the necessary data,
/// (defined by the form in mod_form.php) this function
/// will update an existing instance with new data.
$chat->id = $chat->instance;
- if ($returnid = update_record("chat", $chat)) {
+ if ($returnid = $DB->update_record("chat", $chat)) {
$event = new object();
- if ($event->id = get_field('event', 'id', 'modulename', 'chat', 'instance', $chat->id)) {
+ if ($event->id = $DB->get_field('event', 'id', array('modulename'=>'chat', 'instance'=>$chat->id))) {
$event->name = $chat->name;
$event->description = $chat->intro;
function chat_delete_instance($id) {
+ global $DB;
/// Given an ID of an instance of this module,
/// this function will permanently delete the instance
/// and any data that depends on it.
- if (! $chat = get_record('chat', 'id', $id)) {
+ if (! $chat = $DB->get_record('chat', array('id'=>$id))) {
return false;
}
# Delete any dependent records here #
- if (! delete_records('chat', 'id', $chat->id)) {
+ if (! $DB->delete_records('chat', array('id'=>$chat->id))) {
$result = false;
}
- if (! delete_records('chat_messages', 'chatid', $chat->id)) {
+ if (! $DB->delete_records('chat_messages', array('chatid'=>$chat->id))) {
$result = false;
}
- if (! delete_records('chat_users', 'chatid', $chat->id)) {
+ if (! $DB->delete_records('chat_users', array('chatid'=>$chat->id))) {
$result = false;
}
$pagetypes = page_import_types('mod/chat/');
foreach($pagetypes as $pagetype) {
- if(!delete_records('block_instance', 'pageid', $chat->id, 'pagetype', $pagetype)) {
+ if (!$DB->delete_records('block_instance', array('pageid'=>$chat->id, 'pagetype'=>$pagetype))) {
$result = false;
}
}
- if (! delete_records('event', 'modulename', 'chat', 'instance', $chat->id)) {
+ if (! $DB->delete_records('event', array('modulename'=>'chat', 'instance'=>$chat->id))) {
$result = false;
}
class mod_chat_mod_form extends moodleform_mod {
function definition() {
-
- global $CFG;
+ global $CFG, $DB;
$mform =& $this->_form;
//-------------------------------------------------------------------------------
function choice_add_instance($choice) {
+ global $DB;
// Given an object containing all the necessary data,
// (defined by the form in mod_form.php) this function
// will create a new instance and return the id number
}
//insert answers
- if ($choice->id = insert_record("choice", $choice)) {
+ if ($choice->id = $DB->insert_record("choice", $choice)) {
foreach ($choice->option as $key => $value) {
$value = trim($value);
if (isset($value) && $value <> '') {
$option->maxanswers = $choice->limit[$key];
}
$option->timemodified = time();
- insert_record("choice_options", $option);
+ $DB->insert_record("choice_options", $option);
}
}
}
function choice_update_instance($choice) {
+ global $DB;
// Given an object containing all the necessary data,
// (defined by the form in mod_form.php) this function
// will update an existing instance with new data.
if (isset($choice->optionid[$key]) && !empty($choice->optionid[$key])){//existing choice record
$option->id=$choice->optionid[$key];
if (isset($value) && $value <> '') {
- update_record("choice_options", $option);
+ $DB->update_record("choice_options", $option);
} else { //empty old option - needs to be deleted.
- delete_records("choice_options", "id", $option->id);
+ $DB->delete_records("choice_options", array("id"=>$option->id));
}
} else {
if (isset($value) && $value <> '') {
- insert_record("choice_options", $option);
+ $DB->insert_record("choice_options", $option);
}
}
}
- return update_record('choice', $choice);
+ return $DB->update_record('choice', $choice);
}
function choice_delete_instance($id) {
+ global $DB;
// Given an ID of an instance of this module,
// this function will permanently delete the instance
// and any data that depends on it.
- if (! $choice = get_record("choice", "id", "$id")) {
+ if (! $choice = $DB->get_record("choice", array("id"=>"$id"))) {
return false;
}
$result = true;
- if (! delete_records("choice_answers", "choiceid", "$choice->id")) {
+ if (! $DB->delete_records("choice_answers", array("choiceid"=>"$choice->id"))) {
$result = false;
}
- if (! delete_records("choice_options", "choiceid", "$choice->id")) {
+ if (! $DB->delete_records("choice_options", array("choiceid"=>"$choice->id"))) {
$result = false;
}
- if (! delete_records("choice", "id", "$choice->id")) {
+ if (! $DB->delete_records("choice", array("id"=>"$choice->id"))) {
$result = false;
}
class mod_choice_mod_form extends moodleform_mod {
function definition() {
- global $CHOICE_SHOWRESULTS, $CHOICE_PUBLISH, $CHOICE_DISPLAY;
+ global $CHOICE_SHOWRESULTS, $CHOICE_PUBLISH, $CHOICE_DISPLAY, $DB;
$mform =& $this->_form;
$mform->setHelpButton('limitanswers', array('limit', get_string('limit', 'choice'), 'choice'));
if ($this->_instance){
- $repeatno=count_records('choice_options', 'choiceid', $this->_instance);
+ $repeatno = $DB->count_records('choice_options', array('choiceid'=>$this->_instance));
$repeatno += 2;
} else {
$repeatno = 5;
* Adds an instance of a data *
************************************************************************/
function data_add_instance($data) {
- global $CFG;
+ global $CFG, $DB;
if (empty($data->assessed)) {
$data->assessed = 0;
$data->timemodified = time();
- if (! $data->id = insert_record('data', $data)) {
+ if (! $data->id = $DB->insert_record('data', $data)) {
return false;
}
- $data = stripslashes_recursive($data);
data_grade_item_update($data);
return $data->id;
* updates an instance of a data *
************************************************************************/
function data_update_instance($data) {
- global $CFG;
+ global $CFG, $DB;
$data->timemodified = time();
$data->id = $data->instance;
$data->notification = 0;
}
- if (! update_record('data', $data)) {
+ if (! $DB->update_record('data', $data)) {
return false;
}
- $data = stripslashes_recursive($data);
data_grade_item_update($data);
return true;
* deletes an instance of a data *
************************************************************************/
function data_delete_instance($id) { // takes the dataid
+ global $CFG, $DB;
- global $CFG;
-
- if (! $data = get_record('data', 'id', $id)) {
+ if (! $data = $DB->get_record('data', array('id'=>$id))) {
return false;
}
// Delete all the associated information
// get all the records in this data
- $sql = 'SELECT c.* FROM '.$CFG->prefix.'data_records r LEFT JOIN '.
- $CFG->prefix.'data_content c ON c.recordid = r.id WHERE r.dataid = '.$id;
+ $sql = 'SELECT c.* FROM {data_records} r LEFT JOIN {data_content} c ON c.recordid = r.id WHERE r.dataid =?';
- if ($contents = get_records_sql($sql)){
+ if ($contents = $DB->get_records_sql($sql, array($id))){
foreach($contents as $content){
- $field = get_record('data_fields','id',$content->fieldid);
+ $field = $DB->get_record('data_fields', array('id'=>$content->fieldid));
if ($g = data_get_field($field, $data)){
$g->delete_content_files($id, $content->recordid, $content->content);
}
//delete the content itself
- delete_records('data_content','id', $content->id);
+ $DB->delete_records('data_content', array('id'=>$content->id));
}
}
// delete all the records and fields
- delete_records('data_records', 'dataid', $id);
- delete_records('data_fields','dataid',$id);
+ $DB->delete_records('data_records', array('dataid'=>$id));
+ $DB->delete_records('data_fields', array('dataid'=>$id));
// Delete the instance itself
- $result = delete_records('data', 'id', $id);
+ $result = $DB->delete_records('data', array('id'=>$id));
data_grade_item_delete($data);
class mod_data_mod_form extends moodleform_mod {
function definition() {
+ global $CFG, $DB;
- global $CFG;
$mform =& $this->_form;
//-------------------------------------------------------------------------------
* TODO document
*/
function import() {
- global $CFG;
+ global $CFG, $DB;
list($settings, $newfields, $currentfields) = $this->load_from_file();
$preservedfields = array();
}
}
*/
- delete_records('data_content', 'fieldid', $id);
- delete_records('data_fields', 'id', $id);
+ $DB->delete_records('data_content', array('fieldid'=>$id));
+ $DB->delete_records('data_fields', array('id'=>$id));
}
}
}
- data_update_instance(addslashes_object($settings));
+ data_update_instance($settings);
if (strstr($this->directory, '/temp/')) clean_preset($this->directory); /* Removes the temporary files */
return true;
* @return int
*/
function feedback_add_instance($feedback) {
+ global $DB;
$feedback->timemodified = time();
$feedback->id = '';
}
//saving the feedback in db
- if(!$feedbackid = insert_record("feedback", $feedback)) {
+ if (!$feedbackid = $DB->insert_record("feedback", $feedback)) {
return false;
}
* @return boolean
*/
function feedback_update_instance($feedback) {
+ global $DB;
$feedback->timemodified = time();
$feedback->id = $feedback->instance;
}
//save the feedback into the db
- if(!update_record("feedback", $feedback)) {
+ if (!$DB->update_record("feedback", $feedback)) {
return false;
}
* @return boolean
*/
function feedback_delete_instance($id) {
+ global $DB;
+
//get all referenced items
- $feedbackitems = get_records('feedback_item', 'feedback', $id);
+ $feedbackitems = $DB->get_records('feedback_item', array('feedback'=>$id));
//deleting all referenced items and values
if (is_array($feedbackitems)){
foreach($feedbackitems as $feedbackitem){
- @delete_records("feedback_value", "item", $feedbackitem->id);
- @delete_records("feedback_valuetmp", "item", $feedbackitem->id);
+ $DB->delete_records("feedback_value", array("item"=>$feedbackitem->id));
+ $DB->delete_records("feedback_valuetmp", array("item"=>$feedbackitem->id));
}
- @delete_records("feedback_item", "feedback", $id);
+ $DB->delete_records("feedback_item", array("feedback"=>$id));
}
//deleting the referenced tracking data
- @delete_records('feedback_tracking', 'feedback', $id);
+ $DB->delete_records('feedback_tracking', array('feedback'=>$id));
//deleting the completeds
- @delete_records("feedback_completed", "feedback", $id);
+ $DB->delete_records("feedback_completed", array("feedback"=>$id));
//deleting the unfinished completeds
- @delete_records("feedback_completedtmp", "feedback", $id);
+ $DB->delete_records("feedback_completedtmp", array("feedback"=>$id));
//deleting old events
- @delete_records('event', 'modulename', 'feedback', 'instance', $id);
- return @delete_records("feedback", "id", $id);
+ $DB->delete_records('event', array('modulename'=>'feedback', 'instance'=>$id));
+ return $DB->delete_records("feedback", array("id"=>$id));
}
/**
* @return void
*/
function feedback_set_events($feedback) {
+ global $DB;
+
// adding the feedback to the eventtable (I have seen this at quiz-module)
- delete_records('event', 'modulename', 'feedback', 'instance', $feedback->id);
+ $DB->delete_records('event', array('modulename'=>'feedback', 'instance'=>$feedback->id));
// the open-event
if($feedback->timeopen > 0) {
$event->groupid = 0;
$event->userid = 0;
$event->modulename = 'feedback';
- $event->instance = $feedbackid;
+ $event->instance = $feedback->id;
$event->eventtype = 'open';
$event->timestart = $feedback->timeopen;
$event->visible = instance_is_visible('feedback', $feedback);
$event->groupid = 0;
$event->userid = 0;
$event->modulename = 'feedback';
- $event->instance = $feedbackid;
+ $event->instance = $feedback->id;
$event->eventtype = 'close';
$event->timestart = $feedback->timeclose;
$event->visible = instance_is_visible('feedback', $feedback);
class mod_feedback_mod_form extends moodleform_mod {
function definition() {
- global $CFG;
+ global $CFG, $DB;
$mform =& $this->_form;
$mform->setHelpButton('email_notification', array('emailnotification', get_string('email_notification', 'feedback'), 'feedback'));
// check if there is existing responses to this feedback
- if (is_numeric($this->_instance) AND $this->_instance and $feedback = get_record("feedback", "id", $this->_instance)) {
+ if (is_numeric($this->_instance) AND $this->_instance and $feedback = $DB->get_record("feedback", array("id"=>$this->_instance))) {
$completedFeedbackCount = feedback_get_completeds_group_count($feedback);
} else {
$completedFeedbackCount = false;
* @return int intance id
*/
function forum_add_instance($forum) {
- global $CFG;
+ global $CFG, $DB;
$forum->timemodified = time();
$forum->assesstimefinish = 0;
}
- if (!$forum->id = insert_record('forum', $forum)) {
+ if (!$forum->id = $DB->insert_record('forum', $forum)) {
return false;
}
}
}
- $forum = stripslashes_recursive($forum);
forum_grade_item_update($forum);
return $forum->id;
* @return bool success
*/
function forum_update_instance($forum) {
+ global $DB;
+
$forum->timemodified = time();
$forum->id = $forum->instance;
$forum->assesstimefinish = 0;
}
- $oldforum = get_record('forum', 'id', $forum->id);
+ $oldforum = $DB->get_record('forum', array('id'=>$forum->id));
// MDL-3942 - if the aggregation type or scale (i.e. max grade) changes then recalculate the grades for the entire forum
// if scale changes - do we need to recheck the ratings, if ratings higher than scale how do we want to respond?
}
if ($forum->type == 'single') { // Update related discussion and post.
- if (! $discussion = get_record('forum_discussions', 'forum', $forum->id)) {
- if ($discussions = get_records('forum_discussions', 'forum', $forum->id, 'timemodified ASC')) {
+ if (! $discussion = $DB->get_record('forum_discussions', array('forum'=>$forum->id))) {
+ if ($discussions = $DB->get_records('forum_discussions', array('forum'=>$forum->id), 'timemodified ASC')) {
notify('Warning! There is more than one discussion in this forum - using the most recent');
$discussion = array_pop($discussions);
} else {
error('Could not find the discussion in this forum');
}
}
- if (! $post = get_record('forum_posts', 'id', $discussion->firstpost)) {
+ if (! $post = $DB->get_record('forum_posts', array('id'=>$discussion->firstpost))) {
error('Could not find the first post in this forum discussion');
}
$post->message = $forum->intro;
$post->modified = $forum->timemodified;
- if (! update_record('forum_posts', ($post))) {
+ if (! $DB->update_record('forum_posts', ($post))) {
error('Could not update the first post');
}
$discussion->name = $forum->name;
- if (! update_record('forum_discussions', ($discussion))) {
+ if (! $DB->update_record('forum_discussions', ($discussion))) {
error('Could not update the discussion');
}
}
- if (!update_record('forum', $forum)) {
+ if (!$DB->update_record('forum', $forum)) {
error('Can not update forum');
}
- $forum = stripslashes_recursive($forum);
forum_grade_item_update($forum);
return true;
* @return bool success
*/
function forum_delete_instance($id) {
+ global $DB;
- if (!$forum = get_record('forum', 'id', $id)) {
+ if (!$forum = $DB->get_record('forum', array('id'=>$id))) {
return false;
}
$result = true;
- if ($discussions = get_records('forum_discussions', 'forum', $forum->id)) {
+ if ($discussions = $DB->get_records('forum_discussions', array('forum'=>$forum->id))) {
foreach ($discussions as $discussion) {
if (!forum_delete_discussion($discussion, true)) {
$result = false;
}
}
- if (!delete_records('forum_subscriptions', 'forum', $forum->id)) {
+ if (!$DB->delete_records('forum_subscriptions', array('forum'=>$forum->id))) {
$result = false;
}
forum_tp_delete_read_records(-1, -1, -1, $forum->id);
- if (!delete_records('forum', 'id', $forum->id)) {
+ if (!$DF->delete_records('forum', array('id'=>$forum->id))) {
$result = false;
}
*
*/
function forum_add_attachment($post, $inputname,&$message) {
+ global $CFG, $DB;
- global $CFG;
-
- if (!$forum = get_record("forum", "id", $post->forum)) {
+ if (!$forum = $DB->get_record("forum", array("id"=>$post->forum))) {
return "";
}
- if (!$course = get_record("course", "id", $forum->course)) {
+ if (!$course = $DB->get_record("course", array("id"=>$forum->course))) {
return "";
}
* create a new discussion and return the id
*/
function forum_add_discussion($discussion,&$message) {
-
- global $USER, $CFG;
+ global $USER, $CFG, $DB;
$timenow = time();
// The first post is stored as a real post, and linked
// to from the discuss entry.
- $forum = get_record('forum', 'id', $discussion->forum);
+ $forum = $DB->get_record('forum', array('id'=>$discussion->forum));
$post = new object();
$post->discussion = 0;
$post->format = $discussion->format;
$post->mailnow = $discussion->mailnow;
- if (! $post->id = insert_record("forum_posts", $post) ) {
+ if (! $post->id = $DB->insert_record("forum_posts", $post) ) {
return 0;
}
if ($post->attachment = forum_add_attachment($post, 'attachment',$message)) {
- set_field("forum_posts", "attachment", $post->attachment, "id", $post->id); //ignore errors
+ $DB->set_field("forum_posts", "attachment", $post->attachment, array("id"=>$post->id)); //ignore errors
}
// Now do the main entry for the discussion,
$discussion->usermodified = $post->userid;
$discussion->userid = $USER->id;
- if (! $post->discussion = insert_record("forum_discussions", $discussion) ) {
- delete_records("forum_posts", "id", $post->id);
+ if (! $post->discussion = $DB->insert_record("forum_discussions", $discussion) ) {
+ $DB->delete_records("forum_posts", array("id"=>$post->id));
return 0;
}
// Finally, set the pointer on the post.
- if (! set_field("forum_posts", "discussion", $post->discussion, "id", $post->id)) {
- delete_records("forum_posts", "id", $post->id);
- delete_records("forum_discussions", "id", $post->discussion);
+ if (! $DB->set_field("forum_posts", "discussion", $post->discussion, array("id"=>$post->id))) {
+ $DB->delete_records("forum_posts", array("id"=>$post->id));
+ $DB->delete_records("forum_discussions", array("id"=>$post->discussion));
return 0;
}
class mod_forum_mod_form extends moodleform_mod {
function definition() {
+ global $CFG, $COURSE, $DB;
- global $CFG, $COURSE;
$mform =& $this->_form;
//-------------------------------------------------------------------------------
if ( $xmlglossary['NAME'][0]['#'] ) {
unset($glossary);
- $glossary->name = addslashes($xmlglossary['NAME'][0]['#']);
+ $glossary->name = ($xmlglossary['NAME'][0]['#']);
$glossary->course = $course->id;
- $glossary->globalglossary = addslashes($xmlglossary['GLOBALGLOSSARY'][0]['#']);
- $glossary->intro = addslashes($xmlglossary['INTRO'][0]['#']);
- $glossary->showspecial = addslashes($xmlglossary['SHOWSPECIAL'][0]['#']);
- $glossary->showalphabet = addslashes($xmlglossary['SHOWALPHABET'][0]['#']);
- $glossary->showall = addslashes($xmlglossary['SHOWALL'][0]['#']);
+ $glossary->globalglossary = ($xmlglossary['GLOBALGLOSSARY'][0]['#']);
+ $glossary->intro = ($xmlglossary['INTRO'][0]['#']);
+ $glossary->showspecial = ($xmlglossary['SHOWSPECIAL'][0]['#']);
+ $glossary->showalphabet = ($xmlglossary['SHOWALPHABET'][0]['#']);
+ $glossary->showall = ($xmlglossary['SHOWALL'][0]['#']);
$glossary->timecreated = time();
$glossary->timemodified = time();
// Setting the default values if no values were passed
if ( isset($xmlglossary['ENTBYPAGE'][0]['#']) ) {
- $glossary->entbypage = addslashes($xmlglossary['ENTBYPAGE'][0]['#']);
+ $glossary->entbypage = ($xmlglossary['ENTBYPAGE'][0]['#']);
} else {
$glossary->entbypage = $CFG->glossary_entbypage;
}
if ( isset($xmlglossary['ALLOWDUPLICATEDENTRIES'][0]['#']) ) {
- $glossary->allowduplicatedentries = addslashes($xmlglossary['ALLOWDUPLICATEDENTRIES'][0]['#']);
+ $glossary->allowduplicatedentries = ($xmlglossary['ALLOWDUPLICATEDENTRIES'][0]['#']);
} else {
$glossary->allowduplicatedentries = $CFG->glossary_dupentries;
}
if ( isset($xmlglossary['DISPLAYFORMAT'][0]['#']) ) {
- $glossary->displayformat = addslashes($xmlglossary['DISPLAYFORMAT'][0]['#']);
+ $glossary->displayformat = ($xmlglossary['DISPLAYFORMAT'][0]['#']);
} else {
$glossary->displayformat = 2;
}
if ( isset($xmlglossary['ALLOWCOMMENTS'][0]['#']) ) {
- $glossary->allowcomments = addslashes($xmlglossary['ALLOWCOMMENTS'][0]['#']);
+ $glossary->allowcomments = ($xmlglossary['ALLOWCOMMENTS'][0]['#']);
} else {
$glossary->allowcomments = $CFG->glossary_allowcomments;
}
if ( isset($xmlglossary['USEDYNALINK'][0]['#']) ) {
- $glossary->usedynalink = addslashes($xmlglossary['USEDYNALINK'][0]['#']);
+ $glossary->usedynalink = ($xmlglossary['USEDYNALINK'][0]['#']);
} else {
$glossary->usedynalink = $CFG->glossary_linkentries;
}
if ( isset($xmlglossary['DEFAULTAPPROVAL'][0]['#']) ) {
- $glossary->defaultapproval = addslashes($xmlglossary['DEFAULTAPPROVAL'][0]['#']);
+ $glossary->defaultapproval = ($xmlglossary['DEFAULTAPPROVAL'][0]['#']);
} else {
$glossary->defaultapproval = $CFG->glossary_defaultapproval;
}
/// STANDARD FUNCTIONS ///////////////////////////////////////////////////////////
function glossary_add_instance($glossary) {
+ global $DB;
/// Given an object containing all the necessary data,
/// (defined by the form in mod_form.php) this function
/// will create a new instance and return the id number
print_error("This format doesn't exist!");
}
- if ($returnid = insert_record("glossary", $glossary)) {
+ if ($returnid = $DB->insert_record("glossary", $glossary)) {
$glossary->id = $returnid;
- $glossary = stripslashes_recursive($glossary);
glossary_grade_item_update($glossary);
}
/// Given an object containing all the necessary data,
/// (defined by the form in mod_form.php) this function
/// will update an existing instance with new data.
- global $CFG;
+ global $CFG, $DB;
if (empty($glossary->globalglossary)) {
$glossary->globalglossary = 0;
print_error("This format doesn't exist!");
}
- if ($return = update_record("glossary", $glossary)) {
+ if ($return = $DB->update_record("glossary", $glossary)) {
if ($glossary->defaultapproval) {
- execute_sql("update {$CFG->prefix}glossary_entries SET approved = 1 where approved != 1 and glossaryid = " . $glossary->id,false);
+ $DB->execute("UPDATE {glossary_entries} SET approved = 1 where approved <> 1 and glossaryid = ?", array($glossary->id));
}
- $glossary = stripslashes_recursive($glossary);
glossary_grade_item_update($glossary);
}
function glossary_delete_instance($id) {
+ global $DB;
/// Given an ID of an instance of this module,
/// this function will permanently delete the instance
/// and any data that depends on it.
- if (! $glossary = get_record("glossary", "id", "$id")) {
+ if (! $glossary = $DB->get_record("glossary", array("id"=>"$id"))) {
return false;
}
# Delete any dependent records here #
- if (! delete_records("glossary", "id", "$glossary->id")) {
+ if (! $DB->delete_records("glossary", array("id"=>$glossary->id))) {
$result = false;
} else {
- if ($categories = get_records("glossary_categories","glossaryid",$glossary->id)) {
+ if ($categories = $DB->get_records("glossary_categories", array("glossaryid"=>$glossary->id))) {
$cats = "";
foreach ( $categories as $cat ) {
$cats .= "$cat->id,";
}
$cats = substr($cats,0,-1);
if ($cats) {
- delete_records_select("glossary_entries_categories", "categoryid in ($cats)");
- delete_records("glossary_categories", "glossaryid", $glossary->id);
+ $DB->delete_records_select("glossary_entries_categories", "categoryid in ($cats)");
+ $DB->delete_records("glossary_categories", array("glossaryid"=>$glossary->id));
}
}
- if ( $entries = get_records("glossary_entries", "glossaryid", $glossary->id) ) {
+ if ( $entries = $DB->get_records("glossary_entries", array("glossaryid"=>$glossary->id))) {
$ents = "";
foreach ( $entries as $entry ) {
if ( $entry->sourceglossaryid ) {
$entry->glossaryid = $entry->sourceglossaryid;
$entry->sourceglossaryid = 0;
- update_record("glossary_entries",$entry);
+ $DB->update_record("glossary_entries",$entry);
} else {
$ents .= "$entry->id,";
}
}
$ents = substr($ents,0,-1);
if ($ents) {
- delete_records_select("glossary_comments", "entryid in ($ents)");
- delete_records_select("glossary_alias", "entryid in ($ents)");
- delete_records_select("glossary_ratings", "entryid in ($ents)");
+ $DB->delete_records_select("glossary_comments", "entryid in ($ents)");
+ $DB->delete_records_select("glossary_alias", "entryid in ($ents)");
+ $DB->delete_records_select("glossary_ratings", "entryid in ($ents)");
}
}
glossary_delete_attachments($glossary);
- delete_records("glossary_entries", "glossaryid", "$glossary->id");
+ $DB->delete_records("glossary_entries", array("glossaryid"=>$glossary->id));
}
glossary_grade_item_delete($glossary);
class mod_glossary_mod_form extends moodleform_mod {
function definition() {
+ global $CFG, $COURSE, $DB;
- global $CFG, $COURSE;
$mform =& $this->_form;
//-------------------------------------------------------------------------------
// $hotpot->mode : 'add' or 'update'
// $hotpot->sesskey : unique string required for Moodle's session management
-function hotpot_add_instance(&$hotpot) {
+function hotpot_add_instance($hotpot) {
+ global $DB;
+
if (hotpot_set_form_values($hotpot)) {
- if ($result = insert_record('hotpot', $hotpot)) {
+ if ($result = $DB->insert_record('hotpot', $hotpot)) {
$hotpot->id = $result;
hotpot_update_events($hotpot);
- hotpot_grade_item_update(stripslashes_recursive($hotpot));
+ hotpot_grade_item_update($hotpot);
}
} else {
$result= false;
return $result;
}
-function hotpot_update_instance(&$hotpot) {
+function hotpot_update_instance($hotpot) {
+ global $DB;
+
if (hotpot_set_form_values($hotpot)) {
$hotpot->id = $hotpot->instance;
- if ($result = update_record('hotpot', $hotpot)) {
+ if ($result = $DB->update_record('hotpot', $hotpot)) {
hotpot_update_events($hotpot);
- hotpot_grade_item_update(stripslashes_recursive($hotpot));
+ hotpot_grade_item_update($hotpot);
}
} else {
$result= false;
return $result;
}
function hotpot_update_events($hotpot) {
+ global $DB;
// remove any previous calendar events for this hotpot
- delete_records('event', 'modulename', 'hotpot', 'instance', $hotpot->id);
+ $DB->delete_records('event', array('modulename'=>'hotpot', 'instance'=>$hotpot->id));
$event = new stdClass();
$event->description = $hotpot->summary;
add_event($event);
}
} elseif ($hotpot->timeopen) { // only an open date
- $event->name = addslashes($hotpot->name).' ('.get_string('hotpotopens', 'hotpot').')';
+ $event->name = $hotpot->name.' ('.get_string('hotpotopens', 'hotpot').')';
$event->eventtype = 'open';
$event->timeduration = 0;
add_event($event);
} elseif ($hotpot->timeclose) { // only a closing date
- $event->name = addslashes($hotpot->name).' ('.get_string('hotpotcloses', 'hotpot').')';
+ $event->name = $hotpot->name.' ('.get_string('hotpotcloses', 'hotpot').')';
$event->timestart = $hotpot->timeclose;
$event->eventtype = 'close';
$event->timeduration = 0;
return $ok;
}
function hotpot_delete_instance($id) {
+ global $DB;
/// Given an ID of an instance of this module,
/// this function will permanently delete the instance
/// and any data that depends on it.
- if (! $hotpot = get_record("hotpot", "id", $id)) {
+ if (! $hotpot = $DB->get_record("hotpot", array("id"=>$id))) {
return false;
}
- if (! delete_records("hotpot", "id", "$id")) {
+ if (! $DB->delete_records("hotpot", array("id"=>$id))) {
return false;
}
- delete_records("hotpot_questions", "hotpot", "$id");
- if ($attempts = get_records_select("hotpot_attempts", "hotpot='$id'")) {
+ $DB->delete_records("hotpot_questions", array("hotpot"=>$id));
+ if ($attempts = $DB->get_records("hotpot_attempts", array("hotpot"=>$id))) {
$ids = implode(',', array_keys($attempts));
- delete_records_select("hotpot_attempts", "id IN ($ids)");
- delete_records_select("hotpot_details", "attempt IN ($ids)");
- delete_records_select("hotpot_responses", "attempt IN ($ids)");
+ $DB->delete_records_select("hotpot_attempts", "id IN ($ids)");
+ $DB->delete_records_select("hotpot_details", "attempt IN ($ids)");
+ $DB->delete_records_select("hotpot_responses", "attempt IN ($ids)");
}
// remove calendar events for this hotpot
- delete_records('event', 'modulename', 'hotpot', 'instance', $id);
+ $DB->delete_records('event', array('modulename'=>'hotpot', 'instance'=>$id));
// remove grade item for this hotpot
hotpot_grade_item_delete($hotpot);
define("LABEL_MAX_NAME_LENGTH", 50);
function label_add_instance($label) {
+ global $DB;
/// Given an object containing all the necessary data,
/// (defined by the form in mod_form.php) this function
/// will create a new instance and return the id number
/// of the new instance.
$textlib = textlib_get_instance();
- $label->name = addslashes(strip_tags(format_string(stripslashes($label->content),true)));
+ $label->name = strip_tags(format_string($label->content));
if ($textlib->strlen($label->name) > LABEL_MAX_NAME_LENGTH) {
$label->name = $textlib->substr($label->name, 0, LABEL_MAX_NAME_LENGTH)."...";
}
$label->timemodified = time();
- return insert_record("label", $label);
+ return $DB->insert_record("label", $label);
}
function label_update_instance($label) {
+ global $DB;
/// Given an object containing all the necessary data,
/// (defined by the form in mod_form.php) this function
/// will update an existing instance with new data.
$textlib = textlib_get_instance();
- $label->name = addslashes(strip_tags(format_string(stripslashes($label->content),true)));
+ $label->name = strip_tags(format_string($label->content));
if ($textlib->strlen($label->name) > LABEL_MAX_NAME_LENGTH) {
$label->name = $textlib->substr($label->name, 0, LABEL_MAX_NAME_LENGTH)."...";
}
$label->timemodified = time();
$label->id = $label->instance;
- return update_record("label", $label);
+ return $DB->update_record("label", $label);
}
function label_delete_instance($id) {
+ global $DB;
/// Given an ID of an instance of this module,
/// this function will permanently delete the instance
/// and any data that depends on it.
- if (! $label = get_record("label", "id", "$id")) {
+ if (! $label = $DB->get_record("label", array("id"=>$id))) {
return false;
}
$result = true;
- if (! delete_records("label", "id", "$label->id")) {
+ if (! $DB->delete_records("label", array("id"=>$label->id))) {
$result = false;
}
* @return int
**/
function lesson_add_instance($lesson) {
- global $SESSION;
+ global $SESSION, $DB;
lesson_process_pre_save($lesson);
- if (!$lesson->id = insert_record("lesson", $lesson)) {
+ if (!$lesson->id = $DB->insert_record("lesson", $lesson)) {
return false; // bad
}
lesson_process_post_save($lesson);
- lesson_grade_item_update(stripslashes_recursive($lesson));
+ lesson_grade_item_update($lesson);
return $lesson->id;
}
* @return boolean
**/
function lesson_update_instance($lesson) {
+ global $DB;
$lesson->id = $lesson->instance;
lesson_process_pre_save($lesson);
- if (!$result = update_record("lesson", $lesson)) {
+ if (!$result = $DB->update_record("lesson", $lesson)) {
return false; // Awe man!
}
lesson_process_post_save($lesson);
// update grade item definition
- lesson_grade_item_update(stripslashes_recursive($lesson));
+ lesson_grade_item_update($lesson);
// update grades - TODO: do it only when grading style changes
- lesson_update_grades(stripslashes_recursive($lesson), 0, false);
+ lesson_update_grades($lesson, 0, false);
return $result;
}
/*******************************************************************/
function lesson_delete_instance($id) {
+ global $DB;
/// Given an ID of an instance of this module,
/// this function will permanently delete the instance
/// and any data that depends on it.
- if (! $lesson = get_record("lesson", "id", "$id")) {
+ if (! $lesson = $DB->get_record("lesson", array("id"=>$id))) {
return false;
}
$result = true;
- if (! delete_records("lesson", "id", "$lesson->id")) {
+ if (! $DB->delete_records("lesson", array("id"=>$lesson->id))) {
$result = false;
}
- if (! delete_records("lesson_pages", "lessonid", "$lesson->id")) {
+ if (! $DB->delete_records("lesson_pages", array("lessonid"=>$lesson->id))) {
$result = false;
}
- if (! delete_records("lesson_answers", "lessonid", "$lesson->id")) {
+ if (! $DB->delete_records("lesson_answers", array("lessonid"=>$lesson->id))) {
$result = false;
}
- if (! delete_records("lesson_attempts", "lessonid", "$lesson->id")) {
+ if (! $DB->delete_records("lesson_attempts", array("lessonid"=>$lesson->id))) {
$result = false;
}
- if (! delete_records("lesson_grades", "lessonid", "$lesson->id")) {
+ if (! $DB->delete_records("lesson_grades", array("lessonid"=>$lesson->id))) {
$result = false;
}
- if (! delete_records("lesson_timer", "lessonid", "$lesson->id")) {
+ if (! $DB->delete_records("lesson_timer", array("lessonid"=>$lesson->id))) {
$result = false;
}
- if (! delete_records("lesson_branch", "lessonid", "$lesson->id")) {
+ if (! $DB->delete_records("lesson_branch", array("lessonid"=>$lesson->id))) {
$result = false;
}
- if (! delete_records("lesson_high_scores", "lessonid", "$lesson->id")) {
+ if (! $DB->delete_records("lesson_high_scores", array("lessonid"=>$lesson->id))) {
$result = false;
}
- if ($events = get_records_select('event', "modulename = 'lesson' and instance = '$lesson->id'")) {
+ if ($events = $DB->get_records('event', array("modulename"=>'lesson', "instance"=>$lesson->id))) {
foreach($events as $event) {
delete_event($event->id);
}
}
$pagetypes = page_import_types('mod/lesson/');
foreach ($pagetypes as $pagetype) {
- if (!delete_records('block_instance', 'pageid', $lesson->id, 'pagetype', $pagetype)) {
+ if (!$DB->delete_records('block_instance', array('pageid'=>$lesson->id, 'pagetype'=>$pagetype))) {
$result = false;
}
}
* @return void
**/
function lesson_process_post_save(&$lesson) {
- if ($events = get_records_select('event', "modulename = 'lesson' and instance = '$lesson->id'")) {
+ global $DB;
+
+ if ($events = $DB->get_records('event', array('modulename'=>'lesson', 'instance'=>$lesson->id))) {
foreach($events as $event) {
delete_event($event->id);
}
class mod_lesson_mod_form extends moodleform_mod {
function definition() {
- global $LESSON_NEXTPAGE_ACTION, $COURSE;
+ global $LESSON_NEXTPAGE_ACTION, $COURSE, $DB;
$mform =& $this->_form;
* false or a string error message on failure.
*/
function quiz_add_instance($quiz) {
+ global $DB;
// Process the options from the form.
$quiz->created = time();
}
// Try to store it in the database.
- if (!$quiz->id = insert_record("quiz", $quiz)) {
+ if (!$quiz->id = $DB->insert_record("quiz", $quiz)) {
return false;
}
* @return mixed true on success, false or a string error message on failure.
*/
function quiz_update_instance($quiz) {
+ global $DB;
// Process the options from the form.
$result = quiz_process_options($quiz);
// Update the database.
$quiz->id = $quiz->instance;
- if (!update_record("quiz", $quiz)) {
+ if (!$DB->update_record("quiz", $quiz)) {
return false; // some error occurred
}
quiz_after_add_or_update($quiz);
// Delete any previous preview attempts
- delete_records('quiz_attempts', 'preview', '1', 'quiz', $quiz->id);
+ $DB->delete_records('quiz_attempts', 'preview', '1', array('quiz'=>$quiz->id));
return true;
}
function quiz_delete_instance($id) {
+ global $DB;
/// Given an ID of an instance of this module,
/// this function will permanently delete the instance
/// and any data that depends on it.
- if (! $quiz = get_record("quiz", "id", "$id")) {
+ if (! $quiz = $DB->get_record("quiz", array("id"=>$id))) {
return false;
}
$result = true;
- if ($attempts = get_records("quiz_attempts", "quiz", "$quiz->id")) {
+ if ($attempts = $DB->get_records("quiz_attempts", array("quiz"=>$quiz->id))) {
foreach ($attempts as $attempt) {
// TODO: this should use the delete_attempt($attempt->uniqueid) function in questionlib.php
- if (! delete_records("question_states", "attempt", "$attempt->uniqueid")) {
+ if (! $DB->delete_records("question_states", array("attempt"=>$attempt->uniqueid))) {
$result = false;
}
- if (! delete_records("question_sessions", "attemptid", "$attempt->uniqueid")) {
+ if (! $DB->delete_records("question_sessions", array("attemptid"=>$attempt->uniqueid))) {
$result = false;
}
}
'quiz' => 'id'
);
foreach ($tables_to_purge as $table => $keyfield) {
- if (!delete_records($table, $keyfield, $quiz->id)) {
+ if (!$DB->delete_records($table, array($keyfield=>$quiz->id))) {
$result = false;
}
}
$pagetypes = page_import_types('mod/quiz/');
foreach($pagetypes as $pagetype) {
- if(!delete_records('block_instance', 'pageid', $quiz->id, 'pagetype', $pagetype)) {
+ if (!$DB->delete_records('block_instance', array('pageid'=>$quiz->id, 'pagetype'=>$pagetype))) {
$result = false;
}
}
- if ($events = get_records_select('event', "modulename = 'quiz' and instance = '$quiz->id'")) {
+ if ($events = $DB->get_records('event', array("modulename"=>'quiz', "instance"=>$quiz->id))) {
foreach($events as $event) {
delete_event($event->id);
}
* @param object $quiz the quiz object.
*/
function quiz_after_add_or_update($quiz) {
+ global $DB;
// Save the feedback
- delete_records('quiz_feedback', 'quizid', $quiz->id);
+ $DB->delete_records('quiz_feedback', array('quizid'=>$quiz->id));
for ($i = 0; $i <= $quiz->feedbackboundarycount; $i += 1) {
$feedback = new stdClass;
$feedback->feedbacktext = $quiz->feedbacktext[$i];
$feedback->mingrade = $quiz->feedbackboundaries[$i];
$feedback->maxgrade = $quiz->feedbackboundaries[$i - 1];
- if (!insert_record('quiz_feedback', $feedback, false)) {
+ if (!$DB->insert_record('quiz_feedback', $feedback, false)) {
return "Could not save quiz feedback.";
}
}
// Update the events relating to this quiz.
// This is slightly inefficient, deleting the old events and creating new ones. However,
// there are at most two events, and this keeps the code simpler.
- if ($events = get_records_select('event', "modulename = 'quiz' and instance = '$quiz->id'")) {
+ if ($events = $DB->get_records('event', array('modulename'=>'quiz', 'instance'=>$quiz->id))) {
foreach($events as $event) {
delete_event($event->id);
}
}
//update related grade item
- quiz_grade_item_update(stripslashes_recursive($quiz));
+ quiz_grade_item_update($quiz);
}
function quiz_get_view_actions() {
function definition() {
- global $COURSE, $CFG;
+ global $COURSE, $CFG, $DB;
$mform =& $this->_form;
//-------------------------------------------------------------------------------
$repeatarray[] = &MoodleQuickForm::createElement('text', 'feedbackboundaries', get_string('gradeboundary', 'quiz'), array('size' => 10));
if (!empty($this->_instance)) {
- $this->_feedbacks = get_records('quiz_feedback', 'quizid', $this->_instance, 'mingrade DESC');
+ $this->_feedbacks = $DB->get_records('quiz_feedback', array('quizid'=>$this->_instance), 'mingrade DESC');
} else {
$this->_feedbacks = array();
}
function add_instance($resource) {
+ global $DB;
// Given an object containing all the necessary data,
// (defined by the form in mod_form.php) this function
// will create a new instance and return the id number
$resource->timemodified = time();
- return insert_record("resource", $resource);
+ return $DB->insert_record("resource", $resource);
}
function update_instance($resource) {
+ global $DB;
// Given an object containing all the necessary data,
// (defined by the form in mod_form.php) this function
// will update an existing instance with new data.
$resource->id = $resource->instance;
$resource->timemodified = time();
- return update_record("resource", $resource);
+ return $DB->update_record("resource", $resource);
}
function delete_instance($resource) {
+ global $DB;
// Given an object containing the resource data
// this function will permanently delete the instance
// and any data that depends on it.
$result = true;
- if (! delete_records("resource", "id", "$resource->id")) {
+ if (! $DB->delete_records("resource", array("id"=>$resource->id))) {
$result = false;
}
}
function resource_delete_instance($id) {
- global $CFG;
+ global $CFG, $DB;
- if (! $resource = get_record("resource", "id", "$id")) {
+ if (! $resource = $DB->get_record("resource", array("id"=>$id))) {
return false;
}
var $_resinstance;
function definition() {
- global $CFG;
+ global $CFG, $DB;
$mform =& $this->_form;
// this hack is needed for different settings of each subtype
if (!empty($this->_instance)) {
- if($res = get_record('resource', 'id', (int)$this->_instance)) {
+ if($res = $DB->get_record('resource', array('id', $this->_instance))) {
$type = $res->type;
} else {
print_error('incorrect assignment');
*/
//require_once('locallib.php');
function scorm_add_instance($scorm) {
- global $CFG;
+ global $CFG, $DB;
require_once('locallib.php');
}
$scorm->grademethod = ($scorm->whatgrade * 10) + $scorm->grademethod;
- $id = insert_record('scorm', $scorm);
+ $id = $DB->insert_record('scorm', $scorm);
if (scorm_external_link($scorm->reference) || ((basename($scorm->reference) != 'imsmanifest.xml') && ($scorm->reference[0] != '#'))) {
// Rename temp scorm dir to scorm id
if ($scorm->parse == 1) {
$scorm->id = $id;
$scorm->launch = scorm_parse($scorm);
- set_field('scorm','launch',$scorm->launch,'id',$scorm->id);
+ $DB->set_field('scorm', 'launch', $scorm->launch, array('id'=>$scorm->id));
}
- scorm_grade_item_update(stripslashes_recursive($scorm));
+ scorm_grade_item_update($scorm);
return $id;
} else {
* @return int
*/
function scorm_update_instance($scorm) {
- global $CFG;
+ global $CFG, $DB;
require_once('locallib.php');
$scorm->launch = scorm_parse($scorm);
} else {
- $oldscorm = get_record('scorm','id',$scorm->id);
+ $oldscorm = $DB->get_record('scorm', array('id'=>$scorm->id));
$scorm->reference = $oldscorm->reference; // This fix a problem with Firefox when the teacher choose Cancel on overwrite question
}
- if ($result = update_record('scorm', $scorm)) {
- scorm_grade_item_update(stripslashes_recursive($scorm));
+ if ($result = $DB->update_record('scorm', $scorm)) {
+ scorm_grade_item_update($scorm);
}
return $result;
* @return boolean
*/
function scorm_delete_instance($id) {
+ global $CFG, $DB;
- global $CFG;
-
- if (! $scorm = get_record('scorm', 'id', $id)) {
+ if (! $scorm = $DB->get_record('scorm', array('id'=>$id))) {
return false;
}
}
// Delete any dependent records
- if (! delete_records('scorm_scoes_track', 'scormid', $scorm->id)) {
+ if (! $DB->delete_records('scorm_scoes_track', array('scormid'=>$scorm->id))) {
$result = false;
}
- if ($scoes = get_records('scorm_scoes','scorm',$scorm->id)) {
+ if ($scoes = $DB->get_records('scorm_scoes', array('scorm'=>$scorm->id))) {
foreach ($scoes as $sco) {
- if (! delete_records('scorm_scoes_data', 'scoid', $sco->id)) {
+ if (! $DB->delete_records('scorm_scoes_data', array('scoid'=>$sco->id))) {
$result = false;
}
}
- delete_records('scorm_scoes', 'scorm', $scorm->id);
+ $DB->delete_records('scorm_scoes', array('scorm'=>$scorm->id));
} else {
$result = false;
}
- if (! delete_records('scorm', 'id', $scorm->id)) {
+ if (! $DB->delete_records('scorm', array('id'=>$scorm->id))) {
$result = false;
}
- /*if (! delete_records('scorm_sequencing_controlmode', 'scormid', $scorm->id)) {
+ /*if (! $DB->delete_records('scorm_sequencing_controlmode', array('scormid'=>$scorm->id))) {
$result = false;
}
- if (! delete_records('scorm_sequencing_rolluprules', 'scormid', $scorm->id)) {
+ if (! $DB->delete_records('scorm_sequencing_rolluprules', array('scormid'=>$scorm->id))) {
$result = false;
}
- if (! delete_records('scorm_sequencing_rolluprule', 'scormid', $scorm->id)) {
+ if (! $DB->delete_records('scorm_sequencing_rolluprule', array('scormid'=>$scorm->id))) {
$result = false;
}
- if (! delete_records('scorm_sequencing_rollupruleconditions', 'scormid', $scorm->id)) {
+ if (! $DB->delete_records('scorm_sequencing_rollupruleconditions', array('scormid'=>$scorm->id))) {
$result = false;
}
- if (! delete_records('scorm_sequencing_rolluprulecondition', 'scormid', $scorm->id)) {
+ if (! $DB->delete_records('scorm_sequencing_rolluprulecondition', array('scormid'=>$scorm->id))) {
$result = false;
}
- if (! delete_records('scorm_sequencing_rulecondition', 'scormid', $scorm->id)) {
+ if (! $DB->delete_records('scorm_sequencing_rulecondition', array('scormid'=>$scorm->id))) {
$result = false;
}
- if (! delete_records('scorm_sequencing_ruleconditions', 'scormid', $scorm->id)) {
+ if (! $DB->delete_records('scorm_sequencing_ruleconditions', array('scormid'=>$scorm->id))) {
$result = false;
}*/
- scorm_grade_item_delete(stripslashes_recursive($scorm));
+ scorm_grade_item_delete($scorm);
return $result;
}
// STANDARD FUNCTIONS ////////////////////////////////////////////////////////
function survey_add_instance($survey) {
+ global $DB;
// Given an object containing all the necessary data,
// (defined by the form in mod_form.php) this function
// will create a new instance and return the id number
// of the new instance.
- if (!$template = get_record("survey", "id", $survey->template)) {
+ if (!$template = $DB->get_record("survey", array("id"=>$survey->template))) {
return 0;
}
$survey->timecreated = time();
$survey->timemodified = $survey->timecreated;
- return insert_record("survey", $survey);
+ return $DB->insert_record("survey", $survey);
}
function survey_update_instance($survey) {
+ global $DB;
// Given an object containing all the necessary data,
// (defined by the form in mod_form.php) this function
// will update an existing instance with new data.
- if (!$template = get_record("survey", "id", $survey->template)) {
+ if (!$template = $DB->get_record("survey", array("id"=>$survey->template))) {
return 0;
}
$survey->questions = $template->questions;
$survey->timemodified = time();
- return update_record("survey", $survey);
+ return $DB->update_record("survey", $survey);
}
function survey_delete_instance($id) {
+ global $DB;
// Given an ID of an instance of this module,
// this function will permanently delete the instance
// and any data that depends on it.
- if (! $survey = get_record("survey", "id", "$id")) {
+ if (! $survey = $DB->get_record("survey", array("id"=>$id))) {
return false;
}
$result = true;
- if (! delete_records("survey_analysis", "survey", "$survey->id")) {
+ if (! $DB->delete_records("survey_analysis", array("survey"=>$survey->id))) {
$result = false;
}
- if (! delete_records("survey_answers", "survey", "$survey->id")) {
+ if (! $DB->delete_records("survey_answers", array("survey"=>$survey->id))) {
$result = false;
}
- if (! delete_records("survey", "id", "$survey->id")) {
+ if (! $DB->delete_records("survey", array("id"=>$survey->id))) {
$result = false;
}
function wiki_add_instance($wiki) {
+ global $DB;
/// Given an object containing all the necessary data,
/// (defined by the form in mod_form.php) this function
/// will create a new instance and return the id number
/// Determine the pagename for this wiki and save.
$wiki->pagename = wiki_page_name($wiki);
- return insert_record("wiki", $wiki);
+ return $DB->insert_record("wiki", $wiki);
}
function wiki_update_instance($wiki) {
+ global $DB;
/// Given an object containing all the necessary data,
/// (defined by the form in mod_form.php) this function
/// will update an existing instance with new data.
$wiki->timemodified = time();
$wiki->id = $wiki->instance;
- return update_record("wiki", $wiki);
+ return $DB->update_record("wiki", $wiki);
}
/// Delete all Directories recursively
/// Given an ID of an instance of this module,
/// this function will permanently delete the instance
/// and any data that depends on it.
- global $CFG;
+ global $CFG, $DB;
- if (! $wiki = get_record("wiki", "id", $id)) {
+ if (! $wiki = $DB->get_record("wiki", array("id"=>$id))) {
return false;
}
}
# Delete any dependent records here #
- if(!delete_records("wiki_locks","wikiid",$wiki->id)) {
+ if(!$DB->delete_records("wiki_locks", array("wikiid"=>$wiki->id))) {
$result = false;
}
- if (! delete_records("wiki", "id", $wiki->id)) {
+ if (! $DB->delete_records("wiki", array("id"=>$wiki->id))) {
$result = false;
}
/// Delete all wiki_entries and wiki_pages.
if (($wiki_entries = wiki_get_entries($wiki)) !== false) {
foreach ($wiki_entries as $wiki_entry) {
- if (! delete_records("wiki_pages", "wiki", "$wiki_entry->id")) {
+ if (! $DB->delete_records("wiki_pages", array("wiki"=>$wiki_entry->id))) {
$result = false;
}
- if (! delete_records("wiki_entries", "id", "$wiki_entry->id")) {
+ if (! $DB->delete_records("wiki_entries", array("id"=>$wiki_entry->id))) {
$result = false;
}
}