Revize 2190aaa4
Přidáno uživatelem Filip Jani před téměř 6 roky(ů)
app/AdminModule/component/User/UserGrid.php | ||
---|---|---|
4 | 4 |
namespace App\AdminModule\Components; |
5 | 5 |
|
6 | 6 |
|
7 |
use App\Model\Repository\BookRepository; |
|
8 |
use App\Model\Repository\RoleRepository; |
|
7 | 9 |
use App\Model\Repository\UserRepository; |
10 |
use App\Model\Repository\UserRoleRepository; |
|
8 | 11 |
use App\Utils\DataGrid\DataGrid; |
12 |
use Nette\Database\Table\ActiveRow; |
|
13 |
use Nette\Database\Table\Selection; |
|
9 | 14 |
use Ublaboo\DataGrid\Exception\DataGridException; |
10 | 15 |
|
11 | 16 |
class UserGrid extends DataGrid |
... | ... | |
14 | 19 |
* @var UserRepository |
15 | 20 |
*/ |
16 | 21 |
private $userRepository; |
22 |
/** |
|
23 |
* @var RoleRepository |
|
24 |
*/ |
|
25 |
private $roleRepository; |
|
17 | 26 |
|
18 |
public function __construct(UserRepository $userRepository) |
|
27 |
public function __construct(UserRepository $userRepository, |
|
28 |
RoleRepository $roleRepository) |
|
19 | 29 |
{ |
20 | 30 |
$this->userRepository = $userRepository; |
31 |
$this->roleRepository = $roleRepository; |
|
21 | 32 |
|
22 | 33 |
parent::__construct(); |
23 | 34 |
} |
... | ... | |
46 | 57 |
$this->addColumnNumber(UserRepository::COLUMN_ID, 'ID')->setDefaultHide(TRUE); |
47 | 58 |
$this->addColumnText(UserRepository::COLUMN_USERNAME, 'Uživatel'); |
48 | 59 |
$this->addColumnText(UserRepository::COLUMN_LOGIN, 'Login'); |
60 |
$this->addColumnText(RoleRepository::COLUMN_NAME, 'Role') |
|
61 |
->setRenderer(function (ActiveRow $activeRow) |
|
62 |
{ |
|
63 |
try |
|
64 |
{ |
|
65 |
$userRoleRow = $activeRow->related(UserRoleRepository::TABLE_NAME)->fetch(); |
|
66 |
$roleRow = $userRoleRow->ref(RoleRepository::TABLE_NAME); |
|
67 |
|
|
68 |
return $roleRow->{RoleRepository::COLUMN_NAME}; |
|
69 |
|
|
70 |
} catch (\Exception $ex) |
|
71 |
{ |
|
72 |
\Tracy\Debugger::log($ex->getMessage(), 'user-grid'); |
|
73 |
return "not found"; |
|
74 |
} |
|
75 |
}); |
|
49 | 76 |
$this->addColumnText(UserRepository::COLUMN_EMAIL, 'Email'); |
50 | 77 |
|
51 | 78 |
// Definice filtrů |
52 | 79 |
$this->addFilterText(UserRepository::COLUMN_USERNAME, 'Uživatel'); |
53 | 80 |
$this->addFilterText(UserRepository::COLUMN_LOGIN, 'Login'); |
81 |
$this->addFilterSelect(RoleRepository::COLUMN_NAME, 'Role', ['' => 'all'] + $this->roleRepository->getRolesForSelect()) |
|
82 |
->setCondition(function (Selection $selection, $value) |
|
83 |
{ |
|
84 |
$selection->where(':role.role_id', $value); |
|
85 |
}); |
|
54 | 86 |
$this->addFilterText(UserRepository::COLUMN_EMAIL, 'Email'); |
55 | 87 |
|
56 | 88 |
// Akce |
Také k dispozici: Unified diff
Re #7607 vyhledávání pouze pro přihlášené, upravení menu