XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
tplfile.php
1<?php
2
3if (!defined('XOOPS_ROOT_PATH')) {
4 exit();
5}
6
8{
13 public $Source = null;
14
15 public $mOverride = null;
16
17 public function __construct()
18 {
19 static $initVars;
20 if (isset($initVars)) {
21 $this->mVars = $initVars;
22 return;
23 }
24 $this->initVar('tpl_id', XOBJ_DTYPE_INT, '', true);
25 $this->initVar('tpl_refid', XOBJ_DTYPE_INT, '0', true);
26 $this->initVar('tpl_module', XOBJ_DTYPE_STRING, '', true, 25);
27 $this->initVar('tpl_tplset', XOBJ_DTYPE_STRING, '', true, 50);
28 $this->initVar('tpl_file', XOBJ_DTYPE_STRING, '', true, 50);
29 $this->initVar('tpl_desc', XOBJ_DTYPE_STRING, '', true, 191);
30 $this->initVar('tpl_lastmodified', XOBJ_DTYPE_INT, '0', true);
31 $this->initVar('tpl_lastimported', XOBJ_DTYPE_INT, '0', true);
32 $this->initVar('tpl_type', XOBJ_DTYPE_STRING, '', true, 20);
33 $initVars=$this->mVars;
34 }
35
36 public function loadSource()
37 {
38 if (!is_object($this->Source)) {
39 $handler =& xoops_getmodulehandler('tplsource', 'legacyRender');
40 $this->Source =& $handler->get($this->get('tpl_id'));
41 if (!is_object($this->Source)) {
42 $this->Source =& $handler->create();
43 }
44 }
45 }
46
53 public function &createClone($tplsetName)
54 {
55 $this->loadSource();
56
57 $obj =new LegacyRenderTplfileObject();
58
59 $obj->set('tpl_refid', $this->get('tpl_refid'));
60 $obj->set('tpl_module', $this->get('tpl_module'));
61
62 $obj->set('tpl_tplset', $tplsetName);
63
64 $obj->set('tpl_file', $this->get('tpl_file'));
65 $obj->set('tpl_desc', $this->get('tpl_desc'));
66 $obj->set('tpl_lastmodified', $this->get('tpl_lastmodified'));
67 $obj->set('tpl_lastimported', $this->get('tpl_lastimported'));
68 $obj->set('tpl_type', $this->get('tpl_type'));
69
70 $handler =& xoops_getmodulehandler('tplsource', 'legacyRender');
71 $obj->Source =& $handler->create();
72
73 $obj->Source->set('tpl_source', $this->Source->get('tpl_source'));
74
75 return $obj;
76 }
77
83 public function loadOverride($tplset)
84 {
85 if ('default' == $tplset || null != $this->mOverride) {
86 return;
87 }
88
89 $handler =& xoops_getmodulehandler('tplfile', 'legacyRender');
90
91 $criteria =new CriteriaCompo();
92 $criteria->add(new Criteria('tpl_tplset', $tplset));
93 $criteria->add(new Criteria('tpl_file', $this->get('tpl_file')));
94
95 $objs =& $handler->getObjects($criteria);
96 if ((is_countable($objs) ? count($objs) : 0) > 0) {
97 $this->mOverride =& $objs[0];
98 }
99 }
100}
101
103{
104 public $mTable = 'tplfile';
105 public $mPrimary = 'tpl_id';
106 public $mClass = 'LegacyRenderTplfileObject';
107
108 public function insert(&$obj, $force = false)
109 {
110 if (!parent::insert($obj, $force)) {
111 return false;
112 }
113
114 $obj->loadSource();
115
116 if (!is_object($obj->Source)) {
117 return true;
118 } else {
119 $handler =& xoops_getmodulehandler('tplsource', 'legacyRender');
120
121 if ($obj->Source->isNew()) {
122 $obj->Source->set('tpl_id', $obj->get('tpl_id'));
123 }
124
125 return $handler->insert($obj->Source, $force);
126 }
127 }
128
137 public function &getObjectsWithOverride($criteria, $tplset)
138 {
139 $objs =& $this->getObjects($criteria);
140
141 $ret = [];
142 $dobjs = [];
143 foreach ($objs as $obj) {
144 $set = $obj->get('tpl_tplset');
145 if ('default' == $set) {
146 $ret[] = $obj;
147 }
148 if ($set == $tplset) {
149 $dobjs[$obj->get('tpl_file')] = $obj;
150 }
151 }
152
153 foreach ($ret as $obj) {
154 $obj->mOverride = $dobjs[$obj->get('tpl_file')];
155 }
156
157 return $ret;
158 }
159
160 public function delete(&$obj, $force = false)
161 {
162 $obj->loadSource();
163
164 if (is_object($obj->Source)) {
165 $handler =& xoops_getmodulehandler('tplsource', 'legacyRender');
166 if (!$handler->delete($obj->Source, $force)) {
167 return false;
168 }
169 }
170
171 return parent::delete($obj, $force);
172 }
173
180 public function &getRecentModifyFile($limit = 10)
181 {
182 $criteria = new Criteria('tpl_id', 0, '>');
183
184 $criteria->setLimit($limit);
185
186 $criteria->setSort('tpl_lastmodified');
187 $criteria->setOrder('DESC');
188
189 $objs =& $this->getObjects($criteria);
190
191 return $objs;
192 }
193
206 public function &find($tplsetName, $type = null, $refId = null, $module = null, $file = null)
207 {
208 $criteria =new CriteriaCompo();
209 $criteria->add(new Criteria('tpl_tplset', $tplsetName));
210 if (null != $type) {
211 $criteria->add(new Criteria('tpl_type', $type));
212 }
213 if (null != $refId) {
214 $criteria->add(new Criteria('tpl_refid', $refId));
215 }
216 if (null != $module) {
217 $criteria->add(new Criteria('tpl_module', $module));
218 }
219 if (null != $file) {
220 $criteria->add(new Criteria('tpl_file', $file));
221 }
222
223 $objs =& $this->getObjects($criteria);
224 return $objs;
225 }
226}
& getObjectsWithOverride($criteria, $tplset)
Definition tplfile.php:137
& getRecentModifyFile($limit=10)
Definition tplfile.php:180
& find($tplsetName, $type=null, $refId=null, $module=null, $file=null)
Definition tplfile.php:206
& createClone($tplsetName)
Definition tplfile.php:53
& getObjects($criteria=null, $limit=null, $start=null, $id_as_key=false)
Definition handler.php:83