From 8925d72709410339a7f634ae4a8c9e2661be3b3c Mon Sep 17 00:00:00 2001 From: NeoRazorX Date: Sun, 22 Nov 2020 12:49:28 +0100 Subject: [PATCH] - Email user is now required. - Hide company and warehouse filters on user list when there is only one element. --- Core/Controller/ListUser.php | 56 +++++++++++++++++++----------------- Core/XMLView/EditUser.xml | 2 +- 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/Core/Controller/ListUser.php b/Core/Controller/ListUser.php index 6c5b789814..692c098fd9 100644 --- a/Core/Controller/ListUser.php +++ b/Core/Controller/ListUser.php @@ -1,7 +1,7 @@ + * Copyright (C) 2017-2020 Carlos Garcia Gomez * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as @@ -43,50 +43,54 @@ public function getPageData() } /** - * - * @param string $name + * Load views */ - protected function createViewRoles($name = 'ListRole') + protected function createViews() { - $this->addView($name, 'Role', 'roles', 'fas fa-address-card'); - $this->addSearchFields($name, ['codrole', 'descripcion']); - $this->addOrderBy($name, ['descripcion'], 'description'); - $this->addOrderBy($name, ['codrole'], 'code'); + $this->createViewsUsers(); + $this->createViewsRoles(); } /** - * Load views + * + * @param string $viewName */ - protected function createViews() + protected function createViewsRoles(string $viewName = 'ListRole') { - $this->createViewUsers(); - $this->createViewRoles(); + $this->addView($viewName, 'Role', 'roles', 'fas fa-address-card'); + $this->addSearchFields($viewName, ['codrole', 'descripcion']); + $this->addOrderBy($viewName, ['descripcion'], 'description'); + $this->addOrderBy($viewName, ['codrole'], 'code'); } /** * - * @param string $name + * @param string $viewName */ - protected function createViewUsers($name = 'ListUser') + protected function createViewsUsers(string $viewName = 'ListUser') { - $this->addView($name, 'User', 'users', 'fas fa-users'); - $this->addSearchFields($name, ['nick', 'email']); - $this->addOrderBy($name, ['nick'], 'nick', 1); - $this->addOrderBy($name, ['email'], 'email'); - $this->addOrderBy($name, ['level'], 'level'); - $this->addOrderBy($name, ['lastactivity'], 'last-activity'); + $this->addView($viewName, 'User', 'users', 'fas fa-users'); + $this->addSearchFields($viewName, ['nick', 'email']); + $this->addOrderBy($viewName, ['nick'], 'nick', 1); + $this->addOrderBy($viewName, ['email'], 'email'); + $this->addOrderBy($viewName, ['level'], 'level'); + $this->addOrderBy($viewName, ['lastactivity'], 'last-activity'); /// filters $levels = $this->codeModel->all('users', 'level', 'level'); - $this->addFilterSelect($name, 'level', 'level', 'level', $levels); + $this->addFilterSelect($viewName, 'level', 'level', 'level', $levels); $languages = $this->codeModel->all('users', 'langcode', 'langcode'); - $this->addFilterSelect($name, 'langcode', 'language', 'langcode', $languages); - - $warehouses = $this->codeModel->all('almacenes', 'codalmacen', 'nombre'); - $this->addFilterSelect($name, 'codalmacen', 'warehouse', 'codalmacen', $warehouses); + $this->addFilterSelect($viewName, 'langcode', 'language', 'langcode', $languages); $companies = $this->codeModel->all('empresas', 'idempresa', 'nombrecorto'); - $this->addFilterSelect($name, 'idempresa', 'company', 'idempresa', $companies); + if (\count($companies) > 2) { + $this->addFilterSelect($viewName, 'idempresa', 'company', 'idempresa', $companies); + } + + $warehouses = $this->codeModel->all('almacenes', 'codalmacen', 'nombre'); + if (\count($warehouses) > 2) { + $this->addFilterSelect($viewName, 'codalmacen', 'warehouse', 'codalmacen', $warehouses); + } } } diff --git a/Core/XMLView/EditUser.xml b/Core/XMLView/EditUser.xml index 89f73783f0..0a21e02a19 100644 --- a/Core/XMLView/EditUser.xml +++ b/Core/XMLView/EditUser.xml @@ -26,7 +26,7 @@ - +