Commit 3dd182b6 authored by Dmitrii Metelkin's avatar Dmitrii Metelkin Committed by Robert Lyon
Browse files

Bug #1595026: download CSV file with group settings



behatnotneeded

Change-Id: I7e914c1202e915b9bd1f47de9e4198ebc3346080
Signed-off-by: default avatarDmitrii Metelkin <dmitriim@catalyst-au.net>
parent 502a0b5d
......@@ -22,28 +22,8 @@ safe_require('artefact', 'internal');
ini_set('auto_detect_line_endings', 1);
$FORMAT = array();
$ALLOWEDKEYS = array(
'shortname',
'displayname',
'description',
'open',
'controlled',
'request',
'roles',
'public',
'submitpages',
'allowarchives',
'editroles',
'hidden',
'hidemembers',
'hidemembersfrommembers',
'invitefriends',
'suggestfriends',
);
if ($USER->get('admin')) {
$ALLOWEDKEYS[] = 'usersautoadded';
$ALLOWEDKEYS[] = 'quota';
}
$ALLOWEDKEYS = group_get_allowed_group_csv_keys();
$MANDATORYFIELDS = array(
'shortname',
'displayname',
......@@ -301,6 +281,10 @@ function uploadcsv_submit(Pieform $form, $values) {
$group->submittableto = $record[$formatkeylookup[$field]];
continue;
}
if ($field == 'quota') {
$group->quota = get_real_size($record[$formatkeylookup[$field]]);
continue;
}
$group->{$field} = $record[$formatkeylookup[$field]];
}
......
......@@ -312,6 +312,7 @@ $string['exportstatsascsv'] = 'Export statistics in CSV format';
$string['downloadstatsascsv'] = 'statistics in CSV format';
$string['nostats'] = 'No statistics available';
$string['site'] = 'Site';
$string['exportgroupscsv'] = 'Export groups in CSV format';
// Institution statistics
$string['statistics'] = 'Statistics';
......
......@@ -1592,6 +1592,7 @@ function group_format_editwindow($group) {
* Used by admin/groups/groups.php and admin/groups/groups.json.php for listing groups.
*/
function build_grouplist_html($query, $limit, $offset, &$count=null, $institution) {
global $USER;
$groups = search_group($query, $limit, $offset, 'all', '', $institution);
$count = $groups['count'];
......@@ -1621,6 +1622,27 @@ function build_grouplist_html($query, $limit, $offset, &$count=null, $institutio
$group->categorytitle = ($group->category) ? get_field('group_category', 'title', 'id', $group->category) : '';
}
$group->homepage_url = group_homepage_url($group);
$group->displayname = $group->name;
$group->submitpages = $group->submittableto;
$group->roles = $group->grouptype;
switch ($group->jointype) {
case 'open':
$group->open = 1;
$group->controlled = 0;
break;
case 'controlled':
$group->open = 0;
$group->controlled = 1;
break;
case 'approve':
default:
$group->open = 0;
$group->controlled = 0;
break;
}
$group->quota = display_size($group->quota);
}
$smarty = smarty_core();
......@@ -1646,6 +1668,10 @@ function build_grouplist_html($query, $limit, $offset, &$count=null, $institutio
$data['pagination'] = $pagination['html'];
$data['pagination_js'] = $pagination['javascript'];
$csvfields = group_get_allowed_group_csv_keys();
$USER->set_download_file(generate_csv($groups['data'], $csvfields), 'groups.csv', 'text/csv');
$data['csv'] = true;
return $data;
}
......@@ -2622,3 +2648,38 @@ function group_get_shortname_element($group_data) {
return $element;
}
/**
* Return a list of allowed group keys for csv import/export.
*
* @return array A list of keys.
*/
function group_get_allowed_group_csv_keys() {
global $USER;
$keys = array(
'shortname',
'displayname',
'description',
'open',
'controlled',
'request',
'roles',
'public',
'submitpages',
'allowarchives',
'editroles',
'hidden',
'hidemembers',
'hidemembersfrommembers',
'invitefriends',
'suggestfriends',
);
if ($USER->get('admin')) {
$keys[] = 'usersautoadded';
$keys[] = 'quota';
}
return $keys;
}
......@@ -863,7 +863,7 @@ class PluginSearchInternal extends PluginSearch {
$count = get_field_sql('SELECT COUNT(*) '.$sql, $values);
if ($count > 0) {
$sql = 'SELECT id, name, description, grouptype, jointype, request, public, ctime, mtime, category, urlid, shortname ' . $sql . ' ORDER BY name';
$sql = 'SELECT * ' . $sql . ' ORDER BY name';
$data = get_records_sql_array($sql, $values, $offset, $limit);
}
......
......@@ -21,6 +21,9 @@
{$results.tablerows|safe}
</tbody>
</table>
{if $results.csv}
<a href="{$WWWROOT}download.php" class="panel-footer"><span class="icon icon-table" role="presentation" aria-hidden="true"></span> {str tag=exportgroupscsv section=admin}</a>
{/if}
</div>
{$results.pagination|safe}
{include file="footer.tpl"}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment