Example #1
0
 /**
  * @param Module[] $enabledModules
  * @return \Etu\Core\CoreBundle\Entity\Notification[]
  */
 public function getNotifications($enabledModules)
 {
     if ($this->stopwatch) {
         $this->stopwatch->start('block_notifications', 'home_blocks');
     }
     $query = $this->manager->createQueryBuilder()->select('n')->from('EtuCoreBundle:Notification', 'n')->where('n.authorId != :userId')->setParameter('userId', $this->user->getId())->orderBy('n.createdAt', 'DESC')->setMaxResults(10);
     /** @var $subscriptions Subscription[] */
     $subscriptions = $this->globalAccessorObject->get('notifs')->get('subscriptions');
     $subscriptionsWhere = [];
     /** @var $notifications Notification[] */
     $notifications = [];
     if (!empty($subscriptions)) {
         if ($this->stopwatch) {
             $this->stopwatch->start('block_notifications_filters', 'home_blocks');
         }
         if (Apc::enabled() && Apc::has('etuutt_home_subscription_' . $this->user->getId())) {
             $subscriptionsWhere = Apc::fetch('etuutt_home_subscription_' . $this->user->getId());
         } else {
             foreach ($subscriptions as $key => $subscription) {
                 $subscriptionsWhere[] = '(n.entityType = \'' . $subscription->getEntityType() . '\'
                                             AND n.entityId = ' . intval($subscription->getEntityId()) . ')';
             }
             $subscriptionsWhere = implode(' OR ', $subscriptionsWhere);
             if (Apc::enabled()) {
                 Apc::store('etuutt_home_subscription_' . $this->user->getId(), $subscriptionsWhere, 1200);
             }
         }
         if (!empty($subscriptionsWhere)) {
             $query = $query->andWhere($subscriptionsWhere);
         }
         /*
          * Modules
          */
         $modulesWhere = array('n.module = \'core\'', 'n.module = \'user\'');
         foreach ($enabledModules as $module) {
             $identifier = $module->getIdentifier();
             $modulesWhere[] = 'n.module = :module_' . $identifier;
             $query->setParameter('module_' . $identifier, $identifier);
         }
         if (!empty($modulesWhere)) {
             $query = $query->andWhere(implode(' OR ', $modulesWhere));
         }
         if ($this->stopwatch) {
             $this->stopwatch->stop('block_notifications_filters');
             $this->stopwatch->start('block_notifications_query', 'home_blocks');
         }
         $query = $query->getQuery();
         $query->useResultCache(true, 1200);
         $notifications = $query->getResult();
         if ($this->stopwatch) {
             $this->stopwatch->stop('block_notifications_query');
         }
     }
     if ($this->stopwatch) {
         $this->stopwatch->stop('block_notifications');
     }
     return $notifications;
 }
 /**
  * Event to find subscriptions on page laod
  */
 public function onKernelRequest()
 {
     $layer = new UserLayer($this->securityContext->getToken()->getUser());
     $subscriptions = array();
     if ($layer->isUser()) {
         /** @var $em EntityManager */
         $em = $this->doctrine->getManager();
         $subscriptions = $em->getRepository('EtuCoreBundle:Subscription')->findBy(array('user' => $layer->getUser()));
     }
     $this->globalAccessor->set('notifs', new ArrayCollection());
     $this->globalAccessor->get('notifs')->set('subscriptions', $subscriptions);
     $this->globalAccessor->get('notifs')->set('new', []);
     $this->globalAccessor->get('notifs')->set('new_count', 0);
 }
 /**
  * @param GetResponseEvent $event
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     $modules = $this->modulesManager->getEnabledModules();
     if (is_array($modules)) {
         // Legacy hack for former doctrine ORM versions.
         $arrayobject = new \ArrayObject($modules);
         $modules = $arrayobject->getIterator();
     }
     // Boot modules
     /** @var $module Module */
     /** @var $modules \Iterator<Module> */
     foreach ($modules as $module) {
         if ($module->mustBoot()) {
             $module->setContainer($this->container);
             $module->setRouter($this->router);
             $module->onModuleBoot();
             $module->setEnabled(true);
         }
     }
     // Give an access from Twig
     $this->globalAccessorObject->set('modules', $this->modulesManager->getModules());
     // Access to env from Twig
     $this->globalAccessorObject->set('environment', $this->container->get('kernel')->getEnvironment());
 }