This commit is contained in:
Dan Poltawski 2013-09-09 17:37:49 +08:00
commit cdf6fc243e
10 changed files with 48 additions and 14 deletions

View File

@ -77,7 +77,7 @@ $string['csvimport'] = 'CSV file import';
$string['csvimport_help'] = 'Entries may be imported via a plain text file with a list of field names as the first line, then the data, with one record per line.';
$string['csvwithselecteddelimiter'] = '<acronym title="Comma Separated Values">CSV</acronym> text with selected delimiter:';
$string['data:addinstance'] = 'Add a new database';
$string['data:approve'] = 'Approve unapproved entries';
$string['data:approve'] = 'Approve unapproved entries, or disapprove approved ones';
$string['data:comment'] = 'Write comments';
$string['data:exportallentries'] = 'Export all database entries';
$string['data:exportentry'] = 'Export a database entry';
@ -110,6 +110,7 @@ $string['deletenotenrolled'] = 'Delete entries by users not enrolled';
$string['deletewarning'] = 'Are you sure you want to delete this preset?';
$string['descending'] = 'Descending';
$string['directorynotapreset'] = '{$a->directory} Not a preset: missing files: {$a->missing_files}';
$string['disapprove'] = 'Disapprove';
$string['download'] = 'Download';
$string['edit'] = 'Edit';
$string['editcomment'] = 'Edit comment';
@ -288,6 +289,7 @@ $string['presets'] = 'Presets';
$string['radiobutton'] = 'Radio buttons';
$string['recordapproved'] = 'Entry approved';
$string['recorddeleted'] = 'Entry deleted';
$string['recorddisapproved'] = 'Entry disapproved';
$string['recordsnotsaved'] = 'No entry was saved. Please check the format of the uploaded file.';
$string['recordssaved'] = 'entries saved';
$string['requireapproval'] = 'Approval required';

View File

