XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
imagecategory.php
1<?php
10
11if (!defined('XOOPS_ROOT_PATH')) {
12 exit();
13}
14
16{
17 public $mImage = [];
18 public $_mImageLoadedFlag = false;
19
23 public $mReadGroups = [];
24 public $_mReadGroupsLoadedFlag = false;
25
29 public $mUploadGroups = [];
30 public $_mUploadGroupsLoadedFlag = false;
31
32
33 public function __construct()
34 {
35 static $initVars;
36 if (isset($initVars)) {
37 $this->mVars = $initVars;
38 return;
39 }
40 $this->initVar('imgcat_id', XOBJ_DTYPE_INT, '', false);
41 $this->initVar('imgcat_name', XOBJ_DTYPE_STRING, '', true, 100);
42 $this->initVar('imgcat_maxsize', XOBJ_DTYPE_INT, '1024000', true);
43 $this->initVar('imgcat_maxwidth', XOBJ_DTYPE_INT, '800', true);
44 $this->initVar('imgcat_maxheight', XOBJ_DTYPE_INT, '400', true);
45 $this->initVar('imgcat_display', XOBJ_DTYPE_BOOL, '1', true);
46 $this->initVar('imgcat_weight', XOBJ_DTYPE_INT, '0', true);
47 $this->initVar('imgcat_type', XOBJ_DTYPE_STRING, 'C', true, 1);
48 $this->initVar('imgcat_storetype', XOBJ_DTYPE_STRING, 'file', true, 5);
49 $initVars=$this->mVars;
50 }
51
52 public function loadImage()
53 {
54 if (false === $this->_mImageLoadedFlag) {
55 $handler =& xoops_getmodulehandler('image', 'legacy');
56 $this->mImage =& $handler->getObjects(new Criteria('imagecat_id', $this->get('imagecat_id')));
57 $this->_mImageLoadedFlag = true;
58 }
59 }
60
61 public function &createImage()
62 {
63 $handler =& xoops_getmodulehandler('image', 'legacy');
64 $obj =& $handler->create();
65 $obj->set('imagecat_id', $this->get('imagecat_id'));
66 return $obj;
67 }
68
69 public function getImageCount()
70 {
71 $handler =& xoops_getmodulehandler('image', 'legacy');
72 return $handler->getCount(new Criteria('imgcat_id', $this->get('imgcat_id')));
73 }
74
75 public function loadReadGroups()
76 {
77 if ($this->_mReadGroupsLoadedFlag) {
78 return;
79 }
80
81 $handler =& xoops_gethandler('groupperm');
82 $gidArr = $handler->getGroupIds('imgcat_read', $this->get('imgcat_id'));
83
84 $handler =& xoops_gethandler('group');
85 foreach ($gidArr as $gid) {
86 $object =& $handler->get($gid);
87
88 if (is_object($object)) {
89 $this->mReadGroups[] =& $object;
90 }
91
92 unset($object);
93 }
94
95 $this->_mReadGroupsLoadedFlag = true;
96 }
97
98 public function isLoadedReadGroups()
99 {
100 return $this->_mReadGroupsLoadedFlag;
101 }
102
108 public function hasReadPerm($groups)
109 {
110 $this->loadReadGroups();
111 foreach (array_keys($this->mReadGroups) as $key) {
112 foreach ($groups as $group) {
113 if ($this->mReadGroups[$key]->get('groupid') == $group) {
114 return true;
115 }
116 }
117 }
118
119 return false;
120 }
121
122 public function loadUploadGroups()
123 {
124 if ($this->_mUploadGroupsLoadedFlag) {
125 return;
126 }
127
128 $handler =& xoops_gethandler('groupperm');
129 $gidArr = $handler->getGroupIds('imgcat_write', $this->get('imgcat_id'));
130
131 $handler =& xoops_gethandler('group');
132 foreach ($gidArr as $gid) {
133 $object =& $handler->get($gid);
134
135 if (is_object($object)) {
136 $this->mUploadGroups[] =& $object;
137 }
138
139 unset($object);
140 }
141
142 $this->_mUploadGroupsLoadedFlag = true;
143 }
144
145 public function isLoadedUploadGroups()
146 {
147 return $this->_mUploadGroupsLoadedFlag;
148 }
149
150 public function hasUploadPerm($groups)
151 {
152 $this->loadUploadGroups();
153 foreach (array_keys($this->mUploadGroups) as $key) {
154 foreach ($groups as $group) {
155 if ($this->mUploadGroups[$key]->get('groupid') == $group) {
156 return true;
157 }
158 }
159 }
160
161 return false;
162 }
163}
164
166{
167 public $mTable = 'imagecategory';
168 public $mPrimary = 'imgcat_id';
169 public $mClass = 'LegacyImagecategoryObject';
170
171 public function insert(&$obj, $force = false)
172 {
173 $returnFlag = parent::insert($obj, $force);
174
175 $handler =& xoops_getmodulehandler('group_permission', 'legacy');
176
177 //
178 // If the object has groups which are allowed to read.
179 //
180 if ($obj->isLoadedReadGroups()) {
181 $criteria =new CriteriaCompo();
182 $criteria->add(new Criteria('gperm_itemid', $obj->get('imgcat_id')));
183 $criteria->add(new Criteria('gperm_modid', 1));
184 $criteria->add(new Criteria('gperm_name', 'imgcat_read'));
185 $handler->deleteAll($criteria);
186
187 foreach ($obj->mReadGroups as $group) {
188 $perm =& $handler->create();
189 $perm->set('gperm_groupid', $group->get('groupid'));
190 $perm->set('gperm_itemid', $obj->get('imgcat_id'));
191 $perm->set('gperm_modid', 1);
192 $perm->set('gperm_name', 'imgcat_read');
193
194 $returnFlag &= $handler->insert($perm, $force);
195 }
196 }
197
198 //
199 // If the object has groups which are allowed to upload.
200 //
201 if ($obj->isLoadedUploadGroups()) {
202 $criteria =new CriteriaCompo();
203 $criteria->add(new Criteria('gperm_itemid', $obj->get('imgcat_id')));
204 $criteria->add(new Criteria('gperm_modid', 1));
205 $criteria->add(new Criteria('gperm_name', 'imgcat_write'));
206 $handler->deleteAll($criteria);
207
208 foreach ($obj->mUploadGroups as $group) {
209 $perm =& $handler->create();
210 $perm->set('gperm_groupid', $group->get('groupid'));
211 $perm->set('gperm_itemid', $obj->get('imgcat_id'));
212 $perm->set('gperm_modid', 1);
213 $perm->set('gperm_name', 'imgcat_write');
214
215 $returnFlag &= $handler->insert($perm, $force);
216 }
217 }
218
219 return $returnFlag;
220 }
221
222 public function &getObjectsWithReadPerm($groups = [], $display = null)
223 {
224 $criteria = new CriteriaCompo();
225 if (null !== $display) {
226 $criteria->add(new Criteria('imgcat_display', $display));
227 }
228 $criteria->setSort('imgcat_weight');
229 $objs =& $this->getObjects($criteria);
230 unset($criteria);
231
232 $ret = [];
233 foreach (array_keys($objs) as $key) {
234 if ($objs[$key]->hasReadPerm($groups)) {
235 $ret[] =& $objs[$key];
236 }
237 }
238
239 return $ret;
240 }
241
242 public function delete(&$obj, $force = false)
243 {
244 $handler =& xoops_getmodulehandler('image', 'legacy');
245 $handler->deleteAll(new Criteria('imgcat_id', $obj->get('imgcat_id')));
246 unset($handler);
247
248 $handler =& xoops_getmodulehandler('group_permission', 'legacy');
249 $criteria =new CriteriaCompo();
250 $criteria->add(new Criteria('gperm_itemid', $obj->get('imgcat_id')));
251 $criteria->add(new Criteria('gperm_modid', 1));
252
253 $nameCriteria =new CriteriaCompo();
254 $nameCriteria->add(new Criteria('gperm_name', 'imgcat_read'));
255 $nameCriteria->add(new Criteria('gperm_name', 'imgcat_write'), 'OR');
256
257 $criteria->add($nameCriteria);
258
259 $handler->deleteAll($criteria);
260
261 return parent::delete($obj, $force);
262 }
263}
& getObjects($criteria=null, $limit=null, $start=null, $id_as_key=false)
Definition handler.php:83