I am having issues trying to figure this out. I come from a SQL background and am new to Firebase database. I am building a website that sells individual videos online. What I am trying to do seems simple but I can't for the life of me get it to work.
I want to show a page listing only the videos a user has purchased and not the entire list of videos available. Obviously, because I only want the user to access what they have purchased. Currently, I can display the list of all videos and category heading for each category. I can't figure out how to restrict this list to display only the videos the user has purchased.
Here is my Database Structure
.
As you can see I have videos and their info in a "videos" collection and users in a "users" collection. Under each user is a "pvideos" collection that shows the id of each video the user has purchased.
Any ideas on how I might write this to restrict the list to match only the videos the user has purchased?
Included is the code that displays the category heading and videos (currently) for all available videos regardless of purchase status.
var series = db.child('videos').orderByKey();
series.once('value')
.then(function (snapshot) {
snapshot.forEach(function (childSnapshot) {
var videoseries = childSnapshot.key;
console.log(videoseries);
var seriesheading = document.createElement('h3');
seriesheading.textContent = videoseries;
seriesheading.setAttribute('class', 'bg-color-2');
document.getElementById("container").appendChild(seriesheading);
var videodata = db.child('videos/' + videoseries).orderByKey();
videodata.once('value')
.then(function (snapshot) {
snapshot.forEach(function (childSnapshot) {
var videoid = childSnapshot.key;
var vimeo = childSnapshot.child('vimeo').val();
var videoname = childSnapshot.child('name').val();
var videolength = childSnapshot.child('length').val();
var videodesc = childSnapshot.child('desc').val();
console.log(videoid);
console.log(vimeo);
console.log(videoname);
console.log(videolength);
console.log(videodesc);
var videolisting = document.createElement('div');
videolisting.setAttribute('class', 'row');
videolisting.innerHTML = "<div class='col-md-6'><div class='embed-responsive embed-responsive-16by9'><iframe src='https://player.vimeo.com/video/" + vimeo + "' frameborder='0' webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe></div></div><div class='col-md-6'><h3>" + videoname + "</h3><small>" + videolength + "</small><p>" + videodesc + "</p></div><hr>";
document.getElementById("container").appendChild(videolisting);
});
});
});
});
Aucun commentaire:
Enregistrer un commentaire