|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
You may not change or alter any portion of this comment or credits |
|
4
|
|
|
of supporting developers from this source code or any supporting source code |
|
5
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
|
6
|
|
|
|
|
7
|
|
|
This program is distributed in the hope that it will be useful, |
|
8
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
9
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Alumni module for Xoops |
|
14
|
|
|
* |
|
15
|
|
|
* @copyright XOOPS Project https://xoops.org/ |
|
16
|
|
|
* @license GPL 2.0 or later |
|
17
|
|
|
* @package alumni |
|
18
|
|
|
* @since 2.6.x |
|
19
|
|
|
* @author John Mordo (jlm69) |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
use Xoops\Core\Database\Connection; |
|
23
|
|
|
use Xoops\Core\Kernel\XoopsObject; |
|
24
|
|
|
use Xoops\Core\Kernel\XoopsPersistableObjectHandler; |
|
25
|
|
|
use Xoops\Core\Kernel\Criteria; |
|
26
|
|
|
use Xoops\Core\Kernel\CriteriaCompo; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Class AlumniCategory |
|
30
|
|
|
*/ |
|
31
|
|
|
class AlumniCategory extends XoopsObject |
|
|
|
|
|
|
32
|
|
|
{ |
|
33
|
|
|
public $alumni = null; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var array |
|
37
|
|
|
*/ |
|
38
|
|
|
public $_categoryPath = false; |
|
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
//Constructor |
|
41
|
|
|
public function __construct() |
|
42
|
|
|
{ |
|
43
|
|
|
$this->alumni = Alumni::getInstance(); |
|
44
|
|
|
$this->initVar('cid', XOBJ_DTYPE_INT, null, false, 11); |
|
45
|
|
|
$this->initVar('pid', XOBJ_DTYPE_INT, null, false, 5); |
|
46
|
|
|
$this->initVar('title', XOBJ_DTYPE_TXTBOX, null, false, 255); |
|
47
|
|
|
$this->initVar('scaddress', XOBJ_DTYPE_TXTBOX, null, false, 255); |
|
48
|
|
|
$this->initVar('scaddress2', XOBJ_DTYPE_TXTBOX, null, false, 255); |
|
49
|
|
|
$this->initVar('sccity', XOBJ_DTYPE_TXTBOX, null, false, 255); |
|
50
|
|
|
$this->initVar('scstate', XOBJ_DTYPE_TXTBOX, null, false, 255); |
|
51
|
|
|
$this->initVar('sczip', XOBJ_DTYPE_TXTBOX, null, false, 255); |
|
52
|
|
|
$this->initVar('scphone', XOBJ_DTYPE_TXTBOX, null, false, 255); |
|
53
|
|
|
$this->initVar('scfax', XOBJ_DTYPE_TXTBOX, null, false, 255); |
|
54
|
|
|
$this->initVar('scmotto', XOBJ_DTYPE_TXTBOX, null, false, 255); |
|
55
|
|
|
$this->initVar('scurl', XOBJ_DTYPE_TXTBOX, null, false, 255); |
|
56
|
|
|
$this->initVar('img', XOBJ_DTYPE_TXTBOX, null, false, 255); |
|
57
|
|
|
$this->initVar('scphoto', XOBJ_DTYPE_TXTBOX, null, false, 255); |
|
58
|
|
|
$this->initVar('ordre', XOBJ_DTYPE_INT, null, false, 5); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @param null|int $id |
|
63
|
|
|
* @param string $path |
|
64
|
|
|
* @return string |
|
65
|
|
|
*/ |
|
66
|
|
|
public function getPathFromId($id = null, $path = '') |
|
67
|
|
|
{ |
|
68
|
|
|
$id = null !== $id ? (int)$id : $this->cid; |
|
|
|
|
|
|
69
|
|
|
$myts = MyTextSanitizer::getInstance(); |
|
70
|
|
|
$name = $myts->htmlSpecialChars($this->title); |
|
71
|
|
|
$path = "/{$name}{$path}"; |
|
72
|
|
|
if (0 != $this->pid) { |
|
73
|
|
|
$path = $this->getPathFromId($this->pid, $path); |
|
74
|
|
|
} |
|
75
|
|
|
return $path; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @return array |
|
80
|
|
|
*/ |
|
81
|
|
|
public function getGroups_view() |
|
|
|
|
|
|
82
|
|
|
{ |
|
83
|
|
|
return $this->alumni->getPermissionHandler()->getGrantedGroupsById('alumni_view', $this->getVar('cid')); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Class AlumniCategoryHandler |
|
89
|
|
|
*/ |
|
90
|
|
|
class AlumniCategoryHandler extends XoopsPersistableObjectHandler |
|
|
|
|
|
|
91
|
|
|
{ |
|
92
|
|
|
public $alumni = null; |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* AlumniCategoryHandler constructor. |
|
96
|
|
|
* @param \Xoops\Core\Database\Connection|null $db |
|
97
|
|
|
*/ |
|
98
|
|
|
public function __construct(Connection $db = null) |
|
|
|
|
|
|
99
|
|
|
{ |
|
100
|
|
|
$this->alumni = Alumni::getInstance(); |
|
101
|
|
|
parent::__construct($db, 'alumni_category', 'alumnicategory', 'cid', 'title'); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @param $by_cat |
|
106
|
|
|
* @param $level |
|
107
|
|
|
* @param $cat_array |
|
108
|
|
|
* @param $cat_result |
|
109
|
|
|
*/ |
|
110
|
|
|
public function getSubCatArray($by_cat, $level, $cat_array, $cat_result) |
|
|
|
|
|
|
111
|
|
|
{ |
|
112
|
|
|
global $theresult; |
|
|
|
|
|
|
113
|
|
|
$spaces = ''; |
|
114
|
|
|
for ($j = 0; $j < $level; ++$j) { |
|
115
|
|
|
$spaces .= '--'; |
|
116
|
|
|
} |
|
117
|
|
|
$theresult[$by_cat['cid']] = $spaces . $by_cat['title']; |
|
|
|
|
|
|
118
|
|
|
if (isset($cat_array[$by_cat['cid']])) { |
|
|
|
|
|
|
119
|
|
|
$level = ++$level; |
|
120
|
|
|
foreach ($cat_array[$by_cat['cid']] as $cat) { |
|
|
|
|
|
|
121
|
|
|
$this->getSubCatArray($cat, $level, $cat_array, $cat_result); |
|
|
|
|
|
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* @param int $pid |
|
128
|
|
|
* @return int |
|
129
|
|
|
*/ |
|
130
|
|
|
public function getCategoriesCount($pid = 0) |
|
131
|
|
|
{ |
|
132
|
|
|
$xoops = Xoops::getInstance(); |
|
133
|
|
|
if ($pid == -1) { |
|
134
|
|
|
return $this->getCount(); |
|
135
|
|
|
} |
|
136
|
|
|
$criteria = new CriteriaCompo(); |
|
137
|
|
|
if (null !== $pid && ($pid != -1)) { |
|
138
|
|
|
$criteria->add(new criteria('pid', $pid)); |
|
139
|
|
|
if (!$xoops->userIsAdmin) { |
|
140
|
|
|
$categoriesGranted = $this->alumni->getPermissionHandler()->getGrantedItems('alumni_view'); |
|
141
|
|
|
if (count($categoriesGranted) > 0) { |
|
142
|
|
|
$criteria->add(new Criteria('cid', '(' . implode(',', $categoriesGranted) . ')', 'IN')); |
|
143
|
|
|
} else { |
|
144
|
|
|
return 0; |
|
145
|
|
|
} |
|
146
|
|
|
} |
|
147
|
|
|
} |
|
148
|
|
|
return $this->getCount($criteria); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* @return array |
|
153
|
|
|
*/ |
|
154
|
|
|
public function &getCategoriesForSearch() |
|
155
|
|
|
{ |
|
156
|
|
|
global $theresult, $xoops, $alumni; |
|
|
|
|
|
|
157
|
|
|
$xoops = Xoops::getInstance(); |
|
158
|
|
|
$alumni = Alumni::getInstance(); |
|
159
|
|
|
$moduleId = $alumni->getModule()->mid(); |
|
160
|
|
|
$ret = []; |
|
161
|
|
|
$criteria = new CriteriaCompo(); |
|
162
|
|
|
$criteria->setSort('cid'); |
|
163
|
|
|
$criteria->setOrder('ASC'); |
|
164
|
|
|
if (!$xoops->isAdmin()) { |
|
165
|
|
|
// $gperm_handler = $xoops->gethandler('groupperm'); |
|
|
|
|
|
|
166
|
|
|
$groups = is_object($xoops->isUser()) ? $$xoops->isUser()->getGroups() : '3'; |
|
167
|
|
|
$allowedCategoriesIds = $alumni->getGrouppermHandler()->getItemIds('alumni_view', $groups, $moduleId); |
|
168
|
|
|
$criteria->add(new Criteria('cid', '(' . implode(',', $allowedCategoriesIds) . ')', 'IN')); |
|
169
|
|
|
} |
|
170
|
|
|
$categories = $this->getAll($criteria, ['cid', 'pid', 'title'], false, false); |
|
171
|
|
|
if (0 == count($categories)) { |
|
172
|
|
|
return $ret; |
|
173
|
|
|
} |
|
174
|
|
|
$cat_array = []; |
|
|
|
|
|
|
175
|
|
|
foreach ($categories as $cat) { |
|
176
|
|
|
$cat_array[$cat['pid']][$cat['cid']] = $cat; |
|
|
|
|
|
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
if (!isset($cat_array[0])) { |
|
|
|
|
|
|
180
|
|
|
return $ret; |
|
181
|
|
|
} |
|
182
|
|
|
$cat_result = []; |
|
|
|
|
|
|
183
|
|
|
foreach ($cat_array[0] as $thecat) { |
|
|
|
|
|
|
184
|
|
|
$level = 0; |
|
185
|
|
|
$this->getSubCatArray($thecat, $level, $cat_array, $cat_result); |
|
|
|
|
|
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
return $theresult; |
|
189
|
|
|
} |
|
190
|
|
|
} |
|
191
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.