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')) {
$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');
}
/// 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.'&user='.$note->userid . '#note-' . $note->id , 'add note');
redirect($CFG->wwwroot . '/notes/index.php?course=' . $note->courseid . '&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);
}
// 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');
}
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 . '&user=' . $note->userid;
if (note_delete($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');
}
/// 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.'&user='.$note->userid . '#note-' . $note->id, 'update note');
$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');
}
/// 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';
* @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);
}
/**
* @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);
}
/**
* @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)) {
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 {
}
} else {
// update old note
- $result = update_record('post', $note);
+ $result = $DB->update_record('post', $note);
}
unset($note->module);
return $result;
* @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'));
}
/**
if (empty($states)) {
$states = note_get_state_names();
}
- return @$states[$state];
+ if (isset($states[$state])) {
+ return $states[$state];
+ } else {
+ return null;
+ }
}
/**
* @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.'&course='.$note->courseid.'">'.fullname($author).'</a>';
$authoring->date = userdate($note->lastmodified);
* @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">';
}
}
if ($viewnotes) {
- $notes =& note_list($courseid, $userid, $state, $author);
+ $notes = note_list($courseid, $userid, $state, $author);
if ($notes) {
note_print_list($notes);
}
* @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));
}
?>
}
- if (!$course = get_record('course', 'id', $courseid)) {
+ if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
rss_not_found();
}