/** * Run method with main page logic * * Read in the specified event from the database. * Populate template and display event details in the page. Allow admin preview of un-approved event * @access public */ public function run() { $session = Session::getInstance(); $user = $session->getUser(); $eventDAO = EventDAO::getInstance(); $attendDAO = AttendanceDAO::getInstance(); $title = ""; $event = $attending = $attend_array = null; $attend_count = null; if (!empty($_GET["id"]) && is_numeric($_GET["id"])) { $id = intval($_GET["id"]); $event = $eventDAO->load($id, array("joins" => true)); // Check if event is approved if ($event && $event->status == Event::APPROVED_STATUS) { $title .= " - {$event->title}"; if ($user) { $attending = $attendDAO->loadExists($event, $user); } $attend_count = $attendDAO->countByEvent($event); $attend_array = $attendDAO->allByEvent($event, array("joins" => true, "order" => "id DESC")); } else { if ($event && $session->getUser() && $session->getUser()->isAdmin()) { $title .= " - {$event->title}"; $attending = $attendDAO->loadExists($event, $user); $attend_count = $attendDAO->countByEvent($event); $attend_array = $attendDAO->allByEvent($event, array("joins" => true, "order" => "id DESC")); } else { $event = null; } } } $this->template->render(array("title" => "Event Details" . $title, "main_page" => "view_event_tpl.php", "session" => $session, "event" => $event, "attending" => $attending, "attend_array" => $attend_array, "attend_count" => $attend_count)); }
/** * Delete instances of a User entities with the ids specified in the ids array. LEFT JOIN clauses will be added to delete any associated attendance records, pages, articles and events * * @access public * @param array $ids Array containing int ids of User entities to delete * @param array $options (Optional) Read documentation on parseOptions for details * @return bool Return status of PDOStatement execute method */ public function deleteByIds($ids, $options = null) { if (!is_array($ids)) { throw new InvalidArgumentException("Must pass array of ids as the first parameter"); } // Import associated DAOs require_once "Attendance.php"; require_once "Page.php"; require_once "Article.php"; require_once "Event.php"; $attendDAO = AttendanceDAO::getInstance(); $pagesDAO = PageDAO::getInstance(); $articlesDAO = ArticleDAO::getInstance(); $eventsDAO = EventDAO::getInstance(); $str = ""; for ($i = 0; $i < count($ids) - 1; $i++) { $str .= "?,"; } $str .= "?"; // Use LEFT JOIN in case user does not have some entries $query = "DELETE FROM {$this->tableName}, {$attendDAO->getTableName()}, {$pagesDAO->getTableName()}, {$articlesDAO->getTableName()}, {$eventsDAO->getTableName()} USING {$this->tableName} LEFT JOIN {$attendDAO->getTableName()} ON {$this->tableName}.id = {$attendDAO->getTableName()}.userId LEFT JOIN {$pagesDAO->getTableName()} ON {$this->tableName}.id = {$pagesDAO->getTableName()}.userId LEFT JOIN {$articlesDAO->getTableName()} ON {$this->tableName}.id = {$articlesDAO->getTableName()}.userId LEFT JOIN {$eventsDAO->getTableName()} ON {$this->tableName}.id = {$eventsDAO->getTableName()}.userId WHERE {$this->tableName}.id IN ({$str})"; //echo $query; $stmt = self::$dbh->prepare($query); $params = $ids; $status = $stmt->execute($params); return $status; }
/** * Delete instances of an Event entities with the ids specified in the ids array * * @access public * @param array $ids Array containing int ids of Event entities to delete * @param array $options (Optional) Read documentation on parseOptions for details * @return bool Return status of PDOStatement execute method */ public function deleteByIds($ids, $options = null) { if (!is_array($ids)) { throw new InvalidArgumentException("Must pass array of ids as the first parameter"); } require_once "Attendance.php"; $attendDAO = AttendanceDAO::getInstance(); $str = ""; for ($i = 0; $i < count($ids) - 1; $i++) { $str .= "?,"; } $str .= "?"; $query = "DELETE FROM {$this->tableName}, {$attendDAO->getTableName()} USING {$this->tableName} LEFT JOIN {$attendDAO->getTableName()} ON {$this->tableName}.id = {$attendDAO->getTableName()}.eventId WHERE {$this->tableName}.id IN (" . $str . ")"; //echo $query; $stmt = self::$dbh->prepare($query); $params = $ids; return $stmt->execute($params); }
/** * Retrieve instance of an AttendanceDAO or create one if it does * not exist. * * @access public * @static * @return AttendanceDAO */ public static function getInstance() { if (!isset(self::$instance)) { self::$instance = new self(); } return self::$instance; }
/** * Run method with main page logic * * MEMBERS ONLY. POST requests only. Check that the user has a valid session and that a specified event exists. If true, * make sure that the user does not already have an Attendance record. If no record exists, * create new Attendance record and save it to database. * @access public */ public function run() { $session = Session::getInstance(); $user = $session->getUser(); if (!$user || !$user->validUser()) { $session->setMessage("Do not have permission to access", Session::MESSAGE_ERROR); header("Location: " . BASE_URL); return; } $eventDAO = EventDAO::getInstance(); $attendDAO = AttendanceDAO::getInstance(); if (!empty($_POST)) { $event_id = isset($_POST["eventid"]) && is_numeric($_POST["eventid"]) ? intval($_POST["eventid"]) : 0; $action = isset($_POST["action"]) ? $_POST["action"] : ""; if (empty($event_id) || $event_id < 0) { $session->setMessage("Invalid event id", Session::MESSAGE_ERROR); header("Location: " . BASE_URL); return; } $event = $eventDAO->load($event_id); if (!$event) { $session->setMessage("Event could not be found", Session::MESSAGE_ERROR); header("Location: " . BASE_URL); return; } if ($action && strcmp($action, "remove") == 0) { $attend = $attendDAO->loadExists($event, $user); if (!$attend) { $session->setMessage("You are not marked as attending", Session::MESSAGE_ERROR); header("Location: {$event->getAbsoluteUrl()}"); return; } if ($attendDAO->delete($attend)) { $session->setMessage("You are no longer as attending"); header("Location: {$event->getAbsoluteUrl()}"); return; } else { $session->setMessage("Request for attendance removal failed", Session::MESSAGE_ERROR); header("Location: {$event->getAbsoluteUrl()}"); return; } } else { $attend = $attendDAO->loadExists($event, $user); if ($attend) { $session->setMessage("You are already marked as attending", Session::MESSAGE_ERROR); header("Location: {$event->getAbsoluteUrl()}"); return; } $attend = new Attendance(); $attend->setEventId($event->id); $attend->setUserId($user->id); if ($attendDAO->insert($attend)) { $session->setMessage("You are now marked as attending"); header("Location: {$event->getAbsoluteUrl()}"); return; } else { $session->setMessage("Request for attendance failed", Session::MESSAGE_ERROR); header("Location: {$event->getAbsoluteUrl()}"); return; } } } header("Location: " . BASE_URL); return; }