1: <?php
2:
3: if (!defined('XOOPS_ROOT_PATH')) exit();
4:
5: class LegacyRenderTplfileObject extends XoopsSimpleObject
6: {
7: 8: 9: 10:
11: var $Source = null;
12:
13: var $mOverride = null;
14:
15: function LegacyRenderTplfileObject()
16: {
17: static $initVars;
18: if (isset($initVars)) {
19: $this->mVars = $initVars;
20: return;
21: }
22: $this->initVar('tpl_id', XOBJ_DTYPE_INT, '', true);
23: $this->initVar('tpl_refid', XOBJ_DTYPE_INT, '0', true);
24: $this->initVar('tpl_module', XOBJ_DTYPE_STRING, '', true, 25);
25: $this->initVar('tpl_tplset', XOBJ_DTYPE_STRING, '', true, 50);
26: $this->initVar('tpl_file', XOBJ_DTYPE_STRING, '', true, 50);
27: $this->initVar('tpl_desc', XOBJ_DTYPE_STRING, '', true, 255);
28: $this->initVar('tpl_lastmodified', XOBJ_DTYPE_INT, '0', true);
29: $this->initVar('tpl_lastimported', XOBJ_DTYPE_INT, '0', true);
30: $this->initVar('tpl_type', XOBJ_DTYPE_STRING, '', true, 20);
31: $initVars=$this->mVars;
32: }
33:
34: function loadSource()
35: {
36: if (!is_object($this->Source)) {
37: $handler =& xoops_getmodulehandler('tplsource', 'legacyRender');
38: $this->Source =& $handler->get($this->get('tpl_id'));
39: if (!is_object($this->Source)) {
40: $this->Source =& $handler->create();
41: }
42: }
43: }
44:
45: 46: 47: 48: 49: 50:
51: function &createClone($tplsetName)
52: {
53: $this->loadSource();
54:
55: $obj =new LegacyRenderTplfileObject();
56:
57: $obj->set('tpl_refid', $this->get('tpl_refid'));
58: $obj->set('tpl_module', $this->get('tpl_module'));
59:
60: $obj->set('tpl_tplset', $tplsetName);
61:
62: $obj->set('tpl_file', $this->get('tpl_file'));
63: $obj->set('tpl_desc', $this->get('tpl_desc'));
64: $obj->set('tpl_lastmodified', $this->get('tpl_lastmodified'));
65: $obj->set('tpl_lastimported', $this->get('tpl_lastimported'));
66: $obj->set('tpl_type', $this->get('tpl_type'));
67:
68: $handler =& xoops_getmodulehandler('tplsource', 'legacyRender');
69: $obj->Source =& $handler->create();
70:
71: $obj->Source->set('tpl_source', $this->Source->get('tpl_source'));
72:
73: return $obj;
74: }
75:
76: 77: 78: 79:
80: function loadOverride($tplset)
81: {
82: if ($tplset == 'default' || $this->mOverride != null) {
83: return;
84: }
85:
86: $handler =& xoops_getmodulehandler('tplfile', 'legacyRender');
87:
88: $criteria =new CriteriaCompo();
89: $criteria->add(new Criteria('tpl_tplset', $tplset));
90: $criteria->add(new Criteria('tpl_file', $this->get('tpl_file')));
91:
92: $objs =& $handler->getObjects($criteria);
93: if (count($objs) > 0) {
94: $this->mOverride =& $objs[0];
95: }
96: }
97: }
98:
99: class LegacyRenderTplfileHandler extends XoopsObjectGenericHandler
100: {
101: var $mTable = "tplfile";
102: var $mPrimary = "tpl_id";
103: var $mClass = "LegacyRenderTplfileObject";
104:
105: function insert(&$obj, $force = false)
106: {
107: if (!parent::insert($obj, $force)) {
108: return false;
109: }
110:
111: $obj->loadSource();
112:
113: if (!is_object($obj->Source)) {
114: return true;
115: }
116: else {
117: $handler =& xoops_getmodulehandler('tplsource', 'legacyRender');
118:
119: if ($obj->Source->isNew()) {
120: $obj->Source->set('tpl_id', $obj->get('tpl_id'));
121: }
122:
123: return $handler->insert($obj->Source, $force);
124: }
125: }
126:
127: 128: 129: 130: 131:
132: function &getObjectsWithOverride($criteria, $tplset)
133: {
134: $objs =& $this->getObjects($criteria);
135:
136: $ret = array();
137: $dobjs = array();
138: foreach ($objs as $obj) {
139: $set = $obj->get('tpl_tplset');
140: if ($set == 'default') $ret[] = $obj;
141: if ($set == $tplset) $dobjs[$obj->get('tpl_file')] = $obj;
142: }
143:
144: foreach ($ret as $obj) {
145: $obj->mOverride = $dobjs[$obj->get('tpl_file')];
146: }
147:
148: return $ret;
149: }
150:
151: function delete(&$obj, $force = false)
152: {
153: $obj->loadSource();
154:
155: if (is_object($obj->Source)) {
156: $handler =& xoops_getmodulehandler('tplsource', 'legacyRender');
157: if (!$handler->delete($obj->Source, $force)) {
158: return false;
159: }
160: }
161:
162: return parent::delete($obj, $force);
163: }
164:
165: 166: 167: 168: 169: 170:
171: function &getRecentModifyFile($limit = 10)
172: {
173: $criteria = new Criteria('tpl_id', 0, '>');
174:
175: $criteria->setLimit($limit);
176:
177: $criteria->setSort('tpl_lastmodified');
178: $criteria->setOrder('DESC');
179:
180: $objs =& $this->getObjects($criteria);
181:
182: return $objs;
183: }
184:
185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196:
197: function &find($tplsetName, $type = null, $refId = null, $module = null, $file = null) {
198: $criteria =new CriteriaCompo();
199: $criteria->add(new Criteria('tpl_tplset', $tplsetName));
200: if ($type != null) {
201: $criteria->add(new Criteria('tpl_type', $type));
202: }
203: if ($refId != null) {
204: $criteria->add(new Criteria('tpl_refid', $refId));
205: }
206: if ($module != null) {
207: $criteria->add(new Criteria('tpl_module', $module));
208: }
209: if ($file != null) {
210: $criteria->add(new Criteria('tpl_file', $file));
211: }
212:
213: $objs =& $this->getObjects($criteria);
214: return $objs;
215: }
216: }
217:
218: ?>
219: