|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace XoopsModules\Mylinks; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* MyLinks category.php |
|
7
|
|
|
* |
|
8
|
|
|
* Xoops mylinks - a multicategory links module |
|
9
|
|
|
* |
|
10
|
|
|
* You may not change or alter any portion of this comment or credits |
|
11
|
|
|
* of supporting developers from this source code or any supporting source code |
|
12
|
|
|
* which is considered copyrighted (c) material of the original comment or credit authors. |
|
13
|
|
|
* This program is distributed in the hope that it will be useful, |
|
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
16
|
|
|
* |
|
17
|
|
|
* @copyright :: © ZySpec Incorporated |
|
18
|
|
|
* @license :: {@link https://www.gnu.org/licenses/gpl-2.0.html GNU Public License} |
|
19
|
|
|
* @package :: mylinks |
|
20
|
|
|
* @subpackage:: class |
|
21
|
|
|
* @since :: File available since version 3.11 |
|
22
|
|
|
* @author :: zyspec ([email protected]) |
|
23
|
|
|
*/ |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
$mylinksDir = basename(dirname(__DIR__)); |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Class mylinksCategoryHandler_base |
|
31
|
|
|
*/ |
|
32
|
|
|
class CategoryHandler extends \XoopsPersistableObjectHandler |
|
33
|
|
|
{ |
|
34
|
|
|
/** |
|
35
|
|
|
* @param \XoopsDatabase|null $db |
|
36
|
|
|
*/ |
|
37
|
|
|
public function mylinksCategoryHandler(\XoopsDatabase $db = null) |
|
38
|
|
|
{ |
|
39
|
|
|
$this->__construct($db); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* mylinksCategoryHandler_base constructor. |
|
44
|
|
|
* @param \XoopsDatabase|null $db |
|
45
|
|
|
*/ |
|
46
|
|
|
public function __construct(\XoopsDatabase $db = null) |
|
47
|
|
|
{ |
|
48
|
|
|
$mylinksDir = basename(dirname(__DIR__)); |
|
|
|
|
|
|
49
|
|
|
parent::__construct($db, 'mylinks_cat', Category::class, 'cid'); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Retrieve category names from Database |
|
54
|
|
|
* @param unknown $cats - integer, returns single category name, |
|
|
|
|
|
|
55
|
|
|
* array returns array of category names |
|
56
|
|
|
* NULL return all category names |
|
57
|
|
|
* @return array return category titles with category ID as key |
|
58
|
|
|
*/ |
|
59
|
|
|
public function getCatTitles($cats = null) |
|
60
|
|
|
{ |
|
61
|
|
|
$catTitles = []; |
|
|
|
|
|
|
62
|
|
|
$criteria = new \CriteriaCompo(); |
|
63
|
|
|
if (isset($cats) && is_array($cats)) { |
|
|
|
|
|
|
64
|
|
|
$catIdString = !empty($cats) ? '(' . implode(',', $cats) . ')' : ''; |
|
65
|
|
|
if ($catIdString) { |
|
66
|
|
|
$criteria->add(new \Criteria('cid', $catIdString, 'IN')); |
|
67
|
|
|
} |
|
68
|
|
|
} elseif (isset($cats) && ((int)$cats > 0)) { |
|
69
|
|
|
$criteria->add(new \Criteria('cid', (int)$cats, '=')); |
|
70
|
|
|
} |
|
71
|
|
|
$catFields = ['title']; |
|
72
|
|
|
$categoryArray = $this->getAll($criteria, $catFields, false); |
|
73
|
|
|
$catTitles = []; |
|
74
|
|
|
if (is_array($categoryArray) && count($categoryArray)) { |
|
75
|
|
|
foreach ($categoryArray as $catItem) { |
|
76
|
|
|
$catTitles[$catItem['cid']] = $catItem['title']; |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
return $catTitles; |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
//eval('class ' . $mylinksDir . 'Category extends CategoryBase |
|
85
|
|
|
// { |
|
86
|
|
|
// } |
|
87
|
|
|
// |
|
88
|
|
|
// class ' . $mylinksDir . 'CategoryHandler extends mylinksCategoryHandler_base |
|
89
|
|
|
// { |
|
90
|
|
|
// } |
|
91
|
|
|
// '); |
|
92
|
|
|
|