From d0372ed6f1a555e20cd9f37e89529f55c811f208 Mon Sep 17 00:00:00 2001 From: Henning Bostelmann Date: Thu, 8 Aug 2013 19:15:11 +0100 Subject: [PATCH] MDL-29069 Data / Glossary: allow disapproving entries --- mod/data/lang/en/data.php | 4 +++- mod/data/lib.php | 17 ++++++++++++++--- mod/data/locallib.php | 2 ++ mod/data/templates.php | 1 + mod/data/view.php | 14 +++++++++----- mod/glossary/approve.php | 10 ++++++---- .../restore_glossary_activity_task.class.php | 1 + mod/glossary/db/log.php | 1 + mod/glossary/lang/en/glossary.php | 3 ++- mod/glossary/lib.php | 9 +++++++++ 10 files changed, 48 insertions(+), 14 deletions(-) diff --git a/mod/data/lang/en/data.php b/mod/data/lang/en/data.php index 5841ddc7a05..b31c9feccd6 100644 --- a/mod/data/lang/en/data.php +++ b/mod/data/lang/en/data.php @@ -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'] = 'CSV 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'; diff --git a/mod/data/lib.php b/mod/data/lib.php index 8e108b9fc23..4d8c1d7fa1b 100644 --- a/mod/data/lib.php +++ b/mod/data/lib.php @@ -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)) { diff --git a/mod/data/locallib.php b/mod/data/locallib.php index 30dbcf64b2e..7410091455f 100644 --- a/mod/data/locallib.php +++ b/mod/data/locallib.php @@ -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); diff --git a/mod/data/templates.php b/mod/data/templates.php index 4a34fb51bb9..51add903e12 100644 --- a/mod/data/templates.php +++ b/mod/data/templates.php @@ -246,6 +246,7 @@ if ($mode != 'csstemplate' and $mode != 'jstemplate') { echo ''; echo ''; echo ''; + echo ''; if ($mode != 'rsstemplate') { echo ''; } diff --git a/mod/data/view.php b/mod/data/view.php index 7812c267e59..9dc92efbc07 100644 --- a/mod/data/view.php +++ b/mod/data/view.php @@ -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'); } } } diff --git a/mod/glossary/approve.php b/mod/glossary/approve.php index 4069376e742..73587405811 100644 --- a/mod/glossary/approve.php +++ b/mod/glossary/approve.php @@ -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&eid=$eid", "$eid", $cm->id); + $logaction = $newstate ? "approve entry" : "disapprove entry"; + add_to_log($course->id, "glossary", $logaction, "showentry.php?id=$cm->id&eid=$eid", "$eid", $cm->id); } redirect("view.php?id=$cm->id&mode=$mode&hook=$hook"); diff --git a/mod/glossary/backup/moodle2/restore_glossary_activity_task.class.php b/mod/glossary/backup/moodle2/restore_glossary_activity_task.class.php index fdb5cb87f6d..a2ca9261f2f 100644 --- a/mod/glossary/backup/moodle2/restore_glossary_activity_task.class.php +++ b/mod/glossary/backup/moodle2/restore_glossary_activity_task.class.php @@ -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; diff --git a/mod/glossary/db/log.php b/mod/glossary/db/log.php index 8f802599bdd..5b9874a4eea 100644 --- a/mod/glossary/db/log.php +++ b/mod/glossary/db/log.php @@ -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'), ); \ No newline at end of file diff --git a/mod/glossary/lang/en/glossary.php b/mod/glossary/lang/en/glossary.php index 80676451403..1bc2cc83bf6 100644 --- a/mod/glossary/lang/en/glossary.php +++ b/mod/glossary/lang/en/glossary.php @@ -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'; diff --git a/mod/glossary/lib.php b/mod/glossary/lib.php index 239aebb80d6..ba0ba23c997 100644 --- a/mod/glossary/lib.php +++ b/mod/glossary/lib.php @@ -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 .= ''.
+                   get_string('disapprove','glossary').$altsuffix.''; + } + $iscurrentuser = ($entry->userid == $USER->id); if (has_capability('mod/glossary:manageentries', $context) or (isloggedin() and has_capability('mod/glossary:write', $context) and $iscurrentuser)) {