summaryrefslogtreecommitdiff
path: root/demos/time-tracker/protected/pages/TimeTracker/TimeEntryList.php
blob: 2b5f7a0f01b6f0b493f8e82e04821d746c794b6c (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
87
88
89
<?php

class TimeEntryList extends TTemplateControl
{
	protected function getTimeEntryDao()
	{
		return $this->Application->Modules['daos']->getDao('TimeEntryDao');
	}

	protected function getCategoryDao()
	{
		return $this->Application->Modules['daos']->getDao('CategoryDao');
	}
		
	public function setProjectEntry($userID,$projectID)
	{
		$this->setViewState('ProjectEntry', array($userID,$projectID));
	}
	
	protected function getCategories()
	{	
		$project = $this->getViewState('ProjectEntry');
		foreach($this->getCategoryDao()->getCategoriesByProjectID($project[1]) as $cat)
		{
			$categories[$cat->ID] = $cat->Name;
		}
		return $categories;
	}
	
	protected function showEntryList()
	{
		$project = $this->getViewState('ProjectEntry');
		$list = $this->getTimeEntryDao()->getTimeEntriesInProject($project[0], $project[1]);
		$this->entries->DataSource = $list;
		$this->entries->dataBind();
	}
	
	public function refreshEntryList()
	{
		$this->entries->EditItemIndex=-1;
		$this->showEntryList();
	}
	
	public function editEntryItem($sender, $param)
	{
		$this->entries->EditItemIndex=$param->Item->ItemIndex;
		$this->showEntryList();
	}	

	public function deleteEntryItem($sender, $param)
	{
		$id = $this->entries->DataKeys[$param->Item->ItemIndex];
		$this->getTimeEntryDao()->deleteTimeEntry($id);
		$this->refreshEntryList();
	}
			
	public function updateEntryItem($sender, $param)
	{		
		if(!$this->Page->IsValid)
			return;
			
		$item = $param->Item;
		
		$id = $this->entries->DataKeys[$param->Item->ItemIndex];
		
		$entry = $this->getTimeEntryDao()->getTimeEntryByID($id);
		$category = new Category;
		$category->ID = $param->Item->category->SelectedValue;
		$entry->Category = $category;
		$entry->Description = $param->Item->description->Text;
		$entry->Duration = floatval($param->Item->hours->Text);
		$entry->ReportDate = $param->Item->day->TimeStamp;
		
		$this->getTimeEntryDao()->updateTimeEntry($entry);		
		$this->refreshEntryList();
	}

	public function EntryItemCreated($sender, $param)
	{
		if($param->Item->ItemType == 'EditItem' && $param->Item->DataItem)
		{
			$param->Item->category->DataSource = $this->getCategories();	
			$param->Item->category->dataBind();
			$param->Item->category->SelectedValue = $param->Item->DataItem->Category->ID;
		}
	}
}

?>