68 public function &
create($isNew =
true)
77 public function &
get($id, $getsource =
false)
83 $sql =
'SELECT * FROM '.$this->db->prefix(
'tplfile').
' WHERE tpl_id='.$id;
85 $sql =
'SELECT f.*, s.tpl_source FROM '.$this->db->prefix(
'tplfile').
' f LEFT JOIN '.$this->db->prefix(
'tplsource').
' s ON s.tpl_id=f.tpl_id WHERE f.tpl_id='.$id;
87 if ($result = $this->db->query($sql)) {
88 $numrows = $this->db->getRowsNum($result);
91 $ret->assignVars($this->db->fetchArray($result));
98 public function loadSource(&$tplfile)
100 if (
'xoopstplfile' !== strtolower(get_class($tplfile))) {
103 if (!$tplfile->getVar(
'tpl_source')) {
104 $sql =
'SELECT tpl_source FROM '.$this->db->prefix(
'tplsource').
' WHERE tpl_id='.$tplfile->getVar(
'tpl_id');
105 if (!$result = $this->db->query($sql)) {
108 $myrow = $this->db->fetchArray($result);
109 $tplfile->assignVar(
'tpl_source', $myrow[
'tpl_source']);
121 $tpl_lastmodified =
null;
122 $tpl_lastimported =
null;
124 if (
'xoopstplfile' !== strtolower(get_class($tplfile))) {
127 if (!$tplfile->isDirty()) {
130 if (!$tplfile->cleanVars()) {
133 foreach ($tplfile->cleanVars as $k => $v) {
136 if ($tplfile->isNew()) {
137 $tpl_id = $this->db->genId(
'tplfile_tpl_id_seq');
138 $sql = sprintf(
'INSERT INTO %s (tpl_id, tpl_module, tpl_refid, tpl_tplset, tpl_file, tpl_desc, tpl_lastmodified, tpl_lastimported, tpl_type) VALUES (%u, %s, %u, %s, %s, %s, %u, %u, %s)', $this->db->prefix(
'tplfile'), $tpl_id, $this->db->quoteString($tpl_module), $tpl_refid, $this->db->quoteString($tpl_tplset), $this->db->quoteString($tpl_file), $this->db->quoteString($tpl_desc), $tpl_lastmodified, $tpl_lastimported, $this->db->quoteString($tpl_type));
139 if (!$result = $this->db->query($sql)) {
142 if (empty($tpl_id)) {
143 $tpl_id = $this->db->getInsertId();
145 if (isset($tpl_source) &&
'' !== $tpl_source) {
146 $sql = sprintf(
'INSERT INTO %s (tpl_id, tpl_source) VALUES (%u, %s)', $this->db->prefix(
'tplsource'), $tpl_id, $this->db->quoteString($tpl_source));
147 if (!$result = $this->db->query($sql)) {
148 $this->db->query(sprintf(
'DELETE FROM %s WHERE tpl_id = %u', $this->db->prefix(
'tplfile'), $tpl_id));
152 $tplfile->assignVar(
'tpl_id', $tpl_id);
154 $sql = sprintf(
'UPDATE %s SET tpl_tplset = %s, tpl_file = %s, tpl_desc = %s, tpl_lastimported = %u, tpl_lastmodified = %u WHERE tpl_id = %u', $this->db->prefix(
'tplfile'), $this->db->quoteString($tpl_tplset), $this->db->quoteString($tpl_file), $this->db->quoteString($tpl_desc), $tpl_lastimported, $tpl_lastmodified, $tpl_id);
155 if (!$result = $this->db->query($sql)) {
158 if (isset($tpl_source) &&
'' !== $tpl_source) {
159 $sql = sprintf(
'UPDATE %s SET tpl_source = %s WHERE tpl_id = %u', $this->db->prefix(
'tplsource'), $this->db->quoteString($tpl_source), $tpl_id);
160 if (!$result = $this->db->query($sql)) {
168 public function forceUpdate(&$tplfile)
173 $tpl_lastimported =
null;
174 $tpl_lastmodified =
null;
176 if (
'xoopstplfile' !== strtolower(get_class($tplfile))) {
179 if (!$tplfile->isDirty()) {
182 if (!$tplfile->cleanVars()) {
185 foreach ($tplfile->cleanVars as $k => $v) {
188 if (!$tplfile->isNew()) {
189 $sql = sprintf(
'UPDATE %s SET tpl_tplset = %s, tpl_file = %s, tpl_desc = %s, tpl_lastimported = %u, tpl_lastmodified = %u WHERE tpl_id = %u', $this->db->prefix(
'tplfile'), $this->db->quoteString($tpl_tplset), $this->db->quoteString($tpl_file), $this->db->quoteString($tpl_desc), $tpl_lastimported, $tpl_lastmodified, $tpl_id);
190 if (!$result = $this->db->queryF($sql)) {
193 if (isset($tpl_source) &&
'' != $tpl_source) {
194 $sql = sprintf(
'UPDATE %s SET tpl_source = %s WHERE tpl_id = %u', $this->db->prefix(
'tplsource'), $this->db->quoteString($tpl_source), $tpl_id);
195 if (!$result = $this->db->queryF($sql)) {
205 public function delete(&$tplfile)
207 if (
'xoopstplfile' !== strtolower(get_class($tplfile))) {
210 $id = $tplfile->getVar(
'tpl_id');
211 $sql = sprintf(
'DELETE FROM %s WHERE tpl_id = %u', $this->db->prefix(
'tplfile'), $id);
212 if (!$result = $this->db->query($sql)) {
215 $sql = sprintf(
'DELETE FROM %s WHERE tpl_id = %u', $this->db->prefix(
'tplsource'), $id);
216 $this->db->query($sql);
228 $sql = sprintf(
'SELECT tpl_id FROM %s', $this->db->prefix(
'tplfile'));
229 $sql .=
' ' . $criteria->renderWhere();
231 $result = $this->db->query($sql);
232 while ($row = $this->db->fetchArray($result)) {
233 $sql = sprintf(
'DELETE FROM %s WHERE tpl_id=%u', $this->db->prefix(
'tplsource'), $row[
'tpl_id']);
234 $this->db->query($sql);
237 $sql = sprintf(
'DELETE FROM %s', $this->db->prefix(
'tplfile'));
238 $sql .=
' ' . $criteria->renderWhere();
240 return $this->db->query($sql);
243 public function &getObjects($criteria =
null, $getsource =
false, $id_as_key =
false)
248 $sql =
'SELECT f.*, s.tpl_source FROM '.$this->db->prefix(
'tplfile').
' f LEFT JOIN '.$this->db->prefix(
'tplsource').
' s ON s.tpl_id=f.tpl_id';
250 $sql =
'SELECT * FROM '.$this->db->prefix(
'tplfile');
252 if (isset($criteria) && $criteria instanceof \criteriaelement) {
253 $sql .=
' '.$criteria->renderWhere().
' ORDER BY tpl_refid';
254 $limit = $criteria->getLimit();
255 $start = $criteria->getStart();
257 $result = $this->db->query($sql, $limit, $start);
261 while ($myrow = $this->db->fetchArray($result)) {
262 $tplfile =
new XoopsTplfile();
263 $tplfile->assignVars($myrow);
267 $ret[$myrow[
'tpl_id']] =& $tplfile;
274 public function getCount($criteria =
null)
276 $sql =
'SELECT COUNT(*) FROM '.$this->db->prefix(
'tplfile');
277 if (isset($criteria) && $criteria instanceof \criteriaelement) {
278 $sql .=
' '.$criteria->renderWhere();
280 if (!$result =& $this->db->query($sql)) {
283 [$count] = $this->db->fetchRow($result);
287 public function getModuleTplCount($tplset)
290 $sql =
'SELECT tpl_module, COUNT(tpl_id) AS count FROM ' . $this->db->prefix(
'tplfile') .
' WHERE tpl_tplset=' . $this->db->quoteString($tplset) .
' GROUP BY tpl_module';
291 $result = $this->db->query($sql);
295 while ($myrow = $this->db->fetchArray($result)) {
296 if (
'' !== $myrow[
'tpl_module']) {
297 $ret[$myrow[
'tpl_module']] = $myrow[
'count'];
303 public function &find($tplset =
null, $type =
null, $refid =
null, $module =
null, $file =
null, $getsource =
false)
305 $criteria =
new CriteriaCompo();
306 if (isset($tplset)) {
307 $criteria->add(
new Criteria(
'tpl_tplset', addslashes(trim($tplset))));
309 if (isset($module)) {
310 $criteria->add(
new Criteria(
'tpl_module', $module));
313 $criteria->add(
new Criteria(
'tpl_refid', $refid));
316 $criteria->add(
new Criteria(
'tpl_file', addslashes(trim($file))));
319 if (is_array($type)) {
320 $criteria2 =
new CriteriaCompo();
321 foreach ($type as $t) {
322 $criteria2->add(
new Criteria(
'tpl_type', addslashes(trim($t))),
'OR');
324 $criteria->add($criteria2);
326 $criteria->add(
new Criteria(
'tpl_type', addslashes(trim($type))));
329 $ret =& $this->getObjects($criteria, $getsource,
false);
333 public function templateExists($tplname, $tplset_name)
335 $criteria =
new CriteriaCompo(
new Criteria(
'tpl_file', addslashes(trim($tplname))));
336 $criteria->add(
new Criteria(
'tpl_tplset', addslashes(trim($tplset_name))));
337 return $this->getCount($criteria) > 0;