<?php
namespace App\EventListener;
use App\Services\NotificationCounterService;
use Pimcore\Event\Model\DataObjectEvent;
use Pimcore\Event\Model\ElementEventInterface;
use Pimcore\Model\WebsiteSetting;
class NotificationCounterEventListener
{
public function onPostAdd(ElementEventInterface $e)
{
if (
$e instanceof DataObjectEvent &&
method_exists($e->getObject(), 'getClassName') &&
(
$e->getObject() instanceof \Pimcore\Model\DataObject\Procurement ||
$e->getObject() instanceof \Pimcore\Model\DataObject\IncomingMail ||
$e->getObject() instanceof \Pimcore\Model\DataObject\OutgoingMail
)
) {
$object = $e->getObject();
$object->setNotificationCounter( NotificationCounterService::getMaximumNotificationPerDay() );
$object->save();
}
}
}