From 834686037c6e30f0ac59eccb1f316b6cbe85199d Mon Sep 17 00:00:00 2001 From: Adrian Greeve Date: Mon, 30 Jan 2012 15:52:20 +0800 Subject: [PATCH] MDL-25185 - data - Allowing data from the database to be exported according to group roles. --- mod/data/export.php | 6 +++++- mod/data/lib.php | 14 ++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/mod/data/export.php b/mod/data/export.php index e108b4d78e0..e865858c3ec 100644 --- a/mod/data/export.php +++ b/mod/data/export.php @@ -84,6 +84,8 @@ if($mform->is_cancelled()) { $PAGE->set_title($data->name); $PAGE->set_heading($course->fullname); echo $OUTPUT->header(); + $url = new moodle_url('/mod/data/export.php', array('d' => $d)); + groups_print_activity_menu($cm, $url); echo $OUTPUT->heading(format_string($data->name)); // these are for the tab display @@ -104,7 +106,9 @@ foreach ($formdata as $key => $value) { } } -$exportdata = data_get_exportdata($data->id, $fields, $selectedfields); +$currentgroup = groups_get_activity_group($cm); + +$exportdata = data_get_exportdata($data->id, $fields, $selectedfields, $currentgroup); $count = count($exportdata); switch ($formdata['exporttype']) { case 'csv': diff --git a/mod/data/lib.php b/mod/data/lib.php index 2bee85bf059..54072d2b334 100644 --- a/mod/data/lib.php +++ b/mod/data/lib.php @@ -2804,9 +2804,11 @@ function data_export_ods($export, $dataname, $count) { * @param int $dataid * @param array $fields * @param array $selectedfields + * @param int $currentgroup group ID of the current group. This is used for + * exporting data while maintaining group divisions. * @return array */ -function data_get_exportdata($dataid, $fields, $selectedfields) { +function data_get_exportdata($dataid, $fields, $selectedfields, $currentgroup=0) { global $DB; $exportdata = array(); @@ -2826,7 +2828,15 @@ function data_get_exportdata($dataid, $fields, $selectedfields) { $line = 1; foreach($datarecords as $record) { // get content indexed by fieldid - if( $content = $DB->get_records('data_content', array('recordid'=>$record->id), 'fieldid', 'fieldid, content, content1, content2, content3, content4') ) { + if ($currentgroup) { + $select = 'SELECT c.fieldid, c.content, c.content1, c.content2, c.content3, c.content4 FROM {data_content} c, {data_records} r WHERE c.recordid = ? AND r.id = c.recordid AND r.groupid = ?'; + $where = array($record->id, $currentgroup); + } else { + $select = 'SELECT fieldid, content, content1, content2, content3, content4 FROM {data_content} WHERE recordid = ?'; + $where = array($record->id); + } + + if( $content = $DB->get_records_sql($select, $where) ) { foreach($fields as $field) { $contents = ''; if(isset($content[$field->field->id])) {