Merge branch 'MDL-46316_notes2' of https://github.com/andyjdavis/moodle
This commit is contained in:
+31
-18
@@ -1,24 +1,34 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
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 '<br />';
|
||||
note_print($note, NOTES_SHOW_BODY | NOTES_SHOW_HEAD);
|
||||
echo $OUTPUT->footer();
|
||||
|
||||
+29
-19
@@ -1,23 +1,36 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
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);
|
||||
|
||||
+20
-3
@@ -1,18 +1,35 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
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');
|
||||
|
||||
|
||||
+29
-9
@@ -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;
|
||||
|
||||
+56
-20
@@ -1,4 +1,18 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* 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 '<a href="#sitenotes">' . $strsitenotes . '</a> | <a href="#coursenotes">' . $strcoursenotes . '</a> | <a href="#personalnotes">' . $strpersonalnotes . '</a>';
|
||||
$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('<a name="sitenotes"></a>' . $strsitenotes, $addid, $view, 0, $userid, NOTES_STATE_SITE, 0);
|
||||
note_print_notes('<a name="coursenotes"></a>' . $strcoursenotes. ' ('.$fullname.')', $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);
|
||||
note_print_notes(
|
||||
'<a name="sitenotes"></a>' . $strsitenotes,
|
||||
$addid,
|
||||
$view,
|
||||
0,
|
||||
$userid,
|
||||
NOTES_STATE_SITE,
|
||||
0
|
||||
);
|
||||
note_print_notes(
|
||||
'<a name="coursenotes"></a>' . $strcoursenotes. ' ('.$fullname.')',
|
||||
$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 { // Normal course
|
||||
//echo '<a href="#sitenotes">' . $strsitenotes . '</a> | <a href="#coursenotes">' . $strcoursenotes . '</a>';
|
||||
} else { // Normal course.
|
||||
$view = has_capability('moodle/notes:view', context_system::instance());
|
||||
note_print_notes('<a name="sitenotes"></a>' . $strsitenotes, 0, $view, 0, $userid, NOTES_STATE_SITE, 0);
|
||||
echo '<a name="coursenotes"></a>';
|
||||
|
||||
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 = '<a href="' . $CFG->wwwroot . '/course/view.php?id=' . $c->id . '">' . $cfullname . '</a>';
|
||||
|
||||
+36
-23
@@ -1,4 +1,18 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* 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 = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$author->id.'&course='.$note->courseid.'">'.fullname($author).'</a>';
|
||||
$authoring->name = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $author->id . '&course='.$note->courseid . '">' . fullname($author) . '</a>';
|
||||
$authoring->date = userdate($note->lastmodified);
|
||||
|
||||
echo '<div class="notepost '. $note->publishstate . 'notepost' .
|
||||
($note->usermodified == $USER->id ? ' ownnotepost' : '') .
|
||||
'" id="note-'. $note->id .'">';
|
||||
'" id="note-' . $note->id . '">';
|
||||
|
||||
// print note head (e.g. author, user refering to, etc)
|
||||
// Print note head (e.g. author, user refering to, etc).
|
||||
if ($detail & NOTES_SHOW_HEAD) {
|
||||
echo '<div class="header">';
|
||||
echo '<div class="user">';
|
||||
echo $OUTPUT->user_picture($user, array('courseid'=>$note->courseid));
|
||||
echo $OUTPUT->user_picture($user, array('courseid' => $note->courseid));
|
||||
echo fullname($user) . '</div>';
|
||||
echo '<div class="info">' .
|
||||
get_string('bynameondate', 'notes', $authoring) .
|
||||
@@ -236,20 +250,20 @@ function note_print($note, $detail = NOTES_SHOW_FULL) {
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
// print note content
|
||||
// Print note content.
|
||||
if ($detail & NOTES_SHOW_BODY) {
|
||||
echo '<div class="content">';
|
||||
echo format_text($note->content, $note->format, array('overflowdiv'=>true));
|
||||
echo format_text($note->content, $note->format, array('overflowdiv' => true));
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
// print note options (e.g. delete, edit)
|
||||
// Print note options (e.g. delete, edit).
|
||||
if ($detail & NOTES_SHOW_FOOT) {
|
||||
if (has_capability('moodle/notes:manage', $systemcontext) && $note->publishstate == NOTES_STATE_SITE ||
|
||||
has_capability('moodle/notes:manage', $context) && ($note->publishstate == NOTES_STATE_PUBLIC || $note->usermodified == $USER->id)) {
|
||||
echo '<div class="footer"><p>';
|
||||
echo '<a href="'.$CFG->wwwroot.'/notes/edit.php?id='.$note->id. '">'. get_string('edit') .'</a> | ';
|
||||
echo '<a href="'.$CFG->wwwroot.'/notes/delete.php?id='.$note->id. '">'. get_string('delete') .'</a>';
|
||||
echo '<a href="' . $CFG->wwwroot . '/notes/edit.php?id=' . $note->id. '">' . get_string('edit') . '</a> | ';
|
||||
echo '<a href="' . $CFG->wwwroot . '/notes/delete.php?id=' . $note->id. '">' . get_string('delete') . '</a>';
|
||||
echo '</p></div>';
|
||||
}
|
||||
}
|
||||
@@ -264,7 +278,6 @@ function note_print($note, $detail = NOTES_SHOW_FULL) {
|
||||
*/
|
||||
function note_print_list($notes, $detail = NOTES_SHOW_FULL) {
|
||||
|
||||
/// Start printing of the note
|
||||
echo '<div class="notelist">';
|
||||
foreach ($notes as $note) {
|
||||
note_print($note, $detail);
|
||||
@@ -292,9 +305,9 @@ function note_print_notes($header, $addcourseid = 0, $viewnotes = true, $coursei
|
||||
}
|
||||
if ($addcourseid) {
|
||||
if ($userid) {
|
||||
echo '<p><a href="'. $CFG->wwwroot .'/notes/edit.php?courseid=' . $addcourseid . '&userid=' . $userid . '&publishstate=' . $state . '">' . get_string('addnewnote', 'notes') . '</a></p>';
|
||||
echo '<p><a href="' . $CFG->wwwroot . '/notes/edit.php?courseid=' . $addcourseid . '&userid=' . $userid . '&publishstate=' . $state . '">' . get_string('addnewnote', 'notes') . '</a></p>';
|
||||
} else {
|
||||
echo '<p><a href="'. $CFG->wwwroot .'/user/index.php?id=' . $addcourseid. '">' . get_string('addnewnoteselect', 'notes') . '</a></p>';
|
||||
echo '<p><a href="' . $CFG->wwwroot . '/user/index.php?id=' . $addcourseid. '">' . get_string('addnewnoteselect', 'notes') . '</a></p>';
|
||||
}
|
||||
}
|
||||
if ($viewnotes) {
|
||||
@@ -306,7 +319,7 @@ function note_print_notes($header, $addcourseid = 0, $viewnotes = true, $coursei
|
||||
echo '<p>' . get_string('notesnotvisible', 'notes') . '</p>';
|
||||
}
|
||||
if ($header) {
|
||||
echo '</div>'; // notesgroup
|
||||
echo '</div>'; // The notesgroup div.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -318,7 +331,7 @@ function note_print_notes($header, $addcourseid = 0, $viewnotes = true, $coursei
|
||||
function note_delete_all($courseid) {
|
||||
global $DB;
|
||||
|
||||
return $DB->delete_records('post', array('module'=>'notes', 'courseid'=>$courseid));
|
||||
return $DB->delete_records('post', array('module' => 'notes', 'courseid' => $courseid));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -328,5 +341,5 @@ function note_delete_all($courseid) {
|
||||
* @param stdClass $currentcontext Current context of block
|
||||
*/
|
||||
function note_page_type_list($pagetype, $parentcontext, $currentcontext) {
|
||||
return array('notes-*'=>get_string('page-notes-x', 'notes'));
|
||||
return array('notes-*' => get_string('page-notes-x', 'notes'));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user