From cbb7a11179b9c1c46e35f04d07d6386a44e400b2 Mon Sep 17 00:00:00 2001 From: wei <> Date: Sun, 23 Jul 2006 11:11:21 +0000 Subject: Update time-tracker demo and add simple dynamic SQLMap --- .../protected/pages/TimeTracker/ProjectDetails.php | 160 ++++++++++++++++++++- 1 file changed, 158 insertions(+), 2 deletions(-) (limited to 'demos/time-tracker/protected/pages/TimeTracker/ProjectDetails.php') diff --git a/demos/time-tracker/protected/pages/TimeTracker/ProjectDetails.php b/demos/time-tracker/protected/pages/TimeTracker/ProjectDetails.php index 16c10e6f..767e259c 100644 --- a/demos/time-tracker/protected/pages/TimeTracker/ProjectDetails.php +++ b/demos/time-tracker/protected/pages/TimeTracker/ProjectDetails.php @@ -2,7 +2,30 @@ class ProjectDetails extends TPage { - private $allUsers = null; + private $allUsers; + + private $currentProject; + + protected function getCurrentProject() + { + if(!$this->currentProject) + { + $id = intval($this->Request['ProjectID']); + if($id > 0) + $this->currentProject = $this->getProjectDao()->getProjectByID($id); + } + return $this->currentProject; + } + + protected function getProjectDao() + { + return $this->Application->Modules['daos']->getDao('ProjectDao'); + } + + protected function getCategoryDao() + { + return $this->Application->Modules['daos']->getDao('CategoryDao'); + } public function onLoad($param) { @@ -12,7 +35,53 @@ class ProjectDetails extends TPage $this->manager->dataBind(); $this->members->DataSource = $this->getUsersWithRole('consultant'); $this->members->dataBind(); + + $project = $this->getCurrentProject(); + + if($project !== null) + { + $this->projectName->Text = $project->Name; + $this->completionDate->TimeStamp = $project->CompletionDate; + $this->description->Text = $project->Description; + $this->estimateHours->Text = $project->EstimateDuration; + $this->manager->SelectedValue = $project->ManagerUserName; + + $this->selectProjectMembers($project->ID); + + $this->projectCategoryColumn->Visible = true; + $this->categories->ProjectID = $project->ID; + $this->categories->showCategories(); + + $this->deleteButton->Visible = true; + + $this->projectList->DataSource = $this->getProjects(); + $this->projectList->dataBind(); + + } + else + { + $this->projectCategoryColumn->Visible = false; + $this->deleteButton->Visible = false; + } + + } + } + + protected function getProjects() + { + $projects = array(); + foreach($this->getProjectDao()->getAllProjects() as $project) + { + if($project->Name != $this->currentProject->Name) + $projects[$project->ID] = $project->Name; } + return $projects; + } + + protected function selectProjectMembers($projectID) + { + $members = $this->getProjectDao()->getProjectMembers($projectID); + $this->members->SelectedValues = $members; } protected function getUsersWithRole($role) @@ -26,10 +95,97 @@ class ProjectDetails extends TPage foreach($this->allUsers as $user) { if($user->isInRole($role)) - $users[] = $user->Name; + $users[$user->Name] = $user->Name; } return $users; } + + public function onPreRender($param) + { + $ids = array(); + foreach($this->members->Items as $item) + { + if($item->Selected) + $ids[] = $item->Value; + } + $this->setViewState('ActiveConsultants', $ids); + } + + public function saveButton_clicked($sender, $param) + { + if(!$this->Page->IsValid) + return; + + $newProject = new Project; + + $projectDao = $this->getProjectDao(); + + if($project = $this->getCurrentProject()) + $newProject = $projectDao->getProjectByID($project->ID); + else + $newProject->CreatorUserName = $this->User->Name; + + $newProject->Name = $this->projectName->Text; + $newProject->CompletionDate = $this->completionDate->TimeStamp; + $newProject->Description = $this->description->Text; + $newProject->EstimateDuration = floatval($this->estimateHours->Text); + $newProject->ManagerUserName = $this->manager->SelectedValue; + + if($this->currentProject) + $projectDao->updateProject($newProject); + else + $projectDao->addNewProject($newProject); + + $this->updateProjectMembers($newProject->ID); + + $url = $this->Service->constructUrl('TimeTracker.ProjectDetails', + array('ProjectID'=> $newProject->ID)); + + $this->Response->redirect($url); + } + + protected function updateProjectMembers($projectID) + { + $active = $this->getViewState('ActiveConsultants'); + $projectDao = $this->getProjectDao(); + foreach($this->members->Items as $item) + { + if($item->Selected) + { + if(!in_array($item->Value, $active)) + $projectDao->addUserToProject($projectID, $item->Value); + } + else + { + if(in_array($item->Value, $active)) + $projectDao->removeUserFromProject($projectID, $item->Value); + } + } + } + + public function deleteButton_clicked($sender, $param) + { + if($project = $this->getCurrentProject()) + { + $this->getProjectDao()->deleteProject($project->ID); + $url = $this->Service->constructUrl('TimeTracker.ProjectList'); + $this->Response->redirect($url); + } + } + + public function copyButton_clicked($sender, $param) + { + $project = $this->projectList->SelectedValue; + $categoryDao = $this->getCategoryDao(); + $categories = $categoryDao->getCategoriesByProjectID($project); + $currentProject = $this->getCurrentProject(); + foreach($categories as $cat) + { + $cat->ProjectID = $currentProject->ID; + $categoryDao->addNewCategory($cat); + } + $this->categories->showCategories(); + } } ?> \ No newline at end of file -- cgit v1.2.3