1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Combining Events from other sources alongside sitefinity Events Module

Combining Events from other sources alongside sitefinity Events Module

3 posts, 0 answered
  1. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    22 Apr 2008
    Link to this post
    Hey all, I have been reading through the forums and I am amazed at the level of attention some requests have received, so after hitting this snag I hoped I might luck out the same :)

    I am wanting to use the events module to populate a calendar of events, which seems pretty straightforward, but I am also needing to combine these general events with another datasource of events from a different database with a different schema. I'm fairly certain I can map the necessary data to match the schema needed by the events provider but I guess I just need a starting point.

    would I be better off building my own provider? I'm not needing a way to ADD events to this external calendar, only read into them and combine with the events in the sitefinity module. However, I of course DO need to retain the functionality to add/edit events in the sitefinity calendar.

    Any information would be appreciated here! thanks
  2. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    22 Apr 2008
    Link to this post
    okay well i started playing with it a little. I found some documentation on how to ACTIVATE a custom provider but none on how to actually BUILD one. I did manage to inherit from the events provider and override the get method and populate a list of the external events, but I'm kind of lost on how to join that with the sitefinity events.

    Let me give more detail on what I'm trying to do and maybe someone can provide some ideas, I'd really appreciate it!

    i'd like to be able to display both the sitefinity events module events AND the external events on the rad scheduler component of sitefinity. when a user clicks a sitefinity event, I want them to be directed to the regular built-in single-event view page inside sitefinity (in other words, the way it works out-of-box). however if they click on the external event, i want that to have it's own link to take them to the external calendar. this link is available as part of the external query, so I can put it in, I just don't know where...

    I thought about just copying over the data from the external calendar, but they may edit and/or delete events in which case the data on the sitefinity site will be obsolete. and yes unfortunately, is IS a requirement that I pull this data and merge it with sitefinity somehow...

    I'm starting to think that the best way is just to make my own user controls for the calendar and list, populating and changing the links manually, but if there's a better way or anyone has any ideas I'd be most grateful. thanks!
  3. Ivan
    Ivan avatar
    478 posts
    Registered:
    16 Jun 2015
    28 Apr 2008
    Link to this post
    Hi SelArom,

    you are on your way with implementing the custom provider:

    My suggestion to you is to do following:

    1. Implement the new method on your provider (e.g. GetMyMixedEvents), to make sure that the admin part of Events module does not confuse your method with existing GetEvents methods
    2. Create new Interface (e.g. IExternalEvent). Make it have only one property (e.g. ExternalUrl)
    3. Create a new class (e.g. MyEvent) and implement the IEvent interface on it - this class you'll be using for the external items. Also implement IExternalEvent interface on it
    4. In GetMyMixedEvents class pull the Sitefinity Events first (for example IList sfEvents = this.GetEvents(... )
    5. Do whatever you do to pull the external events... for each of the items create a new instance of MyEvent object and then add it to the list of events you'll already pulled from Sitefinity Events module. You'll be able to do so because they are both implementing IEvent interface
    6. Create new public control and wrap RadScheduler (I mean the Telerik control, not Sitefinity control) in it
    7. Create object data source, set your GetMyMixedEvents as a method and bind it to the RadScheduler
    8. In your RadScheduler item template, set a HyperLink control (you'll set the text and url later)
    9. Handle AppointmentCreated event of RadScheduler. If appointment is of type IExternalEvent you set the NavigateUrl property to the ExternalUrl property. If not, you can call this method that we use in Events module:

    It takes 2 parameters : IContent (pass it IEvent.ContentItem object) and single item url, which is a property with the url of the page where single event should be displayed.

    /// <summary>  
            /// Gets the URL to a single content item. This method is invoked for every item that  
            /// is binding to the list. By default the item ID is appended to the query string portion  
            /// of the URL.  
            /// </summary>  
            /// <returns>String containing the URL address.</returns>  
            /// <param name="contentItem">  
            ///     The <see cref="Telerik.Cms.Engine.IContent">IContent</see> item that is currently  
            ///     binding.  
            /// </param>  
            protected virtual string GetItemUrl(IContent contentItem, string singleItemUrl)  
            {  
                string sep = String.Empty;  
                string ret = String.Empty;  
                string url = singleItemUrl;  
                if (String.IsNullOrEmpty(url) && CmsContext.CurrentUrl != null)  
                {  
                    url = CmsContext.CurrentUrl.Path;  
                }  
                else 
                {  
                    sep = "&";  
     
                    if (String.IsNullOrEmpty(this.Context.Request.QueryString["ReturnURL"]))  
                    {  
                        ret = String.Concat("ReturnURL="this.Context.Server.UrlEncode(this.Context.Request.RawUrl));  
                    }  
                    else 
                    {  
                        ret = String.Concat("ReturnURL="this.Context.Server.UrlEncode(this.Context.Request.QueryString["ReturnURL"]));  
                    }  
                }  
                if (String.IsNullOrEmpty(contentItem.Url))  
                {  
                    int idx = url.IndexOf('?');  
                    if (idx != -1)  
                        url = url.Substring(0, idx);  
                    url = String.Concat(url, "?",  
                        ContentManager.ContentProviderKey, "=", contentItem.ProviderName, "&",  
                        ContentManager.ContentItemKey, "=", contentItem.ID, sep, ret);  
                }  
                else 
                {  
                    string itemUrl = String.Concat(contentItem.Url, this.eventsManager.Content.Provider.ContentExtension);  
                    if (this.eventsManager.Content.Provider.UrlFormatQueryStringIndex != -1)  
                    {  
                        itemUrl += "?" + ContentUrlRewriterService.FormatURL(contentItem, this.eventsManager.Content.Provider  
                            , ContentUrlRewriterService.FormatOptions.QueryString);  
                    }  
                    else if (sep.Length > 0)  
                    {  
                        sep = "?";  
                    }  
                    if (!itemUrl.StartsWith("~"))  
                    {  
                        int idx = url.LastIndexOf('.');  
                        if (idx != -1)  
                        {  
                            url = url.Substring(0, idx);  
                        }  
                        else 
                        {  
                            idx = url.IndexOf('?');  
                            if (idx != -1)  
                                url = url.Substring(0, idx);  
                        }  
     
                        itemUrl = String.Concat(VirtualPathUtility.RemoveTrailingSlash(url), itemUrl);  
                    }  
                    url = String.Concat(itemUrl, sep, ret);  
                }  
                IUrlService svc = UrlServices.GetLanguageService();  
                if (svc != null)  
                    return svc.ResolveLanguageUrl(url);  
                return url;  
            } 

    I hope this helps. You'll probably have more questions as you start implementing this, so don't hesitate to ask.

    Best wishes,
    Ivan
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Register for webinar
3 posts, 0 answered