public List <UsedByRelation> Relation(ApiCall call) { var sitedb = call.WebSite.SiteDb(); string type = call.GetValue("type", "by"); if (string.IsNullOrEmpty(type)) { return(null); } byte consttype = ConstObjectType.GetByte(type); if (call.ObjectId != default(Guid)) { return(sitedb.Styles.GetUsedBy(call.ObjectId) .Where(it => it.ConstType == consttype) .Select(it => { it.Url = sitedb.WebSite.BaseUrl(it.Url); return it; }).ToList()); } return(null); }
private List <UsedByRelation> PageRelation(SiteDb sitedb, string by, Guid PageId) { string baseurl = sitedb.WebSite.BaseUrl(); byte consttype = ConstObjectType.GetByte(by); List <UsedByRelation> result = new List <UsedByRelation>(); var relations = sitedb.Relations.GetRelations(PageId, consttype); foreach (var item in relations) { var objectinfo = ObjectService.GetObjectInfo(sitedb, item.objectYId, item.ConstTypeY); if (objectinfo != null) { UsedByRelation relation = new UsedByRelation(); relation.Name = objectinfo.DisplayName; relation.Url = objectinfo.Url; if (!string.IsNullOrEmpty(relation.Url)) { relation.Url = Lib.Helper.UrlHelper.Combine(baseurl, relation.Url); } relation.ModelType = objectinfo.ModelType; relation.ObjectId = objectinfo.ObjectId; relation.ConstType = objectinfo.ConstType; result.Add(relation); } } return(result); }
public string RenderSystemLink(RenderContext context, Routing.Route route) { Render.FrontContext frontContext = context.GetItem <Render.FrontContext>(); route.Parameters = ObjectRoute.ParseParameters(route, this.Url); var constTypeString = route.Parameters.GetValue("objecttype"); byte constType = ConstObjectType.Unknown; if (!byte.TryParse(constTypeString, out constType)) { constType = ConstObjectType.GetByte(constTypeString); } var id = route.Parameters.GetValue("nameorid"); if (constType == ConstObjectType.View) { var view = context.WebSite.SiteDb().Views.GetByNameOrId(id); if (view != null) { var relation = context.WebSite.SiteDb().Relations.GetReferredBy(view, ConstObjectType.Page); if (relation != null && relation.Count > 0) { var pageid = relation[0].objectXId; var pageroute = context.WebSite.SiteDb().Routes.GetByObjectId(pageid); if (pageroute != null) { return(RenderPageRoute(context, pageroute)); } } /// if view was not rendered within and by the page... try to render with rendercode. if (frontContext.Page != null && frontContext.ExecutingView != null) { string currenturl = context.Request.RelativeUrl; var values = PageRoute.GetViewParameterValues(context.WebSite.SiteDb(), view, frontContext); var alternativeviewcode = Cache.ViewInSamePosition.GetAlternativeCode(frontContext.ExecutingView.Id, view.Id); values.Add(SiteConstants.AlternativeViewQueryName, alternativeviewcode.ToString()); return(Kooboo.Lib.Helper.UrlHelper.AppendQueryString(currenturl, values)); } else if (frontContext.Page == null) { var values = PageRoute.GetViewParameterValues(context.WebSite.SiteDb(), view, frontContext); return(Kooboo.Lib.Helper.UrlHelper.AppendQueryString(this.Url, values)); } } } return(null); }
private PagedListViewModel <MediaFileViewModel> GetPagedFilesBy(SiteDb siteDb, string by, int PageSize, int PageNumber) { string baseurl = siteDb.WebSite.BaseUrl(); // by = View, Page, Layout, TextContent, Style. byte consttype = ConstObjectType.GetByte(by); var images = siteDb.Images.ListUsedBy(consttype); int totalskip = 0; if (PageNumber > 1) { totalskip = (PageNumber - 1) * PageSize; } PagedListViewModel <MediaFileViewModel> Result = new PagedListViewModel <MediaFileViewModel>(); Result.TotalCount = images.Count(); Result.TotalPages = ApiHelper.GetPageCount(Result.TotalCount, PageSize); Result.PageSize = PageSize; Result.PageNr = PageNumber; List <MediaFileViewModel> list = new List <MediaFileViewModel>(); foreach (var item in images.Skip(totalskip).Take(PageSize)) { MediaFileViewModel model = new MediaFileViewModel(); model.Id = item.Id; model.Height = item.Height; model.Width = item.Width; model.Size = item.Size; model.Name = item.Name; model.LastModified = item.LastModified; model.Thumbnail = ThumbnailService.GenerateThumbnailUrl(item.Id, 90, 0, siteDb.Id); model.Url = ObjectService.GetObjectRelativeUrl(siteDb, item); model.IsImage = true; model.PreviewUrl = Lib.Helper.UrlHelper.Combine(baseurl, model.Url); var usedby = siteDb.Images.GetUsedBy(item.Id); if (usedby != null) { model.References = usedby.GroupBy(it => it.ConstType).ToDictionary( key => { return(ConstTypeService.GetModelType(key.Key).Name); }, value => value.Count()); } list.Add(model); } Result.List = list; return(Result); }
public static void Render(FrontContext context) { //systemroute.Name = "__kb/{objecttype}/{nameorid}"; defined in Routes. var paras = context.Route.Parameters; var constTypeString = paras.GetValue("objecttype"); byte constType = ConstObjectType.Unknown; if (!byte.TryParse(constTypeString, out constType)) { constType = ConstObjectType.GetByte(constTypeString); } var id = paras.GetValue("nameorid"); switch (constType) { case ConstObjectType.ResourceGroup: ResourceGroupRender(context, id); return; case ConstObjectType.View: ViewRender(context, id, paras); return; case ConstObjectType.Image: { ImageRender(context, id, paras); return; } case ConstObjectType.File: { FileRender(context, id, paras); return; } case ConstObjectType.kfile: { KFileRender(context, paras); return; } //case ConstObjectType.TextContent: // { // TextContentRender(context, id, paras); // return; // } default: DefaultRender(context, constType, id, paras); break; } }
public List <UsedByRelation> ShowBy(ApiCall call) { var sitedb = call.WebSite.SiteDb(); string type = call.GetValue("type"); string by = call.GetValue("by"); if (string.IsNullOrEmpty(type) || string.IsNullOrEmpty(by)) { return(null); } if (type.ToLower() == "page") { return(PageRelation(sitedb, by, call.ObjectId)); } var repo = sitedb.GetRepository(type); var siteobject = repo?.Get(call.ObjectId); if (repo == null || siteobject == null) { return(null); } string baseurl = call.WebSite.BaseUrl(); byte consttype = ConstObjectType.GetByte(by); List <UsedByRelation> result = new List <UsedByRelation>(); var usedby = repo.GetUsedBy(call.ObjectId).Where(o => o.ConstType == consttype).ToList(); foreach (var item in usedby) { item.Url = sitedb.WebSite.BaseUrl(item.Url); } return(usedby); }
private List <MediaFileViewModel> GetFilesBy(SiteDb siteDb, string by) { string baseurl = siteDb.WebSite.BaseUrl(); // by = View, Page, Layout, TextContent, Style. byte consttype = ConstObjectType.GetByte(by); var images = siteDb.Images.ListUsedBy(consttype); List <MediaFileViewModel> Result = new List <MediaFileViewModel>(); foreach (var item in images) { MediaFileViewModel model = new MediaFileViewModel(); model.Id = item.Id; model.Height = item.Height; model.Width = item.Width; model.Size = item.Size; model.Name = item.Name; model.LastModified = item.LastModified; model.Thumbnail = ThumbnailService.GenerateThumbnailUrl(item.Id, 90, 0, siteDb.Id); model.Url = ObjectService.GetObjectRelativeUrl(siteDb, item); model.IsImage = true; model.PreviewUrl = Lib.Helper.UrlHelper.Combine(baseurl, model.Url); var usedby = siteDb.Images.GetUsedBy(item.Id); if (usedby != null) { model.References = usedby.GroupBy(it => it.ConstType).ToDictionary( key => { return(ConstTypeService.GetModelType(key.Key).Name); }, value => value.Count()); } Result.Add(model); } return(Result); }
public List <UsedByRelation> ShowRelation(ApiCall call) { var viewdatamethod = call.WebSite.SiteDb().ViewDataMethods.Query.Where(o => o.MethodId == call.ObjectId).SelectAll(); string by = call.GetValue("by"); if (string.IsNullOrEmpty(by)) { return(null); } byte consttype = ConstObjectType.GetByte(by); var usedby = call.WebSite.SiteDb().Images.GetUsedBy(call.ObjectId).Where(o => o.ConstType == consttype).ToList(); foreach (var item in usedby) { item.Url = call.WebSite.SiteDb().WebSite.BaseUrl(item.Url); } return(usedby); }
public object Relation(ApiCall call) { string type = call.GetValue("type", "by"); if (string.IsNullOrEmpty(type)) { return(null); } byte consttype = ConstObjectType.GetByte(type); if (call.ObjectId != default(Guid)) { return(call.WebSite.SiteDb().Scripts.GetUsedBy(call.ObjectId) .Where(it => it.ConstType == consttype) .Select(it => { it.Url = call.WebSite.BaseUrl(it.Url); return it; })); } return(null); }