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_AbstractObject extends XoopsSimpleObject
17: {
18:
19:
20:
21: protected $_mMainTable = null;
22:
23: public $mChildList = array();
24: public $mParentList = array();
25: public $mTable = array();
26: protected $_mIsLoaded = array();
27:
28: protected $_mIsTagLoaded = false;
29: public $mTag = array();
30: public $mImage = array();
31:
32: 33: 34: 35: 36: 37: 38:
39: public function __construct()
40: {
41: parent::__construct();
42: $this->_setupChildTables();
43: }
44:
45: 46: 47: 48: 49: 50: 51:
52: protected function _setupChildTables()
53: {
54: foreach($this->mChildList as $table){
55: $this->_mIsLoaded[$table] = false;
56: $this->mTable[$table] = array();
57: }
58: foreach($this->mParentList as $table){
59: $this->_mIsLoaded[$table] = false;
60: $this->mTable[$table] = null;
61: }
62: }
63:
64: 65: 66: 67: 68: 69: 70: 71:
72: public function loadTable( $table, $dirname=null)
73: {
74: if ($this->_mIsLoaded[$table] === true) {
75: return;
76: }
77:
78: $dirname = isset($dirname) ? $dirname : $this->getDirname();
79: $handler = Legacy_Utils::getModuleHandler($table, $dirname);
80:
81: if(in_array($table, $this->mChildList)){
82: $this->mTable[$table] = $handler->getObjects(new Criteria($this->getPrimary(), $this->get($this->getPrimary())));
83: }
84: elseif(in_array($table, $this->mParentList)){
85: $this->mTable[$table] = $handler->get($this->get($handler->mPrimary));
86: }
87: else{
88: die('invalid load table');
89: }
90:
91: $this->_mIsLoaded[$table] = true;
92: }
93:
94: 95: 96: 97: 98: 99: 100:
101: public function getPrimary()
102: {
103: return constant(get_class($this).'::PRIMARY');
104: }
105:
106: 107: 108: 109: 110: 111: 112:
113: public function getDataname()
114: {
115: return constant(get_class($this).'::DATANAME');
116: }
117:
118: 119: 120: 121: 122: 123: 124:
125: public function renderUri( $action=null)
126: {
127: $dataname = ($this->_mMainTable==$this->getDataname()) ? null : $this->getDataname();
128: return Legacy_Utils::renderUri($this->getDirname(), $dataname, $this->get($this->getPrimary()), $action);
129: }
130:
131: 132: 133: 134: 135: 136: 137:
138: public function getImages()
139: {
140: $imageObjs = array();
141: if($this->get($this->getPrimary())>0){
142: XCube_DelegateUtils::call('Legacy_Image.GetImageObjects', new XCube_Ref($imageObjs), $this->getDirname(), $this->getDataname(), $this->get($this->getPrimary()));
143: }
144: return $imageObjs;
145: }
146:
147: 148: 149: 150: 151: 152: 153:
154: public function getImageNumber()
155: {
156: return 0;
157: }
158:
159: 160: 161: 162: 163: 164: 165:
166: public function setupImages($isPost=true)
167: {
168: if(count($this->mImage)>0) return;
169: $handler = Legacy_Utils::getModuleHandler($this->getDataname(), $this->getDirname());
170:
171: $n = $this->getImageNumber();
172: if($n===0) return;
173:
174: $this->mImage = $this->getImages();
175:
176: $originalImage = array();
177: XCube_DelegateUtils::call('Legacy_Image.CreateImageObject', new XCube_Ref($originalImage));
178: $originalImage->set('title', $this->get($handler->getClientField('title')));
179: $originalImage->set('uid', Legacy_Utils::getUid());
180: $originalImage->set('dirname', $this->getDirname());
181: $originalImage->set('dataname', $this->getDataname());
182: $originalImage->set('data_id', $this->get($this->getPrimary()));
183:
184: for($i=1;$i<=$n;$i++){
185: if(! isset($this->mImage[$i])){
186: $this->mImage[$i] = clone $originalImage;
187: $this->mImage[$i]->set('num', $i);
188: }
189: if($isPost===true){
190: $this->mImage[$i]->setupPostData($i);
191: }
192: }
193: }
194:
195: 196: 197: 198: 199: 200: 201:
202: public function loadTag()
203: {
204: $chandler = xoops_gethandler('config');
205: $configArr = $chandler->getConfigsByDirname($this->getDirname());
206:
207: if($this->_mIsTagLoaded==false && $tagDirname = $configArr['tag_dirname']){
208: $tagArr = array();
209: if(! $this->isNew()){
210: XCube_DelegateUtils::call('Legacy_Tag.'.$configArr['tag_dirname'].'.GetTags',
211: new XCube_Ref($tagArr),
212: $tagDirname,
213: $this->getDirname(),
214: $this->getDataname(),
215: $this->get($this->getPrimary())
216: );
217: }
218: $this->mTag = $tagArr;
219: $this->_mIsTagLoaded = true;
220: }
221: }
222: }
223: