Search in sources :

Example 11 with Bookmark

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

the class BookmarkAction method addTopic.

private void addTopic() {
    Topic t = DataAccessDriver.getInstance().newTopicDAO().selectById(this.request.getIntParameter("relation_id"));
    String title = t.getTitle();
    Bookmark b = DataAccessDriver.getInstance().newBookmarkDAO().selectForUpdate(t.getId(), BookmarkType.TOPIC, SessionFacade.getUserSession().getUserId());
    if (b != null) {
        if (b.getTitle() != null) {
            title = b.getTitle();
        }
        this.context.put("description", b.getDescription());
        this.context.put("bookmark", b);
    }
    this.setTemplateName(TemplateKeys.BOOKMARS_ADD_TOPIC);
    this.context.put("title", title);
    this.context.put("relationType", new Integer(BookmarkType.TOPIC));
    this.context.put("relationId", new Integer(t.getId()));
}
Also used : Bookmark(net.jforum.entities.Bookmark) Topic(net.jforum.entities.Topic)

Example 12 with Bookmark

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

the class BookmarkAction method updateSave.

public void updateSave() {
    int id = this.request.getIntParameter("bookmark_id");
    BookmarkDAO bm = DataAccessDriver.getInstance().newBookmarkDAO();
    Bookmark b = bm.selectById(id);
    if (!this.sanityCheck(b)) {
        return;
    }
    b.setTitle(this.request.getParameter("title"));
    b.setDescription(this.request.getParameter("description"));
    String visible = this.request.getParameter("visible");
    b.setPublicVisible(StringUtils.isNotBlank(visible));
    bm.update(b);
    this.setTemplateName(TemplateKeys.BOOKMARKS_UPDATE_SAVE);
}
Also used : BookmarkDAO(net.jforum.dao.BookmarkDAO) Bookmark(net.jforum.entities.Bookmark)

Example 13 with Bookmark

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

the class UserAction method profile.

public void profile() {
    DataAccessDriver da = DataAccessDriver.getInstance();
    UserDAO udao = da.newUserDAO();
    User u = udao.selectById(this.request.getIntParameter("user_id"));
    if (u.getId() == 0) {
        this.userNotFound();
    } else {
        this.setTemplateName(TemplateKeys.USER_PROFILE);
        this.context.put("karmaEnabled", SecurityRepository.canAccess(SecurityConstants.PERM_KARMA_ENABLED));
        this.context.put("rank", new RankingRepository());
        this.context.put("u", u);
        this.context.put("avatarAllowExternalUrl", SystemGlobals.getBoolValue(ConfigKeys.AVATAR_ALLOW_EXTERNAL_URL));
        int loggedId = SessionFacade.getUserSession().getUserId();
        int count = 0;
        List bookmarks = da.newBookmarkDAO().selectByUser(u.getId());
        for (Iterator iter = bookmarks.iterator(); iter.hasNext(); ) {
            Bookmark b = (Bookmark) iter.next();
            if (b.isPublicVisible() || loggedId == u.getId()) {
                count++;
            }
        }
        this.context.put("pageTitle", I18n.getMessage("UserProfile.allAbout") + " " + u.getUsername());
        this.context.put("nbookmarks", new Integer(count));
        this.context.put("ntopics", new Integer(da.newTopicDAO().countUserTopics(u.getId())));
        this.context.put("nposts", new Integer(da.newPostDAO().countUserPosts(u.getId())));
    }
}
Also used : User(net.jforum.entities.User) UserDAO(net.jforum.dao.UserDAO) Bookmark(net.jforum.entities.Bookmark) DataAccessDriver(net.jforum.dao.DataAccessDriver) RankingRepository(net.jforum.repository.RankingRepository) Iterator(java.util.Iterator) List(java.util.List)

Example 14 with Bookmark

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

the class GenericBookmarkDAO method selectForUpdate.

/**
 * @see net.jforum.dao.BookmarkDAO#selectForUpdate(int, int, int)
 */
public Bookmark selectForUpdate(int relationId, int relationType, int userId) {
    PreparedStatement p = null;
    ResultSet rs = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("BookmarkModel.selectForUpdate"));
        p.setInt(1, relationId);
        p.setInt(2, relationType);
        p.setInt(3, userId);
        Bookmark b = null;
        rs = p.executeQuery();
        if (rs.next()) {
            b = this.getBookmark(rs);
        }
        return b;
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbUtils.close(rs, p);
    }
}
Also used : Bookmark(net.jforum.entities.Bookmark) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) DatabaseException(net.jforum.exceptions.DatabaseException)

Aggregations

Bookmark (net.jforum.entities.Bookmark)14 PreparedStatement (java.sql.PreparedStatement)5 ResultSet (java.sql.ResultSet)5 SQLException (java.sql.SQLException)5 DatabaseException (net.jforum.exceptions.DatabaseException)5 List (java.util.List)4 ArrayList (java.util.ArrayList)3 BookmarkDAO (net.jforum.dao.BookmarkDAO)3 User (net.jforum.entities.User)2 Iterator (java.util.Iterator)1 DataAccessDriver (net.jforum.dao.DataAccessDriver)1 UserDAO (net.jforum.dao.UserDAO)1 Forum (net.jforum.entities.Forum)1 Topic (net.jforum.entities.Topic)1 RankingRepository (net.jforum.repository.RankingRepository)1 SafeHtml (net.jforum.util.SafeHtml)1