Toggle Sale activity

@param SaleToggleActivityEvent $event
@param $eventName
@param EventDispatcherInterface $dispatcher
@throws \Propel\Runtime\Exception\PropelException
512993
public function toggleActivity(SaleToggleActivityEvent $event, $eventName, EventDispatcherInterface $dispatcher)
    {
        $sale = $event->getSale();

        $con = Propel::getWriteConnection(SaleTableMap::DATABASE_NAME);

        $con->beginTransaction();

        try {
            $sale
            ->setDispatcher($dispatcher)
            ->setActive(!$sale->getActive())
            ->save($con);

            // Update related products sale status
            $dispatcher->dispatch(
                TheliaEvents::UPDATE_PRODUCT_SALE_STATUS,
                new ProductSaleStatusUpdateEvent($sale)
            );

            $event->setSale($sale);

            $con->commit();
        } catch (PropelException $e) {
            $con->rollback();
            throw $e;
        }
    }
1203321
public function deleteTemplateFeature(TemplateDeleteFeatureEvent $event, $eventName, EventDispatcherInterface $dispatcher)
    {
        // Detete the removed feature in all products which are using this template
        $products = ProductQuery::create()
            ->filterByTemplateId($event->getTemplate()->getId())
            ->find()
        ;
        
        foreach ($products as $product) {
            $dispatcher->dispatch(
                TheliaEvents::PRODUCT_FEATURE_DELETE_VALUE,
                new FeatureProductDeleteEvent($product->getId(), $event->getFeatureId())
            );
        }
    }
758529
public function updateCondition(CouponCreateOrUpdateEvent $event, $eventName, EventDispatcherInterface $dispatcher)
    {
        $modelCoupon = $event->getCouponModel();

        $this->createOrUpdateCondition($modelCoupon, $event, $dispatcher);
    }
467268
public function consume(CouponConsumeEvent $event, $eventName, EventDispatcherInterface $dispatcher)
    {
        $totalDiscount = 0;
        $isValid = false;

        /** @var CouponInterface $coupon */
        $coupon = $this->couponFactory->buildCouponFromCode($event->getCode());

        if ($coupon) {
            $isValid = $coupon->isMatching();

            if ($isValid) {
                $this->couponManager->pushCouponInSession($event->getCode());
                $totalDiscount = $this->couponManager->getDiscount();

                $this->getSession()
                    ->getSessionCart($dispatcher)
                    ->setDiscount($totalDiscount)
                    ->save();

                $this->getSession()
                    ->getOrder()
                    ->setDiscount($totalDiscount)
                ;
            }
        }

        $event->setIsValid($isValid);
        $event->setDiscount($totalDiscount);
    }
915361
public function dispatch($event/*, string $eventName = null*/)
    {
        $eventName = 1 < \func_num_args() ? \func_get_arg(1) : null;

        if (\is_object($event)) {
            $eventName = $eventName ?? \get_class($event);
        } else {
            @trigger_error(sprintf('Calling the "%s::dispatch()" method with the event name as first argument is deprecated since Symfony 4.3, pass it second and provide the event object first instead.', EventDispatcherInterface::class), E_USER_DEPRECATED);
            $swap = $event;
            $event = $eventName ?? new Event();
            $eventName = $swap;

            if (!$event instanceof Event) {
                throw new \TypeError(sprintf('Argument 1 passed to "%s::dispatch()" must be an instance of %s, %s given.', EventDispatcherInterface::class, Event::class, \is_object($event) ? \get_class($event) : \gettype($event)));
            }
        }

        $listeners = $this->getListeners($eventName);
        $stoppable = $event instanceof Event || $event instanceof ContractsEvent || $event instanceof StoppableEventInterface;

        foreach ($listeners as $listener) {
            if ($stoppable && $event->isPropagationStopped()) {
                break;
            }
            $listener($event, $eventName, $this);
        }

        return $event;
    }
1081516
public function onAddToQueueListenerQueryKind(AddToQueueEvent $event, $eventName, EventDispatcherInterface $dispatcher)
    {
        $table          = $event->getQueueTable();
        $oldData        = $event->getOldData();

        if ($oldData) {
            $event->setQuery("UPDATE $table SET ");
        } else {
            $event->setQuery("INSERT INTO $table SET ");
        }
    }
1302231
public function triggerEvent($eventName, Event $event = null)
    {
        if (!$event) {
            $event = new Event;
        }

        $event->setTarget($this);

        return $this->eventDispatcher->dispatch($eventName, $event);
    }
790305
public function update(BrandUpdateEvent $event, $eventName, EventDispatcherInterface $dispatcher)
    {
        if (null !== $brand = BrandQuery::create()->findPk($event->getBrandId())) {
            $brand->setDispatcher($dispatcher);

            $brand
                ->setVisible($event->getVisible())
                ->setLogoImageId(\intval($event->getLogoImageId()) == 0 ? null : $event->getLogoImageId())
                ->setLocale($event->getLocale())
                ->setTitle($event->getTitle())
                ->setDescription($event->getDescription())
                ->setChapo($event->getChapo())
                ->setPostscriptum($event->getPostscriptum())
                ->save()
            ;

            $event->setBrand($brand);
        }
    }
