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 --- .../pages/TimeTracker/CategoryDataList.php | 94 ++++++++++++ .../pages/TimeTracker/CategoryDataList.tpl | 152 ++++++++++++++++++++ .../protected/pages/TimeTracker/LogTimeEntry.page | 77 ++++++++++ .../protected/pages/TimeTracker/LogTimeEntry.php | 107 ++++++++++++++ .../pages/TimeTracker/ProjectDetails.page | 70 ++++++++- .../protected/pages/TimeTracker/ProjectDetails.php | 160 ++++++++++++++++++++- .../protected/pages/TimeTracker/ProjectList.page | 40 +++++- .../protected/pages/TimeTracker/ProjectList.php | 34 +++++ .../protected/pages/TimeTracker/ReportProject.page | 15 +- .../protected/pages/TimeTracker/SiteMap.tpl | 2 +- .../protected/pages/TimeTracker/TimeEntry.page | 4 - .../protected/pages/TimeTracker/TimeEntryList.php | 89 ++++++++++++ .../protected/pages/TimeTracker/TimeEntryList.tpl | 66 +++++++++ .../protected/pages/TimeTracker/UserList.page | 33 ++--- .../protected/pages/TimeTracker/config.xml | 2 +- 15 files changed, 907 insertions(+), 38 deletions(-) create mode 100644 demos/time-tracker/protected/pages/TimeTracker/CategoryDataList.php create mode 100644 demos/time-tracker/protected/pages/TimeTracker/CategoryDataList.tpl create mode 100644 demos/time-tracker/protected/pages/TimeTracker/LogTimeEntry.page create mode 100644 demos/time-tracker/protected/pages/TimeTracker/LogTimeEntry.php create mode 100644 demos/time-tracker/protected/pages/TimeTracker/ProjectList.php delete mode 100644 demos/time-tracker/protected/pages/TimeTracker/TimeEntry.page create mode 100644 demos/time-tracker/protected/pages/TimeTracker/TimeEntryList.php create mode 100644 demos/time-tracker/protected/pages/TimeTracker/TimeEntryList.tpl (limited to 'demos/time-tracker/protected/pages/TimeTracker') diff --git a/demos/time-tracker/protected/pages/TimeTracker/CategoryDataList.php b/demos/time-tracker/protected/pages/TimeTracker/CategoryDataList.php new file mode 100644 index 00000000..d2772067 --- /dev/null +++ b/demos/time-tracker/protected/pages/TimeTracker/CategoryDataList.php @@ -0,0 +1,94 @@ +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 Category; + $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 Category; + $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(); + } +} + +?> \ No newline at end of file diff --git a/demos/time-tracker/protected/pages/TimeTracker/CategoryDataList.tpl b/demos/time-tracker/protected/pages/TimeTracker/CategoryDataList.tpl new file mode 100644 index 00000000..7a19dadb --- /dev/null +++ b/demos/time-tracker/protected/pages/TimeTracker/CategoryDataList.tpl @@ -0,0 +1,152 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Category NameAbbreviationEstimate Duration
<%# $this->DataItem->Name %><%# $this->DataItem->Abbreviation %><%# $this->DataItem->EstimateDuration %> + + +
+ DataItem->Name %> /> + * + + + DataItem->Abbreviation %> /> + * + + + + DataItem->EstimateDuration %> /> + * + + + + + +
+ + + + + + + + + + + + +
+ + diff --git a/demos/time-tracker/protected/pages/TimeTracker/LogTimeEntry.page b/demos/time-tracker/protected/pages/TimeTracker/LogTimeEntry.page new file mode 100644 index 00000000..ca5797e4 --- /dev/null +++ b/demos/time-tracker/protected/pages/TimeTracker/LogTimeEntry.page @@ -0,0 +1,77 @@ + +

Time Entry

+ +
+ +
+Log your hours +
+ +*
+ +
+ +
+ +*
+ +
+ +
+ +*
+ +
+ +
+ +*
+ + + +
+ +
+
+ +
+ +
+ + + + +
+ +
+ +
+ +
+
+Time Sheet For: + + + + + +
+ +
+
\ No newline at end of file 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 diff --git a/demos/time-tracker/protected/pages/TimeTracker/ProjectDetails.page b/demos/time-tracker/protected/pages/TimeTracker/ProjectDetails.page index 2a7cb6dd..ea384452 100644 --- a/demos/time-tracker/protected/pages/TimeTracker/ProjectDetails.page +++ b/demos/time-tracker/protected/pages/TimeTracker/ProjectDetails.page @@ -1,5 +1,5 @@ -

Create New Project

+

Project Details

Project Configuration

Define the project and specify which users will be part of the project. @@ -10,22 +10,51 @@

Project Information

+ *
+ +
+ *
+ *
+ *
+ +
- +
@@ -36,10 +65,39 @@ -
- - - + +

Define Project Categories for Project Management

+ +

Categories can be added in two ways. You can ADD a category + by specifying name, abbreviation, and duration - + the amount of hours that may be charged under the category. Or, + You can COPY categories that already have been defined in + another project to this project.

+ + + +
+ + + +
+ +
+ +
+ + +

Press the SAVE button for your configuration to take effect. + deleteButton->Visible %>> + Press the DELETE button to delete the current project. + +

+
+ + +
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 diff --git a/demos/time-tracker/protected/pages/TimeTracker/ProjectList.page b/demos/time-tracker/protected/pages/TimeTracker/ProjectList.page index 1bc50a4b..f55360c4 100644 --- a/demos/time-tracker/protected/pages/TimeTracker/ProjectList.page +++ b/demos/time-tracker/protected/pages/TimeTracker/ProjectList.page @@ -1,4 +1,42 @@ -

