Skip to content

Commit

Permalink
Use Registry class for reading section and topic parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
minitek committed Feb 23, 2022
1 parent 484f9a2 commit 30bc43c
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 372 deletions.
24 changes: 6 additions & 18 deletions site/layouts/fb_leftnav.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,13 @@
use Joomla\Component\FAQBookPro\Site\Helper\NavigationHelper;
use Joomla\Component\FAQBookPro\Site\Model\SectionModel;
use Joomla\Component\FAQBookPro\Site\Helper\RouteHelper;
use Joomla\Registry\Registry;

$sectionId = $displayData['sectionId'];
$visible = $displayData['visible'];
$section = Table::getInstance('SectionTable', 'Joomla\Component\FAQBookPro\Administrator\Table\\');
$section->load($sectionId);
$sectionParams = json_decode($section->attribs, false);

if (!isset($sectionParams->browse_topics))
{
$sectionParams->browse_topics = false;
}

$sectionParams = new Registry($section->attribs);
$user = Factory::getUser();
$userid = $user->id;
$sectionModel = new SectionModel;
Expand All @@ -50,19 +45,14 @@
$fb_minimized = '';
$minimized_icon = '<a class="NavLeftUL_toggle" href="#"><i class="fas fa-angle-double-left"></i></a>';
$section_title_html = '';
$visible_class = $visible ? '' : 'leftnav-hidden';

if ((!$is_minimized && $sectionParams->leftnav == '2') || $is_minimized == 'on')
if ((!$is_minimized && $sectionParams->get('leftnav', 1) == 2) || $is_minimized == 'on')
{
$fb_minimized = 'fb-minimized';
$minimized_icon = '<a class="NavLeftUL_toggle" href="#"><i class="fas fa-angle-double-right"></i></a>';
}

$visible_class = '';
if (!$visible)
{
$visible_class = 'leftnav-hidden';
}

?><div class="fbLeftNavigation_core fb-hidden <?php echo $fb_minimized; ?> <?php echo $visible_class; ?>"><?php

// Toggle left navigation
Expand All @@ -75,7 +65,6 @@
</div><?php

// Module position fb-nav-top
jimport('joomla.application.module.helper');
$modules_top = ModuleHelper::getModules('fb-nav-top');

if (count($modules_top))
Expand All @@ -92,9 +81,10 @@
<ul class="NavLeftUL_parent"><?php

