Beispiel #1
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;
}