onAnchor[] = function () { if ($this->_securityUser->isAllowed(AclResourceNameEnum::BACKOFFICE_IDENTITIES_ANONYMIZE)) { $this['grid']->addAction('anonymize', 'Anonymizovat') ->setRenderer(function (Identity $identity) { echo ' ' . $this->_translator->translate('fcadmin.grids.user.actions.anonymize') . ' '; }); } }; } public function handleAnonymize(int $identityId): void { if (!$this->_securityUser->isAllowed(AclResourceNameEnum::BACKOFFICE_IDENTITIES_ANONYMIZE)) { $this->getPresenter()->error(); } /** @var Identity $identity */ if (!$identity = $this->createQueryObject()->byId($identityId)->fetchOneOrNull()) { $this->getPresenter()->error(); } $identity->setAnonymizedAt(new \DateTimeImmutable()); $identity->setAnonymizedBy($this->_securityUser->getIdentity()); $identity->setLastName(mb_substr($identity->getLastName(), 0, 1) . '.'); $identity->setEmail(null); $identity->setPhoneNumber(null); $identity->setUsername(null); $identity->setPassword(null); $identity->setIsActive(false); foreach ($identity->getProfiles() as $_profile) { $_profile->setIsActive(false); } $this->_em->flush(); } }