Skip to content

Commit

Permalink
MDL-7077, MDL-10181, adding notes for students
Browse files Browse the repository at this point in the history
  • Loading branch information
toyomoyo committed Jul 5, 2007
1 parent 266ebe0 commit eca3af2
Show file tree
Hide file tree
Showing 17 changed files with 909 additions and 8 deletions.
29 changes: 29 additions & 0 deletions lang/en_utf8/notes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?PHP // $Id$
// note.php
$string['notes'] = 'Notes';
$string['sitenotes'] = 'Site notes';
$string['coursenotes'] = 'Course notes';
$string['personalnotes'] = 'Personal notes';
$string['created'] = 'created';
$string['rating'] = 'Rating';
$string['nonotes'] = 'There are no notes.';
$string['notesnotvisible'] = 'You are not allowed to view the notes.';
$string['addnewnote'] = 'Add a new note';
$string['groupaddnewnote'] = 'Add a new note for all';
$string['deleteconfirm'] = 'Delete this note?';
$string['content'] = 'Note content';
$string['nocontent'] = 'Note content can not be empty';
$string['nouser'] = 'You must select a user';
$string['rating'] = 'Rating';
$string['low'] = 'low';
$string['belownormal'] = 'below normal';
$string['normal'] = 'normal';
$string['abovenormal'] = 'above normal';
$string['high'] = 'high';
$string['unknown'] = 'unknown';
$string['bynameondate'] = 'by $a->name - $a->date';
$string['publishstate'] = 'Status';
$string['personal'] = 'personal';
$string['course'] = 'course';
$string['site'] = 'site';
?>
4 changes: 4 additions & 0 deletions lang/en_utf8/role.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,8 @@
$string['site:mnetlogintoremote'] = 'Roam to a remote Moodle';
$string['site:mnetloginfromremote'] = 'Login from a remote Moodle';

// Notes
$string['notes:view'] = 'View notes';
$string['notes:manage'] = 'Manage notes';

?>
23 changes: 21 additions & 2 deletions lib/db/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -1015,8 +1015,27 @@
'legacy' => array(
'user' => CAP_ALLOW
)
)

),

'moodle/notes:view' => array(
'captype' => 'read',
'contextlevel' => CONTEXT_SYSTEM,
'legacy' => array(
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
'admin' => CAP_ALLOW
)
),

'moodle/notes:manage' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'legacy' => array(
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
'admin' => CAP_ALLOW
)
),
);

?>
6 changes: 5 additions & 1 deletion lib/weblib.php
Original file line number Diff line number Diff line change
Expand Up @@ -3744,7 +3744,11 @@ function print_user($user, $course, $messageselect=false, $return=false) {
if ($CFG->bloglevel > 0) {
$output .= '<a href="'.$CFG->wwwroot.'/blog/index.php?userid='.$user->id.'">'.get_string('blogs','blog').'</a><br />';
}

//link to notes
if (has_capability('moodle/notes:manage', $context) || has_capability('moodle/notes:view', $context)) {
$output .= '<a href="'.$CFG->wwwroot.'/notes/index.php?course=' . $course->id. '&amp;user='.$user->id.'">'.get_string('notes','notes').'</a><br />';
}

if (has_capability('moodle/site:viewreports', $context)) {
$timemidnight = usergetmidnight(time());
$output .= '<a href="'. $CFG->wwwroot .'/course/user.php?id='. $course->id .'&amp;user='. $user->id .'">'. $string->activity .'</a><br />';
Expand Down
76 changes: 76 additions & 0 deletions notes/add.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php // $Id$

require_once('../config.php');
require_once('lib.php');

// retrieve parameters
$courseid = required_param('course', PARAM_INT);
$userid = optional_param('user', 0, PARAM_INT);

// locate course information
if (!($course = get_record('course', 'id', $courseid))) {
error('Incorrect course id found');
}

// locate context information
$context = get_context_instance(CONTEXT_COURSE, $course->id);

// check capability
if (!has_capability('moodle/notes:manage', $context)) {
error('You may not create notes');
}

// build-up form
require_once('edit_form.php');
// get option values for the user select
$extradata['userlist'] = array();
$usersincourse = "SELECT * FROM {$CFG->prefix}user WHERE id IN (SELECT userid FROM {$CFG->prefix}role_assignments WHERE contextid={$context->id})";
$userlist = get_records_sql($usersincourse);
// format userdata using fullname
if($userlist) {
foreach($userlist as $user) {
$extradata['userlist'][$user->id] = fullname($user);
}
}
// create form
$noteform = new note_edit_form(null, $extradata);

// if form was cancelled then return to the previous notes list
if ($noteform->is_cancelled()) {
redirect($CFG->wwwroot . '/notes/index.php?course=' . $courseid . '&amp;user=' . $userid);
}

// if data was submitted and validated, then save it to database
if ($formdata = $noteform->get_data()) {
$note = new object();
$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)) {
add_to_log($note->courseid, 'notes', 'add', 'index.php?course='.$note->courseid.'&amp;user='.$note->userid . '#note-' . $note->id , 'add note');
}
// redirect to notes list that contains this note
redirect($CFG->wwwroot . '/notes/index.php?course=' . $note->courseid . '&amp;user=' . $note->userid);
}

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;

}
$noteform->set_data($note);
$strnotes = get_string('notes', 'notes');

