diff --git a/notes/delete.php b/notes/delete.php
index 573d068d961..ccd2b16f045 100644
--- a/notes/delete.php
+++ b/notes/delete.php
@@ -1,24 +1,34 @@
.
require_once('../config.php');
require_once('lib.php');
-// retrieve parameters
$noteid = required_param('id', PARAM_INT);
-$PAGE->set_url('/notes/delete.php', array('id'=>$noteid));
+$PAGE->set_url('/notes/delete.php', array('id' => $noteid));
-// locate note information
if (!$note = note_load($noteid)) {
print_error('invalidid');
}
-// locate course information
-if (!$course = $DB->get_record('course', array('id'=>$note->courseid))) {
+if (!$course = $DB->get_record('course', array('id' => $note->courseid))) {
print_error('invalidcourseid');
}
-// require login to access notes
require_login($course);
if (empty($CFG->enablenotes)) {
@@ -29,16 +39,14 @@ if (!$user = $DB->get_record('user', array('id' => $note->userid))) {
print_error('invaliduserid');
}
-// locate context information
$context = context_course::instance($course->id);
-// check capability
if (!has_capability('moodle/notes:manage', $context)) {
print_error('nopermissiontodelete', 'notes');
}
if (data_submitted() && confirm_sesskey()) {
-//if data was submitted and is valid, then delete note
+ // 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($note)) {
print_error('cannotdeletepost', 'notes', $returnurl);
@@ -46,24 +54,29 @@ if (data_submitted() && confirm_sesskey()) {
redirect($returnurl);
} else {
-// if data was not submitted yet, then show note data with a delete confirmation form
+ // If data was not submitted yet, then show note data with a delete confirmation form.
$strnotes = get_string('notes', 'notes');
- $optionsyes = array('id'=>$noteid, 'sesskey'=>sesskey());
- $optionsno = array('course'=>$course->id, 'user'=>$note->userid);
+ $optionsyes = array('id' => $noteid, 'sesskey' => sesskey());
+ $optionsno = array('course' => $course->id, 'user' => $note->userid);
-// output HTML
+ // Output HTML.
$link = null;
- if (has_capability('moodle/course:viewparticipants', $context) || has_capability('moodle/site:viewparticipants', context_system::instance())) {
- $link = new moodle_url('/user/index.php',array('id'=>$course->id));
+ if (has_capability('moodle/course:viewparticipants', $context)
+ || has_capability('moodle/site:viewparticipants', context_system::instance())) {
+
+ $link = new moodle_url('/user/index.php', array('id' => $course->id));
}
$PAGE->navbar->add(get_string('participants'), $link);
- $PAGE->navbar->add(fullname($user), new moodle_url('/user/view.php', array('id'=>$user->id,'course'=>$course->id)));
- $PAGE->navbar->add(get_string('notes', 'notes'), new moodle_url('/notes/index.php', array('user'=>$user->id,'course'=>$course->id)));
+ $PAGE->navbar->add(fullname($user), new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $course->id)));
+ $PAGE->navbar->add(get_string('notes', 'notes'),
+ new moodle_url('/notes/index.php', array('user' => $user->id, 'course' => $course->id)));
$PAGE->navbar->add(get_string('delete'));
$PAGE->set_title($course->shortname . ': ' . $strnotes);
$PAGE->set_heading($course->fullname);
echo $OUTPUT->header();
- echo $OUTPUT->confirm(get_string('deleteconfirm', 'notes'), new moodle_url('delete.php',$optionsyes), new moodle_url('index.php',$optionsno));
+ echo $OUTPUT->confirm(get_string('deleteconfirm', 'notes'),
+ new moodle_url('delete.php', $optionsyes),
+ new moodle_url('index.php', $optionsno));
echo '
';
note_print($note, NOTES_SHOW_BODY | NOTES_SHOW_HEAD);
echo $OUTPUT->footer();
diff --git a/notes/edit.php b/notes/edit.php
index be9ed29978f..88a697f7965 100644
--- a/notes/edit.php
+++ b/notes/edit.php
@@ -1,23 +1,36 @@
.
require_once('../config.php');
require_once('lib.php');
require_once('edit_form.php');
-/// retrieve parameters
$noteid = optional_param('id', 0, PARAM_INT);
$url = new moodle_url('/notes/edit.php');
if ($noteid) {
- //existing note
+ // Existing note.
$url->param('id', $noteid);
if (!$note = note_load($noteid)) {
print_error('invalidid', 'notes');
}
} else {
- // adding new note
+ // Adding new note.
$courseid = required_param('courseid', PARAM_INT);
$userid = required_param('userid', PARAM_INT);
$state = optional_param('publishstate', NOTES_STATE_PUBLIC, PARAM_ALPHA);
@@ -36,19 +49,16 @@ if ($noteid) {
$PAGE->set_url($url);
-/// locate course information
-if (!$course = $DB->get_record('course', array('id'=>$note->courseid))) {
+if (!$course = $DB->get_record('course', array('id' => $note->courseid))) {
print_error('invalidcourseid');
}
-/// require login to access notes
require_login($course);
if (empty($CFG->enablenotes)) {
print_error('notesdisabled', 'notes');
}
-/// locate context information
$context = context_course::instance($course->id);
require_capability('moodle/notes:manage', $context);
@@ -56,19 +66,16 @@ if (!$user = $DB->get_record('user', array('id' => $note->userid))) {
print_error('invaliduserid');
}
-/// create form
$noteform = new note_edit_form();
-
-/// set defaults
$noteform->set_data($note);
-/// if form was cancelled then return to the notes list of the note
+// 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 . '&user=' . $note->userid);
}
-/// if data was submitted and validated, then save it to database
-if ($note = $noteform->get_data()){
+// If data was submitted and validated, then save it to database.
+if ($note = $noteform->get_data()) {
if ($noteid) {
// A noteid has been used, we don't allow editing of course or user so
// lets unset them to be sure we never change that by accident.
@@ -76,7 +83,7 @@ if ($note = $noteform->get_data()){
unset($note->userid);
}
note_save($note);
- // redirect to notes list that contains this note
+ // Redirect to notes list that contains this note.
redirect($CFG->wwwroot . '/notes/index.php?course=' . $note->courseid . '&user=' . $note->userid);
}
@@ -86,14 +93,17 @@ if ($noteid) {
$strnotes = get_string('addnewnote', 'notes');
}
-/// output HTML
+// Output HTML.
$link = null;
-if (has_capability('moodle/course:viewparticipants', $context) || has_capability('moodle/site:viewparticipants', context_system::instance())) {
- $link = new moodle_url('/user/index.php',array('id'=>$course->id));
+if (has_capability('moodle/course:viewparticipants', $context)
+ || has_capability('moodle/site:viewparticipants', context_system::instance())) {
+
+ $link = new moodle_url('/user/index.php', array('id' => $course->id));
}
$PAGE->navbar->add(get_string('participants'), $link);
-$PAGE->navbar->add(fullname($user), new moodle_url('/user/view.php', array('id'=>$user->id,'course'=>$course->id)));
-$PAGE->navbar->add(get_string('notes', 'notes'), new moodle_url('/notes/index.php', array('user'=>$user->id,'course'=>$course->id)));
+$PAGE->navbar->add(fullname($user), new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $course->id)));
+$PAGE->navbar->add(get_string('notes', 'notes'),
+ new moodle_url('/notes/index.php', array('user' => $user->id, 'course' => $course->id)));
$PAGE->navbar->add($strnotes);
$PAGE->set_title($course->shortname . ': ' . $strnotes);
$PAGE->set_heading($course->fullname);
diff --git a/notes/edit_form.php b/notes/edit_form.php
index e66c4346cc2..5494a5e87ca 100644
--- a/notes/edit_form.php
+++ b/notes/edit_form.php
@@ -1,18 +1,35 @@
.
if (!defined('MOODLE_INTERNAL')) {
- die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
+ die('Direct access to this script is forbidden.'); // It must be included from a Moodle page.
}
require_once($CFG->libdir.'/formslib.php');
class note_edit_form extends moodleform {
- function definition() {
+ /**
+ * Define the form for editing notes
+ */
+ public function definition() {
$mform =& $this->_form;
$mform->addElement('header', 'general', get_string('note', 'notes'));
- $mform->addElement('textarea', 'content', get_string('content', 'notes'), array('rows'=>15, 'cols'=>40));
+ $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');
diff --git a/notes/externallib.php b/notes/externallib.php
index 92698f0d63f..98f9985b6df 100644
--- a/notes/externallib.php
+++ b/notes/externallib.php
@@ -84,14 +84,14 @@ class core_notes_external extends external_api {
// Retrieve all courses.
$courseids = array();
- foreach($params['notes'] as $note) {
+ foreach ($params['notes'] as $note) {
$courseids[] = $note['courseid'];
}
$courses = $DB->get_records_list("course", "id", $courseids);
// Retrieve all users of the notes.
$userids = array();
- foreach($params['notes'] as $note) {
+ foreach ($params['notes'] as $note) {
$userids[] = $note['userid'];
}
list($sqluserids, $sqlparams) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED, 'userid_');
@@ -191,7 +191,7 @@ class core_notes_external extends external_api {
new external_single_structure(
array(
'clientnoteid' => new external_value(PARAM_ALPHANUMEXT, 'your own id for the note', VALUE_OPTIONAL),
- 'noteid' => new external_value(PARAM_INT, 'test this to know if it success: id of the created note when successed, -1 when failed'),
+ 'noteid' => new external_value(PARAM_INT, 'ID of the created note when successful, -1 when failed'),
'errormessage' => new external_value(PARAM_TEXT, 'error message - if failed', VALUE_OPTIONAL)
)
)
@@ -241,7 +241,10 @@ class core_notes_external extends external_api {
self::validate_context($context);
require_capability('moodle/notes:manage', $context);
if (!note_delete($note)) {
- $warnings[] = array(array('item'=>'note', 'itemid'=>$noteid, 'warningcode'=>'savedfailed', 'message'=>'Note could not be modified'));
+ $warnings[] = array(array('item' => 'note',
+ 'itemid' => $noteid,
+ 'warningcode' => 'savedfailed',
+ 'message' => 'Note could not be modified'));
}
} else {
$warnings[] = array('item'=>'note', 'itemid'=>$noteid, 'warningcode'=>'badid', 'message'=>'Note does not exist');
@@ -307,14 +310,22 @@ class core_notes_external extends external_api {
$context = context_course::instance($note->courseid);
self::validate_context($context);
require_capability('moodle/notes:view', $context);
- list($gotnote['text'], $gotnote['format']) = external_format_text($note->content, $note->format, $context->id, 'notes', '', '');
+ list($gotnote['text'], $gotnote['format']) = external_format_text($note->content,
+ $note->format,
+ $context->id,
+ 'notes',
+ '',
+ '');
$gotnote['noteid'] = $note->id;
$gotnote['userid'] = $note->userid;
$gotnote['publishstate'] = $note->publishstate;
$gotnote['courseid'] = $note->courseid;
$resultnotes["notes"][] = $gotnote;
} else {
- $resultnotes["warnings"][] = array('item'=>'note', 'itemid'=>$noteid, 'warningcode'=>'badid', 'message'=>'Note does not exist');
+ $resultnotes["warnings"][] = array('item' => 'note',
+ 'itemid' => $noteid,
+ 'warningcode' => 'badid',
+ 'message' => 'Note does not exist');
}
}
return $resultnotes;
@@ -417,14 +428,23 @@ class core_notes_external extends external_api {
$dbnote->courseid = SITEID;
break;
default:
- $warnings[] = array('item'=>'note', 'itemid'=>$note["id"], 'warningcode'=>'badparam', 'message'=>'Provided publishstate incorrect');
+ $warnings[] = array('item' => 'note',
+ 'itemid' => $note["id"],
+ 'warningcode' => 'badparam',
+ 'message' => 'Provided publishstate incorrect');
break;
}
if (!note_save($dbnote)) {
- $warnings[] = array('item'=>'note', 'itemid'=>$note["id"], 'warningcode'=>'savedfailed', 'message'=>'Note could not be modified');
+ $warnings[] = array('item' => 'note',
+ 'itemid' => $note["id"],
+ 'warningcode' => 'savedfailed',
+ 'message' => 'Note could not be modified');
}
} else {
- $warnings[] = array('item'=>'note', 'itemid'=>$note["id"], 'warningcode'=>'badid', 'message'=>'Note does not exist');
+ $warnings[] = array('item' => 'note',
+ 'itemid' => $note["id"],
+ 'warningcode' => 'badid',
+ 'message' => 'Note does not exist');
}
}
return $warnings;
diff --git a/notes/index.php b/notes/index.php
index d831b4b1897..61d919a92a5 100644
--- a/notes/index.php
+++ b/notes/index.php
@@ -1,4 +1,18 @@
.
/**
* file index.php
@@ -9,7 +23,6 @@
require_once('../config.php');
require_once('lib.php');
-/// retrieve parameters
$courseid = optional_param('course', SITEID, PARAM_INT);
$userid = optional_param('user', 0, PARAM_INT);
$filtertype = optional_param('filtertype', '', PARAM_ALPHA);
@@ -28,7 +41,7 @@ if ($userid !== 0) {
}
$PAGE->set_url($url);
-/// tabs compatibility
+// Tabs compatibility.
switch($filtertype) {
case 'course':
$courseid = $filterselect;
@@ -42,12 +55,10 @@ if (empty($courseid)) {
$courseid = SITEID;
}
-/// locate course information
-$course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST);
+$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
-/// locate user information
if ($userid) {
- $user = $DB->get_record('user', array('id'=>$userid), '*', MUST_EXIST);
+ $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
$filtertype = 'user';
$filterselect = $user->id;
@@ -63,16 +74,17 @@ if ($userid) {
$filterselect = $course->id;
}
-/// require login to access notes
require_login($course);
-/// output HTML
+
+// Output HTML.
if ($course->id == SITEID) {
- $coursecontext = context_system::instance(); // SYSTEM context
+ $coursecontext = context_system::instance();
} else {
- $coursecontext = context_course::instance($course->id); // Course context
+ $coursecontext = context_course::instance($course->id);
}
+
require_capability('moodle/notes:view', $coursecontext);
-$systemcontext = context_system::instance(); // SYSTEM context
+$systemcontext = context_system::instance();
// Trigger event.
$event = \core\event\notes_viewed::create(array(
@@ -87,8 +99,10 @@ if ($userid) {
$PAGE->navigation->extend_for_user($user);
} else {
$link = null;
- if (has_capability('moodle/course:viewparticipants', $coursecontext) || has_capability('moodle/site:viewparticipants', $systemcontext)) {
- $link = new moodle_url('/user/index.php',array('id'=>$course->id));
+ if (has_capability('moodle/course:viewparticipants', $coursecontext)
+ || has_capability('moodle/site:viewparticipants', $systemcontext)) {
+
+ $link = new moodle_url('/user/index.php', array('id' => $course->id));
}
}
@@ -111,24 +125,46 @@ $straddnewnote = get_string('addnewnote', 'notes');
echo $OUTPUT->box_start();
if ($courseid != SITEID) {
- //echo '' . $strsitenotes . ' | ' . $strcoursenotes . ' | ' . $strpersonalnotes . '';
$context = context_course::instance($courseid);
$addid = has_capability('moodle/notes:manage', $context) ? $courseid : 0;
$view = has_capability('moodle/notes:view', $context);
$fullname = format_string($course->fullname, true, array('context' => $context));
- note_print_notes('' . $strsitenotes, $addid, $view, 0, $userid, NOTES_STATE_SITE, 0);
- note_print_notes('' . $strcoursenotes. ' ('.$fullname.')', $addid, $view, $courseid, $userid, NOTES_STATE_PUBLIC, 0);
- note_print_notes('' . $strpersonalnotes, $addid, $view, $courseid, $userid, NOTES_STATE_DRAFT, $USER->id);
+ note_print_notes(
+ '' . $strsitenotes,
+ $addid,
+ $view,
+ 0,
+ $userid,
+ NOTES_STATE_SITE,
+ 0
+ );
+ note_print_notes(
+ '' . $strcoursenotes. ' ('.$fullname.')',
+ $addid,
+ $view,
+ $courseid,
+ $userid,
+ NOTES_STATE_PUBLIC,
+ 0
+ );
+ note_print_notes(
+ '' . $strpersonalnotes,
+ $addid,
+ $view,
+ $courseid,
+ $userid,
+ NOTES_STATE_DRAFT,
+ $USER->id
+ );
-} else { // Normal course
- //echo '' . $strsitenotes . ' | ' . $strcoursenotes . '';
+} else { // Normal course.
$view = has_capability('moodle/notes:view', context_system::instance());
note_print_notes('' . $strsitenotes, 0, $view, 0, $userid, NOTES_STATE_SITE, 0);
echo '';
if (!empty($userid)) {
$courses = enrol_get_users_courses($userid);
- foreach($courses as $c) {
+ foreach ($courses as $c) {
$ccontext = context_course::instance($c->id);
$cfullname = format_string($c->fullname, true, array('context' => $ccontext));
$header = '' . $cfullname . '';
diff --git a/notes/lib.php b/notes/lib.php
index 45046a3537d..3071f601423 100644
--- a/notes/lib.php
+++ b/notes/lib.php
@@ -1,4 +1,18 @@
.
/**
* Library of functions and constants for notes
@@ -34,7 +48,7 @@ define('NOTES_SHOW_FOOT', 0x04);
function note_list($courseid=0, $userid=0, $state = '', $author = 0, $order='lastmodified DESC', $limitfrom=0, $limitnum=0) {
global $DB;
- // setup filters
+ // Setup filters.
$selects = array();
$params = array();
if ($courseid) {
@@ -58,21 +72,21 @@ function note_list($courseid=0, $userid=0, $state = '', $author = 0, $order='las
$select = implode(' AND ', $selects);
$fields = 'id,courseid,userid,content,format,created,lastmodified,usermodified,publishstate';
- // retrieve data
+
return $DB->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
+ * @param int $noteid ID of the note to retrieve
* @return stdClass object
*/
-function note_load($note_id) {
+function note_load($noteid) {
global $DB;
$fields = 'id,courseid,userid,content,format,created,lastmodified,usermodified,publishstate';
- return $DB->get_record('post', array('id'=>$note_id, 'module'=>'notes'), $fields);
+ return $DB->get_record('post', array('id' => $noteid, 'module' => 'notes'), $fields);
}
/**
@@ -171,7 +185,7 @@ function note_delete($note) {
* @return string corespondent state name
*/
function note_get_state_name($state) {
- // cache state names
+ // Cache state names.
static $states;
if (empty($states)) {
$states = note_get_state_names();
@@ -205,11 +219,11 @@ function note_get_state_names() {
function note_print($note, $detail = NOTES_SHOW_FULL) {
global $CFG, $USER, $DB, $OUTPUT;
- if (!$user = $DB->get_record('user', array('id'=>$note->userid))) {
+ 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))) {
+ if (!$author = $DB->get_record('user', array('id' => $note->usermodified))) {
debugging("User $note->usermodified not found");
return;
}
@@ -217,18 +231,18 @@ function note_print($note, $detail = NOTES_SHOW_FULL) {
$systemcontext = context_system::instance();
$authoring = new stdClass();
- $authoring->name = ''.fullname($author).'';
+ $authoring->name = '' . fullname($author) . '';
$authoring->date = userdate($note->lastmodified);
echo '
' . get_string('addnewnote', 'notes') . '
'; + echo '' . get_string('addnewnote', 'notes') . '
'; } else { - echo '' . get_string('addnewnoteselect', 'notes') . '
'; + echo '' . get_string('addnewnoteselect', 'notes') . '
'; } } if ($viewnotes) { @@ -306,7 +319,7 @@ function note_print_notes($header, $addcourseid = 0, $viewnotes = true, $coursei echo '' . get_string('notesnotvisible', 'notes') . '
'; } if ($header) { - echo '