/**
  * Move object into a different project
  *
  * @param void
  * @return null
  */
 function move()
 {
     if (!$this->active_object->canMove($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('move_to_project_id');
         if ($project_id) {
             $destination_project = Projects::findById($project_id);
         }
         // if
         $move_child_objects = $this->request->post('move_child_objects');
         $this->smarty->assign('data', array('move_child_objects' => $move_child_objects));
         if (!instance_of($destination_project, 'Project')) {
             flash_error('Please select destination project');
             $this->redirectToUrl($this->active_object->getMoveUrl());
         }
         // if
         $source_project = $this->active_object->getProject();
         if (instance_of($this->active_object, 'Milestone') && $move_child_objects) {
             $child_objects = ProjectObjects::findByMilestone($this->active_object);
         } else {
             $child_objects = null;
         }
         // if
         $move = $this->active_object->moveToProject($destination_project);
         if ($move && !is_error($move)) {
             if (is_foreachable($child_objects)) {
                 foreach ($child_objects as $child_object) {
                     $child_moved = $child_object->moveToProject($destination_project, $this->active_object);
                 }
                 // foreach
             }
             // if
             if (instance_of($source_project, 'Project')) {
                 $source_project->refreshTasksCount();
             }
             // if
             $destination_project->refreshTasksCount();
             flash_success('":name" has been successfully moved to ":project" project', array('name' => $this->active_object->getName(), 'project' => $destination_project->getName()));
             $this->redirectToUrl($this->active_object->getViewUrl());
         } else {
             flash_error('Failed to move ":name" to ":project" project', array('name' => $this->active_object->getName(), 'project' => $destination_project->getName()));
             $this->redirectToUrl($this->active_object->getMoveUrl());
         }
         // if
     }
     // if
 }
 /**
  * Clone subscriptions from $from to $to object
  *
  * @param ProjectObject $from
  * @param ProjectObject $to
  * @return boolean
  */
 function cloneSubscriptions($from, $to)
 {
     $project = $to->getProject();
     // we need it to check if user has access to a given project
     $rows = db_execute_all('SELECT * FROM ' . TABLE_PREFIX . 'subscriptions WHERE parent_id = ?', $from->getId());
     if (is_foreachable($rows)) {
         foreach ($rows as $row) {
             $user = Users::findById($row['user_id']);
             if (instance_of($user, 'User') && $user->isProjectMember($project)) {
                 Subscriptions::subscribe($user, $to);
             }
             // if
         }
         // if
     }
     // if
     return true;
 }
 /**
  * Clone assignmnets from $from to $to object
  *
  * @param ProjectObject $from
  * @param ProjectObject $to
  * @return boolean
  */
 function cloneAssignments($from, $to)
 {
     $rows = db_execute_all('SELECT * FROM ' . TABLE_PREFIX . 'assignments WHERE object_id = ?', $from->getId());
     if (is_foreachable($rows)) {
         $project = $to->getProject();
         // we need it to check if user has access to a given project
         $owner_id = null;
         $assignees = null;
         foreach ($rows as $row) {
             $user = Users::findById($row['user_id']);
             if (instance_of($user, 'User') && $user->isProjectMember($project)) {
                 if ($row['is_owner']) {
                     $owner_id = (int) $row['user_id'];
                 } else {
                     $assignees[] = (int) $row['user_id'];
                 }
             }
             // if
         }
         // if
         if ($owner_id) {
             $object_id = $to->getId();
             $to_insert = array("({$owner_id}, {$object_id}, '1')");
             if (is_foreachable($assignees)) {
                 foreach ($assignees as $user_id) {
                     $to_insert[] = "({$user_id}, {$object_id}, '0')";
                 }
                 // foreach
             }
             // if
             return db_execute('INSERT INTO ' . TABLE_PREFIX . 'assignments (user_id, object_id, is_owner) VALUES ' . implode(', ', $to_insert));
         }
         // if
     }
     // if
     return true;
 }