XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
AbstractClientObjectHandler.class.php
1<?php
12
13if (!defined('XOOPS_ROOT_PATH')) {
14 exit;
15}
16
17
19{
20 protected $_mClientField = ['title' =>'title', 'category' =>'category_id', 'posttime' =>'posttime'];
21 protected $_mClientConfig = ['tag' =>'tag_dirname', 'image' =>'use_image', 'workflow' =>'use_workflow', 'activity' =>'use_activity', 'map' =>'use_map'];
22
30 protected function _getTagList(/*** XoopsSimpleObject ***/ $obj)
31 {
32 return $obj->mTag;
33 }
34
43 public function insert(/*** XoopsSimpleObject ***/ &$obj, /*** bool ***/ $force=false)
44 {
45 $ret = parent::insert($obj, $force);
46 if (true == $ret) {
47 $ret = $this->_setClientData($obj);
48 }
49
50 return $ret;
51 }
52
61 public function delete(/*** XoopsSimpleObject ***/ &$obj, /*** bool ***/ $force=false)
62 {
63 $ret = parent::delete($obj, $force);
64 $this->_deleteClientData($obj);
65
66 return $ret;
67 }
68
76 protected function _setClientData(/*** XoopsSimpleObject ***/ $obj)
77 {
78 $handler = xoops_gethandler('config');
79 $conf = $handler->getConfigsByDirname($obj->getDirname());
80
81 $ret = true;
82 if (true === $this->_isActivityClient($conf)) {
83 if (false === $this->_saveActivity($obj)) {
84 $ret = false;
85 }
86 }
87
88 if (true === $this->_isTagClient($conf)) {
89 if (false === $this->_saveTags($obj, $conf[$this->_mClientConfig['tag']])) {
90 $ret = false;
91 }
92 }
93
94 if (true === $this->_isImageClient($conf)) {
95 if (false === $this->_saveImages($obj)) {
96 $ret = false;
97 }
98 }
99
100 if (true === $this->_isMapClient($conf)) {
101 if (false === $this->_saveMap($obj)) {
102 $ret = false;
103 }
104 }
105
106 return $ret;
107 }
108
116 protected function _deleteClientData(/*** XoopsSimpleObject ***/ $obj)
117 {
118 $tagDirname = null;
119 $handler = xoops_gethandler('config');
120 $conf = $handler->getConfigsByDirname($obj->getDirname());
121
122 $ret = true;
123 if (true === $this->_isActivityClient($conf)) {
124 if (false === $this->_deleteActivity($obj)) {
125 $ret = false;
126 }
127 }
128
129 if (true === $this->_isTagClient($conf)) {
130 if (false === $this->_deleteTags($obj, $tagDirname)) {
131 $ret = false;
132 }
133 }
134
135 if (true === $this->_isWorkflowClient($conf)) {
136 $ret = $this->_deleteWorkflow($obj);
137 }
138
139 if (true === $this->_isImageClient($conf)) {
140 if (false === $this->_deleteImages($obj)) {
141 $ret = false;
142 }
143 }
144 return $ret;
145 }
146
154 protected function _saveActivity(/*** XoopsSimpleObject ***/ $obj)
155 {
156 $ret = false;
157 XCube_DelegateUtils::call(
158 'Legacy_Activity.AddActivity',
159 new XCube_Ref($ret),
160 $obj->get('uid'),
161 $obj->get($this->_mClientField['category']),
162 $obj->getDirname(),
163 $this->getDataname(),
164 $obj->get($this->mPrimary),
165 $obj->get($this->_mClientField['posttime'])
166 );
167 return $ret;
168 }
169
178 protected function _saveTags(/*** XoopsSimpleObject ***/ $obj, /*** string ***/ $tagDirname)
179 {
180 $ret = false;
181 XCube_DelegateUtils::call('Legacy_Tag.'.$tagDirname.'.SetTags',
182 new XCube_Ref($ret),
183 $tagDirname,
184 $obj->getDirname(),
185 $this->getDataname(),
186 $obj->get($this->mPrimary),
187 $obj->get($this->_mClientField['posttime']),
188 $this->_getTagList($obj)
189 );
190 return $ret;
191 }
192
200 protected function _saveImages(/*** Legacy_AbstractObject ***/ $obj)
201 {
202 $ret = true;
203 $obj->setupImages();
204 foreach ($obj->mImage as $image) {
205 $result = false;
206 if (true === $image->isDeleted()) { //delete image
207 XCube_DelegateUtils::call('Legacy_Image.DeleteImage', new XCube_Ref($result), $image);
208 } else { //save image
209 XCube_DelegateUtils::call('Legacy_Image.SaveImage', new XCube_Ref($result), $image);
210 }
211 if (false === $result) {
212 $ret = false;
213 }
214 }
215
216 return $ret;
217 }
218
226 protected function _saveMap($obj)
227 {
228 $result = [];
229 XCube_DelegateUtils::call(
230 'Legacy_Map.SetPlace',
231 new XCube_Ref($result),
232 $obj->getDirname(),
233 $obj->getDataname(),
234 $obj->get($obj->getPrimary()),
235 $obj->mLatlng,
236 $obj->get($this->_mClientField['posttime'])
237 );
238
239 return $result;
240 }
241
249 protected function _deleteActivity(/*** XoopsSimpleObject ***/ $obj)
250 {
251 $ret = false;
252 XCube_DelegateUtils::call('Legacy_Activity.DeleteActivity', new XCube_Ref($ret), $obj->getDirname(), $this->getDataname(), $obj->get($this->mPrimary));
253 return $ret;
254 }
255
264 protected function _deleteTags(/*** XoopsSimpleObject ***/ $obj, /*** string ***/ $tagDirname)
265 {
266 $ret = false;
267 XCube_DelegateUtils::call(
268 'Legacy_Tag.'.$tagDirname.'.SetTags',
269 new XCube_Ref($ret),
270 $tagDirname,
271 $obj->getDirname(),
272 $this->getDataname(),
273 $obj->get($this->mPrimary),
274 $obj->get($this->_mClientField['posttime']),
275 []
276 );
277 return $ret;
278 }
279
287 protected function _deleteWorkflow(/*** XoopsSimpleObject ***/ $obj)
288 {
289 XCube_DelegateUtils::call('Legacy_Workflow.DeleteItem', $obj->getDirname(), $this->getDataname(), $obj->get($this->mPrimary));
290 }
291
299 protected function _deleteImages(/*** XoopsSimpleObject ***/ $obj)
300 {
301 $ret = true;
302 $isPost = false;
303 $obj->setupImages($isPost);
304 foreach ($obj->mImage as $image) {
305 if (!($image instanceof Legacy_AbstractImageObject)) {
306 continue;
307 }
308 $result = false;
309 XCube_DelegateUtils::call('Legacy_Image.DeleteImage', new XCube_Ref($result), $image);
310 if (false === $result) {
311 $ret = false;
312 }
313 }
314 return $ret;
315 }
316
324 protected function _isActivityClient(/*** mixed[] ***/ $conf)
325 {
326 $key ='activity';
327 if (! isset($this->_mClientConfig[$key])) {
328 return false;
329 }
330 if (! isset($conf[$this->_mClientConfig[$key]])) {
331 return false;
332 }
333 return 1 == $conf[$this->_mClientConfig[$key]] ? true : false;
334 }
335
343 protected function _isTagClient(/*** mixed[] ***/ $conf)
344 {
345 $key ='tag';
346 if (! isset($this->_mClientConfig[$key])) {
347 return false;
348 }
349 if (! isset($conf[$this->_mClientConfig[$key]])) {
350 return false;
351 }
352 return $conf[$this->_mClientConfig[$key]] ? true : false;
353 }
354
362 protected function _isWorkflowClient(/*** mixed[] ***/ $conf)
363 {
364 $key ='workflow';
365 if (! isset($this->_mClientConfig[$key])) {
366 return false;
367 }
368 if (! isset($conf[$this->_mClientConfig[$key]])) {
369 return false;
370 }
371 return $conf[$this->_mClientConfig[$key]] ? true : false;
372 }
373
381 protected function _isImageClient(/*** mixed[] ***/ $conf)
382 {
383 $key ='image';
384 if (! isset($this->_mClientConfig[$key])) {
385 return false;
386 }
387 if (! isset($conf[$this->_mClientConfig[$key]])) {
388 return false;
389 }
390 return $conf[$this->_mClientConfig[$key]] ? true : false;
391 }
392
400 protected function _isMapClient(/*** mixed[] ***/ $conf)
401 {
402 $key ='map';
403 if (! isset($this->_mClientConfig[$key])) {
404 return false;
405 }
406 if (! isset($conf[$this->_mClientConfig[$key]])) {
407 return false;
408 }
409 return 1 == $conf[$this->_mClientConfig[$key]] ? true : false;
410 }
411
419 public function getClientField(/*** string ***/ $key)
420 {
421 return $this->_mClientField[$key];
422 }
423}