mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
a7c0797a9d
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/branches/2.4@98736 467b73ca-7a2a-4603-9d3b-597d59a354a9
68 lines
1.7 KiB
PHP
68 lines
1.7 KiB
PHP
<?php
|
|
/**
|
|
* Imports {@link Group} records by CSV upload, as defined in
|
|
* {@link GroupCsvBulkLoader}.
|
|
*
|
|
* @package cms
|
|
* @subpackage batchactions
|
|
*/
|
|
class GroupImportForm extends Form {
|
|
|
|
/**
|
|
* @var Group Optional group relation
|
|
*/
|
|
protected $group;
|
|
|
|
function __construct($controller, $name, $fields = null, $actions = null, $validator = null) {
|
|
if(!$fields) {
|
|
$fields = new FieldSet(
|
|
$fileField = new FileField(
|
|
'CsvFile',
|
|
_t(
|
|
'SecurityAdmin_MemberImportForm.FileFieldLabel',
|
|
'CSV File <small>(Allowed extensions: *.csv)</small>'
|
|
)
|
|
)
|
|
);
|
|
$fileField->setAllowedExtensions(array('csv'));
|
|
}
|
|
|
|
if(!$actions) $actions = new FieldSet(
|
|
new FormAction('doImport', _t('SecurityAdmin_MemberImportForm.BtnImport', 'Import'))
|
|
);
|
|
|
|
if(!$validator) $validator = new RequiredFields('CsvFile');
|
|
|
|
|
|
parent::__construct($controller, $name, $fields, $actions, $validator);
|
|
}
|
|
|
|
function doImport($data, $form) {
|
|
$loader = new GroupCsvBulkLoader();
|
|
|
|
// load file
|
|
$result = $loader->load($data['CsvFile']['tmp_name']);
|
|
|
|
// result message
|
|
$msgArr = array();
|
|
if($result->CreatedCount()) $msgArr[] = sprintf(
|
|
_t('GroupImportForm.ResultCreated', 'Created %d groups'),
|
|
$result->CreatedCount()
|
|
);
|
|
if($result->UpdatedCount()) $msgArr[] = sprintf(
|
|
_t('GroupImportForm.ResultUpdated', 'Updated %d groups'),
|
|
$result->UpdatedCount()
|
|
);
|
|
if($result->DeletedCount()) $msgArr[] = sprintf(
|
|
_t('GroupImportForm.ResultDeleted', 'Deleted %d groups'),
|
|
$result->DeletedCount()
|
|
);
|
|
$msg = ($msgArr) ? implode(',', $msgArr) : _t('MemberImportForm.ResultNone', 'No changes');
|
|
|
|
$this->sessionMessage($msg, 'good');
|
|
|
|
Director::redirectBack();
|
|
}
|
|
|
|
}
|
|
?>
|