Example #1
0
 public function deleteTrack($request, $db)
 {
     // Check for login
     if (!isset($request->user_id)) {
         throw new Exception("You must be logged in to delete this track", 401);
     }
     $track_id = $this->getItemId($request);
     $track_mapper = new TrackMapper($db, $request);
     $tracks = $track_mapper->getTrackById($track_id, true);
     if (!$tracks) {
         throw new Exception("Track not found", 404);
     }
     $event_mapper = new EventMapper($db, $request);
     $events = $event_mapper->getEventByTrackId($track_id, true, false, false);
     if (!$events || !$events[0]['ID']) {
         throw new Exception("Associated event not found", 404);
     }
     $event_id = $events[0]['ID'];
     if (!$event_mapper->thisUserHasAdminOn($event_id)) {
         throw new Exception('You do not have permission to delete this track', 403);
     }
     $track_mapper->deleteEventTrack($track_id);
     header("Content-Length: 0", null, 204);
     exit;
 }
Example #2
0
 /**
  * Remove a track from a talk by DELETEing to /talks/123/tracks/456
  *
  * @param PDO $db
  * @param Request $request
  */
 public function removeTrackFromTalk(Request $request, PDO $db)
 {
     if (!isset($request->user_id)) {
         throw new Exception("You must be logged in to create data", 400);
     }
     $talk_id = $this->getItemId($request);
     $track_id = $request->url_elements[5];
     $talk_mapper = new TalkMapper($db, $request);
     $talk = $talk_mapper->getTalkById($talk_id);
     if (!$talk) {
         throw new Exception("Talk not found", 404);
     }
     $is_admin = $talk_mapper->thisUserHasAdminOn($talk_id);
     $is_speaker = $talk_mapper->isUserASpeakerOnTalk($talk_id, $request->user_id);
     if (!($is_admin || $is_speaker)) {
         throw new Exception("You do not have permission to remove this talk from this track", 400);
     }
     // is this track on this event?
     $event_mapper = new EventMapper($db, $request);
     $track_events = $event_mapper->getEventByTrackId($track_id, true, false, false);
     if (!$track_events || !$track_events[0]['ID']) {
         throw new Exception("Associated event not found", 400);
     }
     $track_event_id = $track_events[0]['ID'];
     if ($talk->event_id != $track_event_id) {
         throw new Exception("This talk cannot be added to this track", 400);
     }
     // delete track from talk
     $talk_mapper->removeTrackFromTalk($talk_id, $track_id);
     $uri = $request->base . '/' . $request->version . '/talks/' . $talk_id;
     header('Location: ' . $uri, null, 204);
     exit;
 }