Subversion-Projekte lars-tiefland.prado

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
 
3
class LogTimeEntry extends TPage
4
{
5
 
6
	protected function getProjectDao()
7
	{
8
		return $this->Application->Modules['daos']->getDao('ProjectDao');
9
	}
10
 
11
	protected function getCategoryDao()
12
	{
13
		return $this->Application->Modules['daos']->getDao('CategoryDao');
14
	}
15
 
16
	protected function getTimeEntryDao()
17
	{
18
		return $this->Application->Modules['daos']->getDao('TimeEntryDao');
19
	}
20
 
21
	public function onLoad($param)
22
	{
23
		if(!$this->IsPostBack)
24
		{
25
			$projects = $this->getProjects();
26
			$this->projects->DataSource = $projects;
27
			$this->projects->dataBind();
28
			$this->showCategories(key($projects));
29
		}
30
	}
31
 
32
	protected function showCategories($projectID)
33
	{
34
		$categories = array();
35
		foreach($this->getCategoryDao()->getCategoriesByProjectID($projectID) as $cat)
36
		{
37
			$categories[$cat->ID] = $cat->Name;
38
		}
39
		$this->category->DataSource = $categories;
40
		$this->category->dataBind();
41
		$this->showProjectUsers($projectID);
42
	}
43
 
44
	protected function showProjectUsers($projectID)
45
	{
46
		if($this->User->isInRole('manager'))
47
			$users = $this->getProjectDao()->getProjectMembers($projectID);
48
		else
49
			$users = array($this->User->Name);
50
		$this->projectMembers->DataSource = $users;
51
		$this->projectMembers->dataBind();
52
		if(is_int($index = array_search($this->User->Name, $users)))
53
		{
54
			$this->projectMembers->SelectedIndex = $index;
55
			$this->showTimeSheet();
56
		}
57
	}
58
 
59
	public function showTimeSheet()
60
	{
61
		$user = $this->projectMembers->SelectedItem->Text;
62
		$project = $this->projects->SelectedValue;
63
		$this->entryList->setProjectEntry($user,$project);
64
		$this->entryList->refreshEntryList();
65
	}
66
 
67
	protected function getProjects()
68
	{
69
		$projects = array();
70
		if($this->User->isInRole('admin'))
71
			$list = $this->getProjectDao()->getAllProjects();
72
		else if($this->User->isInRole('manager'))
73
			$list = $this->getProjectDao()->getProjectsByManagerName($this->User->Name);
74
		else
75
			$list = $this->getProjectDao()->getProjectsByUserName($this->User->Name);
76
		foreach($list as $project)
77
			$projects[$project->ID] = $project->Name;
78
		return $projects;
79
	}
80
 
81
	public function projects_Changed($sender, $param)
82
	{
83
		$this->showCategories($sender->SelectedValue);
84
	}
85
 
86
	public function AddNewEntry($sender, $param)
87
	{
88
		if(!$this->IsValid)
89
			return;
90
 
91
		if($this->projectMembers->SelectedItem)
92
		{
93
			$entry = new TimeEntryRecord;
94
			$entry->CreatorUserName = $this->User->Name;
95
			$category = new CategoryRecord;
96
			$category->ID = $this->category->SelectedValue;
97
			$entry->Category = $category;
98
			$entry->Description = $this->description->Text;
99
			$entry->Duration = floatval($this->hours->Text);
100
			$entry->ReportDate = $this->day->TimeStamp;
101
			$entry->Username = $this->projectMembers->SelectedItem->Text;
102
 
103
			$this->hours->Text = '';
104
			$this->description->Text = '';
105
 
106
			$this->getTimeEntryDao()->addNewTimeEntry($entry);
107
			$this->showTimeSheet();
108
		}
109
	}
110
}
111
 
112
?>