/**	Import tasks from another project
  *
  *	@param	int		Project ID of the tasks come from.
  *	@return	bool
  **/
 public function importTasks($from_project_id)
 {
     global $AppUI;
     $errors = array();
     // Load the original
     $origProject = new CProject();
     $origProject->load($from_project_id);
     $q = $this->_query;
     $q->addTable('tasks');
     $q->addQuery('task_id');
     $q->addWhere('task_project =' . (int) $from_project_id);
     $tasks = array_flip($q->loadColumn());
     $q->clear();
     $origDate = new w2p_Utilities_Date($origProject->project_start_date);
     $destDate = new w2p_Utilities_Date($this->project_start_date);
     $timeOffset = $origDate->dateDiff($destDate);
     if ($origDate->compare($origDate, $destDate) > 0) {
         $timeOffset = -1 * $timeOffset;
     }
     // Dependencies array
     $deps = array();
     // Copy each task into this project and get their deps
     foreach ($tasks as $orig => $void) {
         $objTask = new CTask();
         $objTask->load($orig);
         $destTask = $objTask->copy($this->project_id);
         $tasks[$orig] = $destTask;
         $deps[$orig] = $objTask->getDependencies();
     }
     // Fix record integrity
     foreach ($tasks as $old_id => $newTask) {
         // Fix parent Task
         // This task had a parent task, adjust it to new parent task_id
         if ($newTask->task_id != $newTask->task_parent) {
             $newTask->task_parent = $tasks[$newTask->task_parent]->task_id;
         }
         // Fix task start date from project start date offset
         $origDate->setDate($newTask->task_start_date);
         $origDate->addDays($timeOffset);
         $destDate = $origDate;
         $newTask->task_start_date = $destDate->format(FMT_DATETIME_MYSQL);
         // Fix task end date from start date + work duration
         if (!empty($newTask->task_end_date) && $newTask->task_end_date != '0000-00-00 00:00:00') {
             $origDate->setDate($newTask->task_end_date);
             $origDate->addDays($timeOffset);
             $destDate = $origDate;
             $newTask->task_end_date = $destDate->format(FMT_DATETIME_MYSQL);
         }
         // Dependencies
         if (!empty($deps[$old_id])) {
             $oldDeps = explode(',', $deps[$old_id]);
             // New dependencies array
             $newDeps = array();
             foreach ($oldDeps as $dep) {
                 $newDeps[] = $tasks[$dep]->task_id;
             }
             // Update the new task dependencies
             $csList = implode(',', $newDeps);
             $newTask->updateDependencies($csList);
         }
         // end of update dependencies
         $result = $newTask->store($AppUI);
         $newTask->addReminder();
         $importedTasks[] = $newTask->task_id;
         if (is_array($result) && count($result)) {
             foreach ($result as $key => $error_msg) {
                 $errors[] = $newTask->task_name . ': ' . $error_msg;
             }
         }
     }
     // end Fix record integrity
     // We have errors, so rollback everything we've done so far
     if (count($errors)) {
         foreach ($importedTasks as $badTask) {
             $delTask = new CTask();
             $delTask->task_id = $badTask;
             $delTask->delete($AppUI);
         }
     }
     return $errors;
 }
