Ejemplo n.º 1
0
        /// <summary>
        /// Gets the related information
        /// </summary>
        private void GetRelated()
        {
            // Get Permalink
            Permalink = Permalink.GetSingle(Category.PermalinkId);
            if (Permalink == null)
            {
                Permalink = new Permalink()
                {
                    Id          = Guid.NewGuid(),
                    Type        = Models.Permalink.PermalinkType.CATEGORY,
                    NamespaceId = new Guid("AE46C4C4-20F7-4582-888D-DFC148FE9067")
                };
                Category.PermalinkId = Permalink.Id;
            }

            // Get categories
            List <Category> cats = Piranha.Models.Category.Get("category_id != @0", Category.Id,
                                                               new Params()
            {
                OrderBy = "category_name ASC"
            });

            cats.Insert(0, new Category());
            Categories = new SelectList(cats, "Id", "Name");

            // Get extensions
            Extensions = Category.GetExtensions(true);
        }
Ejemplo n.º 2
0
		/// <summary>
		/// Gets the model for the template specified by the given id.
		/// </summary>
		/// <param name="id">The template id</param>
		/// <returns>The model</returns>
		public static PostEditModel GetById(Guid id) {
			PostEditModel m = new PostEditModel();
			m.Template = PostTemplate.GetSingle(id);
			if (m.Template.Properties == null)
				m.Template.Properties = new List<string>();
			if (m.Template.PermalinkId != Guid.Empty)
				m.Permalink = Permalink.GetSingle(m.Template.PermalinkId);
			else m.Template.PermalinkId = m.Permalink.Id;

			return m;
		}
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the model for the post
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static EditModel GetById(Guid id, bool draft = true)
        {
            EditModel m = new EditModel();

            m.Post      = Piranha.Models.Post.GetSingle(id, draft);
            m.Template  = PostTemplate.GetSingle(m.Post.TemplateId);
            m.Permalink = Permalink.GetSingle(m.Post.PermalinkId);
            Category.GetByPostId(m.Post.Id, draft).ForEach(c => m.PostCategories.Add(c.Id));
            m.Categories = new MultiSelectList(Category.GetFields("category_id, category_name",
                                                                  new Params()
            {
                OrderBy = "category_name"
            }), "Id", "Name", m.PostCategories);
            m.GetRelated();

            return(m);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Refreshes the current model.
 /// </summary>
 public void Refresh()
 {
     if (Post != null)
     {
         if (!Post.IsNew)
         {
             Post      = Piranha.Models.Post.GetSingle(Post.Id, true);
             Permalink = Permalink.GetSingle(Post.PermalinkId);
             Category.GetByPostId(Post.Id).ForEach(c => PostCategories.Add(c.Id));
             Categories = new MultiSelectList(Category.GetFields("category_id, category_name",
                                                                 new Params()
             {
                 OrderBy = "category_name"
             }), "Id", "Name", PostCategories);
         }
         Template = PostTemplate.GetSingle(Post.TemplateId);
         GetRelated();
     }
 }
Ejemplo n.º 5
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;
            }
        }
Ejemplo n.º 6
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);
        }