259401
public function onEvent(Event $anyEvent, $eventName, EventDispatcherInterface $dispatcher)
    {
        if (isset($this->propagations[$eventName])) {
            foreach ($this->propagations[$eventName] as $builder) {
                $builder->buildAndForwardEvent($anyEvent);
            }
        }
    }
134482
public function update(AttributeUpdateEvent $event, $eventName, EventDispatcherInterface $dispatcher)
    {
        if (null !== $attribute = AttributeQuery::create()->findPk($event->getAttributeId())) {
            $attribute
                ->setDispatcher($dispatcher)

                ->setLocale($event->getLocale())
                ->setTitle($event->getTitle())
                ->setDescription($event->getDescription())
                ->setChapo($event->getChapo())
                ->setPostscriptum($event->getPostscriptum())

                ->save();

            $event->setAttribute($attribute);
        }
    }
164891
public function create(FeatureAvCreateEvent $event, $eventName, EventDispatcherInterface $dispatcher)
    {
        $feature = new FeatureAvModel();

        $feature
            ->setDispatcher($dispatcher)

            ->setFeatureId($event->getFeatureId())
            ->setLocale($event->getLocale())
            ->setTitle($event->getTitle())

            ->save()
        ;

        $event->setFeatureAv($feature);
    }
435394
public function dispatch($eventName, $data = null)
    {
        if (!interface_exists('Symfony\Component\EventDispatcher\EventDispatcherInterface')) {
            return;
        }

        if (null === $this->dispatcher) {
            return;
        }

        $event = new VcsEvent($data);

        $this->dispatcher->dispatch($eventName, $event);
    }
316890
public function deleteTemplateAttribute(TemplateDeleteAttributeEvent $event, $eventName, EventDispatcherInterface $dispatcher)
    {
        // Detete the removed attribute in all products which are using this template
        $pseToDelete = ProductSaleElementsQuery::create()
            ->useProductQuery()
                ->filterByTemplateId($event->getTemplate()->getId())
            ->endUse()
            ->useAttributeCombinationQuery()
                ->filterByAttributeId($event->getAttributeId())
            ->endUse()
            ->select([ ProductSaleElementsTableMap::COL_ID ])
            ->find();
    
        $currencyId = CurrencyModel::getDefaultCurrency()->getId();
        
        foreach ($pseToDelete->getData() as $pseId) {
            $dispatcher->dispatch(
                TheliaEvents::PRODUCT_DELETE_PRODUCT_SALE_ELEMENT,
                new ProductSaleElementDeleteEvent(
                    $pseId,
                    $currencyId
                )
            );
        }
    }
1031071
public function onSetErrorListenerQuery(
        QueueSetErrorEvent $event,
        $eventName,
        EventDispatcherInterface $dispatcher
    ) {
        $table          = $event->getQueueTable();
        $field          = $event->getField();
        $id             = $event->getId();
        $query          = "UPDATE $table SET $field = 1 WHERE id = $id";
        $event->setQuery($query);
    }
419570
protected function dispatchEvent($eventName, \Symfony\Component\EventDispatcher\Event $event)
    {
        if (!$event->isPropagationStopped()) {
            $dispatcher = $this->getEventDispatcher();
            $dispatcher->dispatch($eventName, $event);
        }
        return !$event->isPropagationStopped();
    }
1359679
public function updateContentPosition(UpdatePositionEvent $event, $eventName, EventDispatcherInterface $dispatcher)
    {
        return $this->genericUpdatePosition(ProductAssociatedContentQuery::create(), $event, $dispatcher);
    }
1213912
public function onAddToQueueListenerQuery(AddToQueueEvent $event, $eventName, EventDispatcherInterface $dispatcher)
    {
        $query          = $event->getQuery();
        $eventToSave    = $event->getEvent();
        $eventToSave    = serialize($eventToSave);
        $eventToSave    = urlencode($eventToSave);  // Ohne urlencode speichert Contao das serialisierte Event nicht!
        $kind           = $event->getKind();
        $priotity       = $event->getPriority();
        $srcmodule      = $event->getSrcmodule();
        $srctable       = $event->getSrctable();
        $srcid          = $event->getSrcid();
        $interval       = $event->getIntervalkind();
        $query         .= "tstamp = " . time();
        $query         .= ", kind = '$kind'";
        $query         .= ", priority = $priotity";
        $query         .= ", data = '$eventToSave'";
        $query         .= ", srcmodule = '$srcmodule'";
        $query         .= ", srcid = $srcid";
        $query         .= ", srctable = '$srctable'";
        $query         .= ", intervalkind = '$interval'";
        $event->setQuery($query);
    }