-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIdentityGridTrait.php
More file actions
74 lines (62 loc) · 2.08 KB
/
Copy pathIdentityGridTrait.php
File metadata and controls
74 lines (62 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
declare(strict_types=1);
namespace ADT\FancyAdmin\UI\Components\Grids\Identity;
use ADT\Datagrid\Component\DataGrid;
use ADT\FancyAdmin\DI\Injects\IdentityQueryFactoryInject;
use ADT\FancyAdmin\DI\Injects\MailerInject;
use ADT\FancyAdmin\DI\Injects\SecurityUserInject;
use ADT\FancyAdmin\Model\Entities\Enums\AclResourceNameEnum;
use ADT\FancyAdmin\UI\Components\Grids\Traits\Editable\Editable;
use ADT\FancyAdmin\UI\Components\Grids\Traits\IdentityData;
use ADT\FancyAdmin\UI\Components\Grids\Traits\ResetPassword\ResetPassword;
use ADT\FancyAdmin\UI\Components\Grids\Traits\SignInAsIdentity\SignInAsIdentity;
use App\Model\Entities\Identity;
use App\Model\Queries\Factories\IdentityQueryFactory;
use Exception;
use ReflectionException;
trait IdentityGridTrait
{
use ResetPassword;
use Editable;
use SignInAsIdentity;
use IdentityData;
use MailerInject;
use SecurityUserInject;
use IdentityQueryFactoryInject;
protected AclResourceNameEnum $aclResource = AclResourceNameEnum::BACKOFFICE_IDENTITIES;
public function initGrid(DataGrid $grid): void
{
$grid->addFilterText('search', '', ['firstName', 'lastName', 'email', 'phoneNumber']);
$this->addIdentityData($grid);
$grid->addAction('logout', 'Anonymizovat')
->setRenderer(function (Identity $identity) {
echo '<a href="' . $this->link('anonymize!', $identity->getId()) . '">
<span class="fa fa-face-disguise"></span>
Anonymizovat
</a>'; // TODO trnslate
});
}
protected function getQueryObjectFactoryClass(): string
{
return IdentityQueryFactory::class;
}
/**
* @throws ReflectionException
* @throws Exception
*/
public function handleAnonymize(int $identityId): void
{
/** @var Identity $identity */
if (!$identity = $this->createQueryObject()->byId($identityId)->fetchOneOrNull()) {
$this->error();
}
$identity->setLastName(mb_substr($identity->getLastName(), 0, 1) . '.');
$identity->setEmail(null);
$identity->setPhoneNumber(null);
$identity->setIsActive(false);
foreach ($identity->getProfiles() as $_profile) {
$_profile->setIsActive(false);
}
$this->_em->flush();
}
}