]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-14679 towards notes conversion and regression
authorskodak <skodak>
Sat, 31 May 2008 17:44:57 +0000 (17:44 +0000)
committerskodak <skodak>
Sat, 31 May 2008 17:44:57 +0000 (17:44 +0000)
lib/pagelib.php
notes/add.php
notes/delete.php
notes/edit.php
notes/index.php
notes/lib.php
rss/file.php

index 089cd7d03530d77aeab0c8fd44e6cb178d606f12..73d0dbe66805986bc1beec88776ea9d58d1bdc29 100644 (file)
@@ -335,7 +335,7 @@ class page_course extends page_base {
         if ($this->id == $COURSE->id) {
             $this->courserecord = $COURSE;
         } else {
-            $this->courserecord = $DB->get_record('course', 'id', $this->id);
+            $this->courserecord = $DB->get_record('course', array('id'=>$this->id));
         }
 
         if(empty($this->courserecord) && !defined('ADMIN_STICKYBLOCKS')) {
index cab3524be3441a4c781810125719ef414e450728..00f4ed77d48cbc5fce7bafadbe65b6fd15487a98 100644 (file)
@@ -8,7 +8,7 @@
     $userid        = required_param('user', PARAM_INT);
 
 /// locate course information
-    if (!($course = get_record('course', 'id', $courseid))) {
+    if (!($course = $DB->get_record('course', array('id'=>$courseid)))) {
         print_error('Incorrect course id found');
     }
 
@@ -23,7 +23,7 @@
 
 
 /// locate user information
-    if (!($user = get_record('user', 'id', $userid))) {
+    if (!($user = $DB->get_record('user', array('id'=>$userid)))) {
         print_error('Incorrect user id found');
     }
 
     }
 
 /// if data was submitted and validated, then save it to database
-    if ($formdata = $noteform->get_data()) {
+    if ($formdata = $noteform->get_data(false)) {
         $note = new object();
-        $note->courseid = $formdata->course;
-        $note->content = $formdata->content;
-        $note->format = FORMAT_PLAIN;
-        $note->userid = $formdata->user;
+        $note->courseid     = $formdata->course;
+        $note->content      = $formdata->content;
+        $note->format       = FORMAT_PLAIN;
+        $note->userid       = $formdata->user;
         $note->publishstate = $formdata->publishstate;
         if (note_save($note)) {
             add_to_log($note->courseid, 'notes', 'add', 'index.php?course='.$note->courseid.'&amp;user='.$note->userid . '#note-' . $note->id , 'add note');
         redirect($CFG->wwwroot . '/notes/index.php?course=' . $note->courseid . '&amp;user=' . $note->userid);
     }
 
-    if($noteform->is_submitted()) {
+    if ($noteform->is_submitted()) {
         // if data was submitted with errors, then use it as default for new form
         $note = $noteform->get_submitted_data(false);
     } else {
         // if data was not submitted yet, then use default values
         $note = new object();
-        $note->id = 0;
-        $note->course = $courseid;
-        $note->user = $userid;
+        $note->id           = 0;
+        $note->course       = $courseid;
+        $note->user         = $userid;
         $note->publishstate = optional_param('state', NOTES_STATE_PUBLIC, PARAM_ALPHA);
     }
     $noteform->set_data($note);
index 4faceeb6235b950f235384bce676005eaf5557c6..242eb90b81de6dfa937d5a5c09c9c58f62bb6422 100644 (file)
@@ -12,12 +12,12 @@ if (!$note = note_load($noteid)) {
 }
 
 // locate course information
-if (!$course = get_record('course', 'id', $note->courseid)) {
+if (!$course = $DB->get_record('course', array('id'=>$note->courseid))) {
     print_error('Incorrect course id found');
 }
 
 // locate user information
-    if (!$user = get_record('user', 'id', $note->userid)) {
+    if (!$user = $DB->get_record('user', array('id'=>$note->userid))) {
         print_error('Incorrect user id found');
     }
 
@@ -32,7 +32,7 @@ if (!has_capability('moodle/notes:manage', $context)) {
     print_error('You may not delete this note');
 }
 
-if (data_submitted() && confirm_sesskey()) {
+if (data_submitted(false) && confirm_sesskey()) {
 //if data was submitted and is valid, then delete note
     $returnurl = $CFG->wwwroot . '/notes/index.php?course=' . $course->id . '&amp;user=' . $note->userid;
     if (note_delete($noteid)) {
index f6ffe05ecae755ef4bcaca3a472a6222906f9f62..65b539c65f7b2dd182d0090f0044e697e6d7be8f 100644 (file)
     }
 
 /// locate course information
-    if (!$course = get_record('course', 'id', $note->courseid)) {
+    if (!$course = $DB->get_record('course', array('id'=>$note->courseid))) {
         print_error('Incorrect course id found');
     }
 
 /// locate user information
-    if (!$user = get_record('user', 'id', $note->userid)) {
+    if (!$user = $DB->get_record('user', array('id'=>$note->userid))) {
         print_error('Incorrect user id found');
     }
 
 
 /// if data was submitted and validated, then save it to database
     if ($formdata = $noteform->get_data()){
-        $note->courseid = $formdata->course;
-        $note->userid = $formdata->user;
-        $note->content = $formdata->content;
-        $note->format = FORMAT_PLAIN;
+        $note->courseid     = $formdata->course;
+        $note->userid       = $formdata->user;
+        $note->content      = $formdata->content;
+        $note->format       = FORMAT_PLAIN;
         $note->publishstate = $formdata->publishstate;
         if (note_save($note)) {
             add_to_log($note->courseid, 'notes', 'update', 'index.php?course='.$note->courseid.'&amp;user='.$note->userid . '#note-' . $note->id, 'update note');
@@ -63,9 +63,9 @@
         $note = $noteform->get_submitted_data(false);
     } else {
         // if data was not submitted yet, then used values retrieved from the database
-        $note->user = $note->userid;
+        $note->user   = $note->userid;
         $note->course = $note->courseid;
-        $note->note = $note->id;
+        $note->note   = $note->id;
     }
     $noteform->set_data($note);
     $strnotes = get_string('editnote', 'notes');
index 8b82b04e203e46ffede53bf92e3845c63f82f712..bc93c4c507fdf147f0f18a918f2c077e7b77258f 100644 (file)
     }
 
 /// locate course information
-    if (!$course = get_record('course', 'id', $courseid)) {
+    if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
         print_error('Incorrect course id specified');
     }
 
 /// locate user information
     if ($userid) {
-        if (!$user = get_record('user', 'id', $userid)) {
+        if (!$user = $DB->get_record('user', array('id'=>$userid))) {
             print_error('Incorrect user id specified');
         }
         $filtertype = 'user';
index e7276c3b076a45e06fb1912b293fe42c51d84b10..94162606a0d01be7f0fe4f9ad24940c2fce192a0 100644 (file)
@@ -32,26 +32,34 @@ define('NOTES_SHOW_FOOT', 0x04);
  * @return array of note objects
  */
 function note_list($courseid=0, $userid=0, $state = '', $author = 0, $order='lastmodified DESC', $limitfrom=0, $limitnum=0) {
+    global $DB;
+
     // setup filters
     $selects = array();
-    if($courseid) {
-        $selects[] = 'courseid=' . $courseid;
+    $params = array();
+    if ($courseid) {
+        $selects[] = 'courseid=?';
+        $params[]  = $courseid;
     }
-    if($userid) {
-        $selects[] = 'userid=' . $userid;
+    if ($userid) {
+        $selects[] = 'userid=?';
+        $params[]  = $userid;
     }
-    if($author) {
-        $selects[] = 'usermodified=' . $author;
+    if ($author) {
+        $selects[] = 'usermodified=?';
+        $params[]  = $author;
     }
-    if($state) {
-        $selects[] = "publishstate='$state'";
+    if ($state) {
+        $selects[] = 'publishstate=?';
+        $params[]  = $state;
     }
-    $selects[] = "module='notes'";
+    $selects[] = "module=?";
+    $params[]  = 'notes';
+
     $select = implode(' AND ', $selects);
     $fields = 'id,courseid,userid,content,format,created,lastmodified,usermodified,publishstate';
     // retrieve data
-    $rs =& get_recordset_select('post', $select, $order, $fields, $limitfrom, $limitnum);
-    return recordset_to_array($rs);
+    return $DB->get_records_select('post', $select, $params, $order, $fields, $limitfrom, $limitnum);
 }
 
 /**
@@ -61,8 +69,10 @@ function note_list($courseid=0, $userid=0, $state = '', $author = 0, $order='las
  * @return note object
  */
 function note_load($note_id) {
+    global $DB;
+
     $fields = 'id,courseid,userid,content,format,created,lastmodified,usermodified,publishstate';
-    return get_record_select('post', "id=$note_id AND module='notes'", $fields);
+    return $DB->get_record('post', array('id'=>$note_id, 'module'=>'notes'), $fields);
 }
 
 /**
@@ -73,9 +83,10 @@ function note_load($note_id) {
  * @return boolean true if the object was saved; false otherwise
  */
 function note_save(&$note) {
-    global $USER;
+    global $USER, $DB;
+
     // setup & clean fields
-    $note->module = 'notes';
+    $note->module       = 'notes';
     $note->lastmodified = time();
     $note->usermodified = $USER->id;
     if(empty($note->format)) {
@@ -88,7 +99,7 @@ function note_save(&$note) {
     if(empty($note->id)) {
         // insert new note
         $note->created = $note->lastmodified;
-        if($id = insert_record('post', $note)) {
+        if ($id = $DB->insert_record('post', $note)) {
             $note->id = $id;
             $result = true;
         } else {
@@ -96,7 +107,7 @@ function note_save(&$note) {
         }
     } else {
         // update old note
-        $result = update_record('post', $note);
+        $result = $DB->update_record('post', $note);
     }
     unset($note->module);
     return $result;
@@ -109,7 +120,9 @@ function note_save(&$note) {
  * @return boolean true if the object was deleted; false otherwise
  */
 function note_delete($noteid) {
-    return delete_records_select('post', "id=$noteid AND module='notes'");
+    global $DB;
+
+    return $DB->delete_records('post', array('id'=>$noteid, 'module'=>'notes'));
 }
 
 /**
@@ -124,7 +137,11 @@ function note_get_state_name($state) {
     if (empty($states)) {
         $states = note_get_state_names();
     }
-    return @$states[$state];
+    if (isset($states[$state])) {
+        return $states[$state];
+    } else {
+        return null;
+    }
 }
 
 /**
@@ -147,20 +164,20 @@ function note_get_state_names() {
  * @param int   $detail OR-ed NOTES_SHOW_xyz flags that specify which note parts to print
  */
 function note_print($note, $detail = NOTES_SHOW_FULL) {
+    global $CFG, $USER, $DB;
 
-    global $CFG, $USER;
-    if (!$user = get_record('user','id',$note->userid)) {
+    if (!$user = $DB->get_record('user', array('id'=>$note->userid))) {
         debugging("User $note->userid not found");
         return;
     }
-    if (!$author = get_record('user','id',$note->usermodified)) {
+    if (!$author = $DB->get_record('user', array('id'=>$note->usermodified))) {
         debugging("User $note->usermodified not found");
         return;
     }
     $context = get_context_instance(CONTEXT_COURSE, $note->courseid);
     $sitecontext = get_context_instance(CONTEXT_SYSTEM);
 
-    $authoring = new object;
+    $authoring = new object();
     $authoring->name = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$author->id.'&amp;course='.$note->courseid.'">'.fullname($author).'</a>';
     $authoring->date = userdate($note->lastmodified);
 
@@ -227,9 +244,9 @@ function note_print_list($notes, $detail = NOTES_SHOW_FULL) {
  * @param string  $state state of the notes (i.e. draft, public, site) ('' means any)
  * @param int     $author id of the user who modified the note last time (0 means any)
  */
-function note_print_notes($header, $addcourseid = 0, $viewnotes = true, $courseid = 0, $userid = 0, $state = '', $author = 0)
-{
+function note_print_notes($header, $addcourseid = 0, $viewnotes = true, $courseid = 0, $userid = 0, $state = '', $author = 0) {
     global $CFG;
+
     if ($header) {
         echo '<h3 class="notestitle">' . $header . '</h3>';
         echo '<div class="notesgroup">';
@@ -242,7 +259,7 @@ function note_print_notes($header, $addcourseid = 0, $viewnotes = true, $coursei
         }
     }
     if ($viewnotes) {
-        $notes =& note_list($courseid, $userid, $state, $author);
+        $notes = note_list($courseid, $userid, $state, $author);
         if ($notes) {
             note_print_list($notes);
         }
@@ -260,6 +277,8 @@ function note_print_notes($header, $addcourseid = 0, $viewnotes = true, $coursei
  * @return bool success
  */
 function note_delete_all($courseid) {
-    return delete_records('post', 'module', 'notes', 'courseid', $courseid);
+    global $DB;
+
+    return $DB->delete_records('post', array('module'=>'notes', 'courseid'=>$courseid));
 }
 ?>
index a110e87bf2dbabb26eddca9c0ca71d1b083efb76..4f349416dcbd474d4b493a0e055ce18b07f0b2c3 100644 (file)
@@ -61,7 +61,7 @@
     }
 
 
-    if (!$course = get_record('course', 'id', $courseid)) {
+    if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
         rss_not_found();
     }