コード例 #1
0
 /**
  * Copy object into a different project
  *
  * @param void
  * @return null
  */
 function copy()
 {
     if (!$this->active_object->canCopy($this->logged_user)) {
         $this->httpError(HTTP_ERR_FORBIDDEN, null, true, $this->request->isApiCall());
     }
     // if
     if ($this->request->isSubmitted()) {
         $project = null;
         $project_id = (int) $this->request->post('copy_to_project_id');
         if ($project_id) {
             $destination_project = Projects::findById($project_id);
         }
         // if
         $copy_child_objects = $this->request->post('copy_child_objects');
         $this->smarty->assign('data', array('copy_child_objects' => $copy_child_objects));
         if (!instance_of($destination_project, 'Project')) {
             flash_error('Please select destination project');
             $this->redirectToUrl($this->active_object->getCopyUrl());
         }
         // if
         $copy = $this->active_object->copyToProject($destination_project);
         if (instance_of($copy, 'ProjectObject')) {
             if (instance_of($this->active_object, 'Milestone') && $copy_child_objects) {
                 $child_objects = ProjectObjects::findByMilestone($this->active_object);
                 if (is_foreachable($child_objects)) {
                     foreach ($child_objects as $child_object) {
                         $child_copied = $child_object->copyToProject($destination_project, $copy);
                     }
                     // foreach
                 }
                 // if
             }
             // if
             $destination_project->refreshTasksCount();
             flash_success('":name" has been successfully copied to ":project" project', array('name' => $this->active_object->getName(), 'project' => $destination_project->getName()));
             $this->redirectToUrl($copy->getViewUrl());
         } else {
             flash_error('Failed to copy ":name" to ":project" project', array('name' => $this->active_object->getName(), 'project' => $destination_project->getName()));
             $this->redirectToUrl($this->active_object->getCopyUrl());
         }
         // if
     }
     // if
 }