/// <summary> /// Creates a new item instance /// </summary> /// <returns>The new item</returns> public T Create() { return((T)PageModel.CreateRegion(TypeId, RegionId)); }
/// <summary> /// Gets the view for model. /// </summary> /// <param name="m">The page model</param> /// <returns>The view</returns> public static string GetView(this Piranha.Models.PageModel m) { return(((Piranha.Models.Page)m.Page).View); }
/// <summary> /// Gets the associated regions for the current page /// </summary> protected void Init() { var id = Page.Id; // Handle page copies if (((Models.Page)Page).OriginalId != Guid.Empty) { var copy = (Models.Page)Page; var org = Models.Page.GetSingle(copy.OriginalId, copy.IsDraft); copy.Id = org.Id; copy.GroupId = org.GroupId; copy.DisabledGroups = org.DisabledGroups; copy.Keywords = org.Keywords; copy.Description = org.Description; copy.LastModified = copy.LastModified > org.LastModified ? copy.LastModified : org.LastModified; copy.Attachments = org.Attachments; } // Get the page template PageTemplate pt = PageTemplate.GetSingle(((Page)Page).TemplateId); // Regions var regions = RegionTemplate.GetByTemplateId(pt.Id); if (regions.Count > 0) { foreach (var rt in regions) { if (rt.Type != "Piranha.Extend.Regions.PostRegion") { if (ExtensionManager.Current.HasType(rt.Type)) { // Create empty region object body = ExtensionManager.Current.CreateInstance(rt.Type); // Initialize empty regions if (body != null) { body = ((IExtension)body).GetContent(this); } ((IDictionary <string, object>)Regions).Add(rt.InternalId, body); } else { ((IDictionary <string, object>)Regions).Add(rt.InternalId, null); } } else { ((IDictionary <string, object>)Regions).Add(rt.InternalId, new List <Piranha.Entities.Post>()); } } Piranha.Models.Region.GetContentByPageId(Page.Id, Page.IsDraft).ForEach(reg => { string cachename = null; if (!Page.IsDraft) { cachename = Extend.Regions.PostRegion.CacheName(Page, reg); } if (!(reg.Body is Extend.Regions.PostRegion)) { object content = reg.Body; // Initialize region content = ((IExtension)content).GetContent(this); if (((IDictionary <string, object>)Regions).ContainsKey(reg.InternalId)) { ((IDictionary <string, object>)Regions)[reg.InternalId] = content; } } else { if (((IDictionary <string, object>)Regions).ContainsKey(reg.InternalId)) { ((IDictionary <string, object>)Regions)[reg.InternalId] = ((Extend.Regions.PostRegion)reg.Body).GetMatchingPosts(cachename); } } }); } // Properties if (pt.Properties.Count > 0) { foreach (string str in pt.Properties) { ((IDictionary <string, object>)Properties).Add(str, ""); } Property.GetContentByParentId(Page.Id, Page.IsDraft).ForEach(pr => { if (((IDictionary <string, object>)Properties).ContainsKey(pr.Name)) { ((IDictionary <string, object>)Properties)[pr.Name] = pr.Value; } }); } // Attachments foreach (var guid in ((Models.Page)Page).Attachments) { var a = Models.Content.GetSingle(guid, Page.IsDraft); if (a != null) { Attachments.Add(a); } } // Extensions foreach (var ext in ((Page)Page).GetExtensions()) { object body = ext.Body; if (body != null) { var getContent = body.GetType().GetMethod("GetContent"); if (getContent != null) { body = getContent.Invoke(body, new object[] { this }); } } ((IDictionary <string, object>)Extensions)[ExtensionManager.Current.GetInternalIdByType(ext.Type)] = body; } // Blocks var blocks = Piranha.Models.Page.GetFields("page_id, page_last_modified", "page_parent_id=@0 AND page_draft = 0 AND pagetemplate_is_block = 1", Page.Id, new Piranha.Data.Params() { OrderBy = "page_seqno" }); foreach (var block in blocks) { var blockModel = PageModel.GetById(block.Id); // Add the block to the page model Blocks.Add(blockModel); // Check if we should update the page's last modified date. if (((Models.Page)blockModel.Page).LastModified > ((Models.Page)Page).LastModified) { ((Models.Page)Page).LastModified = ((Models.Page)blockModel.Page).LastModified; } } // Reset the page id if we changed it to load a copy ((Models.Page)Page).Id = id; }