191 lines
No EOL
8.1 KiB
PHP
191 lines
No EOL
8.1 KiB
PHP
<?php
|
|
namespace App\Helper;
|
|
|
|
use App\Models\IQContentSiteField;
|
|
use App\Models\IQContentTree;
|
|
use App\Models\IQContentTreeNode;
|
|
|
|
class TreeHTML
|
|
{
|
|
|
|
private static $uri = null;
|
|
/**
|
|
* @param $feature
|
|
* @return string
|
|
*/
|
|
/*public static function makeAttrArray($array = array())
|
|
{
|
|
if(is_array($array)){
|
|
return htmlspecialchars(json_encode($array), ENT_QUOTES, 'UTF-8');
|
|
}
|
|
return "";
|
|
|
|
}*/
|
|
|
|
|
|
public static function makeNestableList(IQContentTree $iq_content_tree, $tree_node_id, $lvl = 0, $parent_id = false)
|
|
{
|
|
if ($parent_id) {
|
|
//where('active', true)
|
|
$tree_nodes = IQContentTreeNode::where('tree_id', $iq_content_tree->id)->where('lvl', $lvl)->where('parent_id', $parent_id)->orderBy('pos', 'ASC')->get();
|
|
} else {
|
|
$tree_nodes = IQContentTreeNode::where('tree_id', $iq_content_tree->id)->where('lvl', $lvl)->orderBy('pos', 'ASC')->get();
|
|
}
|
|
$out = "";
|
|
foreach ($tree_nodes as $node) {
|
|
$children = IQContentTreeNode::where('tree_id', $iq_content_tree->id)->where('lvl', $lvl + 1)->where('parent_id', $node->id)->count();
|
|
|
|
$out .= '<li class="dd-item dd-custom-drag-handle" data-id="' . $node->id . '">
|
|
<div class="dd-handle">
|
|
<span class="ion ion-md-expand text-secondary"></span>
|
|
</div>
|
|
<div class="dd-content">
|
|
<a href="' . route('iq_content_tree_detail', [$iq_content_tree->id, $node->id]) . '">
|
|
<div class="dd-content-link">
|
|
' . ($tree_node_id == $node->id ? '<strong> <i class="fa fa-chevron-right"></i> ' : '').$node->name.($tree_node_id == $node->id ? '</strong>' : '') . '
|
|
</div>
|
|
</a>
|
|
<div class="float-right">
|
|
' . ($node->iq_content_sites->count() ? '<span class="text-light">('.$node->iq_content_sites->count().')</span>' : '') . '
|
|
<a href="#" class="iq_update_data_load" data-action="node-set-active" data-target="self" data-url="'.route('iq_content_tree_detail', [$iq_content_tree->id, $node->id]).'">' . ($node->active ? '
|
|
<i class="fa fa-eye text-success"></i>' : '<i class="fa fa-eye-slash text-danger"></i>') . '
|
|
</a>
|
|
</div>
|
|
</div>';
|
|
|
|
if ($children) {
|
|
$out .= self::makeNestableList($iq_content_tree, $tree_node_id, $lvl + 1, $node->id);
|
|
}
|
|
$out .= '</li>';
|
|
}
|
|
return '<ol class="dd-list">' . $out . '</ol>';
|
|
}
|
|
|
|
|
|
public static function getUri()
|
|
{
|
|
if (strpos($_SERVER['REQUEST_URI'], "/") !== false) {
|
|
$uri = explode("/", $_SERVER['REQUEST_URI']);
|
|
$uri = array_filter($uri);
|
|
return $uri;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
|
|
public static function makeFrontendList(IQContentTree $iq_content_tree, $lvl = 0, $parent_id = false, $url = "", $categories = "")
|
|
{
|
|
|
|
if (self::$uri === null) {
|
|
self::$uri = self::getUri();
|
|
}
|
|
|
|
$link = false;
|
|
if (!empty(self::$uri[$lvl + 2])) {
|
|
$link = (self::$uri[$lvl + 2]);
|
|
}
|
|
if ($parent_id) {
|
|
//where('active', true)
|
|
$tree_nodes = IQContentTreeNode::where('tree_id', $iq_content_tree->id)->where('lvl', $lvl)->where('active', true)->where('parent_id', $parent_id)->orderBy('pos', 'ASC')->get();
|
|
} else {
|
|
|
|
$url = "/" . $iq_content_tree->identifier . "/";
|
|
$tree_nodes = IQContentTreeNode::where('tree_id', $iq_content_tree->id)->where('lvl', $lvl)->where('active', true)->orderBy('pos', 'ASC')->get();
|
|
}
|
|
$out = "";
|
|
$class = (!$link) ? 'active' : '';
|
|
|
|
foreach ($tree_nodes as $node) {
|
|
|
|
if($node->settings['show_in_navi'] == 'off'){
|
|
continue;
|
|
}
|
|
$children = IQContentTreeNode::where('tree_id', $iq_content_tree->id)->where('lvl', $lvl + 1)->where('active', true)->where('parent_id', $node->id)->count();
|
|
|
|
$class = ($link == $node->identifier) ? 'active' : '';
|
|
|
|
if ($lvl == 0) {
|
|
$out .= '<li class="nav-item mega-dropdown ' . $class . '">
|
|
<a class="nav-link dropdown-toggle px-md-3 px-lg-4" href="' . url($url . $node->identifier) . '" data-toggle="mega-dropdown" data-trigger="hover">' . $node->name . '</a>
|
|
<div class="dropdown-menu p-0 mt-2 overflow-hidden">
|
|
<div class="row no-gutters row-bordered">
|
|
<div class="col-12 p-4">
|
|
<h6 class="small font-weight-bold text-expanded text-uppercase">'.$categories.'</h6>';
|
|
} else {
|
|
|
|
/*
|
|
$site_field = IQContentSiteField::findSiteField($node, 'main-navi', 'menu-navi-image');
|
|
|
|
$img_src = (isset($site_field->content) ? $site_field->content : '/images/navi_images-assets/titelbild.jpg');
|
|
$out .= ' <a href="' .url($url . $node->identifier). '" class="media align-items-center ui-bordered text-body py-2 px-2 mb-2 img-thumbnail-shadow ' . $class . '">
|
|
<img src="'.$img_src.'" alt="" class="d-block ui-w-60">
|
|
<span class="media-body font-weight-semibold ml-2">' . ($link == $node->identifier ? '<strong>' : '') . $node->name . '</span>' . ($link == $node->identifier ? '</strong>' : '') . '
|
|
</a>';
|
|
*/
|
|
}
|
|
|
|
if ($children && $lvl == 0) {
|
|
$out .= self::makeFrontendList($iq_content_tree, $lvl + 1, $node->id, $url . $node->identifier . "/", $categories);
|
|
|
|
}
|
|
if ($lvl == 0) {
|
|
$out .= ' </div>
|
|
</div>
|
|
</div>
|
|
</li>';
|
|
}
|
|
|
|
}
|
|
return $out;
|
|
}
|
|
|
|
public static function makeFrontendListFooter(IQContentTree $iq_content_tree, $lvl = 0, $parent_id = false, $url = "")
|
|
{
|
|
|
|
if (self::$uri === null) {
|
|
self::$uri = self::getUri();
|
|
}
|
|
|
|
$link = false;
|
|
if (!empty(self::$uri[$lvl + 2])) {
|
|
$link = (self::$uri[$lvl + 2]);
|
|
}
|
|
if ($parent_id) {
|
|
//where('active', true)
|
|
$tree_nodes = IQContentTreeNode::where('tree_id', $iq_content_tree->id)->where('lvl', $lvl)->where('active', true)->where('parent_id', $parent_id)->orderBy('pos', 'ASC')->get();
|
|
} else {
|
|
|
|
$url = "/" . $iq_content_tree->identifier . "/";
|
|
$tree_nodes = IQContentTreeNode::where('tree_id', $iq_content_tree->id)->where('lvl', $lvl)->where('active', true)->orderBy('pos', 'ASC')->get();
|
|
}
|
|
$out = "";
|
|
$class = (!$link) ? 'active' : '';
|
|
|
|
foreach ($tree_nodes as $node) {
|
|
if($node->settings['show_in_navi'] == 'off'){
|
|
continue;
|
|
}
|
|
$children = IQContentTreeNode::where('tree_id', $iq_content_tree->id)->where('lvl', $lvl + 1)->where('active', true)->where('parent_id', $node->id)->count();
|
|
|
|
$class = ($link == $node->identifier) ? 'active' : '';
|
|
|
|
if ($lvl == 0) {
|
|
$out .= '<div class="col-12 col-sm-3 col-md pb-4 border-left-white">
|
|
<div class="footer-text small font-weight-bold mb-3 text-uppercase">' . $node->name . '</div>';
|
|
} else {
|
|
$out .= '<a href="' . url($url . $node->identifier) . '" class="footer-link d-block pb-2">' . ($link == $node->identifier ? '<strong>' : '') . $node->name . '</span>' . ($link == $node->identifier ? '</strong>' : '') . '</a>';
|
|
}
|
|
|
|
if ($children && $lvl == 0) {
|
|
$out .= self::makeFrontendListFooter($iq_content_tree, $lvl + 1, $node->id, $url . $node->identifier . "/");
|
|
|
|
}
|
|
if ($lvl == 0) {
|
|
$out .= '</div>';
|
|
}
|
|
|
|
}
|
|
return $out;
|
|
}
|
|
|
|
} |