Exemplo n.º 1
0
 /**
  * Copy existing form and data to new form
  *
  * @return mixed
  **/
 public function copy()
 {
     $title = $this->getTitle();
     $questions = $this->getPageLayout();
     $oldId = $this->getId();
     // Save new
     $this->id = null;
     $id = $this->getId();
     $this->setTitle($title);
     $base = $this->base . $oldId;
     // Copy actual files
     if (is_dir($base)) {
         // Scan for versions
         $versions = array();
         $dirs = scandir($base);
         foreach ($dirs as $dir) {
             if (is_numeric($dir) && is_dir($base . DS . $dir) && $dir != '.' && $dir != '..') {
                 $versions[] = $dir;
             }
         }
         if (!empty($versions)) {
             $base .= DS . max($versions);
         }
         \Filesystem::copyDirectory($base, $this->base . $id);
     }
     // Copy questions
     $this->setPageLayout($questions);
     // Copy deployment (only most recent)
     try {
         $dep = PdfFormDeployment::latestFromFormId($oldId);
         $dep->setId(null);
         $dep->setFormId($id);
         $dep->genNewCrumb();
         $dep->save();
         // Return the deployment crumb
         return $dep->getCrumb();
     } catch (\Hubzero\Error\Exception\RuntimeException $e) {
         // Just return the form id
         return $id;
     }
 }