summaryrefslogtreecommitdiff
path: root/demos/time-tracker
diff options
context:
space:
mode:
Diffstat (limited to 'demos/time-tracker')
-rw-r--r--demos/time-tracker/index.php68
-rw-r--r--demos/time-tracker/protected/App_Code/Dao/BaseDao.php88
-rw-r--r--demos/time-tracker/protected/App_Code/Dao/CategoryDao.php104
-rw-r--r--demos/time-tracker/protected/App_Code/Dao/CategoryRecord.php24
-rw-r--r--demos/time-tracker/protected/App_Code/Dao/ProjectDao.php208
-rw-r--r--demos/time-tracker/protected/App_Code/Dao/ProjectRecord.php68
-rw-r--r--demos/time-tracker/protected/App_Code/Dao/ReportsDao.php172
-rw-r--r--demos/time-tracker/protected/App_Code/Dao/TimeEntryDao.php74
-rw-r--r--demos/time-tracker/protected/App_Code/Dao/TimeEntryRecord.php30
-rw-r--r--demos/time-tracker/protected/App_Code/Dao/UserDao.php328
-rw-r--r--demos/time-tracker/protected/App_Code/DaoManager.php156
-rw-r--r--demos/time-tracker/protected/App_Code/TimeTrackerException.php64
-rw-r--r--demos/time-tracker/protected/App_Code/TimeTrackerUser.php94
-rw-r--r--demos/time-tracker/protected/App_Code/TrackerAuthManager.php168
-rw-r--r--demos/time-tracker/protected/App_Code/UserManager.php178
-rw-r--r--demos/time-tracker/protected/App_Data/DateTimeTypeHandler.php68
-rw-r--r--demos/time-tracker/protected/App_Data/TimeTrackerUserTypeHandler.php106
-rw-r--r--demos/time-tracker/protected/pages/TimeTracker/CategoryDataList.php186
-rw-r--r--demos/time-tracker/protected/pages/TimeTracker/LogTimeEntry.php222
-rw-r--r--demos/time-tracker/protected/pages/TimeTracker/Login.php108
-rw-r--r--demos/time-tracker/protected/pages/TimeTracker/Logout.php66
-rw-r--r--demos/time-tracker/protected/pages/TimeTracker/MainLayout.php12
-rw-r--r--demos/time-tracker/protected/pages/TimeTracker/ProjectDetails.php380
-rw-r--r--demos/time-tracker/protected/pages/TimeTracker/ProjectList.php66
-rw-r--r--demos/time-tracker/protected/pages/TimeTracker/ReportProject.php104
-rw-r--r--demos/time-tracker/protected/pages/TimeTracker/ReportResource.php140
-rw-r--r--demos/time-tracker/protected/pages/TimeTracker/SiteMap.php112
-rw-r--r--demos/time-tracker/protected/pages/TimeTracker/TimeEntryList.php176
-rw-r--r--demos/time-tracker/protected/pages/TimeTracker/UserCreate.php222
-rw-r--r--demos/time-tracker/protected/pages/TimeTracker/UserList.php66
-rw-r--r--demos/time-tracker/tests/functional.php18
-rw-r--r--demos/time-tracker/tests/functional/HelloPradoTestCase.php26
-rw-r--r--demos/time-tracker/tests/unit.php20
-rw-r--r--demos/time-tracker/tests/unit/BaseTestCase.php126
-rw-r--r--demos/time-tracker/tests/unit/CategoryDaoTestCase.php400
-rw-r--r--demos/time-tracker/tests/unit/ProjectDaoTestCase.php398
-rw-r--r--demos/time-tracker/tests/unit/TimeEntryDaoTestCase.php426
-rw-r--r--demos/time-tracker/tests/unit/UserDaoTestCase.php540
38 files changed, 2906 insertions, 2906 deletions
diff --git a/demos/time-tracker/index.php b/demos/time-tracker/index.php
index 7954aeb9..d1fbccf9 100644
--- a/demos/time-tracker/index.php
+++ b/demos/time-tracker/index.php
@@ -1,35 +1,35 @@
-<?php
-
-$basePath=dirname(__FILE__);
-//$frameworkPath='../../framework/pradolite.php';
-$frameworkPath='../../framework/prado.php';
-$assetsPath=$basePath."/assets";
-$runtimePath=$basePath."/protected/runtime";
-
-$sqlite_dir = $basePath."/protected/App_Data/SQLite";
-$sqlite_db = $sqlite_dir.'/time-tracker.db';
-
-if(!is_file($frameworkPath))
- die("Unable to find prado framework path $frameworkPath.");
-if(!is_writable($assetsPath))
- die("Please make sure that the directory $assetsPath is writable by Web server process.");
-if(!is_writable($runtimePath))
- die("Please make sure that the directory $runtimePath is writable by Web server process.");
-if(!is_writable($sqlite_dir))
- die("Please make sure that the directory $sqlite_dir is writable by Web server process.");
-if(!is_writable($sqlite_db))
- die("Please make sure that the sqlite database file $sqlite_dir is writable by Web server process.");
-
-require_once($frameworkPath);
-
-function h($text)
-{
- $app = Prado::getApplication()->getGlobalization();
- $charset = $app ? $app->getCharset() : 'UTF-8';
- return htmlentities($text, ENT_QUOTES, $charset);
-}
-
-$application=new TApplication;
-$application->run();
-
+<?php
+
+$basePath=dirname(__FILE__);
+//$frameworkPath='../../framework/pradolite.php';
+$frameworkPath='../../framework/prado.php';
+$assetsPath=$basePath."/assets";
+$runtimePath=$basePath."/protected/runtime";
+
+$sqlite_dir = $basePath."/protected/App_Data/SQLite";
+$sqlite_db = $sqlite_dir.'/time-tracker.db';
+
+if(!is_file($frameworkPath))
+ die("Unable to find prado framework path $frameworkPath.");
+if(!is_writable($assetsPath))
+ die("Please make sure that the directory $assetsPath is writable by Web server process.");
+if(!is_writable($runtimePath))
+ die("Please make sure that the directory $runtimePath is writable by Web server process.");
+if(!is_writable($sqlite_dir))
+ die("Please make sure that the directory $sqlite_dir is writable by Web server process.");
+if(!is_writable($sqlite_db))
+ die("Please make sure that the sqlite database file $sqlite_dir is writable by Web server process.");
+
+require_once($frameworkPath);
+
+function h($text)
+{
+ $app = Prado::getApplication()->getGlobalization();
+ $charset = $app ? $app->getCharset() : 'UTF-8';
+ return htmlentities($text, ENT_QUOTES, $charset);
+}
+
+$application=new TApplication;
+$application->run();
+
?> \ No newline at end of file
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 @@
-<?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 $Id$
- * @package Demos
- */
-
-/**
- * Base DAO class.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @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;
- }
-}
-
+<?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 $Id$
+ * @package Demos
+ */
+
+/**
+ * Base DAO class.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @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 @@
-<?php
-
-class CategoryDao extends BaseDao
-{
- function addNewCategory($category)
- {
- $sqlmap = $this->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);
- }
-}
-
+<?php
+
+class CategoryDao extends BaseDao
+{
+ function addNewCategory($category)
+ {
+ $sqlmap = $this->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 @@
-<?php
-
-class CategoryRecord
-{
- public $ActualDuration = 0.0;
- public $Abbreviation = '';
- public $ID=0;
- public $EstimateDuration = 0.0;
- public $Name='';
- public $ProjectID=0;
-}
-
+<?php
+
+class CategoryRecord
+{
+ 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/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 @@
-<?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 $Id$
- * @package Demos
- */
-
-/**
- * Project DAO class.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @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);
- }
-}
-
+<?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 $Id$
+ * @package Demos
+ */
+
+/**
+ * Project DAO class.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @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 @@
-<?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 $Id$
- * @package Demos
- */
-
-/**
- * Time Tracker Project class.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @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 = '';
-}
-
-
+<?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 $Id$
+ * @package Demos
+ */
+
+/**
+ * Time Tracker Project class.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @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 @@
-<?php
-
-class ProjectReport extends TComponent
-{
- public $ProjectName = '';
- public $EstimateHours = 0;
- public $EstimateCompletion = 0;
- public $Categories;
-
- public function __construct()
- {
- $this->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);
- }
-}
-
+<?php
+
+class ProjectReport extends TComponent
+{
+ public $ProjectName = '';
+ public $EstimateHours = 0;
+ public $EstimateCompletion = 0;
+ public $Categories;
+
+ public function __construct()
+ {
+ $this->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 @@
-<?php
-
-class TimeEntryDao extends BaseDao
-{
- public function addNewTimeEntry($entry)
- {
- $sqlmap = $this->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);
- }
-}
-
+<?php
+
+class TimeEntryDao extends BaseDao
+{
+ public function addNewTimeEntry($entry)
+ {
+ $sqlmap = $this->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 @@
-<?php
-
-class TimeEntryRecord
-{
- public $CreatorUserName='';
- public $Category;
- public $DateCreated=0;
- public $Description='';
- public $Duration=0.0;
- public $ID=0;
- public $Project;
- public $ReportDate=0;
- public $Username;
-}
-
+<?php
+
+class TimeEntryRecord
+{
+ 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/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 @@
-<?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 $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 <weizhuo[at]gmail[dot]com>
- * @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);
- }
- }
-}
-
+<?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 $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 <weizhuo[at]gmail[dot]com>
+ * @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 @@
-<?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 $Id$
- * @package Demos
- */
-
-Prado::using('System.Data.SqlMap.TSqlMapConfig');
-
-/**
- * DaoManager class.
- *
- * A Registry for Dao and an implementation of that type.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @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);
- }
-}
-
+<?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 $Id$
+ * @package Demos
+ */
+
+Prado::using('System.Data.SqlMap.TSqlMapConfig');
+
+/**
+ * DaoManager class.
+ *
+ * A Registry for Dao and an implementation of that type.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @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 @@
-<?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 $Id$
- * @package Demos
- */
-
-/**
- * Generic time tracker application exception. Exception messages are saved in
- * "exceptions.txt"
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @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';
- }
-}
-
+<?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 $Id$
+ * @package Demos
+ */
+
+/**
+ * Generic time tracker application exception. Exception messages are saved in
+ * "exceptions.txt"
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @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 @@
-<?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 $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 <weizhuo[at]gmail[dot]com>
- * @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;
- }
-}
-
+<?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 $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 <weizhuo[at]gmail[dot]com>
+ * @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 @@
-<?php
-/**
- * Custom Authentication manager permits authentication using
- * a string token saved in the cookie.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @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;
- }
-}
-
+<?php
+/**
+ * Custom Authentication manager permits authentication using
+ * a string token saved in the cookie.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @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 @@
-<?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 $Id$
- * @package Demos
- */
-
-/**
- * User manager module class for time tracker application.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @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;
- }
-}
-
+<?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 $Id$
+ * @package Demos
+ */
+
+/**
+ * User manager module class for time tracker application.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @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
diff --git a/demos/time-tracker/protected/App_Data/DateTimeTypeHandler.php b/demos/time-tracker/protected/App_Data/DateTimeTypeHandler.php
index 03af3d36..b7a76e3d 100644
--- a/demos/time-tracker/protected/App_Data/DateTimeTypeHandler.php
+++ b/demos/time-tracker/protected/App_Data/DateTimeTypeHandler.php
@@ -1,35 +1,35 @@
-<?php
-
-class DateTimeTypeHandler extends TSqlMapTypeHandler
-{
- /**
- * Not implemented.
- */
- public function getParameter($integer)
- {
- return date('Y-m-d H:i:s', $integer);
- }
-
- /**
- * Not implemented.
- */
- public function getResult($string)
- {
- if(intval($string) > 10000) //strtotime doesn't like unix epoc time.
- return intval($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');
- }
-
-}
-
+<?php
+
+class DateTimeTypeHandler extends TSqlMapTypeHandler
+{
+ /**
+ * Not implemented.
+ */
+ public function getParameter($integer)
+ {
+ return date('Y-m-d H:i:s', $integer);
+ }
+
+ /**
+ * Not implemented.
+ */
+ public function getResult($string)
+ {
+ if(intval($string) > 10000) //strtotime doesn't like unix epoc time.
+ return intval($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_Data/TimeTrackerUserTypeHandler.php b/demos/time-tracker/protected/App_Data/TimeTrackerUserTypeHandler.php
index 54aba438..d9e28ae5 100644
--- a/demos/time-tracker/protected/App_Data/TimeTrackerUserTypeHandler.php
+++ b/demos/time-tracker/protected/App_Data/TimeTrackerUserTypeHandler.php
@@ -1,54 +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 $Id$
- * @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 $Id$
- * @package Demos
- * @since 3.1
- */
-class TimeTrackerUserTypeHandler extends TSqlMapTypeHandler
-{
- /**
- * 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);
- }
-}
-
+<?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 $Id$
+ * @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 $Id$
+ * @package Demos
+ * @since 3.1
+ */
+class TimeTrackerUserTypeHandler extends TSqlMapTypeHandler
+{
+ /**
+ * 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/pages/TimeTracker/CategoryDataList.php b/demos/time-tracker/protected/pages/TimeTracker/CategoryDataList.php
index dd04dbf3..cc21a486 100644
--- a/demos/time-tracker/protected/pages/TimeTracker/CategoryDataList.php
+++ b/demos/time-tracker/protected/pages/TimeTracker/CategoryDataList.php
@@ -1,94 +1,94 @@
-<?php
-
-class CategoryDataList extends TTemplateControl
-{
- public function setProjectID($value)
- {
- $this->setViewState('ProjectID', $value, '');
- }
-
- public function getProjectID()
- {
- return $this->getViewState('ProjectID', '');
- }
-
- public function getCategories()
- {
- $this->ensureChildControls();
- return $this->getRegisteredObject('categories');
- }
-
- protected function getCategoryDao()
- {
- return $this->Application->Modules['daos']->getDao('CategoryDao');
- }
-
- public function showCategories()
- {
- $categoryDao = $this->getCategoryDao();
- $list = $categoryDao->getCategoriesByProjectID($this->getProjectID());
- $this->categories->DataSource = $list;
- $this->categories->dataBind();
- }
-
- public function deleteCategoryItem($sender, $param)
- {
- $id = $this->categories->DataKeys[$param->Item->ItemIndex];
- $this->getCategoryDao()->deleteCategory($id);
- $this->refreshCategoryList($sender, $param);
- }
-
- public function editCategoryItem($sender, $param)
- {
- $this->categories->EditItemIndex=$param->Item->ItemIndex;
- $this->showCategories();
- }
-
- public function refreshCategoryList($sender, $param)
- {
- $this->categories->EditItemIndex=-1;
- $this->showCategories();
- }
-
- public function updateCategoryItem($sender, $param)
- {
- if(!$this->Page->IsValid)
- return;
-
- $item = $param->Item;
-
- $id = $this->categories->DataKeys[$param->Item->ItemIndex];
- $category = new CategoryRecord;
- $category->ID = $id;
- $category->Name = $item->name->Text;
- $category->Abbreviation = $item->abbrev->Text;
- $category->EstimateDuration = floatval($item->duration->Text);
- $category->ProjectID = $this->getProjectID();
-
- $this->getCategoryDao()->updateCategory($category);
-
- $this->refreshCategoryList($sender, $param);
- }
-
- public function addCategory_clicked($sender, $param)
- {
- if(!$this->Page->IsValid)
- return;
-
- $newCategory = new CategoryRecord;
- $newCategory->Name = $this->categoryName->Text;
- $newCategory->Abbreviation = $this->abbrev->Text;
- $newCategory->EstimateDuration = floatval($this->duration->Text);
- $newCategory->ProjectID = $this->getProjectID();
-
- $this->getCategoryDao()->addNewCategory($newCategory);
-
- $this->categoryName->Text = '';
- $this->abbrev->Text = '';
- $this->duration->Text = '';
-
- $this->showCategories();
- }
-}
-
+<?php
+
+class CategoryDataList extends TTemplateControl
+{
+ public function setProjectID($value)
+ {
+ $this->setViewState('ProjectID', $value, '');
+ }
+
+ public function getProjectID()
+ {
+ return $this->getViewState('ProjectID', '');
+ }
+
+ public function getCategories()
+ {
+ $this->ensureChildControls();
+ return $this->getRegisteredObject('categories');
+ }
+
+ protected function getCategoryDao()
+ {
+ return $this->Application->Modules['daos']->getDao('CategoryDao');
+ }
+
+ public function showCategories()
+ {
+ $categoryDao = $this->getCategoryDao();
+ $list = $categoryDao->getCategoriesByProjectID($this->getProjectID());
+ $this->categories->DataSource = $list;
+ $this->categories->dataBind();
+ }
+
+ public function deleteCategoryItem($sender, $param)
+ {
+ $id = $this->categories->DataKeys[$param->Item->ItemIndex];
+ $this->getCategoryDao()->deleteCategory($id);
+ $this->refreshCategoryList($sender, $param);
+ }
+
+ public function editCategoryItem($sender, $param)
+ {
+ $this->categories->EditItemIndex=$param->Item->ItemIndex;
+ $this->showCategories();
+ }
+
+ public function refreshCategoryList($sender, $param)
+ {
+ $this->categories->EditItemIndex=-1;
+ $this->showCategories();
+ }
+
+ public function updateCategoryItem($sender, $param)
+ {
+ if(!$this->Page->IsValid)
+ return;
+
+ $item = $param->Item;
+
+ $id = $this->categories->DataKeys[$param->Item->ItemIndex];
+ $category = new CategoryRecord;
+ $category->ID = $id;
+ $category->Name = $item->name->Text;
+ $category->Abbreviation = $item->abbrev->Text;
+ $category->EstimateDuration = floatval($item->duration->Text);
+ $category->ProjectID = $this->getProjectID();
+
+ $this->getCategoryDao()->updateCategory($category);
+
+ $this->refreshCategoryList($sender, $param);
+ }
+
+ public function addCategory_clicked($sender, $param)
+ {
+ if(!$this->Page->IsValid)
+ return;
+
+ $newCategory = new CategoryRecord;
+ $newCategory->Name = $this->categoryName->Text;
+ $newCategory->Abbreviation = $this->abbrev->Text;
+ $newCategory->EstimateDuration = floatval($this->duration->Text);
+ $newCategory->ProjectID = $this->getProjectID();
+
+ $this->getCategoryDao()->addNewCategory($newCategory);
+
+ $this->categoryName->Text = '';
+ $this->abbrev->Text = '';
+ $this->duration->Text = '';
+
+ $this->showCategories();
+ }
+}
+
?> \ No newline at end of file
diff --git a/demos/time-tracker/protected/pages/TimeTracker/LogTimeEntry.php b/demos/time-tracker/protected/pages/TimeTracker/LogTimeEntry.php
index 2c8f0f3b..71d29b78 100644
--- a/demos/time-tracker/protected/pages/TimeTracker/LogTimeEntry.php
+++ b/demos/time-tracker/protected/pages/TimeTracker/LogTimeEntry.php
@@ -1,112 +1,112 @@
-<?php
-
-class LogTimeEntry extends TPage
-{
-
- protected function getProjectDao()
- {
- return $this->Application->Modules['daos']->getDao('ProjectDao');
- }
-
- protected function getCategoryDao()
- {
- return $this->Application->Modules['daos']->getDao('CategoryDao');
- }
-
- protected function getTimeEntryDao()
- {
- return $this->Application->Modules['daos']->getDao('TimeEntryDao');
- }
-
- public function onLoad($param)
- {
- if(!$this->IsPostBack)
- {
- $projects = $this->getProjects();
- $this->projects->DataSource = $projects;
- $this->projects->dataBind();
- $this->showCategories(key($projects));
- }
- }
-
- protected function showCategories($projectID)
- {
- $categories = array();
- foreach($this->getCategoryDao()->getCategoriesByProjectID($projectID) as $cat)
- {
- $categories[$cat->ID] = $cat->Name;
- }
- $this->category->DataSource = $categories;
- $this->category->dataBind();
- $this->showProjectUsers($projectID);
- }
-
- protected function showProjectUsers($projectID)
- {
- if($this->User->isInRole('manager'))
- $users = $this->getProjectDao()->getProjectMembers($projectID);
- else
- $users = array($this->User->Name);
- $this->projectMembers->DataSource = $users;
- $this->projectMembers->dataBind();
- if(is_int($index = array_search($this->User->Name, $users)))
- {
- $this->projectMembers->SelectedIndex = $index;
- $this->showTimeSheet();
- }
- }
-
- public function showTimeSheet()
- {
- $user = $this->projectMembers->SelectedItem->Text;
- $project = $this->projects->SelectedValue;
- $this->entryList->setProjectEntry($user,$project);
- $this->entryList->refreshEntryList();
- }
-
- protected function getProjects()
- {
- $projects = array();
- if($this->User->isInRole('admin'))
- $list = $this->getProjectDao()->getAllProjects();
- else if($this->User->isInRole('manager'))
- $list = $this->getProjectDao()->getProjectsByManagerName($this->User->Name);
- else
- $list = $this->getProjectDao()->getProjectsByUserName($this->User->Name);
- foreach($list as $project)
- $projects[$project->ID] = $project->Name;
- return $projects;
- }
-
- public function projects_Changed($sender, $param)
- {
- $this->showCategories($sender->SelectedValue);
- }
-
- public function AddNewEntry($sender, $param)
- {
- if(!$this->IsValid)
- return;
-
- if($this->projectMembers->SelectedItem)
- {
- $entry = new TimeEntryRecord;
- $entry->CreatorUserName = $this->User->Name;
- $category = new CategoryRecord;
- $category->ID = $this->category->SelectedValue;
- $entry->Category = $category;
- $entry->Description = $this->description->Text;
- $entry->Duration = floatval($this->hours->Text);
- $entry->ReportDate = $this->day->TimeStamp;
- $entry->Username = $this->projectMembers->SelectedItem->Text;
-
- $this->hours->Text = '';
- $this->description->Text = '';
-
- $this->getTimeEntryDao()->addNewTimeEntry($entry);
- $this->showTimeSheet();
- }
- }
-}
-
+<?php
+
+class LogTimeEntry extends TPage
+{
+
+ protected function getProjectDao()
+ {
+ return $this->Application->Modules['daos']->getDao('ProjectDao');
+ }
+
+ protected function getCategoryDao()
+ {
+ return $this->Application->Modules['daos']->getDao('CategoryDao');
+ }
+
+ protected function getTimeEntryDao()
+ {
+ return $this->Application->Modules['daos']->getDao('TimeEntryDao');
+ }
+
+ public function onLoad($param)
+ {
+ if(!$this->IsPostBack)
+ {
+ $projects = $this->getProjects();
+ $this->projects->DataSource = $projects;
+ $this->projects->dataBind();
+ $this->showCategories(key($projects));
+ }
+ }
+
+ protected function showCategories($projectID)
+ {
+ $categories = array();
+ foreach($this->getCategoryDao()->getCategoriesByProjectID($projectID) as $cat)
+ {
+ $categories[$cat->ID] = $cat->Name;
+ }
+ $this->category->DataSource = $categories;
+ $this->category->dataBind();
+ $this->showProjectUsers($projectID);
+ }
+
+ protected function showProjectUsers($projectID)
+ {
+ if($this->User->isInRole('manager'))
+ $users = $this->getProjectDao()->getProjectMembers($projectID);
+ else
+ $users = array($this->User->Name);
+ $this->projectMembers->DataSource = $users;
+ $this->projectMembers->dataBind();
+ if(is_int($index = array_search($this->User->Name, $users)))
+ {
+ $this->projectMembers->SelectedIndex = $index;
+ $this->showTimeSheet();
+ }
+ }
+
+ public function showTimeSheet()
+ {
+ $user = $this->projectMembers->SelectedItem->Text;
+ $project = $this->projects->SelectedValue;
+ $this->entryList->setProjectEntry($user,$project);
+ $this->entryList->refreshEntryList();
+ }
+
+ protected function getProjects()
+ {
+ $projects = array();
+ if($this->User->isInRole('admin'))
+ $list = $this->getProjectDao()->getAllProjects();
+ else if($this->User->isInRole('manager'))
+ $list = $this->getProjectDao()->getProjectsByManagerName($this->User->Name);
+ else
+ $list = $this->getProjectDao()->getProjectsByUserName($this->User->Name);
+ foreach($list as $project)
+ $projects[$project->ID] = $project->Name;
+ return $projects;
+ }
+
+ public function projects_Changed($sender, $param)
+ {
+ $this->showCategories($sender->SelectedValue);
+ }
+
+ public function AddNewEntry($sender, $param)
+ {
+ if(!$this->IsValid)
+ return;
+
+ if($this->projectMembers->SelectedItem)
+ {
+ $entry = new TimeEntryRecord;
+ $entry->CreatorUserName = $this->User->Name;
+ $category = new CategoryRecord;
+ $category->ID = $this->category->SelectedValue;
+ $entry->Category = $category;
+ $entry->Description = $this->description->Text;
+ $entry->Duration = floatval($this->hours->Text);
+ $entry->ReportDate = $this->day->TimeStamp;
+ $entry->Username = $this->projectMembers->SelectedItem->Text;
+
+ $this->hours->Text = '';
+ $this->description->Text = '';
+
+ $this->getTimeEntryDao()->addNewTimeEntry($entry);
+ $this->showTimeSheet();
+ }
+ }
+}
+
?> \ No newline at end of file
diff --git a/demos/time-tracker/protected/pages/TimeTracker/Login.php b/demos/time-tracker/protected/pages/TimeTracker/Login.php
index 2bd02cc1..d306cf63 100644
--- a/demos/time-tracker/protected/pages/TimeTracker/Login.php
+++ b/demos/time-tracker/protected/pages/TimeTracker/Login.php
@@ -1,55 +1,55 @@
-<?php
-/**
- * Login Page 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 $Id$
- * @package Demos
- */
-
-/**
- * Login page class.
- *
- * Validate the user credentials and redirect to requested page
- * if successful.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package Demos
- * @since 3.1
- */
-class Login extends TPage
-{
- /**
- * Validates the username and password.
- * @param TControl custom validator that created the event.
- * @param TServerValidateEventParameter validation parameters.
- */
- public function validateUser($sender, $param)
- {
- $authManager=$this->Application->getModule('auth');
- if(!$authManager->login($this->username->Text,$this->password->Text))
- $param->IsValid=false;;
- }
-
- /**
- * Redirect to the requested page if login is successful.
- * @param TControl button control that created the event.
- * @param TEventParameter event parameters.
- */
- public function doLogin($sender, $param)
- {
- if($this->Page->IsValid)
- {
- $auth = $this->Application->getModule('auth');
- if($this->remember->Checked)
- $auth->rememberSignon($this->User);
- $this->Response->redirect($auth->getReturnUrl());
- }
- }
-}
-
+<?php
+/**
+ * Login Page 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 $Id$
+ * @package Demos
+ */
+
+/**
+ * Login page class.
+ *
+ * Validate the user credentials and redirect to requested page
+ * if successful.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package Demos
+ * @since 3.1
+ */
+class Login extends TPage
+{
+ /**
+ * Validates the username and password.
+ * @param TControl custom validator that created the event.
+ * @param TServerValidateEventParameter validation parameters.
+ */
+ public function validateUser($sender, $param)
+ {
+ $authManager=$this->Application->getModule('auth');
+ if(!$authManager->login($this->username->Text,$this->password->Text))
+ $param->IsValid=false;;
+ }
+
+ /**
+ * Redirect to the requested page if login is successful.
+ * @param TControl button control that created the event.
+ * @param TEventParameter event parameters.
+ */
+ public function doLogin($sender, $param)
+ {
+ if($this->Page->IsValid)
+ {
+ $auth = $this->Application->getModule('auth');
+ if($this->remember->Checked)
+ $auth->rememberSignon($this->User);
+ $this->Response->redirect($auth->getReturnUrl());
+ }
+ }
+}
+
?> \ No newline at end of file
diff --git a/demos/time-tracker/protected/pages/TimeTracker/Logout.php b/demos/time-tracker/protected/pages/TimeTracker/Logout.php
index 2e3d3ccc..f82f137c 100644
--- a/demos/time-tracker/protected/pages/TimeTracker/Logout.php
+++ b/demos/time-tracker/protected/pages/TimeTracker/Logout.php
@@ -1,34 +1,34 @@
-<?php
-/**
- * Logout 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 $Id$
- * @package Demos
- */
-
-/**
- * Logout page class.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package Demos
- * @since 3.1
- */
-class Logout extends TPage
-{
- /**
- * Logs out the current user and redirect to default page.
- */
- function onLoad($param)
- {
- $this->Application->getModule('auth')->logout();
- $url = $this->Service->constructUrl($this->Service->DefaultPage);
- $this->Response->redirect($url);
- }
-}
-
+<?php
+/**
+ * Logout 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 $Id$
+ * @package Demos
+ */
+
+/**
+ * Logout page class.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package Demos
+ * @since 3.1
+ */
+class Logout extends TPage
+{
+ /**
+ * Logs out the current user and redirect to default page.
+ */
+ function onLoad($param)
+ {
+ $this->Application->getModule('auth')->logout();
+ $url = $this->Service->constructUrl($this->Service->DefaultPage);
+ $this->Response->redirect($url);
+ }
+}
+
?> \ No newline at end of file
diff --git a/demos/time-tracker/protected/pages/TimeTracker/MainLayout.php b/demos/time-tracker/protected/pages/TimeTracker/MainLayout.php
index 253d6c03..c966ba85 100644
--- a/demos/time-tracker/protected/pages/TimeTracker/MainLayout.php
+++ b/demos/time-tracker/protected/pages/TimeTracker/MainLayout.php
@@ -1,7 +1,7 @@
-<?php
-
-class MainLayout extends TTemplateControl
-{
-}
-
+<?php
+
+class MainLayout extends TTemplateControl
+{
+}
+
?> \ No newline at end of file
diff --git a/demos/time-tracker/protected/pages/TimeTracker/ProjectDetails.php b/demos/time-tracker/protected/pages/TimeTracker/ProjectDetails.php
index 98a93148..f4fb9718 100644
--- a/demos/time-tracker/protected/pages/TimeTracker/ProjectDetails.php
+++ b/demos/time-tracker/protected/pages/TimeTracker/ProjectDetails.php
@@ -1,191 +1,191 @@
-<?php
-
-class ProjectDetails extends TPage
-{
- private $allUsers;
-
- private $currentProject;
-
- protected function getCurrentProject()
- {
- if(!$this->currentProject)
- {
- $id = intval($this->Request['ProjectID']);
- if($id > 0)
- $this->currentProject = $this->getProjectDao()->getProjectByID($id);
- }
- return $this->currentProject;
- }
-
- protected function getProjectDao()
- {
- return $this->Application->Modules['daos']->getDao('ProjectDao');
- }
-
- protected function getCategoryDao()
- {
- return $this->Application->Modules['daos']->getDao('CategoryDao');
- }
-
- public function onLoad($param)
- {
- if(!$this->IsPostBack)
- {
- $this->manager->DataSource = $this->getUsersWithRole('manager');
- $this->manager->dataBind();
- $this->members->DataSource = $this->getUsersWithRole('consultant');
- $this->members->dataBind();
-
- $project = $this->getCurrentProject();
-
- if($project !== null)
- {
- $this->projectName->Text = $project->Name;
- $this->completionDate->TimeStamp = $project->CompletionDate;
- $this->description->Text = $project->Description;
- $this->estimateHours->Text = $project->EstimateDuration;
- $this->manager->SelectedValue = $project->ManagerUserName;
-
- $this->selectProjectMembers($project->ID);
-
- $this->projectCategoryColumn->Visible = true;
- $this->categories->ProjectID = $project->ID;
- $this->categories->showCategories();
-
- $this->deleteButton->Visible = true;
-
- $this->projectList->DataSource = $this->getProjects();
- $this->projectList->dataBind();
-
- }
- else
- {
- $this->projectCategoryColumn->Visible = false;
- $this->deleteButton->Visible = false;
- }
-
- }
- }
-
- protected function getProjects()
- {
- $projects = array();
- foreach($this->getProjectDao()->getAllProjects() as $project)
- {
- if($project->Name != $this->currentProject->Name)
- $projects[$project->ID] = $project->Name;
- }
- return $projects;
- }
-
- protected function selectProjectMembers($projectID)
- {
- $members = $this->getProjectDao()->getProjectMembers($projectID);
- $this->members->SelectedValues = $members;
- }
-
- protected function getUsersWithRole($role)
- {
- if(is_null($this->allUsers))
- {
- $dao = $this->Application->Modules['daos']->getDao('UserDao');
- $this->allUsers = $dao->getAllUsers();
- }
- $users = array();
- foreach($this->allUsers as $user)
- {
- if($user->isInRole($role))
- $users[$user->Name] = $user->Name;
- }
- return $users;
- }
-
- public function onPreRender($param)
- {
- $ids = array();
- foreach($this->members->Items as $item)
- {
- if($item->Selected)
- $ids[] = $item->Value;
- }
- $this->setViewState('ActiveConsultants', $ids);
- }
-
- public function saveButton_clicked($sender, $param)
- {
- if(!$this->Page->IsValid)
- return;
-
- $newProject = new ProjectRecord;
-
- $projectDao = $this->getProjectDao();
-
- if($project = $this->getCurrentProject())
- $newProject = $projectDao->getProjectByID($project->ID);
- else
- $newProject->CreatorUserName = $this->User->Name;
-
- $newProject->Name = $this->projectName->Text;
- $newProject->CompletionDate = $this->completionDate->TimeStamp;
- $newProject->Description = $this->description->Text;
- $newProject->EstimateDuration = floatval($this->estimateHours->Text);
- $newProject->ManagerUserName = $this->manager->SelectedValue;
-
- if($this->currentProject)
- $projectDao->updateProject($newProject);
- else
- $projectDao->addNewProject($newProject);
-
- $this->updateProjectMembers($newProject->ID);
-
- $url = $this->Service->constructUrl('TimeTracker.ProjectDetails',
- array('ProjectID'=> $newProject->ID));
-
- $this->Response->redirect($url);
- }
-
- protected function updateProjectMembers($projectID)
- {
- $active = $this->getViewState('ActiveConsultants');
- $projectDao = $this->getProjectDao();
- foreach($this->members->Items as $item)
- {
- if($item->Selected)
- {
- if(!in_array($item->Value, $active))
- $projectDao->addUserToProject($projectID, $item->Value);
- }
- else
- {
- if(in_array($item->Value, $active))
- $projectDao->removeUserFromProject($projectID, $item->Value);
- }
- }
- }
-
- public function deleteButton_clicked($sender, $param)
- {
- if($project = $this->getCurrentProject())
- {
- $this->getProjectDao()->deleteProject($project->ID);
- $url = $this->Service->constructUrl('TimeTracker.ProjectList');
- $this->Response->redirect($url);
- }
- }
-
- public function copyButton_clicked($sender, $param)
- {
- $project = $this->projectList->SelectedValue;
- $categoryDao = $this->getCategoryDao();
- $categories = $categoryDao->getCategoriesByProjectID($project);
- $currentProject = $this->getCurrentProject();
- foreach($categories as $cat)
- {
- $cat->ProjectID = $currentProject->ID;
- $categoryDao->addNewCategory($cat);
- }
- $this->categories->showCategories();
- }
-}
-
+<?php
+
+class ProjectDetails extends TPage
+{
+ private $allUsers;
+
+ private $currentProject;
+
+ protected function getCurrentProject()
+ {
+ if(!$this->currentProject)
+ {
+ $id = intval($this->Request['ProjectID']);
+ if($id > 0)
+ $this->currentProject = $this->getProjectDao()->getProjectByID($id);
+ }
+ return $this->currentProject;
+ }
+
+ protected function getProjectDao()
+ {
+ return $this->Application->Modules['daos']->getDao('ProjectDao');
+ }
+
+ protected function getCategoryDao()
+ {
+ return $this->Application->Modules['daos']->getDao('CategoryDao');
+ }
+
+ public function onLoad($param)
+ {
+ if(!$this->IsPostBack)
+ {
+ $this->manager->DataSource = $this->getUsersWithRole('manager');
+ $this->manager->dataBind();
+ $this->members->DataSource = $this->getUsersWithRole('consultant');
+ $this->members->dataBind();
+
+ $project = $this->getCurrentProject();
+
+ if($project !== null)
+ {
+ $this->projectName->Text = $project->Name;
+ $this->completionDate->TimeStamp = $project->CompletionDate;
+ $this->description->Text = $project->Description;
+ $this->estimateHours->Text = $project->EstimateDuration;
+ $this->manager->SelectedValue = $project->ManagerUserName;
+
+ $this->selectProjectMembers($project->ID);
+
+ $this->projectCategoryColumn->Visible = true;
+ $this->categories->ProjectID = $project->ID;
+ $this->categories->showCategories();
+
+ $this->deleteButton->Visible = true;
+
+ $this->projectList->DataSource = $this->getProjects();
+ $this->projectList->dataBind();
+
+ }
+ else
+ {
+ $this->projectCategoryColumn->Visible = false;
+ $this->deleteButton->Visible = false;
+ }
+
+ }
+ }
+
+ protected function getProjects()
+ {
+ $projects = array();
+ foreach($this->getProjectDao()->getAllProjects() as $project)
+ {
+ if($project->Name != $this->currentProject->Name)
+ $projects[$project->ID] = $project->Name;
+ }
+ return $projects;
+ }
+
+ protected function selectProjectMembers($projectID)
+ {
+ $members = $this->getProjectDao()->getProjectMembers($projectID);
+ $this->members->SelectedValues = $members;
+ }
+
+ protected function getUsersWithRole($role)
+ {
+ if(is_null($this->allUsers))
+ {
+ $dao = $this->Application->Modules['daos']->getDao('UserDao');
+ $this->allUsers = $dao->getAllUsers();
+ }
+ $users = array();
+ foreach($this->allUsers as $user)
+ {
+ if($user->isInRole($role))
+ $users[$user->Name] = $user->Name;
+ }
+ return $users;
+ }
+
+ public function onPreRender($param)
+ {
+ $ids = array();
+ foreach($this->members->Items as $item)
+ {
+ if($item->Selected)
+ $ids[] = $item->Value;
+ }
+ $this->setViewState('ActiveConsultants', $ids);
+ }
+
+ public function saveButton_clicked($sender, $param)
+ {
+ if(!$this->Page->IsValid)
+ return;
+
+ $newProject = new ProjectRecord;
+
+ $projectDao = $this->getProjectDao();
+
+ if($project = $this->getCurrentProject())
+ $newProject = $projectDao->getProjectByID($project->ID);
+ else
+ $newProject->CreatorUserName = $this->User->Name;
+
+ $newProject->Name = $this->projectName->Text;
+ $newProject->CompletionDate = $this->completionDate->TimeStamp;
+ $newProject->Description = $this->description->Text;
+ $newProject->EstimateDuration = floatval($this->estimateHours->Text);
+ $newProject->ManagerUserName = $this->manager->SelectedValue;
+
+ if($this->currentProject)
+ $projectDao->updateProject($newProject);
+ else
+ $projectDao->addNewProject($newProject);
+
+ $this->updateProjectMembers($newProject->ID);
+
+ $url = $this->Service->constructUrl('TimeTracker.ProjectDetails',
+ array('ProjectID'=> $newProject->ID));
+
+ $this->Response->redirect($url);
+ }
+
+ protected function updateProjectMembers($projectID)
+ {
+ $active = $this->getViewState('ActiveConsultants');
+ $projectDao = $this->getProjectDao();
+ foreach($this->members->Items as $item)
+ {
+ if($item->Selected)
+ {
+ if(!in_array($item->Value, $active))
+ $projectDao->addUserToProject($projectID, $item->Value);
+ }
+ else
+ {
+ if(in_array($item->Value, $active))
+ $projectDao->removeUserFromProject($projectID, $item->Value);
+ }
+ }
+ }
+
+ public function deleteButton_clicked($sender, $param)
+ {
+ if($project = $this->getCurrentProject())
+ {
+ $this->getProjectDao()->deleteProject($project->ID);
+ $url = $this->Service->constructUrl('TimeTracker.ProjectList');
+ $this->Response->redirect($url);
+ }
+ }
+
+ public function copyButton_clicked($sender, $param)
+ {
+ $project = $this->projectList->SelectedValue;
+ $categoryDao = $this->getCategoryDao();
+ $categories = $categoryDao->getCategoriesByProjectID($project);
+ $currentProject = $this->getCurrentProject();
+ foreach($categories as $cat)
+ {
+ $cat->ProjectID = $currentProject->ID;
+ $categoryDao->addNewCategory($cat);
+ }
+ $this->categories->showCategories();
+ }
+}
+
?> \ No newline at end of file
diff --git a/demos/time-tracker/protected/pages/TimeTracker/ProjectList.php b/demos/time-tracker/protected/pages/TimeTracker/ProjectList.php
index 4e3ac485..6ea6afe1 100644
--- a/demos/time-tracker/protected/pages/TimeTracker/ProjectList.php
+++ b/demos/time-tracker/protected/pages/TimeTracker/ProjectList.php
@@ -1,34 +1,34 @@
-<?php
-
-class ProjectList extends TPage
-{
- protected function showProjects($sort='', $order='')
- {
- $dao = $this->Application->Modules['daos']->getDao('ProjectDao');
- $this->projectList->DataSource = $dao->getAllProjects($sort, $order);
- $this->projectList->dataBind();
- }
-
- protected function getSortOrdering($sort)
- {
- $ordering = $this->getViewState('SortOrder', array());
- $order = isset($ordering[$sort]) ? $ordering[$sort] : 'DESC';
- $ordering[$sort] = $order == 'DESC' ? 'ASC' : 'DESC';
- $this->setViewState('SortOrder', $ordering);
- return $ordering[$sort];
- }
-
- protected function sortProjects($sender, $param)
- {
- $sort = $param->SortExpression;
- $this->showProjects($sort, $this->getSortOrdering($sort));
- }
-
- public function onLoad($param)
- {
- if(!$this->IsPostBack)
- $this->showProjects();
- }
-}
-
+<?php
+
+class ProjectList extends TPage
+{
+ protected function showProjects($sort='', $order='')
+ {
+ $dao = $this->Application->Modules['daos']->getDao('ProjectDao');
+ $this->projectList->DataSource = $dao->getAllProjects($sort, $order);
+ $this->projectList->dataBind();
+ }
+
+ protected function getSortOrdering($sort)
+ {
+ $ordering = $this->getViewState('SortOrder', array());
+ $order = isset($ordering[$sort]) ? $ordering[$sort] : 'DESC';
+ $ordering[$sort] = $order == 'DESC' ? 'ASC' : 'DESC';
+ $this->setViewState('SortOrder', $ordering);
+ return $ordering[$sort];
+ }
+
+ protected function sortProjects($sender, $param)
+ {
+ $sort = $param->SortExpression;
+ $this->showProjects($sort, $this->getSortOrdering($sort));
+ }
+
+ public function onLoad($param)
+ {
+ if(!$this->IsPostBack)
+ $this->showProjects();
+ }
+}
+
?> \ No newline at end of file
diff --git a/demos/time-tracker/protected/pages/TimeTracker/ReportProject.php b/demos/time-tracker/protected/pages/TimeTracker/ReportProject.php
index fcb1c865..6ce849b9 100644
--- a/demos/time-tracker/protected/pages/TimeTracker/ReportProject.php
+++ b/demos/time-tracker/protected/pages/TimeTracker/ReportProject.php
@@ -1,53 +1,53 @@
-<?php
-
-class ReportProject extends TPage
-{
- protected function getProjects()
- {
- $projectDao = $this->Application->Modules['daos']->getDao('ProjectDao');
- $projects = array();
- foreach($projectDao->getAllProjects() as $project)
- $projects[$project->ID] = $project->Name;
- return $projects;
- }
-
- public function onLoad($param)
- {
- if(!$this->IsPostBack)
- {
- $this->projectList->DataSource = $this->getProjects();
- $this->dataBind();
- }
- }
-
- public function generateReport_Clicked($sender, $param)
- {
- if(count($this->projectList->SelectedValues) > 0)
- $this->showReport();
- }
-
- protected function showReport()
- {
- $reportDao = $this->Application->Modules['daos']->getDao('ReportDao');
- $reports = $reportDao->getTimeReportsByProjectIDs($this->projectList->SelectedValues);
- $this->views->ActiveViewIndex = 1;
- $this->projects->DataSource = $reports;
- $this->projects->dataBind();
- }
-
- public function project_itemCreated($sender, $param)
- {
- $item = $param->Item;
- if($item->ItemType==='Item' || $item->ItemType==='AlternatingItem')
- $item->category->DataSource = $item->DataItem->Categories;
- }
-
- public function category_itemCreated($sender, $param)
- {
- $item = $param->Item;
- if($item->ItemType==='Item' || $item->ItemType==='AlternatingItem')
- $item->members->DataSource = $item->DataItem->members;
- }
-}
-
+<?php
+
+class ReportProject extends TPage
+{
+ protected function getProjects()
+ {
+ $projectDao = $this->Application->Modules['daos']->getDao('ProjectDao');
+ $projects = array();
+ foreach($projectDao->getAllProjects() as $project)
+ $projects[$project->ID] = $project->Name;
+ return $projects;
+ }
+
+ public function onLoad($param)
+ {
+ if(!$this->IsPostBack)
+ {
+ $this->projectList->DataSource = $this->getProjects();
+ $this->dataBind();
+ }
+ }
+
+ public function generateReport_Clicked($sender, $param)
+ {
+ if(count($this->projectList->SelectedValues) > 0)
+ $this->showReport();
+ }
+
+ protected function showReport()
+ {
+ $reportDao = $this->Application->Modules['daos']->getDao('ReportDao');
+ $reports = $reportDao->getTimeReportsByProjectIDs($this->projectList->SelectedValues);
+ $this->views->ActiveViewIndex = 1;
+ $this->projects->DataSource = $reports;
+ $this->projects->dataBind();
+ }
+
+ public function project_itemCreated($sender, $param)
+ {
+ $item = $param->Item;
+ if($item->ItemType==='Item' || $item->ItemType==='AlternatingItem')
+ $item->category->DataSource = $item->DataItem->Categories;
+ }
+
+ public function category_itemCreated($sender, $param)
+ {
+ $item = $param->Item;
+ if($item->ItemType==='Item' || $item->ItemType==='AlternatingItem')
+ $item->members->DataSource = $item->DataItem->members;
+ }
+}
+
?> \ No newline at end of file
diff --git a/demos/time-tracker/protected/pages/TimeTracker/ReportResource.php b/demos/time-tracker/protected/pages/TimeTracker/ReportResource.php
index 65283417..26644bc9 100644
--- a/demos/time-tracker/protected/pages/TimeTracker/ReportResource.php
+++ b/demos/time-tracker/protected/pages/TimeTracker/ReportResource.php
@@ -1,71 +1,71 @@
-<?php
-
-class ReportResource extends TPage
-{
- protected function getProjects()
- {
- $projectDao = $this->Application->Modules['daos']->getDao('ProjectDao');
- $projects = array();
- foreach($projectDao->getAllProjects() as $project)
- $projects[$project->ID] = $project->Name;
- return $projects;
- }
-
- protected function getUsers()
- {
- $dao = $this->Application->Modules['daos']->getDao('UserDao');
- $users = array();
- foreach($dao->getAllUsers() as $user)
- {
- $users[$user->Name] = $user->Name;
- }
- return $users;
- }
-
- public function onLoad($param)
- {
- if(!$this->IsPostBack)
- {
- $this->projectList->DataSource = $this->getProjects();
- $this->resourceList->DataSource = $this->getUsers();
- $this->dataBind();
- }
- }
-
- public function generateReport_Clicked($sender, $param)
- {
- if(count($this->projectList->SelectedValues) > 0
- && count($this->resourceList->SelectedValues) >0)
- {
- $this->showReport();
- }
- }
-
- protected function showReport()
- {
- $this->views->ActiveViewIndex = 1;
- $reportDao = $this->Application->Modules['daos']->getDao('ReportDao');
- $projects = $this->projectList->SelectedValues;
- $users = $this->resourceList->SelectedValues;
- $start = $this->dateFrom->TimeStamp;
- $end = $this->dateTo->TimeStamp;
-
- $report = $reportDao->getUserProjectTimeReports($users, $projects, $start, $end);
-
- $this->resource_report->DataSource = $report;
- $this->resource_report->dataBind();
- }
-
- public function resource_report_itemCreated($sender, $param)
- {
- $item = $param->Item;
- if($item->ItemType==='Item' || $item->ItemType==='AlternatingItem')
- {
- if(count($item->DataItem->Projects) > 0 &&
- $item->DataItem->Projects[0]->ProjectName !== null)
- $item->time_entries->DataSource = $item->DataItem->Projects;
- }
- }
-}
-
+<?php
+
+class ReportResource extends TPage
+{
+ protected function getProjects()
+ {
+ $projectDao = $this->Application->Modules['daos']->getDao('ProjectDao');
+ $projects = array();
+ foreach($projectDao->getAllProjects() as $project)
+ $projects[$project->ID] = $project->Name;
+ return $projects;
+ }
+
+ protected function getUsers()
+ {
+ $dao = $this->Application->Modules['daos']->getDao('UserDao');
+ $users = array();
+ foreach($dao->getAllUsers() as $user)
+ {
+ $users[$user->Name] = $user->Name;
+ }
+ return $users;
+ }
+
+ public function onLoad($param)
+ {
+ if(!$this->IsPostBack)
+ {
+ $this->projectList->DataSource = $this->getProjects();
+ $this->resourceList->DataSource = $this->getUsers();
+ $this->dataBind();
+ }
+ }
+
+ public function generateReport_Clicked($sender, $param)
+ {
+ if(count($this->projectList->SelectedValues) > 0
+ && count($this->resourceList->SelectedValues) >0)
+ {
+ $this->showReport();
+ }
+ }
+
+ protected function showReport()
+ {
+ $this->views->ActiveViewIndex = 1;
+ $reportDao = $this->Application->Modules['daos']->getDao('ReportDao');
+ $projects = $this->projectList->SelectedValues;
+ $users = $this->resourceList->SelectedValues;
+ $start = $this->dateFrom->TimeStamp;
+ $end = $this->dateTo->TimeStamp;
+
+ $report = $reportDao->getUserProjectTimeReports($users, $projects, $start, $end);
+
+ $this->resource_report->DataSource = $report;
+ $this->resource_report->dataBind();
+ }
+
+ public function resource_report_itemCreated($sender, $param)
+ {
+ $item = $param->Item;
+ if($item->ItemType==='Item' || $item->ItemType==='AlternatingItem')
+ {
+ if(count($item->DataItem->Projects) > 0 &&
+ $item->DataItem->Projects[0]->ProjectName !== null)
+ $item->time_entries->DataSource = $item->DataItem->Projects;
+ }
+ }
+}
+
?> \ No newline at end of file
diff --git a/demos/time-tracker/protected/pages/TimeTracker/SiteMap.php b/demos/time-tracker/protected/pages/TimeTracker/SiteMap.php
index dde4b44d..cb923178 100644
--- a/demos/time-tracker/protected/pages/TimeTracker/SiteMap.php
+++ b/demos/time-tracker/protected/pages/TimeTracker/SiteMap.php
@@ -1,57 +1,57 @@
-<?php
-/**
- * SiteMap template 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 $Id$
- * @package Demos
- */
-
-/**
- * SiteMap menu is rendered depending on user roles.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package Demos
- * @since 3.1
- */
-class SiteMap extends TTemplateControl
-{
- /**
- * Sets the active menu item using css class.
- */
- public function onPreRender($param)
- {
- parent::onPreRender($param);
-
- $page = explode('.',$this->Request->ServiceParameter);
- $active = null;
- switch($page[count($page)-1])
- {
- case 'ProjectList':
- case 'ProjectDetails':
- $active = $this->ProjectMenu;
- break;
- case 'UserList':
- case 'UserCreate':
- $active = $this->AdminMenu;
- break;
- case 'ReportProject':
- case 'ReportResource':
- $active = $this->ReportMenu;
- break;
- default:
- $active = $this->LogMenu;
- break;
- }
-
- //add 'active' string to place holder body.
- if(!is_null($active))
- $active->Controls[] = 'active';
- }
-}
-
+<?php
+/**
+ * SiteMap template 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 $Id$
+ * @package Demos
+ */
+
+/**
+ * SiteMap menu is rendered depending on user roles.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package Demos
+ * @since 3.1
+ */
+class SiteMap extends TTemplateControl
+{
+ /**
+ * Sets the active menu item using css class.
+ */
+ public function onPreRender($param)
+ {
+ parent::onPreRender($param);
+
+ $page = explode('.',$this->Request->ServiceParameter);
+ $active = null;
+ switch($page[count($page)-1])
+ {
+ case 'ProjectList':
+ case 'ProjectDetails':
+ $active = $this->ProjectMenu;
+ break;
+ case 'UserList':
+ case 'UserCreate':
+ $active = $this->AdminMenu;
+ break;
+ case 'ReportProject':
+ case 'ReportResource':
+ $active = $this->ReportMenu;
+ break;
+ default:
+ $active = $this->LogMenu;
+ break;
+ }
+
+ //add 'active' string to place holder body.
+ if(!is_null($active))
+ $active->Controls[] = 'active';
+ }
+}
+
?> \ No newline at end of file
diff --git a/demos/time-tracker/protected/pages/TimeTracker/TimeEntryList.php b/demos/time-tracker/protected/pages/TimeTracker/TimeEntryList.php
index ee3f4bb2..0730505f 100644
--- a/demos/time-tracker/protected/pages/TimeTracker/TimeEntryList.php
+++ b/demos/time-tracker/protected/pages/TimeTracker/TimeEntryList.php
@@ -1,89 +1,89 @@
-<?php
-
-class TimeEntryList extends TTemplateControl
-{
- protected function getTimeEntryDao()
- {
- return $this->Application->Modules['daos']->getDao('TimeEntryDao');
- }
-
- protected function getCategoryDao()
- {
- return $this->Application->Modules['daos']->getDao('CategoryDao');
- }
-
- public function setProjectEntry($userID,$projectID)
- {
- $this->setViewState('ProjectEntry', array($userID,$projectID));
- }
-
- protected function getCategories()
- {
- $project = $this->getViewState('ProjectEntry');
- foreach($this->getCategoryDao()->getCategoriesByProjectID($project[1]) as $cat)
- {
- $categories[$cat->ID] = $cat->Name;
- }
- return $categories;
- }
-
- protected function showEntryList()
- {
- $project = $this->getViewState('ProjectEntry');
- $list = $this->getTimeEntryDao()->getTimeEntriesInProject($project[0], $project[1]);
- $this->entries->DataSource = $list;
- $this->entries->dataBind();
- }
-
- public function refreshEntryList()
- {
- $this->entries->EditItemIndex=-1;
- $this->showEntryList();
- }
-
- public function editEntryItem($sender, $param)
- {
- $this->entries->EditItemIndex=$param->Item->ItemIndex;
- $this->showEntryList();
- }
-
- public function deleteEntryItem($sender, $param)
- {
- $id = $this->entries->DataKeys[$param->Item->ItemIndex];
- $this->getTimeEntryDao()->deleteTimeEntry($id);
- $this->refreshEntryList();
- }
-
- public function updateEntryItem($sender, $param)
- {
- if(!$this->Page->IsValid)
- return;
-
- $item = $param->Item;
-
- $id = $this->entries->DataKeys[$param->Item->ItemIndex];
-
- $entry = $this->getTimeEntryDao()->getTimeEntryByID($id);
- $category = new CategoryRecord;
- $category->ID = $param->Item->category->SelectedValue;
- $entry->Category = $category;
- $entry->Description = $param->Item->description->Text;
- $entry->Duration = floatval($param->Item->hours->Text);
- $entry->ReportDate = $param->Item->day->TimeStamp;
-
- $this->getTimeEntryDao()->updateTimeEntry($entry);
- $this->refreshEntryList();
- }
-
- public function EntryItemCreated($sender, $param)
- {
- if($param->Item->ItemType == 'EditItem' && $param->Item->DataItem)
- {
- $param->Item->category->DataSource = $this->getCategories();
- $param->Item->category->dataBind();
- $param->Item->category->SelectedValue = $param->Item->DataItem->Category->ID;
- }
- }
-}
-
+<?php
+
+class TimeEntryList extends TTemplateControl
+{
+ protected function getTimeEntryDao()
+ {
+ return $this->Application->Modules['daos']->getDao('TimeEntryDao');
+ }
+
+ protected function getCategoryDao()
+ {
+ return $this->Application->Modules['daos']->getDao('CategoryDao');
+ }
+
+ public function setProjectEntry($userID,$projectID)
+ {
+ $this->setViewState('ProjectEntry', array($userID,$projectID));
+ }
+
+ protected function getCategories()
+ {
+ $project = $this->getViewState('ProjectEntry');
+ foreach($this->getCategoryDao()->getCategoriesByProjectID($project[1]) as $cat)
+ {
+ $categories[$cat->ID] = $cat->Name;
+ }
+ return $categories;
+ }
+
+ protected function showEntryList()
+ {
+ $project = $this->getViewState('ProjectEntry');
+ $list = $this->getTimeEntryDao()->getTimeEntriesInProject($project[0], $project[1]);
+ $this->entries->DataSource = $list;
+ $this->entries->dataBind();
+ }
+
+ public function refreshEntryList()
+ {
+ $this->entries->EditItemIndex=-1;
+ $this->showEntryList();
+ }
+
+ public function editEntryItem($sender, $param)
+ {
+ $this->entries->EditItemIndex=$param->Item->ItemIndex;
+ $this->showEntryList();
+ }
+
+ public function deleteEntryItem($sender, $param)
+ {
+ $id = $this->entries->DataKeys[$param->Item->ItemIndex];
+ $this->getTimeEntryDao()->deleteTimeEntry($id);
+ $this->refreshEntryList();
+ }
+
+ public function updateEntryItem($sender, $param)
+ {
+ if(!$this->Page->IsValid)
+ return;
+
+ $item = $param->Item;
+
+ $id = $this->entries->DataKeys[$param->Item->ItemIndex];
+
+ $entry = $this->getTimeEntryDao()->getTimeEntryByID($id);
+ $category = new CategoryRecord;
+ $category->ID = $param->Item->category->SelectedValue;
+ $entry->Category = $category;
+ $entry->Description = $param->Item->description->Text;
+ $entry->Duration = floatval($param->Item->hours->Text);
+ $entry->ReportDate = $param->Item->day->TimeStamp;
+
+ $this->getTimeEntryDao()->updateTimeEntry($entry);
+ $this->refreshEntryList();
+ }
+
+ public function EntryItemCreated($sender, $param)
+ {
+ if($param->Item->ItemType == 'EditItem' && $param->Item->DataItem)
+ {
+ $param->Item->category->DataSource = $this->getCategories();
+ $param->Item->category->dataBind();
+ $param->Item->category->SelectedValue = $param->Item->DataItem->Category->ID;
+ }
+ }
+}
+
?> \ 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 8ee077ac..eddb87cb 100644
--- a/demos/time-tracker/protected/pages/TimeTracker/UserCreate.php
+++ b/demos/time-tracker/protected/pages/TimeTracker/UserCreate.php
@@ -1,112 +1,112 @@
-<?php
-/**
- * UserCreate page 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 $Id$
- * @package Demos
- */
-
-/**
- * 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 <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package Demos
- * @since 3.1
- */
-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.
- * @param TServerValidateEventParameter validation parameters.
- */
- public function checkUsername($sender, $param)
- {
- $userDao = $this->Application->Modules['daos']->getDao('UserDao');
- if($userDao->usernameExists($this->username->Text))
- {
- $param->IsValid = false;
- $sender->ErrorMessage =
- "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;
- }
- }
- }
-
- /**
- * Create a new user if all data entered are valid.
- * The default user roles are obtained from "config.xml". The new user
- * details is saved to the database and the new credentials are used as the
- * application user. The user is redirected to the requested page.
- * @param TControl button control that created the event.
- * @param TEventParameter event parameters.
- */
- public function createNewUser($sender, $param)
- {
- if($this->IsValid)
- {
- $newUser = new TimeTrackerUser($this->User->Manager);
- $newUser->EmailAddress = $this->email->Text;
- $newUser->Name = $this->username->Text;
- $newUser->IsGuest = false;
- $newUser->Roles = $this->role->SelectedValue;
-
- //save the user
- $userDao = $this->Application->Modules['daos']->getDao('UserDao');
- $userDao->addNewUser($newUser, $this->password->Text);
-
- //update the user credentials if not admin
- if(!$this->User->isInRole('admin'))
- {
- $auth = $this->Application->getModule('auth');
- $auth->updateCredential($newUser);
- }
- }
- }
-
- /**
- * Continue with requested page.
- */
- public function wizardCompleted($sender, $param)
- {
- //return to requested page
- $auth = $this->Application->getModule('auth');
- $this->Response->redirect($auth->getReturnUrl());
- }
-}
-
+<?php
+/**
+ * UserCreate page 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 $Id$
+ * @package Demos
+ */
+
+/**
+ * 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 <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package Demos
+ * @since 3.1
+ */
+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.
+ * @param TServerValidateEventParameter validation parameters.
+ */
+ public function checkUsername($sender, $param)
+ {
+ $userDao = $this->Application->Modules['daos']->getDao('UserDao');
+ if($userDao->usernameExists($this->username->Text))
+ {
+ $param->IsValid = false;
+ $sender->ErrorMessage =
+ "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;
+ }
+ }
+ }
+
+ /**
+ * Create a new user if all data entered are valid.
+ * The default user roles are obtained from "config.xml". The new user
+ * details is saved to the database and the new credentials are used as the
+ * application user. The user is redirected to the requested page.
+ * @param TControl button control that created the event.
+ * @param TEventParameter event parameters.
+ */
+ public function createNewUser($sender, $param)
+ {
+ if($this->IsValid)
+ {
+ $newUser = new TimeTrackerUser($this->User->Manager);
+ $newUser->EmailAddress = $this->email->Text;
+ $newUser->Name = $this->username->Text;
+ $newUser->IsGuest = false;
+ $newUser->Roles = $this->role->SelectedValue;
+
+ //save the user
+ $userDao = $this->Application->Modules['daos']->getDao('UserDao');
+ $userDao->addNewUser($newUser, $this->password->Text);
+
+ //update the user credentials if not admin
+ if(!$this->User->isInRole('admin'))
+ {
+ $auth = $this->Application->getModule('auth');
+ $auth->updateCredential($newUser);
+ }
+ }
+ }
+
+ /**
+ * 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.php b/demos/time-tracker/protected/pages/TimeTracker/UserList.php
index 22974d29..ad35a758 100644
--- a/demos/time-tracker/protected/pages/TimeTracker/UserList.php
+++ b/demos/time-tracker/protected/pages/TimeTracker/UserList.php
@@ -1,34 +1,34 @@
-<?php
-/**
- * UserList page 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 $Id$
- * @package Demos
- */
-
-/**
- * List all users in a repeater.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Id$
- * @package Demos
- * @since 3.1
- */
-class UserList extends TPage
-{
- /**
- * Load all the users and display them in a repeater.
- */
- function onLoad($param)
- {
- $userDao = $this->Application->Modules['daos']->getDao('UserDao');
- $this->list->DataSource = $userDao->getAllUsers();
- $this->list->dataBind();
- }
-}
-
+<?php
+/**
+ * UserList page 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 $Id$
+ * @package Demos
+ */
+
+/**
+ * List all users in a repeater.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package Demos
+ * @since 3.1
+ */
+class UserList extends TPage
+{
+ /**
+ * Load all the users and display them in a repeater.
+ */
+ function onLoad($param)
+ {
+ $userDao = $this->Application->Modules['daos']->getDao('UserDao');
+ $this->list->DataSource = $userDao->getAllUsers();
+ $this->list->dataBind();
+ }
+}
+
?> \ No newline at end of file
diff --git a/demos/time-tracker/tests/functional.php b/demos/time-tracker/tests/functional.php
index 888b29db..00790199 100644
--- a/demos/time-tracker/tests/functional.php
+++ b/demos/time-tracker/tests/functional.php
@@ -1,10 +1,10 @@
-<?php
-
-include_once '../../../tests/test_tools/functional_tests.php';
-
-$test_cases = dirname(__FILE__)."/functional";
-
-$tester=new PradoFunctionalTester($test_cases);
-$tester->run(new SimpleReporter());
-
+<?php
+
+include_once '../../../tests/test_tools/functional_tests.php';
+
+$test_cases = dirname(__FILE__)."/functional";
+
+$tester=new PradoFunctionalTester($test_cases);
+$tester->run(new SimpleReporter());
+
?> \ No newline at end of file
diff --git a/demos/time-tracker/tests/functional/HelloPradoTestCase.php b/demos/time-tracker/tests/functional/HelloPradoTestCase.php
index b9e4f1e3..13ee9343 100644
--- a/demos/time-tracker/tests/functional/HelloPradoTestCase.php
+++ b/demos/time-tracker/tests/functional/HelloPradoTestCase.php
@@ -1,14 +1,14 @@
-<?php
-
-//web testing
-class HelloPradoTestCase extends SeleniumTestCase
-{
- function testIndexPage()
- {
- $this->open('../index.php');
- $this->assertTextPresent('Welcome to Prado!');
- //add more test assertions...
- }
-}
-
+<?php
+
+//web testing
+class HelloPradoTestCase extends SeleniumTestCase
+{
+ function testIndexPage()
+ {
+ $this->open('../index.php');
+ $this->assertTextPresent('Welcome to Prado!');
+ //add more test assertions...
+ }
+}
+
?> \ No newline at end of file
diff --git a/demos/time-tracker/tests/unit.php b/demos/time-tracker/tests/unit.php
index 20d56432..7961d4f2 100644
--- a/demos/time-tracker/tests/unit.php
+++ b/demos/time-tracker/tests/unit.php
@@ -1,11 +1,11 @@
-<?php
-
-include_once '../../../tests/test_tools/unit_tests.php';
-
-$app_directory = "../protected";
-$test_cases = dirname(__FILE__)."/unit";
-
-$tester = new PradoUnitTester($test_cases, $app_directory);
-$tester->run(new HtmlReporter());
-
+<?php
+
+include_once '../../../tests/test_tools/unit_tests.php';
+
+$app_directory = "../protected";
+$test_cases = dirname(__FILE__)."/unit";
+
+$tester = new PradoUnitTester($test_cases, $app_directory);
+$tester->run(new HtmlReporter());
+
?> \ No newline at end of file
diff --git a/demos/time-tracker/tests/unit/BaseTestCase.php b/demos/time-tracker/tests/unit/BaseTestCase.php
index d72cbc5c..10df400f 100644
--- a/demos/time-tracker/tests/unit/BaseTestCase.php
+++ b/demos/time-tracker/tests/unit/BaseTestCase.php
@@ -1,64 +1,64 @@
-<?php
-
-
-Prado::using('Application.App_Code.Dao.*');
-
-class BaseTestCase extends UnitTestCase
-{
- protected $sqlmap;
-
- function setup()
- {
- $app = Prado::getApplication();
- $this->sqlmap = $app->getModule('daos')->getClient();
- }
-
-
- function flushDatabase()
- {
- $conn = $this->sqlmap->getDbConnection();
- $find = 'sqlite:protected';
- if(is_int(strpos($conn->getConnectionString(),$find)))
- $conn->ConnectionString = str_replace($find, 'sqlite:../protected', $conn->ConnectionString);
- $conn->setActive(false);
- $conn->setActive(true);
- switch(strtolower($conn->getDriverName()))
- {
- case 'mysql':
- return $this->flushMySQLDatabase();
- case 'sqlite':
- return $this->flushSQLiteDatabase();
- }
- }
-
- function flushSQLiteDatabase()
- {
- $conn = $this->sqlmap->getDbConnection();
- $file = str_replace('sqlite:','',$conn->getConnectionString());
- $backup = $file.'.bak';
- copy($backup, $file);
- }
-
- function flushMySQLDatabase()
- {
- $conn = $this->sqlmap->getDbConnection();
- $file = Prado::getPathOfNamespace('Application.App_Data.MySQL4.mysql-reset','.sql');
- if(is_file($file))
- $this->runScript($conn, $file);
- else
- throw new Exception('unable to find script file '.$file);
- }
-
- protected function runScript($connection, $script)
- {
- $sql = file_get_contents($script);
- $lines = explode(';', $sql);
- foreach($lines as $line)
- {
- $line = trim($line);
- if(strlen($line) > 0)
- $connection->createCommand($line)->execute();
- }
- }
-}
+<?php
+
+
+Prado::using('Application.App_Code.Dao.*');
+
+class BaseTestCase extends UnitTestCase
+{
+ protected $sqlmap;
+
+ function setup()
+ {
+ $app = Prado::getApplication();
+ $this->sqlmap = $app->getModule('daos')->getClient();
+ }
+
+
+ function flushDatabase()
+ {
+ $conn = $this->sqlmap->getDbConnection();
+ $find = 'sqlite:protected';
+ if(is_int(strpos($conn->getConnectionString(),$find)))
+ $conn->ConnectionString = str_replace($find, 'sqlite:../protected', $conn->ConnectionString);
+ $conn->setActive(false);
+ $conn->setActive(true);
+ switch(strtolower($conn->getDriverName()))
+ {
+ case 'mysql':
+ return $this->flushMySQLDatabase();
+ case 'sqlite':
+ return $this->flushSQLiteDatabase();
+ }
+ }
+
+ function flushSQLiteDatabase()
+ {
+ $conn = $this->sqlmap->getDbConnection();
+ $file = str_replace('sqlite:','',$conn->getConnectionString());
+ $backup = $file.'.bak';
+ copy($backup, $file);
+ }
+
+ function flushMySQLDatabase()
+ {
+ $conn = $this->sqlmap->getDbConnection();
+ $file = Prado::getPathOfNamespace('Application.App_Data.MySQL4.mysql-reset','.sql');
+ if(is_file($file))
+ $this->runScript($conn, $file);
+ else
+ throw new Exception('unable to find script file '.$file);
+ }
+
+ protected function runScript($connection, $script)
+ {
+ $sql = file_get_contents($script);
+ $lines = explode(';', $sql);
+ foreach($lines as $line)
+ {
+ $line = trim($line);
+ if(strlen($line) > 0)
+ $connection->createCommand($line)->execute();
+ }
+ }
+}
?> \ No newline at end of file
diff --git a/demos/time-tracker/tests/unit/CategoryDaoTestCase.php b/demos/time-tracker/tests/unit/CategoryDaoTestCase.php
index d47fa7ce..e018b0b0 100644
--- a/demos/time-tracker/tests/unit/CategoryDaoTestCase.php
+++ b/demos/time-tracker/tests/unit/CategoryDaoTestCase.php
@@ -1,201 +1,201 @@
-<?php
-
-require_once(dirname(__FILE__).'/BaseTestCase.php');
-
-class CategoryDaoTestCase extends BaseTestCase
-{
- protected $categoryDao;
- protected $projectDao;
-
- function setup()
- {
- parent::setup();
- $app = Prado::getApplication();
- $this->categoryDao = $app->getModule('daos')->getDao('CategoryDao');
- $this->projectDao = $app->getModule('daos')->getDao('ProjectDao');
- $this->flushDatabase();
- }
-
- function createNewProject()
- {
- $project = new ProjectRecord;
- $project->CreatorUserName = "admin";
- $project->DateCreated = time();
- $project->CompletionDate = strtotime('+1 month');
- $project->Description = 'Test project 1';
- $project->EstimateDuration = 100.5;
- $project->ManagerUserName = 'manager';
- $project->Name = 'Project 1';
-
- return $project;
- }
-
- function createNewProject2()
- {
- $project = new ProjectRecord;
- $project->CreatorUserName = "manager";
- $project->DateCreated = time();
- $project->CompletionDate = strtotime('+1 week');
- $project->Description = 'Test project 2';
- $project->EstimateDuration = 30.5;
- $project->ManagerUserName = 'manager';
- $project->Name = 'Project 2';
-
- return $project;
- }
-
- function createNewCategory()
- {
- $category = new CategoryRecord;
- $category->Name = 'Category 1';
- $category->EstimateDuration = 5.5;
- $category->Abbreviation = 'CAT 1';
-
- return $category;
- }
-
- function createNewCategory2()
- {
- $category = new CategoryRecord;
- $category->Name = 'Category 2';
- $category->EstimateDuration = 1.5;
- $category->Abbreviation = 'CAT2';
-
- return $category;
- }
-
- function createNewCategory3()
- {
- $category = new CategoryRecord;
- $category->Name = 'Category 3';
- $category->EstimateDuration = 2.5;
- $category->Abbreviation = 'CAT3';
-
- return $category;
- }
-
- function create3Categories()
- {
- $project1 = $this->createNewProject();
- $this->projectDao->addNewProject($project1);
-
- $project2 = $this->createNewProject2();
- $this->projectDao->addNewProject($project2);
-
- $category1 = $this->createNewCategory();
- $category1->ProjectID = $project1->ID;
-
- $category2 = $this->createNewCategory2();
- $category2->ProjectID = $project2->ID;
-
- $category3 = $this->createNewCategory3();
- $category3->ProjectID = $project1->ID;
-
- $this->categoryDao->addNewCategory($category1);
- $this->categoryDao->addNewCategory($category2);
- $this->categoryDao->addNewCategory($category3);
-
- return array($category1, $category2, $category3);
- }
-
- function testCreateNewCategory()
- {
- $project = $this->createNewProject();
- $this->projectDao->addNewProject($project);
-
- $category = $this->createNewCategory();
- $category->ProjectID = $project->ID;
-
- $this->categoryDao->addNewCategory($category);
-
- $check = $this->categoryDao->getCategoryByID(1);
-
- $this->assertEqual($category, $check);
- }
-
- function testCreateDuplicateCategory()
- {
- $project = $this->createNewProject();
- $this->projectDao->addNewProject($project);
-
- $category = $this->createNewCategory();
- $category->ProjectID = $project->ID;
-
- $this->categoryDao->addNewCategory($category);
-
- try
- {
- $this->categoryDao->addNewCategory($category);
- $this->pass();
- }
- catch(TSqlMapQueryExecutionException $e)
- {
- $this->fail();
- }
- $check = $this->categoryDao->getCategoryByID(1);
- $this->assertEqual($category, $check);
- }
-
- function testGetAllCategories()
- {
- $added = $this->create3Categories();
-
- $list = $this->categoryDao->getAllCategories();
- $this->assertEqual(count($list), 3);
- $this->assertEqual($added[0], $list[0]);
- $this->assertEqual($added[1], $list[1]);
- $this->assertEqual($added[2], $list[2]);
- }
-
- function testDeleteCategory()
- {
- $added = $this->create3Categories();
-
- $this->categoryDao->deleteCategory(1);
-
- $list = $this->categoryDao->getAllCategories();
-
- $this->assertEqual(count($list), 2);
- $this->assertEqual($added[1], $list[0]);
- $this->assertEqual($added[2], $list[1]);
- }
-
- function testCategoriesInProject()
- {
- $added = $this->create3Categories();
-
- $list = $this->categoryDao->getCategoriesByProjectID(1);
-
- $this->assertEqual(count($list), 2);
- $this->assertEqual($added[0], $list[0]);
- $this->assertEqual($added[2], $list[1]);
- }
-
- function testGetCategoryByCategoryNameandProjectId()
- {
- $added = $this->create3Categories();
- $cat = $this->categoryDao->getCategoryByNameInProject('Category 1', 1);
-
- $this->assertEqual($cat, $added[0]);
- }
-
- function testUpdateCategory()
- {
- $project = $this->createNewProject();
- $this->projectDao->addNewProject($project);
-
- $category = $this->createNewCategory();
- $category->ProjectID = $project->ID;
-
- $this->categoryDao->addNewCategory($category);
-
- $category->Name = "Test 2";
- $this->categoryDao->updateCategory($category);
-
- $check = $this->categoryDao->getCategoryByID($category->ID);
-
- $this->assertEqual($category, $check);
- }
-}
-
+<?php
+
+require_once(dirname(__FILE__).'/BaseTestCase.php');
+
+class CategoryDaoTestCase extends BaseTestCase
+{
+ protected $categoryDao;
+ protected $projectDao;
+
+ function setup()
+ {
+ parent::setup();
+ $app = Prado::getApplication();
+ $this->categoryDao = $app->getModule('daos')->getDao('CategoryDao');
+ $this->projectDao = $app->getModule('daos')->getDao('ProjectDao');
+ $this->flushDatabase();
+ }
+
+ function createNewProject()
+ {
+ $project = new ProjectRecord;
+ $project->CreatorUserName = "admin";
+ $project->DateCreated = time();
+ $project->CompletionDate = strtotime('+1 month');
+ $project->Description = 'Test project 1';
+ $project->EstimateDuration = 100.5;
+ $project->ManagerUserName = 'manager';
+ $project->Name = 'Project 1';
+
+ return $project;
+ }
+
+ function createNewProject2()
+ {
+ $project = new ProjectRecord;
+ $project->CreatorUserName = "manager";
+ $project->DateCreated = time();
+ $project->CompletionDate = strtotime('+1 week');
+ $project->Description = 'Test project 2';
+ $project->EstimateDuration = 30.5;
+ $project->ManagerUserName = 'manager';
+ $project->Name = 'Project 2';
+
+ return $project;
+ }
+
+ function createNewCategory()
+ {
+ $category = new CategoryRecord;
+ $category->Name = 'Category 1';
+ $category->EstimateDuration = 5.5;
+ $category->Abbreviation = 'CAT 1';
+
+ return $category;
+ }
+
+ function createNewCategory2()
+ {
+ $category = new CategoryRecord;
+ $category->Name = 'Category 2';
+ $category->EstimateDuration = 1.5;
+ $category->Abbreviation = 'CAT2';
+
+ return $category;
+ }
+
+ function createNewCategory3()
+ {
+ $category = new CategoryRecord;
+ $category->Name = 'Category 3';
+ $category->EstimateDuration = 2.5;
+ $category->Abbreviation = 'CAT3';
+
+ return $category;
+ }
+
+ function create3Categories()
+ {
+ $project1 = $this->createNewProject();
+ $this->projectDao->addNewProject($project1);
+
+ $project2 = $this->createNewProject2();
+ $this->projectDao->addNewProject($project2);
+
+ $category1 = $this->createNewCategory();
+ $category1->ProjectID = $project1->ID;
+
+ $category2 = $this->createNewCategory2();
+ $category2->ProjectID = $project2->ID;
+
+ $category3 = $this->createNewCategory3();
+ $category3->ProjectID = $project1->ID;
+
+ $this->categoryDao->addNewCategory($category1);
+ $this->categoryDao->addNewCategory($category2);
+ $this->categoryDao->addNewCategory($category3);
+
+ return array($category1, $category2, $category3);
+ }
+
+ function testCreateNewCategory()
+ {
+ $project = $this->createNewProject();
+ $this->projectDao->addNewProject($project);
+
+ $category = $this->createNewCategory();
+ $category->ProjectID = $project->ID;
+
+ $this->categoryDao->addNewCategory($category);
+
+ $check = $this->categoryDao->getCategoryByID(1);
+
+ $this->assertEqual($category, $check);
+ }
+
+ function testCreateDuplicateCategory()
+ {
+ $project = $this->createNewProject();
+ $this->projectDao->addNewProject($project);
+
+ $category = $this->createNewCategory();
+ $category->ProjectID = $project->ID;
+
+ $this->categoryDao->addNewCategory($category);
+
+ try
+ {
+ $this->categoryDao->addNewCategory($category);
+ $this->pass();
+ }
+ catch(TSqlMapQueryExecutionException $e)
+ {
+ $this->fail();
+ }
+ $check = $this->categoryDao->getCategoryByID(1);
+ $this->assertEqual($category, $check);
+ }
+
+ function testGetAllCategories()
+ {
+ $added = $this->create3Categories();
+
+ $list = $this->categoryDao->getAllCategories();
+ $this->assertEqual(count($list), 3);
+ $this->assertEqual($added[0], $list[0]);
+ $this->assertEqual($added[1], $list[1]);
+ $this->assertEqual($added[2], $list[2]);
+ }
+
+ function testDeleteCategory()
+ {
+ $added = $this->create3Categories();
+
+ $this->categoryDao->deleteCategory(1);
+
+ $list = $this->categoryDao->getAllCategories();
+
+ $this->assertEqual(count($list), 2);
+ $this->assertEqual($added[1], $list[0]);
+ $this->assertEqual($added[2], $list[1]);
+ }
+
+ function testCategoriesInProject()
+ {
+ $added = $this->create3Categories();
+
+ $list = $this->categoryDao->getCategoriesByProjectID(1);
+
+ $this->assertEqual(count($list), 2);
+ $this->assertEqual($added[0], $list[0]);
+ $this->assertEqual($added[2], $list[1]);
+ }
+
+ function testGetCategoryByCategoryNameandProjectId()
+ {
+ $added = $this->create3Categories();
+ $cat = $this->categoryDao->getCategoryByNameInProject('Category 1', 1);
+
+ $this->assertEqual($cat, $added[0]);
+ }
+
+ function testUpdateCategory()
+ {
+ $project = $this->createNewProject();
+ $this->projectDao->addNewProject($project);
+
+ $category = $this->createNewCategory();
+ $category->ProjectID = $project->ID;
+
+ $this->categoryDao->addNewCategory($category);
+
+ $category->Name = "Test 2";
+ $this->categoryDao->updateCategory($category);
+
+ $check = $this->categoryDao->getCategoryByID($category->ID);
+
+ $this->assertEqual($category, $check);
+ }
+}
+
?> \ No newline at end of file
diff --git a/demos/time-tracker/tests/unit/ProjectDaoTestCase.php b/demos/time-tracker/tests/unit/ProjectDaoTestCase.php
index 22a01fca..1790f4d0 100644
--- a/demos/time-tracker/tests/unit/ProjectDaoTestCase.php
+++ b/demos/time-tracker/tests/unit/ProjectDaoTestCase.php
@@ -1,200 +1,200 @@
-<?php
-
-require_once(dirname(__FILE__).'/BaseTestCase.php');
-
-class ProjectDaoTestCase extends BaseTestCase
-{
- protected $projectDao;
-
- function setup()
- {
- parent::setup();
- $app = Prado::getApplication();
- $this->projectDao = $app->getModule('daos')->getDao('ProjectDao');
- $this->flushDatabase();
- }
-
-
- function createNewProject()
- {
- $project = new ProjectRecord;
- $project->CreatorUserName = "admin";
- $project->DateCreated = time();
- $project->CompletionDate = strtotime('+1 month');
- $project->Description = 'Test project 1';
- $project->EstimateDuration = 100.5;
- $project->ManagerUserName = 'manager';
- $project->Name = 'Project 1';
-
- return $project;
- }
-
- function createNewProject2()
- {
- $project = new ProjectRecord;
- $project->CreatorUserName = "manager";
- $project->DateCreated = time();
- $project->CompletionDate = strtotime('+1 week');
- $project->Description = 'Test project 2';
- $project->EstimateDuration = 30.5;
- $project->ManagerUserName = 'manager';
- $project->Name = 'Project 2';
-
- return $project;
- }
-
- function createNewProject3()
- {
- $project = new ProjectRecord;
- $project->CreatorUserName = "manager";
- $project->DateCreated = time();
- $project->CompletionDate = strtotime('+1 day');
- $project->Description = 'Test project 3';
- $project->EstimateDuration = 5.0;
- $project->ManagerUserName = 'admin';
- $project->Name = 'Project 3';
-
- return $project;
- }
-
- function add3Projects()
- {
- $project1 = $this->createNewProject();
- $project2 = $this->createNewProject2();
- $project3 = $this->createNewProject3();
-
- $this->projectDao->addNewProject($project1);
- $this->projectDao->addNewProject($project2);
- $this->projectDao->addNewProject($project3);
- return array($project1,$project2,$project3);
- }
-
- function testCreateNewProject()
- {
- $newProject = $this->createNewProject();
- $this->projectDao->addNewProject($newProject);
-
- $check = $this->projectDao->getProjectByID(1);
- $this->assertEqual($newProject, $check);
- }
-
- function testDeleteProject()
- {
- $newProject = $this->createNewProject();
- $this->projectDao->addNewProject($newProject);
-
- $check = $this->projectDao->getProjectByID(1);
- $this->assertEqual($newProject, $check);
-
- $this->projectDao->deleteProject(1);
- $verify = $this->projectDao->getProjectByID(1);
- $this->assertNull($verify);
- }
-
- function testAddUserToProject()
- {
- $project = $this->createNewProject();
- $this->projectDao->addNewProject($project);
-
- $this->projectDao->addUserToProject($project->ID, 'admin');
- $this->projectDao->addUserToProject($project->ID, 'manager');
-
- $members = $this->projectDao->getProjectMembers($project->ID);
-
- $this->assertEqual(count($members), 2);
- $this->assertEqual($members[0], 'admin');
- $this->assertEqual($members[1], 'manager');
- }
-
- function testAddNullUserToProject()
- {
- $project = $this->createNewProject();
- $this->projectDao->addNewProject($project);
- try
- {
- $this->projectDao->addUserToProject($project->ID, 'asd');
- $this->fail();
- }
- catch(TDbException $e)
- {
- $this->pass();
- }
- }
-
- function testGetAllProjects()
- {
- $added = $this->add3Projects();
-
- $projects = $this->projectDao->getAllProjects();
-
- $this->assertEqual(count($projects),3);
- $this->assertEqual($added[0],$projects[0]);
- $this->assertEqual($added[1],$projects[1]);
- $this->assertEqual($added[2],$projects[2]);
- }
-
- function testGetProjectsByManagerName()
- {
- $added = $this->add3Projects();
-
- $projects = $this->projectDao->getProjectsByManagerName('manager');
-
- $this->assertEqual(count($projects),2);
- $this->assertEqual($added[0],$projects[0]);
- $this->assertEqual($added[1],$projects[1]);
- }
-
- function testGetProjectsByUserName()
- {
- $added = $this->add3Projects();
-
- $username = 'consultant';
-
- $this->projectDao->addUserToProject(1, $username);
- $this->projectDao->addUserToProject(3, $username);
-
- $projects = $this->projectDao->getProjectsByUserName($username);
-
- $this->assertEqual(count($projects),2);
- $this->assertEqual($added[0],$projects[0]);
- $this->assertEqual($added[2],$projects[1]);
- }
-
- function testRemoveUserFromProject()
- {
- $added = $this->add3Projects();
- $this->projectDao->addUserToProject(1, 'admin');
- $this->projectDao->addUserToProject(1, 'manager');
- $this->projectDao->addUserToProject(1, 'consultant');
-
- $members = $this->projectDao->getProjectMembers(1);
-
- $this->assertEqual(count($members), 3);
- $this->assertEqual($members[0], 'admin');
- $this->assertEqual($members[2], 'manager');
- $this->assertEqual($members[1], 'consultant');
-
- $this->projectDao->removeUserFromProject(1,'admin');
-
- $list = $this->projectDao->getProjectMembers(1);
-
- $this->assertEqual(count($list), 2);
- $this->assertEqual($list[1], 'manager');
- $this->assertEqual($list[0], 'consultant');
- }
-
- function testUpdateProject()
- {
- $project = $this->createNewProject();
- $this->projectDao->addNewProject($project);
-
- $project->Description = "Project Testing 123";
-
- $this->projectDao->updateProject($project);
-
- $check = $this->projectDao->getProjectByID(1);
- $this->assertEqual($check, $project);
- }
-}
-
+<?php
+
+require_once(dirname(__FILE__).'/BaseTestCase.php');
+
+class ProjectDaoTestCase extends BaseTestCase
+{
+ protected $projectDao;
+
+ function setup()
+ {
+ parent::setup();
+ $app = Prado::getApplication();
+ $this->projectDao = $app->getModule('daos')->getDao('ProjectDao');
+ $this->flushDatabase();
+ }
+
+
+ function createNewProject()
+ {
+ $project = new ProjectRecord;
+ $project->CreatorUserName = "admin";
+ $project->DateCreated = time();
+ $project->CompletionDate = strtotime('+1 month');
+ $project->Description = 'Test project 1';
+ $project->EstimateDuration = 100.5;
+ $project->ManagerUserName = 'manager';
+ $project->Name = 'Project 1';
+
+ return $project;
+ }
+
+ function createNewProject2()
+ {
+ $project = new ProjectRecord;
+ $project->CreatorUserName = "manager";
+ $project->DateCreated = time();
+ $project->CompletionDate = strtotime('+1 week');
+ $project->Description = 'Test project 2';
+ $project->EstimateDuration = 30.5;
+ $project->ManagerUserName = 'manager';
+ $project->Name = 'Project 2';
+
+ return $project;
+ }
+
+ function createNewProject3()
+ {
+ $project = new ProjectRecord;
+ $project->CreatorUserName = "manager";
+ $project->DateCreated = time();
+ $project->CompletionDate = strtotime('+1 day');
+ $project->Description = 'Test project 3';
+ $project->EstimateDuration = 5.0;
+ $project->ManagerUserName = 'admin';
+ $project->Name = 'Project 3';
+
+ return $project;
+ }
+
+ function add3Projects()
+ {
+ $project1 = $this->createNewProject();
+ $project2 = $this->createNewProject2();
+ $project3 = $this->createNewProject3();
+
+ $this->projectDao->addNewProject($project1);
+ $this->projectDao->addNewProject($project2);
+ $this->projectDao->addNewProject($project3);
+ return array($project1,$project2,$project3);
+ }
+
+ function testCreateNewProject()
+ {
+ $newProject = $this->createNewProject();
+ $this->projectDao->addNewProject($newProject);
+
+ $check = $this->projectDao->getProjectByID(1);
+ $this->assertEqual($newProject, $check);
+ }
+
+ function testDeleteProject()
+ {
+ $newProject = $this->createNewProject();
+ $this->projectDao->addNewProject($newProject);
+
+ $check = $this->projectDao->getProjectByID(1);
+ $this->assertEqual($newProject, $check);
+
+ $this->projectDao->deleteProject(1);
+ $verify = $this->projectDao->getProjectByID(1);
+ $this->assertNull($verify);
+ }
+
+ function testAddUserToProject()
+ {
+ $project = $this->createNewProject();
+ $this->projectDao->addNewProject($project);
+
+ $this->projectDao->addUserToProject($project->ID, 'admin');
+ $this->projectDao->addUserToProject($project->ID, 'manager');
+
+ $members = $this->projectDao->getProjectMembers($project->ID);
+
+ $this->assertEqual(count($members), 2);
+ $this->assertEqual($members[0], 'admin');
+ $this->assertEqual($members[1], 'manager');
+ }
+
+ function testAddNullUserToProject()
+ {
+ $project = $this->createNewProject();
+ $this->projectDao->addNewProject($project);
+ try
+ {
+ $this->projectDao->addUserToProject($project->ID, 'asd');
+ $this->fail();
+ }
+ catch(TDbException $e)
+ {
+ $this->pass();
+ }
+ }
+
+ function testGetAllProjects()
+ {
+ $added = $this->add3Projects();
+
+ $projects = $this->projectDao->getAllProjects();
+
+ $this->assertEqual(count($projects),3);
+ $this->assertEqual($added[0],$projects[0]);
+ $this->assertEqual($added[1],$projects[1]);
+ $this->assertEqual($added[2],$projects[2]);
+ }
+
+ function testGetProjectsByManagerName()
+ {
+ $added = $this->add3Projects();
+
+ $projects = $this->projectDao->getProjectsByManagerName('manager');
+
+ $this->assertEqual(count($projects),2);
+ $this->assertEqual($added[0],$projects[0]);
+ $this->assertEqual($added[1],$projects[1]);
+ }
+
+ function testGetProjectsByUserName()
+ {
+ $added = $this->add3Projects();
+
+ $username = 'consultant';
+
+ $this->projectDao->addUserToProject(1, $username);
+ $this->projectDao->addUserToProject(3, $username);
+
+ $projects = $this->projectDao->getProjectsByUserName($username);
+
+ $this->assertEqual(count($projects),2);
+ $this->assertEqual($added[0],$projects[0]);
+ $this->assertEqual($added[2],$projects[1]);
+ }
+
+ function testRemoveUserFromProject()
+ {
+ $added = $this->add3Projects();
+ $this->projectDao->addUserToProject(1, 'admin');
+ $this->projectDao->addUserToProject(1, 'manager');
+ $this->projectDao->addUserToProject(1, 'consultant');
+
+ $members = $this->projectDao->getProjectMembers(1);
+
+ $this->assertEqual(count($members), 3);
+ $this->assertEqual($members[0], 'admin');
+ $this->assertEqual($members[2], 'manager');
+ $this->assertEqual($members[1], 'consultant');
+
+ $this->projectDao->removeUserFromProject(1,'admin');
+
+ $list = $this->projectDao->getProjectMembers(1);
+
+ $this->assertEqual(count($list), 2);
+ $this->assertEqual($list[1], 'manager');
+ $this->assertEqual($list[0], 'consultant');
+ }
+
+ function testUpdateProject()
+ {
+ $project = $this->createNewProject();
+ $this->projectDao->addNewProject($project);
+
+ $project->Description = "Project Testing 123";
+
+ $this->projectDao->updateProject($project);
+
+ $check = $this->projectDao->getProjectByID(1);
+ $this->assertEqual($check, $project);
+ }
+}
+
?> \ No newline at end of file
diff --git a/demos/time-tracker/tests/unit/TimeEntryDaoTestCase.php b/demos/time-tracker/tests/unit/TimeEntryDaoTestCase.php
index 1ce97b3a..cead9fba 100644
--- a/demos/time-tracker/tests/unit/TimeEntryDaoTestCase.php
+++ b/demos/time-tracker/tests/unit/TimeEntryDaoTestCase.php
@@ -1,214 +1,214 @@
-<?php
-
-require_once(dirname(__FILE__).'/BaseTestCase.php');
-
-class TimeEntryDaoTestCase extends BaseTestCase
-{
- protected $entryDao;
- protected $projectDao;
- protected $userDao;
- protected $categoryDao;
- protected $reportDao;
-
- function setup()
- {
- parent::setup();
- $app = Prado::getApplication();
- $this->entryDao = $app->getModule('daos')->getDao('TimeEntryDao');
- $this->projectDao = $app->getModule('daos')->getDao('ProjectDao');
- $this->userDao = $app->getModule('daos')->getDao('UserDao');
- $this->categoryDao = $app->getModule('daos')->getDao('CategoryDao');
- $this->reportDao = $app->getModule('daos')->getDao('ReportDao');
- $this->flushDatabase();
- }
-
- function createNewProject()
- {
- $project = new ProjectRecord;
- $project->CreatorUserName = "admin";
- $project->DateCreated = time();
- $project->CompletionDate = strtotime('+1 month');
- $project->Description = 'Test project 1';
- $project->EstimateDuration = 100.5;
- $project->ManagerUserName = 'manager';
- $project->Name = 'Project 1';
-
- return $project;
- }
-
- function createNewProject2()
- {
- $project = new ProjectRecord;
- $project->CreatorUserName = "manager";
- $project->DateCreated = time();
- $project->CompletionDate = strtotime('+1 week');
- $project->Description = 'Test project 2';
- $project->EstimateDuration = 30.5;
- $project->ManagerUserName = 'manager';
- $project->Name = 'Project 2';
-
- return $project;
- }
-
- function createNewCategory()
- {
- $category = new CategoryRecord;
- $category->Name = 'Category 1';
- $category->EstimateDuration = 5.5;
- $category->Abbreviation = 'CAT 1';
-
- return $category;
- }
-
- function createNewCategory2()
- {
- $category = new CategoryRecord;
- $category->Name = 'Category 2';
- $category->EstimateDuration = 1.5;
- $category->Abbreviation = 'CAT2';
-
- return $category;
- }
-
- function createNewCategory3()
- {
- $category = new CategoryRecord;
- $category->Name = 'Category 3';
- $category->EstimateDuration = 2.5;
- $category->Abbreviation = 'CAT3';
-
- return $category;
- }
-
- function createProjectsAndCategories()
- {
- $project1 = $this->createNewProject();
- $this->projectDao->addNewProject($project1);
-
- $project2 = $this->createNewProject2();
- $this->projectDao->addNewProject($project2);
-
- $category1 = $this->createNewCategory();
- $category1->ProjectID = $project1->ID;
-
- $category2 = $this->createNewCategory2();
- $category2->ProjectID = $project2->ID;
-
- $category3 = $this->createNewCategory3();
- $category3->ProjectID = $project1->ID;
-
- $this->categoryDao->addNewCategory($category1);
- $this->categoryDao->addNewCategory($category2);
- $this->categoryDao->addNewCategory($category3);
-
- return array($project1, $project2, $category1, $category2, $category3);
- }
-
- function assertSameEntry($entry1, $entry2)
- {
- $this->assertEqual($entry1->CreatorUserName, $entry2->CreatorUserName);
- $this->assertEqual($entry1->Description, $entry2->Description);
- $this->assertEqual($entry1->Duration, $entry2->Duration);
- $this->assertEqual($entry1->ID, $entry2->ID);
- $this->assertEqual($entry1->ReportDate, $entry2->ReportDate);
- $this->assertEqual($entry1->Username, $entry2->Username);
- }
-
-
- function createTimeEntry1()
- {
- $added = $this->createProjectsAndCategories();
-
- $entry = new TimeEntryRecord;
- $entry->CreatorUserName = "admin";
- $entry->Category = $added[2];
- $entry->Description = "New work";
- $entry->Duration = 1.5;
- $entry->Project = $added[0];
- $entry->ReportDate = strtotime('-1 day');
- $entry->Username = 'consultant';
-
- return array($entry, $added);
- }
-
- function createTimeEntries2()
- {
- $added = $this->createProjectsAndCategories();
-
- $entry = new TimeEntryRecord;
- $entry->CreatorUserName = "admin";
- $entry->Category = $added[2];
- $entry->Description = "New work";
- $entry->Duration = 1.2;
- $entry->Project = $added[0];
- $entry->ReportDate = strtotime('-10 day');
- $entry->Username = 'consultant';
-
- $entry2 = new TimeEntryRecord;
- $entry2->CreatorUserName = "admin";
- $entry2->Category = $added[4];
- $entry2->Description = "New work 2";
- $entry2->Duration = 5.5;
- $entry2->Project = $added[0];
- $entry2->ReportDate = strtotime('-4 day');
- $entry2->Username = 'consultant';
-
- return array($entry, $entry2, $added);
- }
-
- function testCreateNewTimeEntry()
- {
- $added = $this->createTimeEntry1();
- $entry = $added[0];
- $this->entryDao->addNewTimeEntry($entry);
-
- $check = $this->entryDao->getTimeEntryByID(1);
-
- $this->assertSameEntry($entry, $check);
- }
-
- function testDeleteTimeEntry()
- {
- $this->testCreateNewTimeEntry();
- $this->entryDao->deleteTimeEntry(1);
-
- $check = $this->entryDao->getTimeEntryByID(1);
- $this->assertNull($check);
- }
-
- function testGetEntriesInProject()
- {
- $added = $this->createTimeEntries2();
- $this->entryDao->addNewTimeEntry($added[0]);
- $this->entryDao->addNewTimeEntry($added[1]);
-
- $list = $this->entryDao->getTimeEntriesInProject('consultant', 1);
-
- $this->assertEqual(count($list), 2);
-
- $this->assertSameEntry($list[0], $added[0]);
- $this->assertSameEntry($list[1], $added[1]);
- }
-
- function testUpdateEntry()
- {
- $added = $this->createTimeEntry1();
- $entry = $added[0];
- $this->entryDao->addNewTimeEntry($entry);
-
- $check = $this->entryDao->getTimeEntryByID(1);
-
- $this->assertSameEntry($entry, $check);
-
- $entry->Description = "asdasd";
- $entry->Duration = 200;
-
- $this->entryDao->updateTimeEntry($entry);
-
- $verify = $this->entryDao->getTimeEntryByID(1);
-
- $this->assertSameEntry($entry, $verify);
- }
-}
-
+<?php
+
+require_once(dirname(__FILE__).'/BaseTestCase.php');
+
+class TimeEntryDaoTestCase extends BaseTestCase
+{
+ protected $entryDao;
+ protected $projectDao;
+ protected $userDao;
+ protected $categoryDao;
+ protected $reportDao;
+
+ function setup()
+ {
+ parent::setup();
+ $app = Prado::getApplication();
+ $this->entryDao = $app->getModule('daos')->getDao('TimeEntryDao');
+ $this->projectDao = $app->getModule('daos')->getDao('ProjectDao');
+ $this->userDao = $app->getModule('daos')->getDao('UserDao');
+ $this->categoryDao = $app->getModule('daos')->getDao('CategoryDao');
+ $this->reportDao = $app->getModule('daos')->getDao('ReportDao');
+ $this->flushDatabase();
+ }
+
+ function createNewProject()
+ {
+ $project = new ProjectRecord;
+ $project->CreatorUserName = "admin";
+ $project->DateCreated = time();
+ $project->CompletionDate = strtotime('+1 month');
+ $project->Description = 'Test project 1';
+ $project->EstimateDuration = 100.5;
+ $project->ManagerUserName = 'manager';
+ $project->Name = 'Project 1';
+
+ return $project;
+ }
+
+ function createNewProject2()
+ {
+ $project = new ProjectRecord;
+ $project->CreatorUserName = "manager";
+ $project->DateCreated = time();
+ $project->CompletionDate = strtotime('+1 week');
+ $project->Description = 'Test project 2';
+ $project->EstimateDuration = 30.5;
+ $project->ManagerUserName = 'manager';
+ $project->Name = 'Project 2';
+
+ return $project;
+ }
+
+ function createNewCategory()
+ {
+ $category = new CategoryRecord;
+ $category->Name = 'Category 1';
+ $category->EstimateDuration = 5.5;
+ $category->Abbreviation = 'CAT 1';
+
+ return $category;
+ }
+
+ function createNewCategory2()
+ {
+ $category = new CategoryRecord;
+ $category->Name = 'Category 2';
+ $category->EstimateDuration = 1.5;
+ $category->Abbreviation = 'CAT2';
+
+ return $category;
+ }
+
+ function createNewCategory3()
+ {
+ $category = new CategoryRecord;
+ $category->Name = 'Category 3';
+ $category->EstimateDuration = 2.5;
+ $category->Abbreviation = 'CAT3';
+
+ return $category;
+ }
+
+ function createProjectsAndCategories()
+ {
+ $project1 = $this->createNewProject();
+ $this->projectDao->addNewProject($project1);
+
+ $project2 = $this->createNewProject2();
+ $this->projectDao->addNewProject($project2);
+
+ $category1 = $this->createNewCategory();
+ $category1->ProjectID = $project1->ID;
+
+ $category2 = $this->createNewCategory2();
+ $category2->ProjectID = $project2->ID;
+
+ $category3 = $this->createNewCategory3();
+ $category3->ProjectID = $project1->ID;
+
+ $this->categoryDao->addNewCategory($category1);
+ $this->categoryDao->addNewCategory($category2);
+ $this->categoryDao->addNewCategory($category3);
+
+ return array($project1, $project2, $category1, $category2, $category3);
+ }
+
+ function assertSameEntry($entry1, $entry2)
+ {
+ $this->assertEqual($entry1->CreatorUserName, $entry2->CreatorUserName);
+ $this->assertEqual($entry1->Description, $entry2->Description);
+ $this->assertEqual($entry1->Duration, $entry2->Duration);
+ $this->assertEqual($entry1->ID, $entry2->ID);
+ $this->assertEqual($entry1->ReportDate, $entry2->ReportDate);
+ $this->assertEqual($entry1->Username, $entry2->Username);
+ }
+
+
+ function createTimeEntry1()
+ {
+ $added = $this->createProjectsAndCategories();
+
+ $entry = new TimeEntryRecord;
+ $entry->CreatorUserName = "admin";
+ $entry->Category = $added[2];
+ $entry->Description = "New work";
+ $entry->Duration = 1.5;
+ $entry->Project = $added[0];
+ $entry->ReportDate = strtotime('-1 day');
+ $entry->Username = 'consultant';
+
+ return array($entry, $added);
+ }
+
+ function createTimeEntries2()
+ {
+ $added = $this->createProjectsAndCategories();
+
+ $entry = new TimeEntryRecord;
+ $entry->CreatorUserName = "admin";
+ $entry->Category = $added[2];
+ $entry->Description = "New work";
+ $entry->Duration = 1.2;
+ $entry->Project = $added[0];
+ $entry->ReportDate = strtotime('-10 day');
+ $entry->Username = 'consultant';
+
+ $entry2 = new TimeEntryRecord;
+ $entry2->CreatorUserName = "admin";
+ $entry2->Category = $added[4];
+ $entry2->Description = "New work 2";
+ $entry2->Duration = 5.5;
+ $entry2->Project = $added[0];
+ $entry2->ReportDate = strtotime('-4 day');
+ $entry2->Username = 'consultant';
+
+ return array($entry, $entry2, $added);
+ }
+
+ function testCreateNewTimeEntry()
+ {
+ $added = $this->createTimeEntry1();
+ $entry = $added[0];
+ $this->entryDao->addNewTimeEntry($entry);
+
+ $check = $this->entryDao->getTimeEntryByID(1);
+
+ $this->assertSameEntry($entry, $check);
+ }
+
+ function testDeleteTimeEntry()
+ {
+ $this->testCreateNewTimeEntry();
+ $this->entryDao->deleteTimeEntry(1);
+
+ $check = $this->entryDao->getTimeEntryByID(1);
+ $this->assertNull($check);
+ }
+
+ function testGetEntriesInProject()
+ {
+ $added = $this->createTimeEntries2();
+ $this->entryDao->addNewTimeEntry($added[0]);
+ $this->entryDao->addNewTimeEntry($added[1]);
+
+ $list = $this->entryDao->getTimeEntriesInProject('consultant', 1);
+
+ $this->assertEqual(count($list), 2);
+
+ $this->assertSameEntry($list[0], $added[0]);
+ $this->assertSameEntry($list[1], $added[1]);
+ }
+
+ function testUpdateEntry()
+ {
+ $added = $this->createTimeEntry1();
+ $entry = $added[0];
+ $this->entryDao->addNewTimeEntry($entry);
+
+ $check = $this->entryDao->getTimeEntryByID(1);
+
+ $this->assertSameEntry($entry, $check);
+
+ $entry->Description = "asdasd";
+ $entry->Duration = 200;
+
+ $this->entryDao->updateTimeEntry($entry);
+
+ $verify = $this->entryDao->getTimeEntryByID(1);
+
+ $this->assertSameEntry($entry, $verify);
+ }
+}
+
?> \ No newline at end of file
diff --git a/demos/time-tracker/tests/unit/UserDaoTestCase.php b/demos/time-tracker/tests/unit/UserDaoTestCase.php
index d216dbe6..ce40092e 100644
--- a/demos/time-tracker/tests/unit/UserDaoTestCase.php
+++ b/demos/time-tracker/tests/unit/UserDaoTestCase.php
@@ -1,271 +1,271 @@
-<?php
-
-require_once(dirname(__FILE__).'/BaseTestCase.php');
-
-class UserDaoTestCase extends BaseTestCase
-{
- protected $userDao;
-
- function setup()
- {
- parent::setup();
- $app = Prado::getApplication();
- $this->userDao = $app->getModule('daos')->getDao('UserDao');
- $this->flushDatabase();
- }
-
- function assertIsAdmin($user)
- {
- if(!$user)
- return $this->fail();
- $this->assertEqual($user->getName(), 'admin');
- $this->assertEqual($user->getEmailAddress(), 'admin@pradosoft.com');
- }
-
- function assertSameUser($user1, $user2)
- {
- if(is_null($user1) || is_null($user2))
- return $this->fail();
-
- $this->assertEqual($user1->getName(), $user2->getName());
- $this->assertEqual($user1->getEmailAddress(), $user2->getEmailAddress());
- }
-
- function assertIsAdminRole($user)
- {
- if(is_null($user))
- return $this->fail();
-
- $this->assertTrue($user->isInRole('admin'));
- }
-
- function assertIsManagerRole($user)
- {
- if(is_null($user))
- return $this->fail();
-
- $this->assertTrue($user->isInRole('manager'));
- }
-
- function assertIsConsultantRole($user)
- {
- if(is_null($user))
- return $this->fail();
-
- $this->assertTrue($user->isInRole('consultant'));
- }
-
- function assertNotConsultantRole($user)
- {
- if(is_null($user))
- return $this->fail();
-
- $this->assertFalse($user->isInRole('consultant'));
- }
-
- function testGetUserByName()
- {
- $user = $this->userDao->getUserByName('admin');
- $this->assertNotNull($user);
- $this->assertIsAdmin($user);
- }
-
- function testGetNonExistentUser()
- {
- $user = $this->userDao->getUserByName('none');
- $this->assertNull($user);
- }
-
- function testGetUsers()
- {
- $users = $this->userDao->getAllUsers();
- $this->assertEqual(count($users), 3);
- }
-
- function testUserLogon()
- {
- $success = $this->userDao->validateUser('admin', 'admin');
- $this->assertTrue($success);
- }
-
- function testBadLogin()
- {
- $success = $this->userDao->validateUser('admin', 'hahah');
- $this->assertFalse($success);
- }
-
-
- function testAddNewUser()
- {
- $user = new TimeTrackerUser(new UserManager());
- $user->Name = "user1";
- $user->EmailAddress = 'user1@pradosoft.com';
-
- $this->userDao->addNewUser($user, 'password');
-
- $check = $this->userDao->getUserByName($user->Name);
-
- $this->assertSameUser($check, $user);
- }
-
- function testDeleteUserByName()
- {
- $this->userDao->deleteUserByName('admin');
-
- $admin = $this->userDao->getUserByName('admin');
- $this->assertNull($admin);
-
- $users = $this->userDao->getAllUsers();
- $this->assertEqual(count($users), 2);
- }
-
- function testAutoSignon()
- {
- $user = new TimeTrackerUser(new UserManager());
- $user->Name = "admin";
-
- $token = $this->userDao->createSignonToken($user);
-
- $check = $this->userDao->validateSignon($token);
-
- $this->assertIsAdmin($check);
- }
-
-
- function testBadAutoSignon()
- {
- $user = new TimeTrackerUser(new UserManager());
- $user->Name = "admin";
-
- $token = $this->userDao->createSignonToken($user);
-
- $check = $this->userDao->validateSignon('adasd');
- $this->assertNull($check);
- }
-
- function testAdminRoles()
- {
- $user = $this->userDao->getUserByName('admin');
- $this->assertIsAdminRole($user);
- $this->assertIsManagerRole($user);
- $this->assertIsConsultantRole($user);
- }
-
- function testSetUserRoles()
- {
- $user = new TimeTrackerUser(new UserManager());
- $user->Name = "user1";
- $user->EmailAddress = 'user1@pradosoft.com';
- $user->Roles = array("manager", "consultant");
-
- $this->userDao->addNewUser($user, 'password');
- $check = $this->userDao->getUserByName('user1');
-
- $this->assertIsManagerRole($check);
- $this->assertIsConsultantRole($check);
- }
-
- function testSetUserRoleNoNullUser()
- {
- $user = new TimeTrackerUser(new UserManager());
- $user->Name = "user1";
- $user->EmailAddress = 'user1@pradosoft.com';
- $user->Roles = array("manager", "consultant");
-
- try
- {
- $this->userDao->updateUserRoles($user);
- $this->fail();
- }
- catch(TDbException $e)
- {
- $this->pass();
- }
-
- $check = $this->sqlmap->queryForObject('GetUserByName', 'user1');
- $this->assertNull($check);
- }
-
- function testUpdateUser()
- {
- $user = $this->userDao->getUserByName('admin');
- $user->EmailAddress = 'something@pradosoft.com';
- $user->Roles = array('manager', 'admin');
-
- $this->userDao->updateUser($user);
-
- $check = $this->userDao->getUserByName('admin');
- $this->assertIsAdminRole($check);
- $this->assertIsManagerRole($check);
- $this->assertNotConsultantRole($check);
- }
-
- function testUpdateUserPassword()
- {
- $user = $this->userDao->getUserByName('admin');
- $user->EmailAddress = 'something@pradosoft.com';
- $user->Roles = array('manager', 'admin');
-
- $pass = 'newpasword';
-
- $this->userDao->updateUser($user, $pass);
-
- $success = $this->userDao->validateUser('admin', $pass);
-
- $this->assertTrue($success);
- }
-
- function testClearSignonTokens()
- {
- $user = new TimeTrackerUser(new UserManager());
- $user->Name = "admin";
-
- $token1 = $this->userDao->createSignonToken($user);
- sleep(1);
- $token2 = $this->userDao->createSignonToken($user);
- $this->assertNotEqual($token1, $token2);
-
- $check1 = $this->userDao->validateSignon($token1);
- $check2 = $this->userDao->validateSignon($token2);
-
- $this->assertIsAdmin($check1);
- $this->assertIsAdmin($check2);
-
- $this->userDao->clearSignonTokens($user);
-
- $check3 = $this->userDao->validateSignon($token1);
- $check4 = $this->userDao->validateSignon($token2);
-
- $this->assertNull($check3);
- $this->assertNull($check4);
- }
-
- function testClearAllSigonTokens()
- {
- $user1 = new TimeTrackerUser(new UserManager());
- $user1->Name = "admin";
-
- $user2 = new TimeTrackerUser(new UserManager());
- $user2->Name = "manager";
-
- $token1 = $this->userDao->createSignonToken($user1);
- $token2 = $this->userDao->createSignonToken($user2);
-
- $check1 = $this->userDao->validateSignon($token1);
- $check2 = $this->userDao->validateSignon($token2);
-
- $this->assertIsAdmin($check1);
- $this->assertNotNull($check2);
- $this->assertEqual($check2->Name, $user2->Name);
-
- $this->userDao->clearSignonTokens();
-
- $check3 = $this->userDao->validateSignon($token1);
- $check4 = $this->userDao->validateSignon($token2);
-
- $this->assertNull($check3);
- $this->assertNull($check4);
- }
-}
-
+<?php
+
+require_once(dirname(__FILE__).'/BaseTestCase.php');
+
+class UserDaoTestCase extends BaseTestCase
+{
+ protected $userDao;
+
+ function setup()
+ {
+ parent::setup();
+ $app = Prado::getApplication();
+ $this->userDao = $app->getModule('daos')->getDao('UserDao');
+ $this->flushDatabase();
+ }
+
+ function assertIsAdmin($user)
+ {
+ if(!$user)
+ return $this->fail();
+ $this->assertEqual($user->getName(), 'admin');
+ $this->assertEqual($user->getEmailAddress(), 'admin@pradosoft.com');
+ }
+
+ function assertSameUser($user1, $user2)
+ {
+ if(is_null($user1) || is_null($user2))
+ return $this->fail();
+
+ $this->assertEqual($user1->getName(), $user2->getName());
+ $this->assertEqual($user1->getEmailAddress(), $user2->getEmailAddress());
+ }
+
+ function assertIsAdminRole($user)
+ {
+ if(is_null($user))
+ return $this->fail();
+
+ $this->assertTrue($user->isInRole('admin'));
+ }
+
+ function assertIsManagerRole($user)
+ {
+ if(is_null($user))
+ return $this->fail();
+
+ $this->assertTrue($user->isInRole('manager'));
+ }
+
+ function assertIsConsultantRole($user)
+ {
+ if(is_null($user))
+ return $this->fail();
+
+ $this->assertTrue($user->isInRole('consultant'));
+ }
+
+ function assertNotConsultantRole($user)
+ {
+ if(is_null($user))
+ return $this->fail();
+
+ $this->assertFalse($user->isInRole('consultant'));
+ }
+
+ function testGetUserByName()
+ {
+ $user = $this->userDao->getUserByName('admin');
+ $this->assertNotNull($user);
+ $this->assertIsAdmin($user);
+ }
+
+ function testGetNonExistentUser()
+ {
+ $user = $this->userDao->getUserByName('none');
+ $this->assertNull($user);
+ }
+
+ function testGetUsers()
+ {
+ $users = $this->userDao->getAllUsers();
+ $this->assertEqual(count($users), 3);
+ }
+
+ function testUserLogon()
+ {
+ $success = $this->userDao->validateUser('admin', 'admin');
+ $this->assertTrue($success);
+ }
+
+ function testBadLogin()
+ {
+ $success = $this->userDao->validateUser('admin', 'hahah');
+ $this->assertFalse($success);
+ }
+
+
+ function testAddNewUser()
+ {
+ $user = new TimeTrackerUser(new UserManager());
+ $user->Name = "user1";
+ $user->EmailAddress = 'user1@pradosoft.com';
+
+ $this->userDao->addNewUser($user, 'password');
+
+ $check = $this->userDao->getUserByName($user->Name);
+
+ $this->assertSameUser($check, $user);
+ }
+
+ function testDeleteUserByName()
+ {
+ $this->userDao->deleteUserByName('admin');
+
+ $admin = $this->userDao->getUserByName('admin');
+ $this->assertNull($admin);
+
+ $users = $this->userDao->getAllUsers();
+ $this->assertEqual(count($users), 2);
+ }
+
+ function testAutoSignon()
+ {
+ $user = new TimeTrackerUser(new UserManager());
+ $user->Name = "admin";
+
+ $token = $this->userDao->createSignonToken($user);
+
+ $check = $this->userDao->validateSignon($token);
+
+ $this->assertIsAdmin($check);
+ }
+
+
+ function testBadAutoSignon()
+ {
+ $user = new TimeTrackerUser(new UserManager());
+ $user->Name = "admin";
+
+ $token = $this->userDao->createSignonToken($user);
+
+ $check = $this->userDao->validateSignon('adasd');
+ $this->assertNull($check);
+ }
+
+ function testAdminRoles()
+ {
+ $user = $this->userDao->getUserByName('admin');
+ $this->assertIsAdminRole($user);
+ $this->assertIsManagerRole($user);
+ $this->assertIsConsultantRole($user);
+ }
+
+ function testSetUserRoles()
+ {
+ $user = new TimeTrackerUser(new UserManager());
+ $user->Name = "user1";
+ $user->EmailAddress = 'user1@pradosoft.com';
+ $user->Roles = array("manager", "consultant");
+
+ $this->userDao->addNewUser($user, 'password');
+ $check = $this->userDao->getUserByName('user1');
+
+ $this->assertIsManagerRole($check);
+ $this->assertIsConsultantRole($check);
+ }
+
+ function testSetUserRoleNoNullUser()
+ {
+ $user = new TimeTrackerUser(new UserManager());
+ $user->Name = "user1";
+ $user->EmailAddress = 'user1@pradosoft.com';
+ $user->Roles = array("manager", "consultant");
+
+ try
+ {
+ $this->userDao->updateUserRoles($user);
+ $this->fail();
+ }
+ catch(TDbException $e)
+ {
+ $this->pass();
+ }
+
+ $check = $this->sqlmap->queryForObject('GetUserByName', 'user1');
+ $this->assertNull($check);
+ }
+
+ function testUpdateUser()
+ {
+ $user = $this->userDao->getUserByName('admin');
+ $user->EmailAddress = 'something@pradosoft.com';
+ $user->Roles = array('manager', 'admin');
+
+ $this->userDao->updateUser($user);
+
+ $check = $this->userDao->getUserByName('admin');
+ $this->assertIsAdminRole($check);
+ $this->assertIsManagerRole($check);
+ $this->assertNotConsultantRole($check);
+ }
+
+ function testUpdateUserPassword()
+ {
+ $user = $this->userDao->getUserByName('admin');
+ $user->EmailAddress = 'something@pradosoft.com';
+ $user->Roles = array('manager', 'admin');
+
+ $pass = 'newpasword';
+
+ $this->userDao->updateUser($user, $pass);
+
+ $success = $this->userDao->validateUser('admin', $pass);
+
+ $this->assertTrue($success);
+ }
+
+ function testClearSignonTokens()
+ {
+ $user = new TimeTrackerUser(new UserManager());
+ $user->Name = "admin";
+
+ $token1 = $this->userDao->createSignonToken($user);
+ sleep(1);
+ $token2 = $this->userDao->createSignonToken($user);
+ $this->assertNotEqual($token1, $token2);
+
+ $check1 = $this->userDao->validateSignon($token1);
+ $check2 = $this->userDao->validateSignon($token2);
+
+ $this->assertIsAdmin($check1);
+ $this->assertIsAdmin($check2);
+
+ $this->userDao->clearSignonTokens($user);
+
+ $check3 = $this->userDao->validateSignon($token1);
+ $check4 = $this->userDao->validateSignon($token2);
+
+ $this->assertNull($check3);
+ $this->assertNull($check4);
+ }
+
+ function testClearAllSigonTokens()
+ {
+ $user1 = new TimeTrackerUser(new UserManager());
+ $user1->Name = "admin";
+
+ $user2 = new TimeTrackerUser(new UserManager());
+ $user2->Name = "manager";
+
+ $token1 = $this->userDao->createSignonToken($user1);
+ $token2 = $this->userDao->createSignonToken($user2);
+
+ $check1 = $this->userDao->validateSignon($token1);
+ $check2 = $this->userDao->validateSignon($token2);
+
+ $this->assertIsAdmin($check1);
+ $this->assertNotNull($check2);
+ $this->assertEqual($check2->Name, $user2->Name);
+
+ $this->userDao->clearSignonTokens();
+
+ $check3 = $this->userDao->validateSignon($token1);
+ $check4 = $this->userDao->validateSignon($token2);
+
+ $this->assertNull($check3);
+ $this->assertNull($check4);
+ }
+}
+
?> \ No newline at end of file