示例#1
0
 public function register($aParticipant, $aEvent)
 {
     //1.Load all of the data
     $pm = new PersistenceEventRegistration();
     $rm = $pm->loadDataFromStore();
     //2.find the participant
     $myparticipant = Null;
     foreach ($rm->getParticipants() as $participant) {
         if (strcmp($participant->getName(), $aParticipant) == 0) {
             $myparticipant = $participant;
             break;
         }
     }
     //3.find the event
     $myevent = NULL;
     foreach ($rm->getEvents() as $event) {
         if (strcmp($event->getName(), $aEvent) == 0) {
             $myevent = $event;
             break;
         }
     }
     //4.Register for event
     $error = "";
     if ($myparticipant != NULL && $myevent != NULL) {
         $myregistration = new Registration($myparticipant, $myevent);
         $rm->addRegistration($myregistration);
         $pm->writeDataToStore($rm);
     } else {
         if ($myparticipant == NULL) {
             $error .= "@1Participant ";
             if ($aParticipant != NULL) {
                 $error .= $aParticipant;
             }
             $error .= " not found! ";
         }
         if ($myevent == NULL) {
             $error .= "@2Event ";
             if ($aEvent != NULL) {
                 $error .= $aEvent;
             }
             $error .= " not found!";
         }
         throw new Exception(trim($error));
     }
 }
示例#2
0
		<meta charset="UTF-8">
		<title>Event Registration</title>
		<style>
		.error {color: #FF0000;}
		</style>
	</head>
	<body>
	<?php 
require_once 'model\\RegistrationManager.php';
require_once 'model\\Participant.php';
require_once 'model\\Event.php';
require_once 'persistence\\PersistenceEventRegistration.php';
require_once 'model/Participant.php';
session_start();
//Retrieve the data from the model
$pm = new PersistenceEventRegistration();
$rm = $pm->loadDataFromStore();
echo "<form action='register.php' method='post'>";
echo "<p>Name? <select name='participantspinner'>";
foreach ($rm->getParticipants() as $participant) {
    echo "<option>" . $participant->getName() . "</option>";
}
echo "</select><span class='error'>";
if (isset($_SESSION['errorRegisterParticipant']) && !empty($_SESSION['errorRegisterParticipant'])) {
    echo " * " . $_SESSION["errorRegisterParticipant"];
}
echo "</span></p>";
echo "<p>Event? <select name='eventspinner'>";
foreach ($rm->getEvents() as $event) {
    echo "<option>" . $event->getName() . "</option>";
}