Skip to content
Browse files

MDL-25185 - data - Allowing data from the database to be exported acc…

…ording to group roles.
  • Loading branch information...
1 parent a1063d9 commit 17793014241f1ea53e7e3f54b695eac0c40d100f @abgreeve abgreeve committed Jan 30, 2012
Showing with 17 additions and 3 deletions.
  1. +5 −1 mod/data/export.php
  2. +12 −2 mod/data/lib.php
View
6 mod/data/export.php
@@ -84,6 +84,8 @@
$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 @@
}
}
-$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':
View
14 mod/data/lib.php
@@ -2803,9 +2803,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();
@@ -2825,7 +2827,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])) {

0 comments on commit 1779301

Please sign in to comment.
Something went wrong with that request. Please try again.