From f656d844d0096cf8637746afaa1fab7dadaef261 Mon Sep 17 00:00:00 2001 From: Ugnich Anton Date: Fri, 27 Jan 2012 08:34:31 +0700 Subject: User.getCanMedia, Tag.getUserTagsAll --- src/com/juick/server/TagQueries.java | 25 +++++++++++++++++++++++++ src/com/juick/server/UserQueries.java | 20 ++++++++++++++++++++ 2 files changed, 45 insertions(+) (limited to 'src/com') diff --git a/src/com/juick/server/TagQueries.java b/src/com/juick/server/TagQueries.java index 8cb7ee1a..7d78e345 100644 --- a/src/com/juick/server/TagQueries.java +++ b/src/com/juick/server/TagQueries.java @@ -22,6 +22,7 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; +import java.util.ArrayList; /** * @@ -65,4 +66,28 @@ public class TagQueries { return tid; } + + public static ArrayList getUserTagsAll(Connection sql, int uid) { + ArrayList tags = new ArrayList(); + + PreparedStatement stmt = null; + ResultSet rs = null; + try { + stmt = sql.prepareStatement("SELECT tags.name,COUNT(messages.message_id) FROM (messages INNER JOIN messages_tags ON (messages.user_id=? AND messages.message_id=messages_tags.message_id)) INNER JOIN tags ON messages_tags.tag_id=tags.tag_id GROUP BY tags.tag_id ORDER BY tags.name ASC"); + stmt.setInt(1, uid); + rs = stmt.executeQuery(); + rs.beforeFirst(); + while (rs.next()) { + com.juick.Tag t = new com.juick.Tag(); + t.Name = rs.getString(1); + t.UsageCnt = rs.getInt(2); + tags.add(t); + } + } catch (SQLException e) { + System.err.println(e); + } finally { + Utils.finishSQL(rs, stmt); + } + return tags; + } } diff --git a/src/com/juick/server/UserQueries.java b/src/com/juick/server/UserQueries.java index 97cae91f..906f7742 100644 --- a/src/com/juick/server/UserQueries.java +++ b/src/com/juick/server/UserQueries.java @@ -215,4 +215,24 @@ public class UserQueries { Utils.finishSQL(null, stmt); } } + + public static boolean getCanMedia(Connection sql, int uid) { + boolean ret = false; + + PreparedStatement stmt = null; + ResultSet rs = null; + try { + stmt = sql.prepareStatement("SELECT users.lastphoto-UNIX_TIMESTAMP() FROM users WHERE id=?"); + stmt.setInt(1, uid); + rs = stmt.executeQuery(); + if (rs.first()) { + ret = rs.getInt(1) < 3600; + } + } catch (SQLException e) { + System.err.println(e); + } finally { + Utils.finishSQL(rs, stmt); + } + return ret; + } } -- cgit v1.2.3