Ejemplo n.º 1
0
 /**
  * Display form view
  * @param string $content
  * @param array $options
  * @return \Illuminate\Contracts\View\View|string
  */
 public function display($content, $options = [])
 {
     $formData = $this->_defaultData($content);
     $template = !empty($options['view']) ? $options['view'] : $formData->template;
     $templatePath = 'themes.' . PageBuilder::getData('theme') . '.blocks.forms.' . $template;
     return FormWrap::view($this->_block, $options, $templatePath, ['form_data' => $formData]);
 }
Ejemplo 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";
     }
 }