Exemplo n.º 1
0
 public function getSubmissions($pageId = 0, $blockId = 0)
 {
     $block_data = Block::getBlockOnPage($blockId, $pageId);
     if (empty($block_data) || $block_data->type != 'form') {
         \abort('404', 'Form not found on page');
     } else {
         $submission_rows = '';
         $submission_data = new \stdClass();
         $submissions = FormSubmission::where('form_block_id', '=', $blockId)->orderBy('id', 'desc')->paginate(10);
         $i = $submissions->total() - ($submissions->currentPage() - 1) * 10;
         foreach ($submissions as $submission) {
             $submission_data->id = $submission->id;
             $submission_data->numb = $i--;
             $submission_data->content = @unserialize($submission->content);
             if (!empty($submission_data->content)) {
                 foreach ($submission_data->content as $k => $v) {
                     if (is_array($v)) {
                         $submission_data->content[$k] = implode(", ", $v);
                     }
                 }
             } else {
                 preg_match_all('/\\"(.*?)\\";s:\\d*:\\"(.*?)\\";/si', $submission->content, $matches);
                 foreach ($matches[1] as $k => $field_key) {
                     $submission_data->content[$field_key] = $matches[2][$k];
                 }
             }
             $submission_data->sent = $submission->sent;
             $submission_data->created_at = $submission->created_at;
             $submission_data->from_page = !empty($submission->from_page_id) ? Path::getFullName($submission->from_page_id) : '-';
             $submission_rows .= View::make('coaster::partials.forms.submissions', array('submission' => $submission_data))->render();
         }
         $this->layoutData['content'] = View::make('coaster::pages.forms.submissions', array('links' => PaginatorRender::admin($submissions), 'submissions' => $submission_rows, 'form' => $block_data->label, 'can_export' => Auth::action('forms.csv'), 'export_link' => route('coaster.admin.forms.csv', ['pageId' => $pageId, 'blockId' => $blockId])));
     }
 }
Exemplo n.º 2
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";
     }
 }
Exemplo n.º 3
0
 public function postRequests($pageId)
 {
     if (empty($pageId)) {
         // block access to all requests
         return 0;
     }
     $type = Request::input('request_type');
     $type = $type ? ['status' => $type] : [];
     $show = Request::input('request_show');
     $show = $show ?: ['page' => false, 'status' => true, 'requested_by' => true];
     $requests = PagePublishRequests::all_requests($pageId, $type, 25);
     if ($requests->isEmpty()) {
         $requests = 'No awaiting requests';
         $pagination = '';
     } else {
         $pagination = PaginatorRender::admin($requests);
     }
     return View::make('coaster::partials.tabs.publish_requests.table', array('show' => $show, 'requests' => $requests, 'pagination' => $pagination))->render();
 }
Exemplo n.º 4
0
 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) : ''));
 }
Exemplo n.º 5
0
 public static function version_table($page_id)
 {
     $versionsQuery = static::with(['user', 'scheduled_versions'])->where('page_id', '=', $page_id)->orderBy('version_id', 'desc');
     $versions = $versionsQuery->paginate(15);
     $pagination = PaginatorRender::admin($versions);
     $page_lang = PageLang::where('page_id', '=', $page_id)->where('language_id', '=', Language::current())->first();
     $live_version = static::where('page_id', '=', $page_id)->where('version_id', '=', $page_lang ? $page_lang->live_version : 0)->first();
     $live_version = $live_version ?: new static();
     $can_publish = Auth::action('pages.version-publish', ['page_id' => $page_id]);
     return View::make('coaster::partials.tabs.versions.table', ['versions' => $versions, 'pagination' => $pagination, 'live_version' => $live_version, 'can_publish' => $can_publish])->render();
 }
 /**
  * @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]);
 }