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

package student;

import entities.Semester;
import entities.Thesis;
import entities.ThesisStudent;
import entities.Users;
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.SemesterSessionBeanRemote;
import manager.ThesisSessionBeanRemote;
import manager.ThesisStudentSessionBeanRemote;

/**
 *
 * @author Szilárd
 */
@ManagedBean(name="ListDiploma")
@RequestScoped
public class ListDiploma {
    @EJB
    private ThesisStudentSessionBeanRemote thesisStudentSessionBean;
    @EJB
    private ThesisSessionBeanRemote thesisSessionBean;
    @EJB
    private SemesterSessionBeanRemote semesterSessionBean;


    List<Thesis> listThesis;
    Semester semester;
    boolean listEmpty;
    HtmlDataTable tableComponent;
    Users user;
    /** Creates a new instance of ListDiploma */
    public ListDiploma() {
        Map map = FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
        user = (Users) map.get("felhasznalo");
    }

    public List<Thesis> getListThesis() {
        return this.thesisStudentSessionBean.findByStudent(user);
    }

    public void setListThesis(List<Thesis> listThesis) {
        this.listThesis = listThesis;
    }

    public Semester getSemester() {
        return this.semesterSessionBean.findOpen();
    }

    public void setSemester(Semester semester) {
        this.semester = semester;
    }

    public boolean isListEmpty() {
        return getListThesis().isEmpty();
    }

    public void setListEmpty(boolean listEmpty) {
        this.listEmpty = listEmpty;
    }

    public HtmlDataTable getTableComponent() {
        return tableComponent;
    }

    public void setTableComponent(HtmlDataTable tableComponent) {
        this.tableComponent = tableComponent;
    }

    
   
    public String backAction(){
        return "menus";
    }

    public String chooseAction(){
        boolean update = false;
        List<Thesis> t = this.thesisSessionBean.findAktiv();
        int db = t.size();
        Map m = FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
        m.put("update", update);
        m.put("db", db);
        return "listdiplomas";
    }

    public String updateAction(){
        boolean update = true;
        Thesis selected = (Thesis) tableComponent.getRowData();
        List<Thesis> t = this.thesisSessionBean.findAktiv();
        int db = t.size();
        Map m = FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
        m.put("selected", selected);
        m.put("update", update);
        m.put("db", db);
        return "listdiplomas";
    }

    public String deleteAction(){
        ThesisStudent ts = this.thesisStudentSessionBean.findByStudentID(user);
        this.thesisStudentSessionBean.delete(ts);
        return null;
    }


}
