src/Sulu/Bundle/AudienceTargetingBundle/EventListener/TargetGroupSubscriber.php
public function setTargetGroup(GetResponseEvent $event)
    {
        $request = $event->getRequest();

        if ($targetGroupId = $request->headers->get($this->targetGroupHeader)) {
            $this->targetGroupStore->setTargetGroupId($targetGroupId);
        } elseif ($targetGroupId = $request->cookies->get($this->targetGroupCookie)) {
            $visitorSession = $request->cookies->get($this->visitorSessionCookie);
            if ($visitorSession) {
                $this->targetGroupStore->setTargetGroupId($targetGroupId);

                return;
            }

            $targetGroup = $this->targetGroupEvaluator->evaluate(
                TargetGroupRuleInterface::FREQUENCY_SESSION,
                $this->targetGroupRepository->find($targetGroupId)
            );

            if ($targetGroup) {
                $this->targetGroupStore->updateTargetGroupId($targetGroup->getId());
            }
        } elseif ($request->getPathInfo() !== $this->targetGroupUrl) {
            // this should not happen on the endpoint for the cache, because it is set there manually as a header
            $targetGroup = $this->targetGroupEvaluator->evaluate();

            $targetGroupId = 0;
            if ($targetGroup) {
                $targetGroupId = $targetGroup->getId();
            }

            $this->targetGroupStore->updateTargetGroupId($targetGroupId);
        }
    }
public function setTargetGroup(GetResponseEvent $event)
    {
        $request = $event->getRequest();

        if ($targetGroupId = $request->headers->get($this->targetGroupHeader)) {
            $this->targetGroupStore->setTargetGroupId($targetGroupId);
        } elseif ($targetGroupId = $request->cookies->get($this->targetGroupCookie)) {
            $visitorSession = $request->cookies->get($this->visitorSessionCookie);
            if ($visitorSession) {
                $this->targetGroupStore->setTargetGroupId($targetGroupId);

                return;
            }

            $targetGroup = $this->targetGroupEvaluator->evaluate(
                TargetGroupRuleInterface::FREQUENCY_SESSION,
                $this->targetGroupRepository->find($targetGroupId)
            );

            if ($targetGroup) {
                $this->targetGroupStore->updateTargetGroupId($targetGroup->getId());
            }
        } elseif ($request->getPathInfo() !== $this->targetGroupUrl) {
            // this should not happen on the endpoint for the cache, because it is set there manually as a header
            $targetGroup = $this->targetGroupEvaluator->evaluate();

            $targetGroupId = 0;
            if ($targetGroup) {
                $targetGroupId = $targetGroup->getId();
            }

            $this->targetGroupStore->updateTargetGroupId($targetGroupId);
        }
    }
public function setTargetGroup ( GetResponseEvent $ event ) { $ request = $ event -> getRequest ( ) ; if ( $ targetGroupId = $ request -> headers -> get ( $ this -> targetGroupHeader ) ) { $ this -> targetGroupStore -> setTargetGroupId ( $ targetGroupId ) ; } elseif ( $ targetGroupId = $ request -> cookies -> get ( $ this -> targetGroupCookie ) ) { $ visitorSession = $ request -> cookies -> get ( $ this -> visitorSessionCookie ) ; if ( $ visitorSession ) { $ this -> targetGroupStore -> setTargetGroupId ( $ targetGroupId ) ; return ; } $ targetGroup = $ this -> targetGroupEvaluator -> evaluate ( TargetGroupRuleInterface :: FREQUENCY_SESSION , $ this -> targetGroupRepository -> find ( $ targetGroupId ) ) ; if ( $ targetGroup ) { $ this -> targetGroupStore -> updateTargetGroupId ( $ targetGroup -> getId ( ) ) ; } } elseif ( $ request -> getPathInfo ( ) !== $ this -> targetGroupUrl ) { // this should not happen on the endpoint for the cache, because it is set there manually as a header $ targetGroup = $ this -> targetGroupEvaluator -> evaluate ( ) ; $ targetGroupId = 0 ; if ( $ targetGroup ) { $ targetGroupId = $ targetGroup -> getId ( ) ; } $ this -> targetGroupStore -> updateTargetGroupId ( $ targetGroupId ) ; } }
Evaluates the cookie holding the target group information. This has only an effect if there is no cache used,
since in that case the cache already did it.

@param GetResponseEvent $event
Evaluates the cookie holding the target group information . This has only an effect if there is no cache used since in that case the cache already did it .