Example #1
0
 /**
  * @param \SimpleXMLElement $obj
  * @param null $parent
  * @return \Doctrine\Common\Collections\ArrayCollection
  */
 protected function getItems(\SimpleXMLElement $obj, $parent = null)
 {
     $returnChildren = new \Doctrine\Common\Collections\ArrayCollection();
     foreach ($obj->children() as $objData) {
         $id = $this->blockParser->getXmlAttr($objData, 'id');
         $menuItemTranslation = $this->db->createQueryBuilder()->select("menu, translation")->from('\\Fraym\\Menu\\Entity\\MenuItemTranslation', 'translation')->join('translation.menuItem', 'menu')->where('menu.id = :id AND translation.locale = :localeId AND translation.active = 1')->setParameter('id', $id)->setParameter('localeId', $this->route->getCurrentMenuItemTranslation()->locale->id)->getQuery()->getOneOrNullResult();
         $this->db->free();
         if ($menuItemTranslation) {
             $menuItem = clone $this->db->getRepository('\\Fraym\\Menu\\Entity\\MenuItem')->findOneById($menuItemTranslation->menuItem->id);
             $children = $this->getItems($objData, $menuItem);
             $menuItem->parent = $parent;
             $menuItem->children = $children;
             $returnChildren->set($menuItem->id, $menuItem);
         }
     }
     return $returnChildren;
 }
Example #2
0
 /**
  * @return bool|mixed
  */
 public function getChangeSets()
 {
     $changeSets = [];
     $query = $this->db->createQueryBuilder();
     $results = $query->select("block, byRef")->from('\\Fraym\\Block\\Entity\\Block', 'block')->leftJoin('block.byRef', 'byRef')->leftJoin('block.changeSets', 'cs')->andWhere('(block.changeSets IS NOT EMPTY AND block INSTANCE OF \\Fraym\\Block\\Entity\\Block) OR (block.block IS NULL AND block INSTANCE OF \\Fraym\\Block\\Entity\\ChangeSet)')->addOrderBy('cs.created', 'desc')->getQuery()->getResult();
     foreach ($results as $block) {
         if (!isset($changeSets[$block->site->id])) {
             $changeSets[$block->site->id] = [];
         }
         $menuItemId = $block->menuItem ? $block->menuItem->id : 0;
         if (!isset($changeSets[$block->site->id][$menuItemId])) {
             $changeSets[$block->site->id][$menuItemId] = [];
         }
         $translationId = $block->menuItemTranslation ? $block->menuItemTranslation->id : 0;
         if (!isset($changeSets[$block->site->id][$menuItemId][$translationId])) {
             $changeSets[$block->site->id][$menuItemId][$translationId] = ['menuItem' => $block->menuItem, 'menuItemTranslation' => $block->menuItemTranslation, 'blocks' => []];
         }
         $lastChange = $block->changeSets->count() ? $block->changeSets->last() : $block;
         $changeSets[$block->site->id][$menuItemId][$translationId]['blocks'][$block->id] = $lastChange;
     }
     return $changeSets;
 }
Example #3
0
 /**
  * Checks if the current user can do a block action
  *
  * @param $permission
  * @param $extension_id
  * @return bool
  */
 public function permissionAllowed($permission, $extension_id)
 {
     //TODO: Implement this function
     $user = $this->user;
     if (!$user) {
         return false;
     }
     $extension = $this->db->getRepository('\\Fraym\\Block\\Entity\\BlockExtension')->findOneById($extension_id);
     if ($extension && count($extension->permissions)) {
         $identifiers = $user->getIdentifiersFromGroups();
         $identifiers[] = $user->identifier;
         $result = $this->db->createQueryBuilder()->select("perm")->from('\\Fraym\\Block\\Entity\\Permission', 'perm')->where("perm.extension = :id AND perm.identifier IN ('" . implode("','", $identifiers) . "') AND perm.permission LIKE :permission")->setParameter('id', $extension_id)->setParameter('permission', "%{$permission}%")->getQuery()->getOneOrNullResult();
         return $result ? true : false;
     }
     return true;
 }
Example #4
0
 /**
  *
  */
 public function menuItemNotFound()
 {
     $page404 = null;
     if ($this->currentMenuItem) {
         $localeId = $this->session->get('localeId', false);
         $page404 = $this->db->createQueryBuilder()->select("menuItemTranslation, menuItem, template, site, locale")->from('\\Fraym\\Menu\\Entity\\MenuItemTranslation', 'menuItemTranslation')->join('menuItemTranslation.menuItem', 'menuItem')->leftJoin("menuItem.template", 'template')->join("menuItem.site", 'site')->join("menuItemTranslation.locale", 'locale')->setMaxResults(1)->setParameter('site', $this->currentMenuItem->site->id)->where("site.id = :site AND menuItem.is404 = 1 AND menuItem.active = 1");
         if ($localeId) {
             $page404 = $page404->andWhere('locale.id = :locale')->setParameter('locale', $localeId);
         } else {
             $page404 = $page404->andWhere('locale.default = 1');
         }
         $page404 = $page404->getQuery()->getOneOrNullResult();
     }
     // call site note found view
     if (is_object($page404)) {
         $this->render404Site($page404);
         // cache the 404 page
         $this->cache->setCacheContent();
     } else {
         error_log('Menuitem not found or template not set!');
         $this->response->sendHTTPStatusCode(500);
     }
     $this->response->finish(true, true);
 }
