MDL-10181, user management improvements fixes

This commit is contained in:
toyomoyo 2007-07-13 08:26:47 +00:00
parent 0a5a42ed76
commit c55dee3fa9
12 changed files with 127 additions and 109 deletions

View file

@ -4,15 +4,6 @@
* Library of functions and constants for notes
*/
/**
* Constants for ratings.
*/
define('NOTES_RATING_LOW', '1');
define('NOTES_RATING_BELOWNORMAL', '2');
define('NOTES_RATING_NORMAL', '3');
define('NOTES_RATING_ABOVENORMAL', '4');
define('NOTES_RATING_HIGH', '5');
/**
* Constants for states.
*/
@ -57,7 +48,7 @@ function note_list($courseid=0, $userid=0, $state = '', $author = 0, $order='las
}
$selects[] = 'module="notes"';
$select = implode(' AND ', $selects);
$fields = 'id,courseid,userid,content,format,rating,created,lastmodified,usermodified,publishstate';
$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);
@ -70,7 +61,7 @@ function note_list($courseid=0, $userid=0, $state = '', $author = 0, $order='las
* @return note object
*/
function note_load($note_id) {
$fields = 'id,courseid,userid,content,format,rating,created,lastmodified,usermodified,publishstate';
$fields = 'id,courseid,userid,content,format,created,lastmodified,usermodified,publishstate';
return get_record_select('post', 'id=' . $note_id . ' AND module="notes"', $fields);
}
@ -87,9 +78,6 @@ function note_save(&$note) {
$note->module = 'notes';
$note->lastmodified = time();
$note->usermodified = $USER->id;
if(empty($note->rating)) {
$note->rating = NOTES_RATING_NORMAL;
}
if(empty($note->format)) {
$note->format = FORMAT_PLAIN;
}
@ -124,36 +112,6 @@ function note_delete($noteid) {
return delete_records_select('post', 'id=' . $noteid . ' AND module="notes"');
}
/**
* Converts a rating value to its corespondent name
*
* @param int $rating rating value to convert
* @return string corespondent rating name
*/
function note_get_rating_name($rating) {
// cache rating names
static $ratings;
if (empty($ratings)) {
$ratings =& note_get_rating_names();
}
return @$ratings[$rating];
}
/**
* Returns an array of mappings from rating values to rating names
*
* @return array of mappings
*/
function note_get_rating_names() {
return array(
1 => get_string('low', 'notes'),
2 => get_string('belownormal', 'notes'),
3 => get_string('normal', 'notes'),
4 => get_string('abovenormal', 'notes'),
5 => get_string('high', 'notes'),
);
}
/**
* Converts a state value to its corespondent name
*
@ -200,13 +158,12 @@ function note_print($note, $detail = NOTES_SHOW_FULL) {
($note->usermodified == $USER->id ? ' ownnotepost' : '') .
'" id="note-'. $note->id .'">';
// print note head (e.g. author, user refering to, rating, etc)
// print note head (e.g. author, user refering to, etc)
if($detail & NOTES_SHOW_HEAD) {
echo '<div class="header">';
echo '<div class="user">';
print_user_picture($user->id, $note->courseid, $user->picture);
echo fullname($user) . '</div>';
echo '<div class="rating rating' . $note->rating . '">' . get_string('rating', 'notes') . ': ' . note_get_rating_name($note->rating) . '</div>';
echo '<div class="info">' .
get_string('bynameondate', 'notes', $authoring) .
' (' . get_string('created', 'notes') . ': ' . userdate($note->created) . ')</div>';
@ -224,10 +181,10 @@ function note_print($note, $detail = NOTES_SHOW_FULL) {
if($detail & NOTES_SHOW_FOOT) {
if (has_capability('moodle/notes:manage', $sitecontext) && $note->publishstate == NOTES_STATE_SITE ||
has_capability('moodle/notes:manage', $context) && ($note->publishstate == NOTES_STATE_PUBLIC || $note->usermodified == $USER->id)) {
echo '<div class="footer">';
echo '<a href="'.$CFG->wwwroot.'/notes/edit.php?note='.$note->id. '">'. get_string('edit') .'</a>';
echo '<div class="footer"><p>';
echo '<a href="'.$CFG->wwwroot.'/notes/edit.php?note='.$note->id. '">'. get_string('edit') .'</a> | ';
echo '<a href="'.$CFG->wwwroot.'/notes/delete.php?note='.$note->id. '">'. get_string('delete') .'</a>';
echo '</div>';
echo '</p></div>';
}
}
echo '</div>';
@ -253,19 +210,23 @@ function note_print_list($notes, $detail = NOTES_SHOW_FULL) {
* Retrieves and prints a list of note objects with specific atributes.
*
* @param string $header HTML to print above the list
* @param object $context context in which the notes will be displayed (used to check capabilities)
* @param int $addcourseid id of the course for the add notes link (0 hide link)
* @param boolean $viewnotes true if the notes should be printed; false otherwise (print notesnotvisible string)
* @param int $courseid id of the course in which the notes were posted (0 means any)
* @param int $userid id of the user to which the notes refer (0 means any)
* @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, $context, $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 id="notestitle">' . $header . '</h3>';
}
if (has_capability('moodle/notes:view', $context)) {
if ($addcourseid) {
echo '<p><a href="'. $CFG->wwwroot .'/notes/add.php?course=' . $addcourseid . '&amp;user=' . $userid . '&amp;state=' . $state . '">' . get_string('addnewnote', 'notes') . '</a></p>';
}
if ($viewnotes) {
$notes =& note_list($courseid, $userid, $state, $author);
if($notes) {
note_print_list($notes);
@ -275,4 +236,4 @@ function note_print_notes($header, $context, $courseid = 0, $userid = 0, $state
} else {
echo '<p>' . get_string('notesnotvisible', 'notes') . '</p>';
}
}
}