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

Forums / Developing with Sitefinity / Get all Events including expired and unpublished items

Get all Events including expired and unpublished items

4 posts, 0 answered
  1. SteveV
    SteveV avatar
    178 posts
    Registered:
    06 Nov 2011
    21 Nov 2013
    Link to this post
    Hi Everyone,

    Our special needs school has a number of events scheduled throughout the school year and events are assigned one of several different predefined categories. 

    I need to display a school calendar list that pulls information out of a custom school calendar widget that shows holidays, staff training days, etc. and displays the information by month.  I also need to include events by month and category in this list. 

    I have all of this working nicely but have run into an issue I didn't anticipate.  We generally un-publish events a week after the event date has passed.  The problem is that my list doesn't show un-published events which makes it look like we've had no events from July 1, 2013 (the beginning of our current school year) to November 2013.

    Here's what the code that gets events be category looks like.  Any thoughts?
    private PACCalendarItemDataCollection GetNLGEvents()
    {
        string nlgEventCategory = EventUtilities.GeneralNLGEvents;
        Taxon generalNLGCategoryTaxon = TaxonUtilities.GetCategoryByTitle(nlgEventCategory);
        List<Event> nlgEventItems = EventUtilities.GetEventByCategory(generalNLGCategoryTaxon.Id);
        return nlgEventItems
    }
     
    public static List<Event> GetEventByCategory(Guid categoryId)
    {
        var taxonomyMgr = TaxonomyManager.GetManager();
        var eventMgr = EventsManager.GetManager();
     
        // Get the Id of the category
        var taxonId = taxonomyMgr.GetTaxa<HierarchicalTaxon>()
                 .Where(t => t.Id == categoryId)
                 .SingleOrDefault()
                 .Id;
     
        // Get all event items that are assigned to this category
        var eventItemsInCategory = eventMgr.GetEvents().Where(p => p.Status == ContentLifecycleStatus.Live && p.GetValue<TrackedList<Guid>>("Category").Contains(taxonId));
        return eventItemsInCategory.ToList();
    }

    Thanks -- Steve
  2. Elena Ganeva
    Elena Ganeva avatar
    36 posts
    Registered:
    20 Jul 2016
    22 Nov 2013
    Link to this post

    Hello Steve,

    Thank you for sharing your code snippets. Due to our lifecycle we provide three different versions for the items- Master, Live and Temp. The live items are design to be visible on the frontend:

    http://www.sitefinity.com/documentation/documentationarticles/developers-guide/sitefinity-essentials/modules/content-lifecycle

    The items are always created in Master state and once you Publish them we create a Live version for them, similarly when you Unpublish them then you can access the item only through its Master version. Please notice that if you save as Draft any item then the Temp version of the item will be destroyed and the changes over the item will be copied to the Master version, so if you show on the frontend Master items you will display some items that are currently saved as Draft.

    Is there any particular reason to mark the events as Unpublished one week after the event pass? I could suggest you keep their status set to Publish and perform a filtering to get which of the events has been passed if somewhere on the frontend you need only upcoming events.

    Please let me know if this suits your scenario. 


    Regards,
    Elena Ganeva
    Telerik
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. SteveV
    SteveV avatar
    178 posts
    Registered:
    06 Nov 2011
    22 Nov 2013 in reply to Elena Ganeva
    Link to this post
    Hi Elena,

    Most of our events are fundraising in nature.  In many cases, we'll have info about other ways people can contribute if they are unable to attend.  We like to keep the event around for an additional week or so to allow stragglers to make donations or contributions.

    The facts that drafts show up in the Master state makes this unusable to our purposes.  I can imagine a poorly composed or perhaps inappropriate draft being made public.

    Any other ideas?

    Steve
  4. Bonny
    Bonny avatar
    58 posts
    Registered:
    11 Nov 2016
    25 Nov 2013
    Link to this post
    Hello,

    As I understand, you have a list, where you want to display unpublished events.
    At this point, you filter only published events (p.Status == ContentLifecycleStatus.Live). You can get the unpublished events with filter like - p.ApprovalWorkflowState == "Unpublished".
    Also, you can think about not unpublishing them at all if you want them to stay visible. You can filter the "active" events by date for example.

    Please tell me if some of this suggestions works for you, or you need further help in resolving your problem.

    Regards,
    Bonny
    Telerik
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
4 posts, 0 answered