summaryrefslogtreecommitdiff
path: root/demos/time-tracker/protected/pages/TimeTracker/CategoryDataList.php
blob: e7ef6856072e7a6a753930884eb2d27b2cb408dc (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
90
91
92
93
<?php

class CategoryDataList extends TTemplateControl
{
	public function setProjectID($value)
	{
		$this->setViewState('ProjectID', $value, '');
	}
	
	public function getProjectID()
	{
		return $this->getViewState('ProjectID', '');
	}
	
	public function getCategories()
	{
		$this->ensureChildControls();
        return $this->getRegisteredObject('categories');
	}
	
	protected function getCategoryDao()
	{
		return $this->Application->Modules['daos']->getDao('CategoryDao');
	}
		
	public function showCategories()
	{
		$categoryDao = $this->getCategoryDao();
		$list = $categoryDao->getCategoriesByProjectID($this->getProjectID());
		$this->categories->DataSource = $list;
		$this->categories->dataBind();
	}
	
	public function deleteCategoryItem($sender, $param)
	{
		$id = $this->categories->DataKeys[$param->Item->ItemIndex];
		$this->getCategoryDao()->deleteCategory($id);
		$this->refreshCategoryList($sender, $param);
	}
	
	public function editCategoryItem($sender, $param)
	{
		$this->categories->EditItemIndex=$param->Item->ItemIndex;
		$this->showCategories();
	}
	
	public function refreshCategoryList($sender, $param)
	{
		$this->categories->EditItemIndex=-1;
		$this->showCategories();
	}
	
	public function updateCategoryItem($sender, $param)
	{		
		if(!$this->Page->IsValid)
			return;
			
		$item = $param->Item;
		
		$id = $this->categories->DataKeys[$param->Item->ItemIndex];
		$category = new CategoryRecord;
		$category->ID = $id;
		$category->Name = $item->name->Text;
		$category->Abbreviation = $item->abbrev->Text;
		$category->EstimateDuration = floatval($item->duration->Text);
		$category->ProjectID = $this->getProjectID();
		
		$this->getCategoryDao()->updateCategory($category);
		
		$this->refreshCategoryList($sender, $param);
	}
	
	public function addCategory_clicked($sender, $param)
	{
		if(!$this->Page->IsValid)
			return;
		
		$newCategory = new CategoryRecord;
		$newCategory->Name = $this->categoryName->Text;
		$newCategory->Abbreviation = $this->abbrev->Text;
		$newCategory->EstimateDuration = floatval($this->duration->Text);
		$newCategory->ProjectID = $this->getProjectID();
			
		$this->getCategoryDao()->addNewCategory($newCategory);
		
		$this->categoryName->Text = '';
		$this->abbrev->Text = '';
		$this->duration->Text = '';
		
		$this->showCategories();
	}	
}