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