Skip to content

Commit

Permalink
"MDL-19118, improve comments management"
Browse files Browse the repository at this point in the history
  • Loading branch information
Dongsheng Cai committed Mar 31, 2010
1 parent 610a447 commit 34e20eb
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 67 deletions.
44 changes: 0 additions & 44 deletions comment/admin.js

This file was deleted.

68 changes: 68 additions & 0 deletions comment/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,5 +337,73 @@ M.core_comment = {
});

new CommentHelper(options);
},
init_admin: function(Y) {
var select_all = Y.one('#comment_select_all');
select_all.on('click', function() {
var comments = document.getElementsByName('comments');
var checked = false;
for (var i in comments) {
if (comments[i].checked) {
checked=true;
}
}
for (var i in comments) {
comments[i].checked = !checked;
}
this.set('checked', !checked);
});

var comments_delete = Y.one('#comments_delete');
if (comments_delete) {
comments_delete.on('click', function(e) {
e.preventDefault();
var list = '';
var comments = document.getElementsByName('comments');
for (var i in comments) {
if (typeof comments[i] == 'object' && comments[i].checked) {
list += (comments[i].value + '-');
}
}
if (!list) {
return;
}
var args = {};
args.message = M.str.admin.confirmdeletecomments;
args.callback = function() {
var url = M.cfg.wwwroot + '/comment/index.php';

var data = {
'commentids': list,
'sesskey': M.cfg.sesskey,
'action': 'delete'
}
var cfg = {
method: 'POST',
on: {
complete: function(id,o,p) {
if (!o) {
alert('IO FATAL');
return;
}
if (o.responseText == 'yes') {
location.reload();
}
}
},
arguments: {
scope: this
},
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'User-Agent': 'MoodleComment/3.0'
},
data: build_querystring(data)
};
Y.io(url, cfg);
}
M.util.show_confirm_dialog(e, args);
});
}
}
};
35 changes: 22 additions & 13 deletions comment/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,13 @@
$context = get_context_instance(CONTEXT_SYSTEM);
require_capability('moodle/comment:delete', $context);

$PAGE->requires->yui2_lib('yahoo');
$PAGE->requires->yui2_lib('dom');
$PAGE->requires->yui2_lib('event');
$PAGE->requires->yui2_lib('animation');
$PAGE->requires->yui2_lib('json');
$PAGE->requires->yui2_lib('connection');
$PAGE->requires->js('/comment/admin.js');
$PAGE->requires->js_init_call('M.core_comment.init_admin', null, true);

$action = optional_param('action', '', PARAM_ALPHA);
$commentid = optional_param('commentid', 0, PARAM_INT);
$commentids = optional_param('commentids', '', PARAM_ALPHANUMEXT);
$page = optional_param('page', 0, PARAM_INT);
$confirm = optional_param('confirm', 0, PARAM_INT);

$manager = new comment_manager();

