/** * write a new TplFile into the database * * @param XoopsTplFile $tplfile object * * @return bool */ public function insertTpl(XoopsTplFile $tplfile) { $tpl_id = 0; if (!$tplfile->isDirty()) { return true; } if (!$tplfile->cleanVars()) { return false; } $vars = $tplfile->cleanVars; $tpl_module = $vars['tpl_module']; $tpl_refid = $vars['tpl_refid']; $tpl_tplset = $vars['tpl_tplset']; $tpl_file = $vars['tpl_file']; $tpl_desc = $vars['tpl_desc']; $tpl_lastmodified = $vars['tpl_lastmodified']; $tpl_lastimported = $vars['tpl_lastimported']; $tpl_type = $vars['tpl_type']; if (isset($vars['tpl_id'])) { $tpl_id = $vars['tpl_id']; } if (isset($vars['tpl_source'])) { $tpl_source = $vars['tpl_source']; } 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('system_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('system_tplsource', $values)) { $this->db2->deletePrefix('system_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('system_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('system_tplsource', $values, array('tpl_id' => $tpl_id))) { return false; } } } return true; }