using System; using System.Collections.Generic; using System.Linq; using Telligent.Evolution.Extensibility; using Telligent.Evolution.Extensibility.Api.Entities.Version1; using Telligent.Evolution.Extensibility.Api.Version1; using Telligent.Evolution.Extensibility.Content.Version1; using IContent = Telligent.Evolution.Extensibility.Content.Version1.IContent; namespace Samples.Links { public class LinkItemContentType : IContentType, ISearchableContentType { IContentStateChanges _contentState = null; #region IPlugin Members public string Description { get { return "Items in a Links collection"; } } public void Initialize() { } public string Name { get { return "Link Items"; } } #endregion #region IContentType Members public Guid[] ApplicationTypes { get { return new Guid[] { ContentTypes.LinksApplicationId }; } } public void AttachChangeEvents(IContentStateChanges stateChanges) { _contentState = stateChanges; } public Guid ContentTypeId { get { return ContentTypes.LinksItemId; } } public string ContentTypeName { get { return "Links Item"; } } public IContent Get(Guid contentId) { return LinksData.GetLink(contentId); } #endregion #region ISearchableContentType public void SetIndexStatus(Guid[] contentIds, bool isIndexed) { LinksData.UpdateStatus(contentIds, isIndexed); } public IList GetContentToIndex() { var docs = new List(); var links = LinksData.ListLinks().Where(link => !link.IsIndexed); foreach (var link in links) { if (link == null) { continue; } var doc = Apis.Get().NewDocument(link.ContentId, link.ContentTypeId, "linkitem", link.Url, link.HtmlName("web"), link.HtmlDescription("web")); doc.AddField("date", Apis.Get().FormatDate(link.CreatedDate)); docs.Add(doc); } return docs; } public int[] GetViewSecurityRoles(Guid contentId) { var content = LinksData.GetLink(contentId); if (content == null) { return new int[] { }; } if (content.Application == null) { return new int[] { }; } return Apis.Get().Find("Registered Users").Select(r => r.Id.GetValueOrDefault()).ToArray(); } public string GetViewHtml(IContent content, Target target) { if (content == null) { return null; } var user = Apis.Get().Get(new UsersGetOptions { Id = content.CreatedByUserId }); var author = String.Format(@"{1}", PublicApi.Html.EncodeAttribute(user.ProfileUrl), PublicApi.Html.Encode(user.DisplayName)); var appLink = content.Application != null ? String.Format(@"{1}", PublicApi.Html.EncodeAttribute(content.Application.Url), content.Application.HtmlName(target.ToString())) : String.Empty; var groupLink = content.Application != null && content.Application.Container != null ? String.Format(@"{1}", PublicApi.Html.EncodeAttribute(content.Application.Container.Url), content.Application.Container.HtmlName(target.ToString())) : String.Empty; return String.Format(@"
  • {0}
  • {1}

{2}

{5}
{6} {7}
", Apis.Get().FormatDate(content.CreatedDate), author, content.HtmlName("web"), content.HtmlName("web"), PublicApi.Html.EncodeAttribute(content.Url), content.HtmlDescription("web"), appLink, groupLink); } public bool IsCacheable { get { return true; } } public bool VaryCacheByUser { get { return true; } } #endregion } }