Search in sources :

Example 1 with Group

use of net.jforum.entities.Group in project jforum2 by rafaelsteil.

the class GenericGroupDAO method selectById.

/**
	 * @see net.jforum.dao.GroupDAO#selectById(int)
	 */
public Group selectById(int groupId) {
    PreparedStatement p = null;
    ResultSet rs = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("GroupModel.selectById"));
        p.setInt(1, groupId);
        rs = p.executeQuery();
        Group g = new Group();
        if (rs.next()) {
            g = this.getGroup(rs);
        }
        return g;
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbUtils.close(rs, p);
    }
}
Also used : Group(net.jforum.entities.Group) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) DatabaseException(net.jforum.exceptions.DatabaseException)

Example 2 with Group

use of net.jforum.entities.Group in project jforum2 by rafaelsteil.

the class GenericUserDAO method selectById.

/**
	 * @see net.jforum.dao.UserDAO#selectById(int)
	 */
public User selectById(int userId) {
    String q = SystemGlobals.getSql("UserModel.selectById");
    PreparedStatement p = null;
    ResultSet rs = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(q);
        p.setInt(1, userId);
        rs = p.executeQuery();
        User u = new User();
        if (rs.next()) {
            this.fillUserFromResultSet(u, rs);
            u.setPrivateMessagesCount(rs.getInt("private_messages"));
            rs.close();
            p.close();
            // User groups
            p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("UserModel.selectGroups"));
            p.setInt(1, userId);
            rs = p.executeQuery();
            while (rs.next()) {
                Group g = new Group();
                g.setName(rs.getString("group_name"));
                g.setId(rs.getInt("group_id"));
                u.getGroupsList().add(g);
            }
        }
        return u;
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbUtils.close(rs, p);
    }
}
Also used : Group(net.jforum.entities.Group) User(net.jforum.entities.User) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) DatabaseException(net.jforum.exceptions.DatabaseException)

Example 3 with Group

use of net.jforum.entities.Group in project jforum2 by rafaelsteil.

the class GroupAction method insertSave.

// Saves a new group
public void insertSave() {
    GroupDAO gm = DataAccessDriver.getInstance().newGroupDAO();
    Group g = new Group();
    g.setDescription(this.request.getParameter("group_description"));
    g.setParentId(this.request.getIntParameter("parent_id"));
    g.setName(this.request.getParameter("group_name"));
    gm.addNew(g);
    this.list();
}
Also used : TreeGroup(net.jforum.util.TreeGroup) Group(net.jforum.entities.Group) GroupDAO(net.jforum.dao.GroupDAO)

Example 4 with Group

use of net.jforum.entities.Group in project jforum2 by rafaelsteil.

the class GroupAction method editSave.

// Save information for an existing group
public void editSave() {
    int groupId = this.request.getIntParameter("group_id");
    Group g = new Group();
    g.setDescription(this.request.getParameter("group_description"));
    g.setId(groupId);
    int parentId = this.request.getIntParameter("parent_id");
    if (parentId == g.getId()) {
        parentId = 0;
    }
    g.setParentId(parentId);
    g.setName(this.request.getParameter("group_name"));
    DataAccessDriver.getInstance().newGroupDAO().update(g);
    this.list();
}
Also used : TreeGroup(net.jforum.util.TreeGroup) Group(net.jforum.entities.Group)

Example 5 with Group

use of net.jforum.entities.Group in project jforum2 by rafaelsteil.

the class UserAction method groups.

// Groups
public void groups() {
    int userId = this.request.getIntParameter("id");
    UserDAO um = DataAccessDriver.getInstance().newUserDAO();
    User u = um.selectById(userId);
    List selectedList = new ArrayList();
    for (Iterator iter = u.getGroupsList().iterator(); iter.hasNext(); ) {
        selectedList.add(new Integer(((Group) iter.next()).getId()));
    }
    this.context.put("selectedList", selectedList);
    this.context.put("groups", new TreeGroup().getNodes());
    this.context.put("user", u);
    this.context.put("userId", new Integer(userId));
    this.setTemplateName(TemplateKeys.USER_ADMIN_GROUPS);
    this.context.put("groupFor", I18n.getMessage("User.GroupsFor", new String[] { u.getUsername() }));
}
Also used : TreeGroup(net.jforum.util.TreeGroup) Group(net.jforum.entities.Group) User(net.jforum.entities.User) UserDAO(net.jforum.dao.UserDAO) TreeGroup(net.jforum.util.TreeGroup) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

Group (net.jforum.entities.Group)7 TreeGroup (net.jforum.util.TreeGroup)4 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 List (java.util.List)2 GroupDAO (net.jforum.dao.GroupDAO)2 UserDAO (net.jforum.dao.UserDAO)2 User (net.jforum.entities.User)2 DatabaseException (net.jforum.exceptions.DatabaseException)2