jeudi 27 septembre 2018

How do I make my user student view all the classrooms he/she belong to?

In my web app, there are 2 types of user: Teacher and Student

A Teacher can create virtual classrooms and view the students who joined his/her rooms.

While Student can join a classroom and should be able to see the classroom he/she joined to.

These codes allow the Teacher to create a classroom:

function classcreation(q)
    {
        var checkcn = document.getElementById('classroomName').value;
        if(checkcn == "" && checkcn == null){
            alert("Empty Class Name!!");
            }
            else {
              var usuid = generateId();
              var myClasses={};
              myClasses.TheClass = 
                        document.getElementById('classroomName').value;
              myClasses.Teacher = user.displayName;
              myClasses.TeacherID = user.uid;
              myClasses.ClassID = usuid;
              fbclass.child(user.uid).push().set(myClasses);
                }
      }

and these to allow the teacher to view the classrooms he/she created as well as the students who joined his/her room/s.

var userRef = firebase.database().ref().child('Classes' + '/' + user.uid);
      userRef.on('child_added', function(data)
      {
            var roomNames = data.val().TheClass;
            var Studentx = data.val().MyStudents;

            var studentRawList = '';
            for (var key in Studentx) {
                studentRawList += ('['+Studentx[key].Studentname + ']');
            }

            var classD = data.val().ClassID;
            var ul = document.createElement('ul');
            document.getElementById('myList').appendChild(ul);
            var li = document.createElement('li');
            ul.appendChild(li);

            Object.keys(roomNames).forEach(function(key){
            li.innerHTML += '<span onclick="clickDone(this)">'
                             +roomNames[key]+'</span>
                             <ul style="display:none">
                             <li>Class Id : '+classD+'</li>
                             <li><span onclick="clickDone(this)">Students : 
                             </span><ul style="display:none">
                             <li>'+studentRawList+'</li></ul></li></ul>';
              });
            });

JSON:

{
  "Accounts" : {
    "FykyhzEZjndylFj3BbCnPqoTGDo1" : {
      "displayName" : "Dodong Advices",
      "email" : "advicenidodong@gmail.com",
      "status" : "Teacher"
    },
    "HOgdSlTed9V8g0kSZjizgODMDOe2" : {
      "displayName" : "Sweet Macaroni",
      "email" : "Sweet@gmail.com",
      "status" : "Student"
    },
    "yJif4ReTxCcGmo682xWSG3L5MKE3" : {
      "displayName" : "Purple Salad",
      "email" : "Purple@gmail.com",
      "status" : "Student"
    }
  },
  "Classes" : {
    "FykyhzEZjndylFj3BbCnPqoTGDo1" : {
      "-LMpvlBl3mEazhxaJwqb" : {
        "ClassID" : "6503-3503-6827",
        "Teacher" : "Dodong Advices",
        "TeacherID" : "FykyhzEZjndylFj3BbCnPqoTGDo1",
        "TheClass" : "StackMates"
      },
      "-LMrfIBg8v-hj1k8X2Qf" : {
        "ClassID" : "7583-2402-2757",
        "MyStudents" : {
          "HOgdSlTed9V8g0kSZjizgODMDOe2" : {
            "Studentname" : "Sweet Macaroni"
          }
        },
        "Teacher" : "Dodong Advices",
        "TeacherID" : "FykyhzEZjndylFj3BbCnPqoTGDo1",
        "TheClass" : "asdasd"
      },
      "-LMrfMV1aw3YNA0PfooR" : {
        "ClassID" : "8083-2712-3347",
        "MyStudents" : {
          "HOgdSlTed9V8g0kSZjizgODMDOe2" : {
            "Studentname" : "Sweet Macaroni"
          },
          "yJif4ReTxCcGmo682xWSG3L5MKE3" : {
            "Studentname" : "Purple Salad"
          }
        },
        "Teacher" : "Dodong Advices",
        "TeacherID" : "FykyhzEZjndylFj3BbCnPqoTGDo1",
        "TheClass" : "Trial"
      }
    }
  }
 }

So based on JSON, we have 2 Student user named: Sweet Macaroni and Purple Salad. Sweet Macaroni joined a class asdasd and Trial while Purple Salad only joined the classroom Trial

The question is, how do I allow the each user student to see/view the rooms they belong to?




Aucun commentaire:

Enregistrer un commentaire