summaryrefslogtreecommitdiff
path: root/demos/time-tracker/protected/pages/TimeTracker/ReportResource.php
blob: a233e127f148bf00a3c52d041522235a0f73e598 (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
<?php

class ReportResource extends TPage
{
	protected function getProjects()
	{
		$projectDao = $this->Application->Modules['daos']->getDao('ProjectDao');
		$projects = array();
		foreach($projectDao->getAllProjects() as $project)
				$projects[$project->ID] = $project->Name;
		return $projects;
	}
	
	protected function getUsers()
	{
		$dao = $this->Application->Modules['daos']->getDao('UserDao');
		$users = array();
		foreach($dao->getAllUsers() as $user)
		{
			$users[$user->Name] = $user->Name;
		}
		return $users;
	}
	
	public function onLoad($param)
	{
		if(!$this->IsPostBack)
		{
			$this->projectList->DataSource = $this->getProjects();
			$this->resourceList->DataSource = $this->getUsers();
			$this->dataBind();	
		}
	}	
	
	public function generateReport_Clicked($sender, $param)
	{
		$this->views->ActiveViewIndex = 1;
		$reportDao = $this->Application->Modules['daos']->getDao('ReportDao');
		$projects = $this->projectList->SelectedValues;
		$users = $this->resourceList->SelectedValues;
		$start = $this->dateFrom->TimeStamp;
		$end = $this->dateTo->TimeStamp;
		
		$report = $reportDao->getUserProjectTimeReports($users, $projects, $start, $end);
		$this->resource_report->DataSource = $report;
		$this->resource_report->dataBind();
	}
	
	public function resource_report_itemCreated($sender, $param)
	{
		$item = $param->Item;
		if($item->ItemType==='Item' || $item->ItemType==='AlternatingItem')
		{
			if(count($item->DataItem->Projects) > 0 &&
				$item->DataItem->Projects[0]->ProjectName !== null)
			$item->time_entries->DataSource = $item->DataItem->Projects;
		}
	}
}

?>