package com.ese.ils.beta.beans; import java.io.Serializable; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; import javax.faces.bean.ManagedBean; import javax.faces.bean.ManagedProperty; import javax.faces.bean.ViewScoped; import javax.faces.event.ActionEvent; import javax.faces.model.SelectItem; import org.icefaces.ace.component.chart.Axis; import org.icefaces.ace.component.chart.AxisType; import org.icefaces.ace.model.chart.CartesianSeries; import com.liferay.portal.kernel.exception.PortalException; import com.liferay.portal.kernel.exception.SystemException; import com.liferay.portal.service.ServiceContext; import com.liferay.portlet.polls.model.PollsChoice; import com.liferay.portlet.polls.model.PollsQuestion; import com.liferay.portlet.polls.service.PollsChoiceLocalServiceUtil; import com.liferay.portlet.polls.service.PollsQuestionLocalServiceUtil; import com.liferay.portlet.polls.service.PollsQuestionServiceUtil; import com.liferay.portlet.polls.service.PollsVoteLocalServiceUtil; /** * * @author julienhofer * behandelt Gruppenfunktionen und Navigation bei Gruppenfunktionalitaet * */ @ManagedBean @ViewScoped public class DozentVoteBackingBean implements Serializable{ private static final long serialVersionUID = 852961628691348427L; @ManagedProperty(value="#{dozentVoteNavigationBean}") private transient DozentVoteNavigationBean dozentVoteNavigationBean; @ManagedProperty(value="#{dozentGroupNavigationBean}") private transient DozentGroupNavigationBean dozentGroupNavigationBean; @ManagedProperty(value="#{dozentNavigationBean}") private transient DozentNavigationBean dozentNavigationBean; @ManagedProperty(value="#{dozentMessageBean}") private transient DozentMessageBean dozentMessageBean; //Variables private String dozentQuestionTitle; private String dozentQuestionText; private String dozentCurrentVoteId ="00000"; private List<SelectItem> dozentVoteItems; private boolean dozentDisableVoteStatus = false; private List<CartesianSeries> dozentBarData; //ANSWEROPTIONS private String dozentChoiceA; private String dozentChoiceB; private String dozentChoiceC; private String dozentChoiceD; private int dozentVoteCountA = 14; /** * erzeugt eine neue Umfrage * @param event */ public void createVote(ActionEvent event) { createVoting(); dozentMessageBean.showMessage(event, "Umfrage wurde erfolgreich erstellt!"); } /** * erzeugt einen neuen Umfragedatensatz in der Datenbank */ public void createVoting(){ ServiceContext serviceContext = new ServiceContext(); Map<Locale,String> titleMap = new HashMap<Locale,String>(); titleMap.put(new Locale("en","US"),dozentQuestionTitle); Map<Locale,String> descriptionMap = new HashMap<Locale,String>(); descriptionMap.put(new Locale("en","US"),dozentQuestionText); try { PollsQuestion pQuestion = PollsQuestionServiceUtil.addQuestion(titleMap, descriptionMap, 0, 0, 0, 0, 0, true, null, serviceContext); dozentCurrentVoteId=""+pQuestion.getQuestionId(); PollsChoiceLocalServiceUtil.addChoice(pQuestion.getQuestionId(), "A", dozentChoiceA, serviceContext); PollsChoiceLocalServiceUtil.addChoice(pQuestion.getQuestionId(), "B", dozentChoiceB, serviceContext); PollsChoiceLocalServiceUtil.addChoice(pQuestion.getQuestionId(), "C", dozentChoiceC, serviceContext); PollsChoiceLocalServiceUtil.addChoice(pQuestion.getQuestionId(), "D", dozentChoiceD, serviceContext); System.out.println("Umfrage wurde erfolgreich erstellt!!!"); } catch (PortalException e) { e.printStackTrace(); } catch (SystemException e) { e.printStackTrace(); } } /** * bereinigt die Umfragevariablen */ public void clearDozentVoteFields(){ dozentQuestionTitle=""; dozentQuestionText=""; dozentChoiceA=""; dozentChoiceB=""; dozentChoiceC=""; dozentChoiceD=""; } /** * holt alle UmfrageObjekte aus der Datenbank und speichert sie * in der Liste dozentVoteItems */ public void fetchVoteItems() { try { dozentVoteItems = new ArrayList<SelectItem>(); int pQEnd = PollsQuestionLocalServiceUtil.getPollsQuestionsCount() - 1; int pQStart = 0; for(PollsQuestion pQuestion:PollsQuestionLocalServiceUtil.getPollsQuestions(pQStart, pQEnd)) { dozentVoteItems.add(new SelectItem(pQuestion.getQuestionId(),""+pQuestion.getTitleCurrentValue())); } } catch (SystemException sysEx) { sysEx.printStackTrace(); } } /** * holt eine Umfrage mit * Titel <code>dozentQuestionTitle</code>, * Frage <code>dozentQuestionText</code> * und Antwortoptionen * <code>dozentChoiceA</code>, * <code>dozentChoiceB</code>, * <code>dozentChoiceC</code>, * <code>dozentChoiceD</code> * aus der Datenbank * */ public void fetchVote() { try { PollsQuestion pQuestion = PollsQuestionLocalServiceUtil.getPollsQuestion(Long.valueOf(dozentCurrentVoteId)); dozentQuestionTitle = pQuestion.getTitleCurrentValue(); dozentQuestionText = pQuestion.getDescriptionCurrentValue(); List<PollsChoice> choiceList = pQuestion.getChoices(); dozentChoiceA=choiceList.get(0).getDescription(); dozentChoiceB=choiceList.get(1).getDescription(); dozentChoiceC=choiceList.get(2).getDescription(); dozentChoiceD=choiceList.get(3).getDescription(); } catch (NumberFormatException e) { e.printStackTrace(); } catch (PortalException e) { e.printStackTrace(); } catch (SystemException e) { e.printStackTrace(); } } /** * loescht eine Umfrage */ public void deleteVote() { try { PollsQuestionServiceUtil.deleteQuestion(Integer.valueOf(dozentCurrentVoteId)); System.out.println("Umfrage geloescht!!!"); fetchVoteItems(); } catch (PortalException e) { e.printStackTrace(); } catch (SystemException e) { e.printStackTrace(); } } /** * bearbeitet eine Umfrage * @param event */ public void editVote(ActionEvent event) { deleteVote(); createVoting(); dozentMessageBean.showMessage(event, "Umfrage wurde erfolgreich editiert!"); } //Chart Methods /** * holt die Daten fuer das Umfrage Diagramm aus der Datenbank */ public void fetchResults(){ try { dozentBarData = new ArrayList<CartesianSeries>() {{ add(new CartesianSeries() {{ setType(CartesianType.BAR); PollsQuestion pQuestion = PollsQuestionLocalServiceUtil.getPollsQuestion(Long.valueOf(dozentCurrentVoteId)); add("A", PollsVoteLocalServiceUtil.getChoiceVotesCount(pQuestion.getChoices().get(0).getChoiceId())); add("B", PollsVoteLocalServiceUtil.getChoiceVotesCount(pQuestion.getChoices().get(1).getChoiceId())); add("C", PollsVoteLocalServiceUtil.getChoiceVotesCount(pQuestion.getChoices().get(2).getChoiceId())); add("D", PollsVoteLocalServiceUtil.getChoiceVotesCount(pQuestion.getChoices().get(3).getChoiceId())); }}); }}; } catch (NumberFormatException e) { e.printStackTrace(); } catch (PortalException e) { e.printStackTrace(); } catch (SystemException e) { e.printStackTrace(); } } private Axis dozentBarDemoDefaultAxis = new Axis() {{ setTickAngle(0); }}; private Axis dozentBarDemoXAxis = new Axis() {{ setType(AxisType.CATEGORY); }}; private Axis dozentBarDemoYAxis = new Axis() {{ setAutoscale(true); setTickInterval("1"); setLabel("Anz. Votes"); }}; //Navigation Methods /** * navigiert zum Erstellen von Umfragen * @param event */ public void moveToDozentVoteCreate(ActionEvent event) { //NavBeans dozentNavigationBean.setDozentCreateGroupsStatus(false); dozentNavigationBean.setDozentCreateNewModuleStatus(false); dozentNavigationBean.setDozentHomeContentStatus(false); dozentNavigationBean.setDozentShowGroupContentStatus(false); dozentNavigationBean.setDozentShowGroupStatus(false); dozentNavigationBean.setDozentShowModulesStatus(false); dozentNavigationBean.setDozentShowQuestionsStatus(false); dozentNavigationBean.setDozentSlideUploaderStatus(false); dozentNavigationBean.setDozentSlideViewerStatus(false); dozentNavigationBean.setDozentShowFavoritesStatus(false); dozentGroupNavigationBean.setDozentGroupContentSelectionStatus(false); dozentGroupNavigationBean.setDozentGroupSelectionStatus(false); dozentGroupNavigationBean.setDozentGroupShowContentStatus(false); //End clearDozentVoteFields(); System.out.println("Wechsle in Umfrage erstellen Sicht..."); dozentVoteNavigationBean.setDozentShowVoteStatus(false); dozentVoteNavigationBean.setDozentVoteHomeStatus(false); dozentVoteNavigationBean.setDozentResultsStatus(false); dozentVoteNavigationBean.setDozentEditVoteStatus(false); dozentVoteNavigationBean.setDozentShowVoteResultsStatus(false); dozentVoteNavigationBean.setDozentCreateVoteStatus(true); } /** * navigiert zum Selektieren von Umfragen */ public void moveToDozentEditSelectVote() { //NavBeans dozentNavigationBean.setDozentCreateGroupsStatus(false); dozentNavigationBean.setDozentCreateNewModuleStatus(false); dozentNavigationBean.setDozentHomeContentStatus(false); dozentNavigationBean.setDozentShowGroupContentStatus(false); dozentNavigationBean.setDozentShowGroupStatus(false); dozentNavigationBean.setDozentShowModulesStatus(false); dozentNavigationBean.setDozentShowQuestionsStatus(false); dozentNavigationBean.setDozentSlideUploaderStatus(false); dozentNavigationBean.setDozentSlideViewerStatus(false); dozentNavigationBean.setDozentShowFavoritesStatus(false); dozentGroupNavigationBean.setDozentGroupContentSelectionStatus(false); dozentGroupNavigationBean.setDozentGroupSelectionStatus(false); dozentGroupNavigationBean.setDozentGroupShowContentStatus(false); dozentVoteNavigationBean.setDozentShowVoteResultsStatus(false); //End System.out.println("Wechlse in Umfrage Edit Modus..."); fetchVoteItems(); dozentVoteNavigationBean.setDozentCreateVoteStatus(false); dozentVoteNavigationBean.setDozentResultsStatus(false); dozentVoteNavigationBean.setDozentVoteHomeStatus(true); dozentVoteNavigationBean.setDozentShowVoteStatus(false); dozentVoteNavigationBean.setDozentEditVoteStatus(false); } /** * navigiert zum Bearbeiten von Umfragen */ public void moveToDozentEditVote() { //NavBeans dozentNavigationBean.setDozentCreateGroupsStatus(false); dozentNavigationBean.setDozentCreateNewModuleStatus(false); dozentNavigationBean.setDozentHomeContentStatus(false); dozentNavigationBean.setDozentShowGroupContentStatus(false); dozentNavigationBean.setDozentShowGroupStatus(false); dozentNavigationBean.setDozentShowModulesStatus(false); dozentNavigationBean.setDozentShowQuestionsStatus(false); dozentNavigationBean.setDozentSlideUploaderStatus(false); dozentNavigationBean.setDozentSlideViewerStatus(false); dozentNavigationBean.setDozentShowFavoritesStatus(false); dozentGroupNavigationBean.setDozentGroupContentSelectionStatus(false); dozentGroupNavigationBean.setDozentGroupSelectionStatus(false); dozentGroupNavigationBean.setDozentGroupShowContentStatus(false); //End dozentVoteNavigationBean.setDozentCreateVoteStatus(false); dozentVoteNavigationBean.setDozentResultsStatus(false); dozentVoteNavigationBean.setDozentVoteHomeStatus(false); dozentVoteNavigationBean.setDozentShowVoteStatus(false); dozentVoteNavigationBean.setDozentVoteHomeStatus(false); dozentVoteNavigationBean.setDozentShowVoteResultsStatus(false); dozentVoteNavigationBean.setDozentEditVoteStatus(true); fetchVote(); } /** * navigiert zum Anzeigen von Umfrageergebnissen (Diagramm) */ public void moveToShowVoteResults() { //NavBeans dozentNavigationBean.setDozentCreateGroupsStatus(false); dozentNavigationBean.setDozentCreateNewModuleStatus(false); dozentNavigationBean.setDozentHomeContentStatus(false); dozentNavigationBean.setDozentShowGroupContentStatus(false); dozentNavigationBean.setDozentShowGroupStatus(false); dozentNavigationBean.setDozentShowModulesStatus(false); dozentNavigationBean.setDozentShowQuestionsStatus(false); dozentNavigationBean.setDozentSlideUploaderStatus(false); dozentNavigationBean.setDozentSlideViewerStatus(false); dozentNavigationBean.setDozentShowFavoritesStatus(false); dozentVoteNavigationBean.setDozentCreateVoteStatus(false); dozentVoteNavigationBean.setDozentResultsStatus(false); dozentVoteNavigationBean.setDozentVoteHomeStatus(false); dozentVoteNavigationBean.setDozentShowVoteStatus(false); dozentVoteNavigationBean.setDozentVoteHomeStatus(false); dozentVoteNavigationBean.setDozentEditVoteStatus(false); dozentGroupNavigationBean.setDozentGroupContentSelectionStatus(false); dozentGroupNavigationBean.setDozentGroupSelectionStatus(false); dozentGroupNavigationBean.setDozentGroupShowContentStatus(false); dozentVoteNavigationBean.setDozentShowVoteResultsStatus(true); fetchVoteItems(); } //GETTER SETTER public String getDozentQuestionTitle() { return dozentQuestionTitle; } public void setDozentQuestionTitle(String dozentQuestionTitle) { this.dozentQuestionTitle = dozentQuestionTitle; } public String getDozentQuestionText() { return dozentQuestionText; } public void setDozentQuestionText(String dozentQuestionText) { this.dozentQuestionText = dozentQuestionText; } public String getDozentCurrentVoteId() { return dozentCurrentVoteId; } public void setDozentCurrentVoteId(String dozentCurrentVoteId) { this.dozentCurrentVoteId = dozentCurrentVoteId; } public List<SelectItem> getDozentVoteItems() { return dozentVoteItems; } public void setDozentVoteItems(List<SelectItem> dozentVoteItems) { this.dozentVoteItems = dozentVoteItems; } public boolean isDozentDisableVoteStatus() { return dozentDisableVoteStatus; } public void setDozentDisableVoteStatus(boolean dozentDisableVoteStatus) { this.dozentDisableVoteStatus = dozentDisableVoteStatus; } public List<CartesianSeries> getDozentBarData() { return dozentBarData; } public void setDozentBarData(List<CartesianSeries> dozentBarData) { this.dozentBarData = dozentBarData; } public String getDozentChoiceA() { return dozentChoiceA; } public void setDozentChoiceA(String dozentChoiceA) { this.dozentChoiceA = dozentChoiceA; } public String getDozentChoiceB() { return dozentChoiceB; } public void setDozentChoiceB(String dozentChoiceB) { this.dozentChoiceB = dozentChoiceB; } public String getDozentChoiceC() { return dozentChoiceC; } public void setDozentChoiceC(String dozentChoiceC) { this.dozentChoiceC = dozentChoiceC; } public String getDozentChoiceD() { return dozentChoiceD; } public void setDozentChoiceD(String dozentChoiceD) { this.dozentChoiceD = dozentChoiceD; } public int getDozentVoteCountA() { return dozentVoteCountA; } public void setDozentVoteCountA(int dozentVoteCountA) { this.dozentVoteCountA = dozentVoteCountA; } public DozentVoteNavigationBean getDozentVoteNavigationBean() { return dozentVoteNavigationBean; } public void setDozentVoteNavigationBean( DozentVoteNavigationBean dozentVoteNavigationBean) { this.dozentVoteNavigationBean = dozentVoteNavigationBean; } public DozentGroupNavigationBean getDozentGroupNavigationBean() { return dozentGroupNavigationBean; } public void setDozentGroupNavigationBean( DozentGroupNavigationBean dozentGroupNavigationBean) { this.dozentGroupNavigationBean = dozentGroupNavigationBean; } public DozentNavigationBean getDozentNavigationBean() { return dozentNavigationBean; } public void setDozentNavigationBean(DozentNavigationBean dozentNavigationBean) { this.dozentNavigationBean = dozentNavigationBean; } public Axis getDozentBarDemoDefaultAxis() { return dozentBarDemoDefaultAxis; } public void setDozentBarDemoDefaultAxis(Axis dozentBarDemoDefaultAxis) { this.dozentBarDemoDefaultAxis = dozentBarDemoDefaultAxis; } public Axis getDozentBarDemoXAxis() { return dozentBarDemoXAxis; } public void setDozentBarDemoXAxis(Axis dozentBarDemoXAxis) { this.dozentBarDemoXAxis = dozentBarDemoXAxis; } public Axis getDozentBarDemoYAxis() { return dozentBarDemoYAxis; } public void setDozentBarDemoYAxis(Axis dozentBarDemoYAxis) { this.dozentBarDemoYAxis = dozentBarDemoYAxis; } public DozentMessageBean getDozentMessageBean() { return dozentMessageBean; } public void setDozentMessageBean(DozentMessageBean dozentMessageBean) { this.dozentMessageBean = dozentMessageBean; } }