public function duplicate($strNewName = "") { global $objLang, $_CONF, $objLiveUser; if ($this->id > 0) { //*** Cache the name of the current template. $strName = $this->name; if (!empty($strNewName)) { //*** Set the name of the duplicate template. $this->name = sprintf($strNewName, $strName); } //*** Duplicate the template. $objReturn = parent::duplicate(); if (class_exists("AuditLog")) { AuditLog::addLog(AUDIT_TYPE_TEMPLATE, $this->getId(), $strName, "duplicate", $objReturn->getId()); } if (class_exists("AuditLog")) { AuditLog::addLog(AUDIT_TYPE_TEMPLATE, $objReturn->getId(), $objReturn->getName(), "create"); } //*** Reset the name of the current template. $this->name = $strName; //*** Duplicate the fields of the current template. $objFields = $this->getFields(); foreach ($objFields as $objField) { $objNewField = $objField->duplicate(); $objNewField->setTemplateId($objReturn->getId()); $objNewField->setUsername($objLiveUser->getProperty("name")); $objNewField->save(); } //*** Copy any child templates to the duplicate. $strSql = sprintf("SELECT * FROM pcms_template WHERE parentId = '%s' AND accountId = '%s'", $this->id, $_CONF['app']['account']->getId()); $objTemplates = Template::select($strSql); foreach ($objTemplates as $objTemplate) { $objTemplate->copy($objReturn->getId()); } return $objReturn; } return NULL; }
public function duplicate() { self::$__object = "Template"; self::$__table = "pcms_template"; return parent::duplicate(); }