diff --git a/vaktliste/App/Base/ApplicationRegistry.php b/vaktliste/App/Base/ApplicationRegistry.php new file mode 100644 index 0000000..2fea639 --- /dev/null +++ b/vaktliste/App/Base/ApplicationRegistry.php @@ -0,0 +1,73 @@ +values[$key])) { + return $this->values[$key]; + } + return null; + } + + protected function set($key, $val) { + $this->values[$key] = $val; + // storage ... + return $this->values[$key]; + } + + static function getDSN() { + return self::instance()->get('dsn'); + } + + + static function setDSN( $dsn ) { + return self::instance()->set('dsn', $dsn); + } + + static function getControllerMap() { + return self::instance()->get('controllerMap'); + } + + static function setControllerMap(App_Controller_ControllerMap $map ) { + return self::instance()->set('controllerMap', $map); + } + + static function getApplicationController() { + return self::instance()->get('applicationController'); + } + + static function setApplicationController(App_Controller_AppController $appCtrl) { + return self::instance()->set('applicationController', $appCtrl); + } + + static function getAccessManager() { + return self::instance()->get('accessManager'); + } + + static function setAccessManager(App_Controller_AccessManager $manager) { + return self::instance()->set('accessManager', $manager); + } + + static function getPageTitle() { + return self::instance()->get('pagetitle'); + } + + static function setPageTitle( $pagetitle ) { + return self::instance()->set('pagetitle', $pagetitle); + } + +} \ No newline at end of file diff --git a/vaktliste/App/Base/Registry.php b/vaktliste/App/Base/Registry.php new file mode 100644 index 0000000..a901b77 --- /dev/null +++ b/vaktliste/App/Base/Registry.php @@ -0,0 +1,8 @@ + \ No newline at end of file diff --git a/vaktliste/App/Base/RequestRegistry.php b/vaktliste/App/Base/RequestRegistry.php new file mode 100644 index 0000000..69d0ad2 --- /dev/null +++ b/vaktliste/App/Base/RequestRegistry.php @@ -0,0 +1,40 @@ +values[$key])) { + return $this->values[$key]; + } + return null; + } + + protected function set($key, $value) { + $this->values[$key] = $value; + } + + static function getRequest() { + return self::instance()->get('request'); + } + + static function setRequest(App_Controller_Request $request) { + return self::instance()->set('request', $request); + } +} + +?> \ No newline at end of file diff --git a/vaktliste/App/Base/SessionRegistry.php b/vaktliste/App/Base/SessionRegistry.php new file mode 100644 index 0000000..51423a9 --- /dev/null +++ b/vaktliste/App/Base/SessionRegistry.php @@ -0,0 +1,56 @@ +get('userid'))) { + //return self::instance()->get('userid'); + } + // check session from old inside + if (isset($_SESSION['valid-user'])) { + self::instance()->set('userid', $_SESSION['valid-user']); + } + return self::instance()->get('userid'); + } + + static function setUserId($userid) { + if (is_null($userid)) { + unset($_SESSION['valid-user']); + self::instance()->set('userid', null); + } else { + // update old inside as well + $_SESSION['valid-user'] = $userid; + self::instance()->set('userid', $userid); + } + } + +} + +?> \ No newline at end of file diff --git a/vaktliste/App/Command/AddShift.php b/vaktliste/App/Command/AddShift.php new file mode 100644 index 0000000..7ae98f1 --- /dev/null +++ b/vaktliste/App/Command/AddShift.php @@ -0,0 +1,42 @@ +getProperty("title"); + $starts = $request->getProperty("starts"); + $ends = $request->getProperty("ends"); + $numworkers = $request->getProperty("numworkers"); + $location = $request->getProperty("location"); + $group = 97; // CNS bar + $salaryType = 3; // CNS bar + + if (empty($title)) { + $request->addFeedback("Tittel må oppgis."); + return self::statuses('CMD_INSUFFICIENT_DATA'); + } + + if (empty($starts)) { + $request->addFeedback("Starttid må oppgis."); + return self::statuses('CMD_INSUFFICIENT_DATA'); + } + + if (empty($ends)) { + $request->addFeedback("Sluttid må oppgis."); + return self::statuses('CMD_INSUFFICIENT_DATA'); + } + + if (empty($numworkers)) { + $request->addFeedback("Antall må oppgis."); + return self::statuses('CMD_INSUFFICIENT_DATA'); + } + + return self::statuses('CMD_OK'); + } + +} + +?> \ No newline at end of file diff --git a/vaktliste/App/Command/Command.php b/vaktliste/App/Command/Command.php new file mode 100644 index 0000000..7feb7ec --- /dev/null +++ b/vaktliste/App/Command/Command.php @@ -0,0 +1,41 @@ + 0, + 'CMD_OK' => 1, + 'CMD_ERROR' => 2, + 'CMD_INSUFFICIENT_DATA' => 3 + ); + + private $status = 0; + + //private $currentUser = null; + + final function __construct() {} + + function execute(App_Controller_Request $request) { + // check if visitor is logged in + //$this->currentUser = App_Base_SessionRegistry::getCurrentUser(); + + // execute command + $this->status = $this->doExecute($request); + $request->setCommand($this); + } + + function getStatus() { + return $this->status; + } + + static function statuses ($str = 'CMD_DEFAULT') { + if (empty($str)) $str = 'CMD_DEFAULT'; + // convert string into a status number + return self::$STATUS_STRINGS[$str]; + } + + //abstract protected function validate(App_Controller_Request $request); + abstract function doExecute(App_Controller_Request $request); +} + +?> \ No newline at end of file diff --git a/vaktliste/App/Command/CommandHelper.php b/vaktliste/App/Command/CommandHelper.php new file mode 100644 index 0000000..c9f202a --- /dev/null +++ b/vaktliste/App/Command/CommandHelper.php @@ -0,0 +1,12 @@ +find(App_Base_SessionRegistry::getUserId()); + } + return null; + } +} + +?> diff --git a/vaktliste/App/Command/DefaultCommand.php b/vaktliste/App/Command/DefaultCommand.php new file mode 100644 index 0000000..e8d4101 --- /dev/null +++ b/vaktliste/App/Command/DefaultCommand.php @@ -0,0 +1,24 @@ +setObject('currentUser', $user); + return self::statuses('CMD_OK'); + } +// if ($request->getProperty("p") == "login") { +// $request->addFeedback( "you are logged in" ); +// return self::statuses('CMD_OK'); +// } + return self::statuses('CMD_DEFAULT'); + } +} diff --git a/vaktliste/App/Command/Login.php b/vaktliste/App/Command/Login.php new file mode 100644 index 0000000..c093614 --- /dev/null +++ b/vaktliste/App/Command/Login.php @@ -0,0 +1,27 @@ +getProperty("username"); + $password = $request->getProperty("password"); + if (empty($username) || empty($password)) { + $request->addFeedback("Både brukernavn og passord må oppgis."); + return self::statuses('CMD_INSUFFICIENT_DATA'); + } + + $manager = App_Base_ApplicationRegistry::getAccessManager(); + $user = $manager->login($username, $password); + if (is_null($user)) { + $request->addFeedback("Ugyldig brukernavn eller passord."); + return self::statuses('CMD_ERROR'); + } + App_Base_SessionRegistry::setUserId($user->getId()); + return self::statuses('CMD_OK'); + } +} + +?> \ No newline at end of file diff --git a/vaktliste/App/Command/Logout.php b/vaktliste/App/Command/Logout.php new file mode 100644 index 0000000..3b841ed --- /dev/null +++ b/vaktliste/App/Command/Logout.php @@ -0,0 +1,15 @@ +addFeedback("Du er logget ut"); + App_Base_SessionRegistry::setUserId(null); + return self::statuses('CMD_DEFAULT'); + } +} + +?> \ No newline at end of file diff --git a/vaktliste/App/Controller/AccessManager.php b/vaktliste/App/Controller/AccessManager.php new file mode 100644 index 0000000..fd77a60 --- /dev/null +++ b/vaktliste/App/Controller/AccessManager.php @@ -0,0 +1,35 @@ +error; + } + + function setError($msg) { + $this->error = $msg; + } + + function login($username, $password) { + return App_Domain_DomainObject::getFinder(App_Domain_HelperFactory::USER)->findByLogin($username, $password); + } + + function logout() { + if (!is_null(App_Base_SessionRegistry::getUserId())) { + // do something, i.e. logging ? + } + return true; + } + + function getCommandAccess($cmd) { + if (!is_null(App_Base_SessionRegistry::getUserId())) { + return true; + } + return false; + } + +} \ No newline at end of file diff --git a/vaktliste/App/Controller/AppController.php b/vaktliste/App/Controller/AppController.php new file mode 100644 index 0000000..5423627 --- /dev/null +++ b/vaktliste/App/Controller/AppController.php @@ -0,0 +1,116 @@ +controllerMap = $map; + if (!self::$base_cmd) { + self::$base_cmd = new ReflectionClass("App_Command_Command"); + self::$default_cmd = new App_Command_DefaultCommand(); + } + } + + function getView(App_Controller_Request $request) { + $view = $this->getResource($request, "View"); + return $view; + } + + function getForward(App_Controller_Request $request) { + $forward = $this->getResource($request, "Forward"); + if ($forward) { + $request->setProperty("cmd", $forward); + } + return $forward; + } + + private function getResource(App_Controller_Request $request, $res) { + // get the previous command and its execution status + $cmd_str = $request->getProperty("cmd"); + $previous = $request->getLastCommand(); + $status = $previous->getStatus(); + if (!$status) { + $status = 0; + } + + $acquire = "get$res"; + // find resource for previous command and its status + $resource = $this->controllerMap->$acquire($cmd_str, $status); + // alternatively find resource for command and status 0 + if (!$resource) { + $resource = $this->controllerMap->$acquire($cmd_str, 0); + } + // or command 'default' and command status + if (!$resource) { + $resource = $this->controllerMap->$acquire('default', $status); + } + // all else has failed get resource for 'default', status 0 + if (!$resource) { + $resource = $this->controllerMap->$acquire('default', 0); + } + return $resource; + } + + function getCommand(App_Controller_Request $request) { + $previous = $request->getLastCommand(); + if (!$previous) { + // this is first command for this request + $cmd = $request->getProperty("cmd"); + if (!$cmd) { + // no command property - using default + $request->setProperty("cmd", "default"); + return self::$default_cmd; + } + } else { + // a command has been run already in this request + $cmd = $this->getForward($request); + if (!$cmd) { + return null; + } + } + + // we now have a command name in $cmd - turn it into a Command object + $cmd_obj = $this->resolveCommand($cmd); + if (!$cmd_obj) { + throw new Exception("Couldn't resolve '$cmd'"); + } + + // Count the number of times the class has been accessed and check for circular forwarding + $cmd_class = get_class($cmd_obj); + if (isset($this->invoked[$cmd_class])) { + $this->invoked[$cmd_class]++; + } else { + $this->invoked[$cmd_class] = 1; + } + + if ($this->invoked[$cmd_class] > 1) { + throw new Exception("Circular forwarding"); + } + + // return the Command object + return $cmd_obj; + } + + function resolveCommand($cmd) { + $sep = "/"; + $cmd = str_replace(array(".", $sep), "", $cmd); + $classroot = $this->controllerMap->getClassroot($cmd); + $filepath = "App{$sep}Command{$sep}{$classroot}.php"; + $classname = "App_Command_{$classroot}"; + if (file_exists($filepath)) { + @require_once("$filepath"); + if (class_exists($classname)) { + $cmd_class = new ReflectionClass($classname); + if ($cmd_class->isSubClassOf( self::$base_cmd )) { + return $cmd_class->newInstance(); + } + } + } + return null; + } +} + +?> \ No newline at end of file diff --git a/vaktliste/App/Controller/ApplicationHelper.php b/vaktliste/App/Controller/ApplicationHelper.php new file mode 100644 index 0000000..58a2922 --- /dev/null +++ b/vaktliste/App/Controller/ApplicationHelper.php @@ -0,0 +1,110 @@ +getOptions(); + + App_Base_SessionRegistry::instance(); + } + + private function getOptions() { + // $this->ensure( file_exists( $this->config ), "Could not find options file" ); + // $options = @SimpleXml_load_file( $this->config ); + // $this->ensure( $options instanceof SimpleXMLElement, "Could not resolve options file" ); + // $dsn = (string)$options->dsn; + include("../inside/credentials.php"); + $dsn = getDSN("PDO"); + $this->ensure($dsn, "No DSN found"); + App_Base_ApplicationRegistry::setDSN($dsn); + + $map = new App_Controller_ControllerMap(); + //foreach ($options->control->view as $default_view) { + // $stat_str = trim($default_view['status']); + // $status = App_Command_Command::statuses($stat_str); + // $map->addView('default', $status, (string)$default_view); + //} + //foreach ( $options->control->command as $command_view ) { + // $command = trim((string)$command_view['name'] ); + // if ( $command_view->classalias ) { + // $classroot = trim((string)$command_view->classalias['name']); + // $map->addClassroot( $command, $classroot ); + // } + // if ( $command_view->view ) { + // $view = trim((string)$command_view->view); + // $forward = trim((string)$command_view->forward); + // $map->addView( $command, 0, $view ); + // if ( $forward ) { + // $map->addForward( $command, 0, $forward ); + // } + // foreach( $command_view->status as $command_view_status ) { + // $view = trim((string)$command_view_status->view); + // $forward = trim((string)$command_view_status->forward); + // $stat_str = trim($command_view_status['value']); + // $status = App_Command_Command::statuses( $stat_str ); + // if ( $view ) { + // $map->addView( $command, $status, $view ); + // } + // if ( $forward ) { + // $map->addForward( $command, $status, $forward ); + // } + // } + // } + //} + + // Default view + $status = App_Command_Command::statuses(); + $map->addView("default", $status, "login"); + $status = App_Command_Command::statuses("CMD_OK"); + $map->addView("default", $status, "calendar"); + $status = App_Command_Command::statuses("CMD_ERROR"); + $map->addView("default", $status, "error"); + + $map->addClassroot("login", "Login"); + $status = App_Command_Command::statuses(); + $map->addView("login", $status, "login"); + $status = App_Command_Command::statuses("CMD_OK"); + $map->addView("login", $status, "calendar"); + + $map->addClassroot("logout", "Logout"); + //$map->addClassroot("logout", "Logout"); + + App_Base_ApplicationRegistry::setControllerMap($map); + + $appCtrl = new App_Controller_AppController(App_Base_ApplicationRegistry::getControllerMap()); + App_Base_ApplicationRegistry::setApplicationController($appCtrl); + + $manager = new App_Controller_AccessManager(); + App_Base_ApplicationRegistry::setAccessManager($manager); + + $pageTitle = "Det Norske Studentersamfund - vaktliste"; + App_Base_ApplicationRegistry::setPageTitle($pageTitle); + + } + + + + + private function ensure ($expr, $message) { + if (!$expr) { + throw new Exception($message); + } + } +} + +?> \ No newline at end of file diff --git a/vaktliste/App/Controller/Controller.php b/vaktliste/App/Controller/Controller.php new file mode 100644 index 0000000..3fc6c3d --- /dev/null +++ b/vaktliste/App/Controller/Controller.php @@ -0,0 +1,34 @@ +init(); + $instance->handleRequest(); + } + + public function init() { + $this->applicationHelper = App_Controller_ApplicationHelper::instance(); + $this->applicationHelper->init(); + } + + public function handleRequest() { + $request = new App_Controller_Request(); + $app_c = App_Base_ApplicationRegistry::getApplicationController(); + while ($cmd = $app_c->getCommand($request)) { + $cmd->execute($request); + } + $this->invokeView($app_c->getView($request)); + } + + function invokeView($target) { + include("App/View/$target.php"); + exit; + } +} + +?> \ No newline at end of file diff --git a/vaktliste/App/Controller/ControllerMap.php b/vaktliste/App/Controller/ControllerMap.php new file mode 100644 index 0000000..bf29a8c --- /dev/null +++ b/vaktliste/App/Controller/ControllerMap.php @@ -0,0 +1,42 @@ +classrootMap[$command] = $classroot; + } + + function getClassroot ($command) { + if (isset ($this->classrootMap[$command])) { + return $this->classrootMap[$command]; + } + return $command; + } + + function addView ($command = "default", $status = 0, $view) { + $this->viewMap[$command][$status] = $view; + } + + function getView ($command, $status) { + if (isset ($this->viewMap[$command][$status])) { + return $this->viewMap[$command][$status]; + } + return null; + } + + function addForward ($command, $status = 0, $newCommand) { + $this->forwardMap[$command][$status] = $newCommand; + } + + function getForward ($command, $status) { + if (isset ($this->forwardMap[$command][$status])) { + return $this->forwardMap[$command][$status]; + } + return null; + } +} + +?> \ No newline at end of file diff --git a/vaktliste/App/Controller/Request.php b/vaktliste/App/Controller/Request.php new file mode 100644 index 0000000..6d9e036 --- /dev/null +++ b/vaktliste/App/Controller/Request.php @@ -0,0 +1,75 @@ +init(); + App_Base_RequestRegistry::setRequest($this); + } + + function init() { + if (isset($_SERVER['REQUEST_METHOD'])) { + if ($_SERVER['REQUEST_METHOD']) { + $this->properties = $_REQUEST; + return; + } + } + + foreach($_SERVER['argv'] as $arg) { + if (strpos($arg, '=')) { + list($key, $val) = explode("=", $arg); + $this->setProperty($key, $val); + } + } + } + + function getProperty($key) { + if (isset ($this->properties[$key])) { + return $this->properties[$key]; + } + return null; + } + + function setProperty($key, $val) { + $this->properties[$key] = $val; + } + + function addFeedback($msg) { + array_push($this->feedback, $msg); + } + + function getFeedback() { + return $this->feedback; + } + + function getFeedbackString ($separator="\n") { + return implode($separator, $this->feedback); + } + + function setObject( $name, $object ) { + $this->objects[$name] = $object; + } + + function getObject( $name ) { + if ( isset( $this->objects[$name] ) ) { + return $this->objects[$name]; + } + return null; + } + + function setCommand (App_Command_Command $cmd) { + return $this->command = $cmd; + } + + function getLastCommand () { + return $this->command; + } +} +?> \ No newline at end of file diff --git a/vaktliste/App/Domain/Division.php b/vaktliste/App/Domain/Division.php new file mode 100644 index 0000000..3522413 --- /dev/null +++ b/vaktliste/App/Domain/Division.php @@ -0,0 +1,47 @@ +name = $name; + $this->markDirty(); + } + + function getName() { + return $this->name; + } + + function setNiceName($niceName) { + $this->niceName = $niceName; + $this->markDirty(); + } + + function getNiceName() { + return $this->niceName; + } + + function setHidden($hidden) { + $this->hidden = $hidden; + $this->markDirty(); + } + + function getHidden() { + return $this->hidden; + } + +} + +?> diff --git a/vaktliste/App/Domain/DomainObject.php b/vaktliste/App/Domain/DomainObject.php new file mode 100644 index 0000000..a6526cb --- /dev/null +++ b/vaktliste/App/Domain/DomainObject.php @@ -0,0 +1,63 @@ +markNew(); + } else { + $this->id = $id; + } + } + + function markNew() { + App_Domain_ObjectWatcher::addNew($this); + } + + function markDeleted() { + App_Domain_ObjectWatcher::addDelete($this); + } + + function markDirty() { + App_Domain_ObjectWatcher::addDirty($this); + } + + function markClean() { + App_Domain_ObjectWatcher::addClean($this); + } + + function setId($id) { + $this->id = $id; + } + + function getId() { + return $this->id; + } + + function collection() { + return self::getCollection(get_class($this)); + } + + static function getCollection($type) { + return App_Domain_HelperFactory::getCollection($type); + } + + function finder() { + return self::getFinder(get_class($this)); + } + + static function getFinder($type) { + return App_Domain_HelperFactory::getFinder($type); + } + +} + +?> \ No newline at end of file diff --git a/vaktliste/App/Domain/Group.php b/vaktliste/App/Domain/Group.php new file mode 100644 index 0000000..c531ec4 --- /dev/null +++ b/vaktliste/App/Domain/Group.php @@ -0,0 +1,67 @@ +name = $name; + $this->markDirty(); + } + + function getName() { + return $this->name; + } + + function setText($text) { + $this->text = $text; + $this->markDirty(); + } + + function getText() { + return $this->text; + } + + function setDivision(App_Domain_Division $division) { + $this->division = $division; + $this->markDirty(); + } + + function getDivision() { + return $this->division; + } + + function setAdmin($admin) { + $this->admin = $admin; + $this->markDirty(); + } + + function getAdmin() { + return $this->admin; + } + + function setMailinglist($mailinglist) { + $this->mailinglist = $mailinglist; + $this->markDirty(); + } + + function getMailinglist() { + return $this->mailinglist; + } + +} + +?> diff --git a/vaktliste/App/Domain/HelperFactory.php b/vaktliste/App/Domain/HelperFactory.php new file mode 100644 index 0000000..f65a8b0 --- /dev/null +++ b/vaktliste/App/Domain/HelperFactory.php @@ -0,0 +1,66 @@ + \ No newline at end of file diff --git a/vaktliste/App/Domain/Location.php b/vaktliste/App/Domain/Location.php new file mode 100644 index 0000000..97e9090 --- /dev/null +++ b/vaktliste/App/Domain/Location.php @@ -0,0 +1,27 @@ +name = $name; + $this->markDirty(); + } + + function getName() { + return $this->name; + } + +} + +?> diff --git a/vaktliste/App/Domain/ObjectWatcher.php b/vaktliste/App/Domain/ObjectWatcher.php new file mode 100644 index 0000000..85e26f5 --- /dev/null +++ b/vaktliste/App/Domain/ObjectWatcher.php @@ -0,0 +1,112 @@ +getId(); + return $key; + } + + static function add(App_Domain_DomainObject $obj) { + $inst = self::instance(); + $inst->all[$inst->globalKey($obj)] = $obj; + } + + static function exists($classname, $id) { + $inst = self::instance(); + $key = "$classname.$id"; + if (isset($inst->all[$key])) { + return $inst->all[$key]; + } + return null; + } + + static function addDirty(App_Domain_DomainObject $obj) { + $inst = self::instance(); + // verify that the updated object is an object allready in the database + if (!in_array($obj, $inst->new, true)) { + $inst->dirty[$inst->globalKey($obj)] = $obj; + } + } + + static function addNew(App_Domain_DomainObject $obj) { + $inst = self::instance(); + // we don't yet have an id + $inst->new[] = $obj; + } + + /* + * Mark object as clean, changes will not be stored to database + */ + static function addClean(App_Domain_DomainObject $obj) { + $inst = self::instance(); + + unset($inst->dirty[$inst->globalKey($obj)]); + + // check if the object is in the new array, and remove it from it + if (in_array($obj, $inst->new, true)) { + $pruned=array(); + foreach ($inst->new as $newobj) { + if (!($newobj === $obj)) { + $pruned[] = $newobj; + } + } + $inst->new = $pruned; + } + } + + static function addDelete(App_Domain_DomainObject $obj) { + $inst = self::instance(); + + unset($inst->dirty[$inst->globalKey($obj)]); + + if (in_array($obj, $inst->new, true)) { + $pruned=array(); + foreach ($inst->new as $newobj) { + if (!($newobj === $obj)) { + $pruned[] = $newobj; + } + } + $inst->new = $pruned; + } + + $inst->delete[] = $obj; + } + + function performOperations() { + foreach ($this->dirty as $key=>$obj) { + $obj->finder()->update($obj); + } + foreach ($this->new as $key=>$obj) { + $obj->finder()->insert($obj); + } + foreach ($this->delete as $key=>$obj) { + //$obj->finder()->delete($obj); + } + $this->dirty = array(); + $this->new = array(); + $this->delete = array(); + } +} + +?> \ No newline at end of file diff --git a/vaktliste/App/Domain/User.php b/vaktliste/App/Domain/User.php new file mode 100644 index 0000000..de18858 --- /dev/null +++ b/vaktliste/App/Domain/User.php @@ -0,0 +1,170 @@ +username = $username_s; + $this->markDirty(); + } + + function getUsername() { + return $this->username; + } + + function setPassword($password_s) { + $this->password = $password_s; + $this->markDirty(); + } + + function getPassword() { + return $this->password; + } + + function setFirstname($firstname_s) { + $this->firstname = $firstname_s; + $this->markDirty(); + } + + function getFirstname() { + return $this->firstname; + } + + function setLastname($lastname_s) { + $this->lastname = $lastname_s; + $this->markDirty(); + } + + function getLastname() { + return $this->lastname; + } + + function getName($separator = " ") { + return $this->getFirstname() . $separator . $this->getLastname(); + } + + function setValidaddress($validaddress_i) { + $this->validaddress = $validaddress_i; + $this->markDirty(); + } + + function getValidaddress() { + return $this->validaddress; + } + + function setEmail($email_s) { + $this->email = $email_s; + $this->markDirty(); + } + + function getEmail() { + return $this->email; + } + + function setBirthdate($birthdate_d) { + $this->birthdate = $birthdate_d; + $this->markDirty(); + } + + function getBirthdate() { + return $this->birthdate; + } + + function setPlaceOfStudy($placeofstudy_i) { + $this->placeOfStudy = $placeofstudy_i; + $this->markDirty(); + } + + function getPlaceOfStudy() { + return $this->placeOfStudy; + } + + function setPasswordreset($passwordreset_i) { + $this->passwordreset = $passwordreset_i; + $this->markDirty(); + } + + function getPasswordreset() { + return $this->passwordreset; + } + + function setDivisionIdRequest($divisionidrequest_i) { + $this->divisionIdRequest = $divisionidrequest_i; + $this->markDirty(); + } + + function getDivisionIdRequest() { + return $this->divisionIdRequest; + } + + function getUpdates() { + if (is_null($this->updates)) { + $this->updates = self::getFinder("App_Domain_UserUpdate")->findByUserId($this->getId()); + } + return $this->updates; + } + + function getAddress() { + if (is_null($this->address)) { + $this->address = self::getFinder("App_Domain_UserAddress")->findByUserId($this->getId()); + } + return $this->address; + } + + function getMemberships() { + if (is_null($this->memberships)) { + $this->memberships = self::getFinder("App_Domain_Membership")->findByUserId($this->getId()); + } + return $this->memberships; + } + + function getCards() { + if (is_null($this->cards)) { + $this->cards = self::getFinder("App_Domain_MembershipCard")->findByUserId($this->getId()); + } + return $this->cards; + } + + function getWorkShifts() { + if (is_null($this->workShifts)) { + $this->workShifts = self::getFinder("App_Domain_WorkShiftWorkers")->findByUserId($this->getId()); + } + return $this->workShifts; + } + + function getGroups() { + if (is_null($this->groups)) { + $this->groups = self::getFinder("App_Domain_Groups")->findByUserId($this->getId()); + } + return $this->groups; + } + +} + +?> \ No newline at end of file diff --git a/vaktliste/App/Domain/UserPhone.php b/vaktliste/App/Domain/UserPhone.php new file mode 100644 index 0000000..e77f332 --- /dev/null +++ b/vaktliste/App/Domain/UserPhone.php @@ -0,0 +1,38 @@ +user = $user; + $this->markDirty(); + } + + function getUser() { + return $this->user; + } + + function setPhone($phone) { + $this->phone = $phone; + $this->markDirty(); + } + + function getPhone() { + return $this->phone; + } + +} + +?> \ No newline at end of file diff --git a/vaktliste/App/Domain/WorkSalaryType.php b/vaktliste/App/Domain/WorkSalaryType.php new file mode 100644 index 0000000..d8e4202 --- /dev/null +++ b/vaktliste/App/Domain/WorkSalaryType.php @@ -0,0 +1,37 @@ +title = $title; + $this->markDirty(); + } + + function getTitle() { + return $this->title; + } + + function setHourlyRate($hourlyRate) { + $this->hourlyRate = $hourlyRate; + $this->markDirty(); + } + + function getHourlyRate() { + return $this->hourlyRate; + } + +} + +?> diff --git a/vaktliste/App/Domain/WorkShift.php b/vaktliste/App/Domain/WorkShift.php new file mode 100644 index 0000000..7245dd0 --- /dev/null +++ b/vaktliste/App/Domain/WorkShift.php @@ -0,0 +1,142 @@ +starts = $starts; + $this->markDirty(); + } + + function getStarts() { + return $this->starts; + } + + function setEnds(DateTime $ends) { + $this->ends = $ends; + $this->markDirty(); + } + + function getEnds() { + return $this->ends; + } + + function setGroup(App_Domain_Group $group) { + $this->group = $group; + $this->markDirty(); + } + + function getGroup() { + return $this->group; + } + + function setLocation(App_Domain_Location $location) { + $this->location = $location; + $this->markDirty(); + } + + function getLocation() { + return $this->location; + } + + function setActive($active) { + $this->active = $active; + $this->markDirty(); + } + + function getActive() { + return $this->active; + } + + function setTitle($title) { + $this->title = $title; + $this->markDirty(); + } + + function getTitle() { + return $this->title; + } + + function setComment($comment) { + $this->comment = $comment; + $this->markDirty(); + } + + function getComment() { + return $this->comment; + } + + function setNumWorkers($numWorkers) { + $this->numWorkers = $numWorkers; + $this->markDirty(); + } + + function getNumWorkers() { + return $this->numWorkers; + } + + function setLocked($locked) { + $this->locked = $locked; + $this->markDirty(); + } + + function getLocked() { + return $this->locked; + } + + function setAutoassignWorkers($autoassignWorkers) { + $this->autoassignWorkers = $autoassignWorkers; + $this->markDirty(); + } + + function getAutoassignWorkers() { + return $this->autoassignWorkers; + } + + function setSalaryType(App_Domain_WorkSalaryType $salaryType) { + $this->salaryType = $salaryType; + $this->markDirty(); + } + + function getSalaryType() { + return $this->salaryType; + } + + function getWorkers() { + if (is_null($this->workers)) { + $this->workers = self::getFinder("App_Domain_WorkShiftWorkers")->findByShiftId($this->getId()); + } + return $this->workers; + } + + function getUpdates() { + if (is_null($this->updates)) { + $this->updates = self::getFinder("App_Domain_WorkShiftUpdates")->findByShiftId($this->getId()); + } + return $this->updates; + } + +} \ No newline at end of file diff --git a/vaktliste/App/Domain/WorkShiftUpdate.php b/vaktliste/App/Domain/WorkShiftUpdate.php new file mode 100644 index 0000000..eb4ea78 --- /dev/null +++ b/vaktliste/App/Domain/WorkShiftUpdate.php @@ -0,0 +1,57 @@ +shift = $shift; + $this->markDirty(); + } + + function getShift() { + return $this->shift; + } + + function setUpdateTime(DateTime $time) { + $this->updateTime = $time; + $this->markDirty(); + } + + function getUpdateTime() { + return $this->updateTime; + } + + function setUser(App_Domain_User $user) { + $this->user = $user; + $this->markDirty(); + } + + function getUser() { + return $this->user; + } + + function setUpdateText($updateText) { + $this->updateText = $updateText; + $this->markDirty(); + } + + function getUpdateText() { + return $this->updateText; + } + +} + +?> diff --git a/vaktliste/App/Domain/WorkShiftWorker.php b/vaktliste/App/Domain/WorkShiftWorker.php new file mode 100644 index 0000000..db2f13a --- /dev/null +++ b/vaktliste/App/Domain/WorkShiftWorker.php @@ -0,0 +1,76 @@ +shift = $shift; + $this->markDirty(); + } + + function getShift() { + return $this->shift; + } + + function setUser(App_Domain_User $user) { + $this->user = $user; + $this->markDirty(); + } + + function getUser() { + return $this->user; + } + + function setAssigned($assigned) { + $this->assigned = $assigned; + $this->markDirty(); + } + + function getAssigned () { + return $this->assigned; + } + + function setNoShow($noShow) { + $this->noShow = $noShow; + $this->markDirty(); + } + + function getNoShow() { + return $this->noShow; + } + + function setUserComment($comment) { + $this->userComment = $comment; + $this->markDirty(); + } + + function getUserComment() { + return $this->userComment; + } + + function setEmployerComment($comment) { + $this->employerComment = $comment; + $this->markDirty(); + } + + function getEmployerComment() { + return $this->employerComment; + } +} + +?> diff --git a/vaktliste/App/Mapper/Collection.php b/vaktliste/App/Mapper/Collection.php new file mode 100644 index 0000000..1fdef3c --- /dev/null +++ b/vaktliste/App/Mapper/Collection.php @@ -0,0 +1,87 @@ +rewind(); + $this->raw = $raw; + $this->total = count($raw); + } + $this->mapper = $mapper; + } + + /** + * Add an object to the collection + **/ + function add(App_Domain_DomainObject $object) { + $class = $this->targetClass(); + if (!($object instanceof $class)) { + throw new Exception("This is a {$class} collection"); + } + $this->notifyAccess(); + $this->objects[$this->total] = $object; + $this->total++; + } + + abstract function targetClass(); + + protected function notifyAccess() { + // something is coming here.. + } + + private function getRow($num) { + $this->notifyAccess(); + if ($num >= $this->total || $num < 0) { + return null; + } + if (isset($this->objects[$num])) { + return $this->objects[$num]; + } + if (isset($this->raw[$num])) { + // object has not been created yet + $this->objects[$num]=$this->mapper->createObject($this->raw[$num]); + return $this->objects[$num]; + } + } + + public function rewind() { + $this->pointer = 0; + } + + public function current() { + return $this->getRow($this->pointer); + } + + public function key() { + return $this->pointer; + } + + public function next() { + $row = $this->getRow($this->pointer); + if ($row) { + $this->pointer++; + } + return $row; + } + + public function valid() { + return (!is_null($this->current())); + } + +} + +?> \ No newline at end of file diff --git a/vaktliste/App/Mapper/DivisionCollection.php b/vaktliste/App/Mapper/DivisionCollection.php new file mode 100644 index 0000000..97c4085 --- /dev/null +++ b/vaktliste/App/Mapper/DivisionCollection.php @@ -0,0 +1,15 @@ + \ No newline at end of file diff --git a/vaktliste/App/Mapper/DivisionMapper.php b/vaktliste/App/Mapper/DivisionMapper.php new file mode 100644 index 0000000..d3b64de --- /dev/null +++ b/vaktliste/App/Mapper/DivisionMapper.php @@ -0,0 +1,93 @@ +selectStmt = self::$PDO->prepare( + "SELECT * FROM din_group WHERE id=?"); + $this->findByGroupIdStmt = self::$PDO->prepare( + "SELECT * FROM din_division INNER JOIN din_group ON din_division.id = din_group.division_id WHERE din_group.id=?"); + $this->selectAllStmt = self::$PDO->prepare( + "SELECT * FROM din_division"); + $this->insertStmt = self::$PDO->prepare( + "INSERT INTO din_division ( + name, + nicename, + hidden + ) values (?)"); + $this->updateStmt = self::$PDO->prepare( + "UPDATE din_division SET + name=?, + nicename=?, + hidden=? + WHERE id=?"); + $this->deleteStmt = self::$PDO->prepare( + "DELETE FROM din_division WHERE id=?"); + } + + protected function doCreateObject(array $array) { + $obj = new App_Domain_Division($array["id"]); + + $obj->setName($array["name"]); + $obj->setNiceName($array["nicename"]); + $obj->setHidden($array["hidden"]); + + return $obj; + } + + protected function doInsert(App_Domain_DomainObject $object) { + $this->insertStmt->bindValue(1, $object->getName()); + $this->insertStmt->bindValue(2, $object->getNiceName()); + $this->insertStmt->bindValue(3, $object->getHidden()); + + $this->insertStmt->execute(); + $id = self::$PDO->lastInsertId(); + $this->setId($id); + } + + function update(App_Domain_DomainObject $object) { + $this->insertStmt->bindValue(1, $object->getName()); + $this->insertStmt->bindValue(2, $object->getNiceName()); + $this->insertStmt->bindValue(3, $object->getHidden()); + $this->updateStmt->bindValue(4, $object->getId()); + + $this->updateStmt->execute(); + } + + protected function doDelete(App_Domain_DomainObject $object) { + $values = array($object->getId()); + $this->deleteStmt->execute($values); + } + + function selectStmt() { + return $this->selectStmt; + } + + function selectAllStmt() { + return $this->selectAllStmt; + } + + function deleteStmt() { + return $this->deleteStmt; + } + + function getCollection(array $raw) { + return new App_Mapper_DivsionCollection($raw, $this); + } + + protected function targetClass() { + return "App_Domain_Division"; + } +} + +?> \ No newline at end of file diff --git a/vaktliste/App/Mapper/DomainObjectFactory.php b/vaktliste/App/Mapper/DomainObjectFactory.php new file mode 100644 index 0000000..99bbf44 --- /dev/null +++ b/vaktliste/App/Mapper/DomainObjectFactory.php @@ -0,0 +1,7 @@ + \ No newline at end of file diff --git a/vaktliste/App/Mapper/GroupCollection.php b/vaktliste/App/Mapper/GroupCollection.php new file mode 100644 index 0000000..57850fd --- /dev/null +++ b/vaktliste/App/Mapper/GroupCollection.php @@ -0,0 +1,15 @@ + \ No newline at end of file diff --git a/vaktliste/App/Mapper/GroupMapper.php b/vaktliste/App/Mapper/GroupMapper.php new file mode 100644 index 0000000..fd73920 --- /dev/null +++ b/vaktliste/App/Mapper/GroupMapper.php @@ -0,0 +1,119 @@ +selectStmt = self::$PDO->prepare( + "SELECT * FROM din_group WHERE id=?"); + $this->findByDivisionIdStmt = self::$PDO->prepare( + "SELECT * FROM din_group WHERE division_id=?"); + $this->findByUserIdStmt = self::$PDO->prepare( + "SELECT * FROM din_group INNER JOIN din_usergrouprelationship ON din_group.id = din_usergrouprelationship.group_id WHERE din_usergrouprelationship.user_id=?"); + $this->selectAllStmt = self::$PDO->prepare( + "SELECT * FROM din_group"); + $this->insertStmt = self::$PDO->prepare( + "INSERT INTO din_group ( + name, + text, + division_id, + admin, + mailinglist + ) values (?)"); + $this->updateStmt = self::$PDO->prepare( + "UPDATE din_group SET + name=?, + text=?, + division_id=?, + admin=?, + mailinglist=? + WHERE id=?"); + $this->deleteStmt = self::$PDO->prepare( + "DELETE FROM din_group WHERE id=?"); + } + + protected function doCreateObject(array $array) { + $obj = new App_Domain_Group($array["id"]); + + $obj->setName($array["name"]); + $obj->setText($array["text"]); + $obj->setAdmin($array["admin"]); + $obj->setMailinglist($array["mailinglist"]); + + // find division and create division object + $division_mapper = new App_Domain_DivisionMapper(); + $division = $division_mapper->find($array["division_id"]); + $obj->setDivision($division); + + return $obj; + } + + protected function doInsert(App_Domain_DomainObject $object) { + $this->insertStmt->bindValue(1, $object->getName()); + $this->insertStmt->bindValue(2, $object->getText()); + $this->insertStmt->bindValue(3, $object->getDivision()->getId()); + $this->insertStmt->bindValue(4, $object->getAdmin()); + $this->insertStmt->bindValue(5, $object->getMailinglist()); + + $this->insertStmt->execute(); + $id = self::$PDO->lastInsertId(); + $this->setId($id); + } + + function update(App_Domain_DomainObject $object) { + $this->insertStmt->bindValue(1, $object->getName()); + $this->insertStmt->bindValue(2, $object->getText()); + $this->insertStmt->bindValue(3, $object->getDivision()->getId()); + $this->insertStmt->bindValue(4, $object->getAdmin()); + $this->insertStmt->bindValue(5, $object->getMailinglist()); + $this->updateStmt->bindValue(6, $object->getId()); + + $this->updateStmt->execute(); + } + + protected function doDelete(App_Domain_DomainObject $object) { + $values = array($object->getId()); + $this->deleteStmt->execute($values); + } + + function selectStmt() { + return $this->selectStmt; + } + + function selectAllStmt() { + return $this->selectAllStmt; + } + + function deleteStmt() { + return $this->deleteStmt; + } + + function findByDivisionId($division_id) { + $this->findByDivisionIdStmt->execute(array($division_id)); + return new App_Mapper_WorkShiftCollection($this->findByDivisionIdStmt->fetchAll(), $this); + } + + function findByUserId($user_id) { + $this->findByUserIdStmt->execute(array($user_id)); + return new App_Mapper_GroupCollection($this->findByUserIdStmt->fetchAll(), $this); + } + + function getCollection(array $raw) { + return new App_Mapper_GroupCollection($raw, $this); + } + + protected function targetClass() { + return "App_Domain_Group"; + } +} + +?> \ No newline at end of file diff --git a/vaktliste/App/Mapper/LocationCollection.php b/vaktliste/App/Mapper/LocationCollection.php new file mode 100644 index 0000000..cca9f8b --- /dev/null +++ b/vaktliste/App/Mapper/LocationCollection.php @@ -0,0 +1,15 @@ + \ No newline at end of file diff --git a/vaktliste/App/Mapper/LocationMapper.php b/vaktliste/App/Mapper/LocationMapper.php new file mode 100644 index 0000000..0f1ff55 --- /dev/null +++ b/vaktliste/App/Mapper/LocationMapper.php @@ -0,0 +1,81 @@ +selectStmt = self::$PDO->prepare( + "SELECT * FROM lokaler WHERE id=?"); + $this->selectAllStmt = self::$PDO->prepare( + "SELECT * FROM lokaler"); + $this->insertStmt = self::$PDO->prepare( + "INSERT INTO lokaler ( + navn + ) values (?)"); + $this->updateStmt = self::$PDO->prepare( + "UPDATE lokaler SET + navn=? + WHERE id=?"); + $this->deleteStmt = self::$PDO->prepare( + "DELETE FROM lokaler WHERE id=?"); + } + + protected function doCreateObject(array $array) { + $obj = new App_Domain_Location($array["id"]); + + $obj->setName($array["navn"]); + + return $obj; + } + + protected function doInsert(App_Domain_DomainObject $object) { + $this->insertStmt->bindValue(1, $object->getName()); + + $this->insertStmt->execute(); + $id = self::$PDO->lastInsertId(); + $this->setId($id); + } + + function update(App_Domain_DomainObject $object) { + $this->insertStmt->bindValue(1, $object->getName()); + $this->updateStmt->bindValue(2, $object->getId()); + + $this->updateStmt->execute(); + } + + protected function doDelete(App_Domain_DomainObject $object) { + $values = array($object->getId()); + $this->deleteStmt->execute($values); + } + + function selectStmt() { + return $this->selectStmt; + } + + function selectAllStmt() { + return $this->selectAllStmt; + } + + function deleteStmt() { + return $this->deleteStmt; + } + + function getCollection(array $raw) { + return new App_Mapper_LocationCollection($raw, $this); + } + + protected function targetClass() { + return "App_Domain_Location"; + } +} + +?> \ No newline at end of file diff --git a/vaktliste/App/Mapper/Mapper.php b/vaktliste/App/Mapper/Mapper.php new file mode 100644 index 0000000..9d38b03 --- /dev/null +++ b/vaktliste/App/Mapper/Mapper.php @@ -0,0 +1,99 @@ +getDSN("PDO"); + if (is_null($dsn)) { + throw new Exception("No DSN"); + } + try { + self::$PDO = new PDO($dsn["dsn"], $dsn["username"], $dsn["password"]); + self::$PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + } catch (Exception $e) { + throw new Exception("Database connection error: ". getDSN()); + } + } + } + + private function getFromMap($id) { + return App_Domain_ObjectWatcher::exists($this->targetClass(), $id); + } + + private function addToMap(App_Domain_DomainObject $obj) { + return App_Domain_ObjectWatcher::add($obj); + } + + function find($id) { + // check if object allready has been fetch from database + $old = $this->getFromMap($id); + if ($old) { + return $old; + } + + // get object from database + $this->selectStmt()->execute(array($id)); + $array = $this->selectStmt()->fetch(); + $this->selectStmt()->closeCursor(); + if (!is_array($array)) { + return null; + } + if (!isset($array['id'])) { + return null; + } + $object = $this->createObject($array); + $object->markClean(); + return $object; + } + + function findAll() { + $this->selectAllStmt()->execute(array()); + return $this->getCollection( $this->selectAllStmt()->fetchAll( PDO::FETCH_ASSOC ) ); + } + + function createObject($array) { + $old = $this->getFromMap($array['id']); + if ($old) { return $old; } + + // construct object + $obj = $this->doCreateObject($array); + + // add object to object watcher map + $this->addToMap($obj); + $obj->markClean(); + return $obj; + } + + function insert(App_Domain_DomainObject $obj) { + $this->doInsert($obj); + $this->addToMap($obj); + $obj->markClean(); + } + + function delete(App_Domain_DomainObject $obj) { + $this->doDelete($obj); + //$this->removeFromMap($obj); + } + + abstract function update(App_Domain_DomainObject $object); + protected abstract function doCreateObject(array $array); + protected abstract function doInsert(App_Domain_DomainObject $object); + protected abstract function doDelete(App_Domain_DomainObject $object); + protected abstract function targetClass(); + protected abstract function selectStmt(); + protected abstract function selectAllStmt(); + protected abstract function deleteStmt(); + abstract function getCollection(array $raw); +} + +?> \ No newline at end of file diff --git a/vaktliste/App/Mapper/UserCollection.php b/vaktliste/App/Mapper/UserCollection.php new file mode 100644 index 0000000..2c3143d --- /dev/null +++ b/vaktliste/App/Mapper/UserCollection.php @@ -0,0 +1,14 @@ + \ No newline at end of file diff --git a/vaktliste/App/Mapper/UserMapper.php b/vaktliste/App/Mapper/UserMapper.php new file mode 100644 index 0000000..ef058c4 --- /dev/null +++ b/vaktliste/App/Mapper/UserMapper.php @@ -0,0 +1,126 @@ +selectStmt = self::$PDO->prepare( + "SELECT * FROM din_user WHERE id=?"); + $this->selectAllStmt = self::$PDO->prepare( + "SELECT * FROM din_user"); + //$this->updateStmt = self::$PDO->prepare( + // "UPDATE din_user SET + // username=?, + // password=?, + // firstname=?, + // lastname=?, + // addresstype='no', + // valid_address=?, + // email=?, + // birthdate=?, + // placeOfStudy=?, + // passwordReset=?, + // division_id_request=? + // WHERE id=?"); + //$this->insertStmt = self::$PDO->prepare( + // "INSERT INTO din_user ( + // cardno, username, password, firstname, lastname, addresstype, valid_address, email, birthdate, placeOfStudy, passwordReset, division_id_request + // ) values (?)"); + //$this->deleteStmt = self::$PDO->prepare( + // "DELETE FROM din_user WHERE id=?"); + $this->findByLoginStmt = self::$PDO->prepare( + "SELECT * FROM din_user WHERE username=? AND ( password=PASSWORD(?) or password=OLD_PASSWORD(?) )"); + } + + protected function doCreateObject(array $array) { + $obj = new App_Domain_User($array["id"]); + $obj->setUsername($array["username"]); + $obj->setPassword($array["password"]); + $obj->setFirstname($array["firstname"]); + $obj->setLastname($array["lastname"]); + $obj->setValidaddress($array["valid_address"]); + $obj->setEmail($array["email"]); + $obj->setBirthdate($array["birthdate"]); + $obj->setPlaceOfStudy($array["placeOfStudy"]); + $obj->setPasswordreset($array["passwordReset"]); + $obj->setDivisionIdRequest($array["division_id_request"]); + return $obj; + } + + protected function doInsert(App_Domain_DomainObject $object) { + $values = array($object->getUsername()); + throw new Excepetion("UserMapper::doInsert() failure: UserMapper is read only!"); + //$this->insertStmt->execute($values); + //$id = self::$PDO->lastInsertId(); + //$object->setId($id); + } + + function update(App_Domain_DomainObject $object) { + $values = array( + $object->getUsername(), + $object->getPassword(), + $object->getFirstname(), + $object->getLastname(), + $object->getValidAddress(), + $object->getEmail(), + $object->getBirthdate(), + $object->getPlaceOfStudy(), + $object->getPasswordreset(), + $object->getDivisionIdRequest(), + $object->getId() + ); + throw new Excepetion("UserMapper:update() failure: UserMapper is read only!"); + //$this->updateStmt->execute($values); + } + + protected function doDelete(App_Domain_DomainObject $object) { + $values = array($object->getId()); + throw new Excepetion("UserMapper::doDelete() failure: UserMapper is read only!"); + //$this->deleteStmt->execute($values); + } + + function selectStmt() { + return $this->selectStmt; + } + + function selectAllStmt() { + return $this->selectAllStmt; + } + + function deleteStmt() { + throw new Excepetion("UserMapper::deleteStmt() failure: UserMapper is read only!"); + //return $this->deleteStmt; + } + + function findByLogin($username, $password) { + $this->findByLoginStmt->execute(array($username, $password, $password)); + $array = $this->findByLoginStmt->fetch(); + $this->findByLoginStmt->closeCursor(); + if (!is_array($array)) { + return null; + } + if (!isset($array['id'])) { + return null; + } + return $this->createObject($array); + } + + function getCollection(array $raw) { + return new App_Mapper_UserCollection($raw, $this); + } + + protected function targetClass() { + return "App_Domain_User"; + } +} + +?> \ No newline at end of file diff --git a/vaktliste/App/Mapper/WorkSalaryTypeCollection.php b/vaktliste/App/Mapper/WorkSalaryTypeCollection.php new file mode 100644 index 0000000..2085441 --- /dev/null +++ b/vaktliste/App/Mapper/WorkSalaryTypeCollection.php @@ -0,0 +1,15 @@ + \ No newline at end of file diff --git a/vaktliste/App/Mapper/WorkSalaryTypeMapper.php b/vaktliste/App/Mapper/WorkSalaryTypeMapper.php new file mode 100644 index 0000000..2ad95a9 --- /dev/null +++ b/vaktliste/App/Mapper/WorkSalaryTypeMapper.php @@ -0,0 +1,85 @@ +selectStmt = self::$PDO->prepare( + "SELECT * FROM work_salarytype WHERE id=?"); + $this->selectAllStmt = self::$PDO->prepare( + "SELECT * FROM work_salarytype"); + $this->insertStmt = self::$PDO->prepare( + "INSERT INTO work_salarytype ( + title, hourly_rate + ) values (?, ?)"); + $this->updateStmt = self::$PDO->prepare( + "UPDATE work_salarytype SET + title=?, + hourly_rate=? + WHERE id=?"); + $this->deleteStmt = self::$PDO->prepare( + "DELETE FROM work_salarytype WHERE id=?"); + } + + protected function doCreateObject(array $array) { + $obj = new App_Domain_WorkSalaryType($array["id"]); + + $obj->setTitle($array["title"]); + $obj->setHourlyRate($array["hourly_rate"]); + + return $obj; + } + + protected function doInsert(App_Domain_DomainObject $object) { + $this->insertStmt->bindValue(1, $object->getTitle()); + $this->insertStmt->bindValue(2, $object->getHourlyRate()); + + $this->insertStmt->execute(); + $id = self::$PDO->lastInsertId(); + $this->setId($id); + } + + function update(App_Domain_DomainObject $object) { + $this->insertStmt->bindValue(1, $object->getTitle()); + $this->insertStmt->bindValue(2, $object->getHourlyRate()); + $this->updateStmt->bindValue(3, $object->getId()); + + $this->updateStmt->execute(); + } + + protected function doDelete(App_Domain_DomainObject $object) { + $values = array($object->getId()); + $this->deleteStmt->execute($values); + } + + function selectStmt() { + return $this->selectStmt; + } + + function selectAllStmt() { + return $this->selectAllStmt; + } + + function deleteStmt() { + return $this->deleteStmt; + } + + function getCollection(array $raw) { + return new App_Mapper_WorkSalaryTypeCollection($raw, $this); + } + + protected function targetClass() { + return "App_Domain_WorkSalaryType"; + } +} + +?> \ No newline at end of file diff --git a/vaktliste/App/Mapper/WorkShiftCollection.php b/vaktliste/App/Mapper/WorkShiftCollection.php new file mode 100644 index 0000000..e63a5a5 --- /dev/null +++ b/vaktliste/App/Mapper/WorkShiftCollection.php @@ -0,0 +1,15 @@ + \ No newline at end of file diff --git a/vaktliste/App/Mapper/WorkShiftMapper.php b/vaktliste/App/Mapper/WorkShiftMapper.php new file mode 100644 index 0000000..8c102d6 --- /dev/null +++ b/vaktliste/App/Mapper/WorkShiftMapper.php @@ -0,0 +1,140 @@ +selectStmt = self::$PDO->prepare( + "SELECT * FROM work_shift WHERE id=?"); + $this->selectAllStmt = self::$PDO->prepare( + "SELECT * FROM work_shift"); + $this->findByGroupIdStmt = self::$PDO->prepare( + "SELECT * FROM work_shift WHERE group_id=?"); + $this->updateStmt = self::$PDO->prepare( + "UPDATE work_shift SET + starts=?, + ends=?, + group_id=?, + location_id=?, + active=?, + title=?, + comment=?, + num_workers=?, + locked=?, + autoassign_workers=?, + salarytype_id=? + WHERE id=?"); + $this->insertStmt = self::$PDO->prepare( + "INSERT INTO work_shift ( + starts, ends, group_id, location_id, active, title, comment, num_workers, locked, autoassign_workers, salarytype_id + ) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); + $this->deleteStmt = self::$PDO->prepare( + "DELETE FROM work_shift WHERE id=?"); + } + + protected function doCreateObject(array $array) { + $obj = new App_Domain_WorkShift($array["id"]); + + $obj->setStarts(new DateTime($array["starts"])); + $obj->setEnds(new DateTime($array["ends"])); + $obj->setActive($array["active"]); + $obj->setTitle($array["title"]); + $obj->setComment($array["comment"]); + $obj->setNumWorkers($array["num_workers"]); + $obj->setLocked($array["locked"]); + $obj->setAutoAssignWorkers($array["autoassign_workers"]); + + // find group and create division object + $group_mapper = new App_Domain_GroupMapper(); + $group = $group_mapper->find($array["group_id"]); + $obj->setGroup($group); + + // find location and create location object + $location_mapper = new App_Domain_LocationMapper(); + $location = $location_mapper->find($array["location_id"]); + $obj->setLocation($location); + + // find salary type and create salary type object + $salarytype_mapper = new App_Domain_WorkSalaryTypeMapper(); + $salarytype = $salarytype_mapper->find($array["slarytype_id"]); + $obj->setSalaryType($salarytype); + + return $obj; + } + + protected function doInsert(App_Domain_DomainObject $object) { + $this->insertStmt->bindValue(1, $object->getStarts()->format(self::DATETIME_FORMAT)); + $this->insertStmt->bindValue(2, $object->getEnds()->format(self::DATETIME_FORMAT)); + $this->insertStmt->bindValue(3, $object->getGroup()->getId()); + $this->insertStmt->bindValue(4, $object->getLocation()->getId()); + $this->insertStmt->bindValue(5, $object->getActive()); + $this->insertStmt->bindValue(6, $object->getTitle()); + $this->insertStmt->bindValue(7, $object->getComment()); + $this->insertStmt->bindValue(8, $object->getNumWorkers()); + $this->insertStmt->bindValue(9, $object->getLocked()); + $this->insertStmt->bindValue(10, $object->getAutoAssignWorkers()); + $this->insertStmt->bindValue(11, $object->getSalaryType()->getId()); + + $this->insertStmt->execute(); + $id = self::$PDO->lastInsertId(); + $this->setId($id); + } + + function update(App_Domain_DomainObject $object) { + $this->updateStmt->bindValue(1, $object->getStarts()->format(self::DATETIME_FORMAT)); + $this->updateStmt->bindValue(2, $object->getEnds()->format(self::DATETIME_FORMAT)); + $this->updateStmt->bindValue(3, $object->getGroup()->getId()); + $this->updateStmt->bindValue(4, $object->getLocation()->getId()); + $this->updateStmt->bindValue(5, $object->getActive()); + $this->updateStmt->bindValue(6, $object->getTitle()); + $this->updateStmt->bindValue(7, $object->getComment()); + $this->updateStmt->bindValue(8, $object->getNumWorkers()); + $this->updateStmt->bindValue(9, $object->getLocked()); + $this->updateStmt->bindValue(10, $object->getAutoAssignWorkers()); + $this->updateStmt->bindValue(11, $object->getSalaryType()->getId()); + $this->updateStmt->bindValue(12, $object->getId()); + + $this->updateStmt->execute(); + } + + protected function doDelete(App_Domain_DomainObject $object) { + $values = array($object->getId()); + $this->deleteStmt->execute($values); + } + + function selectStmt() { + return $this->selectStmt; + } + + function selectAllStmt() { + return $this->selectAllStmt; + } + + function deleteStmt() { + return $this->deleteStmt; + } + + function findByGroupId($group_id) { + $this->findByGroupIdStmt->execute(array($group_id)); + return new App_Mapper_WorkShiftCollection($this->findByGroupIdStmt->fetchAll(), $this); + } + + function getCollection(array $raw) { + return new App_Mapper_WorkShiftCollection($raw, $this); + } + + protected function targetClass() { + return "App_Domain_WorkShift"; + } +} + +?> \ No newline at end of file diff --git a/vaktliste/App/Mapper/WorkShiftUpdateCollection.php b/vaktliste/App/Mapper/WorkShiftUpdateCollection.php new file mode 100644 index 0000000..43a3801 --- /dev/null +++ b/vaktliste/App/Mapper/WorkShiftUpdateCollection.php @@ -0,0 +1,14 @@ + \ No newline at end of file diff --git a/vaktliste/App/Mapper/WorkShiftUpdateMapper.php b/vaktliste/App/Mapper/WorkShiftUpdateMapper.php new file mode 100644 index 0000000..8a0ff8b --- /dev/null +++ b/vaktliste/App/Mapper/WorkShiftUpdateMapper.php @@ -0,0 +1,109 @@ +selectStmt = self::$PDO->prepare( + "SELECT * FROM work_shiftupdate WHERE id=?"); + $this->selectAllStmt = self::$PDO->prepare( + "SELECT * FROM work_shiftupdate"); + $this->findByShiftIdStmt = self::$PDO->prepare( + "SELECT * FROM work_shiftupdate WHERE shift_id=?"); + $this->updateStmt = self::$PDO->prepare( + "UPDATE work_shiftupdate SET + shift_id=?, + update_time=?, + user_id=?, + update_text=? + WHERE id=?"); + $this->insertStmt = self::$PDO->prepare( + "INSERT INTO work_shiftupdate ( + shift_id, update_time, user_id, update_text + ) values (?, ?, ?, ?)"); + $this->deleteStmt = self::$PDO->prepare( + "DELETE FROM work_shiftupdate WHERE id=?"); + } + + protected function doCreateObject(array $array) { + $obj = new App_Domain_WorkShiftUpdate($array["id"]); + + // find shift and create workshift object + $shift_mapper = new App_Mapper_WorkShiftMapper(); + $shift = $shift_mapper->find($array["shift_id"]); + $obj->setShift($shift); + + $obj->setUpdateTime(new DateTime($array["update_time"])); + + // find user and create user object + $user_mapper = new App_Domain_User(); + $user = $user_mapper->find($array["user_id"]); + $obj->setUser($user); + + $obj->setUpdateText($array["text"]); + + return $obj; + } + + protected function doInsert(App_Domain_DomainObject $object) { + $this->insertStmt->bindValue(1, $object->getShift()->getId()); + $this->insertStmt->bindValue(2, $object->getUpdateTime()->format(self::DATETIME_FORMAT)); + $this->insertStmt->bindValue(3, $object->getUser()->getId()); + $this->insertStmt->bindValue(4, $object->getUpdateText()); + + $this->insertStmt->execute(); + $id = self::$PDO->lastInsertId(); + $this->setId($id); + } + + function update(App_Domain_DomainObject $object) { + $this->insertStmt->bindValue(1, $object->getShift()->getId()); + $this->insertStmt->bindValue(2, $object->getUpdateTime()->format(self::DATETIME_FORMAT)); + $this->insertStmt->bindValue(3, $object->getUser()->getId()); + $this->insertStmt->bindValue(4, $object->getUpdateText()); + $this->updateStmt->bindValue(5, $object->getId()); + + $this->updateStmt->execute(); + } + + protected function doDelete(App_Domain_DomainObject $object) { + $values = array($object->getId()); + $this->deleteStmt->execute($values); + } + + function selectStmt() { + return $this->selectStmt; + } + + function selectAllStmt() { + return $this->selectAllStmt; + } + + function deleteStmt() { + return $this->deleteStmt; + } + + function findByShiftId($shift_id) { + $this->findByShiftIdStmt->execute(array($shift_id)); + return new App_Mapper_WorkShiftUpdateCollection($this->findByShiftIdStmt->fetchAll(), $this); + } + + function getCollection(array $raw) { + return new App_Mapper_WorkShiftUpdateCollection($raw, $this); + } + + protected function targetClass() { + return "App_Domain_WorkShiftUpdate"; + } +} + +?> \ No newline at end of file diff --git a/vaktliste/App/Mapper/WorkShiftWorkerCollection.php b/vaktliste/App/Mapper/WorkShiftWorkerCollection.php new file mode 100644 index 0000000..074d759 --- /dev/null +++ b/vaktliste/App/Mapper/WorkShiftWorkerCollection.php @@ -0,0 +1,15 @@ + \ No newline at end of file diff --git a/vaktliste/App/Mapper/WorkShiftWorkerMapper.php b/vaktliste/App/Mapper/WorkShiftWorkerMapper.php new file mode 100644 index 0000000..ec83588 --- /dev/null +++ b/vaktliste/App/Mapper/WorkShiftWorkerMapper.php @@ -0,0 +1,123 @@ +selectStmt = self::$PDO->prepare( + "SELECT * FROM work_shiftworker WHERE id=?"); + $this->selectAllStmt = self::$PDO->prepare( + "SELECT * FROM work_shiftworker"); + $this->findByShiftIdStmt = self::$PDO->prepare( + "SELECT * FROM work_shiftworker WHERE shift_id=?"); + $this->findByUserIdStmt = self::$PDO->prepare( + "SELECT * FROM work_shiftworker WHERE user_id=?"); + $this->insertStmt = self::$PDO->prepare( + "INSERT INTO work_shiftworker ( + shift_id, user_id, assigned, no_show, user_comment, employer_comment + ) values (?, ?, ?, ?, ?, ?)"); + $this->updateStmt = self::$PDO->prepare( + "UPDATE work_shiftworker SET + shift_id=?, + user_id=?, + assigned=?, + no_show=?, + user_comment=?, + employer_comment=? + WHERE id=?"); + $this->deleteStmt = self::$PDO->prepare( + "DELETE FROM work_shiftworker WHERE id=?"); + } + + protected function doCreateObject(array $array) { + $obj = new App_Domain_WorkShiftWorker($array["id"]); + + // find shift and create workshift object + $shift_mapper = new App_Mapper_WorkShiftMapper(); + $shift = $shift_mapper->find($array["shift_id"]); + $obj->setShift($shift); + + // find user and create user object + $user_mapper = new App_Domain_User(); + $user = $user_mapper->find($array["user_id"]); + $obj->setUser($user); + + $obj->setAssigned($array["assigned"]); + $obj->setNoShow($array["no_show"]); + $obj->setUserComment($array["user_comment"]); + $obj->setEmployerComment($array["employer_comment"]); + + return $obj; + } + + protected function doInsert(App_Domain_DomainObject $object) { + $this->insertStmt->bindValue(1, $object->getShift()->getId()); + $this->insertStmt->bindValue(2, $object->getUser()->getId()); + $this->insertStmt->bindValue(3, $object->getAssigned()); + $this->insertStmt->bindValue(4, $object->getNoShow()); + $this->insertStmt->bindValue(5, $object->getUserComment()); + $this->insertStmt->bindValue(6, $object->getEmployerComment()); + + $this->insertStmt->execute(); + $id = self::$PDO->lastInsertId(); + $this->setId($id); + } + + function update(App_Domain_DomainObject $object) { + $this->insertStmt->bindValue(1, $object->getShift()->getId()); + $this->insertStmt->bindValue(2, $object->getUser()->getId()); + $this->insertStmt->bindValue(3, $object->getAssigned()); + $this->insertStmt->bindValue(4, $object->getNoShow()); + $this->insertStmt->bindValue(5, $object->getUserComment()); + $this->insertStmt->bindValue(6, $object->getEmployerComment()); + $this->updateStmt->bindValue(7, $object->getId()); + + $this->updateStmt->execute(); + } + + protected function doDelete(App_Domain_DomainObject $object) { + $values = array($object->getId()); + $this->deleteStmt->execute($values); + } + + function selectStmt() { + return $this->selectStmt; + } + + function selectAllStmt() { + return $this->selectAllStmt; + } + + function deleteStmt() { + return $this->deleteStmt; + } + + function findByShiftId($shift_id) { + $this->findByShiftIdStmt->execute(array($shift_id)); + return new App_Mapper_WorkShiftWorkerCollection($this->findByShiftIdStmt->fetchAll(), $this); + } + + function findByUserId($user_id) { + $this->findByUserIdStmt->execute(array($user_id)); + return new App_Mapper_WorkShiftWorkerCollection($this->findByUserIdStmt->fetchAll(), $this); + } + + function getCollection(array $raw) { + return new App_Mapper_WorkShiftWorkerCollection($raw, $this); + } + + protected function targetClass() { + return "App_Domain_WorkShiftWorker"; + } +} + +?> \ No newline at end of file diff --git a/vaktliste/App/View/Common/footer.php b/vaktliste/App/View/Common/footer.php new file mode 100644 index 0000000..c3c1f9c --- /dev/null +++ b/vaktliste/App/View/Common/footer.php @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/vaktliste/App/View/Common/header.php b/vaktliste/App/View/Common/header.php new file mode 100644 index 0000000..03b642e --- /dev/null +++ b/vaktliste/App/View/Common/header.php @@ -0,0 +1,98 @@ + + + + + + + + <?php print App_Base_ApplicationRegistry::getPageTitle(); ?> + + + +
+ + +
+ +
\ No newline at end of file diff --git a/vaktliste/App/View/Common/menu.php b/vaktliste/App/View/Common/menu.php new file mode 100644 index 0000000..c57e6f7 --- /dev/null +++ b/vaktliste/App/View/Common/menu.php @@ -0,0 +1,38 @@ + + + \ No newline at end of file diff --git a/vaktliste/App/View/ViewHelper.php b/vaktliste/App/View/ViewHelper.php new file mode 100644 index 0000000..aba7baa --- /dev/null +++ b/vaktliste/App/View/ViewHelper.php @@ -0,0 +1,10 @@ + diff --git a/vaktliste/App/View/calendar.php b/vaktliste/App/View/calendar.php new file mode 100644 index 0000000..dfed522 --- /dev/null +++ b/vaktliste/App/View/calendar.php @@ -0,0 +1,37 @@ +getObject('currentUser'); +//$venue = $request->getObject('venue'); + +include_once("Calendar.php"); +$calendar = new Calendar("barshifts"); +//$month = scriptParam("month"); +if (!empty($month)){ + $year = substr($month, 0, 4); + $month = substr($month, 4, 2); +}else { + $year = date("Y"); + $month = date("m"); +} + +include("Common/header.php"); +?> + +
+ +Vaktliste for " . $month . " " . $year . "\n"; + + print $request->getFeedbackString("
"); + + $calendar->display($year, $month); + +?> + +
+ + diff --git a/vaktliste/App/View/login.php b/vaktliste/App/View/login.php new file mode 100644 index 0000000..d0f6b66 --- /dev/null +++ b/vaktliste/App/View/login.php @@ -0,0 +1,49 @@ + + +
+

Velkommen til vaktlisten!

+

Du må være logget inn for å kunne gjøre noe her.

+ +getFeedback()) > 0) { + print "
\n"; + print "

Beskjeder

\n"; + print "
    \n"; + print "
  • " . $request->getFeedbackString("
  • \n
  • ") . "
  • \n"; + print "
\n"; + print "
\n"; + } +?> + +
+
+ + + + + + + + + + + + + + +
 
+
+
+ +

Mangler du brukernavn eller passord? Få tilsendt brukernavn og passord hvis du er registrert fra før, eller registrér deg!

+ +
+ + \ No newline at end of file diff --git a/vaktliste/App/View/test.php b/vaktliste/App/View/test.php new file mode 100644 index 0000000..695231e --- /dev/null +++ b/vaktliste/App/View/test.php @@ -0,0 +1,14 @@ + + +Apptest + + +

Welcome

+ +getFeedback() as $feedback) { + print $feedback . "
"; +} +?> + + \ No newline at end of file diff --git a/vaktliste/App/View/welcome.php b/vaktliste/App/View/welcome.php new file mode 100644 index 0000000..52890b4 --- /dev/null +++ b/vaktliste/App/View/welcome.php @@ -0,0 +1,21 @@ +getObject('currentUser'); +//$venue = $request->getObject('venue'); + +include("Common/header.php"); +?> + +
+

Velkommen til vaktlisten!

+Du er logget inn som " . $currentUser->getName() . ".

\n"; + print $request->getFeedbackString(""); +?> + +
+ + \ No newline at end of file diff --git a/vaktliste/Calendar.php b/vaktliste/Calendar.php new file mode 100644 index 0000000..044848b --- /dev/null +++ b/vaktliste/Calendar.php @@ -0,0 +1,189 @@ +__construct($type); + } + + public function __construct($type){ + $this->type = $type; + } + + public function display($year, $month){ + $previousYear = $year -1 . $month; + $previousMonth = date("Ym", strtotime("-1 month", strtotime("$year-$month-01"))); + $nextMonth = date("Ym", strtotime("+1 month", strtotime("$year-$month-01"))); + $nextYear = $year +1 . $month; + + $fDate = "$year-$month-01"; + + $dayOfWeek = date("w", strtotime("$year-$month-01")); + if ($dayOfWeek == "0"){ + $dayOfWeek = 7; + } + $lastDayOfMonth = date("t", strtotime("$year-$month-01")); + $weekNumber = date("W", strtotime("$year-$month-01")); + +?> +
+ + +

+
+ _displayCalendarOptions(); ?> + + + + + + + + + + + + + + +printPassiveDay(date("d", strtotime("$year-$month-01 -$offset days"))); + } +// $row = $list->fetchRow(DB_FETCHMODE_ORDERED); + while ($date <= $lastDayOfMonth) { + $this->printOpenActiveDay($date); + +/* while ($row != NULL && $row[2] == $date){ + switch ($this->type){ + case 'events': +?> +
+ + + + +
+ +
+ + + + +
+ +
+ + + +
+displayCalendar($year, $month); + break; + + } + //$row = $list->fetchRow(DB_FETCHMODE_ORDERED); + } +*/ + $this->printCloseActiveDay(); + $date++; + if ($i++ % 7 == 1){ + $weekNumber = date("W", strtotime("$year-$month-$date")); + print(""); + } + } + + $date = 1; + while ($i++ % 7 != 1){ + $this->printPassiveDay($date++); + } + $this->printPassiveDay($date++); + +?> + + +
UkeMandagTirsdagOnsdagTorsdagFredagLørdagSøndag
".$weekNumber."
+type){ + case 'events': + break; + + case 'concerts': + break; + + case 'all': + ?> +
+
+ +
+ +
+
+
+

$day

"); + } + + function printOpenActiveDay($day) { + print ("

$day

"); + } + + function printCloseActiveDay() { + print (""); + } + +} + +?> \ No newline at end of file diff --git a/vaktliste/index.php b/vaktliste/index.php new file mode 100644 index 0000000..8938648 --- /dev/null +++ b/vaktliste/index.php @@ -0,0 +1,38 @@ + \ No newline at end of file