More in this section

Forums / Developing with Sitefinity / EventsView shows non approved, non published events when event workflow is turned on.

EventsView shows non approved, non published events when event workflow is turned on.

3 posts, 0 answered
  1. Adam @Habanero
    Adam @Habanero avatar
    45 posts
    Registered:
    22 Jun 2012
    12 Aug 2008
    Link to this post
    We found a bug and have already reported it, but we thought others may like the solution (work around) until the bug is fixed.

    Situation:
    1.  You turn on workflow for events by adding "allowWorkFlow=true" to the workflow module intry in the web.config.
    2.  You add an event, but do not approve or publish it.
    3.  You add an eventView to a page and view the page on the live site.  The un-published, not approved event shows up even though it should not.


    Here is one way to address this quite easily.  Basically we will create our own EventView control and override the datasource creation.

    1.  Create a new class that inherits from Telerik.Events.WebControls.EventsView  in a code project.  Name the Control "MyEventsView" and the namespace for the class "MyControls".

    2.  Add an entry to the <toolboxControls> section in web.config for this new class

    <add name="My Events View" section="Events" type="MyEventsView, MyControls" /> 

    Make sure your web project has a reference to your custom code project so that the assembly ends up in the bin.  If you do not do this you will need to copy the assembly to the Bin.

    At this point if you go into Sitefinity admin and edit a page, you should have a new control under the Events group on the toolbox called "My Events View"

    Currenttly it will have the exact same behaviour as the out of the box EventsView, so we need a bit more code.

    Using Reflector, we were able to determine which methods to override in order to be able to filter out the events we did not want to see.

    Add the following using statements to your MyEventsView class:

    using System.Collections; 
    using Telerik.Cms.Engine; 
    using Telerik.Events.WebControls; 
    using Telerik.Cms.Engine.Data; 

    Next add the following code to your class:


     protected override IList CreateDataSource() 
            { 
                IList allEvents = base.CreateDataSource(); 
                FilterNonPublished(allEvents); 
                return allEvents; 
                
            } 
     
            protected override IList CreateDataSourceByCategory(Guid categoryID) 
            { 
                IList allEvents = base.CreateDataSourceByCategory(categoryID); 
                FilterNonPublished(allEvents); 
                return allEvents; 
            } 
     
     
            private void FilterNonPublished(IList allEvents) 
            { 
                for(int index = allEvents.Count -1; index >= 0; index--) 
                { 
                    if (((CmsContentBase)allEvents[index]).Status != ContentStatus.Published) 
                        allEvents.RemoveAt(index); 
                } 
     
            } 

    What we are doing is intercepting the List of content items that is to be bound to the events view and removing any that are not currently published.  Because we are inheriting from the out of the box control, the rest of the processing will remain the same.

    Here is the entire class:

    using System; 
    using System.Collections; 
    using Telerik.Cms.Engine; 
    using Telerik.Events.WebControls; 
    using Telerik.Cms.Engine.Data; 
     
    namespace MyControls 
        public class MyEventsView : EventsView 
        { 
            protected override IList CreateDataSource() 
            { 
                IList allEvents = base.CreateDataSource(); 
                FilterNonPublished(allEvents); 
                return allEvents; 
                
            } 
     
            protected override IList CreateDataSourceByCategory(Guid categoryID) 
            { 
                IList allEvents = base.CreateDataSourceByCategory(categoryID); 
                FilterNonPublished(allEvents); 
                return allEvents; 
            } 
     
     
            private void FilterNonPublished(IList allEvents) 
            { 
                for(int index = allEvents.Count -1; index >= 0; index--) 
                { 
                    if (((CmsContentBase)allEvents[index]).Status != ContentStatus.Published) 
                        allEvents.RemoveAt(index); 
                } 
            } 
        } 
     

  2. Ivan
    Ivan avatar
    478 posts
    Registered:
    16 Jun 2015
    14 Aug 2008
    Link to this post
    Hello Adam @Habaneros,

    This is a very nice workaround and we'd like to thank you for it. With your permission, we can publish this on our blog and credit your company for it (Habanero Consulting Group - www.habaneros.com). Let me know what you think about that.

    We really appreciate the effort you undertook to share this with the community.

    Greetings,
    Ivan
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Adam @Habanero
    Adam @Habanero avatar
    45 posts
    Registered:
    22 Jun 2012
    14 Aug 2008
    Link to this post
    Hi Ivan,

    That sounds great.  Glad we could help.

    Adam
Register for webinar
3 posts, 0 answered