mirror of
https://github.com/moodle/moodle.git
synced 2025-08-03 16:13:28 +02:00
MDL-10181, user management improvements fixes
This commit is contained in:
parent
0a5a42ed76
commit
c55dee3fa9
12 changed files with 127 additions and 109 deletions
|
@ -11,6 +11,8 @@ $userid = optional_param('user', 0, PARAM_INT);
|
|||
if (!($course = get_record('course', 'id', $courseid))) {
|
||||
error('Incorrect course id found');
|
||||
}
|
||||
// require login to access notes
|
||||
require_login($course->id);
|
||||
|
||||
// locate context information
|
||||
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
|
@ -46,7 +48,6 @@ if ($formdata = $noteform->get_data()) {
|
|||
$note->courseid = $formdata->course;
|
||||
$note->content = $formdata->content;
|
||||
$note->format = FORMAT_PLAIN;
|
||||
$note->rating = $formdata->rating;
|
||||
$note->userid = $formdata->user;
|
||||
$note->publishstate = $formdata->publishstate;
|
||||
if (note_save($note)) {
|
||||
|
@ -65,12 +66,13 @@ if($noteform->is_submitted()) {
|
|||
$note->id = 0;
|
||||
$note->course = $courseid;
|
||||
$note->user = $userid;
|
||||
|
||||
$note->publishstate = optional_param('state', NOTES_STATE_PUBLIC, PARAM_ALPHA);
|
||||
}
|
||||
$noteform->set_data($note);
|
||||
$strnotes = get_string('notes', 'notes');
|
||||
$strnotes = get_string('addnewnote', 'notes');
|
||||
|
||||
// output HTML
|
||||
print_header($course->shortname . ': ' . $strnotes, $course->fullname);
|
||||
$crumbs = array(array('name' => $strnotes, 'link' => '', 'type' => 'activity'));
|
||||
print_header($course->shortname . ': ' . $strnotes, $course->fullname, build_navigation($crumbs));
|
||||
$noteform->display();
|
||||
print_footer();
|
||||
|
|
|
@ -15,6 +15,8 @@ if (!$note = note_load($noteid)) {
|
|||
if (!$course = get_record('course', 'id', $note->courseid)) {
|
||||
error('Incorrect course id found');
|
||||
}
|
||||
// require login to access notes
|
||||
require_login($course->id);
|
||||
|
||||
// locate context information
|
||||
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
|
@ -38,9 +40,12 @@ if (data_submitted() && confirm_sesskey()) {
|
|||
$strnotes = get_string('notes', 'notes');
|
||||
$optionsyes = array('note'=>$noteid, 'sesskey'=>sesskey());
|
||||
$optionsno = array('course'=>$course->id, 'user'=>$note->userid);
|
||||
print_header($course->shortname . ': ' . $strnotes, $course->fullname);
|
||||
|
||||
// output HTML
|
||||
$crumbs = array(array('name' => $strnotes, 'link' => '', 'type' => 'activity'));
|
||||
print_header($course->shortname . ': ' . $strnotes, $course->fullname, build_navigation($crumbs));
|
||||
notice_yesno(get_string('deleteconfirm', 'notes'), 'delete.php', 'index.php', $optionsyes, $optionsno, 'post', 'get');
|
||||
echo '<br />';
|
||||
note_print($note, NOTES_SHOW_BODY | NOTES_SHOW_HEAD);
|
||||
print_footer();
|
||||
}
|
||||
}
|
|
@ -15,6 +15,8 @@ if (!$note = note_load($noteid)) {
|
|||
if (!$course = get_record('course', 'id', $note->courseid)) {
|
||||
error('Incorrect course id found');
|
||||
}
|
||||
// require login to access notes
|
||||
require_login($course->id);
|
||||
|
||||
// locate context information
|
||||
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
|
@ -54,7 +56,6 @@ if ($formdata = $noteform->get_data()){
|
|||
$note->userid = $formdata->user;
|
||||
$note->content = $formdata->content;
|
||||
$note->format = FORMAT_PLAIN;
|
||||
$note->rating = $formdata->rating;
|
||||
$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');
|
||||
|
@ -74,9 +75,10 @@ if($noteform->is_submitted()) {
|
|||
$note->note = $note->id;
|
||||
}
|
||||
$noteform->set_data($note);
|
||||
$strnotes = get_string('notes', 'notes');
|
||||
$strnotes = get_string('editnote', 'notes');
|
||||
|
||||
// output HTML
|
||||
print_header($course->shortname . ': ' . $strnotes, $course->fullname);
|
||||
$crumbs = array(array('name' => $strnotes, 'link' => '', 'type' => 'activity'));
|
||||
print_header($course->shortname . ': ' . $strnotes, $course->fullname, build_navigation($crumbs));
|
||||
$noteform->display();
|
||||
print_footer();
|
||||
|
|
|
@ -6,23 +6,22 @@ class note_edit_form extends moodleform {
|
|||
|
||||
function definition() {
|
||||
$mform =& $this->_form;
|
||||
|
||||
$mform->addElement('header', 'general', get_string('general', 'form'));
|
||||
$strcontent = get_string('content', 'notes');
|
||||
$strpublishstate = get_string('publishstate', 'notes');
|
||||
$mform->addElement('header', 'general', get_string('note', 'notes'));
|
||||
|
||||
$mform->addElement('select', 'user', get_string('user'), $this->_customdata['userlist']);
|
||||
$mform->addRule('user', get_string('nouser', 'notes'), 'required', null, 'client');
|
||||
|
||||
$mform->addElement('textarea', 'content', get_string('content', 'notes'), array('rows'=>15, 'cols'=>40));
|
||||
$mform->addElement('textarea', 'content', $strcontent, array('rows'=>15, 'cols'=>40));
|
||||
$mform->setType('content', PARAM_RAW);
|
||||
$mform->addRule('content', get_string('nocontent', 'notes'), 'required', null, 'client');
|
||||
$mform->setHelpButton('content', array('writing', 'richtext'), false, 'editorhelpbutton');
|
||||
$mform->setHelpButton('content', 'writing');
|
||||
|
||||
$mform->addElement('select', 'rating', get_string('rating', 'notes'), note_get_rating_names());
|
||||
$mform->setDefault('rating', 3);
|
||||
|
||||
$mform->addElement('select', 'publishstate', get_string('publishstate', 'notes'), note_get_state_names());
|
||||
$mform->addElement('select', 'publishstate', $strpublishstate, note_get_state_names());
|
||||
$mform->setDefault('publishstate', NOTES_STATE_PUBLIC);
|
||||
$mform->setType('publishstate', PARAM_ALPHA);
|
||||
$mform->setHelpButton('publishstate', array('status', $strpublishstate, 'notes'));
|
||||
|
||||
$this->add_action_buttons();
|
||||
|
||||
|
|
|
@ -51,27 +51,38 @@ print_header($course->shortname . ': ' . $strnotes, $course->fullname, build_nav
|
|||
|
||||
require_once($CFG->dirroot .'/user/tabs.php');
|
||||
|
||||
$strsitenotes = get_string('sitenotes', 'notes');
|
||||
$strcoursenotes = get_string('coursenotes', 'notes');
|
||||
$strpersonalnotes = get_string('personalnotes', 'notes');
|
||||
$straddnewnote = get_string('addnewnote', 'notes');
|
||||
|
||||
if($courseid != SITEID) {
|
||||
echo '<a href="#sitenotes">' . $strsitenotes . '</a> | <a href="#coursenotes">' . $strcoursenotes . '</a> | <a href="#personalnotes">' . $strpersonalnotes . '</a>';
|
||||
$context = get_context_instance(CONTEXT_COURSE, $courseid);
|
||||
if (has_capability('moodle/notes:manage', $context)) {
|
||||
$addlink = $CFG->wwwroot .'/notes/add.php?course=' . $courseid . '&user=' . $userid;
|
||||
echo '<p><a href="'. $addlink . '">' . get_string('addnewnote', 'notes') . '</a></p>';
|
||||
}
|
||||
note_print_notes(get_string('sitenotes', 'notes'), $context, 0, $userid, NOTES_STATE_SITE, 0);
|
||||
note_print_notes(get_string('coursenotes', 'notes'), $context, $courseid, $userid, NOTES_STATE_PUBLIC, 0);
|
||||
note_print_notes(get_string('personalnotes', 'notes'), $context, $courseid, $userid, NOTES_STATE_DRAFT, $USER->id);
|
||||
$addid = has_capability('moodle/notes:manage', $context) ? $courseid : 0;
|
||||
$view = has_capability('moodle/notes:view', $context);
|
||||
note_print_notes('<a name="sitenotes"></a>' . $strsitenotes, $addid, $view, 0, $userid, NOTES_STATE_SITE, 0);
|
||||
note_print_notes('<a name="coursenotes"></a>' . $strcoursenotes, $addid, $view, $courseid, $userid, NOTES_STATE_PUBLIC, 0);
|
||||
note_print_notes('<a name="personalnotes"></a>' . $strpersonalnotes, $addid, $view, $courseid, $userid, NOTES_STATE_DRAFT, $USER->id);
|
||||
} else {
|
||||
$context = get_context_instance(CONTEXT_SYSTEM);
|
||||
note_print_notes(get_string('sitenotes', 'notes'), $context, 0, $userid, NOTES_STATE_SITE, 0);
|
||||
echo '<a href="#sitenotes">' . $strsitenotes . '</a> | <a href="#coursenotes">' . $strcoursenotes . '</a>';
|
||||
$view = has_capability('moodle/notes:view', get_context_instance(CONTEXT_SYSTEM));
|
||||
note_print_notes('<a name="sitenotes"></a>' . $strsitenotes, 0, $view, 0, $userid, NOTES_STATE_SITE, 0);
|
||||
echo '<a name="coursenotes"></a>';
|
||||
if($userid) {
|
||||
$courses = get_my_courses($userid);
|
||||
foreach($courses as $c) {
|
||||
$header = '<a href="' . $CFG->wwwroot . '/course/view.php?id=' . $c->id . '">' . $c->fullname . '</a>';
|
||||
note_print_notes($header, $context, $c->id, $userid, NOTES_STATE_PUBLIC, 0);
|
||||
if (has_capability('moodle/notes:manage', get_context_instance(CONTEXT_COURSE, $c->id))) {
|
||||
$addid = $c->id;
|
||||
}else {
|
||||
$addid = 0;
|
||||
}
|
||||
note_print_notes($header, $addid, $view, $c->id, $userid, NOTES_STATE_PUBLIC, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
add_to_log($courseid, 'notes', 'view', 'index.php?course='.$courseid.'&user='.$userid, 'view notes');
|
||||
|
||||
print_footer($course);
|
||||
print_footer($course);
|
|
@ -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 . '&user=' . $userid . '&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>';
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,5 +5,5 @@
|
|||
/// This fragment is called by moodle_needs_upgrading() and /admin/index.php
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
$note_version = 2007070300; // The current version of note module (Date: YYYYMMDDXX)
|
||||
$note_version = 2007070700; // The current version of note module (Date: YYYYMMDDXX)
|
||||
$module->cron = 1800; // Period for cron to check this module (secs)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue