X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/timetracker.git/blobdiff_plain/abfd3bbc6a72c55b30d48466b2719804ebee6733..60c61508f8586f489fc8795c93d9bd45e41467c1:/WEB-INF/lib/ttGroupExportHelper.class.php diff --git a/WEB-INF/lib/ttGroupExportHelper.class.php b/WEB-INF/lib/ttGroupExportHelper.class.php index 9ac4464a..364f984d 100644 --- a/WEB-INF/lib/ttGroupExportHelper.class.php +++ b/WEB-INF/lib/ttGroupExportHelper.class.php @@ -33,24 +33,65 @@ // When done, it should handle export of organizations containing multiple groups. class ttGroupExportHelper { - var $group_id = null; // Group we are exporting. - var $file = null; // File to write to. - var $indentation = null; // A string consisting of a number of spaces. + var $group_id = null; // Group we are exporting. + var $file = null; // File to write to. + var $indentation = null; // A string consisting of a number of spaces. + var $subgroups = array(); // Immediate subgroups. // Constructor. function __construct($group_id, $file, $indentation) { + global $user; $this->group_id = $group_id; $this->file = $file; $this->indentation = $indentation; - // TODO: Build a list of subgroups here. + // Build a list of subgroups. + $mdb2 = getConnection(); + $sql = "select id from tt_groups". + " where status = 1 and parent_id = $this->group_id and org_id = $user->org_id"; + $res = $mdb2->query($sql); + if (!is_a($res, 'PEAR_Error')) { + while ($val = $res->fetchRow()) { + $this->subgroups[] = $val; + } + } + } + + // getGroupData obtains group attributes for export. + function getGroupData() { + global $user; + + $mdb2 = getConnection(); + $sql = "select name, currency, lang from tt_groups". + " where status = 1 and id = $this->group_id and org_id = $user->org_id"; + $res = $mdb2->query($sql); + if (!is_a($res, 'PEAR_Error')) { + $val = $res->fetchRow(); + } + return $val; } // writeData writes group data into file. function writeData() { - // TODO: write code here. - // - // Call itself recursively for all subgroups. + + // Write group info. + $group = $this->getGroupData(); + $group_part = "file, $this->indentation.$group_part); + + // Call self recursively for all subgroups. + foreach ($this->subgroups as $subgroup) { + $subgroup_helper = new ttGroupExportHelper($subgroup['id'], $this->file, $this->indentation.' '); + $subgroup_helper->writeData(); + } + + fwrite($this->file, $this->indentation."\n"); } }