mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
MDL-25185 - data - Allowing data from the database to be exported according to group roles.
This commit is contained in:
parent
baa5cd8240
commit
834686037c
2 changed files with 17 additions and 3 deletions
|
@ -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':
|
||||
|
|
|
@ -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])) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue