} // prepare (and translate) the module name ready for the suffix if ($del) { $result = $obj->delete(); if (is_array($result)) { $AppUI->setMsg($msg, UI_MSG_ERROR); $AppUI->redirect(); } else { $AppUI->setMsg('Task deleted'); $AppUI->redirect('', -1); } } $result = $obj->store($AppUI); if ($taskRecount) { $myTask = new CTask(); CProject::updateTaskCount($taskRecount, $myTask->getTaskCount($taskRecount)); } //$obj->task_project if (is_array($result)) { $AppUI->setMsg($result, UI_MSG_ERROR, true); $AppUI->holdObject($obj); $AppUI->redirect('m=tasks&a=addedit'); } if ($result) { $task_parent = (int) w2PgetParam($_POST, 'task_parent', 0); $old_task_parent = (int) w2PgetParam($_POST, 'old_task_parent', 0); if ($task_parent != $old_task_parent) { $oldTask = new CTask(); $oldTask->load($old_task_parent); $oldTask->updateDynamics(false); }
/** * @todo Parent store could be partially used * @todo Can't delete a task with children */ public function delete(CAppUI $AppUI = null) { global $AppUI; $q = new DBQuery(); $this->_action = 'deleted'; //load it before deleting it because we need info on it to update the parents later on $this->load($this->task_id); addHistory('tasks', $this->task_id, 'delete', $this->task_name, $this->task_project); // delete children $childrenlist = $this->getChildren(); foreach ($childrenlist as $child) { $task = new CTask(); $task->task_id = $child; $task->delete($AppUI); } $taskList = $childrenlist + array($this->task_id); $implodedTaskList = implode(',', $taskList); // delete linked user tasks $q->setDelete('user_tasks'); $q->addWhere('task_id IN (' . $implodedTaskList . ')'); if (!$q->exec()) { return db_error(); } $q->clear(); $q->setDelete('tasks'); $q->addWhere('task_id=' . (int) $this->task_id); if (!$q->exec()) { return db_error(); } elseif ($this->task_parent != $this->task_id) { // Has parent, run the update sequence, this child will no longer be in the // database $this->updateDynamics(); } $q->clear(); // delete affiliated task_logs $q->setDelete('task_log'); $q->addWhere('task_log_task IN (' . $implodedTaskList . ')'); if (!$q->exec()) { return db_error(); } $q->clear(); // delete affiliated task_dependencies $q->setDelete('task_dependencies'); $q->addWhere('dependencies_task_id IN (' . $implodedTaskList . ') OR dependencies_req_task_id IN (' . $implodedTaskList . ')'); if (!$q->exec()) { return db_error(); } else { $this->_action = 'deleted'; } $q->clear(); CProject::updateTaskCount($this->task_project, $this->getTaskCount($this->task_project)); return null; }
/** * This method handles moving the $task_id specified from $project_old to * $project_new and then updates the corresponding task counts and task * start/end dates for the projects. * * @todo Get the start/end dates for the cache.. - updateTaskCache * * @param type $task_id * @param type $project_old * @param type $project_new */ public function moveTaskBetweenProjects($task_id, $project_old, $project_new) { $this->updateSubTasksProject($project_new, $task_id); $this->removeDependencies(); $this->task_project = $project_new; $this->task_parent = $this->task_id; $this->store(); $taskCount_oldProject = $this->getTaskCount($project_old); CProject::updateTaskCount($project_old, $taskCount_oldProject); $taskCount_newProject = $this->getTaskCount($project_new); CProject::updateTaskCount($project_new, $taskCount_newProject); }