public function createEvent($event_name, $event_date, $startTime, $endTime) { $eventName = InputValidator::validate_input($event_name); $error = ""; if ($event_name == NULL) { $error .= "@1Event name cannot be empty! "; } if ($event_date == NULL) { $error .= "@2Event date must be specified correctly (YYYY-MM-DD)! "; } if ($startTime == NULL) { $error .= "@3Event start time must be specified correctly (HH:MM)! "; } if ($endTime == NULL) { $error .= "@4Event end time must be specified correctly (HH:MM)!"; } if ($endTime != NULL && $startTime >= $endTime) { $error .= "@4Event end time cannot be before event start time!"; } if ($event_name == NULL || $event_date == NULL || $startTime >= $endTime || $startTime == NULL || $endTime == NULL) { throw new Exception(trim($error)); } else { //2. load all data $pm = new PersistenceEventRegistration(); $rm = $pm->loadDataFromStore(); //3 Add event $event = new Event($eventName, $event_date, $startTime, $endTime); $rm->addEvent($event); //4 Write all of the data $pm->writeDataToStore($rm); } }
public function createEvent($event_name, $event_date, $starttime, $endtime) { // 1. Validate Input $name = InputValidator::validate_input($event_name); // Reformat Input date('Y-m-d', strtotime($event_date)); date('H:i', strtotime($starttime)); date('H:i', strtotime($endtime)); $error = ""; // Check Validity if ($name == null || strlen(preg_replace('/\\s+/', '', $name)) == 0) { $error = $error . "@1Event name cannot be empty! "; } if (strtotime(preg_replace('/\\s+/', '', $event_date)) == false) { $error = $error . "@2Event date must be specified correctly (YYYY-MM-DD)! "; } if (strtotime(preg_replace('/\\s+/', '', $starttime)) == false) { $error = $error . "@3Event start time must be specified correctly (HH:MM)! "; } if (strtotime(preg_replace('/\\s+/', '', $endtime)) == false) { $error = $error . "@4Event end time must be specified correctly (HH:MM)!"; } if (strtotime($endtime) < strtotime($starttime)) { $error = $error . "@4Event end time cannot be before event start time!"; } if (strlen($error) == 0) { // 2. Load all of the data $pm = new PersistenceEventRegistration(); $rm = $pm->loadDataFromStore(); // 3. Add the new event $event = new Event($name, $event_date, $starttime, $endtime); $rm->addEvent($event); // 4. Write all of the data $pm->writeDataToStore($rm); } else { throw new Exception($error); } }