From 2fbc53d1f5d9e0a000717642d02558453bc610a8 Mon Sep 17 00:00:00 2001
From: wei <>
Date: Tue, 18 Jul 2006 23:39:13 +0000
Subject: Add more tests and business code for time-tracker
---
demos/time-tracker/index.php | 2 +-
demos/time-tracker/protected/App_Code/Category.php | 13 +
.../protected/App_Code/CategoryDao.php | 50 ++++
.../time-tracker/protected/App_Code/DaoManager.php | 2 +-
.../protected/App_Code/DateTimeMySQL.php | 33 +++
demos/time-tracker/protected/App_Code/Project.php | 2 +-
.../time-tracker/protected/App_Code/ProjectDao.php | 115 ++++-----
.../time-tracker/protected/App_Code/TimeEntry.php | 16 ++
.../protected/App_Code/TimeEntryDao.php | 47 ++++
demos/time-tracker/protected/App_Code/UserDao.php | 10 +
.../time-tracker/protected/App_Code/UserReport.php | 10 +
.../protected/App_Code/UserReportsDao.php | 25 ++
.../protected/App_Data/mysql-sqlmap.xml | 14 +-
demos/time-tracker/protected/App_Data/users.xml | 133 -----------
demos/time-tracker/protected/application.xml | 3 +
.../protected/pages/TimeTracker/SiteMap.php | 2 +-
.../protected/pages/TimeTracker/UserCreate.page | 136 ++++++-----
.../protected/pages/TimeTracker/UserCreate.php | 64 +++--
.../protected/pages/TimeTracker/UserList.page | 30 +++
.../protected/pages/TimeTracker/UserList.php | 34 +++
.../tests/unit/CategoryDaoTestCase.php | 200 ++++++++++++++++
.../time-tracker/tests/unit/ProjectDaoTestCase.php | 200 ++++++++++++++++
.../tests/unit/TimeEntryDaoTestCase.php | 264 +++++++++++++++++++++
demos/time-tracker/tests/unit/UserDaoTestCase.php | 14 +-
demos/time-tracker/themes/TimeTracker/site.css | 16 +-
25 files changed, 1144 insertions(+), 291 deletions(-)
create mode 100644 demos/time-tracker/protected/App_Code/Category.php
create mode 100644 demos/time-tracker/protected/App_Code/CategoryDao.php
create mode 100644 demos/time-tracker/protected/App_Code/DateTimeMySQL.php
create mode 100644 demos/time-tracker/protected/App_Code/TimeEntry.php
create mode 100644 demos/time-tracker/protected/App_Code/TimeEntryDao.php
create mode 100644 demos/time-tracker/protected/App_Code/UserReport.php
create mode 100644 demos/time-tracker/protected/App_Code/UserReportsDao.php
delete mode 100644 demos/time-tracker/protected/App_Data/users.xml
create mode 100644 demos/time-tracker/protected/pages/TimeTracker/UserList.php
create mode 100644 demos/time-tracker/tests/unit/CategoryDaoTestCase.php
create mode 100644 demos/time-tracker/tests/unit/ProjectDaoTestCase.php
create mode 100644 demos/time-tracker/tests/unit/TimeEntryDaoTestCase.php
(limited to 'demos')
diff --git a/demos/time-tracker/index.php b/demos/time-tracker/index.php
index afada2c1..0f8f412a 100644
--- a/demos/time-tracker/index.php
+++ b/demos/time-tracker/index.php
@@ -1,7 +1,7 @@
\ No newline at end of file
diff --git a/demos/time-tracker/protected/App_Code/CategoryDao.php b/demos/time-tracker/protected/App_Code/CategoryDao.php
new file mode 100644
index 00000000..f0149f0b
--- /dev/null
+++ b/demos/time-tracker/protected/App_Code/CategoryDao.php
@@ -0,0 +1,50 @@
+getConnection();
+ $sqlmap->insert('AddNewCategory', $category);
+ }
+
+ function getCategoryByID($categoryID)
+ {
+ $sqlmap = $this->getConnection();
+ return $sqlmap->queryForObject('GetCategoryByID', $categoryID);
+ }
+
+ function getAllCategories()
+ {
+ $sqlmap = $this->getConnection();
+ return $sqlmap->queryForList('GetAllCategories');
+ }
+
+ function deleteCategory($categoryID)
+ {
+ $sqlmap = $this->getConnection();
+ $sqlmap->delete('DeleteCategory', $categoryID);
+ }
+
+ function getCategoriesByProjectID($projectID)
+ {
+ $sqlmap = $this->getConnection();
+ return $sqlmap->queryForList('GetCategoriesByProjectID', $projectID);
+ }
+
+ function getCategoryByNameInProject($name, $projectID)
+ {
+ $sqlmap = $this->getConnection();
+ $param['project'] = $projectID;
+ $param['category'] = $name;
+ return $sqlmap->queryForObject('GetCategoryByNameInProject', $param);
+ }
+
+ function updateCategory($category)
+ {
+ $sqlmap = $this->getConnection();
+ $sqlmap->update('UpdateCategory', $category);
+ }
+}
+
+?>
\ No newline at end of file
diff --git a/demos/time-tracker/protected/App_Code/DaoManager.php b/demos/time-tracker/protected/App_Code/DaoManager.php
index b8ac55af..ac546054 100644
--- a/demos/time-tracker/protected/App_Code/DaoManager.php
+++ b/demos/time-tracker/protected/App_Code/DaoManager.php
@@ -98,7 +98,7 @@ class DaoManager extends TModule
return $this->_dao[$class]['instance'];
}
else
- throw TimeTrackerException('daomanager_undefined_dao', $class);
+ throw new TimeTrackerException('daomanager_undefined_dao', $class);
}
/**
diff --git a/demos/time-tracker/protected/App_Code/DateTimeMySQL.php b/demos/time-tracker/protected/App_Code/DateTimeMySQL.php
new file mode 100644
index 00000000..19f41c03
--- /dev/null
+++ b/demos/time-tracker/protected/App_Code/DateTimeMySQL.php
@@ -0,0 +1,33 @@
+
\ No newline at end of file
diff --git a/demos/time-tracker/protected/App_Code/Project.php b/demos/time-tracker/protected/App_Code/Project.php
index 660fad04..bd9c858b 100644
--- a/demos/time-tracker/protected/App_Code/Project.php
+++ b/demos/time-tracker/protected/App_Code/Project.php
@@ -25,7 +25,7 @@ class Project
public $CompletionDate = 0;
public $DateCreated = 0;
public $Description = '';
- public $EstimateDuration = 0;
+ public $EstimateDuration = 0.0;
public $ID = 0;
public $ManagerUserName = '';
public $Name = '';
diff --git a/demos/time-tracker/protected/App_Code/ProjectDao.php b/demos/time-tracker/protected/App_Code/ProjectDao.php
index 81902e0c..416c6540 100644
--- a/demos/time-tracker/protected/App_Code/ProjectDao.php
+++ b/demos/time-tracker/protected/App_Code/ProjectDao.php
@@ -20,32 +20,17 @@
*/
class ProjectDao extends BaseDao
{
-/* public function createNewProject($project)
+ public function projectNameExists($projectName)
{
$sqlmap = $this->getConnection();
- $creator = $sqlmap->queryForObject('GetUserByName', $project->CreatorUserName);
- $manager = $sqlmap->queryForObject('GetUserByName', $project->ManagerUserName);
- $exists = $sqlmap->queryForObject('GetProjectByName', $project->Name);
- if($exists)
- {
- throw new TimeTrackerException(
- 'project_exists', $project->Name);
- }
- else if(!$creator || !$manager)
- {
- throw new TimeTrackerException(
- 'invalid_creator_and_manager',
- $project->Name, $project->CreatorUserName,
- $project->ManagerUserName);
- }
- else
- {
- $param['project'] = $project;
- $param['creator'] = $creator->ID;
- $param['manager'] = $manager->ID;
- return $sqlmap->insert('CreateNewProject', $param);
- }
- }
+ return $sqlmap->queryForObject('ProjectNameExists', $projectName);
+ }
+
+ public function addNewProject($project)
+ {
+ $sqlmap = $this->getConnection();
+ $sqlmap->insert('CreateNewProject', $project);
+ }
public function getProjectByID($projectID)
{
@@ -53,41 +38,61 @@ class ProjectDao extends BaseDao
return $sqlmap->queryForObject('GetProjectByID', $projectID);
}
- public function addUserToProject($project, $user)
+ public function deleteProject($projectID)
{
$sqlmap = $this->getConnection();
- $project = $this->getProjectByID($project->ID);
- $user = $sqlmap->queryForObject('GetUserByName', $user->Name);
- $list = $sqlmap->queryForList('GetProjectMembers', $project);
- $userExists = false;
- foreach($list as $k)
- {
- if($k->ID == $user->ID)
- $userExists = true;
- }
- if(!$project)
- {
- throw new TimeTrackerException(
- 'invalid_project', $project->Name);
- }
- else if(!$user)
- {
- throw new TimeTrackerException(
- 'invalid_user', $user->Name);
- }
- else if($userExists)
- {
- throw new TimeTrackerException(
- 'project_member_exists', $projet->Name, $user->Name);
- }
- else
+ $sqlmap->update('DeleteProject',$projectID);
+ }
+
+ public function addUserToProject($projectID, $username)
+ {
+ $sqlmap = $this->getConnection();
+ $members = $this->getProjectMembers($projectID);
+ if(!in_array($username, $members))
{
- $param['project'] = $project;
- $param['user'] = $user;
- return $sqlmap->insert('AddUserToProject', $param);
- }
+ $param['username'] = $username;
+ $param['project'] = $projectID;
+ $sqlmap->insert('AddUserToProject',$param);
+ }
+ }
+
+ public function getProjectMembers($projectID)
+ {
+ $sqlmap = $this->getConnection();
+ return $sqlmap->queryForList('GetProjectMembers', $projectID);
+ }
+
+ public function getAllProjects()
+ {
+ $sqlmap = $this->getConnection();
+ return $sqlmap->queryForList('GetAllProjects');
+ }
+
+ public function getProjectsByManagerName($manager)
+ {
+ $sqlmap = $this->getConnection();
+ return $sqlmap->queryForList('GetProjectsByManagerName', $manager);
+ }
+
+ public function getProjectsByUserName($username)
+ {
+ $sqlmap = $this->getConnection();
+ return $sqlmap->queryForList('GetProjectsByUserName', $username);
+ }
+
+ public function removeUserFromProject($projectID, $username)
+ {
+ $sqlmap = $this->getConnection();
+ $param['username'] = $username;
+ $param['project'] = $projectID;
+ $sqlmap->delete('RemoveUserFromProject', $param);
+ }
+
+ public function updateProject($project)
+ {
+ $sqlmap = $this->getConnection();
+ $sqlmap->update('UpdateProject', $project);
}
-*/
}
?>
\ No newline at end of file
diff --git a/demos/time-tracker/protected/App_Code/TimeEntry.php b/demos/time-tracker/protected/App_Code/TimeEntry.php
new file mode 100644
index 00000000..e250d67f
--- /dev/null
+++ b/demos/time-tracker/protected/App_Code/TimeEntry.php
@@ -0,0 +1,16 @@
+
\ No newline at end of file
diff --git a/demos/time-tracker/protected/App_Code/TimeEntryDao.php b/demos/time-tracker/protected/App_Code/TimeEntryDao.php
new file mode 100644
index 00000000..60301f3b
--- /dev/null
+++ b/demos/time-tracker/protected/App_Code/TimeEntryDao.php
@@ -0,0 +1,47 @@
+getConnection();
+ $sqlmap->insert('AddNewTimeEntry', $entry);
+ }
+
+ public function getTimeEntryByID($entryID)
+ {
+ $sqlmap = $this->getConnection();
+ return $sqlmap->queryForObject('GetTimeEntryByID', $entryID);
+ }
+
+ public function deleteTimeEntry($entryID)
+ {
+ $sqlmap = $this->getConnection();
+ $sqlmap->delete('DeleteTimeEntry', $entryID);
+ }
+
+ public function getTimeEntriesInProject($username, $projectID)
+ {
+ $sqlmap = $this->getConnection();
+ $param['username'] = $username;
+ $param['project'] = $projectID;
+ return $sqlmap->queryForList('GetAllTimeEntriesByProjectIdAndUser', $param);
+ }
+
+ public function updateTimeEntry($entry)
+ {
+ $sqlmap = $this->getConnection();
+ $sqlmap->update('UpdateTimeEntry', $entry);
+ }
+
+ public function getTimeEntriesByDate($username, $start, $end)
+ {
+ $sqlmap = $this->getConnection();
+ $param['username'] = $username;
+ $param['startDate'] = $start;
+ $param['endDate'] = $end;
+ return $sqlmap->queryForList('GetTimeEntriesByDate', $param);
+ }
+}
+
+?>
\ No newline at end of file
diff --git a/demos/time-tracker/protected/App_Code/UserDao.php b/demos/time-tracker/protected/App_Code/UserDao.php
index 4dc39b2b..6064be7e 100644
--- a/demos/time-tracker/protected/App_Code/UserDao.php
+++ b/demos/time-tracker/protected/App_Code/UserDao.php
@@ -33,6 +33,16 @@ class UserDao extends BaseDao
return $sqlmap->queryForObject('GetUserByName', $username);
}
+ /**
+ * @param string username
+ * @return boolean true if username already exists, false otherwise.
+ */
+ public function usernameExists($username)
+ {
+ $sqlmap = $this->getConnection();
+ return $sqlmap->queryForObject('UsernameExists', $username);
+ }
+
/**
* @return array list of all enabled users.
*/
diff --git a/demos/time-tracker/protected/App_Code/UserReport.php b/demos/time-tracker/protected/App_Code/UserReport.php
new file mode 100644
index 00000000..e7529120
--- /dev/null
+++ b/demos/time-tracker/protected/App_Code/UserReport.php
@@ -0,0 +1,10 @@
+
\ No newline at end of file
diff --git a/demos/time-tracker/protected/App_Code/UserReportsDao.php b/demos/time-tracker/protected/App_Code/UserReportsDao.php
new file mode 100644
index 00000000..3cf943af
--- /dev/null
+++ b/demos/time-tracker/protected/App_Code/UserReportsDao.php
@@ -0,0 +1,25 @@
+getConnection();
+ return $sqlmap->queryForObject('GetTimeReportByUsername', $username);
+ }
+
+ public function getTimeReportsByCategoryID($categoryID)
+ {
+ $sqlmap = $this->getConnection();
+ return $sqlmap->queryForList('GetTimeReportByCategoryID', $categoryID);
+ }
+
+ public function getTimeReportsByProjectID($projectID)
+ {
+ $sqlmap = $this->getConnection();
+ return $sqlmap->queryForList('GetTimeReportByProjectID', $projectID);
+ }
+
+}
+
+?>
\ No newline at end of file
diff --git a/demos/time-tracker/protected/App_Data/mysql-sqlmap.xml b/demos/time-tracker/protected/App_Data/mysql-sqlmap.xml
index fe4ebedc..3f850955 100644
--- a/demos/time-tracker/protected/App_Data/mysql-sqlmap.xml
+++ b/demos/time-tracker/protected/App_Data/mysql-sqlmap.xml
@@ -1,8 +1,11 @@
-
+
+
+
+
-
-
+
+
+
+
+
\ No newline at end of file
diff --git a/demos/time-tracker/protected/App_Data/users.xml b/demos/time-tracker/protected/App_Data/users.xml
deleted file mode 100644
index f4151c30..00000000
--- a/demos/time-tracker/protected/App_Data/users.xml
+++ /dev/null
@@ -1,133 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- INSERT INTO
- users (Username, Password, EmailAddress)
- VALUES
- (#user.Name#, #password#, #user.EmailAddress#)
-
-
-
- UPDATE users SET Disabled = 1 WHERE username = #value#
-
-
-
- INSERT INTO
- signon (SessionToken, Username, LastSignOnDate)
- VALUES
- (#token#, #username#, NOW())
-
-
-
-
-
- UPDATE signon SET LastSignOnDate = NOW()
- WHERE SessionToken = #value#
-
-
-
- DELETE FROM user_roles WHERE UserID = #Name#
-
-
-
- INSERT INTO user_roles (UserID, RoleType)
- VALUES(#username#, #role#)
-
-
-
- UPDATE users
- SET EmailAddress = #EmailAddress#
- WHERE Username = #Name#
-
-
-
- UPDATE users
- SET EmailAddress = #user.EmailAddress#, Password=#password#
- WHERE Username = #user.Name#
-
-
-
- DELETE FROM signon WHERE Username = #value#
-
-
-
- DELETE FROM signon
-
-
-
\ No newline at end of file
diff --git a/demos/time-tracker/protected/application.xml b/demos/time-tracker/protected/application.xml
index 801b6eb3..e7d3b330 100644
--- a/demos/time-tracker/protected/application.xml
+++ b/demos/time-tracker/protected/application.xml
@@ -15,6 +15,9 @@
+
+
+
diff --git a/demos/time-tracker/protected/pages/TimeTracker/SiteMap.php b/demos/time-tracker/protected/pages/TimeTracker/SiteMap.php
index 1f452894..1beed757 100644
--- a/demos/time-tracker/protected/pages/TimeTracker/SiteMap.php
+++ b/demos/time-tracker/protected/pages/TimeTracker/SiteMap.php
@@ -43,7 +43,7 @@ class SiteMap extends TTemplateControl
case 'ReportResource':
$active = $this->ReportMenu;
break;
- case 'TimeEntry':
+ default:
$active = $this->LogMenu;
break;
}
diff --git a/demos/time-tracker/protected/pages/TimeTracker/UserCreate.page b/demos/time-tracker/protected/pages/TimeTracker/UserCreate.page
index 41d97391..edc22bcd 100644
--- a/demos/time-tracker/protected/pages/TimeTracker/UserCreate.page
+++ b/demos/time-tracker/protected/pages/TimeTracker/UserCreate.page
@@ -2,74 +2,86 @@
Create New User
\ No newline at end of file
diff --git a/demos/time-tracker/protected/pages/TimeTracker/UserCreate.php b/demos/time-tracker/protected/pages/TimeTracker/UserCreate.php
index f163ecd6..ed8ea4f1 100644
--- a/demos/time-tracker/protected/pages/TimeTracker/UserCreate.php
+++ b/demos/time-tracker/protected/pages/TimeTracker/UserCreate.php
@@ -11,8 +11,10 @@
*/
/**
- * Create new user page class. Validate that the usernames are unique
- * and set the new user credentials as the current application credentials.
+ * Create new user wizard page class. Validate that the usernames are unique and
+ * set the new user credentials as the current application credentials.
+ *
+ * If logged in as admin, the user role can be change during creation.
*
* @author Wei Zhuo
* @version $Revision: $ $16/07/2006: $
@@ -21,6 +23,18 @@
*/
class UserCreate extends TPage
{
+ /**
+ * Sets the default new user roles, default role is set in config.xml
+ */
+ public function onLoad($param)
+ {
+ if(!$this->IsPostBack)
+ {
+ $this->role->SelectedValue =
+ $this->Application->Parameters['NewUserRoles'];
+ }
+ }
+
/**
* Verify that the username is not taken.
* @param TControl custom validator that created the event.
@@ -29,12 +43,27 @@ class UserCreate extends TPage
public function checkUsername($sender, $param)
{
$userDao = $this->Application->Modules['daos']->getDao('UserDao');
- $user = $userDao->getUserByName($this->username->Text);
- if(!is_null($user))
+ if($userDao->usernameExists($this->username->Text))
{
$param->IsValid = false;
$sender->ErrorMessage =
- "The user name is already taken, try '{$user->Name}01'";
+ "The user name is already taken, try '{$this->username->Text}01'";
+ }
+ }
+
+ /**
+ * Skip the role assignment step if not admin.
+ */
+ public function userWizardNextStep($sender, $param)
+ {
+ if($param->CurrentStepIndex == 0)
+ {
+ //create user with admin credentials
+ if(!$this->User->isInRole('admin'))
+ {
+ $this->createNewUser($sender, $param);
+ $param->NextStepIndex = 2;
+ }
}
}
@@ -54,31 +83,30 @@ class UserCreate extends TPage
$newUser->EmailAddress = $this->email->Text;
$newUser->Name = $this->username->Text;
$newUser->IsGuest = false;
- if($this->User->isInRole('admin'))
- $newUser->Roles = $this->role->SelectedValue;
- else
- $newUser->Roles = $this->Application->Parameters['NewUserRoles'];
+ $newUser->Roles = $this->role->SelectedValue;
//save the user
$userDao = $this->Application->Modules['daos']->getDao('UserDao');
$userDao->addNewUser($newUser, $this->password->Text);
- //update the user
+ //update the user credentials if not admin
if(!$this->User->isInRole('admin'))
{
$auth = $this->Application->getModule('auth');
$auth->updateCredential($newUser);
-
- //return to requested page
- $this->Response->redirect($auth->getReturnUrl());
}
- else
- $this->Response->reload();
- //goto default page.
- //$url = $this->Service->constructUrl($this->Service->DefaultPage);
- //$this->Response->redirect($url);
}
}
+
+ /**
+ * Continue with requested page.
+ */
+ public function wizardCompleted($sender, $param)
+ {
+ //return to requested page
+ $auth = $this->Application->getModule('auth');
+ $this->Response->redirect($auth->getReturnUrl());
+ }
}
?>
\ 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 48b2bbc7..f0c88112 100644
--- a/demos/time-tracker/protected/pages/TimeTracker/UserList.page
+++ b/demos/time-tracker/protected/pages/TimeTracker/UserList.page
@@ -1,3 +1,33 @@