001: /**********************************************************************************
002: * $URL: $
003: * $Id: $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2006,2007 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.poll.model;
021:
022: import java.util.Date;
023:
024: import org.sakaiproject.user.api.User;
025: import org.sakaiproject.user.cover.UserDirectoryService;
026: import org.sakaiproject.user.api.User;
027: import org.sakaiproject.entity.api.Entity;
028: import org.sakaiproject.event.cover.UsageSessionService;
029: import org.sakaiproject.event.api.UsageSession;
030:
031: public class VoteImpl implements Vote {
032:
033: private Long id;
034: private String userId;
035: private String ip;
036: private Long pollId;
037: private Date voteDate;
038: private Long optionid;
039: private String submissionId;
040:
041: public VoteImpl() {
042: //needed by hibernate
043: }
044:
045: public VoteImpl(Poll poll, Option option, String subId) {
046:
047: this .pollId = poll.getPollId();
048: this .optionid = option.getId();
049: this .submissionId = subId;
050:
051: // the date can default to now
052: voteDate = new Date();
053: //user is current user
054: User currentuser = UserDirectoryService.getCurrentUser();
055: userId = currentuser.getId();
056: //set the Ip to the current sessions IP
057: UsageSession usageSession = UsageSessionService.getSession();
058: ip = usageSession.getIpAddress();
059: }
060:
061: public void setId(Long value) {
062: id = value;
063:
064: }
065:
066: public Long getId() {
067:
068: return id;
069: }
070:
071: public void setUserId(String uid) {
072: userId = uid;
073:
074: }
075:
076: public String getUserId() {
077:
078: return userId;
079: }
080:
081: public void setIp(String value) {
082: ip = value;
083:
084: }
085:
086: public String getIp() {
087:
088: return ip;
089: }
090:
091: public void setVoteDate(Date date) {
092: this .voteDate = date;
093:
094: }
095:
096: public Date getVoteDate() {
097:
098: return this .voteDate;
099: }
100:
101: public void setPollOption(Long voption) {
102:
103: optionid = voption;
104: }
105:
106: public Long getPollOption() {
107:
108: return optionid;
109: }
110:
111: public void setPollId(Long value) {
112: this .pollId = value;
113:
114: }
115:
116: public Long getPollId() {
117:
118: return pollId;
119: }
120:
121: public void setSubmissionId(String sid) {
122: this .submissionId = sid;
123:
124: }
125:
126: public String getSubmissionId() {
127:
128: return this .submissionId;
129: }
130:
131: public String toString() {
132:
133: return this .pollId + ":" + this .userId + ":" + this .ip + ":"
134: + this.optionid;
135:
136: }
137:
138: }
|