@ -518,12 +518,12 @@ function data_generate_default_template(&$data, $template, $recordid=0, $form=fa
);
}
if ($template == 'listtemplate') {
$cell = new html_table_cell('##edit## ##more## ##delete## ##approve## ##export##');
$cell = new html_table_cell('##edit## ##more## ##delete## ##approve## ##disapprove## ##export##');
$cell->colspan = 2;
$cell->attributes['class'] = 'controls';
$table->data[] = new html_table_row(array($cell));
} else if ($template == 'singletemplate') {
$cell = new html_table_cell('##edit## ##delete## ##approve## ##export##');
$cell = new html_table_cell('##edit## ##delete## ##approve## ##disapprove## ##export##');
$cell->colspan = 2;
$cell->attributes['class'] = 'controls';
$table->data[] = new html_table_row(array($cell));
@ -1270,13 +1270,24 @@ function data_print_template($template, $records, $data, $search='', $page=0, $r
if (has_capability('mod/data:approve', $context) && ($data->approval) && (!$record->approved)) {
$approveurl = new moodle_url('/mod/data/view.php',
array('d' => $data->id, 'approve' => $record->id, 'sesskey' => sesskey()));
$approveicon = new pix_icon('t/approve', get_string('approve'), '', array('class' => 'iconsmall'));
$approveicon = new pix_icon('t/approve', get_string('approve', 'data'), '', array('class' => 'iconsmall'));
$replacement[] = html_writer::tag('span', $OUTPUT->action_icon($approveurl, $approveicon),
array('class' => 'approve'));
} else {
$replacement[] = '';
}
$patterns[]='##disapprove##';
if (has_capability('mod/data:approve', $context) && ($data->approval) && ($record->approved)) {
$disapproveurl = new moodle_url('/mod/data/view.php',
array('d' => $data->id, 'disapprove' => $record->id, 'sesskey' => sesskey()));
$disapproveicon = new pix_icon('t/block', get_string('disapprove', 'data'), '', array('class' => 'iconsmall'));
$replacement[] = html_writer::tag('span', $OUTPUT->action_icon($disapproveurl, $disapproveicon),
array('class' => 'disapprove'));
} else {
$replacement[] = '';
}
$patterns[]='##comments##';
if (($template == 'listtemplate') && ($data->comments)) {

View File

@ -311,6 +311,7 @@ class data_portfolio_caller extends portfolio_module_caller_base {
$patterns[]='##moreurl##';
$patterns[]='##user##';
$patterns[]='##approve##';
$patterns[]='##disapprove##';
$patterns[]='##comments##';
$patterns[] = '##timeadded##';
$patterns[] = '##timemodified##';
@ -322,6 +323,7 @@ class data_portfolio_caller extends portfolio_module_caller_base {
$replacement[] = '';
$replacement[] = '';
$replacement[] = '';
$replacement[] = '';
$replacement[] = userdate($record->timecreated);
$replacement[] = userdate($record->timemodified);

View File

@ -246,6 +246,7 @@ if ($mode != 'csstemplate' and $mode != 'jstemplate') {
echo '<option value="##edit##">' .get_string('edit', 'data'). ' - ##edit##</option>';
echo '<option value="##delete##">' .get_string('delete', 'data'). ' - ##delete##</option>';
echo '<option value="##approve##">' .get_string('approve', 'data'). ' - ##approve##</option>';
echo '<option value="##disapprove##">' .get_string('disapprove', 'data'). ' - ##disapprove##</option>';
if ($mode != 'rsstemplate') {
echo '<option value="##export##">' .get_string('export', 'data'). ' - ##export##</option>';
}

View File

@ -39,6 +39,7 @@
$page = optional_param('page', 0, PARAM_INT);
/// These can be added to perform an action on a record
$approve = optional_param('approve', 0, PARAM_INT); //approval recordid
$disapprove = optional_param('disapprove', 0, PARAM_INT); // disapproval recordid
$delete = optional_param('delete', 0, PARAM_INT); //delete recordid
$multidelete = optional_param_array('delcheck', null, PARAM_INT);
$serialdelete = optional_param('serialdelete', null, PARAM_RAW);
@ -453,19 +454,22 @@ if ($showactivity) {
$maxcount = 0;
} else {
/// Approve any requested records
// Approve or disapprove any requested records
$params = array(); // named params array
$approvecap = has_capability('mod/data:approve', $context);
if ($approve && confirm_sesskey() && $approvecap) {
if ($approverecord = $DB->get_record('data_records', array('id'=>$approve))) { // Need to check this is valid
if (($approve || $disapprove) && confirm_sesskey() && $approvecap) {
$newapproved = $approve ? 1 : 0;
$recordid = $newapproved ? $approve : $disapprove;
if ($approverecord = $DB->get_record('data_records', array('id' => $recordid))) { // Need to check this is valid
if ($approverecord->dataid == $data->id) { // Must be from this database
$newrecord = new stdClass();
$newrecord->id = $approverecord->id;
$newrecord->approved = 1;
$newrecord->approved = $newapproved;
$DB->update_record('data_records', $newrecord);
echo $OUTPUT->notification(get_string('recordapproved','data'), 'notifysuccess');
$msgkey = $newapproved ? 'recordapproved' : 'recorddisapproved';
echo $OUTPUT->notification(get_string($msgkey, 'data'), 'notifysuccess');
}
}
}

View File

@ -5,10 +5,11 @@ require_once("lib.php");
$eid = required_param('eid', PARAM_INT); // Entry ID
$newstate = optional_param('newstate', 1, PARAM_BOOL);
$mode = optional_param('mode', 'approval', PARAM_ALPHA);
$hook = optional_param('hook', 'ALL', PARAM_CLEAN);
$url = new moodle_url('/mod/glossary/approve.php', array('eid'=>$eid,'mode'=>$mode, 'hook'=>$hook));
$url = new moodle_url('/mod/glossary/approve.php', array('eid' => $eid, 'mode' => $mode, 'hook' => $hook, 'newstate' => $newstate));
$PAGE->set_url($url);
$entry = $DB->get_record('glossary_entries', array('id'=> $eid), '*', MUST_EXIST);
@ -21,10 +22,10 @@ require_login($course, false, $cm);
$context = context_module::instance($cm->id);
require_capability('mod/glossary:approve', $context);
if (!$entry->approved and confirm_sesskey()) {
if (($newstate != $entry->approved) && confirm_sesskey()) {
$newentry = new stdClass();
$newentry->id = $entry->id;
$newentry->approved = 1;
$newentry->approved = $newstate;
$newentry->timemodified = time(); // wee need this date here to speed up recent activity, TODO: use timestamp in approved field instead in 2.0
$DB->update_record("glossary_entries", $newentry);
@ -34,7 +35,8 @@ if (!$entry->approved and confirm_sesskey()) {
$completion->update_state($cm, COMPLETION_COMPLETE, $entry->userid);
}
add_to_log($course->id, "glossary", "approve entry", "showentry.php?id=$cm->id&amp;eid=$eid", "$eid", $cm->id);
$logaction = $newstate ? "approve entry" : "disapprove entry";
add_to_log($course->id, "glossary", $logaction, "showentry.php?id=$cm->id&amp;eid=$eid", "$eid", $cm->id);
}
redirect("view.php?id=$cm->id&amp;mode=$mode&amp;hook=$hook");

View File

@ -95,6 +95,7 @@ class restore_glossary_activity_task extends restore_activity_task {
$rules[] = new restore_log_rule('glossary', 'update entry', 'view.php?id={course_module}&mode=entry&hook={glossary_entry}', '{glossary_entry}');
$rules[] = new restore_log_rule('glossary', 'delete entry', 'view.php?id={course_module}&mode=entry&hook={glossary_entry}', '{glossary_entry}');
$rules[] = new restore_log_rule('glossary', 'approve entry', 'showentry.php?id={course_module}&eid={glossary_entry}', '{glossary_entry}');
$rules[] = new restore_log_rule('glossary', 'disapprove entry', 'showentry.php?id={course_module}&eid={glossary_entry}', '{glossary_entry}');
$rules[] = new restore_log_rule('glossary', 'view entry', 'showentry.php?eid={glossary_entry}', '{glossary_entry}');
return $rules;

View File

@ -37,5 +37,6 @@ $logs = array(
array('module'=>'glossary', 'action'=>'update category', 'mtable'=>'glossary', 'field'=>'name'),
array('module'=>'glossary', 'action'=>'delete category', 'mtable'=>'glossary', 'field'=>'name'),
array('module'=>'glossary', 'action'=>'approve entry', 'mtable'=>'glossary', 'field'=>'name'),
array('module'=>'glossary', 'action'=>'disapprove entry', 'mtable'=>'glossary', 'field'=>'name'),
array('module'=>'glossary', 'action'=>'view entry', 'mtable'=>'glossary_entries', 'field'=>'concept'),
);

View File

@ -108,6 +108,7 @@ $string['deletingnoneemptycategory'] = 'Deleting this category will not delete t
$string['descending'] = 'descending';
$string['destination'] = 'Destination of imported entries';
$string['destination_help'] = 'Entries can either be imported and added to the current glossary or to a new glossary, in which case a new glossary will be created based on information in the XML file.';
$string['disapprove'] = 'Disapprove';
$string['displayformat'] = 'Display format';
$string['displayformat_help'] = 'There are 7 display formats:
@ -173,7 +174,7 @@ $string['filtername'] = 'Glossary auto-linking';
$string['fullmatch'] = 'Match whole words only';
$string['fullmatch_help'] = 'This setting specifies whether only whole words will be linked, for example, a glossary entry named "construct" will not create a link inside the word "constructivism".';
$string['glossary:addinstance'] = 'Add a new glossary';
$string['glossary:approve'] = 'Approve unapproved entries';
$string['glossary:approve'] = 'Approve unapproved entries, or disapprove approved ones';
$string['glossary:comment'] = 'Create comments';
$string['glossary:export'] = 'Export entries';
$string['glossary:exportentry'] = 'Export single entry';

View File

@ -1238,6 +1238,15 @@ function glossary_print_entry_icons($course, $cm, $glossary, $entry, $mode='',$h
array('class' => 'glossary-hidden-note'));
}
if (has_capability('mod/glossary:approve', $context) && !$glossary->defaultapproval && $entry->approved) {
$output = true;
$return .= '<a class="action-icon" title="' . get_string('disapprove', 'glossary').
'" href="approve.php?newstate=0&amp;eid='.$entry->id.'&amp;mode='.$mode.
'&amp;hook='.urlencode($hook).'&amp;sesskey='.sesskey().
'"><img src="'.$OUTPUT->pix_url('t/block').'" class="smallicon" alt="'.
get_string('disapprove','glossary').$altsuffix.'" /></a>';
}
$iscurrentuser = ($entry->userid == $USER->id);
if (has_capability('mod/glossary:manageentries', $context) or (isloggedin() and has_capability('mod/glossary:write', $context) and $iscurrentuser)) {