diff options
author | wei <> | 2006-07-14 06:56:16 +0000 |
---|---|---|
committer | wei <> | 2006-07-14 06:56:16 +0000 |
commit | 143980b6dab8ad87c44518e5b7befb614fb83b85 (patch) | |
tree | 6afadfb80ca6e4d36443f83bd5a6cc2cfe73032d /demos/time-tracker/protected/APP_CODE | |
parent | c004bbdf4f0e824e5ccbaef8f98ca4a3d44d3b49 (diff) |
Add time-tracker sample and docs. (Incomplete)
Diffstat (limited to 'demos/time-tracker/protected/APP_CODE')
6 files changed, 159 insertions, 0 deletions
diff --git a/demos/time-tracker/protected/APP_CODE/BaseDao.php b/demos/time-tracker/protected/APP_CODE/BaseDao.php new file mode 100644 index 00000000..f9146b59 --- /dev/null +++ b/demos/time-tracker/protected/APP_CODE/BaseDao.php @@ -0,0 +1,18 @@ +<?php
+
+class BaseDao
+{
+ private $_connection;
+
+ public function setConnection($connection)
+ {
+ $this->_connection = $connection;
+ }
+
+ protected function getConnection()
+ {
+ return $this->_connection;
+ }
+}
+
+?>
\ No newline at end of file diff --git a/demos/time-tracker/protected/APP_CODE/Project.php b/demos/time-tracker/protected/APP_CODE/Project.php new file mode 100644 index 00000000..ad9f7d19 --- /dev/null +++ b/demos/time-tracker/protected/APP_CODE/Project.php @@ -0,0 +1,17 @@ +<?php
+
+class Project
+{
+ public $ActualDuration = 0;
+ public $CreatorUserName = '';
+ public $CompletionDate = 0;
+ public $DateCreated = 0;
+ public $Description = '';
+ public $EstimateDuration = 0;
+ public $ID = 0;
+ public $ManagerUserName = '';
+ public $Name = '';
+}
+
+
+?>
\ No newline at end of file diff --git a/demos/time-tracker/protected/APP_CODE/ProjectDao.php b/demos/time-tracker/protected/APP_CODE/ProjectDao.php new file mode 100644 index 00000000..25a2845d --- /dev/null +++ b/demos/time-tracker/protected/APP_CODE/ProjectDao.php @@ -0,0 +1,76 @@ +<?php
+
+Prado::using('Application.APP_CODE.BaseDao');
+
+class ProjectDao extends BaseDao
+{
+ public function createNewProject($project)
+ {
+ $sqlmap = $this->getConnection();
+ $creator = $sqlmap->queryForObject('GetUserByName', $project->CreatorUserName);
+ $manager = $sqlmap->queryForObject('GetUserByName', $project->ManagerUserName);
+ $exists = $sqlmap->queryForObject('GetProjectByName', $project->Name);
+ if($exists)
+ {
+ throw new TimeTrackerException(
+ 'project_exists', $project->Name);
+ }
+ else if(!$creator || !$manager)
+ {
+ throw new TimeTrackerException(
+ 'invalid_creator_and_manager',
+ $project->Name, $project->CreatorUserName,
+ $project->ManagerUserName);
+ }
+ else
+ {
+ $param['project'] = $project;
+ $param['creator'] = $creator->ID;
+ $param['manager'] = $manager->ID;
+ return $sqlmap->insert('CreateNewProject', $param);
+ }
+ }
+
+ public function getProjectByID($projectID)
+ {
+ $sqlmap = $this->getConnection();
+ return $sqlmap->queryForObject('GetProjectByID', $projectID);
+ }
+
+ public function addUserToProject($project, $user)
+ {
+ $sqlmap = $this->getConnection();
+ $project = $this->getProjectByID($project->ID);
+ $user = $sqlmap->queryForObject('GetUserByName', $user->Name);
+ $list = $sqlmap->queryForList('GetProjectMembers', $project);
+ $userExists = false;
+ foreach($list as $k)
+ {
+ if($k->ID == $user->ID)
+ $userExists = true;
+ }
+ if(!$project)
+ {
+ throw new TimeTrackerException(
+ 'invalid_project', $project->Name);
+ }
+ else if(!$user)
+ {
+ throw new TimeTrackerException(
+ 'invalid_user', $user->Name);
+ }
+ else if($userExists)
+ {
+ throw new TimeTrackerException(
+ 'project_member_exists', $projet->Name, $user->Name);
+ }
+ else
+ {
+ $param['project'] = $project;
+ $param['user'] = $user;
+ return $sqlmap->insert('AddUserToProject', $param);
+ }
+ }
+}
+
+?>
\ No newline at end of file diff --git a/demos/time-tracker/protected/APP_CODE/TimeTrackerException.php b/demos/time-tracker/protected/APP_CODE/TimeTrackerException.php new file mode 100644 index 00000000..d715eefa --- /dev/null +++ b/demos/time-tracker/protected/APP_CODE/TimeTrackerException.php @@ -0,0 +1,14 @@ +<?php
+
+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 new file mode 100644 index 00000000..4b6987bd --- /dev/null +++ b/demos/time-tracker/protected/APP_CODE/TimeTrackerUser.php @@ -0,0 +1,31 @@ +<?php
+
+Prado::using('System.Security.TUser');
+Prado::using('System.Security.TUserManager');
+
+class TimeTrackerUser extends TUser
+{
+ private $_ID;
+
+ public function __construct()
+ {
+ parent::__construct(new TUserManager());
+ }
+
+ public function getID(){ return $this->_ID; }
+ public function setID($value)
+ {
+ if(is_null($this->_ID))
+ $this->_ID = $value;
+ else
+ throw new TimeTrackerUserException(
+ 'timetracker_user_readonly_id');
+ }
+}
+
+class TimeTrackerUserException extends TimeTrackerException
+{
+
+}
+
+?>
\ No newline at end of file diff --git a/demos/time-tracker/protected/APP_CODE/exceptions.txt b/demos/time-tracker/protected/APP_CODE/exceptions.txt new file mode 100644 index 00000000..e948f4d0 --- /dev/null +++ b/demos/time-tracker/protected/APP_CODE/exceptions.txt @@ -0,0 +1,3 @@ +timetracker_user_readonly_id = Time tracker user ID is read-only.
+invalid_creator_and_manager = Unable to find time tracker usernames '{1}' and '{2}' for project '{0}'.
+project_exists = Project '{0}' already exists.
\ No newline at end of file |