bundles/Jabber/GenericBundle/EventListener/Event.php line 13

Open in your IDE?
  1. <?php 
  2. namespace Jabber\GenericBundle\EventListener;
  3. use Pimcore\Event\Model\ElementEventInterface;
  4. use Pimcore\Event\Model\DataObjectEvent;
  5. use Pimcore\Model\Asset;
  6. use Pimcore\Model\DataObject\Photoshoot;
  7. class Event {
  8.     public function onPreAdd (ElementEventInterface $e) {
  9.         if (!$e->hasArgument('isAutoSave')) {
  10.             if ($e instanceof DataObjectEvent) {
  11.                 // do something with the object
  12.                 $dataObject $e->getObject();
  13.                 if ($dataObject instanceof Photoshoot) {
  14.                     if (empty($dataObject->getAccessKey())) {
  15.                         $dataObject->setAccessKey(implode(''str_split(substr(strtolower(md5(microtime().rand(10009999))), 030), 6)));
  16.                     }
  17.                 }
  18.             }
  19.         }
  20.     }
  21.     public function onPreDelete(ElementEventInterface $e) {
  22.         if ($e instanceof DataObjectEvent) {
  23.             $eventObject $e->getObject();
  24.             if ($eventObject instanceof Photoshoot) {
  25.                 $assetPath $eventObject->getDirectories();
  26.                 foreach ($assetPath as $path) {
  27.                     $assets Asset::getById($path->getElementId());
  28.                     $children $assets->getChildren();
  29.                     if (count($children) > 0) {
  30.                         throw new \Exception("The event has assets stored against it. Cannot be deleted.");
  31.                     } else {
  32.                         $assets->delete();
  33.                     }
  34.                 }
  35.             }
  36.         }
  37.     }
  38. }