public static function onPostCategoryCall(Event $event)
 {
     $response = $event->getResponse();
     $entityManager = $event->getApplication()->getEntityManager();
     $user = $event->getApplication()->getBBUserToken()->getUser();
     $favoriteCategory = self::getFavoriteCategory($entityManager, $user->getId());
     if (empty($favoriteCategory['contents'])) {
         $favoriteCategory = self::getDefaultFavoriteCategory($entityManager, $event->getApplication()->getSite()->getUid(), $favoriteCategory);
     }
     $categories = json_decode($response->getContent(), true);
     /* the new category has been pushed on top of class content categories */
     array_unshift($categories, $favoriteCategory);
     $response->setContent(json_encode($categories, true));
 }
예제 #2
0
 /**
  * Occur on nestednode.page.onflush events.
  *
  * @param \BackBee\Event\Event $event
  */
 public static function onFlushPage(Event $event)
 {
     if (true === self::$onFlushPageAlreadyCalled) {
         return;
     }
     $page = $event->getTarget();
     if (!$page instanceof Page) {
         return;
     }
     $application = $event->getApplication();
     $em = $application->getEntityManager();
     $uow = $em->getUnitOfWork();
     if ($uow->isScheduledForDelete($page)) {
         return;
     }
     if (null === ($metadata_config = $application->getConfig()->getSection('metadata'))) {
         return;
     }
     if (null === ($metadata = $page->getMetaData())) {
         $metadata = new \BackBee\MetaData\MetaDataBag($metadata_config, $page);
     } else {
         $metadata->update($metadata_config, $page);
     }
     $page->setMetaData($metadata->compute($page));
     if ($uow->isScheduledForInsert($page) || $uow->isScheduledForUpdate($page)) {
         $uow->recomputeSingleEntityChangeSet($em->getClassMetadata('BackBee\\NestedNode\\Page'), $page);
     } elseif (!$uow->isScheduledForDelete($page)) {
         $uow->computeChangeSet($em->getClassMetadata('BackBee\\NestedNode\\Page'), $page);
     }
     self::$onFlushPageAlreadyCalled = true;
 }
예제 #3
0
 /**
  * Occur on nestednode.page.onflush events.
  *
  * @param Event $event
  */
 public static function onFlushPage(Event $event)
 {
     if (self::$onFlushPageAlreadyCalled) {
         return;
     }
     $page = $event->getTarget();
     if (!$page instanceof Page) {
         return;
     }
     $application = $event->getApplication();
     $em = $application->getEntityManager();
     $uow = $em->getUnitOfWork();
     if ($uow->isScheduledForDelete($page)) {
         return;
     }
     $metadata = $application->getContainer()->get('nestednode.metadata.resolver')->resolve($page);
     $page->setMetaData($metadata);
     if ($uow->isScheduledForInsert($page) || $uow->isScheduledForUpdate($page)) {
         $uow->recomputeSingleEntityChangeSet($em->getClassMetadata('BackBee\\NestedNode\\Page'), $page);
     } elseif (!$uow->isScheduledForDelete($page)) {
         $uow->computeChangeSet($em->getClassMetadata('BackBee\\NestedNode\\Page'), $page);
     }
     self::$onFlushPageAlreadyCalled = true;
 }
예제 #4
0
 public static function onFlushElementFile(Event $event)
 {
     $revision = $event->getTarget();
     $content = $revision->getContent();
     if (!$content instanceof ElementFile || !is_file($content->path)) {
         return;
     }
     $application = $event->getApplication();
     $em = $application->getEntityManager();
     $uow = $em->getUnitOfWork();
     if ($uow->isScheduledForDelete($content)) {
         return;
     }
     $fileRepository = $em->getRepository('BackBee\\ClassContent\\Element\\File');
     $fileRepository->setDirectories($application);
     $fileRepository->commitFile($content);
     $moveFrom = $content->path;
     File::resolveFilepath($moveFrom, null, array('base_dir' => $application->getMediaDir()));
     $content->setParam('stat', json_encode(stat($moveFrom)));
     if ($content instanceof ElementImage) {
         list($width, $height) = getimagesize($moveFrom);
         $content->setParam('width', $width);
         $content->setParam('height', $height);
     }
     $uow->recomputeSingleEntityChangeSet($em->getClassMetadata('BackBee\\ClassContent\\Revision'), $revision);
 }
예제 #5
0
 public static function onPostCall(Event $event)
 {
     $response = $event->getResponse();
     if ($response->headers->get('content-type') === 'text/html') {
         return;
     }
     $application = $event->getApplication();
     $renderer = $application->getRenderer();
     $content = json_decode($response->getContent());
     $result = false;
     if ($content instanceof \StdClass) {
         if (isset($content->type) && isset($content->parameters)) {
             if (isset($content->parameters->rendermode)) {
                 $result = true;
             }
         }
     }
     if (!$result) {
         return;
     }
     $rendermodeParam = $content->parameters->rendermode;
     $classname = AbstractClassContent::getClassnameByContentType($content->type);
     $modes = ['default' => 'Default mode'];
     foreach ($renderer->getAvailableRenderMode(new $classname()) as $mode) {
         $modes[$mode] = ucfirst(str_replace('_', ' ', $mode));
     }
     $rendermodeParam->options = $modes;
     $response->setContent(json_encode($content));
 }
예제 #6
0
 /**
  * Occur on nestednode.page.preupdate events and nestednode.section.preupdate.
  *
  * @access public
  *
  * @param Event $event
  */
 public static function onFlushPage(Event $event)
 {
     $em = $event->getApplication()->getEntityManager();
     $uow = $em->getUnitOfWork();
     $page = $event->getTarget();
     if ($uow->isScheduledForInsert($page) && $page->getParent() !== null && $page->getState() < 4) {
         self::setSectionHasChildren($em, $page->getParent()->getSection(), +1);
     }
 }