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