From: Nik Okuntseff Date: Fri, 9 Nov 2018 22:18:20 +0000 (+0000) Subject: Improved new export a bit by adding tasks to output. X-Git-Tag: timetracker_1.19-1~674 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=bf2399f1315130312cc513cdd4efbcffaeb617d0;p=timetracker.git Improved new export a bit by adding tasks to output. --- diff --git a/WEB-INF/lib/ttAdmin.class.php b/WEB-INF/lib/ttAdmin.class.php index 30c78f94..23d8480d 100644 --- a/WEB-INF/lib/ttAdmin.class.php +++ b/WEB-INF/lib/ttAdmin.class.php @@ -41,7 +41,17 @@ class ttAdmin { // getSubgroups rerurns an array of subgroups for a group. function getSubgroups($group_id) { - return array(); // TODO: not yet implemented. + $mdb2 = getConnection(); + + $subgroups = array(); + $sql = "select id from tt_groups where parent_id = $group_id"; + $res = $mdb2->query($sql); + if (!is_a($res, 'PEAR_Error')) { + while ($val = $res->fetchRow()) { + $subgroups[] = $val; + } + } + return $subgroups; } // getUsers obtains user ids in a group. diff --git a/WEB-INF/lib/ttGroupExportHelper.class.php b/WEB-INF/lib/ttGroupExportHelper.class.php index af49e19e..5338d2d4 100644 --- a/WEB-INF/lib/ttGroupExportHelper.class.php +++ b/WEB-INF/lib/ttGroupExportHelper.class.php @@ -42,6 +42,7 @@ class ttGroupExportHelper { // We write to the file sequentially (1,2,3...) while in the database the entities have different ids. var $userMap = array(); // User ids. var $roleMap = array(); // Role ids. + var $taskMap = array(); // Task ids. var $clientMap = array(); // Client ids. // Constructor. @@ -114,6 +115,24 @@ class ttGroupExportHelper { return false; } + // getTasks - obtains all tasks defined for group. + function getTasks() { + global $user; + $mdb2 = getConnection(); + + $result = array(); + $sql = "select * from tt_tasks where group_id = $this->group_id and org_id = $user->org_id"; + $res = $mdb2->query($sql); + $result = array(); + if (!is_a($res, 'PEAR_Error')) { + while ($val = $res->fetchRow()) { + $result[] = $val; + } + return $result; + } + return false; + } + // writeData writes group data into file. function writeData() { @@ -138,15 +157,20 @@ class ttGroupExportHelper { foreach ($roles as $key=>$role_item) $this->roleMap[$role_item['id']] = $key + 1; + // Prepare task map. + $tasks = $this->getTasks(); + foreach ($tasks as $key=>$task_item) + $this->taskMap[$task_item['id']] = $key + 1; + // Prepare client map. $clients = ttTeamHelper::getAllClients($this->group_id, true); foreach ($clients as $key=>$client_item) $this->clientMap[$client_item['id']] = $key + 1; // Write roles. - fwrite($this->file, $this->indentation."\n"); + fwrite($this->file, $this->indentation." \n"); foreach ($roles as $role) { - $role_part = $this->indentation.' '."roleMap[$role['id']]."\""; + $role_part = $this->indentation.' '."roleMap[$role['id']]."\""; $role_part .= " name=\"".htmlentities($role['name'])."\""; $role_part .= " description=\"".htmlentities($role['description'])."\""; $role_part .= " rank=\"".$role['rank']."\""; @@ -155,13 +179,25 @@ class ttGroupExportHelper { $role_part .= ">\n"; fwrite($this->file, $role_part); } - fwrite($this->file, $this->indentation."\n"); + fwrite($this->file, $this->indentation." \n"); + + // Write tasks. + fwrite($this->file, $this->indentation." \n"); + foreach ($tasks as $task) { + $task_part = $this->indentation.' '."taskMap[$task['id']]."\""; + $task_part .= " name=\"".htmlentities($task['name'])."\""; + $task_part .= " description=\"".htmlentities($task['description'])."\""; + $task_part .= " status=\"".$task['status']."\""; + $task_part .= ">\n"; + fwrite($this->file, $task_part); + } + fwrite($this->file, $this->indentation." \n"); // Write users. - fwrite($this->file, $this->indentation."\n"); + fwrite($this->file, $this->indentation." \n"); foreach ($users as $user_item) { $role_id = $user_item['rank'] == 512 ? 0 : $this->roleMap[$user_item['role_id']]; // Special role_id 0 (not null) for top manager. - $user_part = $this->indentation.' '."userMap[$user_item['id']]."\""; + $user_part = $this->indentation.' '."userMap[$user_item['id']]."\""; $user_part .= " name=\"".htmlentities($user_item['name'])."\""; $user_part .= " login=\"".htmlentities($user_item['login'])."\""; $user_part .= " password=\"".$user_item['password']."\""; @@ -173,7 +209,7 @@ class ttGroupExportHelper { $user_part .= ">\n"; fwrite($this->file, $user_part); } - fwrite($this->file, $this->indentation."\n"); + fwrite($this->file, $this->indentation." \n"); // Call self recursively for all subgroups. foreach ($this->subgroups as $subgroup) { diff --git a/WEB-INF/lib/ttOrgImportHelper.class.php b/WEB-INF/lib/ttOrgImportHelper.class.php index ba1b120f..015579c0 100644 --- a/WEB-INF/lib/ttOrgImportHelper.class.php +++ b/WEB-INF/lib/ttOrgImportHelper.class.php @@ -27,6 +27,7 @@ // +----------------------------------------------------------------------+ import('ttUserHelper'); +import('ttRoleHelper'); // ttOrgImportHelper - this class is a future replacement for ttImportHelper. // Currently, it is work in progress. @@ -37,10 +38,11 @@ class ttOrgImportHelper { var $canImport = true; // False if we cannot import data due to a conflict such as login collision. var $firstPass = true; // True during first pass through the file. var $org_id = null; // Organization id (same as top group_id). - var $current_parent_group_id = null; // Current parent group id as we parse the file. + var $current_group_id = null; // Current group id during parsing. + var $current_parent_group_id = null; // Current parent group id during parsing. // Set when we create a new group. - // Entities for current group. - var $currentGroupRoles = array(); // Array of arrays of role properties. + // Entities for current group. -- Looks like they are not needed as we insert right away... + // var $currentGroupRoles = array(); // Array of arrays of role properties. // var $currentGroupUsers = array(); // Array of arrays of user properties. // Entity maps for current group. They map XML ids with database ids. @@ -77,7 +79,7 @@ class ttOrgImportHelper { // We are in second pass and can import data. if ($name == 'GROUP') { // Create a new group. - $group_id = $this->createGroup(array( + $this->current_group_id = $this->createGroup(array( 'parent_id' => $this->current_parent_group_id, 'org_id' => $this->org_id, 'name' => $attrs['NAME'], @@ -87,13 +89,13 @@ class ttOrgImportHelper { // Special handling for top group. if (!$this->org_id) { - $this->org_id = $group_id; - $sql = "update tt_groups set org_id = $group_id where org_id is NULL and id = $group_id"; + $this->org_id = $this->current_group_id; + $sql = "update tt_groups set org_id = $this->current_group_id where org_id is NULL and id = $this->current_group_id"; $affected = $mdb2->exec($sql); // TODO: design a better error handling approach for the entire import process. } // Set current parent group. - $this->current_parent_group_id = $group_id; + $this->current_parent_group_id = $this->current_group_id; } if ($name == 'ROLES') { @@ -108,8 +110,16 @@ class ttOrgImportHelper { if ($name == 'ROLE') { // We get here when processing a tag for the current group. - // Add new role to $this->currentGroupRoles and a mapping to $this->currentGroupRoleMap. - $this->currentGroupRoles[$attrs['ID']] = $attrs; + $role_id = ttRoleHelper::insert(array( + 'group_id' => $this->current_group_id, + 'org_id' => $this->org_id, + 'name' => $attrs['NAME'], + 'description' => $attrs['DESCRIPTION'], + 'rank' => $attrs['RANK'], + 'rights' => $attrs['RIGHTS'], + 'status' => $attrs['STATUS'])); + // Add a mapping. + $this->currentGroupRoleMap[$attrs['ID']] = $role_id; } } } diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index fd5880c7..9e7af7c9 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.18.12.4398 | Copyright © Anuko | +  Anuko Time Tracker 1.18.12.4399 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve}