Skip to content
Snippets Groups Projects
Commit 670d79b4 authored by Dorian Merz's avatar Dorian Merz
Browse files

Merge branch 'instance/fid' into instance/fid_bbi

parents 1ccf4ef4 139f096e
No related merge requests found
...@@ -23,4 +23,7 @@ overview_fields[] = 'Permissions' ...@@ -23,4 +23,7 @@ overview_fields[] = 'Permissions'
; List of all available user permissions ; List of all available user permissions
permission_options[] = 'basic_access' permission_options[] = 'basic_access'
permission_options[] = 'limited_access' permission_options[] = 'limited_access'
permission_options[] = 'full_access' permission_options[] = 'full_access'
\ No newline at end of file
; file prefix for CSV export
user_list_export_file_prefix = 'export'
\ No newline at end of file
...@@ -349,7 +349,17 @@ $config = [ ...@@ -349,7 +349,17 @@ $config = [
], ],
], ],
], ],
'edit' => [ 'exportList' => [
'type' => 'literal',
'options' => [
'route' => '/exportList',
'defaults' => [
'controller' => UserController::class,
'action' => 'exportList',
],
],
],
'edit' => [
'type' => 'Zend\Router\Http\Segment', 'type' => 'Zend\Router\Http\Segment',
'options' => [ 'options' => [
'route' => '/edit/[:userid]', 'route' => '/edit/[:userid]',
......
...@@ -51,7 +51,7 @@ return [ ...@@ -51,7 +51,7 @@ return [
'username_confirmation' => [ 'username_confirmation' => [
'spec' => [ 'spec' => [
'name' => 'username_confirmation', 'name' => 'username_confirmation',
'type' => Text::class, 'type' => Email::class,
'options' => [ 'options' => [
'label' => 'label_username_confirmation', 'label' => 'label_username_confirmation',
], ],
......
...@@ -42,6 +42,7 @@ use Zend\Http\Response; ...@@ -42,6 +42,7 @@ use Zend\Http\Response;
use Zend\Mvc\Plugin\FlashMessenger\FlashMessenger; use Zend\Mvc\Plugin\FlashMessenger\FlashMessenger;
use Zend\ServiceManager\ServiceLocatorInterface; use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\View\Model\ViewModel; use Zend\View\Model\ViewModel;
use Zend\Http\PhpEnvironment\Response as HttpResponse;
class UserController extends AbstractBase class UserController extends AbstractBase
{ {
...@@ -744,4 +745,44 @@ class UserController extends AbstractBase ...@@ -744,4 +745,44 @@ class UserController extends AbstractBase
return false; return false;
} }
/**
* @return HttpResponse
* @throws ClientException
* @throws UserNotAuthorizedException
*/
public function exportListAction()
{
$userList = $this->client->requestUserList();
$fields = $this->config['Admin']['export_fields'] ?? null;
if (empty($fields)) {
$fields = current($userList)->getFieldList();
}
return $this->createExportFile(
$userList,
$fields
);
}
protected function createExportFile($userList, $fields=null)
{
$response = new HttpResponse();
$prefix = $this->config['Admin']['user_list_export_file_prefix'] ?? 'export';
$response->getHeaders()->addHeaders(
[
'Content-type' => 'text/plain',
'Content-Disposition' => 'attachment; filename="'.$prefix.'_'.date('Ymd_His').'.csv"'
]
);
$output = implode("\t",$fields)."\n";
foreach ($userList as $user) {
// we need to load the actual user object since some
// properties are missing from the overview list
$user = $this->client->requestUserDetails($user->id);
$output .= $user->export($fields)."\n";
}
$response->setContent($output);
return $response;
}
} }
...@@ -212,4 +212,9 @@ class Address ...@@ -212,4 +212,9 @@ class Address
{ {
$this->country = $country; $this->country = $country;
} }
public function __toString()
{
return $this->id.': '. $this->line1.' '.$this->line2.'; '.$this->zip.' '.$this->city.'; '.$this->country;
}
} }
...@@ -198,4 +198,9 @@ class Order ...@@ -198,4 +198,9 @@ class Order
{ {
$this->createdAt = $createdAt; $this->createdAt = $createdAt;
} }
public function __toString()
{
return $this->getLabel();
}
} }
\ No newline at end of file
...@@ -494,4 +494,45 @@ class User ...@@ -494,4 +494,45 @@ class User
public function getLiberoId () : string { public function getLiberoId () : string {
return 'FID'.str_pad($this->getId(),10,"0",STR_PAD_LEFT); return 'FID'.str_pad($this->getId(),10,"0",STR_PAD_LEFT);
} }
public function getFieldList()
{
$fields = [];
foreach ($this as $property => $value) {
if ($property === 'password') continue;
$fields[] = $property;
}
return $fields;
}
public function export($fields,$delimiter="\t") {
$output = '';
foreach ($fields as $property) {
if ($property === 'password') continue;
if ($property === 'permissions') {
$value = [];
$permissions = $this->getPermissions();
foreach ($permissions as $key => $perm) {
$value[] = $key.' ('.$perm.')';
}
} else {
$value = $this->{$property} ?? '';
if ($property === 'data' && is_array($value))
{
array_walk(
$value,
function(&$data,$key) {
$data = $key.': '.($data ? 'yes': 'no');
}
);
}
}
if (is_array($value)) {
$value = implode(', ', $value);
}
$output .= $value . $delimiter;
}
return rtrim($output,$delimiter);
}
} }
...@@ -115,6 +115,7 @@ user_edit_not_allowed = "Sie haben keine Berechtigung Nutzer %%userid%% zu editi ...@@ -115,6 +115,7 @@ user_edit_not_allowed = "Sie haben keine Berechtigung Nutzer %%userid%% zu editi
user_read_error = "Fehler beim Lesen der Daten von Nutzer %%userid%%" user_read_error = "Fehler beim Lesen der Daten von Nutzer %%userid%%"
read_user_list_not_allowed = "Sie haben keine Berechtigung die Nutzerliste einzusehen" read_user_list_not_allowed = "Sie haben keine Berechtigung die Nutzerliste einzusehen"
read_user_list_error = "Fehler beim Lesen der Nutzerliste" read_user_list_error = "Fehler beim Lesen der Nutzerliste"
user_list_export = "CSV-Export"
read_order_list_not_allowed = "Sie haben keine Berechtigung die Bestellliste einzusehen" read_order_list_not_allowed = "Sie haben keine Berechtigung die Bestellliste einzusehen"
user_edit_form_title = "Nutzerdaten ändern für <em>%%username%%</em> (ID %%userid%%)" user_edit_form_title = "Nutzerdaten ändern für <em>%%username%%</em> (ID %%userid%%)"
......
...@@ -113,6 +113,7 @@ user_edit_not_allowed = "You are not entitled to edit user %%userid%%" ...@@ -113,6 +113,7 @@ user_edit_not_allowed = "You are not entitled to edit user %%userid%%"
user_read_error = "Error reading data of user %%userid%%" user_read_error = "Error reading data of user %%userid%%"
read_user_list_not_allowed = "You are not entitled to read the user list" read_user_list_not_allowed = "You are not entitled to read the user list"
read_user_list_error = "Error reading user list" read_user_list_error = "Error reading user list"
user_list_export = "CSV-Export"
read_order_list_not_allowed = "You are not entitled to read the order list" read_order_list_not_allowed = "You are not entitled to read the order list"
user_edit_form_title = "Edit user data of <em>%%username%%</em> (ID %%userid%%)" user_edit_form_title = "Edit user data of <em>%%username%%</em> (ID %%userid%%)"
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
<tr><td><a href="<?=$this->url('fid/admin/edit',['userid' => $id])?>" title="<?=$tooltip?>"><i class="fa fa-pencil-square-o"></i><span class="sr-only"><?=$tooltip?></span></a></td><th><?=$id?></th><?= $this->render('fid/admin/list-entry',['user' => $user,'fields'=>$fields, 'config' => $config]) ?></tr> <tr><td><a href="<?=$this->url('fid/admin/edit',['userid' => $id])?>" title="<?=$tooltip?>"><i class="fa fa-pencil-square-o"></i><span class="sr-only"><?=$tooltip?></span></a></td><th><?=$id?></th><?= $this->render('fid/admin/list-entry',['user' => $user,'fields'=>$fields, 'config' => $config]) ?></tr>
<?php endforeach; ?> <?php endforeach; ?>
</table> </table>
<a href="<?=$this->url('fid/admin/exportList')?>" class="btn btn-primary" target="_blank"><i class="fa fa-download"></i> <?=$this->translate('fid::user_list_export')?></a>
<?php else: ?> <?php else: ?>
<?= $this->translate('fid::user_list_empty') ?> <?= $this->translate('fid::user_list_empty') ?>
<?php endif; ?> <?php endif; ?>
......
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