summaryrefslogtreecommitdiff
path: root/demos/time-tracker/protected/App_Code
diff options
context:
space:
mode:
authorwei <>2006-07-18 23:39:13 +0000
committerwei <>2006-07-18 23:39:13 +0000
commit2fbc53d1f5d9e0a000717642d02558453bc610a8 (patch)
tree0ab6b464cf6b319f862e075ddd442558971c5aa6 /demos/time-tracker/protected/App_Code
parent319df8f534520c8c926d0cdaa1f5577c7bd8a909 (diff)
Add more tests and business code for time-tracker
Diffstat (limited to 'demos/time-tracker/protected/App_Code')
-rw-r--r--demos/time-tracker/protected/App_Code/Category.php13
-rw-r--r--demos/time-tracker/protected/App_Code/CategoryDao.php50
-rw-r--r--demos/time-tracker/protected/App_Code/DaoManager.php2
-rw-r--r--demos/time-tracker/protected/App_Code/DateTimeMySQL.php33
-rw-r--r--demos/time-tracker/protected/App_Code/Project.php2
-rw-r--r--demos/time-tracker/protected/App_Code/ProjectDao.php115
-rw-r--r--demos/time-tracker/protected/App_Code/TimeEntry.php16
-rw-r--r--demos/time-tracker/protected/App_Code/TimeEntryDao.php47
-rw-r--r--demos/time-tracker/protected/App_Code/UserDao.php10
-rw-r--r--demos/time-tracker/protected/App_Code/UserReport.php10
-rw-r--r--demos/time-tracker/protected/App_Code/UserReportsDao.php25
11 files changed, 266 insertions, 57 deletions
diff --git a/demos/time-tracker/protected/App_Code/Category.php b/demos/time-tracker/protected/App_Code/Category.php
new file mode 100644
index 00000000..9bdedb5f
--- /dev/null
+++ b/demos/time-tracker/protected/App_Code/Category.php
@@ -0,0 +1,13 @@
+<?php
+
+class Category
+{
+ public $ActualDuration = 0.0;
+ public $Abbreviation = '';
+ public $ID=0;
+ public $EstimateDuration = 0.0;
+ public $Name='';
+ public $ProjectID=0;
+}
+
+?> \ 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 @@
+<?php
+
+class CategoryDao extends BaseDao
+{
+ function addNewCategory($category)
+ {
+ $sqlmap = $this->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 @@
+<?php
+
+class DateTimeMySQL implements ITypeHandlerCallback
+{
+ /**
+ * Not implemented.
+ */
+ public function getParameter($integer)
+ {
+ return date('Y-m-d H:i:s', $integer);
+ }
+
+ /**
+ * Not implemented.
+ */
+ public function getResult($string)
+ {
+ return strtotime($string);
+ }
+
+ /**
+ * Creates a new instance of TimeTrackerUser
+ * @param array result data
+ * @return TimeTrackerUser new user instance
+ */
+ public function createNewInstance($row=null)
+ {
+ throw new TimeTrackerException('Not implemented');
+ }
+
+}
+
+?> \ 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 @@
+<?php
+
+class TimeEntry
+{
+ public $CreatorUserName='';
+ public $Category;
+ public $DateCreated=0;
+ public $Description='';
+ public $Duration=0.0;
+ public $ID=0;
+ public $Project;
+ public $ReportDate=0;
+ public $Username;
+}
+
+?> \ 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 @@
+<?php
+
+class TimeEntryDao extends BaseDao
+{
+ public function addNewTimeEntry($entry)
+ {
+ $sqlmap = $this->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
@@ -34,6 +34,16 @@ class UserDao extends BaseDao
}
/**
+ * @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.
*/
public function getAllUsers()
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 @@
+<?php
+
+class UserReport
+{
+ public $Username = '';
+ public $CategoryID = 0;
+ public $ActualDuration = 0.0;
+}
+
+?> \ 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 @@
+<?php
+
+class UserReportsDao extends BaseDao
+{
+ public function getUserTimeReport($username)
+ {
+ $sqlmap = $this->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