1: <?php
2: 3: 4: 5: 6:
7:
8: if(!defined('XOOPS_ROOT_PATH'))
9: {
10: exit;
11: }
12:
13: 14: 15:
16: abstract class Legacy_AbstractClientObjectHandler extends XoopsObjectGenericHandler
17: {
18: protected $_mClientField = array('title'=>'title', 'category'=>'category_id', 'posttime'=>'posttime');
19: protected $_mClientConfig = array('tag'=>'tag_dirname', 'image'=>'use_image', 'workflow'=>'use_workflow', 'activity'=>'use_activity', 'map'=>'use_map');
20:
21: 22: 23: 24: 25: 26: 27:
28: protected function _getTagList( $obj)
29: {
30: return $obj->mTag;
31: }
32:
33: 34: 35: 36: 37: 38: 39: 40:
41: public function insert( $obj, $force=false)
42: {
43: $ret = parent::insert($obj, $force);
44: if ($ret == true)
45: {
46: $ret = $this->_setClientData($obj);
47: }
48:
49: return $ret;
50: }
51:
52: 53: 54: 55: 56: 57: 58: 59:
60: public function delete( $obj, $force=false)
61: {
62: $ret = parent::delete($obj, $force);
63: $this->_deleteClientData($obj);
64:
65: return $ret;
66: }
67:
68: 69: 70: 71: 72: 73: 74:
75: protected function _setClientData( $obj)
76: {
77: $handler = xoops_gethandler('config');
78: $conf = $handler->getConfigsByDirname($obj->getDirname());
79:
80: $ret = true;
81: if($this->_isActivityClient($conf)===true){
82: if($this->_saveActivity($obj)===false){
83: $ret = false;
84: }
85: }
86:
87: if($this->_isTagClient($conf)===true){
88: if($this->_saveTags($obj, $conf[$this->_mClientConfig['tag']])===false){
89: $ret = false;
90: }
91: }
92:
93: if($this->_isWorkflowClient($conf)===true){
94: $this->_saveWorkflow($obj);
95: }
96:
97: if($this->_isImageClient($conf)===true){
98: if($this->_saveImages($obj)===false){
99: $ret = false;
100: }
101: }
102:
103: if($this->_isMapClient($conf)===true){
104: if($this->_saveMap($obj)===false){
105: $ret = false;
106: }
107: }
108:
109: return $ret;
110: }
111:
112: 113: 114: 115: 116: 117: 118:
119: protected function _deleteClientData( $obj)
120: {
121: $handler = xoops_gethandler('config');
122: $conf = $handler->getConfigsByDirname($obj->getDirname());
123:
124: $ret = true;
125: if($this->_isActivityClient($conf)===true){
126: if($this->_deleteActivity($obj)===false){
127: $ret = false;
128: }
129: }
130:
131: if($this->_isTagClient($conf)===true){
132: if($this->_deleteTags($obj, $tagDirname)===false){
133: $ret = false;
134: }
135: }
136:
137: if($this->_isWorkflowClient($conf)===true){
138: $ret = $this->_deleteWorkflow($obj);
139: }
140:
141: if($this->_isImageClient($conf)===true){
142: if($this->_deleteImages($obj)===false){
143: $ret = false;
144: }
145: }
146: return $ret;
147: }
148:
149: 150: 151: 152: 153: 154: 155:
156: protected function _saveActivity( $obj)
157: {
158: $ret = false;
159: XCube_DelegateUtils::call(
160: 'Legacy_Activity.AddActivity',
161: new XCube_Ref($ret),
162: $obj->get('uid'),
163: $obj->get($this->_mClientField['category']),
164: $obj->getDirname(),
165: $this->getDataname(),
166: $obj->get($this->mPrimary),
167: $obj->get($this->_mClientField['posttime'])
168: );
169: return $ret;
170: }
171:
172: 173: 174: 175: 176: 177: 178: 179:
180: protected function _saveTags( $obj, $tagDirname)
181: {
182: $ret = false;
183: XCube_DelegateUtils::call('Legacy_Tag.'.$tagDirname.'.SetTags',
184: new XCube_Ref($ret),
185: $tagDirname,
186: $obj->getDirname(),
187: $this->getDataname(),
188: $obj->get($this->mPrimary),
189: $obj->get($this->_mClientField['posttime']),
190: $this->_getTagList($obj)
191: );
192: return $ret;
193: }
194:
195: 196: 197: 198: 199: 200: 201:
202: protected function _saveWorkflow( $obj)
203: {
204: XCube_DelegateUtils::call(
205: 'Legacy_Workflow.AddItem',
206: $obj->getShow($this->mPrimary),
207: $obj->getDirname(),
208: $this->getDataname(),
209: $obj->get($obj->getPrimary()),
210: Legacy_Utils::renderUri($obj->getDirname(), $this->getDataname(), $obj->get($this->mPrimary))
211: );
212: }
213:
214: 215: 216: 217: 218: 219: 220:
221: protected function _saveImages( $obj)
222: {
223: $ret = true;
224: $obj->setupImages();
225: foreach($obj->mImage as $image){
226: $result = false;
227: if($image->isDeleted()===true){
228: XCube_DelegateUtils::call('Legacy_Image.DeleteImage', new XCube_Ref($result), $image);
229: }
230: else{
231: XCube_DelegateUtils::call('Legacy_Image.SaveImage', new XCube_Ref($result), $image);
232: }
233: if($result===false){
234: $ret = false;
235: }
236: }
237:
238: return $ret;
239: }
240:
241: 242: 243: 244: 245: 246: 247:
248: protected function _saveMap($obj)
249: {
250: $result = array();
251: XCube_DelegateUtils::call(
252: 'Legacy_Map.SetPlace',
253: new XCube_Ref($result),
254: $obj->getDirname(),
255: $obj->getDataname(),
256: $obj->get($obj->getPrimary()),
257: $obj->mLatlng,
258: $obj->get($this->_mClientField['posttime'])
259: );
260:
261: return $result;
262: }
263:
264: 265: 266: 267: 268: 269: 270:
271: protected function _deleteActivity( $obj)
272: {
273: $ret = false;
274: XCube_DelegateUtils::call('Legacy_Activity.DeleteActivity', new XCube_Ref($ret), $obj->getDirname(), $this->getDataname(), $obj->get($this->mPrimary));
275: return $ret;
276: }
277:
278: 279: 280: 281: 282: 283: 284: 285:
286: protected function _deleteTags( $obj, $tagDirname)
287: {
288: $ret = false;
289: XCube_DelegateUtils::call(
290: 'Legacy_Tag.'.$tagDirname.'.SetTags',
291: new XCube_Ref($ret),
292: $tagDirname,
293: $obj->getDirname(),
294: $this->getDataname(),
295: $obj->get($this->mPrimary),
296: $obj->get($this->_mClientField['posttime']),
297: array()
298: );
299: return $ret;
300: }
301:
302: 303: 304: 305: 306: 307: 308:
309: protected function _deleteWorkflow( $obj)
310: {
311: XCube_DelegateUtils::call('Legacy_Workflow.DeleteItem', $obj->getDirname(), $this->getDataname(), $obj->get($this->mPrimary));
312: }
313:
314: 315: 316: 317: 318: 319: 320:
321: protected function _deleteImages( $obj)
322: {
323: $ret = true;
324: $isPost = false;
325: $obj->setupImages($isPost);
326: foreach($obj->mImage as $image){
327: if(!($image instanceof Legacy_AbstractImageObject)){
328: continue;
329: }
330: $result = false;
331: XCube_DelegateUtils::call('Legacy_Image.DeleteImage', new XCube_Ref($result), $image);
332: if($result===false){
333: $ret = false;
334: }
335: }
336: return $ret;
337: }
338:
339: 340: 341: 342: 343: 344: 345:
346: protected function _isActivityClient( $conf)
347: {
348: return $conf[$this->_mClientConfig['activity']]==1 ? true : false;
349: }
350:
351: 352: 353: 354: 355: 356: 357:
358: protected function _isTagClient( $conf)
359: {
360: $flag = isset($conf[$this->_mClientConfig['tag']]) ? $conf[$this->_mClientConfig['tag']] : 0 ;
361: return $flag && $flag==1 ? true : false;
362: }
363:
364: 365: 366: 367: 368: 369: 370:
371: protected function _isWorkflowClient( $conf)
372: {
373: $flag = isset($conf[$this->_mClientConfig['workflow']]) ? $conf[$this->_mClientConfig['workflow']] : 0 ;
374: return $flag==1 ? true : false;
375: }
376:
377: 378: 379: 380: 381: 382: 383:
384: protected function _isImageClient( $conf)
385: {
386: $flag = isset($conf[$this->_mClientConfig['image']]) ? $conf[$this->_mClientConfig['image']] : 0;
387: return $flag && $flag==1 ? true : false;
388: }
389:
390: 391: 392: 393: 394: 395: 396:
397: protected function _isMapClient( $conf)
398: {
399: $flag = isset($conf[$this->_mClientConfig['map']]) ? $conf[$this->_mClientConfig['map']] : 0;
400: return $flag && $flag==1 ? true : false;
401: }
402:
403: 404: 405: 406: 407: 408: 409:
410: public function getClientField( $key)
411: {
412: return $this->_mClientField[$key];
413: }
414: }
415:
416: ?>
417: