コード例 #1
0
ファイル: ForumTopic.cs プロジェクト: smithydll/boxsocial
        public TopicPost AddReply(Core core, Forum forum, string subject, string text)
        {
            db.BeginTransaction();

            TopicPost post = TopicPost.Create(core, forum, this, subject, text);

            topicPosts++;

            UpdateQuery uQuery = new UpdateQuery(ForumTopic.GetTable(typeof(ForumTopic)));
            uQuery.AddField("topic_posts", new QueryOperation("topic_posts", QueryOperations.Addition, 1));
            uQuery.AddField("topic_last_post_id", post.Id);
            uQuery.AddField("topic_last_post_time_ut", post.TimeCreatedRaw);
            uQuery.AddCondition("topic_id", post.TopicId);

            long rowsUpdated = db.Query(uQuery);

            if (rowsUpdated != 1)
            {
                db.RollBackTransaction();
                core.Display.ShowMessage("ERROR", "Error, rolling back transaction");
            }

            if (forumId > 0)
            {
                List<long> parentForumIds = new List<long>();
                parentForumIds.Add(Forum.Id);

                if (Forum.Parents != null)
                {
                    foreach (ParentTreeNode ptn in Forum.Parents.Nodes)
                    {
                        parentForumIds.Add(ptn.ParentId);
                    }
                }

                uQuery = new UpdateQuery(Forum.GetTable(typeof(Forum)));
                uQuery.AddField("forum_posts", new QueryOperation("forum_posts", QueryOperations.Addition, 1));
                uQuery.AddField("forum_last_post_id", post.Id);
                uQuery.AddField("forum_last_post_time_ut", post.TimeCreatedRaw);
                uQuery.AddCondition("forum_id", ConditionEquality.In, parentForumIds);

                rowsUpdated = db.Query(uQuery);

                if (rowsUpdated < 1)
                {
                    db.RollBackTransaction();
                    core.Display.ShowMessage("ERROR", "Error, rolling back transaction");
                }
            }

            uQuery = new UpdateQuery(ForumSettings.GetTable(typeof(ForumSettings)));
            uQuery.AddField("forum_posts", new QueryOperation("forum_posts", QueryOperations.Addition, 1));
            uQuery.AddCondition("forum_item_id", Forum.Owner.Id);
            uQuery.AddCondition("forum_item_type_id", Forum.Owner.TypeId);

            rowsUpdated = db.Query(uQuery);

            if (rowsUpdated != 1)
            {
                db.RollBackTransaction();
                core.Display.ShowMessage("ERROR", "Error, rolling back transaction");
            }

            /*uQuery = new UpdateQuery(ForumMember.GetTable(typeof(ForumMember)));
            uQuery.AddField("posts", new QueryOperation("posts", QueryOperations.Addition, 1));
            uQuery.AddCondition("user_id", core.session.LoggedInMember.Id);
            uQuery.AddCondition("item_id", Forum.Owner.Id);
            uQuery.AddCondition("item_type_id", Forum.Owner.TypeId);

            rowsUpdated = db.Query(uQuery);

            if (rowsUpdated == 0)
            {
                ForumMember fm = ForumMember.Create(core, Forum.Owner, core.session.LoggedInMember, true);

                uQuery = new UpdateQuery(ForumMember.GetTable(typeof(ForumMember)));
                uQuery.AddField("posts", new QueryOperation("posts", QueryOperations.Addition, 1));
                uQuery.AddCondition("user_id", core.session.LoggedInMember.Id);
                uQuery.AddCondition("item_id", Forum.Owner.Id);
                uQuery.AddCondition("item_type_id", Forum.Owner.TypeId);

                db.Query(uQuery);
            }*/

            ForumMember fm = null;

            try
            {
                fm = new ForumMember(core, Forum.Owner, core.Session.LoggedInMember);
            }
            catch (InvalidForumMemberException)
            {
                fm = ForumMember.Create(core, Forum.Owner, core.Session.LoggedInMember, true);
            }

            fm.ForumPosts += 1;

            /*Dictionary<long, ForumMemberRank> ranks = ForumMemberRank.GetRanks(core, Forum.Owner);

            if (!(ranks.ContainsKey(fm.ForumRankId) && ranks[fm.ForumRankId].RankSpecial))
            {
                int rankLastMin = 0;
                foreach (ForumMemberRank rank in ranks.Values)
                {
                    if ((!rank.RankSpecial) && fm.ForumPosts >= rank.RankPosts && rank.RankPosts > rankLastMin)
                    {
                        fm.ForumRankId = rank.Id;
                        rankLastMin = rank.RankPosts;
                    }
                }
            }*/

            fm.Update(typeof(ForumMember));

            return post;
        }
