Skip to content

Commit

Permalink
MDL-29069 Data / Glossary: allow disapproving entries
Browse files Browse the repository at this point in the history
  • Loading branch information
bostelm committed Sep 4, 2013
1 parent ee78814 commit d0372ed
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 14 deletions.
4 changes: 3 additions & 1 deletion mod/data/lang/en/data.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
$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['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['csvwithselecteddelimiter'] = '<acronym title="Comma Separated Values">CSV</acronym> text with selected delimiter:';
$string['data:addinstance'] = 'Add a new database'; $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:comment'] = 'Write comments';
$string['data:exportallentries'] = 'Export all database entries'; $string['data:exportallentries'] = 'Export all database entries';
$string['data:exportentry'] = 'Export a database entry'; $string['data:exportentry'] = 'Export a database entry';
Expand Down Expand Up @@ -110,6 +110,7 @@
$string['deletewarning'] = 'Are you sure you want to delete this preset?'; $string['deletewarning'] = 'Are you sure you want to delete this preset?';
$string['descending'] = 'Descending'; $string['descending'] = 'Descending';
$string['directorynotapreset'] = '{$a->directory} Not a preset: missing files: {$a->missing_files}'; $string['directorynotapreset'] = '{$a->directory} Not a preset: missing files: {$a->missing_files}';
$string['disapprove'] = 'Disapprove';
$string['download'] = 'Download'; $string['download'] = 'Download';
$string['edit'] = 'Edit'; $string['edit'] = 'Edit';
$string['editcomment'] = 'Edit comment'; $string['editcomment'] = 'Edit comment';
Expand Down Expand Up @@ -288,6 +289,7 @@
$string['radiobutton'] = 'Radio buttons'; $string['radiobutton'] = 'Radio buttons';
$string['recordapproved'] = 'Entry approved'; $string['recordapproved'] = 'Entry approved';
$string['recorddeleted'] = 'Entry deleted'; $string['recorddeleted'] = 'Entry deleted';
$string['recorddisapproved'] = 'Entry disapproved';
$string['recordsnotsaved'] = 'No entry was saved. Please check the format of the uploaded file.'; $string['recordsnotsaved'] = 'No entry was saved. Please check the format of the uploaded file.';
$string['recordssaved'] = 'entries saved'; $string['recordssaved'] = 'entries saved';
$string['requireapproval'] = 'Approval required'; $string['requireapproval'] = 'Approval required';
Expand Down
17 changes: 14 additions & 3 deletions mod/data/lib.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -518,12 +518,12 @@ function data_generate_default_template(&$data, $template, $recordid=0, $form=fa
); );
} }
if ($template == 'listtemplate') { 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->colspan = 2;
$cell->attributes['class'] = 'controls'; $cell->attributes['class'] = 'controls';
$table->data[] = new html_table_row(array($cell)); $table->data[] = new html_table_row(array($cell));
} else if ($template == 'singletemplate') { } 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->colspan = 2;
$cell->attributes['class'] = 'controls'; $cell->attributes['class'] = 'controls';
$table->data[] = new html_table_row(array($cell)); $table->data[] = new html_table_row(array($cell));
Expand Down Expand Up @@ -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)) { if (has_capability('mod/data:approve', $context) && ($data->approval) && (!$record->approved)) {
$approveurl = new moodle_url('/mod/data/view.php', $approveurl = new moodle_url('/mod/data/view.php',
array('d' => $data->id, 'approve' => $record->id, 'sesskey' => sesskey())); 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), $replacement[] = html_writer::tag('span', $OUTPUT->action_icon($approveurl, $approveicon),
array('class' => 'approve')); array('class' => 'approve'));
} else { } else {
$replacement[] = ''; $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##'; $patterns[]='##comments##';
if (($template == 'listtemplate') && ($data->comments)) { if (($template == 'listtemplate') && ($data->comments)) {


Expand Down
2 changes: 2 additions & 0 deletions mod/data/locallib.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ private function exportentry($record) {
$patterns[]='##moreurl##'; $patterns[]='##moreurl##';
$patterns[]='##user##'; $patterns[]='##user##';
$patterns[]='##approve##'; $patterns[]='##approve##';
$patterns[]='##disapprove##';
$patterns[]='##comments##'; $patterns[]='##comments##';
$patterns[] = '##timeadded##'; $patterns[] = '##timeadded##';
$patterns[] = '##timemodified##'; $patterns[] = '##timemodified##';
Expand All @@ -322,6 +323,7 @@ private function exportentry($record) {
$replacement[] = ''; $replacement[] = '';
$replacement[] = ''; $replacement[] = '';
$replacement[] = ''; $replacement[] = '';
$replacement[] = '';
$replacement[] = userdate($record->timecreated); $replacement[] = userdate($record->timecreated);
$replacement[] = userdate($record->timemodified); $replacement[] = userdate($record->timemodified);


Expand Down
1 change: 1 addition & 0 deletions mod/data/templates.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@
echo '<option value="##edit##">' .get_string('edit', 'data'). ' - ##edit##</option>'; echo '<option value="##edit##">' .get_string('edit', 'data'). ' - ##edit##</option>';
echo '<option value="##delete##">' .get_string('delete', 'data'). ' - ##delete##</option>'; echo '<option value="##delete##">' .get_string('delete', 'data'). ' - ##delete##</option>';
echo '<option value="##approve##">' .get_string('approve', 'data'). ' - ##approve##</option>'; echo '<option value="##approve##">' .get_string('approve', 'data'). ' - ##approve##</option>';
echo '<option value="##disapprove##">' .get_string('disapprove', 'data'). ' - ##disapprove##</option>';
if ($mode != 'rsstemplate') { if ($mode != 'rsstemplate') {
echo '<option value="##export##">' .get_string('export', 'data'). ' - ##export##</option>'; echo '<option value="##export##">' .get_string('export', 'data'). ' - ##export##</option>';
} }
Expand Down
14 changes: 9 additions & 5 deletions mod/data/view.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
$page = optional_param('page', 0, PARAM_INT); $page = optional_param('page', 0, PARAM_INT);
/// These can be added to perform an action on a record /// These can be added to perform an action on a record
$approve = optional_param('approve', 0, PARAM_INT); //approval recordid $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 $delete = optional_param('delete', 0, PARAM_INT); //delete recordid
$multidelete = optional_param_array('delcheck', null, PARAM_INT); $multidelete = optional_param_array('delcheck', null, PARAM_INT);
$serialdelete = optional_param('serialdelete', null, PARAM_RAW); $serialdelete = optional_param('serialdelete', null, PARAM_RAW);
Expand Down Expand Up @@ -453,19 +454,22 @@
$maxcount = 0; $maxcount = 0;


} else { } else {
/// Approve any requested records // Approve or disapprove any requested records
$params = array(); // named params array $params = array(); // named params array


$approvecap = has_capability('mod/data:approve', $context); $approvecap = has_capability('mod/data:approve', $context);


if ($approve && confirm_sesskey() && $approvecap) { if (($approve || $disapprove) && confirm_sesskey() && $approvecap) {
if ($approverecord = $DB->get_record('data_records', array('id'=>$approve))) { // Need to check this is valid $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 if ($approverecord->dataid == $data->id) { // Must be from this database
$newrecord = new stdClass(); $newrecord = new stdClass();
$newrecord->id = $approverecord->id; $newrecord->id = $approverecord->id;
$newrecord->approved = 1; $newrecord->approved = $newapproved;
$DB->update_record('data_records', $newrecord); $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');
} }
} }
} }
Expand Down
10 changes: 6 additions & 4 deletions mod/glossary/approve.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@


$eid = required_param('eid', PARAM_INT); // Entry ID $eid = required_param('eid', PARAM_INT); // Entry ID


$newstate = optional_param('newstate', 1, PARAM_BOOL);
$mode = optional_param('mode', 'approval', PARAM_ALPHA); $mode = optional_param('mode', 'approval', PARAM_ALPHA);
$hook = optional_param('hook', 'ALL', PARAM_CLEAN); $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); $PAGE->set_url($url);


$entry = $DB->get_record('glossary_entries', array('id'=> $eid), '*', MUST_EXIST); $entry = $DB->get_record('glossary_entries', array('id'=> $eid), '*', MUST_EXIST);
Expand All @@ -21,10 +22,10 @@
$context = context_module::instance($cm->id); $context = context_module::instance($cm->id);
require_capability('mod/glossary:approve', $context); require_capability('mod/glossary:approve', $context);


if (!$entry->approved and confirm_sesskey()) { if (($newstate != $entry->approved) && confirm_sesskey()) {
$newentry = new stdClass(); $newentry = new stdClass();
$newentry->id = $entry->id; $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 $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); $DB->update_record("glossary_entries", $newentry);


Expand All @@ -34,7 +35,8 @@
$completion->update_state($cm, COMPLETION_COMPLETE, $entry->userid); $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"); redirect("view.php?id=$cm->id&amp;mode=$mode&amp;hook=$hook");
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ static public function define_restore_log_rules() {
$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', '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', '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', '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}'); $rules[] = new restore_log_rule('glossary', 'view entry', 'showentry.php?eid={glossary_entry}', '{glossary_entry}');


return $rules; return $rules;
Expand Down
1 change: 1 addition & 0 deletions mod/glossary/db/log.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@
array('module'=>'glossary', 'action'=>'update category', 'mtable'=>'glossary', 'field'=>'name'), array('module'=>'glossary', 'action'=>'update category', 'mtable'=>'glossary', 'field'=>'name'),
array('module'=>'glossary', 'action'=>'delete 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'=>'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'), array('module'=>'glossary', 'action'=>'view entry', 'mtable'=>'glossary_entries', 'field'=>'concept'),
); );
3 changes: 2 additions & 1 deletion mod/glossary/lang/en/glossary.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
$string['descending'] = 'descending'; $string['descending'] = 'descending';
$string['destination'] = 'Destination of imported entries'; $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['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'] = 'Display format';
$string['displayformat_help'] = 'There are 7 display formats: $string['displayformat_help'] = 'There are 7 display formats:
Expand Down Expand Up @@ -173,7 +174,7 @@
$string['fullmatch'] = 'Match whole words only'; $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['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: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:comment'] = 'Create comments';
$string['glossary:export'] = 'Export entries'; $string['glossary:export'] = 'Export entries';
$string['glossary:exportentry'] = 'Export single entry'; $string['glossary:exportentry'] = 'Export single entry';
Expand Down
9 changes: 9 additions & 0 deletions mod/glossary/lib.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1238,6 +1238,15 @@ function glossary_print_entry_icons($course, $cm, $glossary, $entry, $mode='',$h
array('class' => 'glossary-hidden-note')); 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); $iscurrentuser = ($entry->userid == $USER->id);


if (has_capability('mod/glossary:manageentries', $context) or (isloggedin() and has_capability('mod/glossary:write', $context) and $iscurrentuser)) { if (has_capability('mod/glossary:manageentries', $context) or (isloggedin() and has_capability('mod/glossary:write', $context) and $iscurrentuser)) {
Expand Down

0 comments on commit d0372ed

Please sign in to comment.