<?php
/**
* This file is part of the Pimcore X Installation by
* ercas GmbH & CO. KG <https://www.ercasdieagentur.de>
*
* @license GPLv3
*/
namespace App\mvk\Auth\EventListener;
use App\Services\ContainerHelperService;
use App\Services\MailService;
use Pimcore\Event\Model\DataObjectEvent;
use Pimcore\Event\Model\ElementEventInterface;
use Pimcore\Model\DataObject\Agent;
class PostUpdateListener
{
protected const USER_CLASSES = ['Agent'];
private $containerHelperService;
private MailService $mailService;
public function __construct(ContainerHelperService $containerHelperService, MailService $mailService)
{
$this->containerHelperService = $containerHelperService;
$this->mailService = $mailService;
}
public function onPostUpdate(ElementEventInterface $e): void
{
if ($e instanceof DataObjectEvent) {
$user = $e->getObject();
if ($user instanceof Agent) {
if ($user->getPublished() == false) {
// user is unpublished - be sure all childs are unpublished too
$subAgents = $user->getSubAgent();
if (count($subAgents) > 0) {
foreach($subAgents as $subAgentObj) {
if ($subAgentObj->getPublished() == true) {
$subAgentObj->setPublished(false);
$subAgentObj->save();
}
}
}
}
}
}
}
private function supports($class)
{
if (in_array($class, self::USER_CLASSES)) {
return true;
}
return false;
}
}