get_records_select('post', $select, $params, $order, $fields, $limitfrom, $limitnum); } /** * Retrieves a note object based on its id. * * @param int $note_id id of the note to retrieve * @return note object */ function note_load($note_id) { global $DB; $fields = 'id,courseid,userid,content,format,created,lastmodified,usermodified,publishstate'; return $DB->get_record('post', array('id'=>$note_id, 'module'=>'notes'), $fields); } /** * Saves a note object. The note object is passed by reference and its fields (i.e. id) * might change during the save. * * @param note $note object to save * @return boolean true if the object was saved; false otherwise */ function note_save(&$note) { global $USER, $DB; // setup & clean fields $note->module = 'notes'; $note->lastmodified = time(); $note->usermodified = $USER->id; if (empty($note->format)) { $note->format = FORMAT_PLAIN; } if (empty($note->publishstate)) { $note->publishstate = NOTES_STATE_PUBLIC; } // save data if (empty($note->id)) { // insert new note $note->created = $note->lastmodified; $id = $DB->insert_record('post', $note); $note = $DB->get_record('post', array('id'=>$id)); } else { // update old note $DB->update_record('post', $note); } unset($note->module); return true; } /** * Deletes a note object based on its id. * * @param int $note_id id of the note to delete * @return boolean true if the object was deleted; false otherwise */ function note_delete($noteid) { global $DB; return $DB->delete_records('post', array('id'=>$noteid, 'module'=>'notes')); } /** * Converts a state value to its corespondent name * * @param string $state state value to convert * @return string corespondent state name */ function note_get_state_name($state) { // cache state names static $states; if (empty($states)) { $states = note_get_state_names(); } if (isset($states[$state])) { return $states[$state]; } else { return null; } } /** * Returns an array of mappings from state values to state names * * @return array of mappings */ function note_get_state_names() { return array( NOTES_STATE_DRAFT => get_string('personal', 'notes'), NOTES_STATE_PUBLIC => get_string('course', 'notes'), NOTES_STATE_SITE => get_string('site', 'notes'), ); } /** * Prints a note object * * @param note $note the note object to print * @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, $OUTPUT; if (!$user = $DB->get_record('user', array('id'=>$note->userid))) { debugging("User $note->userid not found"); return; } 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); $systemcontext = get_context_instance(CONTEXT_SYSTEM); $authoring = new stdClass(); $authoring->name = ''.fullname($author).''; $authoring->date = userdate($note->lastmodified); echo '
' . get_string('addnewnote', 'notes') . '
'; } else { echo '' . get_string('addnewnoteselect', 'notes') . '
'; } } if ($viewnotes) { $notes = note_list($courseid, $userid, $state, $author); if ($notes) { note_print_list($notes); } } else { echo '' . get_string('notesnotvisible', 'notes') . '
'; } if ($header) { echo '