spGet_DataForEditAthleticEventURL

Parameters

Parameter Parameter Type Mode Description
@athletic_eventid int IN

Definition

Copy

            CREATE procedure [dbo].[spGet_DataForEditAthleticEventURL](@athletic_eventid int) as

            -- breaking this out into 2 parts to simplify the logic. Needs to handle calendars on site pages,

            -- and team personal pages, where multiple pages may exist for a team, or the underlying page 

            -- has been deleted. If no page exists for the calendar event, no row is returned.


                -- on a site page calendar?

                if exists(select ce.ID
                          from dbo.athletics_events ae
                              inner join dbo.calendarevent ce on ae.id = ce.athleticeventid
                              inner join dbo.eventcalendar ec on ec.id = ce.eventcalendarid
                              inner join dbo.PageContent pc on pc.sitecontentid = ec.sitecontentid
                              left join dbo.UserPageManagerPageTemplates upt on upt.SitePageID = pc.SitePagesID
                          where 
                            ae.id = @athletic_eventid 
                            and upt.ID is null)

                    select ae.teamid, ce.id calendareventid, ce.eventcalendarid, pc.sitepagesid, null 
                      from dbo.athletics_events ae
                          inner join dbo.calendarevent ce on ae.id = ce.athleticeventid
                          inner join dbo.eventcalendar ec on ec.id = ce.eventcalendarid
                          inner join dbo.PageContent pc on pc.sitecontentid = ec.sitecontentid
                          left join dbo.UserPageManagerPageTemplates upt on upt.SitePageID = pc.SitePagesID
                      where 
                        ae.id = @athletic_eventid 
                        and upt.ID is null      -- must be site page


                else

                    -- this is on a team personal page calendar

                    select ae.teamid, ce.id calendareventid, ce.eventcalendarid, pc.sitepagesid, up.id userpageid
                    from dbo.athletics_events ae
                      inner join dbo.calendarevent ce on ae.id = ce.athleticeventid
                      inner join dbo.eventcalendar ec on ec.id = ce.eventcalendarid
                      inner join dbo.PageContent pc on pc.sitecontentid = ec.sitecontentid
                      inner join dbo.UserPages up on up.RealmContextId = ae.teamid
                      inner join dbo.UserPageManagerPageTemplates upt on upt.ID = up.UserPageTemplateId
                      inner join dbo.PersonalizedContentData pcd on  pcd.UserPageID = up.ID 
                    where 
                    ae.id = @athletic_eventid 
                    and (upt.RealmType = 7       -- only team pages

                            -- multiple personal pages may exist for team; need userpageid for page containing EventCalendar for this Event

                            and convert(xml, pcd.XMLData).value('/TeamCalendarPersonalContent[1]/EventCalendarID[1]', 'int') = ce.EventCalendarID)