Exemple #1
0
 /**
  * public static getCloneFromID
  *
  * Clones a Row, changes some attributes
  * and writes it to persistence (MySQL for now)
  *
  * @param anyRowID as the ID of Row to be cloned
  * @param String label receive a new label for this Row
  * @param boolean $setPrivate Should the template be set as a private one ?  ALSO determines if the new row should point to the same file
  * @return a valid new CMS_row
  */
 static function getCloneFromID($rowID = 0, $label = false, $setPrivate = false)
 {
     $ret = false;
     $model = new CMS_row($rowID);
     if ($model->getID() > 0) {
         //New blank one
         $row = new CMS_row();
         //First write a new object to get it's ID
         $row->writeToPersistence();
         //Setting label
         $label = $label ? $label : $model->getLabel();
         $row->setLabel($label);
         //Copying template definition file (if not private template)
         if ($setPrivate) {
             $filename = $model->getDefinitionFileName();
         } else {
             $filename = "r" . $row->getID() . "_" . SensitiveIO::sanitizeAsciiString($row->getLabel()) . ".xml";
         }
         if ($setPrivate || CMS_file::copyTo(PATH_TEMPLATES_ROWS_FS . "/" . $model->getDefinitionFileName(), PATH_TEMPLATES_ROWS_FS . "/" . $filename)) {
             $row->setDefinitionFile($filename);
             //Copying groupsStack from database
             foreach ($model->getGroups() as $grp) {
                 $row->addGroup($grp);
             }
             //Copying image
             $row->setImage($model->getImage(CMS_file::WEBROOT, true));
             //set private if asked to.
             if ($setPrivate) {
                 $row->setPrivate(true);
             }
             //copy description
             $row->setDescription($model->getDescription());
             //add filtered templates
             $row->setFilteredTemplates($model->getFilteredTemplates());
             //Partial update for groups and image
             $row->writeToPersistence();
             $ret = $row;
         }
         unset($model);
     }
     if ($row) {
         //Clean if any error when out
         if (!$ret) {
             $row->destroy();
         }
         unset($row);
     }
     return $ret;
 }