// output HTML
print_header($course->shortname . ': ' . $strnotes, $course->fullname);
$noteform->display();
print_footer();
46 changes: 46 additions & 0 deletions notes/delete.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php // $Id$

require_once('../config.php');
require_once('lib.php');

// retrieve parameters
$noteid = required_param('note', PARAM_INT);

// locate note information
if (!$note = note_load($noteid)) {
error('Incorrect note id specified');
}

// locate course information
if (!$course = get_record('course', 'id', $note->courseid)) {
error('Incorrect course id found');
}

// locate context information
$context = get_context_instance(CONTEXT_COURSE, $course->id);

// check capability
if (!has_capability('moodle/notes:manage', $context)) {
error('You may not delete this note');
}

if (data_submitted() && 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)) {
add_to_log($note->courseid, 'notes', 'delete', 'index.php?course='.$note->courseid.'&amp;user='.$note->userid . '#note-' . $note->id , 'delete note');
} else {
error('Error occured while deleting post', $returnurl);
}
redirect($returnurl);
} else {
// if data was not submitted yet, then show note data with a delete confirmation form
$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);
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();
}
82 changes: 82 additions & 0 deletions notes/edit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php // $Id$

require_once('../config.php');
require_once('lib.php');

// retrieve parameters
$noteid = required_param('note', PARAM_INT);

// locate note information
if (!$note = note_load($noteid)) {
error('Incorrect note id specified');
}

// locate course information
if (!$course = get_record('course', 'id', $note->courseid)) {
error('Incorrect course id found');
}

// locate context information
$context = get_context_instance(CONTEXT_COURSE, $course->id);

// check capability
if (!has_capability('moodle/notes:manage', $context)) {
error('You may not modify notes');
}

// build-up form
require_once('edit_form.php');
// get option values for the user select
$extradata['userlist'] = array();
if ($course->id == SITEID) {
$usersincourse = "SELECT * FROM {$CFG->prefix}user WHERE id={$userid}";
} else {
$usersincourse = "SELECT * FROM {$CFG->prefix}user WHERE id IN (SELECT userid FROM {$CFG->prefix}role_assignments WHERE contextid={$context->id})";
}
$userlist = get_records_sql($usersincourse);
// format userdata using fullname
if($userlist) {
foreach($userlist as $user) {
$extradata['userlist'][$user->id] = fullname($user);
}
}
// create form
$noteform = new note_edit_form(null, $extradata);

// if form was cancelled then return to the notes list of the note
if ($noteform->is_cancelled()) {
redirect($CFG->wwwroot . '/notes/index.php?course=' . $note->courseid . '&amp;user=' . $note->userid);
}

// 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->rating = $formdata->rating;
$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');
}
// redirect to notes list that contains this note
redirect($CFG->wwwroot . '/notes/index.php?course=' . $note->courseid . '&amp;user=' . $note->userid);
}


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 used values retrieved from the database
$note->user = $note->userid;
$note->course = $note->courseid;
$note->note = $note->id;
}
$noteform->set_data($note);
$strnotes = get_string('notes', 'notes');

// output HTML
print_header($course->shortname . ': ' . $strnotes, $course->fullname);
$noteform->display();
print_footer();
35 changes: 35 additions & 0 deletions notes/edit_form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php // $Id$

require_once($CFG->libdir.'/formslib.php');

class note_edit_form extends moodleform {

function definition() {
$mform =& $this->_form;

$mform->addElement('header', 'general', get_string('general', 'form'));

$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->setType('content', PARAM_RAW);
$mform->addRule('content', get_string('nocontent', 'notes'), 'required', null, 'client');
$mform->setHelpButton('content', array('writing', 'richtext'), false, 'editorhelpbutton');

$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->setDefault('publishstate', NOTES_STATE_PUBLIC);
$mform->setType('publishstate', PARAM_ALPHA);

$this->add_action_buttons();

$mform->addElement('hidden', 'course');
$mform->setType('course', PARAM_INT);

$mform->addElement('hidden', 'note');
$mform->setType('note', PARAM_INT);
}
}
Loading

0 comments on commit eca3af2

Please sign in to comment.