Commit 84712c37 authored by Robert Lyon's avatar Robert Lyon
Browse files

Bug 1826284: Allow the bulk export page to handle all export types



Also allow the selecting of specific users by select2 dropdown

behatnotneeded

Change-Id: Ib4cdaf6251cbbb69285406e7618fee84ba797136
Signed-off-by: default avatarRobert Lyon <robertl@catalyst.net.nz>
parent ff63091b
Loading
Loading
Loading
Loading
+19 −9
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@ define('INTERNAL', 1);
define('ADMIN', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');

define('TITLE', get_string('bulkexporttitle', 'admin'));
define('TITLE', get_string('bulkexporttitle1', 'admin'));

/**
 * Convert a 2D array to a CSV file. This follows the basic rules from http://en.wikipedia.org/wiki/Comma-separated_values
@@ -111,15 +111,13 @@ function bulkexport_submit(Pieform $form, $values) {
        }
    }

    if (empty($usernames) and !empty($values['authinstance'])) {
    if (empty($usernames) && !empty($values['authinstance'])) {
        // Export all users from the selected institution
        $rs = get_recordset_select('usr', 'authinstance = ? AND deleted = 0', array($values['authinstance']), '', 'username');
        while ($record = $rs->FetchRow()) {
            $usernames[] = $record['username'];
        }
        $usernames = get_column_sql("SELECT username FROM {usr} WHERE authinstance = ? AND deleted = 0 AND id != 0", array($values['authinstance']));
    }

    safe_require('export', 'leap');
    $exporttype = !empty($values['exporttype']) ? $values['exporttype'] : 'leap';
    safe_require('export', $exporttype);

    $listing = array();
    $files = array();
@@ -141,7 +139,12 @@ function bulkexport_submit(Pieform $form, $values) {
            continue; // Skip non-existent users
        }

        if ($exporttype == 'html') {
            $exporter = new PluginExportHtml($user, PluginExport::EXPORT_ALL_VIEWS_COLLECTIONS, PluginExport::EXPORT_ALL_ARTEFACTS);
        }
        else {
            $exporter = new PluginExportLeap($user, PluginExport::EXPORT_ALL_VIEWS_COLLECTIONS, PluginExport::EXPORT_ALL_ARTEFACTS);
        }
        try {
            $exporter->export();
            $zipfile = $exporter->export_compress();
@@ -205,6 +208,13 @@ $form = array(
    'jserrorcallback' => 'pmeter_error',
    'presubmitcallback' => 'pmeter_presubmit',
    'elements' => array(
        'exporttype' => array(
            'type' => 'select',
            'title' => get_string('chooseanexportformat', 'export'),
            'options' => array('leap' => 'Leap2A',
                               'html' => 'HTML'),
            'defaultvalue' => 'leap'
        ),
        'authinstance' => $authinstanceelement,
        'usernames' => array(
            'type' => 'textarea',
@@ -232,5 +242,5 @@ $form = pieform($form);

$smarty = smarty();
$smarty->assign('bulkexportform', $form);
$smarty->assign('bulkexportdescription', get_string('bulkexportdescription', 'admin'));
$smarty->assign('bulkexportdescription', get_string('bulkexportdescription1', 'admin'));
$smarty->display('admin/users/bulkexport.tpl');
+1 −3
Original line number Diff line number Diff line
@@ -464,9 +464,7 @@ class PluginExportHtml extends PluginExport {
                }
            }
        }
        function sort_by_title($a, $b) {
            return strnatcasecmp($a['title'], $b['title']);
        }

        foreach (array_keys($this->collections) as $id) {
            usort($list['collections'][$id]['views'], 'sort_by_title');
        }
+2 −2
Original line number Diff line number Diff line
@@ -1183,8 +1183,8 @@ $string['unsuspendinstitutiondescription_instadmin'] = 'People of suspended inst
$string['bulkexport'] = 'Export accounts';
$string['bulkexportempty'] = 'Nothing suitable to export. Please double-check the list of usernames.';
$string['bulkexportinstitution'] = 'The institution from which all members should be exported';
$string['bulkexporttitle'] = 'Export accounts to Leap2A files';
$string['bulkexportdescription'] = 'Choose an institution to export <b>OR</b> specify a list of usernames:';
$string['bulkexporttitle1'] = 'Bulk export accounts';
$string['bulkexportdescription1'] = 'Choose an export format and then either choose institution to export <b>OR</b> specify a list of usernames.';
$string['bulkexportusernames'] = 'Usernames to export';
$string['bulkexportusernamesdescription'] = 'A list of the accounts (one username per line) to be exported along with their data.';
$string['couldnotexportusers'] = 'The following account(s) could not be exported: %s';
+4 −0
Original line number Diff line number Diff line
@@ -5621,6 +5621,10 @@ function sort_menu_by_weight($a, $b) {
    return ($aweight < $bweight) ? -1 : 1;
}

function sort_by_title($a, $b) {
    return strnatcasecmp($a['title'], $b['title']);
}

/**
 * Disable elasticsearch triggers for site - useful for upgrades if we don't need to reindex the changes
 * This should be paired with create_elasticsearch_triggers(); - an example:
+20 −0
Original line number Diff line number Diff line
@@ -459,6 +459,26 @@ div.toolbarhtml {
    display: flex;
}

// Add space when there are 2 selects next to each other
.select {
    + .select {
        margin-left: 5px;
    }
    + .submit:not(.input-group-append) {
        margin-left: 5px;
    }
    #bulkexport & {
        + .select {
            margin-left: 0;
        }
    }
}

// Removes weird text node between buttons on admin/users/suspended.php
.pieform-fieldset.btn-group {
    font-size: 0;
}

.elasticsearch-filters {
    border-bottom: 1px solid $card-border-color;
    background-color: $card-header-bg;