From 280d6ea0ee096843551d7734b23377ec06d42e81 Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Sat, 17 Nov 2018 22:38:52 +0000 Subject: [PATCH] Started to populate tt_project_task_binds with group_id and org_id. --- WEB-INF/lib/ttOrgImportHelper.class.php | 4 ++-- WEB-INF/lib/ttProjectHelper.class.php | 12 +++++----- WEB-INF/lib/ttTaskHelper.class.php | 29 ++++++++++++++----------- WEB-INF/templates/footer.tpl | 2 +- 4 files changed, 26 insertions(+), 21 deletions(-) diff --git a/WEB-INF/lib/ttOrgImportHelper.class.php b/WEB-INF/lib/ttOrgImportHelper.class.php index 6764ba53..d95aabb4 100644 --- a/WEB-INF/lib/ttOrgImportHelper.class.php +++ b/WEB-INF/lib/ttOrgImportHelper.class.php @@ -204,8 +204,8 @@ class ttOrgImportHelper { foreach ($tasks as $id) $mapped_tasks[] = $this->currentGroupTaskMap[$id]; - $project_id = ttProjectHelper::insert(array( - 'group_id' => $this->current_group_id, + $project_id = ttProjectHelper::insert(array( // TODO: continue refactoring, write a separate, simple function to import projects + 'group_id' => $this->current_group_id, // because ttProjectHelper::insert is complicated. 'org_id' => $this->org_id, 'name' => $attrs['NAME'], 'description' => $attrs['DESCRIPTION'], diff --git a/WEB-INF/lib/ttProjectHelper.class.php b/WEB-INF/lib/ttProjectHelper.class.php index 47783d59..240760df 100644 --- a/WEB-INF/lib/ttProjectHelper.class.php +++ b/WEB-INF/lib/ttProjectHelper.class.php @@ -226,7 +226,8 @@ class ttProjectHelper { $all_tasks = ttTeamHelper::getAllTasks($group_id); foreach ($all_tasks as $task) { if(in_array($task['id'], $tasks)) { - $sql = "insert into tt_project_task_binds (project_id, task_id) values($last_id, ".$task['id'].")"; + $sql = "insert into tt_project_task_binds (project_id, task_id, group_id, org_id)". + " values($last_id, ".$task['id'].", $group_id, $org_id)"; $affected = $mdb2->exec($sql); if (is_a($affected, 'PEAR_Error')) return false; @@ -240,7 +241,9 @@ class ttProjectHelper { static function update($fields) { global $user; $mdb2 = getConnection(); - + + $group_id = $user->getActiveGroup(); + $org_id = $user->org_id; $project_id = $fields['id']; // Project we are updating. $name = $fields['name']; // Project name. $description = $fields['description']; // Project description. @@ -271,8 +274,6 @@ class ttProjectHelper { while ($row = $res->fetchRow()) { $user_rate[$row['id']] = $row['rate']; } - $group_id = $user->getActiveGroup(); - $org_id = $user->org_id; foreach ($users_to_add as $id) { $sql = "insert into tt_user_project_binds (user_id, project_id, group_id, org_id, rate, status)". " values($id, $project_id, $group_id, $org_id, ".$user_rate[$id].", 1)"; @@ -308,7 +309,8 @@ class ttProjectHelper { return false; } foreach ($task_binds_to_add as $task_id) { - $sql = "insert into tt_project_task_binds (project_id, task_id) values($project_id, $task_id)"; + $sql = "insert into tt_project_task_binds (project_id, task_id, group_id, org_id)". + " values($project_id, $task_id, $group_id, $org_id)"; $affected = $mdb2->exec($sql); if (is_a($affected, 'PEAR_Error')) return false; diff --git a/WEB-INF/lib/ttTaskHelper.class.php b/WEB-INF/lib/ttTaskHelper.class.php index b4644d51..2c0fbe1e 100644 --- a/WEB-INF/lib/ttTaskHelper.class.php +++ b/WEB-INF/lib/ttTaskHelper.class.php @@ -157,12 +157,13 @@ class ttTaskHelper { if (is_array($projects)) { foreach ($projects as $p_id) { // Insert task binds into tt_project_task_binds table. - $sql = "insert into tt_project_task_binds (project_id, task_id) values($p_id, $last_id)"; + $sql = "insert into tt_project_task_binds (project_id, task_id, group_id, org_id)". + " values($p_id, $last_id, $group_id, $org_id)"; $affected = $mdb2->exec($sql); - if (is_a($affected, 'PEAR_Error')) - return false; + if (is_a($affected, 'PEAR_Error')) + return false; - // Add task bind to the tasks field of the tt_projects table. + // Add task bind to the tasks field of the tt_projects table. $sql = "select tasks from tt_projects where id = $p_id"; $res = $mdb2->query($sql); if (is_a($res, 'PEAR_Error')) @@ -171,16 +172,16 @@ class ttTaskHelper { $val = $res->fetchRow(); $task_ids = $val['tasks']; if ($task_ids) { - $task_ids .= ",$last_id"; - $task_ids = ttTaskHelper::sort($task_ids); - } else - $task_ids = $last_id; + $task_ids .= ",$last_id"; + $task_ids = ttTaskHelper::sort($task_ids); + } else + $task_ids = $last_id; $sql = "update tt_projects set tasks = ".$mdb2->quote($task_ids)." where id = $p_id"; $affected = $mdb2->exec($sql); if (is_a($affected, 'PEAR_Error')) return false; - } + } } return $last_id; } @@ -189,9 +190,10 @@ class ttTaskHelper { static function update($fields) { global $user; - $mdb2 = getConnection(); + $group_id = $user->getActiveGroup(); + $org_id = $user->org_id; $task_id = (int)$fields['task_id']; $name = $fields['name']; $description = $fields['description']; @@ -199,7 +201,7 @@ class ttTaskHelper { $projects = $fields['projects']; $sql = "update tt_tasks set name = ".$mdb2->quote($name).", description = ".$mdb2->quote($description). - ", status = $status where id = $task_id and group_id = $user->group_id"; + ", status = $status where id = $task_id and group_id = $group_id"; $affected = $mdb2->exec($sql); if (is_a($affected, 'PEAR_Error')) die($affected->getMessage()); @@ -211,7 +213,8 @@ class ttTaskHelper { die($affected->getMessage()); if (count($projects) > 0) foreach ($projects as $p_id) { - $sql = "insert into tt_project_task_binds (project_id, task_id) values($p_id, $task_id)"; + $sql = "insert into tt_project_task_binds (project_id, task_id, group_id, org_id)". + " values($p_id, $task_id, $group_id, $org_id)"; $affected = $mdb2->exec($sql); if (is_a($affected, 'PEAR_Error')) die($affected->getMessage()); @@ -221,7 +224,7 @@ class ttTaskHelper { // We need to either delete or insert task id in all affected projects. // Get all not deleted projects for group. - $sql = "select id, tasks from tt_projects where group_id = $user->group_id and status is not NULL"; + $sql = "select id, tasks from tt_projects where group_id = $group_id and status is not NULL"; $res = $mdb2->query($sql); if (is_a($res, 'PEAR_Error')) die($res->getMessage()); diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index 433f5934..a01384cc 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.18.17.4446 | Copyright © Anuko | +  Anuko Time Tracker 1.18.17.4447 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} -- 2.20.1