use of net.jforum.dao.UserDAO in project jforum2 by rafaelsteil.
the class UserAction method groupsSave.
// Groups Save
public void groupsSave() {
int userId = this.request.getIntParameter("user_id");
UserDAO um = DataAccessDriver.getInstance().newUserDAO();
GroupDAO gm = DataAccessDriver.getInstance().newGroupDAO();
// Remove the old groups
List allGroupsList = gm.selectAll();
int[] allGroups = new int[allGroupsList.size()];
int counter = 0;
for (Iterator iter = allGroupsList.iterator(); iter.hasNext(); counter++) {
Group g = (Group) iter.next();
allGroups[counter] = g.getId();
}
um.removeFromGroup(userId, allGroups);
// Associate the user to the selected groups
String[] selectedGroups = this.request.getParameterValues("groups");
if (selectedGroups == null) {
selectedGroups = new String[0];
}
int[] newGroups = new int[selectedGroups.length];
for (int i = 0; i < selectedGroups.length; i++) {
newGroups[i] = Integer.parseInt(selectedGroups[i]);
}
um.addToGroup(userId, newGroups);
SecurityRepository.remove(userId);
this.list();
}
use of net.jforum.dao.UserDAO in project jforum2 by rafaelsteil.
the class HottestTopicsAction method showTopicsByUser.
public void showTopicsByUser() {
DataAccessDriver da = DataAccessDriver.getInstance();
UserDAO udao = da.newUserDAO();
User u = udao.selectById(this.request.getIntParameter("user_id"));
if (u.getId() == 0) {
this.context.put("message", I18n.getMessage("User.notFound"));
this.setTemplateName(TemplateKeys.USER_NOT_FOUND);
return;
}
TopicsCommon.topicListingBase();
int start = ViewCommon.getStartPage();
int topicsPerPage = SystemGlobals.getIntValue(ConfigKeys.TOPICS_PER_PAGE);
int postsPerPage = SystemGlobals.getIntValue(ConfigKeys.POSTS_PER_PAGE);
this.setTemplateName(TemplateKeys.HOTTEST_USER_TOPICS_SHOW);
int totalTopics = da.newTopicDAO().countUserTopics(u.getId());
this.context.put("u", u);
this.context.put("pageTitle", I18n.getMessage("ForumListing.userTopics") + " " + u.getUsername());
this.context.put("postsPerPage", new Integer(postsPerPage));
List topics = da.newTopicDAO().selectByUserByLimit(u.getId(), start, topicsPerPage);
List l = TopicsCommon.prepareTopics(topics);
Map forums = new HashMap();
for (Iterator iter = l.iterator(); iter.hasNext(); ) {
Topic t = (Topic) iter.next();
Forum f = ForumRepository.getForum(t.getForumId());
if (f == null) {
iter.remove();
totalTopics--;
continue;
}
forums.put(new Integer(t.getForumId()), f);
}
this.context.put("topics", l);
this.context.put("forums", forums);
ViewCommon.contextToPagination(start, totalTopics, topicsPerPage);
}
use of net.jforum.dao.UserDAO in project jforum2 by rafaelsteil.
the class PostAction method edit.
private void edit(boolean preview, Post p) {
int userId = SessionFacade.getUserSession().getUserId();
if (!preview) {
PostDAO pm = DataAccessDriver.getInstance().newPostDAO();
p = pm.selectById(this.request.getIntParameter("post_id"));
// The post exist?
if (p.getId() == 0) {
this.postNotFound();
return;
}
}
boolean isModerator = SecurityRepository.canAccess(SecurityConstants.PERM_MODERATION_POST_EDIT);
boolean canEdit = SessionFacade.isLogged() && (isModerator || p.getUserId() == userId);
if (!canEdit) {
this.setTemplateName(TemplateKeys.POSTS_EDIT_CANNOTEDIT);
this.context.put("message", I18n.getMessage("CannotEditPost"));
} else {
Topic topic = TopicRepository.getTopic(new Topic(p.getTopicId()));
if (topic == null) {
topic = DataAccessDriver.getInstance().newTopicDAO().selectRaw(p.getTopicId());
}
if (!TopicsCommon.isTopicAccessible(topic.getForumId())) {
return;
}
if (topic.getStatus() == Topic.STATUS_LOCKED && !isModerator) {
this.topicLocked();
return;
}
if (preview && this.request.getParameter("topic_type") != null) {
topic.setType(this.request.getIntParameter("topic_type"));
}
if (p.hasAttachments()) {
this.context.put("attachments", DataAccessDriver.getInstance().newAttachmentDAO().selectAttachments(p.getId()));
}
Poll poll = null;
if (topic.isVote() && topic.getFirstPostId() == p.getId()) {
// It has a poll associated with the topic
PollDAO poolDao = DataAccessDriver.getInstance().newPollDAO();
poll = poolDao.selectById(topic.getVoteId());
}
this.setTemplateName(TemplateKeys.POSTS_EDIT);
this.context.put("attachmentsEnabled", SecurityRepository.canAccess(SecurityConstants.PERM_ATTACHMENTS_ENABLED, Integer.toString(p.getForumId())));
this.context.put("moderationLoggingEnabled", SystemGlobals.getBoolValue(ConfigKeys.MODERATION_LOGGING_ENABLED));
QuotaLimit ql = new AttachmentCommon(this.request, p.getForumId()).getQuotaLimit(userId);
this.context.put("maxAttachmentsSize", new Long(ql != null ? ql.getSizeInBytes() : 1));
this.context.put("isEdit", true);
this.context.put("maxAttachments", SystemGlobals.getValue(ConfigKeys.ATTACHMENTS_MAX_POST));
this.context.put("smilies", SmiliesRepository.getSmilies());
this.context.put("forum", ForumRepository.getForum(p.getForumId()));
this.context.put("action", "editSave");
this.context.put("post", p);
this.context.put("setType", p.getId() == topic.getFirstPostId());
this.context.put("topic", topic);
this.context.put("poll", poll);
this.context.put("pageTitle", I18n.getMessage("PostShow.messageTitle") + " " + p.getSubject());
this.context.put("isModerator", isModerator);
this.context.put("start", this.request.getParameter("start"));
this.context.put("htmlAllowed", SecurityRepository.canAccess(SecurityConstants.PERM_HTML_DISABLED, Integer.toString(topic.getForumId())));
this.context.put("canCreateStickyOrAnnouncementTopics", SecurityRepository.canAccess(SecurityConstants.PERM_CREATE_STICKY_ANNOUNCEMENT_TOPICS));
this.context.put("canCreatePolls", SecurityRepository.canAccess(SecurityConstants.PERM_CREATE_POLL));
}
UserDAO udao = DataAccessDriver.getInstance().newUserDAO();
User u = udao.selectById(userId);
ViewCommon.prepareUserSignature(u);
if (preview) {
u.setNotifyOnMessagesEnabled(this.request.getParameter("notify") != null);
if (u.getId() != p.getUserId()) {
// Probably a moderator is editing the message
User previewUser = udao.selectById(p.getUserId());
ViewCommon.prepareUserSignature(previewUser);
this.context.put("previewUser", previewUser);
}
}
this.context.put("user", u);
}
use of net.jforum.dao.UserDAO in project jforum2 by rafaelsteil.
the class RecentTopicsAction method showTopicsByUser.
public void showTopicsByUser() {
DataAccessDriver da = DataAccessDriver.getInstance();
UserDAO udao = da.newUserDAO();
User u = udao.selectById(this.request.getIntParameter("user_id"));
if (u.getId() == 0) {
this.context.put("message", I18n.getMessage("User.notFound"));
this.setTemplateName(TemplateKeys.USER_NOT_FOUND);
return;
}
TopicsCommon.topicListingBase();
int start = ViewCommon.getStartPage();
int topicsPerPage = SystemGlobals.getIntValue(ConfigKeys.TOPICS_PER_PAGE);
int postsPerPage = SystemGlobals.getIntValue(ConfigKeys.POSTS_PER_PAGE);
this.setTemplateName(TemplateKeys.RECENT_USER_TOPICS_SHOW);
int totalTopics = da.newTopicDAO().countUserTopics(u.getId());
this.context.put("u", u);
this.context.put("pageTitle", I18n.getMessage("ForumListing.userTopics") + " " + u.getUsername());
this.context.put("postsPerPage", new Integer(postsPerPage));
List topics = da.newTopicDAO().selectByUserByLimit(u.getId(), start, topicsPerPage);
List l = TopicsCommon.prepareTopics(topics);
Map forums = new HashMap();
for (Iterator iter = l.iterator(); iter.hasNext(); ) {
Topic t = (Topic) iter.next();
Forum f = ForumRepository.getForum(t.getForumId());
if (f == null) {
iter.remove();
totalTopics--;
continue;
}
forums.put(new Integer(t.getForumId()), f);
}
this.context.put("topics", l);
this.context.put("forums", forums);
ViewCommon.contextToPagination(start, totalTopics, topicsPerPage);
}
use of net.jforum.dao.UserDAO in project jforum2 by rafaelsteil.
the class UserREST method list.
/**
* List all users
*/
public void list() {
try {
this.authenticate();
UserDAO dao = DataAccessDriver.getInstance().newUserDAO();
List users = dao.selectAll();
this.setTemplateName(TemplateKeys.API_USER_LIST);
this.context.put("users", users);
} catch (Exception e) {
this.setTemplateName(TemplateKeys.API_ERROR);
this.context.put("exception", e);
}
}
Aggregations