From: Nik Okuntseff Date: Fri, 30 Nov 2018 15:57:21 +0000 (+0000) Subject: A bit more progress on decoupling import. X-Git-Tag: timetracker_1.19-1~516 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=dd0021e48080a708591d7ad763c63f5fb98e3fb7;p=timetracker.git A bit more progress on decoupling import. --- diff --git a/WEB-INF/lib/ttOrgImportHelper.class.php b/WEB-INF/lib/ttOrgImportHelper.class.php index ebb5febd..cbf7d28a 100644 --- a/WEB-INF/lib/ttOrgImportHelper.class.php +++ b/WEB-INF/lib/ttOrgImportHelper.class.php @@ -27,7 +27,6 @@ // +----------------------------------------------------------------------+ import('ttUserHelper'); -import('ttTaskHelper'); import('ttInvoiceHelper'); // ttOrgImportHelper class is used to import organization data from an XML file @@ -167,7 +166,7 @@ class ttOrgImportHelper { if ($name == 'TASK') { // We get here when processing tags for the current group. - $task_id = ttTaskHelper::insert(array( + $task_id = $this->insertTask(array( 'group_id' => $this->current_group_id, 'org_id' => $this->org_id, 'name' => $attrs['NAME'], @@ -700,6 +699,29 @@ class ttOrgImportHelper { return (!is_a($affected, 'PEAR_Error')); } + // insertTask function inserts a new task into database. + private function insertTask($fields) + { + $mdb2 = getConnection(); + + $group_id = (int) $fields['group_id']; + $org_id = (int) $fields['org_id']; + $name = $fields['name']; + $description = $fields['description']; + $projects = $fields['projects']; + $status = $fields['status']; + + $sql = "insert into tt_tasks (group_id, org_id, name, description, status) + values ($group_id, $org_id, ".$mdb2->quote($name).", ".$mdb2->quote($description).", ".$mdb2->quote($status).")"; + $affected = $mdb2->exec($sql); + $last_id = 0; + if (is_a($affected, 'PEAR_Error')) + return false; + + $last_id = $mdb2->lastInsertID('tt_tasks', 'id'); + return $last_id; + } + // insertProject - a helper function to insert a project as well as project to task binds. private function insertProject($fields) { diff --git a/WEB-INF/lib/ttTaskHelper.class.php b/WEB-INF/lib/ttTaskHelper.class.php index 2987d278..01567406 100644 --- a/WEB-INF/lib/ttTaskHelper.class.php +++ b/WEB-INF/lib/ttTaskHelper.class.php @@ -137,10 +137,11 @@ class ttTaskHelper { // insert function inserts a new task into database. static function insert($fields) { + global $user; $mdb2 = getConnection(); - $group_id = (int) $fields['group_id']; - $org_id = (int) $fields['org_id']; + $group_id = $user->getGroup(); + $org_id = $user->org_id; $name = $fields['name']; $description = $fields['description']; $projects = $fields['projects']; @@ -270,17 +271,17 @@ class ttTaskHelper { // sort function sorts task ids passed as comma-separated list by their name. static function sort($comma_separated) { - // We can't sort an empty string. - if (!$comma_separated) - return $comma_separated; - + // We can't sort an empty string. + if (!$comma_separated) + return $comma_separated; + $mdb2 = getConnection(); - - $sql = "select id, name from tt_tasks where id in ($comma_separated)"; + + $sql = "select id, name from tt_tasks where id in ($comma_separated)"; $res = $mdb2->query($sql); if (is_a($res, 'PEAR_Error')) die ($res->getMessage()); - + $task_arr = array(); while ($val = $res->fetchRow()) { $task_arr[] = array('id'=>$val['id'],'name'=>$val['name']); @@ -290,7 +291,7 @@ class ttTaskHelper { for($i = 0; $i < count($task_arr); $i++) { $task_ids[] = $task_arr[$i]['id']; } - $result = implode(',', $task_ids); + $result = implode(',', $task_ids); return $result; } } diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index 3b96b55b..85ad89fe 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.18.28.4548 | Copyright © Anuko | +  Anuko Time Tracker 1.18.28.4549 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/mobile/task_add.php b/mobile/task_add.php index 00300347..9deed925 100644 --- a/mobile/task_add.php +++ b/mobile/task_add.php @@ -68,8 +68,6 @@ if ($request->isPost()) { if ($err->no()) { if (!ttTaskHelper::getTaskByName($cl_name)) { if (ttTaskHelper::insert(array( - 'group_id' => $user->getGroup(), - 'org_id' => $user->org_id, 'name' => $cl_name, 'description' => $cl_description, 'status' => ACTIVE, diff --git a/mobile/task_edit.php b/mobile/task_edit.php index 47dc5d71..ba36ea56 100644 --- a/mobile/task_edit.php +++ b/mobile/task_edit.php @@ -103,8 +103,6 @@ if ($request->isPost()) { if ($request->getParameter('btn_copy')) { if (!ttTaskHelper::getTaskByName($cl_name)) { if (ttTaskHelper::insert(array( - 'group_id' => $user->getGroup(), - 'org_id' => $user->org_id, 'name' => $cl_name, 'description' => $cl_description, 'status' => $cl_status, diff --git a/task_add.php b/task_add.php index 91f0e4fc..1fdc7b18 100644 --- a/task_add.php +++ b/task_add.php @@ -68,8 +68,6 @@ if ($request->isPost()) { if ($err->no()) { if (!ttTaskHelper::getTaskByName($cl_name)) { if (ttTaskHelper::insert(array( - 'group_id' => $user->getGroup(), - 'org_id' => $user->org_id, 'name' => $cl_name, 'description' => $cl_description, 'status' => ACTIVE, diff --git a/task_edit.php b/task_edit.php index c9f95ecb..efe8509d 100644 --- a/task_edit.php +++ b/task_edit.php @@ -101,8 +101,6 @@ if ($request->isPost()) { if ($request->getParameter('btn_copy')) { if (!ttTaskHelper::getTaskByName($cl_name)) { if (ttTaskHelper::insert(array( - 'group_id' => $user->getGroup(), - 'org_id' => $user->org_id, 'name' => $cl_name, 'description' => $cl_description, 'status' => $cl_status,