summaryrefslogtreecommitdiff
path: root/demos/time-tracker/protected/APP_CODE
diff options
context:
space:
mode:
Diffstat (limited to 'demos/time-tracker/protected/APP_CODE')
-rw-r--r--demos/time-tracker/protected/APP_CODE/BaseDao.php27
-rw-r--r--demos/time-tracker/protected/APP_CODE/DaoManager.php126
-rw-r--r--demos/time-tracker/protected/APP_CODE/Project.php18
-rw-r--r--demos/time-tracker/protected/APP_CODE/ProjectDao.php23
-rw-r--r--demos/time-tracker/protected/APP_CODE/TimeTrackerException.php19
-rw-r--r--demos/time-tracker/protected/APP_CODE/TimeTrackerUser.php51
-rw-r--r--demos/time-tracker/protected/APP_CODE/TimeTrackerUserTypeHandler.php54
-rw-r--r--demos/time-tracker/protected/APP_CODE/UserDao.php155
-rw-r--r--demos/time-tracker/protected/APP_CODE/UserManager.php68
-rw-r--r--demos/time-tracker/protected/APP_CODE/exceptions.txt6
10 files changed, 526 insertions, 21 deletions
diff --git a/demos/time-tracker/protected/APP_CODE/BaseDao.php b/demos/time-tracker/protected/APP_CODE/BaseDao.php
index f9146b59..63b91def 100644
--- a/demos/time-tracker/protected/APP_CODE/BaseDao.php
+++ b/demos/time-tracker/protected/APP_CODE/BaseDao.php
@@ -1,14 +1,41 @@
<?php
+/**
+ * Base DAO class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2006 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Revision: $ $16/07/2006: $
+ * @package Demos
+ */
+/**
+ * Base DAO class.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Revision: $ $16/07/2006: $
+ * @package Demos
+ * @since 3.1
+ */
class BaseDao
{
+ /**
+ * @var TSqlMapper sqlmap client.
+ */
private $_connection;
+ /**
+ * @param TSqlMapper sqlmap client.
+ */
public function setConnection($connection)
{
$this->_connection = $connection;
}
+ /**
+ * @return TSqlMapper sqlmap client.
+ */
protected function getConnection()
{
return $this->_connection;
diff --git a/demos/time-tracker/protected/APP_CODE/DaoManager.php b/demos/time-tracker/protected/APP_CODE/DaoManager.php
new file mode 100644
index 00000000..b8ac55af
--- /dev/null
+++ b/demos/time-tracker/protected/APP_CODE/DaoManager.php
@@ -0,0 +1,126 @@
+<?php
+/**
+ * DaoManager class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2006 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Revision: $ $16/07/2006: $
+ * @package Demos
+ */
+
+/**
+ * DaoManager class.
+ *
+ * A Registry for Dao and an implementation of that type.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Revision: $ $16/07/2006: $
+ * @package Demos
+ * @since 3.1
+ */
+class DaoManager extends TModule
+{
+ /**
+ * @var TSqlMapper sqlmap client
+ */
+ private $_connection;
+ /**
+ * @var boolean if the module has been initialized
+ */
+ private $_initialized=false;
+ /**
+ * @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($config)
+ {
+ if($this->_connection === null)
+ throw new TimeTrackerException('daomanager_connection_required');
+ $app = $this->getApplication();
+ if(is_string($this->_connection))
+ {
+ if(($conn=$app->getModule($this->_connection)->getClient())===null)
+ throw new TimeTrackerException('daomanager_undefined_connection',$this->_connection);
+ if(!($conn instanceof TSqlMapper))
+ throw new TimeTrackerException('daomanager_invalid_connection', $this->_connection);
+ $this->_connection = $conn;
+ }
+ $this->includeDaoImplementation($config->getElementsByTagName('dao'));
+ $this->_initialized = true;
+ }
+
+ /**
+ * Register the dao type and implementation class names.
+ * @param array list of TXmlDocument nodes.
+ */
+ protected function includeDaoImplementation($nodes)
+ {
+ foreach($nodes as $node)
+ {
+ $id = $node->getAttribute('id');
+ $class = $node->getAttribute('class');
+ $this->_dao[$id] = array('class' => $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->setConnection($this->getConnection());
+ $this->_dao[$class]['instance'] = $dao;
+ }
+ return $this->_dao[$class]['instance'];
+ }
+ else
+ throw TimeTrackerException('daomanager_undefined_dao', $class);
+ }
+
+ /**
+ * @return TSqlMapper sqlmap client instance
+ */
+ public function getConnection()
+ {
+ return $this->_connection;
+ }
+
+ /**
+ * Sets the connection for all Daos registered.
+ * @param string|TSqlMapper sqlmap client module id or TSqlMapper instance.
+ */
+ public function setConnection($client)
+ {
+ if($this->_initialized)
+ throw new TimeTrackerException('daomanager_unchangeable');
+ if(!is_string($client) && !($client instanceof TSqlMapper))
+ throw new TConfigurationException('daomanager_invalid_connection',$client);
+ $this->_connection = $client;
+ }
+}
+
+?> \ 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 ad9f7d19..660fad04 100644
--- a/demos/time-tracker/protected/APP_CODE/Project.php
+++ b/demos/time-tracker/protected/APP_CODE/Project.php
@@ -1,5 +1,23 @@
<?php
+/**
+ * Project class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2006 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Revision: $ $16/07/2006: $
+ * @package Demos
+ */
+/**
+ * Time Tracker Project class.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Revision: $ $16/07/2006: $
+ * @package Demos
+ * @since 3.1
+ */
class Project
{
public $ActualDuration = 0;
diff --git a/demos/time-tracker/protected/APP_CODE/ProjectDao.php b/demos/time-tracker/protected/APP_CODE/ProjectDao.php
index 25a2845d..81902e0c 100644
--- a/demos/time-tracker/protected/APP_CODE/ProjectDao.php
+++ b/demos/time-tracker/protected/APP_CODE/ProjectDao.php
@@ -1,10 +1,26 @@
<?php
+/**
+ * Project DAO class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2006 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Revision: $ $16/07/2006: $
+ * @package Demos
+ */
-Prado::using('Application.APP_CODE.BaseDao');
-
+/**
+ * Project DAO class.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Revision: $ $16/07/2006: $
+ * @package Demos
+ * @since 3.1
+ */
class ProjectDao extends BaseDao
{
- public function createNewProject($project)
+/* public function createNewProject($project)
{
$sqlmap = $this->getConnection();
$creator = $sqlmap->queryForObject('GetUserByName', $project->CreatorUserName);
@@ -71,6 +87,7 @@ class ProjectDao extends BaseDao
return $sqlmap->insert('AddUserToProject', $param);
}
}
+*/
}
?> \ 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 d715eefa..64b11405 100644
--- a/demos/time-tracker/protected/APP_CODE/TimeTrackerException.php
+++ b/demos/time-tracker/protected/APP_CODE/TimeTrackerException.php
@@ -1,5 +1,24 @@
<?php
+/**
+ * TimeTrackerException class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2006 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Revision: $ $16/07/2006: $
+ * @package Demos
+ */
+/**
+ * Generic time tracker application exception. Exception messages are saved in
+ * "exceptions.txt"
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Revision: $ $16/07/2006: $
+ * @package Demos
+ * @since 3.1
+ */
class TimeTrackerException extends TException
{
/**
diff --git a/demos/time-tracker/protected/APP_CODE/TimeTrackerUser.php b/demos/time-tracker/protected/APP_CODE/TimeTrackerUser.php
index 4b6987bd..99ac1209 100644
--- a/demos/time-tracker/protected/APP_CODE/TimeTrackerUser.php
+++ b/demos/time-tracker/protected/APP_CODE/TimeTrackerUser.php
@@ -1,31 +1,48 @@
<?php
+/**
+ * TimeTrackerUser class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2006 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Revision: $ $16/07/2006: $
+ * @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 <weizhuo[at]gmail[dot]com>
+ * @version $Revision: $ $16/07/2006: $
+ * @package Demos
+ * @since 3.1
+ */
class TimeTrackerUser extends TUser
{
- private $_ID;
+ private $_emailAddress;
- public function __construct()
+ /**
+ * @param string user email address
+ */
+ public function setEmailAddress($value)
{
- parent::__construct(new TUserManager());
+ $this->_emailAddress = $value;
}
-
- public function getID(){ return $this->_ID; }
- public function setID($value)
- {
- if(is_null($this->_ID))
- $this->_ID = $value;
- else
- throw new TimeTrackerUserException(
- 'timetracker_user_readonly_id');
- }
-}
-
-class TimeTrackerUserException extends TimeTrackerException
-{
+ /**
+ * @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/TimeTrackerUserTypeHandler.php b/demos/time-tracker/protected/APP_CODE/TimeTrackerUserTypeHandler.php
new file mode 100644
index 00000000..07c46acc
--- /dev/null
+++ b/demos/time-tracker/protected/APP_CODE/TimeTrackerUserTypeHandler.php
@@ -0,0 +1,54 @@
+<?php
+/**
+ * TimeTrackerUserTypeHandler class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2006 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Revision: $ $16/07/2006: $
+ * @package Demos
+ */
+
+/**
+ * SQLMap type handler for TimeTrackerUser.
+ * The TimeTrackerUser requires an instance of IUserManager in constructor.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Revision: $ $16/07/2006: $
+ * @package Demos
+ * @since 3.1
+ */
+class TimeTrackerUserTypeHandler implements ITypeHandlerCallback
+{
+ /**
+ * Not implemented.
+ */
+ public function getParameter($object)
+ {
+ throw new TimeTrackerException('Not implemented');
+ }
+
+ /**
+ * Not implemented.
+ */
+ public function getResult($string)
+ {
+ throw new TimeTrackerException('Not implemented');
+ }
+
+ /**
+ * Creates a new instance of TimeTrackerUser
+ * @param array result data
+ * @return TimeTrackerUser new user instance
+ */
+ public function createNewInstance($row=null)
+ {
+ $manager = Prado::getApplication()->getModule('users');
+ if(is_null($manager))
+ $manager = new UserManager();
+ return new TimeTrackerUser($manager);
+ }
+}
+
+?> \ 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
new file mode 100644
index 00000000..4dc39b2b
--- /dev/null
+++ b/demos/time-tracker/protected/APP_CODE/UserDao.php
@@ -0,0 +1,155 @@
+<?php
+/**
+ * User Dao class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2006 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Revision: $ $16/07/2006: $
+ * @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 <weizhuo[at]gmail[dot]com>
+ * @version $Revision: $ $16/07/2006: $
+ * @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->getConnection();
+ return $sqlmap->queryForObject('GetUserByName', $username);
+ }
+
+ /**
+ * @return array list of all enabled users.
+ */
+ public function getAllUsers()
+ {
+ $sqlmap = $this->getConnection();
+ return $sqlmap->queryForList('GetAllUsers');
+ }
+
+ /**
+ * @param TimeTrackerUser new user details.
+ * @param string new user password.
+ */
+ public function addNewUser($user, $password)
+ {
+ $sqlmap = $this->getConnection();
+ $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->getConnection();
+ $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->getConnection();
+ 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->getConnection();
+ $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->getConnection();
+ $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->getConnection();
+ $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->getConnection();
+ 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->getConnection();
+ $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/UserManager.php b/demos/time-tracker/protected/APP_CODE/UserManager.php
new file mode 100644
index 00000000..1327dc3c
--- /dev/null
+++ b/demos/time-tracker/protected/APP_CODE/UserManager.php
@@ -0,0 +1,68 @@
+<?php
+/**
+ * UserManager class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2006 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Revision: $ $16/07/2006: $
+ * @package Demos
+ */
+
+/**
+ * User manager module class for time tracker application.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Revision: $ $16/07/2006: $
+ * @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);
+ }
+}
+
+?> \ No newline at end of file
diff --git a/demos/time-tracker/protected/APP_CODE/exceptions.txt b/demos/time-tracker/protected/APP_CODE/exceptions.txt
index e948f4d0..6568cc72 100644
--- a/demos/time-tracker/protected/APP_CODE/exceptions.txt
+++ b/demos/time-tracker/protected/APP_CODE/exceptions.txt
@@ -1,3 +1,7 @@
timetracker_user_readonly_id = Time tracker user ID is read-only.
invalid_creator_and_manager = Unable to find time tracker usernames '{1}' and '{2}' for project '{0}'.
-project_exists = Project '{0}' already exists. \ No newline at end of file
+project_exists = Project '{0}' already exists.
+daomanager_connection_required = An TSqlMapper connection is required by Dao Manager.
+daomanager_undefined_connection = Connection '{0}' for Dao Manager is undefined.
+daomanager_invalid_connection = Connection '{0}' does not appear to ba a TSqlMapper in Dao Manager.
+daomanager_undefined_dao = Dao class '{0}' is not registered. \ No newline at end of file