From f8a5c98eb6e8650824510afd946b83d3ebcabe8a Mon Sep 17 00:00:00 2001 From: Jun Pataleta Date: Thu, 5 May 2016 10:26:27 +0800 Subject: [PATCH] MDL-54056 gradingform_guide: Conditionally render comments chooser Render the frequently-used comments only if there are defined frequently used comments --- grade/grading/form/guide/renderer.php | 38 +++++++++++++++------------ 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/grade/grading/form/guide/renderer.php b/grade/grading/form/guide/renderer.php index 928094ef17b..53ce81e410b 100644 --- a/grade/grading/form/guide/renderer.php +++ b/grade/grading/form/guide/renderer.php @@ -235,26 +235,30 @@ class gradingform_guide_renderer extends plugin_renderer_base { // Grading remark text area. $input = html_writer::tag('textarea', s($currentremark), $remarkparams); - // Frequently used comments chooser. - $chooserbuttonid = 'criteria-' . $criterion['id'] . '-commentchooser'; - $commentchooserparams = array('id' => $chooserbuttonid, 'class' => 'commentchooser'); - $commentchooser = html_writer::tag('button', get_string('insertcomment', 'gradingform_guide'), $commentchooserparams); + // Show the frequently-used comments chooser only if there are defined entries. + if (!empty($comments)) { + // Frequently used comments chooser. + $chooserbuttonid = 'criteria-' . $criterion['id'] . '-commentchooser'; + $commentchooserparams = array('id' => $chooserbuttonid, 'class' => 'commentchooser'); + $commentchooser = html_writer::tag('button', get_string('insertcomment', 'gradingform_guide'), + $commentchooserparams); - // Option items for the frequently used comments chooser dialog. - $commentoptions = array(); - foreach ($comments as $id => $comment) { - $commentoption = new stdClass(); - $commentoption->id = $id; - $commentoption->description = s($comment['description']); - $commentoptions[] = $commentoption; + // Option items for the frequently used comments chooser dialog. + $commentoptions = array(); + foreach ($comments as $id => $comment) { + $commentoption = new stdClass(); + $commentoption->id = $id; + $commentoption->description = s($comment['description']); + $commentoptions[] = $commentoption; + } + + // Include string for JS for the comment chooser title. + $PAGE->requires->string_for_js('insertcomment', 'gradingform_guide'); + // Include comment_chooser module. + $PAGE->requires->js_call_amd('gradingform_guide/comment_chooser', 'initialise', + array($criterion['id'], $chooserbuttonid, $remarkid, $commentoptions)); } - // Include string for JS for the comment chooser title. - $PAGE->requires->string_for_js('insertcomment', 'gradingform_guide'); - // Include comment_chooser module. - $PAGE->requires->js_call_amd('gradingform_guide/comment_chooser', 'initialise', - array($criterion['id'], $chooserbuttonid, $remarkid, $commentoptions)); - // Hidden marking guide remark label. $remarklabelparams = array( 'class' => 'hidden',