/** * write a new Tplfile into the database * * @param XoopsTplfile|XoopsObject $tplfile * * @return bool */ public function insertTpl(XoopsTplfile &$tplfile) { if (!$tplfile->isDirty()) { return true; } if (!$tplfile->cleanVars(false)) { return false; } foreach ($tplfile->cleanVars as $k => $v) { ${$k} = $v; } if ($tplfile->isNew()) { $tpl_id = 0; $values = array('tpl_module' => $tpl_module, 'tpl_refid' => $tpl_refid, 'tpl_tplset' => $tpl_tplset, 'tpl_file' => $tpl_file, 'tpl_desc' => $tpl_desc, 'tpl_lastmodified' => $tpl_lastmodified, 'tpl_lastimported' => $tpl_lastimported, 'tpl_type' => $tpl_type); if (!$this->db2->insertPrefix('tplfile', $values)) { return false; } if (empty($tpl_id)) { $tpl_id = $this->db2->lastInsertId(); } if (isset($tpl_source) && $tpl_source != '') { $values = array('tpl_id' => $tpl_id, 'tpl_source' => $tpl_source); if (!$this->db2->insertPrefix('tplsource', $values)) { $this->db2->deletePrefix('tplfile', array('tpl_id' => $tpl_id)); return false; } } $tplfile->assignVar('tpl_id', $tpl_id); } else { $values = array('tpl_module' => $tpl_module, 'tpl_refid' => $tpl_refid, 'tpl_tplset' => $tpl_tplset, 'tpl_file' => $tpl_file, 'tpl_desc' => $tpl_desc, 'tpl_lastmodified' => $tpl_lastmodified, 'tpl_lastimported' => $tpl_lastimported, 'tpl_type' => $tpl_type); if (!$this->db2->updatePrefix('tplfile', $values, array('tpl_id' => $tpl_id))) { return false; } if (isset($tpl_source) && $tpl_source != '') { $values = array('tpl_source' => $tpl_source); if ($this->db2->updatePrefix('tplsource', $values, array('tpl_id' => $tpl_id))) { return false; } } } return true; }