Exemplo n.º 1
0
        private void GetRelated()
        {
            // Clear related
            Properties.Clear();

            if (Template != null)
            {
                // Get Properties
                foreach (string name in Template.Properties)
                {
                    Property prp = Property.GetSingle("property_name = @0 AND property_parent_id = @1 AND property_draft = @2",
                                                      name, Post.Id, Post.IsDraft);
                    if (prp != null)
                    {
                        Properties.Add(prp);
                    }
                    else
                    {
                        Properties.Add(new Property()
                        {
                            Name = name, ParentId = Post.Id, IsDraft = Post.IsDraft
                        });
                    }
                }
            }

            // Get attached content
            if (Post.Attachments.Count > 0)
            {
                // Content meta data is actually memcached, so this won't result in multiple queries
                Post.Attachments.ForEach(a => {
                    Models.Content c = Models.Content.GetSingle(a);
                    if (c != null)
                    {
                        AttachedContent.Add(c);
                    }
                });
            }

            // Get extensions
            Extensions = Post.GetExtensions();

            // Get whether comments should be enabled
            EnableComments = Areas.Manager.Models.CommentSettingsModel.Get().EnablePosts;
            if (!Post.IsNew && EnableComments)
            {
                using (var db = new DataContext()) {
                    Comments = db.Comments.
                               Include("CreatedBy").
                               Where(c => c.ParentId == Post.Id && c.ParentIsDraft == false).
                               OrderByDescending(c => c.Created).ToList();
                }
            }
        }
Exemplo n.º 2
0
        private void GetRelated()
        {
            // Clear related
            Properties.Clear();

            if (Template != null)
            {
                // Get Properties
                foreach (string name in Template.Properties)
                {
                    Property prp = Property.GetSingle("property_name = @0 AND property_parent_id = @1 AND property_draft = @2",
                                                      name, Post.Id, Post.IsDraft);
                    if (prp != null)
                    {
                        Properties.Add(prp);
                    }
                    else
                    {
                        Properties.Add(new Property()
                        {
                            Name = name, ParentId = Post.Id, IsDraft = Post.IsDraft
                        });
                    }
                }
            }

            // Get attached content
            if (Post.Attachments.Count > 0)
            {
                // Content meta data is actually memcached, so this won't result in multiple queries
                Post.Attachments.ForEach(a => {
                    Models.Content c = Models.Content.GetSingle(a);
                    if (c != null)
                    {
                        AttachedContent.Add(c);
                    }
                });
            }
        }
