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

package admin;

import entities.Thesis;
import entities.Users;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.model.SelectItem;
import manager.SemesterSessionBeanRemote;
import manager.ThesisSessionBeanRemote;
import manager.UserSessionBeanRemote;

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


    Thesis thesis;
    ArrayList<SelectItem> listTeachers;
    Long teacherId;
    /** Creates a new instance of CreateThesis */
    public CreateThesis() {
        thesis = new Thesis();
    }

    public Thesis getThesis() {
        return thesis;
    }

    public void setThesis(Thesis thesis) {
        this.thesis = thesis;
    }

    public Long getTeacherId() {
        return teacherId;
    }

    public void setTeacherId(Long teacherId) {
        this.teacherId = teacherId;
    }

    public ArrayList getListTeachers() {
        List<Users> teachers = this.userSessionBean.findTeacher();
        listTeachers = new ArrayList();
        for(Users akt: teachers){
            listTeachers.add(new SelectItem(akt.getId(),akt.getName()));
        }
        return listTeachers;
    }

    public void setListTeachers(ArrayList listTeachers) {
        this.listTeachers = listTeachers;
    }

    public String backAction(){
        return "listthesis.jsp";
    }

    public String saveAction(){
        thesis.setTeacherId(this.userSessionBean.findById(teacherId));
        thesis.setSemesterId(this.semesterSessionBean.findOpen());
        this.thesisSessionBean.newThesis(thesis);
        return "listthesis.jsp";
    }

}