// Browse Topics
if ($sectionParams->browse_topics && isset($topics_tree) && $topics_tree)
if ($sectionParams->get('browse_topics', 1) && isset($topics_tree) && $topics_tree)
{
$browse_topics_class = '';

if ($app->input->get('view', '') == 'section' && $app->input->get('tab', '') == 'topics')
{
$browse_topics_class = 'li_selected';
Expand All @@ -117,7 +107,6 @@

<div class="fbLeftNavigation_wrap">
<ul id="NavLeftUL" class="NavLeftUL_parent level0"><?php

// Topics
if (isset($topics_tree) && $topics_tree)
{
Expand All @@ -126,7 +115,6 @@
echo $topic_tree;
}
}

?></ul>
</div>
</div><?php
Expand Down
14 changes: 7 additions & 7 deletions site/layouts/fb_topnav.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* @title Minitek FAQ Book
* @copyright Copyright (C) 2011-2021 Minitek, All rights reserved.
* @copyright Copyright (C) 2011-2022 Minitek, All rights reserved.
* @license GNU General Public License version 3 or later.
* @author url https://www.minitek.gr/
* @developers Minitek.gr
Expand All @@ -16,6 +16,7 @@
use Joomla\Component\FAQBookPro\Site\Helper\UtilitiesHelper;
use Joomla\CMS\Table\Table;
use Joomla\Component\FAQBookPro\Site\Helper\RouteHelper;
use Joomla\Registry\Registry;

$sectionId = $displayData['sectionId'];
$params = UtilitiesHelper::getParams('com_faqbookpro');
Expand All @@ -29,11 +30,10 @@
$section = Table::getInstance('SectionTable', 'Joomla\Component\FAQBookPro\Administrator\Table\\');
$section->load($sectionId);
$sectionTitle = $section->title;
$sectionParams = json_decode($section->attribs, false);
$sectionParams = new Registry($section->attribs);
$menu = $app->getMenu();
$activeMenu = $menu->getActive();
$topnav_sections = isset($sectionParams->topnav_sections) ? $sectionParams->topnav_sections : false;
$home_itemid = isset($sectionParams->topnav_root) ? $sectionParams->topnav_root : $activeMenu->id;
$home_itemid = $sectionParams->get('topnav_root', '') ? $sectionParams->get('topnav_root', '') : $activeMenu->id;
$home_menuitem = $menu->getItem($home_itemid);
$home_title = $home_menuitem->title;
}
Expand All @@ -52,7 +52,7 @@
<div class="fbTopNavigation_wrap">
<ul class="fbTopNavigation_root fb-hidden-phone"><?php
// Sections link
if (($view != 'profile' || $sectionId) && $topnav_sections)
if (($view != 'profile' || $sectionId) && $sectionParams->get('topnav_sections', 0))
{
?><li class="NavTopUL_home"><a class="NavTopUL_link NavTopUL_sections" href="<?php echo Route::_(RouteHelper::getSectionsRoute($home_itemid)); ?>">
<i class="fas fa-home NavTopUL_homeIcon"></i><?php echo $home_title; ?></a></li>
Expand All @@ -65,7 +65,7 @@
?><li id="top_liid_home" class="NavTopUL_item NavTopUL_section NavTopUL_firstChild <?php echo $class; ?>">
<a class="NavTopUL_link" href="<?php echo Route::_(RouteHelper::getSectionRoute($sectionId)); ?>" onclick="return false;"><?php

if ($topnav_sections)
if ($sectionParams->get('topnav_sections', 0))
{
?><i class="fas fa-caret-right NavTopUL_homeIcon"></i><?php echo $sectionTitle;
}
Expand Down Expand Up @@ -96,7 +96,7 @@

<div class="NavTopUL_buttons"><?php
// Menu button
if ((isset($sectionParams->leftnav) && $sectionParams->leftnav) || !$sectionId)
if ($view != 'profile' && ($sectionParams->get('leftnav', 1) || !$sectionId))
{
?><a href="#" onclick="return false;" class="show_menu btn btn-outline-primary btn-mfb"><i class="fas fa-bars"></i></a><?php
}
Expand Down
11 changes: 6 additions & 5 deletions site/src/Helper/NavigationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Joomla\Component\FAQBookPro\Site\Model\TopicModel;
use Joomla\CMS\Table\Table;
use Joomla\Component\FAQBookPro\Site\Helper\RouteHelper;
use Joomla\Registry\Registry;

/**
* FAQ Book Component Navigation Helper.
Expand All @@ -27,7 +28,7 @@ abstract class NavigationHelper
public static function getTopicsTree($item, $level = 1)
{
$topicModel = new TopicModel;
$topicParams = json_decode($item->params, false);
$topicParams = new Registry($item->params);
$output = '';
$subitems = $topicModel->getTopicChildren($item->id);

Expand All @@ -54,9 +55,9 @@ public static function getTopicsTree($item, $level = 1)
$output .= '<a href="'.Route::_(RouteHelper::getTopicRoute($item->id)).'" class="NavLeftUL_anchor" onclick="return false;">';
$output .= '<span class="topicTitle">';

if (isset($topicParams->topic_icon_class) && $topicParams->topic_icon_class)
if ($topicParams->get('topic_icon_class', ''))
{
$output .= '<i class="NavLeftUL_topicIcon fas fa-'.$topicParams->topic_icon_class.'"></i>';
$output .= '<i class="NavLeftUL_topicIcon fas fa-'.$topicParams->get('topic_icon_class', '').'"></i>';
}

$output .= $item->title;
Expand Down Expand Up @@ -100,9 +101,9 @@ public static function getTopicsTree($item, $level = 1)
$output .= '<a href="'.Route::_(RouteHelper::getTopicRoute($item->id)).'" class="NavLeftUL_anchor" onclick="return false;">';
$output .= '<span class="topicTitle">';

if (isset($topicParams->topic_icon_class) && $topicParams->topic_icon_class)
if ($topicParams->get('topic_icon_class', ''))
{
$output .= '<i class="NavLeftUL_topicIcon fas fa-'.$topicParams->topic_icon_class.'"></i>';
$output .= '<i class="NavLeftUL_topicIcon fas fa-'.$topicParams->get('topic_icon_class', '').'"></i>';
}

$icon = '<div class="NavLeftUL_endpointIcon">'.
Expand Down
10 changes: 5 additions & 5 deletions site/src/Model/SectionModel.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* @title Minitek FAQ Book
* @copyright Copyright (C) 2011-2020 Minitek, All rights reserved.
* @copyright Copyright (C) 2011-2022 Minitek, All rights reserved.
* @license GNU General Public License version 3 or later.
* @author url https://www.minitek.gr/
* @developers Minitek.gr
Expand All @@ -17,6 +17,7 @@
use Joomla\Component\FAQBookPro\Site\Helper\UtilitiesHelper;
use Joomla\CMS\Language\Multilanguage;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\Registry\Registry;

/**
* FAQ Book Component Section Model
Expand Down Expand Up @@ -172,10 +173,9 @@ public function getSectionTopics($sectionId)

// Ordering
$section = $this->getItem($sectionId);
$sectionParams = json_decode($section->attribs, false);
$ordering = isset($sectionParams->topics_ordering) ? 'c.'.$sectionParams->topics_ordering : 'c.lft';
$ordering_dir = isset($sectionParams->topics_ordering_dir) ? $sectionParams->topics_ordering_dir : 'ASC';
$query->order($ordering.' '.$ordering_dir);
$sectionParams = new Registry($section->attribs);
$ordering = 'c.'.$sectionParams->get('topics_ordering', 'lft');
$ordering_dir = $sectionParams->get('topics_ordering_dir', 'ASC');

// Get the results
$db->setQuery($query);
Expand Down
2 changes: 1 addition & 1 deletion site/src/Model/TopicModel.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* @title Minitek FAQ Book
* @copyright Copyright (C) 2011-2020 Minitek, All rights reserved.
* @copyright Copyright (C) 2011-2022 Minitek, All rights reserved.
* @license GNU General Public License version 3 or later.
* @author url https://www.minitek.gr/
* @developers Minitek.gr
Expand Down
Loading

0 comments on commit 30bc43c

Please sign in to comment.