示例#2
0
 /**	Import tasks from another project
  *
  *	@param	int		Project ID of the tasks come from.
  *	@return	bool
  **/
 function importTasks($from_project_id, $scale_project = false)
 {
     // Load the original
     $origProject = new CProject();
     $origProject->load($from_project_id);
     $q = new DBQuery();
     $q->addTable('tasks');
     $q->addQuery('task_id');
     $q->addWhere('task_project =' . $from_project_id);
     $sql = $q->prepare();
     $q->clear();
     $tasks = array_flip(db_loadColumn($sql));
     //Pristine Start and End Dates of Source and Destination Projects
     $origStartDate = new CDate($origProject->project_start_date);
     $origEndDate = new CDate($origProject->project_end_date);
     $destStartDate = new CDate($this->project_start_date);
     $destEndDate = new CDate($this->project_end_date);
     $dateOffset = $destStartDate->dateDiff($origStartDate);
     //Check that we have enough information to scale properly
     //(i.e. no information is missing or "zero")
     if (empty($origProject->project_start_date) || empty($origProject->project_end_date) || empty($this->project_start_date) || empty($this->project_end_date) || $origProject->project_start_date == '0000-00-00 00:00:00' || $origProject->project_end_date == '0000-00-00 00:00:00' || $this->project_start_date == '0000-00-00 00:00:00' || $this->project_end_date == '0000-00-00 00:00:00') {
         $scale_project = false;
     }
     if ($scale_project) {
         //get ratio for scaling, protect from division by 0
         $ratio = (abs($destEndDate->dateDiff($destStartDate)) + 1) / (abs($origEndDate->dateDiff($origStartDate)) + 1);
     }
     // Old dependencies array from imported tasks
     $deps = array();
     // New dependencies array for new copies of imported tasks
     $newDeps = array();
     // Old2New task ID array
     $taskXref = array();
     // New task ID to old parent array
     $nid2op = array();
     // Copy each task into this project and get their deps
     foreach ($tasks as $orig => $void) {
         $objTask = new CTask();
         $objTask->load($orig);
         // Grab the old parent id
         $oldParent = (int) $objTask->task_parent;
         $deps[$orig] = $objTask->getDependencies();
         $destTask = $objTask->copy($this->project_id, 0);
         $nid2op[$destTask->task_id] = $oldParent;
         $tasks[$orig] = $destTask;
         $taskXref[$orig] = (int) $destTask->task_id;
     }
     // Build new dependencies array
     foreach ($deps as $odkey => $od) {
         $ndt = '';
         $ndkey = $taskXref[$odkey];
         $odep = explode(',', $od);
         foreach ($odep as $odt) {
             $ndt = $ndt . $taskXref[$odt] . ',';
         }
         $ndt = rtrim($ndt, ',');
         $newDeps[$ndkey] = $ndt;
     }
     $q->addTable('tasks');
     $q->addQuery('task_id');
     $q->addWhere('task_project =' . $this->project_id);
     $tasks = $q->loadColumn();
     // Update dates based on new project's start date.
     $origDate = new CDate($origProject->project_start_date);
     $origStartHour = new CDate($this->project_start_date);
     $destDate = new CDate($this->project_start_date);
     foreach ($tasks as $task_id) {
         $newTask = new CTask();
         $newTask->load($task_id);
         if (in_array($task_id, $taskXref)) {
             $task_date_vars = array('task_start_date', 'task_end_date');
             //Adjust task dates based on calculated offsets
             foreach ($task_date_vars as $my_date) {
                 if (!empty($newTask->{$my_date}) && $newTask->{$my_date} != '0000-00-00 00:00:00') {
                     $origDate->setDate($newTask->{$my_date});
                     $origStartHour->setDate($newTask->{$my_date});
                     $origStartHour->setTime(intval(dPgetConfig('cal_day_start')));
                     $destDate->setDate($newTask->{$my_date});
                     $destDate->addDays($dateOffset);
                     if ($scale_project) {
                         $offsetAdd = round($origDate->dateDiff($origStartDate) * $ratio) - $origDate->dateDiff($origStartDate);
                         $destDate->addDays($offsetAdd);
                         $hours_in = $origStartHour->calcDuration($origDate);
                         $offsetAddHours = round($hours_in * $ratio) - $hours_in;
                         if ($offsetAddHours % dPgetConfig('daily_working_hours')) {
                             $destDate->addDuration($offsetAddHours);
                         }
                     }
                     $destDate = $destDate->next_working_day();
                     $newTask->{$my_date} = $destDate->format(FMT_DATETIME_MYSQL);
                 }
             }
             //Adjust durration to scale
             if ($scale_project) {
                 $newTask->task_duration = round($newTask->task_duration * $ratio, 2);
             }
             $newTask->task_parent = $taskXref[$nid2op[$newTask->task_id]];
             $newTask->store();
             $newTask->updateDependencies($newDeps[$task_id]);
         }
         // end check if imported task
         $newTask->store();
     }
     // end Fix record integrity
 }
