mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 00:12:56 +02:00
MDL-16692 converted glossary comments to new editor + file API fixes
This commit is contained in:
parent
32a9397820
commit
989c16eeb9
@ -84,7 +84,6 @@ $string['cannotimport'] = 'Import error';
|
||||
$string['cannotimportgrade'] = 'Grade import error';
|
||||
$string['cannotimportformat'] = 'Sorry, importing this format is not yet implemented!';
|
||||
$string['cannotinsertcategory'] = 'Weird error. The category was not inserted.';
|
||||
$string['cannotinsertcomment'] = 'Could not insert this new comment';
|
||||
$string['cannotinsertgrade'] = 'Cannot insert grade item without course id!';
|
||||
$string['cannotinsertrate'] = 'Could not insert a new rating ($a->id = $a->rating)';
|
||||
$string['cannotinsertrecord'] = 'Could not insert new record ID $a';
|
||||
|
@ -128,6 +128,9 @@ function file_prepare_standard_editor($data, $field, array $options, $context=nu
|
||||
if (!isset($options['subdirs'])) {
|
||||
$options['subdirs'] = false;
|
||||
}
|
||||
if (!isset($options['maxfiles'])) {
|
||||
$options['maxfiles'] = 0; // no files by default
|
||||
}
|
||||
|
||||
if (empty($data->id) or empty($context)) {
|
||||
$contextid = null;
|
||||
@ -152,9 +155,13 @@ function file_prepare_standard_editor($data, $field, array $options, $context=nu
|
||||
$contextid = $context->id;
|
||||
}
|
||||
|
||||
$draftid_editor = file_get_submitted_draft_itemid($field);
|
||||
$currenttext = file_prepare_draft_area($draftid_editor, $contextid, $filearea, $data->id, $options['subdirs'], $data->{$field}, $options['forcehttps']);
|
||||
$data->{$field.'_editor'} = array('text'=>$currenttext, 'format'=>$data->{$field.'format'}, 'itemid'=>$draftid_editor);
|
||||
if ($options['maxfiles'] != 0) {
|
||||
$draftid_editor = file_get_submitted_draft_itemid($field);
|
||||
$currenttext = file_prepare_draft_area($draftid_editor, $contextid, $filearea, $data->id, $options['subdirs'], $data->{$field}, $options['forcehttps']);
|
||||
$data->{$field.'_editor'} = array('text'=>$currenttext, 'format'=>$data->{$field.'format'}, 'itemid'=>$draftid_editor);
|
||||
} else {
|
||||
$data->{$field.'_editor'} = array('text'=>$data->{$field}, 'format'=>$data->{$field.'format'}, 0);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
@ -169,7 +176,7 @@ function file_prepare_standard_editor($data, $field, array $options, $context=nu
|
||||
* @param int $itemid item id, required if item exists
|
||||
* @return object modified data object
|
||||
*/
|
||||
function file_postupdate_standard_editor($data, $field, array $options, $context, $filearea, $itemid) {
|
||||
function file_postupdate_standard_editor($data, $field, array $options, $context, $filearea=null, $itemid=null) {
|
||||
$options = (array)$options;
|
||||
if (!isset($options['trusttext'])) {
|
||||
$options['trusttext'] = false;
|
||||
@ -195,7 +202,11 @@ function file_postupdate_standard_editor($data, $field, array $options, $context
|
||||
|
||||
$editor = $data->{$field.'_editor'};
|
||||
|
||||
$data->{$field} = file_save_draft_area_files($editor['itemid'], $context->id, $filearea, $itemid, $options, $editor['text'], $options['forcehttps']);
|
||||
if ($options['maxfiles'] != 0 or is_null($filearea) or is_null($itemid)) {
|
||||
$data->{$field} = file_save_draft_area_files($editor['itemid'], $context->id, $filearea, $itemid, $options, $editor['text'], $options['forcehttps']);
|
||||
} else {
|
||||
$data->{$field} = $editor['text'];
|
||||
}
|
||||
$data->{$field.'format'} = $editor['format'];
|
||||
|
||||
return $data;
|
||||
|
@ -30,9 +30,9 @@ switch ($action) {
|
||||
function glossary_comment_add() {
|
||||
global $USER, $DB;
|
||||
|
||||
$eid = optional_param('eid', 0, PARAM_INT); // Entry ID
|
||||
$entryid = optional_param('entryid', 0, PARAM_INT); // Entry ID
|
||||
|
||||
if (!$entry = $DB->get_record('glossary_entries', array('id'=>$eid))) {
|
||||
if (!$entry = $DB->get_record('glossary_entries', array('id'=>$entryid))) {
|
||||
print_error('invalidentry');
|
||||
}
|
||||
if (!$glossary = $DB->get_record('glossary', array('id'=>$entry->glossaryid))) {
|
||||
@ -45,34 +45,37 @@ function glossary_comment_add() {
|
||||
print_error('coursemisconf');
|
||||
}
|
||||
|
||||
require_login($course->id, false, $cm);
|
||||
require_login($course, false, $cm);
|
||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||
/// Both the configuration and capability must allow comments
|
||||
if (!$glossary->allowcomments or !has_capability('mod/glossary:comment', $context)) {
|
||||
print_error('nopermissiontocomment');
|
||||
}
|
||||
|
||||
$mform = new mod_glossary_comment_form();
|
||||
$mform->set_data(array('eid'=>$eid, 'action'=>'add'));
|
||||
$commentoptions = array('trusttext'=>true, 'maxfiles'=>0);
|
||||
|
||||
$comment = new object();
|
||||
$comment->id = null;
|
||||
$comment->action = 'edit';
|
||||
$comment->entryid = $entry->id;
|
||||
|
||||
$comment = file_prepare_standard_editor($comment, 'entrycomment', $commentoptions, $context);
|
||||
|
||||
$mform = new mod_glossary_comment_form(array('current'=>$comment, 'commentoptions'=>$commentoptions));
|
||||
|
||||
if ($mform->is_cancelled()) {
|
||||
redirect("comments.php?id=$cm->id&eid=$entry->id");
|
||||
}
|
||||
|
||||
if ($data = $mform->get_data()) {
|
||||
$newcomment = new object();
|
||||
$newcomment->entryid = $entry->id;
|
||||
$newcomment->entrycomment = $data->entrycomment;
|
||||
$newcomment->entrycommentformat = $data->entrycommentformat;
|
||||
$newcomment->entrycommenttrust = trusttext_trusted($context);
|
||||
$newcomment->timemodified = time();
|
||||
$newcomment->userid = $USER->id;
|
||||
if ($newcomment = $mform->get_data()) {
|
||||
|
||||
if (!$newcomment->id = $DB->insert_record('glossary_comments', $newcomment)) {
|
||||
print_error('cannotinsertcomment');
|
||||
} else {
|
||||
add_to_log($course->id, 'glossary', 'add comment', "comments.php?id=$cm->id&eid=$entry->id", "$newcomment->id", $cm->id);
|
||||
}
|
||||
$newcomment = file_postupdate_standard_editor($newcomment, 'entrycomment', $newcommentoptions, $context);//no files - can be used before insert
|
||||
$newcomment->timemodified = time();
|
||||
$newcomment->userid = $USER->id;
|
||||
|
||||
$newcomment->id = $DB->insert_record('glossary_comments', $newcomment);
|
||||
|
||||
add_to_log($course->id, 'glossary', 'add comment', "comments.php?id=$cm->id&eid=$entry->id", "$newcomment->id", $cm->id);
|
||||
redirect("comments.php?id=$cm->id&eid=$entry->id");
|
||||
|
||||
} else {
|
||||
@ -89,10 +92,10 @@ function glossary_comment_add() {
|
||||
function glossary_comment_delete() {
|
||||
global $USER, $DB;
|
||||
|
||||
$cid = optional_param('cid', 0, PARAM_INT); // Comment ID
|
||||
$id = optional_param('id', 0, PARAM_INT); // Comment ID
|
||||
$confirm = optional_param('confirm', 0, PARAM_BOOL); // delete confirmation
|
||||
|
||||
if (!$comment = $DB->get_record('glossary_comments', array('id'=>$cid))) {
|
||||
if (!$comment = $DB->get_record('glossary_comments', array('id'=>$id))) {
|
||||
print_error('invalidcomment');
|
||||
}
|
||||
if (!$entry = $DB->get_record('glossary_entries', array('id'=>$comment->entryid))) {
|
||||
@ -108,7 +111,7 @@ function glossary_comment_delete() {
|
||||
print_error('coursemisconf');
|
||||
}
|
||||
|
||||
require_login($course->id, false, $cm);
|
||||
require_login($course, false, $cm);
|
||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||
if (($comment->userid <> $USER->id) and !has_capability('mod/glossary:managecomments', $context)) {
|
||||
print_error('nopermissiontodelcomment', 'glossary');
|
||||
@ -118,15 +121,15 @@ function glossary_comment_delete() {
|
||||
}
|
||||
|
||||
if (data_submitted() and $confirm) {
|
||||
$DB->delete_records('glossary_comments', array('id'=>$cid));
|
||||
$DB->delete_records('glossary_comments', array('id'=>$id));
|
||||
add_to_log($course->id, 'glossary', 'delete comment', "comments.php?id=$cm->id&eid=$entry->id", "$comment->id",$cm->id);
|
||||
redirect("comments.php?id=$cm->id&eid=$entry->id");
|
||||
|
||||
} else {
|
||||
$linkyes = 'comment.php';
|
||||
$optionsyes = array('action'=>'delete', 'cid'=>$cid, 'confirm'=>1);
|
||||
$optionsyes = array('action'=>'delete', 'id'=>$id, 'confirm'=>1);
|
||||
$linkno = 'comments.php';
|
||||
$optionsno = array('id'=>$cm->id, 'eid'=>$entry->id);
|
||||
$optionsno = array('id'=>$cm->id, 'entryid'=>$entry->id);
|
||||
$strdeletewarning = get_string('areyousuredeletecomment','glossary');
|
||||
|
||||
glossary_comment_print_header($course, $cm, $glossary, $entry, 'delete');
|
||||
@ -143,9 +146,9 @@ function glossary_comment_delete() {
|
||||
function glossary_comment_edit() {
|
||||
global $CFG, $USER, $DB;
|
||||
|
||||
$cid = optional_param('cid', 0, PARAM_INT); // Comment ID
|
||||
$id = optional_param('id', 0, PARAM_INT); // Comment ID
|
||||
|
||||
if (!$comment = $DB->get_record('glossary_comments', array('id'=>$cid))) {
|
||||
if (!$comment = $DB->get_record('glossary_comments', array('id'=>$id))) {
|
||||
print_error('invalidcomment');
|
||||
}
|
||||
if (!$entry = $DB->get_record('glossary_entries', array('id'=>$comment->entryid))) {
|
||||
@ -161,7 +164,7 @@ function glossary_comment_edit() {
|
||||
print_error('coursemisconf');
|
||||
}
|
||||
|
||||
require_login($course->id, false, $cm);
|
||||
require_login($course, false, $cm);
|
||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||
if (!$glossary->allowcomments and !has_capability('mod/glossary:managecomments', $context)) {
|
||||
print_error('nopermissiontodelinglossary', 'glossary');
|
||||
@ -174,20 +177,17 @@ function glossary_comment_edit() {
|
||||
print_error('cannoteditcommentexpired');
|
||||
}
|
||||
|
||||
// clean up existing text if needed
|
||||
$comment = trusttext_pre_edit($comment, 'entrycomment', $context);
|
||||
$commentoptions = array('trusttext'=>true, 'maxfiles'=>0);
|
||||
|
||||
$mform = new mod_glossary_comment_form();
|
||||
$mform->set_data(array('cid'=>$cid, 'action'=>'edit', 'entrycomment'=>$comment->entrycomment, 'entrycommentformat'=>$comment->entrycommentformat));
|
||||
$comment->action = 'edit';
|
||||
$comment = file_prepare_standard_editor($comment, 'entrycomment', $commentoptions, $context);
|
||||
|
||||
if ($data = $mform->get_data()) {
|
||||
$mform = new mod_glossary_comment_form(array('current'=>$comment, 'commentoptions'=>$commentoptions));
|
||||
|
||||
$updatedcomment = new object();
|
||||
$updatedcomment->id = $cid;
|
||||
$updatedcomment->entrycomment = $data->entrycomment;
|
||||
$updatedcomment->entrycommentformat = $data->entrycommentformat;
|
||||
$updatedcomment->entrycommenttrust = trusttext_trusted($context);
|
||||
$updatedcomment->timemodified = time();
|
||||
if ($updatedcomment = $mform->get_data()) {
|
||||
|
||||
$updatedcomment = file_postupdate_standard_editor($updatedcomment, 'entrycomment', $commentoptions, $context);
|
||||
$updatedcomment->timemodified = time();
|
||||
|
||||
$DB->update_record('glossary_comments', $updatedcomment);
|
||||
add_to_log($course->id, 'glossary', 'update comment', "comments.php?id=$cm->id&eid=$entry->id", "$updatedcomment->id",$cm->id);
|
||||
|
@ -6,21 +6,20 @@ class mod_glossary_comment_form extends moodleform {
|
||||
function definition() {
|
||||
$mform =& $this->_form;
|
||||
|
||||
$current = $this->_customdata['current'];
|
||||
$commentoptions = $this->_customdata['commentoptions'];
|
||||
|
||||
// visible elements
|
||||
$mform->addElement('htmleditor', 'entrycomment',get_string('comment', 'glossary'));
|
||||
$mform->addRule('entrycomment', get_string('required'), 'required', null, 'client');
|
||||
$mform->setType('entrycomment', PARAM_RAW); // processed by trust text or cleaned before the display
|
||||
$mform->setHelpButton('entrycomment', array('writing', 'richtext2'), false, 'editorhelpbutton');
|
||||
|
||||
$mform->addElement('format', 'entrycommentformat', get_string('format'));
|
||||
$mform->setHelpButton('entrycommentformat', array('textformat', get_string('helpformatting')));
|
||||
$mform->addElement('editor', 'entrycomment_editor', get_string('comment', 'glossary'), $commentoptions);
|
||||
$mform->addRule('entrycomment_editor', get_string('required'), 'required', null, 'client');
|
||||
$mform->setType('entrycomment_editor', PARAM_RAW); // processed by trust text or cleaned before the display
|
||||
|
||||
// hidden optional params
|
||||
$mform->addElement('hidden', 'cid', 0);
|
||||
$mform->setType('cid', PARAM_INT);
|
||||
$mform->addElement('hidden', 'id', 0);
|
||||
$mform->setType('id', PARAM_INT);
|
||||
|
||||
$mform->addElement('hidden', 'eid', 0);
|
||||
$mform->setType('eid', PARAM_INT);
|
||||
$mform->addElement('hidden', 'entryid', 0);
|
||||
$mform->setType('entryid', PARAM_INT);
|
||||
|
||||
$mform->addElement('hidden', 'action', '');
|
||||
$mform->setType('action', PARAM_ACTION);
|
||||
@ -28,6 +27,9 @@ class mod_glossary_comment_form extends moodleform {
|
||||
//-------------------------------------------------------------------------------
|
||||
// buttons
|
||||
$this->add_action_buttons(false);
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
$this->set_data($current);
|
||||
}
|
||||
}
|
||||
?>
|
@ -56,7 +56,7 @@
|
||||
print_heading(format_string(get_string('commentson','glossary')." <b>\"$entry->concept\"</b>"));
|
||||
|
||||
if (has_capability('mod/glossary:comment', $context) and $glossary->allowcomments) {
|
||||
print_heading("<a href=\"comment.php?action=add&eid=$entry->id\">$straddcomment <img title=\"$straddcomment\" src=\"comment.gif\" class=\"iconsmall\" alt=\"$straddcomment\" /></a>");
|
||||
print_heading("<a href=\"comment.php?action=add&entryid=$entry->id\">$straddcomment <img title=\"$straddcomment\" src=\"comment.gif\" class=\"iconsmall\" alt=\"$straddcomment\" /></a>");
|
||||
}
|
||||
|
||||
if ($comments = $DB->get_records("glossary_comments", array("entryid"=>$entry->id), "timemodified ASC")) {
|
||||
|
@ -751,7 +751,7 @@ function glossary_print_entry_icons($course, $cm, $glossary, $entry, $mode='',$h
|
||||
|
||||
if (has_capability('mod/glossary:comment', $context) and $glossary->allowcomments) {
|
||||
$output = true;
|
||||
$return .= ' <a title="' . get_string('addcomment','glossary') . '" href="comment.php?action=add&eid='.$entry->id.'"><img src="comment.gif" class="iconsmall" alt="'.get_string('addcomment','glossary').$altsuffix.'" /></a>';
|
||||
$return .= ' <a title="' . get_string('addcomment','glossary') . '" href="comment.php?action=add&entryid='.$entry->id.'"><img src="comment.gif" class="iconsmall" alt="'.get_string('addcomment','glossary').$altsuffix.'" /></a>';
|
||||
}
|
||||
|
||||
|
||||
@ -1431,11 +1431,11 @@ function glossary_print_comment($course, $cm, $glossary, $entry, $comment) {
|
||||
|
||||
$ineditperiod = ((time() - $comment->timemodified < $CFG->maxeditingtime) || $glossary->editalways);
|
||||
if ( ($glossary->allowcomments && $ineditperiod && $USER->id == $comment->userid) || has_capability('mod/glossary:managecomments', $context)) {
|
||||
echo "<a href=\"comment.php?cid=$comment->id&action=edit\"><img
|
||||
echo "<a href=\"comment.php?id=$comment->id&action=edit\"><img
|
||||
alt=\"" . get_string("edit") . "\" src=\"$CFG->pixpath/t/edit.gif\" class=\"iconsmall\" /></a> ";
|
||||
}
|
||||
if ( ($glossary->allowcomments && $USER->id == $comment->userid) || has_capability('mod/glossary:managecomments', $context) ) {
|
||||
echo "<a href=\"comment.php?cid=$comment->id&action=delete\"><img
|
||||
echo "<a href=\"comment.php?id=$comment->id&action=delete\"><img
|
||||
alt=\"" . get_string("delete") . "\" src=\"$CFG->pixpath/t/delete.gif\" class=\"iconsmall\" /></a>";
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user