From 4cac2470bb4d6c331b7e92c58e430f6b5bf28333 Mon Sep 17 00:00:00 2001 From: Adrian Greeve Date: Mon, 22 Dec 2014 11:49:02 +0800 Subject: [PATCH] MDL-48325 mod_data: Export to portfolio button uses capability. The Export to portfolio button now checks the mod/data:exportownentry capability to see if the export button should be shown. --- mod/data/view.php | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/mod/data/view.php b/mod/data/view.php index 5f2071ccb6e..6b867590025 100644 --- a/mod/data/view.php +++ b/mod/data/view.php @@ -820,14 +820,25 @@ if ($showactivity) { } echo html_writer::end_tag('form'); + // Check to see if we can export records to a portfolio. This is for exporting all records, not just the ones in the search. if ($mode == '' && !empty($CFG->enableportfolios) && !empty($records)) { - require_once($CFG->libdir . '/portfoliolib.php'); - $button = new portfolio_add_button(); - $button->set_callback_options('data_portfolio_caller', array('id' => $cm->id), 'mod_data'); - if (data_portfolio_caller::has_files($data)) { - $button->set_formats(array(PORTFOLIO_FORMAT_RICHHTML, PORTFOLIO_FORMAT_LEAP2A)); // no plain html for us + $canexport = false; + // Exportallentries and exportentry are basically the same capability. + if (has_capability('mod/data:exportallentries', $context) || has_capability('mod/data:exportentry', $context)) { + $canexport = true; + } else if (has_capability('mod/data:exportownentry', $context) && + $DB->record_exists('data_records', array('userid' => $USER->id))) { + $canexport = true; + } + if ($canexport) { + require_once($CFG->libdir . '/portfoliolib.php'); + $button = new portfolio_add_button(); + $button->set_callback_options('data_portfolio_caller', array('id' => $cm->id), 'mod_data'); + if (data_portfolio_caller::has_files($data)) { + $button->set_formats(array(PORTFOLIO_FORMAT_RICHHTML, PORTFOLIO_FORMAT_LEAP2A)); // No plain html for us. + } + echo $button->to_html(PORTFOLIO_ADD_FULL_FORM); } - echo $button->to_html(PORTFOLIO_ADD_FULL_FORM); } //Advanced search form doesn't make sense for single (redirects list view)