use of net.jforum.entities.PollOption in project jforum2 by rafaelsteil.
the class GenericPollDAO method updatePollOptions.
protected void updatePollOptions(int pollId, List options) throws SQLException {
PreparedStatement p = null;
try {
p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("PollModel.updatePollOption"));
for (Iterator iter = options.iterator(); iter.hasNext(); ) {
PollOption o = (PollOption) iter.next();
p.setString(1, o.getText());
p.setInt(2, o.getId());
p.setInt(3, pollId);
p.executeUpdate();
}
} finally {
DbUtils.close(p);
}
}
use of net.jforum.entities.PollOption in project jforum2 by rafaelsteil.
the class GenericPollDAO method makePollOption.
protected PollOption makePollOption(ResultSet rs) throws SQLException {
PollOption option = new PollOption();
option.setPollId(rs.getInt("vote_id"));
option.setId(rs.getInt("vote_option_id"));
option.setText(rs.getString("vote_option_text"));
option.setVoteCount(rs.getInt("vote_result"));
return option;
}
use of net.jforum.entities.PollOption in project jforum2 by rafaelsteil.
the class PollCommon method fillPollFromRequest.
public static Poll fillPollFromRequest() {
RequestContext request = JForumExecutionContext.getRequest();
String label = request.getParameter("poll_label");
if (label == null || label.length() == 0) {
return null;
}
Poll poll = new Poll();
poll.setStartTime(new Date());
poll.setLabel(label);
int count = request.getIntParameter("poll_option_count");
for (int i = 0; i <= count; i++) {
String option = request.getParameter("poll_option_" + i);
if (option == null) {
continue;
}
option = option.trim();
if (option.length() > 0) {
PollOption po = new PollOption();
po.setId(i);
po.setText(option);
poll.addOption(po);
}
}
String pollLength = request.getParameter("poll_length");
if (pollLength != null && pollLength.length() > 0) {
poll.setLength(Integer.parseInt(pollLength));
}
return poll;
}
use of net.jforum.entities.PollOption in project jforum2 by rafaelsteil.
the class GenericPollDAO method addNewPollOptions.
protected void addNewPollOptions(int pollId, List options) {
Connection connection = JForumExecutionContext.getConnection();
PreparedStatement p = null;
ResultSet rs = null;
try {
p = connection.prepareStatement(SystemGlobals.getSql("PollModel.selectMaxVoteId"));
p.setInt(1, pollId);
rs = p.executeQuery();
rs.next();
int optionId = rs.getInt(1);
rs.close();
rs = null;
p.close();
p = null;
p = connection.prepareStatement(SystemGlobals.getSql("PollModel.addNewPollOption"));
for (Iterator iter = options.iterator(); iter.hasNext(); ) {
PollOption option = (PollOption) iter.next();
p.setInt(1, pollId);
p.setInt(2, ++optionId);
p.setString(3, option.getText());
p.executeUpdate();
}
} catch (SQLException e) {
throw new DatabaseException(e);
} finally {
DbUtils.close(rs, p);
}
}
use of net.jforum.entities.PollOption in project jforum2 by rafaelsteil.
the class GenericPollDAO method deletePollOptions.
protected void deletePollOptions(int pollId, List deleted) throws SQLException {
Connection connection = JForumExecutionContext.getConnection();
PreparedStatement options = null;
try {
options = connection.prepareStatement(SystemGlobals.getSql("PollModel.deletePollOption"));
for (Iterator iter = deleted.iterator(); iter.hasNext(); ) {
PollOption o = (PollOption) iter.next();
// Option
options.setInt(1, pollId);
options.setInt(2, o.getId());
options.executeUpdate();
}
} finally {
DbUtils.close(options);
}
}
Aggregations