예제 #1
0
        /// <summary>
        /// Sets the selected location.
        /// Note this will redirect to the current page to include a LocationId query parameter if a LocationId parameter in the URL is missing or doesn't match.
        /// </summary>
        /// <param name="rockBlock">The rock block.</param>
        /// <param name="lpLocation">The lp location.</param>
        /// <param name="locationId">The identifier of the location.</param>
        /// <param name="campusId">The campus identifier.</param>
        public static void SetSelectedLocation(RockBlock rockBlock, LocationPicker lpLocation, int?locationId, int campusId)
        {
            if (locationId.HasValue && locationId > 0)
            {
                CheckinManagerHelper.SaveCampusLocationConfigurationToCookie(campusId, locationId);
                var pageParameterLocationId = rockBlock.PageParameter(PageParameterKey.LocationId).AsIntegerOrNull();
                if (!pageParameterLocationId.HasValue || pageParameterLocationId.Value != locationId)
                {
                    var additionalQueryParameters = new Dictionary <string, string>();
                    additionalQueryParameters.Add(PageParameterKey.LocationId, locationId.ToString());
                    rockBlock.NavigateToCurrentPageReference(additionalQueryParameters);
                    return;
                }

                using (var rockContext = new RockContext())
                {
                    if (locationId.HasValue)
                    {
                        lpLocation.SetNamedLocation(NamedLocationCache.Get(locationId.Value));
                    }
                }
            }
            else
            {
                lpLocation.Location = null;
                CheckinManagerHelper.SaveCampusLocationConfigurationToCookie(campusId, null);
            }
        }
예제 #2
0
        /// <summary>
        /// Gets the selected location.
        /// </summary>
        /// <param name="rockBlock">The rock block.</param>
        /// <param name="campus">The campus.</param>
        /// <param name="lpLocation">The lp location.</param>
        /// <returns></returns>
        public static int?GetSelectedLocation(RockBlock rockBlock, CampusCache campus, LocationPicker lpLocation)
        {
            // If the Campus selection has changed, we need to reload the LocationItemPicker with the Locations specific to that Campus.
            lpLocation.NamedPickerRootLocationId = campus.LocationId.GetValueOrDefault();

            // Check the LocationPicker for the Location ID.
            int locationId = lpLocation.NamedLocation?.Id ?? 0;

            if (locationId > 0)
            {
                return(locationId);
            }

            // If not defined on the LocationPicker, check first for a LocationId Page parameter.
            locationId = rockBlock.PageParameter(PageParameterKey.LocationId).AsInteger();

            if (locationId > 0)
            {
                // double check the locationId in the URL is valid for the Campus (just in case it was altered or is no longer valid for the campus)
                var locationCampusId = NamedLocationCache.Get(locationId).CampusId;
                if (locationCampusId != campus.Id)
                {
                    locationId = 0;
                }
            }

            if (locationId > 0)
            {
                CheckinManagerHelper.SaveCampusLocationConfigurationToCookie(campus.Id, locationId);
            }
            else
            {
                // If still not defined, check for cookie setting.
                locationId = CheckinManagerHelper.GetCheckinManagerConfigurationFromCookie().LocationIdFromSelectedCampusId.GetValueOrNull(campus.Id) ?? 0;

                if (locationId > 0)
                {
                    // double check the locationId in the cookie is valid for the Campus (just in case it was altered or is no longer valid for the campus)
                    var locationCampusId = NamedLocationCache.Get(locationId)?.CampusId;
                    if (locationCampusId != campus.Id)
                    {
                        locationId = 0;
                    }
                }

                if (locationId <= 0)
                {
                    return(null);
                }
            }

            return(locationId);
        }
예제 #3
0
        /// <summary>
        /// Gets the checkin area filter that the (Checkin Manager) block uses.
        /// Determined by 'Area' PageParameter, 'ShowAllAreas' block setting, Cookie or 'CheckInAreaGuid' block setting
        /// </summary>
        /// <param name="rockBlock">The rock block.</param>
        /// <returns></returns>
        public static GroupTypeCache GetCheckinAreaFilter(RockBlock rockBlock)
        {
            // If a Check-in Area query string parameter is defined, it takes precedence.
            Guid?checkinManagerPageParameterCheckinAreaGuid = rockBlock.PageParameter(PageParameterKey.Area).AsGuidOrNull();

            if (checkinManagerPageParameterCheckinAreaGuid.HasValue)
            {
                var checkinManagerPageParameterCheckinArea = GroupTypeCache.Get(checkinManagerPageParameterCheckinAreaGuid.Value);

                if (checkinManagerPageParameterCheckinArea != null)
                {
                    return(checkinManagerPageParameterCheckinArea);
                }
            }

            // If ShowAllAreas is enabled, we won't filter by Check-in Area (unless there was a page parameter).
            if (rockBlock.GetAttributeValue(BlockAttributeKey.ShowAllAreas).AsBoolean())
            {
                return(null);
            }

            // If ShowAllAreas is false, get the area filter from the cookie.
            var checkinManagerCookieCheckinAreaGuid = CheckinManagerHelper.GetCheckinManagerConfigurationFromCookie().CheckinAreaGuid;

            if (checkinManagerCookieCheckinAreaGuid != null)
            {
                var checkinManagerCookieCheckinArea = GroupTypeCache.Get(checkinManagerCookieCheckinAreaGuid.Value);
                if (checkinManagerCookieCheckinArea != null)
                {
                    return(checkinManagerCookieCheckinArea);
                }
            }

            // Next, check the Block AttributeValue.
            var checkinManagerBlockAttributeCheckinAreaGuid = rockBlock.GetAttributeValue(BlockAttributeKey.CheckInAreaGuid).AsGuidOrNull();

            if (checkinManagerBlockAttributeCheckinAreaGuid.HasValue)
            {
                var checkinManagerBlockAttributeCheckinArea = GroupTypeCache.Get(checkinManagerBlockAttributeCheckinAreaGuid.Value);
                if (checkinManagerBlockAttributeCheckinArea != null)
                {
                    return(checkinManagerBlockAttributeCheckinArea);
                }
            }

            return(null);
        }