Exemplo n.º 3
0
        private void GetRelated()
        {
            // Clear related
            Regions.Clear();
            Properties.Clear();
            AttachedContent.Clear();

            // Get group parents
            DisableGroups = SysGroup.GetParents(Page.GroupId);
            DisableGroups.Reverse();

            // Get template & permalink
            Template  = PageTemplate.GetSingle("pagetemplate_id = @0", Page.TemplateId);
            Permalink = Permalink.GetSingle(Page.PermalinkId);
            if (Permalink == null)
            {
                // Get the site tree
                using (var db = new DataContext()) {
                    var sitetree = db.SiteTrees.Where(s => s.Id == Page.SiteTreeId).Single();

                    Permalink = new Permalink()
                    {
                        Id = Guid.NewGuid(), Type = Permalink.PermalinkType.PAGE, NamespaceId = sitetree.NamespaceId
                    };
                    Page.PermalinkId = Permalink.Id;
                }
            }

            // Get placement ref title
            if (!IsSite)
            {
                if (Page.ParentId != Guid.Empty || Page.Seqno > 1)
                {
                    Page refpage = null;
                    if (Page.Seqno > 1)
                    {
                        if (Page.ParentId != Guid.Empty)
                        {
                            refpage = Page.GetSingle("page_parent_id = @0 AND page_seqno = @1", Page.ParentId, Page.Seqno - 1);
                        }
                        else
                        {
                            refpage = Page.GetSingle("page_parent_id IS NULL AND page_seqno = @0", Page.Seqno - 1);
                        }
                    }
                    else
                    {
                        refpage = Page.GetSingle(Page.ParentId, true);
                    }
                    PlaceRef = refpage.Title;
                }
            }

            if (Template != null)
            {
                // Only load regions & properties if this is an original
                if (Page.OriginalId == Guid.Empty)
                {
                    // Get regions
                    var regions = RegionTemplate.Get("regiontemplate_template_id = @0", Template.Id, new Params()
                    {
                        OrderBy = "regiontemplate_seqno"
                    });
                    foreach (var rt in regions)
                    {
                        var reg = Region.GetSingle("region_regiontemplate_id = @0 AND region_page_id = @1 and region_draft = @2",
                                                   rt.Id, Page.Id, Page.IsDraft);
                        if (reg != null)
                        {
                            Regions.Add(reg);
                        }
                        else
                        {
                            Regions.Add(new Region()
                            {
                                InternalId       = rt.InternalId,
                                Name             = rt.Name,
                                Type             = rt.Type,
                                PageId           = Page.Id,
                                RegiontemplateId = rt.Id,
                                IsDraft          = Page.IsDraft,
                                IsPageDraft      = Page.IsDraft
                            });
                        }
                    }

                    // Get Properties
                    foreach (string name in Template.Properties)
                    {
                        Property prp = Property.GetSingle("property_name = @0 AND property_parent_id = @1 AND property_draft = @2",
                                                          name, Page.Id, Page.IsDraft);
                        if (prp != null)
                        {
                            Properties.Add(prp);
                        }
                        else
                        {
                            Properties.Add(new Property()
                            {
                                Name = name, ParentId = Page.Id, IsDraft = Page.IsDraft
                            });
                        }
                    }
                }
            }
            else
            {
                throw new ArgumentException("Could not find page template for page {" + Page.Id.ToString() + "}");
            }

            // Only load attachments if this is an original
            if (Page.OriginalId == Guid.Empty)
            {
                // Get attached content
                if (Page.Attachments.Count > 0)
                {
                    // Content meta data is actually memcached, so this won't result in multiple queries
                    Page.Attachments.ForEach(a => {
                        Models.Content c = Models.Content.GetSingle(a, true);
                        if (c != null)
                        {
                            AttachedContent.Add(c);
                        }
                    });
                }
            }

            // Get page position
            Parents = BuildParentPages(Sitemap.GetStructure(Page.SiteTreeInternalId, false), Page);
            Parents.Insert(0, new PagePlacement()
            {
                Level = 1, IsSelected = Page.ParentId == Guid.Empty
            });
            Siblings = BuildSiblingPages(Page.Id, Page.ParentId, Page.Seqno, Page.ParentId, Page.SiteTreeInternalId);

            // Only load extensions if this is an original
            if (Page.OriginalId == Guid.Empty)
            {
                // Get extensions
                Extensions = Page.GetExtensions(true);
            }

            // Initialize regions
            foreach (var reg in Regions)
            {
                reg.Body.InitManager(this);
            }

            // Get whether comments should be enabled
            EnableComments = Areas.Manager.Models.CommentSettingsModel.Get().EnablePages;
            if (!Page.IsNew && EnableComments)
            {
                using (var db = new DataContext()) {
                    Comments = db.Comments.
                               Where(c => c.ParentId == Page.Id && c.ParentIsDraft == false).
                               OrderByDescending(c => c.Created).ToList();
                }
            }

            // Get the site if this is a site page
            if (Permalink.Type == Models.Permalink.PermalinkType.SITE)
            {
                using (var db = new DataContext()) {
                    SiteTree = db.SiteTrees.Where(s => s.Id == Page.SiteTreeId).Single();
                }
            }

            // Check if the page can be published
            if (Page.OriginalId != Guid.Empty)
            {
                CanPublish = Page.GetScalar("SELECT count(*) FROM page WHERE page_id=@0 AND page_draft=0", Page.OriginalId) > 0;
            }
        }
