Beispiel #1
0
 /**
  * Set model properties from active record data
  */
 public function before()
 {
     // is new item?
     if ($this->_content->id === null) {
         $this->_new = true;
         if (null === $this->galleryFreeId) {
             $this->galleryFreeId = '_tmp_' . Str::randomLatin(mt_rand(16, 32));
         }
         if (null === $this->authorId) {
             $this->authorId = App::$User->identity()->getId();
         }
         if (null === $this->categoryId) {
             $this->categoryId = 1;
         }
     } else {
         // is edit of exist item? define available data
         $this->title = $this->_content->title;
         $this->text = $this->_content->text;
         $this->path = $this->_content->path;
         $this->poster = $this->_content->poster;
         $this->categoryId = $this->_content->category_id;
         $this->authorId = $this->_content->author_id;
         $this->metaTitle = $this->_content->meta_title;
         $this->metaKeywords = $this->_content->meta_keywords;
         $this->metaDescription = $this->_content->meta_description;
         $this->display = $this->_content->display;
         $this->source = $this->_content->source;
         $this->createdAt = Date::convertToDatetime($this->_content->created_at, Date::FORMAT_TO_HOUR);
         $this->galleryFreeId = $this->_content->id;
     }
 }
 /**
  * Set default values from database record
  */
 public function before()
 {
     // set data from db record
     $this->title = $this->_record->title;
     $this->text = $this->_record->text;
     $this->path = $this->_record->path;
     $this->categoryId = $this->_record->category_id;
     // set current user id
     $this->authorId = App::$User->identity()->getId();
     // set true if it is a new content item
     if ($this->_record->id === null || (int) $this->_record->id < 1) {
         $this->_new = true;
     }
     // set random path slug if not defined
     if ($this->path === null || Str::likeEmpty($this->path)) {
         $randPath = date('d-m-Y') . '-' . Str::randomLatin(mt_rand(8, 12));
         $this->path = Str::lowerCase($randPath);
     }
 }
Beispiel #3
0
 /**
  * Build bootstrap navbar
  * @param array $elements
  * @return NULL|string
  */
 public static function display($elements)
 {
     // check if elements passed well
     if (!Obj::isArray($elements) || count($elements['items']) < 1) {
         return null;
     }
     // set default bootstrap properties if not defined
     $elements['property']['class'] = Str::concat(' ', 'nav', $elements['property']['class']);
     $elements['nav']['class'] = Str::concat(' ', 'navbar', $elements['nav']['class']);
     if ($elements['container'] === null) {
         $elements['container'] = 'container-fluid';
     }
     // set mobile collapse id for toggle
     $mobCollapseId = $elements['collapseId'];
     if (Str::likeEmpty($mobCollapseId)) {
         $mobCollapseId = Str::randomLatin(mt_rand(6, 12)) . mt_rand(1, 99);
     }
     // set element id for toggle
     $ulId = 1;
     // prepare array's for left, right and static elements
     $itemsLeft = [];
     $itemsRight = [];
     $itemsStatic = null;
     foreach ($elements['items'] as $item) {
         if (Obj::isString($item)) {
             // sounds like a static object w/o render request
             $itemsStatic .= $item;
         } else {
             if ($item['type'] === 'dropdown') {
                 // build bootstrap dropdown properties
                 $item['dropdown'] = ['class' => 'dropdown-toggle', 'data-toggle' => 'dropdown', 'href' => '#'];
                 $item['property']['class'] = Str::concat(' ', 'dropdown', $item['property']['class']);
             } else {
                 $item['type'] = 'link';
             }
             // set item with position
             if ($item['position'] !== null && $item['position'] === 'right') {
                 // right position item
                 $itemsRight[] = $item;
             } else {
                 // left pos item
                 $itemsLeft[] = $item;
             }
         }
     }
     // build html dom for left and right elements
     $leftBuild = null;
     $rightBuild = null;
     if (count($itemsLeft) > 0) {
         $mainElemLeft = $elements['property'];
         // todo: fix me!!
         $mainElemLeft['id'] .= $ulId;
         $ulId++;
         $leftBuild = Listing::display(['type' => 'ul', 'property' => $mainElemLeft, 'activeOrder' => $elements['activeOrder'], 'items' => $itemsLeft]);
     }
     if (count($itemsRight) > 0) {
         $mainElemRight = $elements['property'];
         // todo: fix me!!
         $mainElemRight['class'] .= ' navbar-right';
         $mainElemRight['id'] .= $ulId;
         $ulId++;
         $rightBuild = Listing::display(['type' => 'ul', 'property' => $mainElemRight, 'activeOrder' => $elements['activeOrder'], 'items' => $itemsRight]);
     }
     // generate output dom of bootstrap navbar
     $dom = new Dom();
     $body = $dom->div(function () use($leftBuild, $rightBuild, $itemsStatic) {
         return $leftBuild . $itemsStatic . $rightBuild;
     }, ['class' => 'collapse navbar-collapse', 'id' => $mobCollapseId]);
     // drow <nav @properties>@next</nav>
     return $dom->nav(function () use($dom, $elements, $mobCollapseId, $body) {
         // drow <div @container>@next</div>
         return $dom->div(function () use($dom, $elements, $mobCollapseId, $body) {
             // drow <div @navbar-header>@next</div>
             $header = $dom->div(function () use($dom, $elements, $mobCollapseId) {
                 // drow <button @collapse>@next</button>
                 $collapseButton = $dom->button(function () use($dom) {
                     $toggleItem = $dom->span(function () {
                         return 'Toggle menu';
                     }, ['class' => 'sr-only']);
                     $toggleIcon = null;
                     for ($i = 0; $i < 3; $i++) {
                         $toggleIcon .= $dom->span(function () {
                             return null;
                         }, ['class' => 'icon-bar']);
                     }
                     return $toggleItem . $toggleIcon;
                 }, ['type' => 'button', 'class' => 'navbar-toggle collapsed', 'data-toggle' => 'collapse', 'data-target' => '#' . $mobCollapseId]);
                 // drow <div @brand>@brandtext<?div>
                 $brand = null;
                 if (isset($elements['brand'])) {
                     if (isset($elements['brand']['link'])) {
                         $brand = Url::link($elements['brand']['link'], $elements['brand']['text'], ['class' => 'navbar-brand']);
                     } else {
                         $brand = (new Dom())->span(function () use($elements) {
                             return $elements['brand']['text'];
                         }, ['class' => 'navbar-brand']);
                     }
                 }
                 return $collapseButton . $brand;
             }, ['class' => 'navbar-header']);
             // return header and body concat
             return $header . $body;
         }, $elements['container']);
     }, $elements['nav']);
 }
