2 // +----------------------------------------------------------------------+
3 // | Anuko Time Tracker
4 // +----------------------------------------------------------------------+
5 // | Copyright (c) Anuko International Ltd. (https://www.anuko.com)
6 // +----------------------------------------------------------------------+
7 // | LIBERAL FREEWARE LICENSE: This source code document may be used
8 // | by anyone for any purpose, and freely redistributed alone or in
9 // | combination with other software, provided that the license is obeyed.
11 // | There are only two ways to violate the license:
13 // | 1. To redistribute this code in source form, with the copyright
14 // | notice or license removed or altered. (Distributing in compiled
15 // | forms without embedded copyright notices is permitted).
17 // | 2. To redistribute modified versions of this code in *any* form
18 // | that bears insufficient indications that the modifications are
19 // | not the work of the original author(s).
21 // | This license applies to this document only, not any other software
22 // | that it may be combined with.
24 // +----------------------------------------------------------------------+
26 // | https://www.anuko.com/time_tracker/credits.htm
27 // +----------------------------------------------------------------------+
29 // ttGroupExportHelper - this class is used to write data for a single group
30 // to a file. When group contains other groups, it reuses itself recursively.
32 // Currently, it is work in progress.
33 // When done, it should handle export of organizations containing multiple groups.
34 class ttGroupExportHelper {
36 var $group_id = null; // Group we are exporting.
37 var $file = null; // File to write to.
38 var $indentation = null; // A string consisting of a number of spaces.
39 var $subgroups = array(); // Immediate subgroups.
42 function __construct($group_id, $file, $indentation) {
45 $this->group_id = $group_id;
47 $this->indentation = $indentation;
49 // Build a list of subgroups.
50 $mdb2 = getConnection();
51 $sql = "select id from tt_groups".
52 " where status = 1 and parent_id = $this->group_id and org_id = $user->org_id order by id desc";
53 $res = $mdb2->query($sql);
54 if (!is_a($res, 'PEAR_Error')) {
55 while ($val = $res->fetchRow()) {
56 $this->subgroups[] = $val;
61 // writeData writes group data into file.
62 function writeData() {
63 // TODO: write code here.
65 // Write group info. Something dummy for now to test...
66 fwrite($this->file, $this->indentation."<group>\n");
68 // Call itself recursively for all subgroups.
69 foreach ($this->subgroups as $subgroup) {
70 $subgroup_helper = new ttGroupExportHelper($subgroup['id'], $this->file, $this->indentation.' ');
71 $subgroup_helper->writeData();
74 fwrite($this->file, $this->indentation."</group>\n");