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/App_Code/CategoryDao.php | 5 +-
.../time-tracker/protected/App_Code/ProjectDao.php | 11 +-
.../protected/App_Data/time_tracker.db | Bin 16384 -> 17408 bytes
demos/time-tracker/protected/application.xml | 2 +-
.../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 +-
19 files changed, 921 insertions(+), 42 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')
diff --git a/demos/time-tracker/protected/App_Code/CategoryDao.php b/demos/time-tracker/protected/App_Code/CategoryDao.php
index f0149f0b..cb1b6399 100644
--- a/demos/time-tracker/protected/App_Code/CategoryDao.php
+++ b/demos/time-tracker/protected/App_Code/CategoryDao.php
@@ -5,7 +5,10 @@ class CategoryDao extends BaseDao
function addNewCategory($category)
{
$sqlmap = $this->getConnection();
- $sqlmap->insert('AddNewCategory', $category);
+ $exists = $this->getCategoryByNameInProject(
+ $category->Name, $category->ProjectID);
+ if(!$exists)
+ $sqlmap->insert('AddNewCategory', $category);
}
function getCategoryByID($categoryID)
diff --git a/demos/time-tracker/protected/App_Code/ProjectDao.php b/demos/time-tracker/protected/App_Code/ProjectDao.php
index 416c6540..0a0771e3 100644
--- a/demos/time-tracker/protected/App_Code/ProjectDao.php
+++ b/demos/time-tracker/protected/App_Code/ProjectDao.php
@@ -62,10 +62,17 @@ class ProjectDao extends BaseDao
return $sqlmap->queryForList('GetProjectMembers', $projectID);
}
- public function getAllProjects()
+ public function getAllProjects($sort='', $order='ASC')
{
$sqlmap = $this->getConnection();
- return $sqlmap->queryForList('GetAllProjects');
+ if($sort === '')
+ return $sqlmap->queryForList('GetAllProjects');
+ else
+ {
+ $param['sort'] = $sort;
+ $param['order'] = $order;
+ return $sqlmap->queryForList('GetAllProjectsOrdered', $param);
+ }
}
public function getProjectsByManagerName($manager)
diff --git a/demos/time-tracker/protected/App_Data/time_tracker.db b/demos/time-tracker/protected/App_Data/time_tracker.db
index 03fe9156..e7adaec3 100644
Binary files a/demos/time-tracker/protected/App_Data/time_tracker.db and b/demos/time-tracker/protected/App_Data/time_tracker.db differ
diff --git a/demos/time-tracker/protected/application.xml b/demos/time-tracker/protected/application.xml
index e7d3b330..02be327b 100644
--- a/demos/time-tracker/protected/application.xml
+++ b/demos/time-tracker/protected/application.xml
@@ -21,6 +21,6 @@
-
+
\ No newline at end of file
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 Name |
+ Abbreviation |
+ Estimate 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
+
+
+
+
+
+
+
+
+
+
+
+
\ 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