Ejemplo n.º 1
0
        public List<Page> GetPageList(Primitive owner, User loggedInMember, Page current)
        {
            Database db = core.Db;
            long loggedIdUid = User.GetMemberId(loggedInMember);

            SelectQuery query = Page.GetSelectQueryStub(core, typeof(Page));
            query.AddCondition("page_item_id", owner.Id);
            query.AddCondition("page_item_type_id", owner.TypeId);
            query.AddCondition("page_status", "PUBLISH");
            QueryCondition qc1 = query.AddCondition("page_parent_id", 0);
            if (current != null)
            {
                ParentTree pt = current.GetParents();
                if (pt != null)
                {
                    foreach (ParentTreeNode ptn in pt.Nodes)
                    {
                        qc1.AddCondition(ConditionRelations.Or, "page_parent_id", ptn.ParentId);
                    }
                }

                qc1.AddCondition(ConditionRelations.Or, "page_parent_id", current.Id);
            }
            query.AddSort(SortOrder.Ascending, "page_order");

            System.Data.Common.DbDataReader pagesReader = db.ReaderQuery(query);

            List<IPermissibleItem> tempPages = new List<IPermissibleItem>();
            List<Page> pages = new List<Page>();

            while (pagesReader.Read())
            {
                tempPages.Add(new Page(core, owner, pagesReader));
            }

            pagesReader.Close();
            pagesReader.Dispose();

            core.AcessControlCache.CacheGrants(tempPages);

            foreach (IPermissibleItem page in tempPages)
            {
                if (page.Access.Can("VIEW"))
                {
                    pages.Add((Page)page);
                }
            }

            return pages;
        }
Ejemplo n.º 2
0
        public string GeneratePageList(Primitive owner, User loggedInMember, bool fragment, Page current)
        {
            Database db = core.Db;

            //ushort readAccessLevel = owner.GetAccessLevel(loggedInMember);
            long loggedIdUid = User.GetMemberId(loggedInMember);

            SelectQuery query = Page.GetSelectQueryStub(core, typeof(Page));
            query.AddCondition("page_item_id", owner.Id);
            query.AddCondition("page_item_type_id", owner.TypeId);
            query.AddCondition("page_status", "PUBLISH");
            QueryCondition qc1 = query.AddCondition("page_parent_id", 0);
            if (current != null)
            {
                ParentTree pt = current.GetParents();
                if (pt != null)
                {
                    foreach (ParentTreeNode ptn in pt.Nodes)
                    {
                        qc1.AddCondition(ConditionRelations.Or, "page_parent_id", ptn.ParentId);
                    }
                }

                qc1.AddCondition(ConditionRelations.Or, "page_parent_id", current.Id);
            }
            query.AddSort(SortOrder.Ascending, "page_order");

            StringBuilder output = new StringBuilder();

            int parents = 0;
            int nextParents = 0;

            List<IPermissibleItem> tempPages = new List<IPermissibleItem>();
            List<Page> pages = new List<Page>();

            System.Data.Common.DbDataReader pagesReader = db.ReaderQuery(query);

            if (!fragment)
            {
                if (!pagesReader.HasRows)
                {
                    return string.Empty;
                }
                else
                {
                    output.Append("<ul>\n");
                }
            }

            while (pagesReader.Read())
            {
                tempPages.Add(new Page(core, owner, pagesReader));
            }

            pagesReader.Close();
            pagesReader.Dispose();

            core.AcessControlCache.CacheGrants(tempPages);

            foreach (IPermissibleItem page in tempPages)
            {
                if (page.Access.Can("VIEW"))
                {
                    pages.Add((Page)page);
                }
            }

            for (int i = 0; i < pages.Count; i++)
            {
                bool hasChildren = false;
                if (i + 1 < pages.Count)
                {
                    if (pages[i + 1].ParentId == 0)
                    {
                        nextParents = 0;
                    }
                    else
                    {
                        nextParents = pages[i + 1].ParentPath.Split('/').Length;
                    }
                }
                else
                {
                    nextParents = 0;
                }

                if (pages[i].ParentId == 0)
                {
                    parents = 0;
                }
                else
                {
                    parents = pages[i].ParentPath.Split('/').Length;
                }

                if (nextParents > parents)
                {
                    hasChildren = true;
                }

                if (core.IsMobile)
                {
                    output.Append("<li class=\"page-li\">");
                }
                else
                {
                    if (!string.IsNullOrEmpty(pages[i].Icon))
                    {
                        output.Append("<li style=\"background-image: url('" + HttpUtility.HtmlEncode(pages[i].Icon) + "');\" class=\"page-li\"> ");
                    }
                    else
                    {
                        output.Append("<li class=\"page-li\">");
                    }
                }
                output.Append("<a href=\"");
                output.Append(HttpUtility.HtmlEncode(pages[i].Uri));
                output.Append("\">");
                if (core.IsMobile && (!string.IsNullOrEmpty(pages[i].Icon)))
                {
                    output.Append("<img src=\"" + HttpUtility.HtmlEncode(pages[i].Icon) + "\" class=\"ui-li-icon\" />");
                }
                output.Append("<span>");
                if (current != null)
                {
                    if (pages[i].Id == current.Id)
                    {
                        output.Append("<b>");
                    }
                    output.Append(HttpUtility.HtmlEncode(pages[i].Title));
                    if (pages[i].Id == current.Id)
                    {
                        output.Append("</b>");
                    }
                }
                else
                {
                    output.Append(HttpUtility.HtmlEncode(pages[i].Title));
                }
                output.Append("</span></a>");

                if ((!hasChildren) || core.IsMobile)
                {
                    output.Append("</li>\n");
                }
                else
                {
                    for (int j = parents; j < nextParents; j++)
                    {
                        if (j > parents)
                        {
                            output.Append("<li class=\"empty\">");
                        }
                        output.Append("<ul>\n");
                    }

                    if (parents == nextParents)
                    {
                        output.Append("\n<ul>\n");
                    }
                }

                if (!core.IsMobile)
                {
                    for (int j = nextParents; j < parents; j++)
                    {
                        output.Append("</ul>\n</li>\n");
                    }
                }
            }

            if (!fragment)
            {
                output.Append("</ul>\n");
            }

            return output.ToString();
        }