Exemple #1
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 PageEditModel GetById(Guid id) {
			PageEditModel m = new PageEditModel() ;
			m.Template = PageTemplate.GetSingle(id) ;
			m.Regions = RegionTemplate.Get("regiontemplate_template_id = @0", id, new Params() { OrderBy = "regiontemplate_seqno" }) ;

			return m ;
		}
        /// <summary>
        /// Saves the model.
        /// </summary>
        /// <returns>Weather the operation succeeded</returns>
        public bool SaveAll()
        {
            using (IDbTransaction tx = Database.OpenTransaction()) {
                List <object> args  = new List <object>();
                string        sql   = "";
                var           isNew = Template.IsNew;

                // Delete all unattached properties
                args.Add(Template.Id);
                Template.Properties.Each((n, p) => {
                    sql += (sql != "" ? "," : "") + "@" + (n + 1).ToString();
                    args.Add(p);
                });
                Property.Execute("DELETE FROM property WHERE property_parent_id IN (" +
                                 "SELECT page_id FROM page WHERE page_template_id = @0) " +
                                 (sql != "" ? "AND property_name NOT IN (" + sql + ")" : ""), tx, args.ToArray());

                // Save the template
                Template.Save(tx);

                // Update all regiontemplates with the id if this is an insert
                if (isNew)
                {
                    Regions.ForEach(r => r.TemplateId = Template.Id);
                }

                // Delete removed regions templates
                sql = "";
                args.Clear();
                args.Add(Template.Id);
                var pos = 1;
                foreach (var reg in Regions)
                {
                    if (reg.Id != Guid.Empty)
                    {
                        sql += (sql != "" ? "," : "") + "@" + pos.ToString();
                        args.Add(reg.Id);
                        pos++;
                    }
                }
                RegionTemplate.Execute("DELETE FROM regiontemplate WHERE regiontemplate_template_id = @0 " +
                                       (sql != "" ? "AND regiontemplate_id NOT IN (" + sql + ")" : ""), tx, args.ToArray());
                // Save the regions
                foreach (var reg in Regions)
                {
                    reg.Save(tx);
                }
                tx.Commit();
            }
            // Reload regions
            Regions = RegionTemplate.Get("regiontemplate_template_id = @0", Template.Id,
                                         new Params()
            {
                OrderBy = "regiontemplate_seqno"
            });

            return(true);
        }
Exemple #3
0
        /// <summary>
        /// Gets the model for the template specified by the given id.
        /// </summary>
        /// <param name="id">The template id</param>
        /// <param name="loadRegionTypes">If the region types should be loaded</param>
        /// <returns>The model</returns>
        public static PageEditModel GetById(Guid id, bool loadRegionTypes = true)
        {
            PageEditModel m = new PageEditModel(loadRegionTypes);

            m.Template = PageTemplate.GetSingle(id);
            m.Regions  = RegionTemplate.Get("regiontemplate_template_id = @0", id, new Params()
            {
                OrderBy = "regiontemplate_seqno"
            });

            return(m);
        }
Exemple #4
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;
            }
        }
Exemple #5
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);
        }