Пример #1
0
 public function duplicate()
 {
     self::$__object = "Element";
     self::$__table = "pcms_element";
     return parent::duplicate();
 }
Пример #2
0
 public function duplicate($strNewName = "")
 {
     global $objLang, $_CONF, $objLiveUser;
     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_ELEMENT, $this->getId(), $strName, "duplicate", $objReturn->getId());
         }
         if (class_exists("AuditLog")) {
             AuditLog::addLog(AUDIT_TYPE_ELEMENT, $objReturn->getId(), $objReturn->getName(), "create");
         }
         //*** Reset the name of the current element.
         $this->name = $strName;
         //*** Duplicate the fields of the current element.
         $objFields = $this->getFields();
         foreach ($objFields as $objField) {
             $objNewField = $objField->duplicate();
             $objNewField->setElementId($objReturn->getId());
             $objNewField->setUsername($objLiveUser->getProperty("name"));
             $objNewField->save();
             $objNewField->setValue($objField->getValue());
         }
         //*** Copy any child elements to the duplicate.
         $strSql = sprintf("SELECT * FROM pcms_element WHERE parentId = '%s' AND accountId = '%s'", $this->id, $_CONF['app']['account']->getId());
         $objElements = Element::select($strSql);
         foreach ($objElements as $objElement) {
             $objElement->copy($objReturn->getId());
         }
         //*** Save permissions.
         $objTemp = $this->getPermissions();
         $objTemp->setElementId($objReturn->getId());
         $objTemp->save();
         //*** Save language properties.
         $objTemps = $this->getLanguageActives();
         foreach ($objTemps as $key => $value) {
             $objReturn->setLanguageActive($value, TRUE);
         }
         //*** Save schedule information.
         $objTemp = $this->getSchedule();
         $objTemp->id = 0;
         $objReturn->setSchedule($objTemp);
         return $objReturn;
     }
     return NULL;
 }