Exemple #1
0
 /**
  * creates a new playlist for user and adds episode
  */
 public function newPlaylist($name, $user, $uniqID)
 {
     $playlist = new Playlist();
     $playlist->setUser($user);
     $playlist->setName($name);
     $episode = $this->em->getRepository('AppBundle:Episode')->findOneBy(['uniqID' => $uniqID]);
     $playlistItem = new PlaylistItem();
     $playlistItem->setEpisode($episode);
     $playlist->addItem($playlistItem);
     $this->em->persist($playlist);
     $this->em->persist($playlistItem);
     $this->em->flush();
 }
Exemple #2
0
            //indicate the requester is not the playlist owner and is not allowed to update it
            return;
        }
        //get request's body containing array of track's id
        if (!array_key_exists('body', $api->query)) {
            $api->output(400, 'Track identifiers must be provided in request body');
            //tracks identifier were not provided, return an error
            return;
        }
        $tracks = $api->query['body'];
        if (!is_array($tracks)) {
            $api->output(400, 'Track identifiers must be provided in an array');
            //tracks identifier were not provided, return an error
            return;
        }
        //add each tracks
        foreach ($tracks as $track) {
            $playlistItem = new PlaylistItem($userId, null, $track->id);
            $playlistItem->insert();
        }
        //get full user's playlist for response
        $playlist = new Playlist($userId);
        $playlist->populate();
        if (count($playlist->tracks) === 0) {
            $api->output(204, null);
            //user's playlist is empty
            return;
        }
        $api->output(200, $playlist->tracks);
        break;
}