Example #1
0
 /**
  * Display repeater view
  * @param string $content
  * @param array $options
  * @return string
  */
 public function display($content, $options = [])
 {
     $repeaterId = $content;
     $template = !empty($options['view']) ? $options['view'] : $this->_block->name;
     $repeatersViews = 'themes.' . PageBuilder::getData('theme') . '.blocks.repeaters.';
     if (!empty($options['form'])) {
         return FormWrap::view($this->_block, $options, $repeatersViews . $template . '-form');
     }
     if (View::exists($repeatersViews . $template)) {
         $renderedContent = '';
         if ($repeaterBlocks = BlockRepeater::getRepeaterBlocks($this->_block->id)) {
             $random = !empty($options['random']) ? $options['random'] : false;
             $repeaterRows = PageBlockRepeaterData::loadRepeaterData($repeaterId, $options['version'], $random);
             // pagination
             if (!empty($options['per_page']) && !empty($repeaterRows)) {
                 $pagination = new LengthAwarePaginator($repeaterRows, count($repeaterRows), $options['per_page'], Request::input('page', 1));
                 $pagination->setPath(Request::getPathInfo());
                 $paginationLinks = PaginatorRender::run($pagination);
                 $repeaterRows = array_slice($repeaterRows, ($pagination->currentPage() - 1) * $options['per_page'], $options['per_page'], true);
             } else {
                 $paginationLinks = '';
             }
             if (!empty($repeaterRows)) {
                 $i = 1;
                 $isFirst = true;
                 $isLast = false;
                 $rows = count($repeaterRows);
                 $cols = !empty($options['cols']) ? (int) $options['cols'] : 1;
                 $column = !empty($options['column']) ? (int) $options['column'] : 1;
                 foreach ($repeaterRows as $rowId => $row) {
                     if ($i % $cols == $column % $cols) {
                         $previousKey = PageBuilder::getCustomBlockDataKey();
                         PageBuilder::setCustomBlockDataKey('repeater' . $repeaterId . '.' . $rowId);
                         foreach ($repeaterBlocks as $repeaterBlock) {
                             if ($repeaterBlock->exists) {
                                 PageBuilder::setCustomBlockData($repeaterBlock->name, !empty($row[$repeaterBlock->id]) ? $row[$repeaterBlock->id] : '', null, false);
                             }
                         }
                         if ($i + $cols - 1 >= $rows) {
                             $isLast = true;
                         }
                         $renderedContent .= View::make($repeatersViews . $template, array('is_first' => $isFirst, 'is_last' => $isLast, 'count' => $i, 'total' => $rows, 'id' => $repeaterId, 'pagination' => $paginationLinks, 'links' => $paginationLinks))->render();
                         $isFirst = false;
                         PageBuilder::setCustomBlockDataKey($previousKey);
                     }
                     $i++;
                 }
             }
         }
         return $renderedContent;
     } else {
         return "Repeater view does not exist in theme";
     }
 }
 public function getYourRequests()
 {
     $user_requests = PagePublishRequests::all_requests(0, ['user_id' => Auth::user()->id], 25);
     if ($user_requests->isEmpty()) {
         $user_requests = 'You have made no requests';
     }
     $user_requests_table = View::make('coaster::partials.tabs.publish_requests.table', array('show' => ['page' => true, 'status' => true, 'requested_by' => false], 'requests' => $user_requests))->render();
     $this->layoutData['title'] = 'Your Publish Requests';
     $this->layoutData['content'] = View::make('coaster::pages.home.requests', array('title' => $this->layoutData['title'], 'requests' => $user_requests_table, 'pagination' => !is_string($user_requests) ? PaginatorRender::run($user_requests, 2) : ''));
 }
 /**
  * @param int $categoryPageId
  * @param Page[]|Collection $pages
  * @param array $options
  * @return string
  */
 protected function _renderCategory($categoryPageId, $pages, $options)
 {
     if (array_key_exists('view', $options) && empty($options['view'])) {
         unset($options['view']);
     }
     $defaultOptions = ['render' => true, 'renderIfEmpty' => true, 'view' => 'default', 'type' => 'all', 'per_page' => 20, 'limit' => 0, 'content' => '', 'canonicals' => config('coaster::frontend.canonicals')];
     $options = array_merge($defaultOptions, $options);
     if (!$options['render']) {
         return $pages;
     }
     // select page of selected type
     $pagesOfSelectedType = [];
     if ($options['type'] == 'all') {
         $pagesOfSelectedType = is_a($pages, Collection::class) ? $pages->all() : $pages;
     } else {
         foreach ($pages as $page) {
             $children = count(Page::getChildPageIds($page->id));
             if ($options['type'] == 'pages' && $children == 0 || $options['type'] == 'categories' && $children > 0) {
                 $pagesOfSelectedType[] = $page;
             }
         }
     }
     // limit results
     if (!empty($options['limit']) && is_int($options['limit'])) {
         $pagesOfSelectedType = array_slice($pagesOfSelectedType, 0, $options['limit']);
     }
     // pagination
     if (!empty($options['per_page']) && (int) $options['per_page'] > 0) {
         $paginator = new LengthAwarePaginator($pagesOfSelectedType, count($pagesOfSelectedType), $options['per_page'], Request::input('page', 1));
         $paginator->setPath(Request::getPathInfo());
         $paginationLinks = PaginatorRender::run($paginator);
         $pages = array_slice($pagesOfSelectedType, ($paginator->currentPage() - 1) * $options['per_page'], $options['per_page']);
     } else {
         $pages = $pagesOfSelectedType;
         $paginationLinks = '';
     }
     $list = '';
     $total = count($pages);
     if (!$total && !$options['renderIfEmpty']) {
         return '';
     }
     $groupPageContainerId = 0;
     if ($categoryPageId && !$options['canonicals']) {
         $categoryPage = Page::preload($categoryPageId);
         $groupPageContainerId = $categoryPage->exists && $categoryPage->group_container > 0 ? $categoryPage->id : 0;
     }
     $pages = array_values($pages);
     foreach ($pages as $count => $page) {
         $isFirst = $count == 0;
         $isLast = $count == $total - 1;
         if (is_string($page->id)) {
             $tmpCustomBlockKey = $this->_customBlockDataKey;
             $this->_customBlockDataKey = 'customPage:' . $page->id;
             $pageDetails = new \stdClass();
             foreach ($page as $blockName => $content) {
                 if (in_array($blockName, ['fullUrl', 'fullName'])) {
                     $pageDetails->{$blockName} = $content;
                 } else {
                     $this->setCustomBlockData($blockName, $content, $this->_customBlockDataKey);
                 }
             }
             Path::addCustomPagePath($page->id, $pageDetails);
         }
         $fullPageInfo = new PageDetails($page->id, $groupPageContainerId);
         $this->pageOverride = $page;
         $list .= $this->_getRenderedView('categories.' . $options['view'] . '.page', ['page' => $fullPageInfo, 'category_id' => $categoryPageId, 'is_first' => $isFirst, 'is_last' => $isLast, 'count' => $count + 1, 'total' => $total]);
         if (isset($tmpCustomBlockKey)) {
             $this->_customBlockDataKey = $tmpCustomBlockKey;
             $tmpCustomBlockKey = null;
         }
         $this->pageOverride = null;
     }
     return $this->_getRenderedView('categories.' . $options['view'] . '.pages_wrap', ['pages' => $list, 'category_id' => $categoryPageId, 'pagination' => $paginationLinks, 'links' => $paginationLinks, 'total' => $total, 'content' => $options['content'], 'search_query' => $this->searchQuery]);
 }