コード例 #2
0
ファイル: ForumMember.cs プロジェクト: smithydll/boxsocial
        private static void Save(Core core, PPage page)
        {
            AccountSubModule.AuthoriseRequestSid(core);

            if (core.Session.IsLoggedIn && core.Session.LoggedInMember != null)
            {
                ForumMember member = null;

                try
                {
                    member = new ForumMember(core, page.Owner, core.Session.LoggedInMember);
                }
                catch (InvalidForumMemberException)
                {
                    member = ForumMember.Create(core, page.Owner, core.Session.LoggedInMember, false);
                }
                member.ForumSignature = core.Http.Form["signature"];

                member.Update(typeof(ForumMember));

                core.Display.ShowMessage("Profile Updated", "Your forum profile has been saved in the database.");

                core.Template.Parse("REDIRECT_URI", core.Hyperlink.AppendSid(string.Format("{0}forum/ucp",
                    page.Owner.UriStub)));
            }
        }
コード例 #3
0
ファイル: ForumTopic.cs プロジェクト: smithydll/boxsocial
        public static ForumTopic Create(Core core, Forum forum, string subject, string text, TopicStates status)
        {
            if (core == null)
            {
                throw new NullCoreException();
            }

            if (forum == null)
            {
                throw new InvalidForumException();
            }

            core.Db.BeginTransaction();

            if (!forum.Access.Can("CREATE_TOPICS"))
            {
                // todo: throw new exception
                throw new UnauthorisedToCreateItemException();
            }

            if ((status == TopicStates.Announcement || status == TopicStates.Global) && (!forum.Access.Can("CREATE_ANNOUNCEMENTS")))
            {
                throw new UnauthorisedToCreateItemException();
            }

            if (status == TopicStates.Sticky && (!forum.Access.Can("CREATE_STICKY")))
            {
                throw new UnauthorisedToCreateItemException();
            }

            if (forum.Owner is UserGroup)
            {
                ForumSettings settings = new ForumSettings(core, (UserGroup)forum.Owner);

                if (forum.Id == 0 && (!settings.AllowTopicsAtRoot))
                {
                    throw new UnauthorisedToCreateItemException();
                }

                if (!((UserGroup)forum.Owner).IsGroupOperator(core.Session.LoggedInMember.ItemKey))
                {
                    status = TopicStates.Normal;
                }
            }

            InsertQuery iquery = new InsertQuery(ForumTopic.GetTable(typeof(ForumTopic)));
            iquery.AddField("forum_id", forum.Id);
            iquery.AddField("topic_title", subject);
            iquery.AddField("user_id", core.LoggedInMemberId);
            iquery.AddField("topic_posts", 0);
            iquery.AddField("topic_views", 0);
            iquery.AddField("topic_time_ut", UnixTime.UnixTimeStamp());
            iquery.AddField("topic_modified_ut", UnixTime.UnixTimeStamp());
            iquery.AddField("topic_last_post_time_ut", UnixTime.UnixTimeStamp());
            iquery.AddField("topic_status", (byte)status);
            iquery.AddField("topic_locked", false);
            iquery.AddField("topic_last_post_id", 0);
            iquery.AddField("topic_first_post_id", 0);
            iquery.AddField("topic_item_id", forum.Owner.Id);
            iquery.AddField("topic_item_type_id", forum.Owner.TypeId);

            long topicId = core.Db.Query(iquery);

            ForumTopic topic = new ForumTopic(core, forum, topicId);

            TopicPost post = TopicPost.Create(core, forum, topic, subject, text);

            UpdateQuery uQuery = new UpdateQuery(ForumTopic.GetTable(typeof(ForumTopic)));
            uQuery.AddField("topic_first_post_id", post.Id);
            uQuery.AddField("topic_last_post_id", post.Id);
            uQuery.AddField("topic_last_post_time_ut", post.TimeCreatedRaw);
            uQuery.AddCondition("topic_id", topic.Id);

            long rowsUpdated = core.Db.Query(uQuery);

            topic.firstPostId = post.Id;
            topic.lastPostId = post.Id;
            topic.lastPostTimeRaw = post.TimeCreatedRaw;

            if (rowsUpdated != 1)
            {
                core.Db.RollBackTransaction();
                core.Display.ShowMessage("ERROR", "Error, rolling back transaction");
            }

            if (forum.Id > 0)
            {
                List<long> parentForumIds = new List<long>();
                parentForumIds.Add(forum.Id);

                if (forum.Parents != null)
                {
                    foreach (ParentTreeNode ptn in forum.Parents.Nodes)
                    {
                        parentForumIds.Add(ptn.ParentId);
                    }
                }

                uQuery = new UpdateQuery(Forum.GetTable(typeof(Forum)));
                uQuery.AddField("forum_posts", new QueryOperation("forum_posts", QueryOperations.Addition, 1));
                uQuery.AddField("forum_topics", new QueryOperation("forum_topics", QueryOperations.Addition, 1));
                uQuery.AddField("forum_last_post_id", post.Id);
                uQuery.AddField("forum_last_post_time_ut", post.TimeCreatedRaw);
                uQuery.AddCondition("forum_id", ConditionEquality.In, parentForumIds);

                rowsUpdated = core.Db.Query(uQuery);

                if (rowsUpdated < 1)
                {
                    core.Db.RollBackTransaction();
                    core.Display.ShowMessage("ERROR", "Error, rolling back transaction");
                }

                uQuery = new UpdateQuery(Forum.GetTable(typeof(Forum)));
                uQuery.AddField("forum_topics", new QueryOperation("forum_topics_paged", QueryOperations.Addition, 1));
                uQuery.AddCondition("forum_id", forum.Id);

                rowsUpdated = core.Db.Query(uQuery);

                if (rowsUpdated < 1)
                {
                    core.Db.RollBackTransaction();
                    core.Display.ShowMessage("ERROR", "Error, rolling back transaction");
                }
            }

            uQuery = new UpdateQuery(ForumSettings.GetTable(typeof(ForumSettings)));
            uQuery.AddField("forum_posts", new QueryOperation("forum_posts", QueryOperations.Addition, 1));
            uQuery.AddField("forum_topics", new QueryOperation("forum_topics", QueryOperations.Addition, 1));
            uQuery.AddCondition("forum_item_id", forum.Owner.Id);
            uQuery.AddCondition("forum_item_type_id", forum.Owner.TypeId);

            rowsUpdated = core.Db.Query(uQuery);

            if (rowsUpdated != 1)
            {
                core.Db.RollBackTransaction();
                core.Display.ShowMessage("ERROR", "Error, rolling back transaction");
            }

            /*uQuery = new UpdateQuery(ForumMember.GetTable(typeof(ForumMember)));
            uQuery.AddField("posts", new QueryOperation("posts", QueryOperations.Addition, 1));
            uQuery.AddCondition("user_id", core.session.LoggedInMember.Id);
            uQuery.AddCondition("item_id", forum.Owner.Id);
            uQuery.AddCondition("item_type_id", forum.Owner.TypeId);

            rowsUpdated = core.db.Query(uQuery);

            if (rowsUpdated == 0)
            {
                ForumMember fm = ForumMember.Create(core, forum.Owner, core.session.LoggedInMember, true);

                uQuery = new UpdateQuery(ForumMember.GetTable(typeof(ForumMember)));
                uQuery.AddField("posts", new QueryOperation("posts", QueryOperations.Addition, 1));
                uQuery.AddCondition("user_id", core.session.LoggedInMember.Id);
                uQuery.AddCondition("item_id", forum.Owner.Id);
                uQuery.AddCondition("item_type_id", forum.Owner.TypeId);

                core.db.Query(uQuery);
            }*/

            ForumMember fm = null;

            try
            {
                fm = new ForumMember(core, forum.Owner, core.Session.LoggedInMember);
            }
            catch (InvalidForumMemberException)
            {
                fm = ForumMember.Create(core, forum.Owner, core.Session.LoggedInMember, true);
            }

            fm.ForumPosts += 1;

            /*Dictionary<long, ForumMemberRank> ranks = ForumMemberRank.GetRanks(core, forum.Owner);

            if (!(ranks.ContainsKey(fm.ForumRankId) && ranks[fm.ForumRankId].RankSpecial))
            {
                int rankLastMin = 0;
                foreach (ForumMemberRank rank in ranks.Values)
                {
                    if ((!rank.RankSpecial) && fm.ForumPosts >= rank.RankPosts && rank.RankPosts > rankLastMin)
                    {
                        fm.ForumRankId = rank.Id;
                        rankLastMin = rank.RankPosts;
                    }
                }
            }*/

            fm.Update(typeof(ForumMember));

            return topic;
        }
コード例 #4
0
        void AccountForumMemberManage_Edit_Save(object sender, EventArgs e)
        {
            AuthoriseRequestSid();

            long id = core.Functions.FormLong("id", 0);
            long rankId = core.Functions.FormLong("ranks", 0);
            ForumMember member = null;

            try
            {
                member = new ForumMember(core, Owner, id, UserLoadOptions.Common);
            }
            catch (InvalidForumMemberException)
            {
                core.Functions.Generate404();
            }
            catch (InvalidUserException)
            {
                core.Functions.Generate404();
            }

            member.ForumSignature = core.Http.Form["signature"];
            member.ForumRankId = rankId;

            member.Update(typeof(ForumMember));

            SetRedirectUri(BuildUri());
            core.Display.ShowMessage("Forum Profile Updated", "The user's forum profile has been saved in the database");
        }