Search in sources :

Example 11 with UserDAO

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();
}
Also used : TreeGroup(net.jforum.util.TreeGroup) Group(net.jforum.entities.Group) UserDAO(net.jforum.dao.UserDAO) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) GroupDAO(net.jforum.dao.GroupDAO)

Example 12 with UserDAO

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);
}
Also used : User(net.jforum.entities.User) UserDAO(net.jforum.dao.UserDAO) HashMap(java.util.HashMap) DataAccessDriver(net.jforum.dao.DataAccessDriver) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Topic(net.jforum.entities.Topic) HashMap(java.util.HashMap) Map(java.util.Map) Forum(net.jforum.entities.Forum)

Example 13 with UserDAO

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);
}
Also used : PollDAO(net.jforum.dao.PollDAO) User(net.jforum.entities.User) PostDAO(net.jforum.dao.PostDAO) UserDAO(net.jforum.dao.UserDAO) Poll(net.jforum.entities.Poll) Topic(net.jforum.entities.Topic) QuotaLimit(net.jforum.entities.QuotaLimit) AttachmentCommon(net.jforum.view.forum.common.AttachmentCommon)

Example 14 with UserDAO

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);
}
Also used : User(net.jforum.entities.User) UserDAO(net.jforum.dao.UserDAO) HashMap(java.util.HashMap) DataAccessDriver(net.jforum.dao.DataAccessDriver) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Topic(net.jforum.entities.Topic) HashMap(java.util.HashMap) Map(java.util.Map) Forum(net.jforum.entities.Forum)

Example 15 with UserDAO

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);
    }
}
Also used : UserDAO(net.jforum.dao.UserDAO) List(java.util.List) APIException(net.jforum.exceptions.APIException)

Aggregations

UserDAO (net.jforum.dao.UserDAO)26 User (net.jforum.entities.User)18 List (java.util.List)12 ArrayList (java.util.ArrayList)7 Iterator (java.util.Iterator)6 Topic (net.jforum.entities.Topic)6 Post (net.jforum.entities.Post)5 HashMap (java.util.HashMap)4 PostDAO (net.jforum.dao.PostDAO)4 AttachmentCommon (net.jforum.view.forum.common.AttachmentCommon)4 Map (java.util.Map)3 DataAccessDriver (net.jforum.dao.DataAccessDriver)3 Forum (net.jforum.entities.Forum)3 UserSession (net.jforum.entities.UserSession)3 Date (java.util.Date)2 TopicDAO (net.jforum.dao.TopicDAO)2 Group (net.jforum.entities.Group)2 PrivateMessage (net.jforum.entities.PrivateMessage)2 QuotaLimit (net.jforum.entities.QuotaLimit)2 APIException (net.jforum.exceptions.APIException)2