This repository has been archived by the owner on Jan 21, 2024. It is now read-only.
/
view_event.php
94 lines (86 loc) · 3.35 KB
/
view_event.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
/**
* File defines the ViewEventController PageController class
* @package PageController
*/
/**
*/
$current_dir = dirname (__FILE__);
require_once ($current_dir . DIRECTORY_SEPARATOR . "shared" . DIRECTORY_SEPARATOR . "bootstrap.php");
require_once (joinPath (INCLUDES_DIR, "models", "Event.php"));
require_once (joinPath (INCLUDES_DIR, "models", "Attendance.php"));
require_once (joinPath (INCLUDES_DIR, "Session.php"));
/**
* View event details page
*
* Read in the specified event from the database.
* Display event details in the page. Allow admin preview of un-approved event
* @package PageController
*/
class ViewEventController implements Controller {
/**
* PageTemplate object used to render page
* @access protected
* @var PageTemplate
*/
protected $template;
/**
* Constructor. Create instance of PageTemplate using default index_tpl.php file
* @access public
*/
public function __construct () {
$this->template = new PageTemplate ();
}
/**
* 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"));
}
// Allow admin preview access to non-approved events
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"));
}
// Event does not exist
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,
));
}
}
$controller = new ViewEventController ();
$controller->run ();
?>