summaryrefslogtreecommitdiff
path: root/demos/time-tracker/protected/App_Code/Dao/ReportsDao.php
blob: 2e566de65097d18748616ac73573acdd524c30c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php

class ProjectReport extends TComponent
{
	public $ProjectName = '';
	public $EstimateHours = 0;
	public $EstimateCompletion = 0;
	public $Categories;

	public function __construct()
	{
		$this->Categories = new TList;
	}

	public function getActualHours()
	{
		$total = 0;
		foreach($this->Categories as $cat)
			$total += $cat->getActualHours();
		return $total;
	}
}

class CategoryReport extends TComponent
{
	public $CategoryName = '';
	public $EstimateHours = 0;
	public $members = array();

	public function getActualHours()
	{
		$total = 0;
		foreach($this->members as $member)
			$total += $member['hours'];
		return $total;
	}
}

class UserReport extends TComponent
{
	public $Username;
	public $Projects = array();

	public function getTotalHours()
	{
		$hours = 0;
		foreach($this->Projects as $project)
			$hours += $project->Duration;
		return $hours;
	}
}

class UserProjectReport
{
	public $ProjectName = '';
	public $CategoryName = '';
	public $Duration = 0;
	public $Description='';
	public $ReportDate=0;
}

class ReportsDao extends BaseDao
{
	public function getTimeReportsByProjectIDs($projects)
	{
		$ids = implode(',', array_map('intval', $projects));
		$sqlmap = $this->getSqlMap();
		return $sqlmap->queryForList('GetTimeReportByProjectIDs', $ids);
	}

	public function getUserProjectTimeReports($users, $projects, $startDate, $endDate)
	{
		$sqlmap = $this->getSqlMap();
		$ids = implode(',', array_map('intval', $projects));
		$sqlmap->getDbConnection()->setActive(true); //db connection needs to be open for quoteString
		$usernames = implode(',', array_map(array($sqlmap->getDbConnection(), 'quoteString'), $users));

		$param['projects'] = $ids;
		$param['members'] = $usernames;
		$param['startDate'] = intval($startDate);
		$param['endDate'] = intval($endDate);

		return $sqlmap->queryForList('GetTimeReportByUsername', $param);
	}
}