|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Module: SmartFAQ |
|
5
|
|
|
* Author: The SmartFactory <www.smartfactory.ca> |
|
6
|
|
|
* Licence: GNU |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
use Xmf\Request; |
|
10
|
|
|
use XoopsModules\Smartfaq; |
|
11
|
|
|
use XoopsModules\Smartfaq\Constants; |
|
12
|
|
|
use XoopsModules\Smartfaq\Helper; |
|
13
|
|
|
|
|
14
|
|
|
$GLOBALS['xoopsOption']['template_main'] = 'smartfaq_category.tpl'; |
|
15
|
|
|
|
|
16
|
|
|
require_once __DIR__ . '/header.php'; |
|
17
|
|
|
|
|
18
|
|
|
/** @var Smartfaq\Helper $helper */ |
|
19
|
|
|
$helper = Helper::getInstance(); |
|
20
|
|
|
|
|
21
|
|
|
global $xoopsConfig, $xoopsModule; |
|
22
|
|
|
|
|
23
|
|
|
require_once XOOPS_ROOT_PATH . '/header.php'; |
|
24
|
|
|
require_once __DIR__ . '/footer.php'; |
|
25
|
|
|
|
|
26
|
|
|
$categoryid = Request::getInt('categoryid', 0, 'GET'); |
|
27
|
|
|
|
|
28
|
|
|
// Creating the category object for the selected category |
|
29
|
|
|
$categoryObj = new Smartfaq\Category($categoryid); |
|
30
|
|
|
|
|
31
|
|
|
// If the selected category was not found, exit |
|
32
|
|
|
if ($categoryObj->notLoaded()) { |
|
33
|
|
|
redirect_header('<script>javascript:history.go(-1)</script>', 1, _MD_SF_NOCATEGORYSELECTED); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
// Check user permissions to access this category |
|
37
|
|
|
if (!$categoryObj->checkPermission()) { |
|
38
|
|
|
redirect_header('<script>javascript:history.go(-1)</script>', 1, _NOPERM); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
// Creating the category handler object |
|
42
|
|
|
/** @var \XoopsModules\Smartfaq\CategoryHandler $categoryHandler */ |
|
43
|
|
|
$categoryHandler = Helper::getInstance()->getHandler('Category'); |
|
44
|
|
|
|
|
45
|
|
|
// At which record shall we start |
|
46
|
|
|
$start = Request::getInt('start', 0, 'GET'); |
|
47
|
|
|
|
|
48
|
|
|
// Creating the faq handler object |
|
49
|
|
|
/** @var \XoopsModules\Smartfaq\FaqHandler $faqHandler */ |
|
50
|
|
|
$faqHandler = Helper::getInstance()->getHandler('Faq'); |
|
51
|
|
|
|
|
52
|
|
|
// creating the FAQ objects that belong to the selected category |
|
53
|
|
|
$faqsObj = $faqHandler->getFaqs($helper->getConfig('indexperpage'), $start, Constants::SF_STATUS_OPENED, $categoryid); |
|
54
|
|
|
|
|
55
|
|
|
$totalQnasOnPage = 0; |
|
56
|
|
|
if ($faqsObj) { |
|
57
|
|
|
$totalQnasOnPage = count($faqsObj); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
// If there is no Q&As to display, exit |
|
61
|
|
|
/*if ($totalQnasOnPage == 0) { |
|
62
|
|
|
redirect_header("javascript:history.go(-1)", 2, _AM_SF_NO_TOP_PERMISSIONS); |
|
63
|
|
|
}*/ |
|
64
|
|
|
|
|
65
|
|
|
// Arrays that will hold the information passed on to smarty variables |
|
66
|
|
|
$category = []; |
|
67
|
|
|
$qnas = []; |
|
68
|
|
|
$last_qnaObj = $faqHandler->getLastPublishedByCat([Constants::SF_STATUS_OPENED]); |
|
69
|
|
|
if (isset($last_qnaObj[$categoryid])) { |
|
70
|
|
|
$categoryObj->setVar('last_faqid', $last_qnaObj[$categoryid]->getVar('faqid')); |
|
71
|
|
|
$categoryObj->setVar('last_question_link', "<a href='faq.php?faqid=" . $last_qnaObj[$categoryid]->getVar('faqid') . "'>" . $last_qnaObj[$categoryid]->question(50) . '</a>'); |
|
72
|
|
|
} |
|
73
|
|
|
// Populating the smarty variables with information related to the selected category |
|
74
|
|
|
$category = $categoryObj->toArray(null, true); |
|
75
|
|
|
$totalQnas = $categoryHandler->faqsCount(0, [Constants::SF_STATUS_OPENED]); |
|
|
|
|
|
|
76
|
|
|
$category['categoryPath'] = $categoryObj->getCategoryPath(false, true); |
|
77
|
|
|
|
|
78
|
|
|
// Creating the sub-categories objects that belong to the selected category |
|
79
|
|
|
$subcatsObj = &$categoryHandler->getCategories(0, 0, $categoryid); |
|
80
|
|
|
$total_subcats = count($subcatsObj); |
|
81
|
|
|
$catQnasWithSub = 0; |
|
82
|
|
|
if (0 != $total_subcats) { |
|
83
|
|
|
$faqHandler = Helper::getInstance()->getHandler('Faq'); |
|
84
|
|
|
// Arrays that will hold the information passed on to smarty variables |
|
85
|
|
|
foreach ($subcatsObj as $key => $subcat) { |
|
86
|
|
|
$subcat_id = $subcat->getVar('categoryid'); |
|
87
|
|
|
if (isset($totalQnas[$subcat_id]) && $totalQnas[$subcat_id] > 0) { |
|
88
|
|
|
if (isset($last_qnaObj[$subcat_id])) { |
|
89
|
|
|
$subcat->setVar('last_faqid', $last_qnaObj[$subcat_id]->getVar('faqid')); |
|
90
|
|
|
$subcat->setVar('last_question_link', "<a href='faq.php?faqid=" . $last_qnaObj[$subcat_id]->getVar('faqid') . "'>" . $last_qnaObj[$subcat_id]->question(50) . '</a>'); |
|
91
|
|
|
} |
|
92
|
|
|
$subcat->setVar('faqcount', $totalQnas[$subcat_id]); |
|
93
|
|
|
$subcats[$subcat_id] = $subcat->toArray(null, true); |
|
94
|
|
|
$catQnasWithSub += $subcats[$subcat_id]['total']; |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
$xoopsTpl->assign('subcats', $subcats); |
|
98
|
|
|
} |
|
99
|
|
|
$category['total'] = $catQnasWithSub + $totalQnas[$categoryid]; |
|
100
|
|
|
if ($faqsObj) { |
|
101
|
|
|
$userids = []; |
|
102
|
|
|
foreach ($faqsObj as $key => $thisfaq) { |
|
103
|
|
|
$faqids[] = $thisfaq->getVar('faqid'); |
|
104
|
|
|
$userids[$thisfaq->uid()] = 1; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** @var \XoopsMemberHandler $memberHandler */ |
|
108
|
|
|
$memberHandler = xoops_getHandler('member'); |
|
109
|
|
|
$users = $memberHandler->getUsers(new \Criteria('uid', '(' . implode(',', array_keys($userids)) . ')', 'IN'), true); |
|
110
|
|
|
foreach ($faqsObj as $iValue) { |
|
111
|
|
|
$faq = $iValue->toArray(null, $allcategories); |
|
112
|
|
|
|
|
113
|
|
|
$faq['adminlink'] = Smartfaq\Utility::getAdminLinks($iValue->faqid(), true); |
|
114
|
|
|
|
|
115
|
|
|
$faq['who_when'] = $iValue->getWhoAndWhen(null, $users); |
|
116
|
|
|
|
|
117
|
|
|
$xoopsTpl->append('faqs', $faq); |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
// Language constants |
|
121
|
|
|
$xoopsTpl->assign('whereInSection', htmlspecialchars($xoopsModule->getVar('name'), ENT_QUOTES | ENT_HTML5) . " > <a href='open_index.php'>" . _MD_SF_OPEN_SECTION . '</a>'); |
|
122
|
|
|
$xoopsTpl->assign('modulename', $xoopsModule->dirname()); |
|
123
|
|
|
|
|
124
|
|
|
$xoopsTpl->assign('displaylastfaqs', true); |
|
125
|
|
|
$xoopsTpl->assign('display_categoryname', false); |
|
126
|
|
|
|
|
127
|
|
|
$xoopsTpl->assign('lang_reads', _MD_SF_READS); |
|
128
|
|
|
$xoopsTpl->assign('lang_home', _MD_SF_HOME); |
|
129
|
|
|
$xoopsTpl->assign('lang_smartfaqs_info', _MD_SF_OPENED_INFO); |
|
130
|
|
|
$xoopsTpl->assign('lang_smartfaqs', _MD_SF_QUESTIONS); |
|
131
|
|
|
$xoopsTpl->assign('lang_cat_title', _MD_SF_OPENED_QUESTIONS); |
|
132
|
|
|
$xoopsTpl->assign('lang_subcat_title', _MD_SF_CATEGORY_SUMMARY); |
|
133
|
|
|
$xoopsTpl->assign('lang_category_summary', _MD_SF_CATEGORY_SUMMARY); |
|
134
|
|
|
$xoopsTpl->assign('lang_category_summary_info', _MD_SF_CATEGORY_SUMMARY_INFO); |
|
135
|
|
|
$xoopsTpl->assign('lang_category', _MD_SF_CATEGORY); |
|
136
|
|
|
|
|
137
|
|
|
// The Navigation Bar |
|
138
|
|
|
require_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
|
139
|
|
|
$pagenav = new \XoopsPageNav($totalQnas[$categoryid], $helper->getConfig('indexperpage'), $start, 'start', 'categoryid=' . $categoryObj->getVar('categoryid')); |
|
140
|
|
|
if (1 == $helper->getConfig('useimagenavpage')) { |
|
141
|
|
|
$category['navbar'] = '<div style="text-align:right;">' . $pagenav->renderImageNav() . '</div>'; |
|
142
|
|
|
} else { |
|
143
|
|
|
$category['navbar'] = '<div style="text-align:right;">' . $pagenav->renderNav() . '</div>'; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
$xoopsTpl->assign('category', $category); |
|
147
|
|
|
|
|
148
|
|
|
// Page Title Hack by marcan |
|
149
|
|
|
$module_name = htmlspecialchars($xoopsModule->getVar('name'), ENT_QUOTES | ENT_HTML5); |
|
150
|
|
|
$xoopsTpl->assign('xoops_pagetitle', $module_name . ' - ' . $category['name']); |
|
151
|
|
|
// End Page Title Hack by marcan |
|
152
|
|
|
|
|
153
|
|
|
require_once XOOPS_ROOT_PATH . '/footer.php'; |
|
154
|
|
|
|