XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
AbstractObject.class.php
1<?php
12
13if (!defined('XOOPS_ROOT_PATH')) {
14 exit;
15}
16
17
19{
20 //const PRIMARY = '';
21 //const DATANAME = '';
22
23 protected $_mMainTable = null; //module's main table name
24
25 /*** string[] ***/ public $mChildList = []; //Child table's name array
26 /*** string[] ***/ public $mParentList = []; //Parent table's name array
27 /*** XoopsSimpleObject[] ***/ public $mTable = [];
28 /*** bool[] ***/ protected $_mIsLoaded = [];
29
30 /*** bool ***/ protected $_mIsTagLoaded = false;
31 /*** string[] ***/ public $mTag = [];
32 /*** Legacy_ImageObject[] ***/ public $mImage = [];
33
41 public function __construct()
42 {
43 parent::__construct();
44 $this->_setupChildTables();
45 }
46
54 protected function _setupChildTables()
55 {
56 foreach ($this->mChildList as $table) {
57 $this->_mIsLoaded[$table] = false;
58 $this->mTable[$table] = [];
59 }
60 foreach ($this->mParentList as $table) {
61 $this->_mIsLoaded[$table] = false;
62 $this->mTable[$table] = null;
63 }
64 }
65
74 public function loadTable(/*** string ***/ $table, /*** string ***/ $dirname=null)
75 {
76 if (true === $this->_mIsLoaded[$table]) {
77 return;
78 }
79
80 $dirname ??= $this->getDirname();
81 $handler = Legacy_Utils::getModuleHandler($table, $dirname);
82
83 if (in_array($table, $this->mChildList)) {
84 $this->mTable[$table] = $handler->getObjects(new Criteria($this->getPrimary(), $this->get($this->getPrimary())));
85 } elseif (in_array($table, $this->mParentList)) {
86 $this->mTable[$table] = $handler->get($this->get($handler->mPrimary));
87 } else {
88 die('invalid load table');
89 }
90
91 $this->_mIsLoaded[$table] = true;
92 }
93
101 public function getPrimary()
102 {
103 return constant(get_class($this).'::PRIMARY');
104 }
105
113 public function getDataname()
114 {
115 return constant(get_class($this).'::DATANAME');
116 }
117
125 public function renderUri(/*** string **/ $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
136 public function getImages()
137 {
138 $imageObjs = [];
139 if ($this->get($this->getPrimary())>0) {
140 XCube_DelegateUtils::call('Legacy_Image.GetImageObjects', new XCube_Ref($imageObjs), $this->getDirname(), $this->getDataname(), $this->get($this->getPrimary()));
141 }
142 return $imageObjs;
143 }
144
152 public function getImageNumber()
153 {
154 return 0;
155 }
156
164 public function setupImages($isPost=true)
165 {
166 if (count($this->mImage)>0) {
167 return;
168 }
169 $handler = Legacy_Utils::getModuleHandler($this->getDataname(), $this->getDirname());
170
171 $n = $this->getImageNumber();
172 if (0 === $n) {
173 return;
174 }
175
176 $this->mImage = $this->getImages();
177
178 $originalImage = [];
179 XCube_DelegateUtils::call('Legacy_Image.CreateImageObject', new XCube_Ref($originalImage));
180 $originalImage->set('title', $this->get($handler->getClientField('title')));
181 $originalImage->set('uid', Legacy_Utils::getUid());
182 $originalImage->set('dirname', $this->getDirname());
183 $originalImage->set('dataname', $this->getDataname());
184 $originalImage->set('data_id', $this->get($this->getPrimary()));
185
186 for ($i=1;$i<=$n;$i++) {
187 if (! isset($this->mImage[$i])) {
188 $this->mImage[$i] = clone $originalImage;
189 $this->mImage[$i]->set('num', $i);
190 }
191 if (true === $isPost) {
192 $this->mImage[$i]->setupPostData($i);
193 }
194 }
195 }
196
204 public function loadTag()
205 {
206 $chandler = xoops_gethandler('config');
207 $configArr = $chandler->getConfigsByDirname($this->getDirname());
208
209 if (false == $this->_mIsTagLoaded && $tagDirname = $configArr['tag_dirname']) {
210 $tagArr = [];
211 if (! $this->isNew()) {
212 XCube_DelegateUtils::call('Legacy_Tag.'.$configArr['tag_dirname'].'.GetTags',
213 new XCube_Ref($tagArr),
214 $tagDirname,
215 $this->getDirname(),
216 $this->getDataname(),
217 $this->get($this->getPrimary())
218 );
219 }
220 $this->mTag = $tagArr;
221 $this->_mIsTagLoaded = true;
222 }
223 }
224
225 public function onWorkflow()
226 {
227 }
228}
loadTable( $table, $dirname=null)
static getModuleHandler( $name, $dirname)
static renderUri( $dirname, $dataname=null, $data_id=0, $action=null, $query=null)