public function renderShow($id) { $service = new TripService($this->entityManager); $trip = $service->find($id); $this->template->trip = $trip; try { $eventService = new EventService(); $config = Environment::getConfig('api'); $events = $eventService->getEvents($trip->arrival, new DateTime(), new EventfulMapper($config->eventfulUser, $config->eventfulPassword, $config->eventfulKey)); $this->template->events = $events; } catch (InvalidStateException $e) { $this->template->events = array(); } $articleService = new ArticleService($this->entityManager); $this->template->article = $articleService->buildArticle($trip->arrival, new ArticleWikipediaMapper()); try { $airportMapper = new AirportTravelMathMapper(); $airportService = new AirportService(); $locationService = new LocationService(); $coordinates = $locationService->getCoordinates($trip->getDeparture()); $from = $airportService->searchNearestAirport($airportMapper, $coordinates['latitude'], $coordinates['longitude']); $coordinates = $locationService->getCoordinates($trip->getArrival()); $to = $airportService->searchNearestAirport($airportMapper, $coordinates['latitude'], $coordinates['longitude']); $flightMapper = new FlightKayakMapper(); $flightService = new FlightService($this->entityManager); $depart_date = new DateTime('now'); $return_date = new DateTime('+1 week'); $this->template->flights = $flightService->buildFlights($flightMapper, $from, $to, $depart_date, $return_date, '1', 'e', 'n'); } catch (FlightException $e) { $this->template->flightsError = "Connection with search system <a href='http://kayak.com'>Kayak</a> failed."; } catch (AirportException $e) { $this->template->flightsError = $e->getMessage(); } }
/** * @param $request * @return SS_HTTPResponse */ public function events($request) { $response = Controller::curr()->getResponse(); $service = new EventService($request); $objects = $service->processRequest(); $responseData = array('objects' => $service->formatObjects($service->paginateObjects($objects)), 'count' => ceil($objects->count() / $service->getItemsPerPage())); $response = $response->setBody(json_encode($responseData)); return $response; }
public function mark_paid($email = false) { $id = mysql_real_escape_string($this->id); $me = EventService::find_by_id($id); if ($me and !$me->deleted) { $this->paid = true; $this->save(); } }
protected static function load_event_service($signup_id, $id = null) { if (!$id) { $id = $_GET['id']; } $id = mysql_real_escape_string($id); $signup_id = mysql_real_escape_string($signup_id); $service = EventService::find("event_services.id = '{$id}' AND event_signups.id = '{$signup_id}'"); if ($service) { return $service; } else { Error404(); } }
public function edit($id = null) { $signup = self::load_signup($id); if ($this->post) { $signup->lift_required = $_POST['lift_required']; $signup->paid = $_POST['paid']; $signup->voucher_code = $_POST['voucher_code']; $signup->voucher = $_POST['voucher']; if ($_POST['ticket'] != $signup->event_ticket_id) { // Ticket is different, fetch the new one and remove any services that // aren't allowed for that type. If there are services that are paid // for, raise an error instead $event_id = mysql_real_escape_string($signup->event->id); $ticket_id = mysql_real_escape_string($_POST['ticket']); $ticket = EventTicket::find("event_tickets.event_id = {$event_id} AND event_tickets.id = {$ticket_id}"); if ($ticket) { if (!$ticket->participant) { $signup_id = mysql_real_escape_string($signup->id); $paid_services = EventService::find_all("event_services.event_signup_id = {$signup_id} AND services.participant = true AND event_services.paid = true AND services.cost > 0"); if (count($paid_services) == 0) { $services = EventService::find_all("event_services.event_signup_id = {$signup_id} AND services.participant = true AND (event_services.paid = false OR services.cost = 0)"); foreach ($services as $service) { $service->destroy(); } $signup->event_ticket_id = $ticket->id; $signup->event_ticket = $ticket; } else { $signup->add_error("This signup has paid participant services, it cannot be changed to spectator"); } } else { $signup->event_ticket_id = $ticket->id; $signup->event_ticket = $ticket; } } } if ($signup->save()) { Site::Flash("notice", "The signup has been edited"); Redirect("admin/signups/{$signup->id}"); } } $tickets = array(); foreach ($signup->event->tickets() as $ticket) { $tickets[$ticket->id] = "({$ticket->id}) {$ticket->name}"; } $this->assign("tickets", $tickets); $this->assign("signup", $signup); $this->title = "Edit {$signup->event->name} Signup"; $this->render("event_signup/edit.tpl"); }
public function filtered_services($filter = "all", $reload = false) { if ($filter == "all") { return $this->event_services($reload); } elseif ($filter == "paid") { if ($reload or !$this->paid_cache) { $id = mysql_real_escape_string($this->id); $this->paid_cache = EventService::find_all("event_services.service_id = '{$id}' AND event_services.paid = true"); } return $this->paid_cache; } elseif ($filter == "unpaid") { if ($reload or !$this->unpaid_cache) { $id = mysql_real_escape_string($this->id); $this->unpaid_cache = EventService::find_all("event_services.service_id = '{$id}' AND event_services.paid = false"); } return $this->unpaid_cache; } }
protected static function get_fields() { return implode(', ', array(self::select_fields(), DiscountCode::select_fields(), Cart::select_fields(), CartItem::select_fields(), EventSignup::select_fields(), EventService::select_fields(), User::select_fields())); }
public function add() { $signup = self::load_signup(); if ($signup->event->enddate <= time()) { Site::Flash("error", "It is not possible to edit this booking"); Redirect("bookings/{$signup->id}"); } $services = $signup->available_services(); if (count($services) > 0) { if ($this->post and $this->csrf) { $added = 0; $available_services = array(); foreach ($services as $service) { $available_services[] = $service->id; } foreach ($_POST['services'] as $id => $quantity) { $quantity = intval($quantity); for ($i = 0; $i < $quantity; $i++) { if (in_array($id, $available_services)) { $service = Service::find_by_id($id); if ($service->max_per_signup != -1 && $i >= $service->max_per_signup || $i == $service->available()) { break; } $event_service = new EventService(); $event_service->event_signup_id = $signup->id; $event_service->service_id = $id; if ($signup->paid and $service->cost == 0 and $service->available() != 0) { $event_service->paid = true; } if (isset($_POST['service_notes'][$id])) { $event_service->note = $_POST['service_notes'][$id]; } if ($event_service->save()) { $added++; } else { Site::Flash("error", "Unable to add {$service->name}"); Redirect("bookings/{$signup->id}/services"); } } } } if ($added > 0) { Site::Flash("notice", "The service has been added"); if ($added > 1) { Site::Flash("notice", "The services have been added"); } Redirect("bookings/{$signup->id}"); } else { Site::Flash("error", "No services were added"); Redirect("bookings/{$signup->id}/services"); } } elseif ($this->post) { global $site; $site['flash']['error'] = "Invalid form submission"; } $this->assign("signup", $signup); $this->assign("services", $services); $this->title = "My Bookings :: {$signup->event->name} :: Add Services"; $this->render("event_service/add.tpl"); } else { Site::Flash("error", "There are no services available for you to add"); Redirect("bookings/{$signup->id}"); } }
/** * Process the incoming request for the overview * view of published primary genres. * * @param object Joomla mainframe object * @return bean SummaryPageModel */ public function overview($mainframe) { global $logger; $logger->debug(get_class($this) . '::overview()'); $model = new SummaryPageModel(); $es = new EventService(); $courses = array(); $events = $es->getEventsByPubState('Course', array('Published')); foreach ($events as $crse) { $pg = $crse->getPrimaryGenre(); // Check to see if we are looking for school-related courses (not expected) $school = isset($_REQUEST['school']) ? $school : null; // add only the proper type (public or school) if ($pg->getSchool() == $school) { $courses[] = $crse; } } $model->setList($courses); // announcement $model->setAnnouncement($this->getPublishedAnnouncement('Course', false)); return $model; }
/** * A convenience method to convert the incoming bean * to the corresponding PDO. This includes all translations * such as the nested PublicationSate and Address objects. * If the bean has an oid, then it will fetch the venue, * if the venue id is null, a new pdo object will be returned. * * @access private * @param bean Venue bean * @return pdo Venue PDO */ private function beanToPdo($bean) { global $logger; $logger->debug(get_class($this) . "::beanToPdo({$bean})"); // Check to see if there is a valid Venue OID if ($bean->getOid() > 0) { $pdo = $this->fetchVenueById($bean->getOid()); } else { // Get a new event PDO $epm = epManager::instance(); $pdo = $epm->create('Venue'); } // Copy the bean values over the top of the PDO values BeanUtil::copyBean($bean, $pdo); // Translate the pubState from string to object instance $pubState = $this->fetchPubState($bean->getPubState()); $pdo->setPubState($pubState); // Translate the address from bean to object instance $addrBean = $bean->getAddress(); if ($addrBean != null) { if ($addrBean->getOid() > 0 || trim($addrBean->getStreet()) != "") { $addrPdo = $this->fetchAddressById($addrBean->getOid()); BeanUtil::copyBean($addrBean, $addrPdo); $pdo->setAddress($addrPdo); } } // Translate the events from array of oids to array of PDOs $eventAssoc = $bean->getEvents(); if ($eventAssoc != null) { $es = new EventService(); $eventPdo = array(); foreach ($eventAssoc as $key => $value) { $type = ucfirst($key); $logger->debug("The event type is: " . $type); foreach ($value as $evoid) { $eventPdo[] = $es->fetchEventById($type, $evoid); } } $pdo->setEvents($eventPdo); } return $pdo; }
public function edit() { $signup = self::load_signup($id); if ($signup->event->enddate <= time()) { Site::Flash("error", "It is not possible to edit this booking"); Redirect("bookings/{$signup->id}"); } // Seating Manager $managers = array('' => 'None'); $clan = mysql_real_escape_string(Site::CurrentUser()->clan); if ($clan != '') { $id = mysql_real_escape_string(Site::CurrentUser()->id); $allManagers = User::find_all("users.clan = '{$clan}'", "users.nickname ASC"); foreach ($allManagers as $manager) { $permalink = $manager->permalink(); $managers[$permalink] = $manager->nickname; } } $currentManager = ''; if ($signup->manager_id) { $currentManager = $signup->manager->permalink(); } if ($this->post and !$this->csrf) { global $site; $site['flash']['error'] = "Invalid form submission"; } elseif ($this->post) { $signup->lift_required = $_POST['lift_required']; if (!$signup->paid and !$signup->event_ticket->hidden) { $ticket_id = mysql_real_escape_string($_POST['ticket']); if ($ticket_id != $signup->event_ticket_id) { $event_id = mysql_real_escape_string($signup->event_id); $ticket = EventTicket::find("event_tickets.id = '{$ticket_id}' AND event_tickets.event_id = '{$event_id}' AND event_tickets.hidden = false"); if ($ticket) { $signup->event_ticket_id = $ticket->id; $signup->event_ticket = $ticket; } } } $save = true; if ($this->PostData('manager_id')) { $manager = User::find_by_nickname($this->PostData('manager_id')); if ($manager && array_key_exists($manager->permalink(), $managers)) { $signup->manager_id = $manager->id; } else { global $site; $site['flash']['error'] = "Unable to find the seat manager you selected"; $save = false; } } else { $signup->manager_id = null; } if ($save && $signup->save()) { // Remove any services that don't fit this booking if (!$signup->event_ticket->participant) { $signup_id = mysql_real_escape_string($signup->id); $services = EventService::find_all("event_services.event_signup_id = '{$signup_id}' AND participant = true"); $paid = array(); foreach ($services as $service) { if ($service->paid) { // Service has been paid, don't remove it, email staff $paid[] = $service; } else { $service->destroy(); } } if (count($paid) > 0) { // One or more services were unsuitable but paid for (this should // really not happen! Let's email staff and they can handle it } } Site::Flash("notice", "Your event booking has been updated"); Redirect("bookings/{$signup->id}"); } } $this->assign("signup", $signup); $this->assign("tickets", $signup->event->public_tickets()); $this->assign("managers", $managers); $this->assign("currentManager", $currentManager); $this->title = "My Bookings :: " . $signup->event->name . " :: Edit"; $this->render("event_signup/edit.tpl"); }
/** * Process the incoming request for the overview * view of published primary genres. * * @param object Joomla mainframe object * @return bean SummaryPageModel */ public function overview($mainframe = null) { global $logger; $logger->debug(get_class($this) . '::overview()'); $model = new SummaryPageModel(); $es = new EventService(); $genres = array(); $events = $es->getEventsByPubState('Program', array('Published')); foreach ($events as $prgm) { $pg = $prgm->getPrimaryGenre(); // Check to see if we are looking for school-related programs (not expected) $school = isset($_REQUEST['school']) ? $school : null; // add only the proper type (public or school) if ($pg && $pg->getSchool() == $school) { // only add it to the list once if (isset($genres[$pg->getOid()])) { continue; } else { $genres[$pg->getOid()] = $pg; } } } $model->setList($genres); // announcement $model->setAnnouncement($this->getPublishedAnnouncement('Program')); return $model; }
/** * 处理event */ private function event() { $service = new EventService(); $result = $service->invoke($this->commonUri); echo json_encode($result); }
public function check_services() { // Get all available services $event_id = mysql_real_escape_string($this->event_id); $participant = ""; if (!$this->event_ticket->participant) { $participant = " AND services.participant = false"; } $available_services = Service::find_all("services.event_id = '{$event_id}'{$participant}"); $available = array(); foreach ($available_services as $service) { if ($service->available() != 0) { $available[] = $service->id; } } // Get unpaid services $signup_id = mysql_real_escape_string($this->id); $unpaid = EventService::find_all("event_services.event_signup_id = '{$signup_id}' AND event_services.paid = false"); $removed = array(); foreach ($unpaid as $service) { if (!in_array($service->service_id, $available)) { $removed[] = $service->service; $service->destroy(); } } return $removed; }
public function show($permalink = null, $id = null) { $event = self::load_event(); $service = self::load_service($event); $sort = ""; if (isset($_GET['sort'])) { $sort = $_GET['sort']; } if ($sort == "nickname") { $order = "users.nickname ASC"; } elseif ($sort == "date") { $order = "event_signups.created_at DESC"; } elseif ($sort == "id") { $order = "event_signups.id ASC"; } else { $order = "event_services.paid DESC, users.nickname ASC"; } $page = 1; if ($this->GetData('page')) { $page = $this->GetData('page'); } $id = mysql_real_escape_string($service->id); $signups = EventService::paginate("event_services.service_id = '{$id}'", $order, $page, 100); $this->assign("event", $event); $this->assign("service", $service); $this->assign("signups", $signups); $this->assign("sort", $sort); $this->title = "View Service"; $this->render("service/show.tpl"); }