Skip to content

Commit

Permalink
SAK-42584 - Add percentage of voters (sakaiproject#7406)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmerino authored and Miguel Pellicer committed Oct 4, 2019
1 parent 71abaa3 commit f43d948
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -232,5 +232,10 @@ public interface ExternalLogic {
* Register a statement with the system LearningResourceStoreService
*/
public void registerStatement(String pollText, boolean newPoll, String pollId);

/**
* Get the total number of users that have permission for voting
*/
public int getNumberUsersCanVote();

}
Original file line number Diff line number Diff line change
Expand Up @@ -515,5 +515,12 @@ public void registerStatement(String pollText, boolean newPoll, String pollId) {
eventTrackingService.post(event);
}
}

@Override
public int getNumberUsersCanVote() {
ArrayList<String> siteGroupRefs = new ArrayList<>();
siteGroupRefs.add(siteService.siteReference(developerHelperService.getCurrentLocationId()));
return (authzGroupService.getUsersIsAllowed(PollListManager.PERMISSION_VOTE, siteGroupRefs).size());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -211,5 +211,10 @@ public void registerStatement(String pollText, Vote vote) {
public void registerStatement(String pollText, boolean newPoll, String pollId) {
// TODO Auto-generated method stub
}

@Override
public int getNumberUsersCanVote() {
return 0;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ results_answers_reset_ordering=Borrar orden
results_answers_numbering=N\u00famero de opci\u00f3n
results_answers_numbering_tooltip=Ordenar por opci\u00f3n
result_novote=No ha seleccionado ninguna opci\u00f3n
results_poll_size=N\u00famero de votos\: {0}
results_poll_size=N\u00famero de votantes\: {0}
results_cancel=Volver
results_cancel_tooltip=Volver
results_chart_type=Tipo de gr\u00e1fico\:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

package org.sakaiproject.poll.tool.producers;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -135,9 +137,11 @@ public void fillComponents(UIContainer tofill, ViewParameters viewparams,

//get the number of votes
int voters = pollVoteManager.getDisctinctVotersForPoll(poll);
//Object[] args = new Object[] { Integer.valueOf(voters).toString()};
if (poll.getMaxOptions()>1)
UIOutput.make(tofill,"poll-size",messageLocator.getMessage("results_poll_size",Integer.valueOf(voters).toString()));
int totalVoters = externalLogic.getNumberUsersCanVote();
BigDecimal percentVoters = new BigDecimal(voters).divide(new BigDecimal(totalVoters),4, RoundingMode.HALF_UP).multiply(new BigDecimal(100));
String statsVoters = String.format("%d / %d (%.02f %%)",voters,totalVoters,percentVoters);

UIOutput.make(tofill,"poll-size",messageLocator.getMessage("results_poll_size",statsVoters));

log.debug(voters + " have voted on this poll");

Expand Down

0 comments on commit f43d948

Please sign in to comment.