| 1 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
class ProjectDetails extends TPage
|
|
|
4 |
{
|
|
|
5 |
private $allUsers;
|
|
|
6 |
|
|
|
7 |
private $currentProject;
|
|
|
8 |
|
|
|
9 |
protected function getCurrentProject()
|
|
|
10 |
{
|
|
|
11 |
if(!$this->currentProject)
|
|
|
12 |
{
|
|
|
13 |
$id = intval($this->Request['ProjectID']);
|
|
|
14 |
if($id > 0)
|
|
|
15 |
$this->currentProject = $this->getProjectDao()->getProjectByID($id);
|
|
|
16 |
}
|
|
|
17 |
return $this->currentProject;
|
|
|
18 |
}
|
|
|
19 |
|
|
|
20 |
protected function getProjectDao()
|
|
|
21 |
{
|
|
|
22 |
return $this->Application->Modules['daos']->getDao('ProjectDao');
|
|
|
23 |
}
|
|
|
24 |
|
|
|
25 |
protected function getCategoryDao()
|
|
|
26 |
{
|
|
|
27 |
return $this->Application->Modules['daos']->getDao('CategoryDao');
|
|
|
28 |
}
|
|
|
29 |
|
|
|
30 |
public function onLoad($param)
|
|
|
31 |
{
|
|
|
32 |
if(!$this->IsPostBack)
|
|
|
33 |
{
|
|
|
34 |
$this->manager->DataSource = $this->getUsersWithRole('manager');
|
|
|
35 |
$this->manager->dataBind();
|
|
|
36 |
$this->members->DataSource = $this->getUsersWithRole('consultant');
|
|
|
37 |
$this->members->dataBind();
|
|
|
38 |
|
|
|
39 |
$project = $this->getCurrentProject();
|
|
|
40 |
|
|
|
41 |
if($project !== null)
|
|
|
42 |
{
|
|
|
43 |
$this->projectName->Text = $project->Name;
|
|
|
44 |
$this->completionDate->TimeStamp = $project->CompletionDate;
|
|
|
45 |
$this->description->Text = $project->Description;
|
|
|
46 |
$this->estimateHours->Text = $project->EstimateDuration;
|
|
|
47 |
$this->manager->SelectedValue = $project->ManagerUserName;
|
|
|
48 |
|
|
|
49 |
$this->selectProjectMembers($project->ID);
|
|
|
50 |
|
|
|
51 |
$this->projectCategoryColumn->Visible = true;
|
|
|
52 |
$this->categories->ProjectID = $project->ID;
|
|
|
53 |
$this->categories->showCategories();
|
|
|
54 |
|
|
|
55 |
$this->deleteButton->Visible = true;
|
|
|
56 |
|
|
|
57 |
$this->projectList->DataSource = $this->getProjects();
|
|
|
58 |
$this->projectList->dataBind();
|
|
|
59 |
|
|
|
60 |
}
|
|
|
61 |
else
|
|
|
62 |
{
|
|
|
63 |
$this->projectCategoryColumn->Visible = false;
|
|
|
64 |
$this->deleteButton->Visible = false;
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
}
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
protected function getProjects()
|
|
|
71 |
{
|
|
|
72 |
$projects = array();
|
|
|
73 |
foreach($this->getProjectDao()->getAllProjects() as $project)
|
|
|
74 |
{
|
|
|
75 |
if($project->Name != $this->currentProject->Name)
|
|
|
76 |
$projects[$project->ID] = $project->Name;
|
|
|
77 |
}
|
|
|
78 |
return $projects;
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
protected function selectProjectMembers($projectID)
|
|
|
82 |
{
|
|
|
83 |
$members = $this->getProjectDao()->getProjectMembers($projectID);
|
|
|
84 |
$this->members->SelectedValues = $members;
|
|
|
85 |
}
|
|
|
86 |
|
|
|
87 |
protected function getUsersWithRole($role)
|
|
|
88 |
{
|
|
|
89 |
if(is_null($this->allUsers))
|
|
|
90 |
{
|
|
|
91 |
$dao = $this->Application->Modules['daos']->getDao('UserDao');
|
|
|
92 |
$this->allUsers = $dao->getAllUsers();
|
|
|
93 |
}
|
|
|
94 |
$users = array();
|
|
|
95 |
foreach($this->allUsers as $user)
|
|
|
96 |
{
|
|
|
97 |
if($user->isInRole($role))
|
|
|
98 |
$users[$user->Name] = $user->Name;
|
|
|
99 |
}
|
|
|
100 |
return $users;
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
public function onPreRender($param)
|
|
|
104 |
{
|
|
|
105 |
$ids = array();
|
|
|
106 |
foreach($this->members->Items as $item)
|
|
|
107 |
{
|
|
|
108 |
if($item->Selected)
|
|
|
109 |
$ids[] = $item->Value;
|
|
|
110 |
}
|
|
|
111 |
$this->setViewState('ActiveConsultants', $ids);
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
public function saveButton_clicked($sender, $param)
|
|
|
115 |
{
|
|
|
116 |
if(!$this->Page->IsValid)
|
|
|
117 |
return;
|
|
|
118 |
|
|
|
119 |
$newProject = new ProjectRecord;
|
|
|
120 |
|
|
|
121 |
$projectDao = $this->getProjectDao();
|
|
|
122 |
|
|
|
123 |
if($project = $this->getCurrentProject())
|
|
|
124 |
$newProject = $projectDao->getProjectByID($project->ID);
|
|
|
125 |
else
|
|
|
126 |
$newProject->CreatorUserName = $this->User->Name;
|
|
|
127 |
|
|
|
128 |
$newProject->Name = $this->projectName->Text;
|
|
|
129 |
$newProject->CompletionDate = $this->completionDate->TimeStamp;
|
|
|
130 |
$newProject->Description = $this->description->Text;
|
|
|
131 |
$newProject->EstimateDuration = floatval($this->estimateHours->Text);
|
|
|
132 |
$newProject->ManagerUserName = $this->manager->SelectedValue;
|
|
|
133 |
|
|
|
134 |
if($this->currentProject)
|
|
|
135 |
$projectDao->updateProject($newProject);
|
|
|
136 |
else
|
|
|
137 |
$projectDao->addNewProject($newProject);
|
|
|
138 |
|
|
|
139 |
$this->updateProjectMembers($newProject->ID);
|
|
|
140 |
|
|
|
141 |
$url = $this->Service->constructUrl('TimeTracker.ProjectDetails',
|
|
|
142 |
array('ProjectID'=> $newProject->ID));
|
|
|
143 |
|
|
|
144 |
$this->Response->redirect($url);
|
|
|
145 |
}
|
|
|
146 |
|
|
|
147 |
protected function updateProjectMembers($projectID)
|
|
|
148 |
{
|
|
|
149 |
$active = $this->getViewState('ActiveConsultants');
|
|
|
150 |
$projectDao = $this->getProjectDao();
|
|
|
151 |
foreach($this->members->Items as $item)
|
|
|
152 |
{
|
|
|
153 |
if($item->Selected)
|
|
|
154 |
{
|
|
|
155 |
if(!in_array($item->Value, $active))
|
|
|
156 |
$projectDao->addUserToProject($projectID, $item->Value);
|
|
|
157 |
}
|
|
|
158 |
else
|
|
|
159 |
{
|
|
|
160 |
if(in_array($item->Value, $active))
|
|
|
161 |
$projectDao->removeUserFromProject($projectID, $item->Value);
|
|
|
162 |
}
|
|
|
163 |
}
|
|
|
164 |
}
|
|
|
165 |
|
|
|
166 |
public function deleteButton_clicked($sender, $param)
|
|
|
167 |
{
|
|
|
168 |
if($project = $this->getCurrentProject())
|
|
|
169 |
{
|
|
|
170 |
$this->getProjectDao()->deleteProject($project->ID);
|
|
|
171 |
$url = $this->Service->constructUrl('TimeTracker.ProjectList');
|
|
|
172 |
$this->Response->redirect($url);
|
|
|
173 |
}
|
|
|
174 |
}
|
|
|
175 |
|
|
|
176 |
public function copyButton_clicked($sender, $param)
|
|
|
177 |
{
|
|
|
178 |
$project = $this->projectList->SelectedValue;
|
|
|
179 |
$categoryDao = $this->getCategoryDao();
|
|
|
180 |
$categories = $categoryDao->getCategoriesByProjectID($project);
|
|
|
181 |
$currentProject = $this->getCurrentProject();
|
|
|
182 |
foreach($categories as $cat)
|
|
|
183 |
{
|
|
|
184 |
$cat->ProjectID = $currentProject->ID;
|
|
|
185 |
$categoryDao->addNewCategory($cat);
|
|
|
186 |
}
|
|
|
187 |
$this->categories->showCategories();
|
|
|
188 |
}
|
|
|
189 |
}
|
|
|
190 |
|
|
|
191 |
?>
|