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/LogTimeEntry.php | 107 +++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 demos/time-tracker/protected/pages/TimeTracker/LogTimeEntry.php (limited to 'demos/time-tracker/protected/pages/TimeTracker/LogTimeEntry.php') diff --git a/demos/time-tracker/protected/pages/TimeTracker/LogTimeEntry.php b/demos/time-tracker/protected/pages/TimeTracker/LogTimeEntry.php new file mode 100644 index 00000000..cc27c93c --- /dev/null +++ b/demos/time-tracker/protected/pages/TimeTracker/LogTimeEntry.php @@ -0,0 +1,107 @@ +Application->Modules['daos']->getDao('ProjectDao'); + } + + protected function getCategoryDao() + { + return $this->Application->Modules['daos']->getDao('CategoryDao'); + } + + protected function getTimeEntryDao() + { + return $this->Application->Modules['daos']->getDao('TimeEntryDao'); + } + + public function onLoad($param) + { + if(!$this->IsPostBack) + { + $projects = $this->getProjects(); + $this->projects->DataSource = $projects; + $this->projects->dataBind(); + $this->showCategories(key($projects)); + } + } + + protected function showCategories($projectID) + { + $categories = array(); + foreach($this->getCategoryDao()->getCategoriesByProjectID($projectID) as $cat) + { + $categories[$cat->ID] = $cat->Name; + } + $this->category->DataSource = $categories; + $this->category->dataBind(); + $this->showProjectUsers($projectID); + } + + protected function showProjectUsers($projectID) + { + if($this->User->isInRole('manager')) + $users = $this->getProjectDao()->getProjectMembers($projectID); + else + $users = array($this->User->Name); + $this->projectMembers->DataSource = $users; + $this->projectMembers->dataBind(); + if(is_int($index = array_search($this->User->Name, $users))) + $this->projectMembers->SelectedIndex = $index; + $this->showTimeSheet(); + } + + public function showTimeSheet() + { + $user = $this->projectMembers->SelectedItem->Text; + $project = $this->projects->SelectedValue; + $this->entryList->setProjectEntry($user,$project); + $this->entryList->refreshEntryList(); + } + + protected function getProjects() + { + $projects = array(); + if($this->User->isInRole('admin')) + $list = $this->getProjectDao()->getAllProjects(); + else if($this->User->isInRole('manager')) + $list = $this->getProjectDao()->getProjectsByManagerName($this->User->Name); + else + $list = $this->getProjectDao()->getProjectsByUserName($this->User->Name); + foreach($list as $project) + $projects[$project->ID] = $project->Name; + return $projects; + } + + public function projects_Changed($sender, $param) + { + $this->showCategories($sender->SelectedValue); + } + + public function AddNewEntry($sender, $param) + { + if(!$this->IsValid) + return; + + $entry = new TimeEntry; + $entry->CreatorUserName = $this->User->Name; + $category = new Category; + $category->ID = $this->category->SelectedValue; + $entry->Category = $category; + $entry->Description = $this->description->Text; + $entry->Duration = floatval($this->hours->Text); + $entry->ReportDate = $this->day->TimeStamp; + $entry->Username = $this->projectMembers->SelectedItem->Text; + + $this->hours->Text = ''; + $this->description->Text = ''; + + $this->getTimeEntryDao()->addNewTimeEntry($entry); + $this->showTimeSheet(); + } +} + +?> \ No newline at end of file -- cgit v1.2.3