From 903ae8a581fac1e6917fc3e31d2ad8fb91df80c3 Mon Sep 17 00:00:00 2001 From: ctrlaltca <> Date: Thu, 12 Jul 2012 11:21:01 +0000 Subject: standardize the use of unix eol; use svn properties to enforce native eol --- .../protected/App_Code/Dao/BaseDao.php | 88 +++--- .../protected/App_Code/Dao/CategoryDao.php | 104 +++---- .../protected/App_Code/Dao/CategoryRecord.php | 24 +- .../protected/App_Code/Dao/ProjectDao.php | 208 ++++++------- .../protected/App_Code/Dao/ProjectRecord.php | 68 ++--- .../protected/App_Code/Dao/ReportsDao.php | 172 +++++------ .../protected/App_Code/Dao/TimeEntryDao.php | 74 ++--- .../protected/App_Code/Dao/TimeEntryRecord.php | 30 +- .../protected/App_Code/Dao/UserDao.php | 328 ++++++++++----------- .../time-tracker/protected/App_Code/DaoManager.php | 156 +++++----- .../protected/App_Code/TimeTrackerException.php | 64 ++-- .../protected/App_Code/TimeTrackerUser.php | 94 +++--- .../protected/App_Code/TrackerAuthManager.php | 168 +++++------ .../protected/App_Code/UserManager.php | 178 +++++------ 14 files changed, 878 insertions(+), 878 deletions(-) (limited to 'demos/time-tracker/protected/App_Code') diff --git a/demos/time-tracker/protected/App_Code/Dao/BaseDao.php b/demos/time-tracker/protected/App_Code/Dao/BaseDao.php index 5edb6af7..a75011d7 100644 --- a/demos/time-tracker/protected/App_Code/Dao/BaseDao.php +++ b/demos/time-tracker/protected/App_Code/Dao/BaseDao.php @@ -1,45 +1,45 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2005-2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - * @package Demos - */ - -/** - * Base DAO class. - * - * @author Wei Zhuo - * @version $Id$ - * @package Demos - * @since 3.1 - */ -class BaseDao -{ - /** - * @var TSqlMapGateway sqlmap client. - */ - private $_sqlmap; - - /** - * @param TSqlMapGateway sqlmap client. - */ - public function setSqlMap($sqlmap) - { - $this->_sqlmap = $sqlmap; - } - - /** - * @return TSqlMapGateway sqlmap client. - */ - protected function getSqlMap() - { - return $this->_sqlmap; - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + * @package Demos + */ + +/** + * Base DAO class. + * + * @author Wei Zhuo + * @version $Id$ + * @package Demos + * @since 3.1 + */ +class BaseDao +{ + /** + * @var TSqlMapGateway sqlmap client. + */ + private $_sqlmap; + + /** + * @param TSqlMapGateway sqlmap client. + */ + public function setSqlMap($sqlmap) + { + $this->_sqlmap = $sqlmap; + } + + /** + * @return TSqlMapGateway sqlmap client. + */ + protected function getSqlMap() + { + return $this->_sqlmap; + } +} + ?> \ No newline at end of file diff --git a/demos/time-tracker/protected/App_Code/Dao/CategoryDao.php b/demos/time-tracker/protected/App_Code/Dao/CategoryDao.php index 7476f036..e43639a0 100644 --- a/demos/time-tracker/protected/App_Code/Dao/CategoryDao.php +++ b/demos/time-tracker/protected/App_Code/Dao/CategoryDao.php @@ -1,53 +1,53 @@ -getSqlMap(); - $exists = $this->getCategoryByNameInProject( - $category->Name, $category->ProjectID); - if(!$exists) - $sqlmap->insert('AddNewCategory', $category); - } - - function getCategoryByID($categoryID) - { - $sqlmap = $this->getSqlMap(); - return $sqlmap->queryForObject('GetCategoryByID', $categoryID); - } - - function getAllCategories() - { - $sqlmap = $this->getSqlMap(); - return $sqlmap->queryForList('GetAllCategories'); - } - - function deleteCategory($categoryID) - { - $sqlmap = $this->getSqlMap(); - $sqlmap->delete('DeleteCategory', $categoryID); - } - - function getCategoriesByProjectID($projectID) - { - $sqlmap = $this->getSqlMap(); - return $sqlmap->queryForList('GetCategoriesByProjectID', $projectID); - } - - function getCategoryByNameInProject($name, $projectID) - { - $sqlmap = $this->getSqlMap(); - $param['project'] = $projectID; - $param['category'] = $name; - return $sqlmap->queryForObject('GetCategoryByNameInProject', $param); - } - - function updateCategory($category) - { - $sqlmap = $this->getSqlMap(); - $sqlmap->update('UpdateCategory', $category); - } -} - +getSqlMap(); + $exists = $this->getCategoryByNameInProject( + $category->Name, $category->ProjectID); + if(!$exists) + $sqlmap->insert('AddNewCategory', $category); + } + + function getCategoryByID($categoryID) + { + $sqlmap = $this->getSqlMap(); + return $sqlmap->queryForObject('GetCategoryByID', $categoryID); + } + + function getAllCategories() + { + $sqlmap = $this->getSqlMap(); + return $sqlmap->queryForList('GetAllCategories'); + } + + function deleteCategory($categoryID) + { + $sqlmap = $this->getSqlMap(); + $sqlmap->delete('DeleteCategory', $categoryID); + } + + function getCategoriesByProjectID($projectID) + { + $sqlmap = $this->getSqlMap(); + return $sqlmap->queryForList('GetCategoriesByProjectID', $projectID); + } + + function getCategoryByNameInProject($name, $projectID) + { + $sqlmap = $this->getSqlMap(); + $param['project'] = $projectID; + $param['category'] = $name; + return $sqlmap->queryForObject('GetCategoryByNameInProject', $param); + } + + function updateCategory($category) + { + $sqlmap = $this->getSqlMap(); + $sqlmap->update('UpdateCategory', $category); + } +} + ?> \ No newline at end of file diff --git a/demos/time-tracker/protected/App_Code/Dao/CategoryRecord.php b/demos/time-tracker/protected/App_Code/Dao/CategoryRecord.php index 876b582d..0394ce92 100644 --- a/demos/time-tracker/protected/App_Code/Dao/CategoryRecord.php +++ b/demos/time-tracker/protected/App_Code/Dao/CategoryRecord.php @@ -1,13 +1,13 @@ - \ No newline at end of file diff --git a/demos/time-tracker/protected/App_Code/Dao/ProjectDao.php b/demos/time-tracker/protected/App_Code/Dao/ProjectDao.php index 9e8867bc..1d085b47 100644 --- a/demos/time-tracker/protected/App_Code/Dao/ProjectDao.php +++ b/demos/time-tracker/protected/App_Code/Dao/ProjectDao.php @@ -1,105 +1,105 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2005-2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - * @package Demos - */ - -/** - * Project DAO class. - * - * @author Wei Zhuo - * @version $Id$ - * @package Demos - * @since 3.1 - */ -class ProjectDao extends BaseDao -{ - public function projectNameExists($projectName) - { - $sqlmap = $this->getSqlMap(); - return $sqlmap->queryForObject('ProjectNameExists', $projectName); - } - - public function addNewProject($project) - { - $sqlmap = $this->getSqlMap(); - $sqlmap->insert('CreateNewProject', $project); - } - - public function getProjectByID($projectID) - { - $sqlmap = $this->getSqlMap(); - return $sqlmap->queryForObject('GetProjectByID', $projectID); - } - - public function deleteProject($projectID) - { - $sqlmap = $this->getSqlMap(); - $sqlmap->update('DeleteProject',$projectID); - } - - public function addUserToProject($projectID, $username) - { - $sqlmap = $this->getSqlMap(); - $members = $this->getProjectMembers($projectID); - if(!in_array($username, $members)) - { - $param['username'] = $username; - $param['project'] = $projectID; - $sqlmap->insert('AddUserToProject',$param); - } - } - - public function getProjectMembers($projectID) - { - $sqlmap = $this->getSqlMap(); - return $sqlmap->queryForList('GetProjectMembers', $projectID); - } - - public function getAllProjects($sort='', $order='ASC') - { - $sqlmap = $this->getSqlMap(); - if($sort === '') - return $sqlmap->queryForList('GetAllProjects'); - else - { - $param['sort'] = $sort; - $param['order'] = $order; - return $sqlmap->queryForList('GetAllProjectsOrdered', $param); - } - } - - public function getProjectsByManagerName($manager) - { - $sqlmap = $this->getSqlMap(); - return $sqlmap->queryForList('GetProjectsByManagerName', $manager); - } - - public function getProjectsByUserName($username) - { - $sqlmap = $this->getSqlMap(); - return $sqlmap->queryForList('GetProjectsByUserName', $username); - } - - public function removeUserFromProject($projectID, $username) - { - $sqlmap = $this->getSqlMap(); - $param['username'] = $username; - $param['project'] = $projectID; - $sqlmap->delete('RemoveUserFromProject', $param); - } - - public function updateProject($project) - { - $sqlmap = $this->getSqlMap(); - $sqlmap->update('UpdateProject', $project); - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + * @package Demos + */ + +/** + * Project DAO class. + * + * @author Wei Zhuo + * @version $Id$ + * @package Demos + * @since 3.1 + */ +class ProjectDao extends BaseDao +{ + public function projectNameExists($projectName) + { + $sqlmap = $this->getSqlMap(); + return $sqlmap->queryForObject('ProjectNameExists', $projectName); + } + + public function addNewProject($project) + { + $sqlmap = $this->getSqlMap(); + $sqlmap->insert('CreateNewProject', $project); + } + + public function getProjectByID($projectID) + { + $sqlmap = $this->getSqlMap(); + return $sqlmap->queryForObject('GetProjectByID', $projectID); + } + + public function deleteProject($projectID) + { + $sqlmap = $this->getSqlMap(); + $sqlmap->update('DeleteProject',$projectID); + } + + public function addUserToProject($projectID, $username) + { + $sqlmap = $this->getSqlMap(); + $members = $this->getProjectMembers($projectID); + if(!in_array($username, $members)) + { + $param['username'] = $username; + $param['project'] = $projectID; + $sqlmap->insert('AddUserToProject',$param); + } + } + + public function getProjectMembers($projectID) + { + $sqlmap = $this->getSqlMap(); + return $sqlmap->queryForList('GetProjectMembers', $projectID); + } + + public function getAllProjects($sort='', $order='ASC') + { + $sqlmap = $this->getSqlMap(); + if($sort === '') + return $sqlmap->queryForList('GetAllProjects'); + else + { + $param['sort'] = $sort; + $param['order'] = $order; + return $sqlmap->queryForList('GetAllProjectsOrdered', $param); + } + } + + public function getProjectsByManagerName($manager) + { + $sqlmap = $this->getSqlMap(); + return $sqlmap->queryForList('GetProjectsByManagerName', $manager); + } + + public function getProjectsByUserName($username) + { + $sqlmap = $this->getSqlMap(); + return $sqlmap->queryForList('GetProjectsByUserName', $username); + } + + public function removeUserFromProject($projectID, $username) + { + $sqlmap = $this->getSqlMap(); + $param['username'] = $username; + $param['project'] = $projectID; + $sqlmap->delete('RemoveUserFromProject', $param); + } + + public function updateProject($project) + { + $sqlmap = $this->getSqlMap(); + $sqlmap->update('UpdateProject', $project); + } +} + ?> \ No newline at end of file diff --git a/demos/time-tracker/protected/App_Code/Dao/ProjectRecord.php b/demos/time-tracker/protected/App_Code/Dao/ProjectRecord.php index 7812751b..1f6ededd 100644 --- a/demos/time-tracker/protected/App_Code/Dao/ProjectRecord.php +++ b/demos/time-tracker/protected/App_Code/Dao/ProjectRecord.php @@ -1,35 +1,35 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2005-2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - * @package Demos - */ - -/** - * Time Tracker Project class. - * - * @author Wei Zhuo - * @version $Id$ - * @package Demos - * @since 3.1 - */ -class ProjectRecord -{ - public $ActualDuration = 0; - public $CreatorUserName = ''; - public $CompletionDate = 0; - public $DateCreated = 0; - public $Description = ''; - public $EstimateDuration = 0.0; - public $ID = 0; - public $ManagerUserName = ''; - public $Name = ''; -} - - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + * @package Demos + */ + +/** + * Time Tracker Project class. + * + * @author Wei Zhuo + * @version $Id$ + * @package Demos + * @since 3.1 + */ +class ProjectRecord +{ + public $ActualDuration = 0; + public $CreatorUserName = ''; + public $CompletionDate = 0; + public $DateCreated = 0; + public $Description = ''; + public $EstimateDuration = 0.0; + public $ID = 0; + public $ManagerUserName = ''; + public $Name = ''; +} + + ?> \ No newline at end of file diff --git a/demos/time-tracker/protected/App_Code/Dao/ReportsDao.php b/demos/time-tracker/protected/App_Code/Dao/ReportsDao.php index 15d0c2a3..c03dd81d 100644 --- a/demos/time-tracker/protected/App_Code/Dao/ReportsDao.php +++ b/demos/time-tracker/protected/App_Code/Dao/ReportsDao.php @@ -1,87 +1,87 @@ -Categories = new TList; - } - - public function getActualHours() - { - $total = 0; - foreach($this->Categories as $cat) - $total += $cat->getActualHours(); - return $total; - } -} - -class CategoryReport extends TComponent -{ - public $CategoryName = ''; - public $EstimateHours = 0; - public $members = array(); - - public function getActualHours() - { - $total = 0; - foreach($this->members as $member) - $total += $member['hours']; - return $total; - } -} - -class UserReport extends TComponent -{ - public $Username; - public $Projects = array(); - - public function getTotalHours() - { - $hours = 0; - foreach($this->Projects as $project) - $hours += $project->Duration; - return $hours; - } -} - -class UserProjectReport -{ - public $ProjectName = ''; - public $CategoryName = ''; - public $Duration = 0; - public $Description=''; - public $ReportDate=0; -} - -class ReportsDao extends BaseDao -{ - public function getTimeReportsByProjectIDs($projects) - { - $ids = implode(',', array_map('intval', $projects)); - $sqlmap = $this->getSqlMap(); - return $sqlmap->queryForList('GetTimeReportByProjectIDs', $ids); - } - - public function getUserProjectTimeReports($users, $projects, $startDate, $endDate) - { - $sqlmap = $this->getSqlMap(); - $ids = implode(',', array_map('intval', $projects)); - $sqlmap->getDbConnection()->setActive(true); //db connection needs to be open for quoteString - $usernames = implode(',', array_map(array($sqlmap->getDbConnection(), 'quoteString'), $users)); - - $param['projects'] = $ids; - $param['members'] = $usernames; - $param['startDate'] = intval($startDate); - $param['endDate'] = intval($endDate); - - return $sqlmap->queryForList('GetTimeReportByUsername', $param); - } -} - +Categories = new TList; + } + + public function getActualHours() + { + $total = 0; + foreach($this->Categories as $cat) + $total += $cat->getActualHours(); + return $total; + } +} + +class CategoryReport extends TComponent +{ + public $CategoryName = ''; + public $EstimateHours = 0; + public $members = array(); + + public function getActualHours() + { + $total = 0; + foreach($this->members as $member) + $total += $member['hours']; + return $total; + } +} + +class UserReport extends TComponent +{ + public $Username; + public $Projects = array(); + + public function getTotalHours() + { + $hours = 0; + foreach($this->Projects as $project) + $hours += $project->Duration; + return $hours; + } +} + +class UserProjectReport +{ + public $ProjectName = ''; + public $CategoryName = ''; + public $Duration = 0; + public $Description=''; + public $ReportDate=0; +} + +class ReportsDao extends BaseDao +{ + public function getTimeReportsByProjectIDs($projects) + { + $ids = implode(',', array_map('intval', $projects)); + $sqlmap = $this->getSqlMap(); + return $sqlmap->queryForList('GetTimeReportByProjectIDs', $ids); + } + + public function getUserProjectTimeReports($users, $projects, $startDate, $endDate) + { + $sqlmap = $this->getSqlMap(); + $ids = implode(',', array_map('intval', $projects)); + $sqlmap->getDbConnection()->setActive(true); //db connection needs to be open for quoteString + $usernames = implode(',', array_map(array($sqlmap->getDbConnection(), 'quoteString'), $users)); + + $param['projects'] = $ids; + $param['members'] = $usernames; + $param['startDate'] = intval($startDate); + $param['endDate'] = intval($endDate); + + return $sqlmap->queryForList('GetTimeReportByUsername', $param); + } +} + ?> \ No newline at end of file diff --git a/demos/time-tracker/protected/App_Code/Dao/TimeEntryDao.php b/demos/time-tracker/protected/App_Code/Dao/TimeEntryDao.php index 4bd74eb5..f761fd25 100644 --- a/demos/time-tracker/protected/App_Code/Dao/TimeEntryDao.php +++ b/demos/time-tracker/protected/App_Code/Dao/TimeEntryDao.php @@ -1,38 +1,38 @@ -getSqlMap(); - $sqlmap->insert('AddNewTimeEntry', $entry); - } - - public function getTimeEntryByID($entryID) - { - $sqlmap = $this->getSqlMap(); - return $sqlmap->queryForObject('GetTimeEntryByID', $entryID); - } - - public function deleteTimeEntry($entryID) - { - $sqlmap = $this->getSqlMap(); - $sqlmap->delete('DeleteTimeEntry', $entryID); - } - - public function getTimeEntriesInProject($username, $projectID) - { - $sqlmap = $this->getSqlMap(); - $param['username'] = $username; - $param['project'] = $projectID; - return $sqlmap->queryForList('GetAllTimeEntriesByProjectIdAndUser', $param); - } - - public function updateTimeEntry($entry) - { - $sqlmap = $this->getSqlMap(); - $sqlmap->update('UpdateTimeEntry', $entry); - } -} - +getSqlMap(); + $sqlmap->insert('AddNewTimeEntry', $entry); + } + + public function getTimeEntryByID($entryID) + { + $sqlmap = $this->getSqlMap(); + return $sqlmap->queryForObject('GetTimeEntryByID', $entryID); + } + + public function deleteTimeEntry($entryID) + { + $sqlmap = $this->getSqlMap(); + $sqlmap->delete('DeleteTimeEntry', $entryID); + } + + public function getTimeEntriesInProject($username, $projectID) + { + $sqlmap = $this->getSqlMap(); + $param['username'] = $username; + $param['project'] = $projectID; + return $sqlmap->queryForList('GetAllTimeEntriesByProjectIdAndUser', $param); + } + + public function updateTimeEntry($entry) + { + $sqlmap = $this->getSqlMap(); + $sqlmap->update('UpdateTimeEntry', $entry); + } +} + ?> \ No newline at end of file diff --git a/demos/time-tracker/protected/App_Code/Dao/TimeEntryRecord.php b/demos/time-tracker/protected/App_Code/Dao/TimeEntryRecord.php index fa4f5b8f..8b533070 100644 --- a/demos/time-tracker/protected/App_Code/Dao/TimeEntryRecord.php +++ b/demos/time-tracker/protected/App_Code/Dao/TimeEntryRecord.php @@ -1,16 +1,16 @@ - \ No newline at end of file diff --git a/demos/time-tracker/protected/App_Code/Dao/UserDao.php b/demos/time-tracker/protected/App_Code/Dao/UserDao.php index 4bb23b3a..dcb72ee7 100644 --- a/demos/time-tracker/protected/App_Code/Dao/UserDao.php +++ b/demos/time-tracker/protected/App_Code/Dao/UserDao.php @@ -1,165 +1,165 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2005-2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - * @package Demos - */ - -/** - * UserDao class list, create, find and delete users. - * In addition, it can validate username and password, and update - * the user roles. Furthermore, a unique new token can be generated, - * this token can be used to perform persistent cookie login. - * - * @author Wei Zhuo - * @version $Id$ - * @package Demos - * @since 3.1 - */ -class UserDao extends BaseDao -{ - /** - * @param string username - * @return TimeTrackerUser find by user name, null if not found or disabled. - */ - public function getUserByName($username) - { - $sqlmap = $this->getSqlMap(); - return $sqlmap->queryForObject('GetUserByName', $username); - } - - /** - * @param string username - * @return boolean true if username already exists, false otherwise. - */ - public function usernameExists($username) - { - $sqlmap = $this->getSqlMap(); - return $sqlmap->queryForObject('UsernameExists', $username); - } - - /** - * @return array list of all enabled users. - */ - public function getAllUsers() - { - $sqlmap = $this->getSqlMap(); - return $sqlmap->queryForList('GetAllUsers'); - } - - /** - * @param TimeTrackerUser new user details. - * @param string new user password. - */ - public function addNewUser($user, $password) - { - $sqlmap = $this->getSqlMap(); - $param['user'] = $user; - $param['password'] = md5($password); - $sqlmap->insert('AddNewUser', $param); - if(count($user->getRoles()) > 0) - $this->updateUserRoles($user); - } - - /** - * @param string username to delete - */ - public function deleteUserByName($username) - { - $sqlmap = $this->getSqlMap(); - $sqlmap->delete('DeleteUserByName', $username); - } - - /** - * Updates the user profile details, including user roles. - * @param TimeTrackerUser updated user details. - * @param string new user password, null to avoid updating password. - */ - public function updateUser($user,$password=null) - { - $sqlmap = $this->getSqlMap(); - if($password !== null) - { - $param['user'] = $user; - $param['password'] = md5($password); - $sqlmap->update('UpdateUserDetailsAndPassword', $param); - } - else - { - $sqlmap->update('UpdateUserDetails', $user); - } - $this->updateUserRoles($user); - } - - /** - * @param string username to be validated - * @param string matching password - * @return boolean true if the username and password matches. - */ - public function validateUser($username, $password) - { - $sqlmap = $this->getSqlMap(); - $param['username'] = $username; - $param['password'] = md5($password); - return $sqlmap->queryForObject('ValidateUser', $param); - } - - /** - * @param string unique persistent session token - * @return TimeTrackerUser user details if valid token, null otherwise. - */ - public function validateSignon($token) - { - $sqlmap = $this->getSqlMap(); - $sqlmap->update('UpdateSignon', $token); - return $sqlmap->queryForObject('ValidateAutoSignon', $token); - } - - /** - * @param TimeTrackerUser user details to generate the token - * @return string unique persistent login token. - */ - public function createSignonToken($user) - { - $sqlmap = $this->getSqlMap(); - $param['username'] = $user->getName(); - $param['token'] = md5(microtime().$param['username']); - $sqlmap->insert('RegisterAutoSignon', $param); - return $param['token']; - } - - /** - * @param TimeTrackerUser deletes all signon token for given user, null to delete all - * tokens. - */ - public function clearSignonTokens($user=null) - { - $sqlmap = $this->getSqlMap(); - if($user !== null) - $sqlmap->delete('DeleteAutoSignon', $user->getName()); - else - $sqlmap->delete('DeleteAllSignon'); - } - - /** - * @param TimeTrackerUser user details for updating the assigned roles. - */ - public function updateUserRoles($user) - { - $sqlmap = $this->getSqlMap(); - $sqlmap->delete('DeleteUserRoles', $user); - foreach($user->getRoles() as $role) - { - $param['username'] = $user->getName(); - $param['role'] = $role; - $sqlmap->update('AddUserRole', $param); - } - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + * @package Demos + */ + +/** + * UserDao class list, create, find and delete users. + * In addition, it can validate username and password, and update + * the user roles. Furthermore, a unique new token can be generated, + * this token can be used to perform persistent cookie login. + * + * @author Wei Zhuo + * @version $Id$ + * @package Demos + * @since 3.1 + */ +class UserDao extends BaseDao +{ + /** + * @param string username + * @return TimeTrackerUser find by user name, null if not found or disabled. + */ + public function getUserByName($username) + { + $sqlmap = $this->getSqlMap(); + return $sqlmap->queryForObject('GetUserByName', $username); + } + + /** + * @param string username + * @return boolean true if username already exists, false otherwise. + */ + public function usernameExists($username) + { + $sqlmap = $this->getSqlMap(); + return $sqlmap->queryForObject('UsernameExists', $username); + } + + /** + * @return array list of all enabled users. + */ + public function getAllUsers() + { + $sqlmap = $this->getSqlMap(); + return $sqlmap->queryForList('GetAllUsers'); + } + + /** + * @param TimeTrackerUser new user details. + * @param string new user password. + */ + public function addNewUser($user, $password) + { + $sqlmap = $this->getSqlMap(); + $param['user'] = $user; + $param['password'] = md5($password); + $sqlmap->insert('AddNewUser', $param); + if(count($user->getRoles()) > 0) + $this->updateUserRoles($user); + } + + /** + * @param string username to delete + */ + public function deleteUserByName($username) + { + $sqlmap = $this->getSqlMap(); + $sqlmap->delete('DeleteUserByName', $username); + } + + /** + * Updates the user profile details, including user roles. + * @param TimeTrackerUser updated user details. + * @param string new user password, null to avoid updating password. + */ + public function updateUser($user,$password=null) + { + $sqlmap = $this->getSqlMap(); + if($password !== null) + { + $param['user'] = $user; + $param['password'] = md5($password); + $sqlmap->update('UpdateUserDetailsAndPassword', $param); + } + else + { + $sqlmap->update('UpdateUserDetails', $user); + } + $this->updateUserRoles($user); + } + + /** + * @param string username to be validated + * @param string matching password + * @return boolean true if the username and password matches. + */ + public function validateUser($username, $password) + { + $sqlmap = $this->getSqlMap(); + $param['username'] = $username; + $param['password'] = md5($password); + return $sqlmap->queryForObject('ValidateUser', $param); + } + + /** + * @param string unique persistent session token + * @return TimeTrackerUser user details if valid token, null otherwise. + */ + public function validateSignon($token) + { + $sqlmap = $this->getSqlMap(); + $sqlmap->update('UpdateSignon', $token); + return $sqlmap->queryForObject('ValidateAutoSignon', $token); + } + + /** + * @param TimeTrackerUser user details to generate the token + * @return string unique persistent login token. + */ + public function createSignonToken($user) + { + $sqlmap = $this->getSqlMap(); + $param['username'] = $user->getName(); + $param['token'] = md5(microtime().$param['username']); + $sqlmap->insert('RegisterAutoSignon', $param); + return $param['token']; + } + + /** + * @param TimeTrackerUser deletes all signon token for given user, null to delete all + * tokens. + */ + public function clearSignonTokens($user=null) + { + $sqlmap = $this->getSqlMap(); + if($user !== null) + $sqlmap->delete('DeleteAutoSignon', $user->getName()); + else + $sqlmap->delete('DeleteAllSignon'); + } + + /** + * @param TimeTrackerUser user details for updating the assigned roles. + */ + public function updateUserRoles($user) + { + $sqlmap = $this->getSqlMap(); + $sqlmap->delete('DeleteUserRoles', $user); + foreach($user->getRoles() as $role) + { + $param['username'] = $user->getName(); + $param['role'] = $role; + $sqlmap->update('AddUserRole', $param); + } + } +} + ?> \ 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 bf25c555..705dd4d0 100644 --- a/demos/time-tracker/protected/App_Code/DaoManager.php +++ b/demos/time-tracker/protected/App_Code/DaoManager.php @@ -1,79 +1,79 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2005-2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - * @package Demos - */ - -Prado::using('System.Data.SqlMap.TSqlMapConfig'); - -/** - * DaoManager class. - * - * A Registry for Dao and an implementation of that type. - * - * @author Wei Zhuo - * @version $Id$ - * @package Demos - * @since 3.1 - */ -class DaoManager extends TSqlMapConfig -{ - /** - * @var array registered list of dao - */ - private $_dao=array(); - - /** - * Initializes the module. - * This method is required by IModule and is invoked by application. - * It loads dao information from the module configuration. - * @param TXmlElement module configuration - */ - public function init($xml) - { - parent::init($xml); - foreach($xml->getElementsByTagName("dao") as $node) - { - $this->_dao[$node->getAttribute('id')] = - array('class' => $node->getAttribute('class')); - } - } - - /** - * @return array list of registered Daos - */ - public function getDaos() - { - return $this->_dao; - } - - /** - * Returns an implementation of a Dao type, implements the Registery - * pattern. Multiple calls returns the same Dao instance. - * @param string Dao type to find. - * @return object instance of the Dao implementation. - */ - public function getDao($class) - { - if(isset($this->_dao[$class])) - { - if(!isset($this->_dao[$class]['instance'])) - { - $dao = Prado::createComponent($this->_dao[$class]['class']); - $dao->setSqlMap($this->getClient()); - $this->_dao[$class]['instance'] = $dao; - } - return $this->_dao[$class]['instance']; - } - else - throw new TimeTrackerException('daomanager_undefined_dao', $class); - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + * @package Demos + */ + +Prado::using('System.Data.SqlMap.TSqlMapConfig'); + +/** + * DaoManager class. + * + * A Registry for Dao and an implementation of that type. + * + * @author Wei Zhuo + * @version $Id$ + * @package Demos + * @since 3.1 + */ +class DaoManager extends TSqlMapConfig +{ + /** + * @var array registered list of dao + */ + private $_dao=array(); + + /** + * Initializes the module. + * This method is required by IModule and is invoked by application. + * It loads dao information from the module configuration. + * @param TXmlElement module configuration + */ + public function init($xml) + { + parent::init($xml); + foreach($xml->getElementsByTagName("dao") as $node) + { + $this->_dao[$node->getAttribute('id')] = + array('class' => $node->getAttribute('class')); + } + } + + /** + * @return array list of registered Daos + */ + public function getDaos() + { + return $this->_dao; + } + + /** + * Returns an implementation of a Dao type, implements the Registery + * pattern. Multiple calls returns the same Dao instance. + * @param string Dao type to find. + * @return object instance of the Dao implementation. + */ + public function getDao($class) + { + if(isset($this->_dao[$class])) + { + if(!isset($this->_dao[$class]['instance'])) + { + $dao = Prado::createComponent($this->_dao[$class]['class']); + $dao->setSqlMap($this->getClient()); + $this->_dao[$class]['instance'] = $dao; + } + return $this->_dao[$class]['instance']; + } + else + throw new TimeTrackerException('daomanager_undefined_dao', $class); + } +} + ?> \ No newline at end of file diff --git a/demos/time-tracker/protected/App_Code/TimeTrackerException.php b/demos/time-tracker/protected/App_Code/TimeTrackerException.php index 41632c01..8c8e7efa 100644 --- a/demos/time-tracker/protected/App_Code/TimeTrackerException.php +++ b/demos/time-tracker/protected/App_Code/TimeTrackerException.php @@ -1,33 +1,33 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2005-2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - * @package Demos - */ - -/** - * Generic time tracker application exception. Exception messages are saved in - * "exceptions.txt" - * - * @author Wei Zhuo - * @version $Id$ - * @package Demos - * @since 3.1 - */ -class TimeTrackerException extends TException -{ - /** - * @return string path to the error message file - */ - protected function getErrorMessageFile() - { - return dirname(__FILE__).'/exceptions.txt'; - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + * @package Demos + */ + +/** + * Generic time tracker application exception. Exception messages are saved in + * "exceptions.txt" + * + * @author Wei Zhuo + * @version $Id$ + * @package Demos + * @since 3.1 + */ +class TimeTrackerException extends TException +{ + /** + * @return string path to the error message file + */ + protected function getErrorMessageFile() + { + return dirname(__FILE__).'/exceptions.txt'; + } +} + ?> \ No newline at end of file diff --git a/demos/time-tracker/protected/App_Code/TimeTrackerUser.php b/demos/time-tracker/protected/App_Code/TimeTrackerUser.php index b519fcde..1bf25ac1 100644 --- a/demos/time-tracker/protected/App_Code/TimeTrackerUser.php +++ b/demos/time-tracker/protected/App_Code/TimeTrackerUser.php @@ -1,48 +1,48 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2005-2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - * @package Demos - */ - -/** - * Import TUser and TUserManager - */ -Prado::using('System.Security.TUser'); -Prado::using('System.Security.TUserManager'); - -/** - * User class for Time Tracker application. - * - * @author Wei Zhuo - * @version $Id$ - * @package Demos - * @since 3.1 - */ -class TimeTrackerUser extends TUser -{ - private $_emailAddress; - - /** - * @param string user email address - */ - public function setEmailAddress($value) - { - $this->_emailAddress = $value; - } - - /** - * @return string user email address - */ - public function getEmailAddress() - { - return $this->_emailAddress; - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + * @package Demos + */ + +/** + * Import TUser and TUserManager + */ +Prado::using('System.Security.TUser'); +Prado::using('System.Security.TUserManager'); + +/** + * User class for Time Tracker application. + * + * @author Wei Zhuo + * @version $Id$ + * @package Demos + * @since 3.1 + */ +class TimeTrackerUser extends TUser +{ + private $_emailAddress; + + /** + * @param string user email address + */ + public function setEmailAddress($value) + { + $this->_emailAddress = $value; + } + + /** + * @return string user email address + */ + public function getEmailAddress() + { + return $this->_emailAddress; + } +} + ?> \ No newline at end of file diff --git a/demos/time-tracker/protected/App_Code/TrackerAuthManager.php b/demos/time-tracker/protected/App_Code/TrackerAuthManager.php index 989fcc54..ea6b5aab 100644 --- a/demos/time-tracker/protected/App_Code/TrackerAuthManager.php +++ b/demos/time-tracker/protected/App_Code/TrackerAuthManager.php @@ -1,85 +1,85 @@ - - * @version $Id$ - * @package Demos - * @since 3.1 - */ -class TrackerAuthManager extends TAuthManager -{ - /** - * @const string signon token cookie name. - */ - const SignonCookieName = 'time-tracker-signon'; - - /** - * Performs the real authentication work. Overrides and calls parent - * implementation. Trys to authenticate using token saved in cookie. - * @param mixed parameter to be passed to OnAuthenticate event - */ - public function onAuthenticate($param) - { - parent::onAuthenticate($param); - $currentUser = $this->Application->User; - if(!$currentUser || $currentUser->IsGuest) - $this->authenticateFromCookie($param); - } - - /** - * If the user is not set or is still a guest, try to authenticate the user - * using a string token saved in the cookie if any. - * @param mixed parameter to be passed to OnAuthenticate event - */ - protected function authenticateFromCookie($param) - { - $cookie = $this->Request->Cookies[self::SignonCookieName]; - if(!is_null($cookie)) - { - $daos = $this->getApplication()->getModule('daos'); - $userDao = $daos->getDao('UserDao'); - $user = $userDao->validateSignon($cookie->Value); - if($user instanceof TimeTrackerUser) - $this->updateCredential($user); - } - } - - /** - * Changes the user credentials. - * @param TUser new user details. - */ - public function updateCredential($user) - { - $user->IsGuest = false; - $this->updateSessionUser($user); - $this->Application->User = $user; - } - - /** - * Generate a token to be saved in the cookie for later authentication. - * @param TimeTrackerUser user details. - */ - public function rememberSignon($user) - { - $daos = $this->getApplication()->getModule('daos'); - $userDao = $daos->getDao('UserDao'); - $token = $userDao->createSignonToken($user); - $cookie = new THttpCookie(self::SignonCookieName, $token); - $cookie->Expire = strtotime('+1 month'); - $this->Response->Cookies[] = $cookie; - } - - /** - * Logs out the user and delete the token from cookie. - */ - public function logout() - { - parent::logout(); - $cookie = new THttpCookie(self::SignonCookieName,''); - $this->Response->Cookies[] = $cookie; - } -} - + + * @version $Id$ + * @package Demos + * @since 3.1 + */ +class TrackerAuthManager extends TAuthManager +{ + /** + * @const string signon token cookie name. + */ + const SignonCookieName = 'time-tracker-signon'; + + /** + * Performs the real authentication work. Overrides and calls parent + * implementation. Trys to authenticate using token saved in cookie. + * @param mixed parameter to be passed to OnAuthenticate event + */ + public function onAuthenticate($param) + { + parent::onAuthenticate($param); + $currentUser = $this->Application->User; + if(!$currentUser || $currentUser->IsGuest) + $this->authenticateFromCookie($param); + } + + /** + * If the user is not set or is still a guest, try to authenticate the user + * using a string token saved in the cookie if any. + * @param mixed parameter to be passed to OnAuthenticate event + */ + protected function authenticateFromCookie($param) + { + $cookie = $this->Request->Cookies[self::SignonCookieName]; + if(!is_null($cookie)) + { + $daos = $this->getApplication()->getModule('daos'); + $userDao = $daos->getDao('UserDao'); + $user = $userDao->validateSignon($cookie->Value); + if($user instanceof TimeTrackerUser) + $this->updateCredential($user); + } + } + + /** + * Changes the user credentials. + * @param TUser new user details. + */ + public function updateCredential($user) + { + $user->IsGuest = false; + $this->updateSessionUser($user); + $this->Application->User = $user; + } + + /** + * Generate a token to be saved in the cookie for later authentication. + * @param TimeTrackerUser user details. + */ + public function rememberSignon($user) + { + $daos = $this->getApplication()->getModule('daos'); + $userDao = $daos->getDao('UserDao'); + $token = $userDao->createSignonToken($user); + $cookie = new THttpCookie(self::SignonCookieName, $token); + $cookie->Expire = strtotime('+1 month'); + $this->Response->Cookies[] = $cookie; + } + + /** + * Logs out the user and delete the token from cookie. + */ + public function logout() + { + parent::logout(); + $cookie = new THttpCookie(self::SignonCookieName,''); + $this->Response->Cookies[] = $cookie; + } +} + ?> \ No newline at end of file diff --git a/demos/time-tracker/protected/App_Code/UserManager.php b/demos/time-tracker/protected/App_Code/UserManager.php index 66eecb95..fd6eeb8e 100644 --- a/demos/time-tracker/protected/App_Code/UserManager.php +++ b/demos/time-tracker/protected/App_Code/UserManager.php @@ -1,90 +1,90 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2005-2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - * @package Demos - */ - -/** - * User manager module class for time tracker application. - * - * @author Wei Zhuo - * @version $Id$ - * @package Demos - * @since 3.1 - */ -class UserManager extends TModule implements IUserManager -{ - /** - * @return string name for a guest user. - */ - public function getGuestName() - { - return 'Guest'; - } - - /** - * Returns a user instance given the user name. - * @param string user name, null if it is a guest. - * @return TUser the user instance, null if the specified username is not in the user database. - */ - public function getUser($username=null) - { - if($username===null) - { - $user=new TUser($this); - $user->setIsGuest(true); - return $user; - } - else - { - $daos = $this->getApplication()->getModule('daos'); - $userDao = $daos->getDao('UserDao'); - $user = $userDao->getUserByName($username); - $user->setIsGuest(false); - return $user; - } - } - - /** - * Validates if the username and password are correct. - * @param string user name - * @param string password - * @return boolean true if validation is successful, false otherwise. - */ - public function validateUser($username,$password) - { - $daos = $this->getApplication()->getModule('daos'); - $userDao = $daos->getDao('UserDao'); - return $userDao->validateUser($username, $password); - } - - /** - * Saves user auth data into a cookie. - * @param THttpCookie the cookie to receive the user auth data. - * @since 3.1.1 - */ - public function saveUserToCookie($cookie) - { - // do nothing since we don't support cookie-based auth in this example - } - - /** - * Returns a user instance according to auth data stored in a cookie. - * @param THttpCookie the cookie storing user authentication information - * @return TUser the user instance generated based on the cookie auth data, null if the cookie does not have valid auth data. - * @since 3.1.1 - */ - public function getUserFromCookie($cookie) - { - // do nothing since we don't support cookie-based auth in this example - return null; - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + * @package Demos + */ + +/** + * User manager module class for time tracker application. + * + * @author Wei Zhuo + * @version $Id$ + * @package Demos + * @since 3.1 + */ +class UserManager extends TModule implements IUserManager +{ + /** + * @return string name for a guest user. + */ + public function getGuestName() + { + return 'Guest'; + } + + /** + * Returns a user instance given the user name. + * @param string user name, null if it is a guest. + * @return TUser the user instance, null if the specified username is not in the user database. + */ + public function getUser($username=null) + { + if($username===null) + { + $user=new TUser($this); + $user->setIsGuest(true); + return $user; + } + else + { + $daos = $this->getApplication()->getModule('daos'); + $userDao = $daos->getDao('UserDao'); + $user = $userDao->getUserByName($username); + $user->setIsGuest(false); + return $user; + } + } + + /** + * Validates if the username and password are correct. + * @param string user name + * @param string password + * @return boolean true if validation is successful, false otherwise. + */ + public function validateUser($username,$password) + { + $daos = $this->getApplication()->getModule('daos'); + $userDao = $daos->getDao('UserDao'); + return $userDao->validateUser($username, $password); + } + + /** + * Saves user auth data into a cookie. + * @param THttpCookie the cookie to receive the user auth data. + * @since 3.1.1 + */ + public function saveUserToCookie($cookie) + { + // do nothing since we don't support cookie-based auth in this example + } + + /** + * Returns a user instance according to auth data stored in a cookie. + * @param THttpCookie the cookie storing user authentication information + * @return TUser the user instance generated based on the cookie auth data, null if the cookie does not have valid auth data. + * @since 3.1.1 + */ + public function getUserFromCookie($cookie) + { + // do nothing since we don't support cookie-based auth in this example + return null; + } +} + ?> \ No newline at end of file -- cgit v1.2.3