From 462a07e6e23d8088060b31865d82686a19e0d30e Mon Sep 17 00:00:00 2001 From: inga-lovinde <52715130+inga-lovinde@users.noreply.github.com> Date: Thu, 8 Jul 2010 19:22:37 +0000 Subject: [PATCH] Joins implemented in MySQLConnector; UserReplies page implemented --- Builder/IISMainHandler/build.txt | 2 +- Builder/IISUploadHandler/build.txt | 2 +- Common/dataobjects/User.cs | 28 +++++++ Core/DB/JoinSpec.cs | 12 +-- IISMainHandler/HandlersFactory.cs | 2 + IISMainHandler/IISMainHandler.csproj | 1 + .../handlers/response/UserRepliesHandler.cs | 45 +++++++++++ MySQLConnector/Connection.cs | 13 ++- templates/Full/Boards.xslt | 11 ++- templates/Full/UserInfo.xslt | 7 +- templates/Full/UserReplies.xslt | 81 +++++++++++++++++++ 11 files changed, 191 insertions(+), 13 deletions(-) create mode 100644 IISMainHandler/handlers/response/UserRepliesHandler.cs create mode 100644 templates/Full/UserReplies.xslt diff --git a/Builder/IISMainHandler/build.txt b/Builder/IISMainHandler/build.txt index 7383593..d02412a 100644 --- a/Builder/IISMainHandler/build.txt +++ b/Builder/IISMainHandler/build.txt @@ -1 +1 @@ -652 \ No newline at end of file +655 \ No newline at end of file diff --git a/Builder/IISUploadHandler/build.txt b/Builder/IISUploadHandler/build.txt index c4c828b..d2d0776 100644 --- a/Builder/IISUploadHandler/build.txt +++ b/Builder/IISUploadHandler/build.txt @@ -1 +1 @@ -386 \ No newline at end of file +388 \ No newline at end of file diff --git a/Common/dataobjects/User.cs b/Common/dataobjects/User.cs index 37c3e16..1b31515 100644 --- a/Common/dataobjects/User.cs +++ b/Common/dataobjects/User.cs @@ -224,5 +224,33 @@ namespace FLocal.Common.dataobjects { ); } + public IEnumerable getReplies(Diapasone diapasone) { + JoinSpec parent = new JoinSpec( + Post.TableSpec.instance.getColumnSpec(Post.TableSpec.FIELD_PARENTPOSTID), + Post.TableSpec.instance, + "parent" + ); + return Post.LoadByIds( + from stringId in Config.instance.mainConnection.LoadIdsByConditions( + Post.TableSpec.instance, + new ComparisonCondition( + parent.additionalTable.getColumnSpec(Post.TableSpec.FIELD_POSTERID), + ComparisonType.EQUAL, + this.id.ToString() + ), + diapasone, + new JoinSpec[] { + parent + }, + new SortSpec[] { + new SortSpec( + Post.TableSpec.instance.getIdSpec(), + false + ), + } + ) select int.Parse(stringId) + ); + } + } } diff --git a/Core/DB/JoinSpec.cs b/Core/DB/JoinSpec.cs index 0cf903c..84fb2fc 100644 --- a/Core/DB/JoinSpec.cs +++ b/Core/DB/JoinSpec.cs @@ -8,8 +8,10 @@ namespace FLocal.Core.DB { private class TableSpec : ITableSpec { private readonly string _name; - public TableSpec(string name) { + private readonly string _idName; + public TableSpec(ITableSpec raw, string name) { this._name = name; + this._idName = raw.idName; } public string name { get { @@ -18,7 +20,7 @@ namespace FLocal.Core.DB { } public string idName { get { - throw new NotImplementedException(); + return this._idName; } } } @@ -26,12 +28,12 @@ namespace FLocal.Core.DB { public readonly ColumnSpec mainColumn; public readonly ITableSpec additionalTable; - public readonly ITableSpec additionalTableJoin; + public readonly ITableSpec additionalTableRaw; public JoinSpec(ColumnSpec mainColumn, ITableSpec additionalTable, string alias) { this.mainColumn = mainColumn; - this.additionalTableJoin = additionalTable; - this.additionalTable = new TableSpec(alias); + this.additionalTableRaw = additionalTable; + this.additionalTable = new TableSpec(additionalTable, alias); } } diff --git a/IISMainHandler/HandlersFactory.cs b/IISMainHandler/HandlersFactory.cs index 75a43d9..1332c23 100644 --- a/IISMainHandler/HandlersFactory.cs +++ b/IISMainHandler/HandlersFactory.cs @@ -93,6 +93,8 @@ namespace FLocal.IISHandler { switch(context.requestParts[2].ToLower()) { case "posts": return new handlers.response.UserPostsHandler(); + case "replies": + return new handlers.response.UserRepliesHandler(); default: return new handlers.WrongUrlHandler(); } diff --git a/IISMainHandler/IISMainHandler.csproj b/IISMainHandler/IISMainHandler.csproj index a75803d..94ba77f 100644 --- a/IISMainHandler/IISMainHandler.csproj +++ b/IISMainHandler/IISMainHandler.csproj @@ -93,6 +93,7 @@ + diff --git a/IISMainHandler/handlers/response/UserRepliesHandler.cs b/IISMainHandler/handlers/response/UserRepliesHandler.cs new file mode 100644 index 0000000..c6995be --- /dev/null +++ b/IISMainHandler/handlers/response/UserRepliesHandler.cs @@ -0,0 +1,45 @@ +п»їusing System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Web; +using System.Xml.Linq; +using FLocal.Common; +using FLocal.Common.dataobjects; +using FLocal.Core; +using FLocal.Core.DB; +using FLocal.Core.DB.conditions; + +namespace FLocal.IISHandler.handlers.response { + + class UserRepliesHandler : AbstractGetHandler { + + override protected string templateName { + get { + return "UserReplies.xslt"; + } + } + + override protected XElement[] getSpecificData(WebContext context) { + User user = User.LoadById(int.Parse(context.requestParts[1])); + PageOuter pageOuter = PageOuter.createFromGet( + context.requestParts, + context.userSettings.postsPerPage, + 3 + ); + IEnumerable posts = user.getReplies(pageOuter); + + XElement[] result = new XElement[] { + user.exportToXmlForViewing(context), + new XElement("posts", + from post in posts select post.exportToXmlWithoutThread(context, true), + pageOuter.exportToXml(2, 5, 2) + ) + }; + + return result; + } + + } + +} \ No newline at end of file diff --git a/MySQLConnector/Connection.cs b/MySQLConnector/Connection.cs index 764c434..d3985de 100644 --- a/MySQLConnector/Connection.cs +++ b/MySQLConnector/Connection.cs @@ -91,10 +91,17 @@ namespace FLocal.MySQLConnector { if(conditionsCompiled.Key != "") queryConditions = "WHERE " + conditionsCompiled.Key; ParamsHolder paramsHolder = conditionsCompiled.Value; - string queryJoins = ""; + StringBuilder queryJoins = new StringBuilder(); { - if(joins.Length > 0) { - throw new NotImplementedException(); + foreach(var join in joins) { + queryJoins.Append(" JOIN "); + queryJoins.Append(join.additionalTableRaw.compile(this.traits)); + queryJoins.Append(" "); + queryJoins.Append(join.additionalTable.compile(this.traits)); + queryJoins.Append(" ON "); + queryJoins.Append(join.mainColumn.compile(this.traits)); + queryJoins.Append(" = "); + queryJoins.Append(join.additionalTable.getIdSpec().compile(this.traits)); } } diff --git a/templates/Full/Boards.xslt b/templates/Full/Boards.xslt index 1d7aa71..0530643 100644 --- a/templates/Full/Boards.xslt +++ b/templates/Full/Boards.xslt @@ -25,7 +25,11 @@ - Вы вошли в форум как + Вы вошли в форум как + + /User// + + Вы не вошли в форум @@ -52,7 +56,10 @@
Последние 7 дней
- Последние ответы на мои сообщения + + /User//Replies/ + Последние ответы на мои сообщения +
Мои сообщения с оценками
diff --git a/templates/Full/UserInfo.xslt b/templates/Full/UserInfo.xslt index 8281a20..eb2def2 100644 --- a/templates/Full/UserInfo.xslt +++ b/templates/Full/UserInfo.xslt @@ -205,7 +205,12 @@ /User//Posts/ - Показать все сообщения пользователя + Сообщения + + | + + /User//Replies/ + Ответы | diff --git a/templates/Full/UserReplies.xslt b/templates/Full/UserReplies.xslt new file mode 100644 index 0000000..048c608 --- /dev/null +++ b/templates/Full/UserReplies.xslt @@ -0,0 +1,81 @@ + + + + + + Ответы - + + + + + + + +
+ + + + +
+ + + + +
+ + + /Users/ + Пользователи + + >> + + /User/ + + + >> + Ответы + +
+
+
+
+ + + + +
+ + + + + + + + +
+ + + + +
+ страницы: + + /User//Replies/ + +
+
+ + + + +
+ страницы: + + /User//Replies/ + +
+
+
+
+ +
\ No newline at end of file