diff --git a/classes/report_table.php b/classes/report_table.php index 5267e55..92b577e 100644 --- a/classes/report_table.php +++ b/classes/report_table.php @@ -60,22 +60,34 @@ class report_table extends \table_sql { * @param int $customcertid * @param \stdClass $cm the course module * @param bool $groupmode are we in group mode? + * @param string|null $download The file type, null if we are not downloading */ - public function __construct($customcertid, $cm, $groupmode) { + public function __construct($customcertid, $cm, $groupmode, $download = null) { parent::__construct('mod_customcert_report_table'); - $this->define_columns(array( + $columns = array( 'fullname', 'timecreated', - 'code', - 'download' - )); - $this->define_headers(array( + 'code' + ); + $headers = array( get_string('fullname'), get_string('receiveddate', 'customcert'), - get_string('code', 'customcert'), - get_string('file') - )); + get_string('code', 'customcert') + ); + + // Check if we were passed a filename, which means we want to download it. + if ($download) { + $this->is_downloading($download, 'customcert-report'); + } + + if (!$this->is_downloading()) { + $columns[] = 'download'; + $headers[] = get_string('file'); + } + + $this->define_columns($columns); + $this->define_headers($headers); $this->collapsible(false); $this->sortable(true); $this->no_sorting('code'); diff --git a/report.php b/report.php index a4f29e8..dc75753 100644 --- a/report.php +++ b/report.php @@ -25,7 +25,7 @@ require_once('../../config.php'); $id = required_param('id', PARAM_INT); -$download = optional_param('download', '', PARAM_ALPHA); +$download = optional_param('download', null, PARAM_ALPHA); $downloadcert = optional_param('downloadcert', '', PARAM_BOOL); if ($downloadcert) { $userid = required_param('userid', PARAM_INT); @@ -59,10 +59,10 @@ if ($groupmode = groups_get_activity_groupmode($cm)) { groups_get_activity_group($cm, true); } -$table = new \mod_customcert\report_table($customcert->id, $cm, $groupmode); +$table = new \mod_customcert\report_table($customcert->id, $cm, $groupmode, $download); $table->define_baseurl($pageurl); -if ($table->is_downloading($download, 'customcert-report')) { +if ($table->is_downloading()) { $table->download(); exit(); }