Example #1
0
 public function duplicate($strNewName = "")
 {
     global $objLang, $_CONF;
     if ($this->id > 0) {
         //*** Cache the name of the current element.
         $strName = $this->name;
         if (!empty($strNewName)) {
             //*** Set the name of the duplicate element.
             $this->name = sprintf($strNewName, $strName);
         }
         //*** Duplicate the element.
         $objReturn = parent::duplicate();
         if (class_exists("AuditLog")) {
             AuditLog::addLog(AUDIT_TYPE_STORAGE, $this->getId(), $strName, "duplicate", $objReturn->getId());
         }
         if (class_exists("AuditLog")) {
             AuditLog::addLog(AUDIT_TYPE_STORAGE, $objReturn->getId(), $objReturn->getName(), "create");
         }
         //*** Reset the name of the current element.
         $this->name = $strName;
         //*** Copy any child elements to the duplicate.
         $strSql = sprintf("SELECT * FROM pcms_storage_item WHERE parentId = '%s' AND accountId = '%s'", $this->id, $_CONF['app']['account']->getId());
         $objElements = StorageItem::select($strSql);
         foreach ($objElements as $objElement) {
             $objElement->copy($objReturn->getId());
         }
         return $objReturn;
     }
     return NULL;
 }