Projects

+

Projects

+ +
+Project List + + + + + + + NamingContainer->DataItem->CompletionDate %> /> + + + + + +
\ No newline at end of file diff --git a/demos/time-tracker/protected/pages/TimeTracker/ProjectList.php b/demos/time-tracker/protected/pages/TimeTracker/ProjectList.php new file mode 100644 index 00000000..eb92dcb7 --- /dev/null +++ b/demos/time-tracker/protected/pages/TimeTracker/ProjectList.php @@ -0,0 +1,34 @@ +Application->Modules['daos']->getDao('ProjectDao'); + $this->projectList->DataSource = $dao->getAllProjects($sort, $order); + $this->projectList->dataBind(); + } + + protected function getSortOrder($sort) + { + $ordering = $this->getViewState('SortOrder', array()); + $order = isset($ordering[$sort]) ? $ordering[$sort] : 'DESC'; + $ordering[$sort] = $order == 'DESC' ? 'ASC' : 'DESC'; + $this->setViewState('SortOrder', $ordering); + return $ordering[$sort]; + } + + protected function sortProjects($sender, $param) + { + $sort = $param->SortExpression; + $this->showProjects($sort, $this->getSortOrder($sort)); + } + + public function onLoad($param) + { + if(!$this->IsPostBack) + $this->showProjects(); + } +} + +?> \ No newline at end of file diff --git a/demos/time-tracker/protected/pages/TimeTracker/ReportProject.page b/demos/time-tracker/protected/pages/TimeTracker/ReportProject.page index 699c2544..065b6b17 100644 --- a/demos/time-tracker/protected/pages/TimeTracker/ReportProject.page +++ b/demos/time-tracker/protected/pages/TimeTracker/ReportProject.page @@ -1,4 +1,17 @@ -

Project Reports

+

Project Reports

+ +
+ Project Report + + + + + + + + +
\ No newline at end of file diff --git a/demos/time-tracker/protected/pages/TimeTracker/SiteMap.tpl b/demos/time-tracker/protected/pages/TimeTracker/SiteMap.tpl index 808c233b..5bea2811 100644 --- a/demos/time-tracker/protected/pages/TimeTracker/SiteMap.tpl +++ b/demos/time-tracker/protected/pages/TimeTracker/SiteMap.tpl @@ -1,7 +1,7 @@
  • "> - Log + Log
  • User->isInRole('manager') %> >
  • "> diff --git a/demos/time-tracker/protected/pages/TimeTracker/TimeEntry.page b/demos/time-tracker/protected/pages/TimeTracker/TimeEntry.page deleted file mode 100644 index f934ca02..00000000 --- a/demos/time-tracker/protected/pages/TimeTracker/TimeEntry.page +++ /dev/null @@ -1,4 +0,0 @@ - -

    Time Entry

    - -
    \ No newline at end of file diff --git a/demos/time-tracker/protected/pages/TimeTracker/TimeEntryList.php b/demos/time-tracker/protected/pages/TimeTracker/TimeEntryList.php new file mode 100644 index 00000000..2b5f7a0f --- /dev/null +++ b/demos/time-tracker/protected/pages/TimeTracker/TimeEntryList.php @@ -0,0 +1,89 @@ +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; + } + } +} + +?> \ No newline at end of file diff --git a/demos/time-tracker/protected/pages/TimeTracker/TimeEntryList.tpl b/demos/time-tracker/protected/pages/TimeTracker/TimeEntryList.tpl new file mode 100644 index 00000000..ace8a95b --- /dev/null +++ b/demos/time-tracker/protected/pages/TimeTracker/TimeEntryList.tpl @@ -0,0 +1,66 @@ + + + There are no time entries for this user. + + + + + + + + + + + + + +
    Category NameDescriptionDurationReported DateEdit/Delete
    + + + + <%# $this->DataItem->Category->Name %> + <%# $this->DataItem->Description %> + <%# $this->DataItem->Duration %> + + DataItem->ReportDate %> /> + + + + + + + + + + + + + + + DataItem->Description %> /> + + + DataItem->Duration %> /> + + + DataItem->ReportDate %> /> + + + + + + + + +
    \ No newline at end of file diff --git a/demos/time-tracker/protected/pages/TimeTracker/UserList.page b/demos/time-tracker/protected/pages/TimeTracker/UserList.page index f0c88112..3696e1db 100644 --- a/demos/time-tracker/protected/pages/TimeTracker/UserList.page +++ b/demos/time-tracker/protected/pages/TimeTracker/UserList.page @@ -1,31 +1,20 @@ -

    List Users

    +

    Users

    User List - - - - - - - - - - - - - - - - + +
    User NameE-Mail Address
    <%#$this->DataItem->Name %><%#$this->DataItem->EmailAddress %>
    <%#$this->DataItem->Name %>
    + + + + + + + - - - -
    User NameE-Mail Address
    <%#$this->DataItem->Name %> <%#$this->DataItem->EmailAddress %>
    <%#$this->DataItem->Name %> <%#$this->DataItem->EmailAddress %>
    - +
    Create New User diff --git a/demos/time-tracker/protected/pages/TimeTracker/config.xml b/demos/time-tracker/protected/pages/TimeTracker/config.xml index 4497d9e3..b086f8a0 100644 --- a/demos/time-tracker/protected/pages/TimeTracker/config.xml +++ b/demos/time-tracker/protected/pages/TimeTracker/config.xml @@ -13,7 +13,7 @@ - + -- cgit v1.2.3