/classes/DataManager.class.php

https://github.com/Aaron-P/Cranberry-Scheduler · PHP · 1002 lines · 595 code · 158 blank · 249 comment · 14 complexity · 7fa28e02e03ac58e79a6110157a036bb MD5 · raw file

  1. <?php
  2. /**
  3. * Defines the DataManagerSingleton and DataManager classes.
  4. * @file DataManager.class.php
  5. * @author Aaron Papp
  6. * @author Shawn LeMaster
  7. * @version 1.0
  8. * @date 2011-2012
  9. * @copyright University of Illinois/NCSA Open Source License
  10. */
  11. error_reporting(E_ALL | E_STRICT);
  12. require_once("DBHandler.class.php");
  13. /**
  14. * A wrapper for interfacing with the database. One function per SQL query.
  15. * @class DataManagerSingleton
  16. */
  17. class DataManagerSingleton
  18. {
  19. private static $db; /**< Holds the DBHandler singleton for interfacing with the database. */
  20. /**
  21. * All SQL queries used in this class.
  22. */
  23. private $teamEventsSQL = "SELECT DISTINCT m.MeetingType,
  24. m.Description,
  25. DATE(m.StartTime) AS Date,
  26. TIME(m.StartTime) AS Start,
  27. TIME(m.EndTime) AS End,
  28. l.LocationName AS Location,
  29. m.NumVolunteers,
  30. m.RequiredForms
  31. FROM meeting As m, location AS l, teamperson, person
  32. WHERE m.TeamID = teamperson.TeamID
  33. AND l.LocationID = m.LocationID
  34. AND teamperson.PersonID = person.PersonID
  35. AND person.Eid = :eid;";
  36. private $personInfoSQL =
  37. "SELECT Eid, FirstName, LastName, IsVolunteer, IsResearcher, IsTeacher
  38. FROM person
  39. WHERE Eid = :eid;";
  40. private $volunteerOpportunitiesSQL =
  41. "SELECT DISTINCT m.MeetingType,
  42. m.Description,
  43. DATE_FORMAT(m.StartTime, '%W, %M %e, %Y') AS Date,
  44. DATE_FORMAT(m.StartTime, '%l:%i %p') AS Start,
  45. DATE_FORMAT(m.EndTime, '%l:%i %p') AS End,
  46. l.LocationName AS Location,
  47. m.RequiredForms,
  48. m.MeetingID
  49. FROM meeting As m, location AS l
  50. WHERE l.LocationID = m.LocationID
  51. AND m.MeetingType = 'Interview'
  52. AND m.NumVolunteers > (SELECT COUNT(v.MeetingID)
  53. FROM volunteer AS v
  54. WHERE v.MeetingID = m.MeetingID)
  55. AND m.StartTime > NOW()
  56. ORDER BY m.StartTime;";
  57. private $upcomingTeamEventsDetailedSQL =
  58. "SELECT DISTINCT m.MeetingType,
  59. DATE_FORMAT(m.StartTime, '%W, %M %e, %Y') AS Date,
  60. DATE_FORMAT(m.StartTime, '%l:%i %p') AS Start,
  61. DATE_FORMAT(m.EndTime, '%l:%i %p') AS End,
  62. m.MeetingID,
  63. m.Description
  64. FROM meeting As m, teamperson, person
  65. WHERE m.TeamID = teamperson.TeamID
  66. AND teamperson.PersonID = person.PersonID
  67. AND NOW() < m.StartTime
  68. AND person.Eid = :eid;";
  69. private $upcomingTeamEventsSQL =
  70. "SELECT DISTINCT m.MeetingType,
  71. DATE_FORMAT(m.StartTime, '%b %e') AS Date,
  72. m.MeetingID
  73. FROM meeting As m, teamperson, person
  74. WHERE m.TeamID = teamperson.TeamID
  75. AND teamperson.PersonID = person.PersonID
  76. AND NOW() < m.StartTime
  77. AND person.Eid = :eid;";
  78. private $eventInfoSQL =
  79. "SELECT DISTINCT m.MeetingType,
  80. m.Description,
  81. UNIX_TIMESTAMP(m.StartTime) < UNIX_TIMESTAMP(NOW()) AS InPast,
  82. DATE_FORMAT(m.StartTime, '%W, %M %e, %Y') AS Date,
  83. DATE_FORMAT(m.StartTime, '%l:%i %p') AS Start,
  84. DATE_FORMAT(m.EndTime, '%l:%i %p') AS End,
  85. l.LocationName AS Location,
  86. m.NumVolunteers,
  87. m.RequiredForms
  88. FROM meeting As m, location AS l
  89. WHERE m.MeetingID = :eventID
  90. AND l.LocationID = m.LocationID;";
  91. private $meetingVolunteersSQL =
  92. "SELECT p.FirstName, p.LastName, p.Eid
  93. FROM person AS p, meeting AS m, volunteer AS v
  94. WHERE p.PersonID = v.PersonID
  95. AND m.MeetingID = :meetingID
  96. AND m.MeetingID = v.MeetingID;";
  97. private $teamEventsBetweenSQL =
  98. "SELECT DISTINCT m.MeetingType AS title,
  99. UNIX_TIMESTAMP(m.StartTime) AS start,
  100. UNIX_TIMESTAMP(m.EndTime) AS end,
  101. m.MeetingID as id
  102. FROM meeting As m, teamperson, person
  103. WHERE m.TeamID = teamperson.TeamID
  104. AND teamperson.PersonID = person.PersonID
  105. AND person.Eid = :eid
  106. AND m.StartTime BETWEEN FROM_UNIXTIME(:start) AND FROM_UNIXTIME(:end);";
  107. private $volEventsSQL =
  108. "SELECT DISTINCT 'Volunteer' AS MeetingType,
  109. DATE_FORMAT(m.StartTime, '%b %e') AS Date,
  110. m.MeetingID
  111. FROM meeting As m, location AS l, volunteer, person
  112. WHERE m.MeetingID = volunteer.MeetingID
  113. AND l.LocationID = m.LocationID
  114. AND volunteer.PersonID = person.PersonID
  115. AND NOW() < m.StartTime
  116. AND person.Eid = :eid;";
  117. private $volEventsDetailedSQL =
  118. "SELECT DISTINCT 'Volunteer' AS MeetingType,
  119. DATE_FORMAT(m.StartTime, '%W, %M %e, %Y') AS Date,
  120. DATE_FORMAT(m.StartTime, '%l:%i %p') AS Start,
  121. DATE_FORMAT(m.EndTime, '%l:%i %p') AS End,
  122. m.MeetingID,
  123. m.Description
  124. FROM meeting As m, location AS l, volunteer, person
  125. WHERE m.MeetingID = volunteer.MeetingID
  126. AND l.LocationID = m.LocationID
  127. AND volunteer.PersonID = person.PersonID
  128. AND NOW() < m.StartTime
  129. AND person.Eid = :eid;";
  130. private $teamEventsAtLocSQL =
  131. "SELECT DISTINCT l.LocationName AS Location,
  132. m.MeetingType,
  133. m.Description,
  134. DATE(m.StartTime) AS Date,
  135. TIME(m.StartTime) AS Start,
  136. TIME(m.EndTime) AS End
  137. FROM location AS l, meeting AS m, teamperson AS t, person AS p
  138. WHERE l.LocationID = m.LocationID
  139. AND m.TeamID = t.TeamID
  140. AND t.PersonID = p.PersonID
  141. AND p.Eid = :eid && l.LocationName = :location;";
  142. private $volEventsAtLocSQL =
  143. "SELECT DISTINCT l.LocationName AS Location,
  144. m.Description,
  145. DATE(m.StartTime) AS Date,
  146. TIME(m.StartTime) AS Start,
  147. TIME(m.EndTime) AS End
  148. FROM location AS l, meeting AS m, volunteer AS v, person AS p
  149. WHERE l.LocationID = m.LocationID
  150. AND m.MeetingID = v. MeetingID
  151. AND v.PersonID = p.PersonID
  152. AND p.Eid = :eid && l.LocationName = :location;";
  153. private $nonTeamEventsAtLocSQL =
  154. "SELECT DISTINCT l.LocationName AS Location,
  155. m.MeetingType,
  156. m.Description,
  157. DATE(m.StartTime) AS Date,
  158. TIME(m.StartTime) AS Start,
  159. TIME(m.EndTime) AS End
  160. FROM location AS l, meeting AS m, teamperson AS t, person AS p
  161. WHERE l.LocationID = m.LocationID
  162. AND m.TeamID != t.TeamID
  163. AND t.PersonID = p.PersonID
  164. AND p.Eid = :eid && l.LocationName = :location;";
  165. private $volsAndPointsSQL =
  166. "SELECT DISTINCT p.FirstName, p.LastName, v.Participated AS ParticipationPoints
  167. FROM person, volunteer AS v
  168. JOIN person AS p ON p.PersonID = v.PersonID
  169. ORDER BY p.FirstName ASC;";
  170. private $volsAndPointsByLastNameSQL =
  171. "SELECT DISTINCT p.LastName,p.FirstName ,v.Participated AS ParticipationPoints
  172. FROM person, volunteer AS v
  173. JOIN person AS p ON p.PersonID = v.PersonID
  174. ORDER BY p.LastName ASC;";
  175. private $allLocationsSQL =
  176. "SELECT LocationID, LocationName, IsUsable
  177. FROM location
  178. ORDER BY LocationName ASC;";
  179. private $locationIDSQL =
  180. "SELECT LocationID
  181. FROM location
  182. WHERE LocationName = :locName;";
  183. private $teamIDSQL =
  184. "SELECT teamperson.TeamID
  185. FROM teamperson, person
  186. WHERE teamperson.PersonID = person.PersonID
  187. AND person.Eid = :eid;";
  188. private $insertMeetingSQL =
  189. "INSERT INTO meeting(MeetingType, Description,
  190. StartTime, EndTime, LocationID,
  191. TeamID, NumVolunteers)
  192. VALUES (:type, :description, FROM_UNIXTIME(:start), FROM_UNIXTIME(:finish), :loc, :teamID, :numOfVolunteers);";
  193. private $updateMeetingSQL =
  194. "UPDATE meeting
  195. SET MeetingType = :meetType,
  196. Description = :description,
  197. StartTime = FROM_UNIXTIME(:startTime),
  198. EndTime = FROM_UNIXTIME(:endTime),
  199. LocationID = :locID,
  200. NumVolunteers = :numVolunteers
  201. WHERE MeetingID = :meetID;";
  202. private $updateVolunteerSQL =
  203. "UPDATE volunteer AS v
  204. JOIN meeting AS m ON m.MeetingID = v.MeetingID
  205. SET Participated = Participated + :incValue
  206. WHERE m.MeetingID = :meetID && v.PersonID = :personID;";
  207. private $settingsSQL =
  208. "SELECT s.EmailAddress, s.EmailNotify, s.SMSNotify, s.reminderTime
  209. FROM setting s, person p
  210. WHERE s.PersonID = p.PersonID
  211. AND p.Eid = :eid;";
  212. private $updateSettingsSQL =
  213. "INSERT INTO setting (PersonID, EmailAddress, EmailNotify, reminderTime)
  214. VALUES (:pid, :email, :enotify, :rtime)
  215. ON DUPLICATE KEY UPDATE EmailAddress = :email, EmailNotify = :enotify, reminderTime = :rtime";
  216. private $personIDSQL =
  217. "SELECT PersonID
  218. FROM person
  219. WHERE Eid = :eid;";
  220. private $locationEventsBetweenSQL =
  221. "SELECT DISTINCT m.MeetingType AS title,
  222. UNIX_TIMESTAMP(m.StartTime) AS start,
  223. UNIX_TIMESTAMP(m.EndTime) AS end,
  224. m.MeetingID as id
  225. FROM meeting As m
  226. WHERE m.StartTime BETWEEN FROM_UNIXTIME(:start) AND FROM_UNIXTIME(:end)
  227. AND m.LocationID = :location";
  228. private $reminderInfo = "SELECT TIME_TO_SEC(TIMEDIFF(m.StartTime, NOW())) AS diff, s.EmailAddress, m.MeetingType, m.Description, UNIX_TIMESTAMP(m.StartTime) AS StartTime, UNIX_TIMESTAMP(m.EndTime) AS EndTime, l.LocationName, p.FirstName, p.LastName
  229. FROM setting s, person p, teamperson t, meeting m, location l
  230. WHERE s.PersonID = p.PersonID
  231. AND p.PersonID = t.PersonID
  232. AND t.TeamID = m.TeamID
  233. AND m.LocationID = l.LocationID
  234. AND m.StartTime > NOW()
  235. AND s.EmailNotify = 1";
  236. private $isInMeetingSQL = "SELECT COUNT(*) AS Count
  237. FROM meeting m, teamperson t, person p
  238. WHERE m.TeamID = t.TeamID
  239. AND t.PersonID = p.PersonID
  240. AND m.MeetingID = :meetingId
  241. AND p.Eid = :eid;";
  242. private $isVolunteerSQL = "SELECT COUNT(*) AS Count
  243. FROM meeting As m, location AS l, volunteer, person
  244. WHERE m.MeetingID = volunteer.MeetingID
  245. AND m.MeetingID = :meetingId
  246. AND l.LocationID = m.LocationID
  247. AND volunteer.PersonID = person.PersonID
  248. AND NOW() < m.StartTime
  249. AND person.Eid = :eid;";
  250. private $unconfirmedVolunteersSQL = "SELECT m.*, p.PersonID, p.FirstName, p.LastName
  251. FROM meeting m, volunteer v, person p
  252. WHERE m.NumVolunteers > 0
  253. AND m.AllVolunteersConfirmed = '0'
  254. AND m.MeetingID = v.MeetingID
  255. AND UNIX_TIMESTAMP(m.EndTime) < UNIX_TIMESTAMP(NOW())
  256. AND v.PersonID = p.PersonID
  257. AND m.TeamID = (SELECT t.TeamID
  258. FROM teamperson t, person p
  259. WHERE t.PersonID = p.PersonID
  260. AND p.Eid = :eid)";
  261. private $unconfirmedVolunteersCountSQL = "SELECT COUNT(*) AS Count
  262. FROM meeting m, volunteer v, person p
  263. WHERE m.NumVolunteers > 0
  264. AND m.AllVolunteersConfirmed = '0'
  265. AND m.MeetingID = v.MeetingID
  266. AND UNIX_TIMESTAMP(m.EndTime) < UNIX_TIMESTAMP(NOW())
  267. AND v.PersonID = p.PersonID
  268. AND m.TeamID = (SELECT t.TeamID
  269. FROM teamperson t, person p
  270. WHERE t.PersonID = p.PersonID
  271. AND p.Eid = :eid)";
  272. private $meetingDataSQL = "SELECT m.MeetingID, m.MeetingType, m.Description, m.LocationID, m.NumVolunteers,
  273. DATE_FORMAT(m.StartTime, '%m/%e/%Y') AS Date,
  274. DATE_FORMAT(m.StartTime, '%l:%i %p') AS Start,
  275. DATE_FORMAT(m.EndTime, '%l:%i %p') AS End
  276. FROM meeting m
  277. WHERE m.MeetingID = :meetingId";
  278. private $addLocationSQL = "INSERT INTO location(LocationName)
  279. VALUES (:locname);";
  280. private $disableLocationSQL = "UPDATE location
  281. SET IsUsable = :usable
  282. WHERE LocationID = :id;";
  283. private $deleteLocationSQL = "DELETE FROM location
  284. WHERE LocationID = :id";
  285. private $addCourseSQL = "INSERT INTO course(CourseName)
  286. VALUES (:name);";
  287. private $allCoursesSQL = "SELECT * FROM course;";
  288. private $deleteCourseSQL = "DELETE FROM course WHERE CourseID = :id;";
  289. private $addPersonSQL = "INSERT INTO courseperson(CourseID, PersonID)
  290. VALUES (:courseID, :personID);";
  291. private $allPeopleSQL = "SELECT PersonID, FirstName, LastName FROM person;";
  292. private $deletePersonSQL = "DELETE FROM courseperson
  293. WHERE PersonID = :personID
  294. AND CourseID = :courseID;";
  295. private $groupIDByNameSQL = "SELECT TeamID FROM team WHERE TeamName = :name;";
  296. private $addGroupSQL = "INSERT INTO team(TeamName) VALUES (:tname);";
  297. private $addGroupPersonSQL = "INSERT INTO teamPerson(TeamID, PersonID) VALUES (:tid, :pid);";
  298. private $allGroupsSQL = "SELECT TeamID, TeamName FROM team ORDER BY TeamName;";
  299. private $deleteGroupSQL = "DELETE FROM team WHERE TeamID = :id;";
  300. private $checkEidExistsSQL = "SELECT COUNT(*) AS Count FROM person p WHERE p.Eid = :eid;";
  301. private $updateUserLevelSQL = "UPDATE person
  302. SET IsResearcher = :isResearcher,
  303. IsTeacher = :isTeacher
  304. WHERE PersonID = :personID;";
  305. private $ownsMeetingSQL =
  306. "SELECT m.MeetingID
  307. FROM meeting m, person p, teamperson tp
  308. WHERE m.TeamID = tp.TeamID
  309. AND p.Eid = :eid
  310. AND p.PersonID = tp.PersonID
  311. AND m.MeetingID = :meetingID
  312. AND p.IsResearcher = 1;";
  313. private $signUpSQL = "INSERT INTO volunteer(MeetingID, PersonID)
  314. VALUES (:mid, :pid);";
  315. /**
  316. * Constructs the DataManagerSingleton object.
  317. */
  318. protected static function Instance()
  319. {
  320. if (!self::$db)
  321. self::$db = new DBHandler("cranberryscheduler", "127.0.0.1", null, "root", null);
  322. return self::$db;
  323. }
  324. /**
  325. * Checks to see if an e-id exists in the database.
  326. * @param[in] $eid The e-id (username) that is checked
  327. */
  328. public function eidExists($eid)
  329. {
  330. $result = self::$db->query($this->checkEidExistsSQL, array(":eid" => $eid));
  331. if ($result[0]["Count"] !== "0")
  332. return true;
  333. return false;
  334. }
  335. /**
  336. * Given an e-id for any team member, return the events for that team.
  337. * @param[in] $eid The e-id (username) of one of the teammates on a team
  338. */
  339. public function getTeamEvents($eid)
  340. {
  341. return self::$db->query($this->teamEventsSQL, array(":eid" => $eid));
  342. }
  343. /**
  344. * Grabs detailed information about a person in the database.
  345. * @param[in] $eid The e-id (username) of the person
  346. */
  347. public function getPersonInfo($eid)
  348. {
  349. $result = self::$db->query($this->personInfoSQL, array(":eid" => $eid));
  350. return $result[0];
  351. }
  352. /**
  353. * Retrieves all available volunteer opportunities.
  354. */
  355. public function getVolunteerOpportunities()
  356. {
  357. return self::$db->query($this->volunteerOpportunitiesSQL);
  358. }
  359. /**
  360. * Grabs detailed information about a team's upcoming events.
  361. * @param[in] $eid The e-id (username) of one of the teammates
  362. */
  363. public function getUpcomingTeamEventsDetailed($eid)
  364. {
  365. return self::$db->query($this->upcomingTeamEventsDetailedSQL, array(":eid" => $eid));
  366. }
  367. /**
  368. * Grabs less detailed information about a team's upcoming events.
  369. * @param[in] $eid The e-id (username) of one of the teammates
  370. */
  371. public function getUpcomingTeamEvents($eid)
  372. {
  373. return self::$db->query($this->upcomingTeamEventsSQL, array(":eid" => $eid));
  374. }
  375. /**
  376. * Grabs the complete details of a single event.
  377. * @param[in] $eventID The event's ID
  378. */
  379. public function getEventInfo($eventID)
  380. {
  381. $result = self::$db->query($this->eventInfoSQL, array(":eventID" => $eventID));
  382. return $result[0];
  383. }
  384. /**
  385. * Gets the information about a meeting's scheduled volunteers.
  386. * @param[in] $meetingID The meeting's ID
  387. */
  388. public function getMeetingVolunteers($meetingID)
  389. {
  390. return self::$db->query($this->meetingVolunteersSQL, array(":meetingID" => $meetingID));
  391. }
  392. /**
  393. * Return the events for a team scheduled between the specified periods of time
  394. * @param[in] $eid The e-id (username) of a person on the team
  395. * @param[in] $start The UNIX timestamp of the start of the time interval
  396. * @param[in] $end The UNIX timestamp of the end of the time interval
  397. */
  398. public function getTeamEventsBetween($eid, $start, $end)
  399. {
  400. return self::$db->query($this->teamEventsBetweenSQL, array(":eid" => $eid, ":start" => $start, ":end" => $end));
  401. }
  402. /**
  403. * Return the events scheduled at a location between the specified periods of time
  404. * @param[in] $location The location ID
  405. * @param[in] $start The UNIX timestamp of the start of the time interval
  406. * @param[in] $end The UNIX timestamp of the end of the time interval
  407. */
  408. public function getLocationEventsBetween($location, $start, $end)
  409. {
  410. return self::$db->query($this->locationEventsBetweenSQL, array(":location" => $location, ":start" => $start, ":end" => $end));
  411. }
  412. /**
  413. * Grabs all the events that a volunteer is signed up for.
  414. * @param[in] $eid The volunteer's e-id (username)
  415. */
  416. public function getVolEvents($eid)
  417. {
  418. return self::$db->query($this->volEventsSQL, array(":eid" => $eid));
  419. }
  420. /**
  421. * Grabs all the events (including all details) that a volunteer is signed up for.
  422. * @param[in] $eid The volunteer's e-id (username)
  423. */
  424. public function getVolEventsDetailed($eid)
  425. {
  426. return self::$db->query($this->volEventsDetailedSQL, array(":eid" => $eid));
  427. }
  428. /**
  429. * Grabs all the events for a team at a particular location.
  430. * @param[in] $eid The e-id (username) of one of the teammate's
  431. * @param[in] $location The location ID
  432. */
  433. public function getTeamEventsAtLoc($eid, $location)
  434. {
  435. return self::$db->query($this->teamEventsAtLocSQL, array(":eid" => $eid, ":location" => $location));
  436. }
  437. /**
  438. * Grabs all the events for a volunteer at a particular location.
  439. * @param[in] $eid The e-id (username) of the volunteer
  440. * @param[in] $location The location ID
  441. */
  442. public function getVolEventsAtLoc($eid, $location)
  443. {
  444. return self::$db->query($this->volEventsAtLocSQL, array(":eid" => $eid, ":location" => $location));
  445. }
  446. /**
  447. * Grabs all the events at a location that do NOT belong to a team.
  448. * @param[in] $eid The e-id (username) of one of the teammates
  449. * @param[in] $location The location ID
  450. */
  451. public function getNonTeamEventsAtLoc($eid, $location)
  452. {
  453. return self::$db->query($this->nonTeamEventsAtLocSQL, array(":eid" => $eid, ":location" => $location));
  454. }
  455. /**
  456. * Grabs the names and associated participation points of all volunteers.
  457. */
  458. public function getVolsAndPoints()
  459. {
  460. return self::$db->query($this->volsAndPointsSQL);
  461. }
  462. /**
  463. * Grabs the names and associated participation points of all volunteers
  464. * ordered ascending by last name.
  465. */
  466. public function getVolsAndPointsByLastName()
  467. {
  468. return self::$db->query($this->volsAndPointsByLastNameSQL);
  469. }
  470. /**
  471. * Returns all the locations in the database.
  472. */
  473. public function getAllLocations()
  474. {
  475. return self::$db->query($this->allLocationsSQL);
  476. }
  477. /**
  478. * Fetches the location ID of a location given its name.
  479. * @param[in] $locName The name of the location
  480. */
  481. public function getLocationID($locName)
  482. {
  483. $result = self::$db->query($this->locationIDSQL, array(":locName" => $locName));
  484. return $result[0]["LocationID"];
  485. }
  486. /**
  487. * Gets the ID of a person's team
  488. * @param[in] $eid The e-id (username) of one of the teammates
  489. */
  490. public function getTeamID($eid)
  491. {
  492. $result = self::$db->query($this->teamIDSQL, array(":eid" => $eid));
  493. return $result[0]["TeamID"];
  494. }
  495. /**
  496. * Inserts a new meeting into the database
  497. * @param[in] $type The type of meeting (rehearsal or interview)
  498. * @param[in] $description The meeting description
  499. * @param[in] $start The UNIX timestamp of when the meeting begins
  500. * @param[in] $finish The UNIX timestamp of when the meeting ends
  501. * @param[in] $locName The name of the location where the meeting will take place
  502. * @param[in] $numOfVolunteers The number of requested volunteers
  503. * @param[in] $eid The e-id of the person who scheduled the meeting
  504. */
  505. public function insertMeeting($type, $description, $start, $finish, $locName, $numOfVolunteers, $eid)
  506. {
  507. $loc = $locName;//$this->getLocationID($locName);
  508. $teamID = $this->getTeamID($eid);
  509. if ($numOfVolunteers == NULL || $numOfVolunteers <= 0)
  510. $numOfVolunteers = 0;
  511. $sqlVars = array(
  512. ":type" => $type,
  513. ":description" => $description,
  514. ":start" => $start,
  515. ":finish" => $finish,
  516. ":loc" => $loc,
  517. ":teamID" => $teamID,
  518. ":numOfVolunteers" => $numOfVolunteers
  519. );
  520. return self::$db->query($this->insertMeetingSQL, $sqlVars);
  521. }
  522. /**
  523. * Gets the details of a meeting
  524. * @param[in] $meetingId The ID of the meeting
  525. */
  526. public function getMeetingData($meetingId)
  527. {
  528. $result = self::$db->query($this->meetingDataSQL, array(":meetingId" => $meetingId));
  529. return $result[0];
  530. }
  531. /**
  532. * Updates the details of a meeting.
  533. * @param[in] $meetID The meeting ID
  534. * @param[in] $meetType The type of meeting (e.g. rehearsal or interview)
  535. * @param[in] $description The meeting description
  536. * @param[in] $startTime The UNIX timestamp of when the meeting begins
  537. * @param[in] $endTime The UNIX timestamp of when the meeting ends
  538. * @param[in] $locID The ID of the location where the meeting is to take place
  539. * @param[in] $numVolunteers The number of volunteers requested for the meeting
  540. */
  541. public function updateMeeting($meetID, $meetType, $description, $startTime, $endTime, $locID, $numVolunteers)
  542. {
  543. $sqlVars = array(
  544. ":meetID" => $meetID,
  545. ":meetType" => $meetType,
  546. ":description" => $description,
  547. ":startTime" => $startTime,
  548. ":endTime" => $endTime,
  549. ":locID" => $locID,
  550. ":numVolunteers" => $numVolunteers
  551. );
  552. return self::$db->query($this->updateMeetingSQL, $sqlVars);
  553. }
  554. /**
  555. * Updates the information of a volunteer after he/she participates
  556. * in a research meeting.
  557. * @param[in] $personID The ID of the volunteer
  558. * @param[in] $meetID The ID of the meeting the volunteer participated in
  559. * @param[in] $incValue The number of participation points earned
  560. */
  561. public function updateVolunteer($personID, $meetID, $incValue)
  562. {
  563. $sqlVars = array(
  564. ":personID" => $personID,
  565. ":meetID" => $meetID,
  566. ":incValue" => $incValue
  567. );
  568. return self::$db->query($this->updateVolunteerSQL, $sqlVars);
  569. }
  570. /**
  571. * Gets the website settings for a person
  572. * @param[in] $eid The person's e-id (username)
  573. */
  574. public function getSettings($eid)
  575. {
  576. $result = self::$db->query($this->settingsSQL, array(":eid" => $eid));
  577. if (!empty($result))
  578. return $result[0];
  579. return null;
  580. }
  581. /**
  582. * Updates a person's settings
  583. * @param[in] $eid The ID of the person
  584. * @param[in] $email The email address of the person
  585. * @param[in] $enotify Whether or not to send the person an email reminder
  586. * @param[in] $rtime The amount of time (in hours) before an event that the person will receive an email reminder
  587. */
  588. public function updateSettings($eid, $email, $enotify, $rtime)
  589. {
  590. $pid = $this->getPersonID($eid);
  591. $sqlVars = array(
  592. ":pid" => $pid,
  593. ":email" => $email,
  594. ":enotify" => $enotify,
  595. ":rtime" => $rtime
  596. );
  597. return self::$db->query($this->updateSettingsSQL, $sqlVars);
  598. }
  599. /**
  600. * Gets the ID (the ID internal to the databse) of a person given their e-id
  601. * @param[in] $eid The person's e-id (username)
  602. */
  603. public function getPersonID($eid)
  604. {
  605. $result = self::$db->query($this->personIDSQL, array(":eid" => $eid));
  606. return $result[0]["PersonID"];
  607. }
  608. /**
  609. * Grabs the time remaining until scheduled events occur. Can be utilized
  610. * when sending out email reminders X hours before a meeting is scheduled.
  611. */
  612. public function getReminderInfo()
  613. {
  614. $result = self::$db->query($this->reminderInfo, array());
  615. return $result;
  616. }
  617. /**
  618. * Checks if a person is participating in a meeting as a researcher
  619. * @param[in] $meetingId The ID of the meeting
  620. * @param[in] $eid The researcher's e-id (username)
  621. */
  622. public function isInMeeting($meetingId, $eid)
  623. {
  624. $result = self::$db->query($this->isInMeetingSQL, array(":meetingId" => $meetingId, ":eid" => $eid));
  625. return (bool)$result[0]["Count"];
  626. }
  627. /**
  628. * Checks if a person is participating in a meeting as a volunteer
  629. * @param[in] $meetingId The ID of the meeting
  630. * @param[in] $eid The volunteer's e-id (username)
  631. */
  632. public function isVolunteer($meetingId, $eid)
  633. {
  634. $result = self::$db->query($this->isVolunteerSQL, array(":meetingId" => $meetingId, ":eid" => $eid));
  635. return (bool)$result[0]["Count"];
  636. }
  637. /**
  638. * Checks if a person's team has volunteers that are still uncomfirmed
  639. * (in terms of participation) from a previously held meeting.
  640. * @param[in] $eid The e-id of the person
  641. */
  642. public function areUnconfirmedVolunteers($eid)
  643. {
  644. $result = self::$db->query($this->unconfirmedVolunteersCountSQL, array(":eid" => $eid));
  645. return (bool)$result[0]["Count"];
  646. }
  647. /**
  648. * Gets the uncomfirmed volunteers for a person's team.
  649. * @param[in] $eid The e-id of the person
  650. */
  651. public function getUnconfirmedVolunteers($eid)
  652. {
  653. $result = self::$db->query($this->unconfirmedVolunteersSQL, array(":eid" => $eid));
  654. return $result;
  655. }
  656. /**
  657. * Adds a new location in the database to be used as a meeting place
  658. * @param[in] $location The name of the new location
  659. */
  660. public function addLocation($location)
  661. {
  662. return self::$db->query($this->addLocationSQL, array(":locname" => $location));
  663. }
  664. /**
  665. * Disables or deletes locations from the database. If disabled, a location
  666. * cannot be used when scheduling new meetings. Deleting removes a location
  667. * from the database completely - even currently scheduled events. So use
  668. * with caution.
  669. * @param[in] $locations The IDs of the locations
  670. * @param[in] $locations boolean that determines whether or not to delete the locations
  671. */
  672. public function updateDisabledLocations($locations, $delete)
  673. {
  674. $result = array();
  675. if ($delete)
  676. {
  677. foreach ($locations as $l)
  678. $result[] = self::$db->query($this->deleteLocationSQL, array(":id" => $l));
  679. }
  680. $allLocations = $this->getAllLocations();
  681. foreach ($allLocations as $l)
  682. self::$db->query($this->disableLocationSQL, array(":id" => $l['LocationID'], ":usable" => 1));
  683. if (!$delete)
  684. foreach ($locations as $id)
  685. $result[] = self::$db->query($this->disableLocationSQL, array(":id" => $id, ":usable" => 0));
  686. return $result;
  687. }
  688. /**
  689. * Adds a new course to the database
  690. * @param[in] $courseName The name of the new course
  691. */
  692. public function addCourse($courseName)
  693. {
  694. return self::$db->query($this->addCourseSQL, array(":name" => $courseName));
  695. }
  696. /**
  697. * Retrieves all courses from the database
  698. */
  699. public function getAllCourses()
  700. {
  701. return self::$db->query($this->allCoursesSQL);
  702. }
  703. /**
  704. * Deletes a course from the database.
  705. * @param[in] $courseID The ID of the course
  706. */
  707. public function deleteCourse($courseID)
  708. {
  709. return self::$db->query($this->deleteCourseSQL, array(":id" => $courseID));
  710. }
  711. /**
  712. * Adds a person to a course
  713. * @param[in] $personID The ID of the person
  714. * @param[in] $courseID The ID of the course
  715. * @param[in] $isResearcher boolean determining if this person is a researcher
  716. * @param[in] $isTeacher boolean determining if this person is a teacher/admin
  717. */
  718. public function addPerson($personID, $courseID, $isResearcher, $isTeacher)
  719. {
  720. $sqlVars = array(
  721. ":isResearcher" => $isResearcher,
  722. ":isTeacher" => $isTeacher,
  723. ":personID" => $personID
  724. );
  725. $result[] = self::$db->query($this->updateUserLevelSQL, $sqlVars);
  726. $sqlVars = array(
  727. ":personID" => $personID,
  728. ":courseID" => $courseID
  729. );
  730. $result[] = self::$db->query($this->addPersonSQL, $sqlVars);
  731. return $result;
  732. }
  733. /**
  734. * Retrieves all people in the database
  735. */
  736. public function getAllPeople()
  737. {
  738. return self::$db->query($this->allPeopleSQL);
  739. }
  740. /**
  741. * Deletes a person from a course and revises their persmissions.
  742. * @param[in] $personID The ID of the person
  743. * @param[in] $courseID The ID of the course
  744. * @param[in] $isResearcher boolean determining if this person is a researcher
  745. * @param[in] $isTeacher boolean determining if this person is a teacher/admin
  746. */
  747. public function deletePerson($personID, $courseID, $isResearcher, $isTeacher)
  748. {
  749. $sqlVars = array(
  750. ":isResearcher" => $isResearcher,
  751. ":isTeacher" => $isTeacher,
  752. ":personID" => $personID
  753. );
  754. $result[] = self::$db->query($this->updateUserLevelSQL, $sqlVars);
  755. $sqlVars = array(
  756. ":personID" => $personID,
  757. ":courseID" => $courseID
  758. );
  759. $result[] = self::$db->query($this->deletePersonSQL, $sqlVars);
  760. return $result;
  761. }
  762. /**
  763. * Gets the group ID of a group.
  764. * @param[in] $name The name of the group
  765. */
  766. public function getGroupIDByName($name)
  767. {
  768. $result = self::$db->query($this->groupIDByNameSQL, array(":name" => $name));
  769. if (!empty($result))
  770. return $result[0]["TeamID"];
  771. return null;
  772. }
  773. /**
  774. * Adds a new group to the database
  775. * @param[in] $name The name of the group
  776. */
  777. public function addGroup($name)
  778. {
  779. return self::$db->query($this->addGroupSQL, array(":tname" => $name));
  780. }
  781. /**
  782. * Adds a person to a group
  783. * @param[in] $teamID The ID of the team
  784. * @param[in] $personID The ID of the person
  785. */
  786. public function addGroupPerson($teamID, $personID)
  787. {
  788. return self::$db->query($this->addGroupPersonSQL, array(":tid" => $teamID, ":pid" => $personID));
  789. }
  790. /**
  791. * Fetches all groups in the database
  792. */
  793. public function getAllGroups()
  794. {
  795. return self::$db->query($this->allGroupsSQL);
  796. }
  797. /**
  798. * Deletes a group from the database
  799. * @param[in] $teamID The ID of the team
  800. */
  801. public function deleteGroup($teamID)
  802. {
  803. return self::$db->query($this->deleteGroupSQL, array(":id", $teamID));
  804. }
  805. /**
  806. * Determines if a person is in a group that owns a particular meeting
  807. * @param[in] $meetingID The ID of the meeting
  808. * @param[in] $eid The e-id of the person (username)
  809. */
  810. public function ownsMeeting($meetingID, $eid)
  811. {
  812. $sqlVars = array(
  813. ":eid" => $eid,
  814. ":meetingID" => $meetingID
  815. );
  816. $result = self::$db->query($this->ownsMeetingSQL, $sqlVars);
  817. return !empty($result);
  818. }
  819. /**
  820. * Signs a volunteer up for a meeting
  821. * @param[in] $eid The e-id of the volunteer
  822. * @param[in] $meetingID The ID of the meeting being signed up for
  823. */
  824. public function volunteerSignUp($eid, $meetingID)
  825. {
  826. $pid = $this->getPersonID($eid);
  827. return self::$db->query($this->signUpSQL, array(":mid" => $meetingID, ":pid" => $pid));
  828. }
  829. }
  830. /**
  831. * A wrapper for the DataManagerSingleton class.
  832. * @class DataManager
  833. */
  834. class DataManager extends DataManagerSingleton
  835. {
  836. /**
  837. * Constructs the DataManager object.
  838. */
  839. public function __construct()
  840. {
  841. DataManagerSingleton::Instance();
  842. }
  843. }
  844. ?>