示例#3
0
 } else {
     if ($action == 'm') {
         //move task
         if (isset($children)) {
             $t->deepMove($new_project, $new_task);
         } else {
             $t->move($new_project, $new_task);
         }
         $t->store();
     } else {
         if ($action == 'c') {
             //copy task
             if (isset($children)) {
                 $t2 = $t->deepCopy($new_project, $new_task);
             } else {
                 $t2 = $t->copy($new_project, $new_task);
             }
             $t2->store();
         } else {
             if ($action > -2 && $action < 2) {
                 //set priority
                 $t->task_priority = $action;
                 $t->store();
                 if (isset($children)) {
                     foreach ($children as $child_id) {
                         $child_t = new CTask();
                         $child_t->load($child_id);
                         $child_t->task_priority = $action;
                         $child_t->store();
                     }
                 }
 /**	Import tasks from another project
  *
  *	@param	int		Project ID of the tasks come from.
  *	@return	bool	
  **/
 function importTasks($from_project_id)
 {
     // Load the original
     $origProject = new CProject();
     $origProject->load($from_project_id);
     $q = new DBQuery();
     $q->addTable('tasks');
     $q->addQuery('task_id');
     $q->addWhere('task_project =' . $from_project_id);
     $sql = $q->prepare();
     $q->clear();
     $tasks = array_flip(db_loadColumn($sql));
     $origDate = new CDate($origProject->project_start_date);
     $destDate = new CDate($this->project_start_date);
     $timeOffset = $destDate->getTime() - $origDate->getTime();
     // Dependencies array
     $deps = array();
     // Copy each task into this project and get their deps
     foreach ($tasks as $orig => $void) {
         $objTask = new CTask();
         $objTask->load($orig);
         $destTask = $objTask->copy($this->project_id);
         $tasks[$orig] = $destTask;
         $deps[$orig] = $objTask->getDependencies();
     }
     // Fix record integrity
     foreach ($tasks as $old_id => $newTask) {
         // Fix parent Task
         // This task had a parent task, adjust it to new parent task_id
         if ($newTask->task_id != $newTask->task_parent) {
             $newTask->task_parent = $tasks[$newTask->task_parent]->task_id;
         }
         // Fix task start date from project start date offset
         $origDate->setDate($newTask->task_start_date);
         $destDate->setDate($origDate->getTime() + $timeOffset, DATE_FORMAT_UNIXTIME);
         $destDate = $destDate->next_working_day();
         $newTask->task_start_date = $destDate->format(FMT_DATETIME_MYSQL);
         // Fix task end date from start date + work duration
         //$newTask->calc_task_end_date();
         if (!empty($newTask->task_end_date) && $newTask->task_end_date != '0000-00-00 00:00:00') {
             $origDate->setDate($newTask->task_end_date);
             $destDate->setDate($origDate->getTime() + $timeOffset, DATE_FORMAT_UNIXTIME);
             $destDate = $destDate->next_working_day();
             $newTask->task_end_date = $destDate->format(FMT_DATETIME_MYSQL);
         }
         // Dependencies
         if (!empty($deps[$old_id])) {
             $oldDeps = explode(',', $deps[$old_id]);
             // New dependencies array
             $newDeps = array();
             foreach ($oldDeps as $dep) {
                 $newDeps[] = $tasks[$dep]->task_id;
             }
             // Update the new task dependencies
             $csList = implode(',', $newDeps);
             $newTask->updateDependencies($csList);
         }
         // end of update dependencies
         $newTask->store();
     }
     // end Fix record integrity
 }
 /**	Import tasks from another project
  *
  *	@param	int		Project ID of the tasks come from.
  *	@return	bool	
  **/
 function importTasks($from_project_id)
 {
     // Load the original
     $origProject = new CProject();
     $origProject->load($from_project_id);
     $q = new DBQuery();
     $q->addTable('tasks');
     $q->addQuery('task_id');
     $q->addWhere('task_project =' . $from_project_id);
     $sql = $q->prepare();
     $q->clear();
     $tasks = array_flip(db_loadColumn($sql));
     $origDate = new CDate($origProject->project_start_date);
     $destDate = new CDate($this->project_start_date);
     $timeOffset = $destDate->getTime() - $origDate->getTime();
     $objTask = new CTask();
     // Dependencies array
     $deps = array();
     // Copy each task into this project and get their deps, y tambien copia los usuarios asignados
     foreach ($tasks as $orig => $void) {
         $objTask->load($orig);
         $destTask = $objTask->copy($this->project_id);
         $tasks[$orig] = $destTask;
         if ($this->project_company == $origProject->project_company) {
             // guarda en user_tasks todos los usuarios asignados a la tarea original, solo si this y
             //  origProy pertenecen a la misma compañía.
             $sql = "select * from user_tasks where task_id = {$orig}";
             $rows = db_LoadList($sql);
             foreach ($rows as $row) {
                 $sql2 = "INSERT INTO user_tasks (user_id, user_type, task_id, perc_assignment, user_task_priority) \n\t\t\t\t\t\t\t\tVALUES (" . $row['user_id'] . "," . $row['user_type'] . "," . $destTask->task_id . "," . $row['perc_assignment'] . "," . $row['user_task_priority'] . ")";
                 db_exec($sql2);
             }
         }
         $deps[$orig] = $objTask->getDependencies();
     }
     // Fix record integrity
     foreach ($tasks as $old_id => $newTask) {
         // Fix parent Task
         // This task had a parent task, adjust it to new parent task_id
         if ($newTask->task_id != $newTask->task_parent) {
             $newTask->task_parent = $tasks[$newTask->task_parent]->task_id;
         }
         // Fix task start date from project start date offset
         $origDate->setDate($newTask->task_start_date);
         $destDate->setDate($origDate->getTime() + $timeOffset, DATE_FORMAT_UNIXTIME);
         $destDate = $newTask->next_working_day($destDate);
         $newTask->task_start_date = $destDate->format(FMT_DATETIME_MYSQL);
         // Fix task end date from start date + work duration
         $newTask->calc_task_end_date();
         // Dependencies
         if (!empty($deps[$old_id])) {
             $oldDeps = explode(',', $deps[$old_id]);
             // New dependencies array
             $newDeps = array();
             foreach ($oldDeps as $dep) {
                 $newDeps[] = $tasks[$dep]->task_id;
             }
             // Update the new task dependencies
             $csList = implode(',', $newDeps);
             $newTask->updateDependencies($csList);
         }
         // end of update dependencies
         //Asignados
         $newTask->store();
     }
     // end Fix record integrity
 }
示例#6
0
 /**	Import tasks from another project
  *
  *	@param	int		Project ID of the tasks come from.
  *	@return	bool	
  **/
 function importTasks($from_project_id)
 {
     // Load the original
     $origProject = new CProject();
     $origProject->load($from_project_id);
     $q = new DBQuery();
     $q->addTable('tasks');
     $q->addQuery('task_id');
     $q->addWhere('task_project =' . $from_project_id);
     $sql = $q->prepare();
     $q->clear();
     $tasks = array_flip(db_loadColumn($sql));
     $origDate = new CDate($origProject->project_start_date);
     $destDate = new CDate($this->project_start_date);
     $dateOffset = $destDate->dateDiff($origDate);
     // Old dependencies array from imported tasks
     $deps = array();
     // New dependencies array for new copies of imported tasks
     $newDeps = array();
     // Old2New task ID array
     $taskXref = array();
     // New task ID to old parent array
     $nid2op = array();
     // Copy each task into this project and get their deps
     foreach ($tasks as $orig => $void) {
         $objTask = new CTask();
         $objTask->load($orig);
         // Grab the old parent id
         $oldParent = (int) $objTask->task_parent;
         $deps[$orig] = $objTask->getDependencies();
         $destTask = $objTask->copy($this->project_id, 0);
         $nid2op[$destTask->task_id] = $oldParent;
         $tasks[$orig] = $destTask;
         $taskXref[$orig] = (int) $destTask->task_id;
     }
     // Build new dependencies array
     foreach ($deps as $odkey => $od) {
         $ndt = '';
         $ndkey = $taskXref[$odkey];
         $odep = explode(',', $od);
         foreach ($odep as $odt) {
             $ndt = $ndt . $taskXref[$odt] . ',';
         }
         $ndt = rtrim($ndt, ',');
         $newDeps[$ndkey] = $ndt;
     }
     $q->addTable('tasks');
     $q->addQuery('task_id');
     $q->addWhere('task_project =' . $this->project_id);
     $tasks = $q->loadColumn();
     // Update dates based on new project's start date.
     foreach ($tasks as $task_id) {
         $newTask = new CTask();
         $newTask->load($task_id);
         if (in_array($task_id, $taskXref)) {
             // Fix task start date from project start date offset
             $origDate->setDate($newTask->task_start_date);
             $destDate->setDate($newTask->task_start_date);
             $destDate->addDays($dateOffset);
             $destDate = $destDate->next_working_day();
             $newTask->task_start_date = $destDate->format(FMT_DATETIME_MYSQL);
             // Fix task end date from start date + work duration
             //$newTask->calc_task_end_date();
             if (!empty($newTask->task_end_date) && $newTask->task_end_date != '0000-00-00 00:00:00') {
                 $origDate->setDate($newTask->task_end_date);
                 $destDate->setDate($newTask->task_end_date);
                 $destDate->addDays($dateOffset);
                 $destDate = $destDate->next_working_day();
                 $newTask->task_end_date = $destDate->format(FMT_DATETIME_MYSQL);
             }
             $newTask->task_parent = $taskXref[$nid2op[$newTask->task_id]];
             $newTask->store();
             $newTask->updateDependencies($newDeps[$task_id]);
         }
         // end check if imported task
         $newTask->store();
     }
     // end Fix record integrity
 }