Exemplo n.º 4
0
        private void GetRelated()
        {
            // Clear related
            Regions.Clear();
            Properties.Clear();
            AttachedContent.Clear();

            // Get group parents
            DisableGroups = SysGroup.GetParents(Page.GroupId);
            DisableGroups.Reverse();

            // Get placement ref title
            if (Page.ParentId != Guid.Empty || Page.Seqno > 1)
            {
                Page refpage = null;
                if (Page.Seqno > 1)
                {
                    if (Page.ParentId != Guid.Empty)
                    {
                        refpage = Page.GetSingle("page_parent_id = @0 AND page_seqno = @1", Page.ParentId, Page.Seqno - 1);
                    }
                    else
                    {
                        refpage = Page.GetSingle("page_parent_id IS NULL AND page_seqno = @0", Page.Seqno - 1);
                    }
                }
                else
                {
                    refpage = Page.GetSingle(Page.ParentId, true);
                }
                PlaceRef = refpage.Title;
            }

            // Get template & permalink
            Template  = PageTemplate.GetSingle("pagetemplate_id = @0", Page.TemplateId);
            Permalink = Permalink.GetSingle(Page.PermalinkId);
            if (Permalink == null)
            {
                Permalink = new Permalink()
                {
                    Id = Guid.NewGuid(), Type = Permalink.PermalinkType.PAGE, NamespaceId = new Guid("8FF4A4B4-9B6C-4176-AAA2-DB031D75AC03")
                };
                Page.PermalinkId = Permalink.Id;
            }

            if (Template != null)
            {
                // Get regions
                var regions = RegionTemplate.Get("regiontemplate_template_id = @0", Template.Id, new Params()
                {
                    OrderBy = "regiontemplate_seqno"
                });
                foreach (var rt in regions)
                {
                    var reg = Region.GetSingle("region_regiontemplate_id = @0 AND region_page_id = @1 and region_draft = @2",
                                               rt.Id, Page.Id, Page.IsDraft);
                    if (reg != null)
                    {
                        Regions.Add(reg);
                    }
                    else
                    {
                        Regions.Add(new Region()
                        {
                            InternalId       = rt.InternalId,
                            Name             = rt.Name,
                            Type             = rt.Type,
                            PageId           = Page.Id,
                            RegiontemplateId = rt.Id,
                            IsDraft          = Page.IsDraft,
                            IsPageDraft      = Page.IsDraft
                        });
                    }
                }

                // Get Properties
                foreach (string name in Template.Properties)
                {
                    Property prp = Property.GetSingle("property_name = @0 AND property_parent_id = @1 AND property_draft = @2",
                                                      name, Page.Id, Page.IsDraft);
                    if (prp != null)
                    {
                        Properties.Add(prp);
                    }
                    else
                    {
                        Properties.Add(new Property()
                        {
                            Name = name, ParentId = Page.Id, IsDraft = Page.IsDraft
                        });
                    }
                }
            }
            else
            {
                throw new ArgumentException("Could not find page template for page {" + Page.Id.ToString() + "}");
            }

            // Get attached content
            if (Page.Attachments.Count > 0)
            {
                // Content meta data is actually memcached, so this won't result in multiple queries
                Page.Attachments.ForEach(a => {
                    Models.Content c = Models.Content.GetSingle(a);
                    if (c != null)
                    {
                        AttachedContent.Add(c);
                    }
                });
            }

            // Get page position
            Parents = BuildParentPages(Sitemap.GetStructure(false), Page);
            Parents.Insert(0, new PagePlacement()
            {
                Level = 1, IsSelected = Page.ParentId == Guid.Empty
            });
            Siblings = BuildSiblingPages(Page.Id, Page.ParentId, Page.Seqno, Page.ParentId);
        }