Example #5
0
 /**
  * @param $menuId
  * @param $contentId
  * @return mixed
  */
 public function findBlocks($menuId, $contentId)
 {
     $result = $this->db->createQueryBuilder()->select("block, byRef")->from('\\Fraym\\Block\\Entity\\Block', 'block')->leftJoin('block.byRef', 'byRef')->orderBy('block.position', 'asc')->where("block.contentId = :contentId")->andWhere("block.menuItem IS NULL OR block.menuItem = :menuId")->andWhere("block.site = :site")->andWhere("block.menuItemTranslation IS NULL OR block.menuItemTranslation = :menuTranslationId")->setParameter('menuId', $menuId)->setParameter('menuTranslationId', $this->route->getCurrentMenuItemTranslation()->id)->setParameter('site', $this->route->getCurrentMenuItem()->site)->setParameter('contentId', $contentId)->getQuery()->getResult();
     return $result;
 }
Example #6
0
 /**
  * @param $xml
  */
 protected function listFilter($xml)
 {
     $listPageUrl = '';
     $listPage = $this->db->getRepository('\\Fraym\\Menu\\Entity\\MenuItem')->findOneById($xml->listPage);
     if ($listPage) {
         $listPageUrl = $listPage->getUrl($this->route, true);
     }
     if ((string) $xml->view == 'list-category') {
         $categories = $this->db->createQueryBuilder()->select("c")->from('\\Extension\\News\\Entity\\Category', 'c')->join('c.news', 'n')->leftJoin('n.sites', 's')->where("s = :site OR n.sites IS EMPTY")->orderBy("c.name", 'asc')->setParameter('site', $this->route->getCurrentMenuItem()->site)->getQuery()->getResult();
         return $this->newsController->renderNewsCategories($listPageUrl, $categories);
     } elseif ((string) $xml->view == 'list-tag') {
         $tags = $this->db->createQueryBuilder()->select("t")->from('\\Extension\\News\\Entity\\Tag', 't')->join('t.news', 'n')->leftJoin('n.sites', 's')->where("s = :site OR n.sites IS EMPTY")->orderBy("t.name", 'asc')->setParameter('site', $this->route->getCurrentMenuItem()->site)->getQuery()->getResult();
         return $this->newsController->renderNewsTags($listPageUrl, $tags);
     }
 }
Example #7
0
 /**
  * @param $menuId
  * @param $contentId
  * @return mixed
  */
 public function findBlocks($menuId, $contentId)
 {
     $queryBuilder = $this->db->createQueryBuilder();
     $menuTranslationId = $this->route->getCurrentMenuItemTranslation()->id;
     $siteId = $this->route->getCurrentMenuItem()->site->id;
     $blocks = [];
     $query = $queryBuilder->select("block")->from('\\Fraym\\Block\\Entity\\Block', 'block')->andWhere('block INSTANCE OF \\Fraym\\Block\\Entity\\Block OR block.block IS NULL');
     if ($this->user->isAdmin() === false) {
         $query = $query->andWhere("block.menuItem IS NULL OR block.menuItem = :menuId")->andWhere("block.site = :site")->andWhere("block.menuItemTranslation IS NULL OR block.menuItemTranslation = :menuTranslationId")->setParameter('menuId', $menuId)->setParameter('menuTranslationId', $menuTranslationId)->setParameter('site', $siteId);
     }
     $results = $query->addOrderBy('block.position', 'asc')->addOrderBy('block.id', 'desc')->getQuery()->getResult();
     foreach ($results as $result) {
         if ($this->user->isAdmin() && $result->changeSets->count() > 0) {
             $lastChange = $result->changeSets->last();
             if ($lastChange->contentId === $contentId && ($lastChange->menuItem === null || $lastChange->menuItem->id === $menuId) && ($lastChange->menuItemTranslation === null || $lastChange->menuItemTranslation->id === $menuTranslationId) && $lastChange->site->id == $siteId && $lastChange->type !== Entity\ChangeSet::DELETED) {
                 // Changed blocks
                 $lastChange = clone $lastChange;
                 $lastChange->id = $result->id;
                 $blocks[$result->id] = $lastChange;
             }
         } elseif ($this->user->isAdmin() && $result->contentId === $contentId && ($result->menuItem === null || $result->menuItem->id === $menuId) && ($result->menuItemTranslation === null || $result->menuItemTranslation->id === $menuTranslationId) && $result->site->id == $siteId && get_class($result) === 'Fraym\\Block\\Entity\\ChangeSet') {
             // New blocks
             $blocks[$result->id] = $result;
         } elseif ($contentId === $result->contentId && ($result->menuItem === null || $result->menuItem->id === $menuId) && ($result->menuItemTranslation === null || $result->menuItemTranslation->id === $menuTranslationId) && $result->site->id == $siteId && get_class($result) === 'Fraym\\Block\\Entity\\Block') {
             // Old none changed blocks
             $blocks[$result->id] = $result;
         }
     }
     if ($this->user->isAdmin()) {
         uasort($blocks, function ($a, $b) {
             if ($a->position === $b->position) {
                 return $a->id < $b->id ? 1 : -1;
             }
             return $a->position > $b->position ? 1 : -1;
         });
     }
     return $blocks;
 }