src/EventListener/NotificationCounterEventListener.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use App\Services\NotificationCounterService;
  4. use Pimcore\Event\Model\DataObjectEvent;
  5. use Pimcore\Event\Model\ElementEventInterface;
  6. use Pimcore\Model\WebsiteSetting;
  7. class NotificationCounterEventListener
  8. {
  9.     public function onPostAdd(ElementEventInterface $e)
  10.     {
  11.         if (
  12.             $e instanceof DataObjectEvent &&
  13.             method_exists($e->getObject(), 'getClassName') &&
  14.             (
  15.                 $e->getObject() instanceof \Pimcore\Model\DataObject\Procurement ||
  16.                 $e->getObject() instanceof \Pimcore\Model\DataObject\IncomingMail ||
  17.                 $e->getObject() instanceof \Pimcore\Model\DataObject\OutgoingMail
  18.             )
  19.         ) {
  20.             $object $e->getObject();
  21.             $object->setNotificationCounterNotificationCounterService::getMaximumNotificationPerDay() );
  22.             $object->save();
  23.         }
  24.     }
  25. }