Expand All @@ -51,10 +46,21 @@
if ($action === 'delete') {
// delete a single comment
if (!empty($commentid)) {
if ($manager->delete_comment($commentid)) {
redirect($CFG->httpswwwroot.'/comment/', get_string('deleted'));
if (!$confirm) {
echo $OUTPUT->header();
$optionsyes = array('action'=>'delete', 'commentid'=>$commentid, 'confirm'=>1, 'sesskey'=>sesskey());
$optionsno = array('sesskey'=>sesskey());
$buttoncontinue = new single_button(new moodle_url('/comment/index.php', $optionsyes), get_string('delete'));
$buttoncancel = new single_button(new moodle_url('/comment/index.php', $optionsno), get_string('cancel'));
echo $OUTPUT->confirm(get_string('confirmdeletecomments', 'admin'), $buttoncontinue, $buttoncancel);
echo $OUTPUT->footer();
die;
} else {
$err = 'cannotdeletecomment';
if ($manager->delete_comment($commentid)) {
redirect($CFG->httpswwwroot.'/comment/');
} else {
$err = 'cannotdeletecomment';
}
}
}
// delete a list of comments
Expand All @@ -69,13 +75,16 @@

echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('comments'));
echo $OUTPUT->box_start('generalbox commentsreport');
if (!empty($err)) {
print_error($err, 'error', $CFG->httpswwwroot.'/comment/');
}
if (empty($action)) {
echo '<form method="post">';
$manager->print_comments($page);
echo '<div class="mdl-align">';
echo '<button id="comments_delete">'.get_string('delete').'</button>';
echo '</div>';
echo '<input type="submit" id="comments_delete" name="batchdelete" value="'.get_string('delete').'" />';
echo '</form>';
}

echo $OUTPUT->box_end();
echo $OUTPUT->footer();
23 changes: 14 additions & 9 deletions comment/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class comment_manager {
private $perpage;
function __construct() {
global $CFG;
$this->perpage = $CFG->commentsperpage;
}

/**
* Return comments by pages
Expand Down Expand Up @@ -97,25 +102,25 @@ private function setup_plugin($comment) {
*/
function print_comments($page=0) {
global $CFG, $OUTPUT, $DB;
$this->perpage = 10;
$count = $DB->count_records_sql('SELECT COUNT(*) FROM {comments} c');
$comments = $this->get_comments($page);
$table = new html_table();
$table->head = array ('<input type="checkbox" id="comment_select_all" />', 'author', 'content', 'action');
$table->head = array (html_writer::checkbox('selectall', '', false, get_string('selectall'), array('id'=>'comment_select_all', 'class'=>'comment-report-selectall')), get_string('author', 'search'), get_string('content'), get_string('action'));
$table->align = array ('left', 'left', 'left', 'left');
$table->width = "95%";
$table->data = array();
$linkbase = $CFG->wwwroot.'/comment/index.php?action=delete&sesskey='.sesskey();
foreach ($comments as $c) {
$link = $linkbase . '&commentid='. $c->id;
$this->setup_plugin($c);
if (!empty($this->plugintype)) {
$url = plugin_callback($this->plugintype, $this->pluginname, FEATURE_COMMENT, 'url', array($c));
$context_url = plugin_callback($this->plugintype, $this->pluginname, FEATURE_COMMENT, 'url', array($c));
}
$checkbox = '<input type="checkbox" name="comments" value="'. $c->id .'" />';
$action = '';
$action .= "<a href='{$CFG->wwwroot}/comment/index.php?action=delete&amp;sesskey=".sesskey()."&amp;commentid={$c->id}'>".get_string('delete').'</a>';
$action .= "<br />";
if (!empty($url)) {
$action .= "<a target='_blank' href='{$url}'>".get_string('commentincontext').'</a>';
$checkbox = html_writer::checkbox('comments', $c->id, false);
$action = html_writer::link($link, get_string('delete'));
if (!empty($context_url)) {
$action .= html_writer::tag('br', null);
$action .= html_writer::link($context_url, get_string('commentincontext'), array('target'=>'_blank'));
}
$table->data[] = array($checkbox, $c->username, $c->content, $action);
}
Expand Down
1 change: 1 addition & 0 deletions lang/en_utf8/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@
$string['confirmation'] = 'Confirmation';
$string['confirmed'] = 'Confirmed';
$string['confirminstall'] = 'You are about to install language pack ($a), are you sure?';
$string['confirmdeletecomments'] = 'You are about to delete comments, are you sure?';
$string['cookiehttponly'] = 'Only http cookies';
$string['cookiesecure'] = 'Secure cookies only';
$string['country'] = 'Default country';
Expand Down
1 change: 1 addition & 0 deletions lang/en_utf8/moodle.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@
$string['confirmcheckfull'] = 'Are you absolutely sure you want to confirm $a ?';
$string['confirmed'] = 'Your registration has been confirmed';
$string['confirmednot'] = 'Your registration has not yet been confirmed!';
$string['content'] = 'Content';
$string['continue'] = 'Continue';
$string['continuetocourse'] = 'Click here to enter your course';
$string['convertingwikitomarkdown'] = 'Converting Wiki to Markdown';
Expand Down
4 changes: 3 additions & 1 deletion lib/outputrequirementslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,9 @@ protected function find_module($name) {
case 'core_comment':
$module = array('name' => 'core_comment',
'fullpath' => '/comment/comment.js',
'requires' => array('base', 'io', 'node', 'json', 'yui2-animation'));
'requires' => array('base', 'io', 'node', 'json', 'yui2-animation'),
'strings' => array(array('confirmdeletecomments', 'admin'))
);
break;
case 'core_role':
$module = array('name' => 'core_role',
Expand Down
2 changes: 2 additions & 0 deletions theme/base/style/core.css
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@ table.mod_index {width:100%;}
.comment-content p {padding:0;margin:0 18px 0 0;}
.comment-delete {float:right;text-align:right;}
.comment-container {float:left;width: 305px;margin: 4px;}
.comment-report-selectall{display:none}
.jsenabled .comment-report-selectall{display:inline}

/**
* Completion progress report
Expand Down

0 comments on commit 34e20eb

Please sign in to comment.