/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package admin;

import entities.CurrentSubject;
import entities.Lesson;
import entities.Subject;
import java.util.List;
import java.util.Map;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.component.html.HtmlDataTable;
import javax.faces.context.FacesContext;
import manager.LessionSessionBeanRemote;

/**
 *
 * @author Szilárd
 */
@ManagedBean(name="CreateSubject")
@RequestScoped
public class CreateSubject {
    @EJB
    private LessionSessionBeanRemote lessionSessionBean;

    CurrentSubject currentSubject;
    List<Lesson> listLessonL;
    List<Lesson> listLessonP;
    HtmlDataTable tableComponentL, tableComponentP;
    boolean current;
    String utvonal;
    int listSize1,listSize2;

    public CreateSubject() {
        Map m = FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
        this.currentSubject =  (CurrentSubject) m.get("currentsubject");
        this.utvonal =(String) m.get("utvonal");
        current = (utvonal != null) ? true : false;
    }

    public List<Lesson> getListLessonL() {
        return this.lessionSessionBean.findByL(currentSubject);
    }

    public void setListLessonL(List<Lesson> listLessonL) {
        this.listLessonL = listLessonL;
    }

    public List<Lesson> getListLessonP() {
        return this.lessionSessionBean.findByP(currentSubject);
    }

    public void setListLessonP(List<Lesson> listLessonP) {
        this.listLessonP = listLessonP;
    }

    public CurrentSubject getCurrentSubject() {
        return currentSubject;
    }

    public void setCurrentSubject(CurrentSubject currentSubject) {
        this.currentSubject = currentSubject;
    }


    public HtmlDataTable getTableComponentL() {
        return tableComponentL;
    }

    public void setTableComponentL(HtmlDataTable tableComponentL) {
        this.tableComponentL = tableComponentL;
    }

    public HtmlDataTable getTableComponentP() {
        return tableComponentP;
    }

    public void setTableComponentP(HtmlDataTable tableComponentP) {
        this.tableComponentP = tableComponentP;
    }

    public int getListSize1() {
        return getListLessonL().size();
    }

    public void setListSize1(int listSize1) {
        this.listSize1 = listSize1;
    }

    public int getListSize2() {
        return getListLessonP().size();
    }

    public void setListSize2(int listSize2) {
        this.listSize2 = listSize2;
    }




    public String backAction(){
        if(current)
            return "listcurrentsubject.jsp";
        else
            return "listsubject.jsp";
    }

    public String saveAction(){
        if(current)
            return "listcurrentsubject.jsp";
        else
            return "listsubject.jsp";
    }

    public String updateLectureAction(){
        return null;
    }

    public String addLectureAction(){
        String type = "Lecture";
        Map m = FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
        m.put("type", type);
        return "createlesson.jsp";
    }

    public String addPracticeAction(){
        String type = "Practice";
        Map m = FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
        m.put("type", type);
        return "createlesson.jsp";
    }

}