Beispiel #4
0
 /**
  * Display nav listing block
  * @param array $elements
  */
 public static function display($elements)
 {
     // check if elements isn't empty and contains rows
     if (!Obj::isArray($elements) || count($elements['items']) < 1) {
         return null;
     }
     // prepare tab order
     if ($elements['tabAnchor'] === null) {
         $elements['tabAnchor'] = Str::randomLatin(mt_rand(6, 12));
     }
     // set global element properties
     $blockProperty = [];
     if ($elements['blockProperty'] !== null) {
         if (Obj::isArray($elements['blockProperty'])) {
             $blockProperty = $elements['blockProperty'];
         }
         unset($elements['blockProperty']);
     }
     // check if items have defined active order
     $activeDefined = Arr::in(true, Arr::ploke('active', $elements['items']));
     // prepare tab content
     $tabContent = null;
     $tabIdx = 1;
     // initialize dom model
     $dom = new Dom();
     // prepare items to drow listing
     $items = [];
     foreach ($elements['items'] as $item) {
         // its just a link, drow it as is
         if ($item['type'] === 'link') {
             $items[] = $item;
         } elseif ($item['type'] === 'dropdown') {
             // build bootstrap dropdown properties
             $item['dropdown'] = ['class' => 'dropdown-toggle', 'data-toggle' => 'dropdown', 'href' => '#'];
             $item['property']['class'] = Str::concat(' ', 'dropdown', $item['property']['class']);
             $items[] = $item;
         } elseif ($item['type'] === 'tab') {
             $activeObject = false;
             $item['type'] = 'link';
             // fix for global Listing builder
             $item['link'] = '#' . $elements['tabAnchor'] . $tabIdx;
             $item['property']['role'] = 'presentation';
             // check if active definition is exist in elements options
             if ($activeDefined) {
                 if ($item['active'] === true) {
                     $activeObject = true;
                 }
             } elseif ($tabIdx === 1) {
                 // if not exist set first as active
                 $activeObject = true;
             }
             // mark active tab
             if ($activeObject === true) {
                 $item['property']['class'] .= (Str::length($item['property']['class']) > 0 ? ' ' : null) . 'active';
             }
             // tab special properties for bootstrap
             $item['linkProperty']['aria-controls'] = $elements['tabAnchor'] . $tabIdx;
             $item['linkProperty']['role'] = 'tab';
             $item['linkProperty']['data-toggle'] = 'tab';
             $itemContent = $item['content'];
             unset($item['content']);
             $items[] = $item;
             // draw tab content
             $tabContent .= $dom->div(function () use($item, $itemContent) {
                 if ($item['html'] === true) {
                     if ($item['!secure'] === true) {
                         return $itemContent;
                     } else {
                         return self::safe($itemContent, true);
                     }
                 } else {
                     return self::nohtml($itemContent);
                 }
             }, ['role' => 'tabpanel', 'class' => 'tab-pane fade' . ($activeObject === true ? ' in active' : null), 'id' => $elements['tabAnchor'] . $tabIdx]);
             $tabIdx++;
         }
     }
     // check if global class "nav" isset
     if ($elements['property']['class'] !== null) {
         if (!Str::contains('nav ', $elements['property']['class'])) {
             $elements['property']['class'] = 'nav ' . $elements['property']['class'];
         }
     } else {
         $elements['property']['class'] = 'nav';
     }
     // render final output
     return $dom->div(function () use($elements, $items, $tabContent, $dom) {
         // drow listing
         $listing = Listing::display(['type' => 'ul', 'property' => $elements['property'], 'activeOrder' => $elements['activeOrder'], 'items' => $items]);
         // drow tabs if isset
         if ($tabContent !== null) {
             $tabContent = $dom->div(function () use($tabContent) {
                 return $tabContent;
             }, ['class' => 'tab-content']);
         }
         return $listing . $tabContent;
     }, $blockProperty);
 }