Ejemplo n.º 1
0
        /// <summary>
        /// Shows the readonly details.
        /// </summary>
        /// <param name="page">The page.</param>
        private void ShowReadonlyDetails(Rock.Model.Page page)
        {
            SetEditMode(false);

            pdAuditDetails.Visible = true;
            pdAuditDetails.SetEntity(page, ResolveRockUrl("~"));

            string pageIconHtml = !string.IsNullOrWhiteSpace(page.IconCssClass) ?
                                  pageIconHtml = string.Format("<i class='{0} fa-2x' ></i>", page.IconCssClass) : string.Empty;

            lTitle.Text = page.InternalName.FormatAsHtmlTitle();
            if (!string.IsNullOrEmpty(page.IconCssClass))
            {
                lIcon.Text = string.Format("<i class='{0}'></i>", page.IconCssClass);
            }
            else
            {
                lIcon.Text = "<i class='fa fa-file-text-o'></i>";
            }

            var site = SiteCache.Get(page.Layout.SiteId);

            hlblSiteName.Text = "Site: " + site.Name;

            lblMainDetailsCol1.Text = new DescriptionList()
                                      .Add("Internal Name", page.InternalName)
                                      .Add("Page Title", page.PageTitle)
                                      .Add("Browser Title", page.BrowserTitle)
                                      .Add("Description", page.Description)
                                      .Html;

            var pageReference = new PageReference(page.Id);
            var pageUrl       = pageReference.BuildUrl();
            var pageLink      = string.Format("<a href='{0}'>{0}</a>", pageUrl);

            lblMainDetailsCol2.Text = new DescriptionList()
                                      .Add("Layout", page.Layout)
                                      .Add("URL", pageLink)
                                      .Html;

            RenderMedianPageLoadTime(page);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Builds and returns the URL for a linked <see cref="Rock.Model.Page" /> from a "linked page attribute" and any necessary query parameters.
        /// </summary>
        /// <param name="attributeKey">A <see cref="System.String" /> representing the name of the linked <see cref="Rock.Model.Page" /> attribute key.</param>
        /// <param name="queryParams">A <see cref="System.Collections.Generic.Dictionary{String,String}" /> containing the query string parameters to be added to the URL.
        /// In each <see cref="System.Collections.Generic.KeyValuePair{String,String}" /> the key value is a <see cref="System.String" /> that represents the name of the query string
        /// parameter, and the value is a <see cref="System.String" /> that represents the query string value..</param>
        /// <returns>
        /// A <see cref="System.String" /> representing the URL to the linked <see cref="Rock.Model.Page" />.
        /// </returns>
        public override string LinkedPageUrl(string attributeKey, Dictionary <string, string> queryParams = null)
        {
            var pageReference = new PageReference(GetAttributeValue(attributeKey), queryParams);

            if (pageReference.PageId > 0)
            {
                var page = PageCache.Get(pageReference.PageId);
                if (page != null && page.PageTitle == "Welcome")
                {
                    if (pageReference.Parameters == null)
                    {
                        pageReference.Parameters = new Dictionary <string, string>();
                    }

                    pageReference.Parameters.AddOrIgnore("IsActive", "True");
                }
                return(pageReference.BuildUrl());
            }
            else
            {
                return(string.Empty);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Updates the list.
        /// </summary>
        private void UpdateList()
        {
            using (var rockContext = new RockContext())
            {
                var searchSelections = new Dictionary <string, string>();

                var connectionTypeId             = GetAttributeValue("ConnectionTypeId").AsInteger();
                var connectionType               = new ConnectionTypeService(rockContext).Get(connectionTypeId);
                var connectionOpportunityService = new ConnectionOpportunityService(rockContext);

                var qrySearch = connectionOpportunityService.Queryable().Where(a => a.ConnectionTypeId == connectionTypeId && a.IsActive == true).ToList();

                if (GetAttributeValue("DisplayNameFilter").AsBoolean())
                {
                    if (!string.IsNullOrWhiteSpace(tbSearchName.Text))
                    {
                        searchSelections.Add("tbSearchName", tbSearchName.Text);
                        var searchTerms = tbSearchName.Text.ToLower().SplitDelimitedValues(true);
                        qrySearch = qrySearch.Where(o => searchTerms.Any(t => t.Contains(o.Name.ToLower()) || o.Name.ToLower().Contains(t))).ToList();
                    }
                }

                if (GetAttributeValue("DisplayCampusFilter").AsBoolean())
                {
                    var searchCampuses = cblCampus.SelectedValuesAsInt;
                    if (searchCampuses.Count > 0)
                    {
                        searchSelections.Add("cblCampus", searchCampuses.AsDelimited("|"));
                        qrySearch = qrySearch.Where(o => o.ConnectionOpportunityCampuses.Any(c => searchCampuses.Contains(c.CampusId))).ToList();
                    }
                }

                if (GetAttributeValue("DisplayAttributeFilters").AsBoolean())
                {
                    // Filter query by any configured attribute filters
                    if (AvailableAttributes != null && AvailableAttributes.Any())
                    {
                        var attributeValueService = new AttributeValueService(rockContext);
                        var parameterExpression   = attributeValueService.ParameterExpression;

                        foreach (var attribute in AvailableAttributes)
                        {
                            string filterControlId = "filter_" + attribute.Id.ToString();
                            var    filterControl   = phAttributeFilters.FindControl(filterControlId);
                            if (filterControl != null)
                            {
                                var filterValues = attribute.FieldType.Field.GetFilterValues(filterControl, attribute.QualifierValues, Rock.Reporting.FilterMode.SimpleFilter);
                                var expression   = attribute.FieldType.Field.AttributeFilterExpression(attribute.QualifierValues, filterValues, parameterExpression);
                                if (expression != null)
                                {
                                    searchSelections.Add(filterControlId, filterValues.ToJson());
                                    var attributeValues = attributeValueService
                                                          .Queryable()
                                                          .Where(v => v.Attribute.Id == attribute.Id);

                                    attributeValues = attributeValues.Where(parameterExpression, expression, null);

                                    qrySearch = qrySearch.Where(o => attributeValues.Select(v => v.EntityId).Contains(o.Id)).ToList();
                                }
                            }
                        }
                    }
                }

                string sessionKey = string.Format("ConnectionSearch_{0}", this.BlockId);
                Session[sessionKey] = searchSelections;

                var opportunities = qrySearch.OrderBy(s => s.PublicName).ToList();

                var mergeFields = new Dictionary <string, object>();
                mergeFields.Add("CurrentPerson", CurrentPerson);
                mergeFields.Add("CampusContext", RockPage.GetCurrentContext(EntityTypeCache.Read("Rock.Model.Campus")) as Campus);
                var pageReference = new PageReference(GetAttributeValue("DetailPage"), null);
                mergeFields.Add("DetailPage", BuildDetailPageUrl(pageReference.BuildUrl()));

                // iterate through the opportunities and lava merge the summaries and descriptions
                foreach (var opportunity in opportunities)
                {
                    opportunity.Summary     = opportunity.Summary.ResolveMergeFields(mergeFields);
                    opportunity.Description = opportunity.Description.ResolveMergeFields(mergeFields);
                }

                mergeFields.Add("Opportunities", opportunities);

                lOutput.Text = GetAttributeValue("LavaTemplate").ResolveMergeFields(mergeFields);

                if (GetAttributeValue("SetPageTitle").AsBoolean())
                {
                    string pageTitle = "Connection";
                    RockPage.PageTitle    = pageTitle;
                    RockPage.BrowserTitle = String.Format("{0} | {1}", pageTitle, RockPage.Site.Name);
                    RockPage.Header.Title = String.Format("{0} | {1}", pageTitle, RockPage.Site.Name);
                }
            }
        }
Ejemplo n.º 4
0
        private void Map()
        {
            string mapStylingFormat = @"
                        <style>
                            #map_wrapper {{
                                height: {0}px;
                            }}

                            #map_canvas {{
                                width: 100%;
                                height: 100%;
                                border-radius: var(--border-radius-base);
                            }}
                        </style>";

            lMapStyling.Text = string.Format(mapStylingFormat, GetAttributeValue("MapHeight"));

            string settingGroupTypeId     = GetAttributeValue("GroupType");
            string queryStringGroupTypeId = PageParameter("GroupTypeId");

            if ((string.IsNullOrWhiteSpace(settingGroupTypeId) && string.IsNullOrWhiteSpace(queryStringGroupTypeId)))
            {
                pnlMap.Visible = false;
                lMessages.Text = "<div class='alert alert-warning'><strong>Group Mapper</strong> Please configure a group type to display as a block setting or pass a GroupTypeId as a query parameter.</div>";
            }
            else
            {
                var rockContext = new RockContext();

                pnlMap.Visible = true;

                int groupsMapped    = 0;
                int groupsWithNoGeo = 0;

                StringBuilder sbGroupJson       = new StringBuilder();
                StringBuilder sbGroupsWithNoGeo = new StringBuilder();

                Guid?groupType   = null;
                int  groupTypeId = -1;

                if (!string.IsNullOrWhiteSpace(settingGroupTypeId))
                {
                    groupType = new Guid(settingGroupTypeId);
                }
                else
                {
                    if (!string.IsNullOrWhiteSpace(queryStringGroupTypeId) && Int32.TryParse(queryStringGroupTypeId, out groupTypeId))
                    {
                        groupType = new GroupTypeService(rockContext).Get(groupTypeId).Guid;
                    }
                }

                if (groupType != null)
                {
                    Template      template     = null;
                    ILavaTemplate lavaTemplate = null;

                    if (LavaService.RockLiquidIsEnabled)
                    {
                        if (GetAttributeValue("ShowMapInfoWindow").AsBoolean())
                        {
                            template = Template.Parse(GetAttributeValue("InfoWindowContents").Trim());

                            LavaHelper.VerifyParseTemplateForCurrentEngine(GetAttributeValue("InfoWindowContents").Trim());
                        }
                        else
                        {
                            template = Template.Parse(string.Empty);
                        }
                    }
                    else
                    {
                        string templateContent;

                        if (GetAttributeValue("ShowMapInfoWindow").AsBoolean())
                        {
                            templateContent = GetAttributeValue("InfoWindowContents").Trim();
                        }
                        else
                        {
                            templateContent = string.Empty;
                        }

                        var parseResult = LavaService.ParseTemplate(templateContent);

                        lavaTemplate = parseResult.Template;
                    }

                    var groupPageRef = new PageReference(GetAttributeValue("GroupDetailPage"));

                    // create group detail link for use in map's info window
                    var personPageParams = new Dictionary <string, string>();
                    personPageParams.Add("PersonId", string.Empty);
                    var personProfilePage = LinkedPageUrl("PersonProfilePage", personPageParams);

                    var groupEntityType = EntityTypeCache.Get(typeof(Group));
                    var dynamicGroups   = new List <dynamic>();


                    // Create query to get attribute values for selected attribute keys.
                    var attributeKeys   = GetAttributeValue("Attributes").SplitDelimitedValues().ToList();
                    var attributeValues = new AttributeValueService(rockContext).Queryable("Attribute")
                                          .Where(v =>
                                                 v.Attribute.EntityTypeId == groupEntityType.Id &&
                                                 attributeKeys.Contains(v.Attribute.Key));

                    GroupService groupService = new GroupService(rockContext);
                    var          groups       = groupService.Queryable()
                                                .Where(g => g.GroupType.Guid == groupType)
                                                .Select(g => new
                    {
                        Group           = g,
                        GroupId         = g.Id,
                        GroupName       = g.Name,
                        GroupGuid       = g.Guid,
                        GroupMemberTerm = g.GroupType.GroupMemberTerm,
                        GroupCampus     = g.Campus.Name,
                        IsActive        = g.IsActive,
                        GroupLocation   = g.GroupLocations
                                          .Where(l => l.Location.GeoPoint != null)
                                          .Select(l => new
                        {
                            l.Location.Street1,
                            l.Location.Street2,
                            l.Location.City,
                            l.Location.State,
                            PostalCode = l.Location.PostalCode,
                            Latitude   = l.Location.GeoPoint.Latitude,
                            Longitude  = l.Location.GeoPoint.Longitude,
                            Name       = l.GroupLocationTypeValue.Value
                        }).FirstOrDefault(),
                        GroupMembers    = g.Members,
                        AttributeValues = attributeValues
                                          .Where(v => v.EntityId == g.Id)
                    });


                    if (GetAttributeValue("IncludeInactiveGroups").AsBoolean() == false)
                    {
                        groups = groups.Where(g => g.IsActive == true);
                    }

                    // Create dynamic object to include attribute values
                    foreach (var group in groups)
                    {
                        dynamic dynGroup = new ExpandoObject();
                        dynGroup.GroupId   = group.GroupId;
                        dynGroup.GroupName = group.GroupName;

                        // create group detail link for use in map's info window
                        if (groupPageRef.PageId > 0)
                        {
                            var groupPageParams = new Dictionary <string, string>();
                            groupPageParams.Add("GroupId", group.GroupId.ToString());
                            groupPageRef.Parameters  = groupPageParams;
                            dynGroup.GroupDetailPage = groupPageRef.BuildUrl();
                        }
                        else
                        {
                            dynGroup.GroupDetailPage = string.Empty;
                        }

                        dynGroup.PersonProfilePage = personProfilePage;
                        dynGroup.GroupMemberTerm   = group.GroupMemberTerm;
                        dynGroup.GroupCampus       = group.GroupCampus;
                        dynGroup.GroupLocation     = group.GroupLocation;

                        var groupAttributes = new List <dynamic>();
                        foreach (AttributeValue value in group.AttributeValues)
                        {
                            var attrCache     = AttributeCache.Get(value.AttributeId);
                            var dictAttribute = new Dictionary <string, object>();
                            dictAttribute.Add("Key", attrCache.Key);
                            dictAttribute.Add("Name", attrCache.Name);

                            if (attrCache != null)
                            {
                                dictAttribute.Add("Value", attrCache.FieldType.Field.FormatValueAsHtml(null, attrCache.EntityTypeId, group.GroupId, value.Value, attrCache.QualifierValues, false));
                            }
                            else
                            {
                                dictAttribute.Add("Value", value.Value);
                            }

                            groupAttributes.Add(dictAttribute);
                        }

                        dynGroup.Attributes = groupAttributes;

                        var groupMembers = new List <dynamic>();
                        foreach (GroupMember member in group.GroupMembers)
                        {
                            var dictMember = new Dictionary <string, object>();
                            dictMember.Add("Id", member.Person.Id);
                            dictMember.Add("GuidP", member.Person.Guid);
                            dictMember.Add("NickName", member.Person.NickName);
                            dictMember.Add("LastName", member.Person.LastName);
                            dictMember.Add("RoleName", member.GroupRole.Name);
                            dictMember.Add("Email", member.Person.Email);
                            dictMember.Add("PhotoGuid", member.Person.Photo != null ? member.Person.Photo.Guid : Guid.Empty);

                            var phoneTypes = new List <dynamic>();
                            foreach (PhoneNumber p in member.Person.PhoneNumbers)
                            {
                                var dictPhoneNumber = new Dictionary <string, object>();
                                dictPhoneNumber.Add("Name", p.NumberTypeValue.Value);
                                dictPhoneNumber.Add("Number", p.ToString());
                                phoneTypes.Add(dictPhoneNumber);
                            }

                            dictMember.Add("PhoneTypes", phoneTypes);

                            groupMembers.Add(dictMember);
                        }

                        dynGroup.GroupMembers = groupMembers;

                        dynamicGroups.Add(dynGroup);
                    }

                    foreach (var group in dynamicGroups)
                    {
                        if (group.GroupLocation != null && group.GroupLocation.Latitude != null)
                        {
                            groupsMapped++;
                            var groupDict = group as IDictionary <string, object>;

                            string infoWindow;

                            if (LavaService.RockLiquidIsEnabled)
                            {
                                infoWindow = template.Render(Hash.FromDictionary(groupDict)).Replace("\n", string.Empty);
                            }
                            else
                            {
                                var result = LavaService.RenderTemplate(lavaTemplate, groupDict);

                                infoWindow = result.Text;

                                if (!result.HasErrors)
                                {
                                    infoWindow = infoWindow.Replace("\n", string.Empty);
                                }
                            }

                            sbGroupJson.Append(string.Format(
                                                   @"{{ ""name"":""{0}"" , ""latitude"":""{1}"", ""longitude"":""{2}"", ""infowindow"":""{3}"" }},",
                                                   HttpUtility.HtmlEncode(group.GroupName),
                                                   group.GroupLocation.Latitude,
                                                   group.GroupLocation.Longitude,
                                                   HttpUtility.HtmlEncode(infoWindow)));
                        }
                        else
                        {
                            groupsWithNoGeo++;

                            if (!string.IsNullOrWhiteSpace(group.GroupDetailPage))
                            {
                                sbGroupsWithNoGeo.Append(string.Format(@"<li><a href='{0}'>{1}</a></li>", group.GroupDetailPage, group.GroupName));
                            }
                            else
                            {
                                sbGroupsWithNoGeo.Append(string.Format(@"<li>{0}</li>", group.GroupName));
                            }
                        }
                    }

                    string groupJson = sbGroupJson.ToString();

                    // remove last comma
                    if (groupJson.Length > 0)
                    {
                        groupJson = groupJson.Substring(0, groupJson.Length - 1);
                    }

                    // add styling to map
                    string styleCode   = "null";
                    string markerColor = "FE7569";

                    DefinedValueCache dvcMapStyle = DefinedValueCache.Get(GetAttributeValue("MapStyle").AsGuid());
                    if (dvcMapStyle != null)
                    {
                        styleCode = dvcMapStyle.GetAttributeValue("DynamicMapStyle");
                        var colors = dvcMapStyle.GetAttributeValue("Colors").Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                        if (colors.Any())
                        {
                            markerColor = colors.First().Replace("#", "");
                        }
                    }

                    // write script to page
                    string mapScriptFormat = @" <script>
                                                Sys.Application.add_load(function () {{
                                                    var groupData = JSON.parse('{{ ""groups"" : [ {0} ]}}');
                                                    var showInfoWindow = {1};
                                                    var mapStyle = {2};
                                                    var pinColor = '{3}';

                                                    var pinImage = {{
                                                        path: 'M 0,0 C -2,-20 -10,-22 -10,-30 A 10,10 0 1,1 10,-30 C 10,-22 2,-20 0,0 z',
                                                        fillColor: '#' + pinColor,
                                                        fillOpacity: 1,
                                                        strokeColor: '#000',
                                                        strokeWeight: 1,
                                                        scale: 1,
                                                        labelOrigin: new google.maps.Point(0,-28)
                                                    }};

                                                    initializeMap();

                                                    function initializeMap() {{
                                                        console.log(mapStyle);
                                                        var map;
                                                        var bounds = new google.maps.LatLngBounds();
                                                        var mapOptions = {{
                                                            mapTypeId: 'roadmap',
                                                            styles: mapStyle
                                                        }};

                                                        // Display a map on the page
                                                        map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
                                                        map.setTilt(45);

                                                        // Display multiple markers on a map
                                                        if (showInfoWindow) {{
                                                            var infoWindow = new google.maps.InfoWindow(), marker, i;
                                                        }}

                                                        // Loop through our array of markers & place each one on the map
                                                        $.each(groupData.groups, function (i, group) {{

                                                            var position = new google.maps.LatLng(group.latitude, group.longitude);
                                                            bounds.extend(position);

                                                            marker = new google.maps.Marker({{
                                                                position: position,
                                                                map: map,
                                                                title: htmlDecode(group.name),
                                                                icon: pinImage,
                                                                label: String.fromCharCode(9679)
                                                            }});

                                                            // Allow each marker to have an info window
                                                            if (showInfoWindow) {{
                                                                google.maps.event.addListener(marker, 'click', (function (marker, i) {{
                                                                    return function () {{
                                                                        infoWindow.setContent(htmlDecode(groupData.groups[i].infowindow));
                                                                        infoWindow.open(map, marker);
                                                                    }}
                                                                }})(marker, i));
                                                            }}

                                                            map.fitBounds(bounds);

                                                        }});

                                                        // Override our map zoom level once our fitBounds function runs (Make sure it only runs once)
                                                        var boundsListener = google.maps.event.addListener((map), 'bounds_changed', function (event) {{
                                                            google.maps.event.removeListener(boundsListener);
                                                        }});
                                                    }}

                                                    function htmlDecode(input) {{
                                                        var e = document.createElement('div');
                                                        e.innerHTML = input;
                                                        return e.childNodes.length === 0 ? """" : e.childNodes[0].nodeValue;
                                                    }}
                                                }});
                                            </script>";

                    string mapScript = string.Format(
                        mapScriptFormat,
                        groupJson,
                        GetAttributeValue("ShowMapInfoWindow").AsBoolean().ToString().ToLower(),
                        styleCode,
                        markerColor);

                    ScriptManager.RegisterStartupScript(pnlMap, pnlMap.GetType(), "group-mapper-script", mapScript, false);

                    if (groupsMapped == 0)
                    {
                        pnlMap.Visible = false;
                        lMessages.Text = @" <p>
                                                <div class='alert alert-warning fade in'>No groups were able to be mapped. You may want to check your configuration.</div>
                                        </p>";
                    }
                    else
                    {
                        // output any warnings
                        if (groupsWithNoGeo > 0)
                        {
                            string messagesFormat = @" <p>
                                                <div class='alert alert-warning fade in'>Some groups could not be mapped.
                                                    <button type='button' class='close' data-dismiss='alert' aria-hidden='true'><i class='fa fa-times'></i></button>
                                                    <small><a data-toggle='collapse' data-parent='#accordion' href='#map-error-details'>Show Details</a></small>
                                                    <div id='map-error-details' class='collapse'>
                                                        <p class='margin-t-sm'>
                                                            <strong>Groups That Could Not Be Mapped</strong>
                                                            <ul>
                                                                {0}
                                                            </ul>
                                                        </p>
                                                    </div>
                                                </div>
                                            </p>";
                            lMessages.Text = string.Format(messagesFormat, sbGroupsWithNoGeo.ToString());
                        }
                    }
                }
                else
                {
                    pnlMap.Visible = false;
                    lMessages.Text = "<div class='alert alert-warning'><strong>Group Mapper</strong> Please configure a group type to display and a location type to use.</div>";
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Updates the list.
        /// </summary>
        private void UpdateList()
        {
            using (var rockContext = new RockContext())
            {
                var searchSelections = new Dictionary <string, string>();

                var connectionTypeId             = GetAttributeValue("ConnectionTypeId").AsInteger();
                var connectionType               = new ConnectionTypeService(rockContext).Get(connectionTypeId);
                var connectionOpportunityService = new ConnectionOpportunityService(rockContext);

                var qrySearch = connectionOpportunityService.Queryable().Where(a => a.ConnectionTypeId == connectionTypeId && a.IsActive == true).ToList();

                if (GetAttributeValue("EnableCampusContext").AsBoolean() && !GetAttributeValue("DisplayCampusFilter").AsBoolean())
                {
                    var campusEntityType = EntityTypeCache.Get("Rock.Model.Campus");
                    var contextCampus    = RockPage.GetCurrentContext(campusEntityType) as Campus;

                    if (contextCampus != null)
                    {
                        var campusId = contextCampus.Id;
                        qrySearch = qrySearch.Where(o => o.ConnectionOpportunityCampuses.Any(c => c.CampusId.Equals(campusId))).ToList();
                    }
                }

                if (AttributeOne != null)
                {
                    var control = phAttributeOne.Controls[0] as DropDownList;
                    if (control != null)
                    {
                        searchSelections.Add("ddlAttributeOne", control.SelectedValue);

                        var attributeValueService = new AttributeValueService(rockContext);
                        var parameterExpression   = attributeValueService.ParameterExpression;

                        var value = AttributeOne.FieldType.Field.GetEditValue(control, AttributeOne.QualifierValues);
                        if (!string.IsNullOrWhiteSpace(value))
                        {
                            var attributeValues = attributeValueService
                                                  .Queryable()
                                                  .Where(v => v.Attribute.Id == AttributeOne.Id)
                                                  .Where(v => v.Value.Equals(value));
                            qrySearch = qrySearch.Where(o => attributeValues.Select(v => v.EntityId).Contains(o.Id)).ToList();
                        }
                    }
                    else
                    {
                        var newDdlOne = phAttributeOne.Controls[2] as DropDownList;

                        searchSelections.Add("ddlAttributeOne", newDdlOne.SelectedValue);

                        var attributeValueService = new AttributeValueService(rockContext);
                        var parameterExpression   = attributeValueService.ParameterExpression;

                        var value = newDdlOne.SelectedValue;
                        if (!string.IsNullOrWhiteSpace(value))
                        {
                            var attributeValues = attributeValueService
                                                  .Queryable()
                                                  .Where(v => v.Attribute.Id == AttributeOne.Id)
                                                  .Where(v => v.Value.Contains(value));
                            qrySearch = qrySearch.Where(o => attributeValues.Select(v => v.EntityId).Contains(o.Id)).ToList();
                        }
                    }
                }

                if (AttributeTwo != null)
                {
                    var control = phAttributeTwo.Controls[0] as DropDownList;
                    if (control != null)
                    {
                        searchSelections.Add("ddlAttributeTwo", control.SelectedValue);

                        var attributeValueService = new AttributeValueService(rockContext);
                        var parameterExpression   = attributeValueService.ParameterExpression;

                        var value = AttributeTwo.FieldType.Field.GetEditValue(control, AttributeTwo.QualifierValues);
                        if (!string.IsNullOrWhiteSpace(value))
                        {
                            var attributeValues = attributeValueService
                                                  .Queryable()
                                                  .Where(v => v.Attribute.Id == AttributeTwo.Id)
                                                  .Where(v => v.Value.Equals(value));
                            qrySearch = qrySearch.Where(o => attributeValues.Select(v => v.EntityId).Contains(o.Id)).ToList();
                        }
                    }
                    else
                    {
                        var newDdlTwo = phAttributeTwo.Controls[2] as DropDownList;

                        searchSelections.Add("ddlAttributeTwo", newDdlTwo.SelectedValue);

                        var attributeValueService = new AttributeValueService(rockContext);
                        var parameterExpression   = attributeValueService.ParameterExpression;

                        var value = newDdlTwo.SelectedValue;
                        if (!string.IsNullOrWhiteSpace(value))
                        {
                            var attributeValues = attributeValueService
                                                  .Queryable()
                                                  .Where(v => v.Attribute.Id == AttributeTwo.Id)
                                                  .Where(v => v.Value.Contains(value));
                            qrySearch = qrySearch.Where(o => attributeValues.Select(v => v.EntityId).Contains(o.Id)).ToList();
                        }
                    }
                }

                string sessionKey = string.Format("ConnectionSearch_{0}", this.BlockId);
                Session[sessionKey] = searchSelections;

                var opportunities = qrySearch.OrderBy(s => s.PublicName).ToList();

                var mergeFields = new Dictionary <string, object>();
                mergeFields.Add("CurrentPerson", CurrentPerson);
                mergeFields.Add("CampusContext", RockPage.GetCurrentContext(EntityTypeCache.Get("Rock.Model.Campus")) as Campus);
                var pageReference = new PageReference(GetAttributeValue("DetailPage"), null);
                mergeFields.Add("DetailPage", BuildDetailPageUrl(pageReference.BuildUrl()));

                // iterate through the opportunities and lava merge the summaries and descriptions
                foreach (var opportunity in opportunities)
                {
                    opportunity.Summary     = opportunity.Summary.ResolveMergeFields(mergeFields);
                    opportunity.Description = opportunity.Description.ResolveMergeFields(mergeFields);
                }

                mergeFields.Add("Opportunities", opportunities);

                lOutput.Text = GetAttributeValue("LavaTemplate").ResolveMergeFields(mergeFields);

                if (GetAttributeValue("SetPageTitle").AsBoolean())
                {
                    string pageTitle = "Connection";
                    RockPage.PageTitle    = pageTitle;
                    RockPage.BrowserTitle = String.Format("{0} | {1}", pageTitle, RockPage.Site.Name);
                    RockPage.Header.Title = String.Format("{0} | {1}", pageTitle, RockPage.Site.Name);
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Updates the list.
        /// </summary>
        private void UpdateList()
        {
            using (var rockContext = new RockContext())
            {
                var searchSelections = new Dictionary <string, string>();

                var connectionTypeId             = GetAttributeValue(AttributeKey.ConnectionTypeId).AsInteger();
                var connectionType               = new ConnectionTypeService(rockContext).Get(connectionTypeId);
                var connectionOpportunityService = new ConnectionOpportunityService(rockContext);

                var qrySearch = connectionOpportunityService.Queryable().Where(a => a.ConnectionTypeId == connectionTypeId && a.IsActive && a.ConnectionType.IsActive);

                if (GetAttributeValue(AttributeKey.DisplayNameFilter).AsBoolean())
                {
                    if (!string.IsNullOrWhiteSpace(tbSearchName.Text))
                    {
                        searchSelections.Add("tbSearchName", tbSearchName.Text);
                        var searchTerms = tbSearchName.Text.ToLower().SplitDelimitedValues(true);
                        qrySearch = qrySearch.Where(o => searchTerms.Any(t => t.Contains(o.Name.ToLower()) || o.Name.ToLower().Contains(t)));
                    }
                }

                if (GetAttributeValue(AttributeKey.DisplayCampusFilter).AsBoolean())
                {
                    cblCampus.Label = GetAttributeValue(AttributeKey.CampusLabel);
                    var searchCampuses = cblCampus.SelectedValuesAsInt;
                    if (searchCampuses.Count > 0)
                    {
                        searchSelections.Add("cblCampus", searchCampuses.AsDelimited("|"));
                        qrySearch = qrySearch.Where(o => o.ConnectionOpportunityCampuses.Any(c => searchCampuses.Contains(c.CampusId)));
                    }
                }

                if (GetAttributeValue(AttributeKey.DisplayAttributeFilters).AsBoolean())
                {
                    // Filter query by any configured attribute filters
                    if (AvailableAttributes != null && AvailableAttributes.Any())
                    {
                        foreach (var attribute in AvailableAttributes)
                        {
                            string filterControlId = "filter_" + attribute.Id.ToString();
                            var    filterControl   = phAttributeFilters.FindControl(filterControlId);
                            qrySearch = attribute.FieldType.Field.ApplyAttributeQueryFilter(qrySearch, filterControl, attribute, connectionOpportunityService, Rock.Reporting.FilterMode.SimpleFilter);
                        }
                    }
                }

                string sessionKey = string.Format("ConnectionSearch_{0}", this.BlockId);
                Session[sessionKey] = searchSelections;

                var opportunities = qrySearch
                                    .ToList()
                                    .Where(o => o.IsAuthorized(Authorization.VIEW, CurrentPerson))
                                    .OrderBy(o => o.Order)
                                    .ThenBy(o => o.Name)
                                    .ToList();

                var mergeFields = new Dictionary <string, object>();
                mergeFields.Add("CurrentPerson", CurrentPerson);
                mergeFields.Add("CampusContext", RockPage.GetCurrentContext(EntityTypeCache.Get("Rock.Model.Campus")) as Campus);
                var pageReference = new PageReference(GetAttributeValue(AttributeKey.DetailPage), null);
                // Not using the BuildUrlEncoded due to the additional method here that handles the encoding
                mergeFields.Add("DetailPage", BuildDetailPageUrl(pageReference.BuildUrl()));

                // iterate through the opportunities and lava merge the summaries and descriptions
                foreach (var opportunity in opportunities)
                {
                    opportunity.Summary     = opportunity.Summary.ResolveMergeFields(mergeFields);
                    opportunity.Description = opportunity.Description.ResolveMergeFields(mergeFields);
                }

                mergeFields.Add("Opportunities", opportunities);

                lOutput.Text = GetAttributeValue(AttributeKey.LavaTemplate).ResolveMergeFields(mergeFields);

                if (GetAttributeValue(AttributeKey.SetPageTitle).AsBoolean())
                {
                    string pageTitle = "Connection";
                    RockPage.PageTitle    = pageTitle;
                    RockPage.BrowserTitle = string.Format("{0} | {1}", pageTitle, RockPage.Site.Name);
                    RockPage.Header.Title = string.Format("{0} | {1}", pageTitle, RockPage.Site.Name);
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Builds the URL.
        /// </summary>
        /// <returns></returns>
        private string BuildUrl(int pageOffset = 0, Boolean respectSmartSearch = true) // respect smart search flag allows a search that started as a smart search to be converted to a normal search via refining the search
        {
            var pageReference = new PageReference();

            pageReference.PageId  = CurrentPageReference.PageId;
            pageReference.RouteId = CurrentPageReference.RouteId;

            if (!string.IsNullOrWhiteSpace(tbSearch.Text))
            {
                pageReference.Parameters.AddOrReplace("Q", tbSearch.Text);
            }

            if (PageParameter("SmartSearch").IsNotNullOrWhiteSpace() && respectSmartSearch)
            {
                pageReference.Parameters.AddOrReplace("SmartSearch", "true");
            }

            if (cblModelFilter.SelectedValues.Count > 0)
            {
                pageReference.Parameters.AddOrReplace("Models", string.Join(",", cblModelFilter.SelectedValues));
            }

            // add dynamic filters
            var selectedEntities = cblModelFilter.SelectedValuesAsInt;

            // if no entities from the UI get from the block config
            if (selectedEntities.Count == 0 && GetAttributeValue("EnabledModels").IsNotNullOrWhiteSpace())
            {
                selectedEntities = GetAttributeValue("EnabledModels").Split(',').Select(int.Parse).ToList();
            }

            if (selectedEntities.Count > 0)
            {
                foreach (var control in phFilters.Controls)
                {
                    if (control is HtmlGenericContainer)
                    {
                        var htmlContainer = (HtmlGenericContainer)control;
                        var childControls = htmlContainer.Controls;

                        foreach (var childControl in childControls)
                        {
                            if (childControl is RockCheckBoxList)
                            {
                                var filterControl = (RockCheckBoxList)childControl;
                                var entityId      = filterControl.Attributes["entity-id"].AsInteger();
                                var fieldName     = filterControl.Attributes["entity-filter-field"];

                                if (selectedEntities.Contains(entityId))
                                {
                                    pageReference.Parameters.AddOrReplace(fieldName, string.Join(",", filterControl.SelectedValues));
                                }
                            }
                        }
                    }
                }
            }

            if (_currentPageNum != 0 || pageOffset != 0)
            {
                pageReference.Parameters.AddOrReplace("CurrentPage", ((_currentPageNum + 1) + pageOffset).ToString());
            }

            if (!string.IsNullOrWhiteSpace(PageParameter("SearchType")))
            {
                pageReference.Parameters.AddOrReplace("SearchType", PageParameter("SearchType"));
            }

            if (pnlRefineSearch.Visible)
            {
                pageReference.Parameters.AddOrReplace("RefinedSearch", "True");
            }

            return(pageReference.BuildUrl());
        }
Ejemplo n.º 8
0
        private SetExpressCheckoutRequestType populateRequestObject(FinancialGateway financialGateway, PaymentInfo paymentInfo, List <GatewayAccountItem> selectedAccounts)
        {
            SetExpressCheckoutRequestType        request   = new SetExpressCheckoutRequestType();
            SetExpressCheckoutRequestDetailsType ecDetails = new SetExpressCheckoutRequestDetailsType();
            String host      = GlobalAttributesCache.Value("PublicApplicationRoot");
            int    lastSlash = host.LastIndexOf('/');

            host = (lastSlash > -1) ? host.Substring(0, lastSlash) : host;
            if (financialGateway.GetAttributeValue("ReturnPage") != string.Empty)
            {
                PageReference pageReference = new PageReference(financialGateway.GetAttributeValue("ReturnPage"));
                ecDetails.ReturnURL = host + pageReference.BuildUrl();
            }
            if (financialGateway.GetAttributeValue("CancelPage") != string.Empty)
            {
                PageReference pageReference = new PageReference(financialGateway.GetAttributeValue("CancelPage"));
                ecDetails.CancelURL = host + pageReference.BuildUrl();
            }

            /*
             * // (Optional) Email address of the buyer as entered during checkout. PayPal uses this value to pre-fill the PayPal membership sign-up portion on the PayPal pages.
             * if (buyerEmail.Value != string.Empty)
             * {
             *
             * }*/
            ecDetails.BuyerEmail = paymentInfo.Email;

            /* Populate payment requestDetails.
             * SetExpressCheckout allows parallel payments of upto 10 payments.
             * This samples shows just one payment.
             */
            PaymentDetailsType paymentDetails = new PaymentDetailsType();

            ecDetails.PaymentDetails.Add(paymentDetails);
            // (Required) Total cost of the transaction to the buyer. If shipping cost and tax charges are known, include them in this value. If not, this value should be the current sub-total of the order. If the transaction includes one or more one-time purchases, this field must be equal to the sum of the purchases. Set this field to 0 if the transaction does not include a one-time purchase such as when you set up a billing agreement for a recurring payment that is not immediately charged. When the field is set to 0, purchase-specific fields are ignored.
            double orderTotal = 0.0;
            // Sum of cost of all items in this order. For digital goods, this field is required.
            double           itemTotal = Convert.ToDouble(paymentInfo.Amount);
            CurrencyCodeType currency  = CurrencyCodeType.USD;

            //(Optional) Description of items the buyer is purchasing.
            paymentDetails.OrderDescription = "Contribution";

            // We do a authorization then complete the sale in the "Charge" phase
            paymentDetails.PaymentAction = PaymentActionCodeType.AUTHORIZATION;
            foreach (GatewayAccountItem item in selectedAccounts)
            {
                if (item.Amount > 0)
                {
                    PaymentDetailsItemType itemDetails = new PaymentDetailsItemType();

                    itemDetails.Name        = item.Name;
                    itemDetails.Amount      = new BasicAmountType(currency, item.Amount.ToString());
                    itemDetails.Quantity    = 1;
                    itemDetails.Description = item.PublicName;
                    itemDetails.Number      = item.Id.ToString();
                    paymentDetails.PaymentDetailsItem.Add(itemDetails);
                }
            }

            orderTotal += itemTotal;
            paymentDetails.ItemTotal  = new BasicAmountType(currency, itemTotal.ToString());
            paymentDetails.OrderTotal = new BasicAmountType(currency, orderTotal.ToString());

            //(Optional) Your URL for receiving Instant Payment Notification (IPN)
            //about this transaction. If you do not specify this value in the request,
            //the notification URL from your Merchant Profile is used, if one exists.
            //Important:
            //The notify URL applies only to DoExpressCheckoutPayment.
            //This value is ignored when set in SetExpressCheckout or GetExpressCheckoutDetails.
            //Character length and limitations: 2,048 single-byte alphanumeric characters
            paymentDetails.NotifyURL = "";
            // ipnNotificationUrl.Value.Trim();

            //(Optional) Locale of pages displayed by PayPal during Express Checkout.

            /*if (localeCode.SelectedIndex != 0)
             * {
             *  ecDetails.LocaleCode = localeCode.SelectedValue;
             * }
             *
             * // (Optional) Name of the Custom Payment Page Style for payment pages associated with this button or link. It corresponds to the HTML variable page_style for customizing payment pages. It is the same name as the Page Style Name you chose to add or edit the page style in your PayPal Account profile.
             * if (pageStyle.Value != string.Empty)
             * {
             *  ecDetails.PageStyle = pageStyle.Value;
             * }*/
            //(Optional) URL for the image you want to appear at the top left of the payment page. The image has a maximum size of 750 pixels wide by 90 pixels high. PayPal recommends that you provide an image that is stored on a secure (https) server. If you do not specify an image, the business name displays.
            if (financialGateway.GetAttributeValue("PayPalLogoImage") != string.Empty)
            {
                ecDetails.cppHeaderImage = financialGateway.GetAttributeValue("PayPalLogoImage");
            }

            /*// (Optional) Sets the border color around the header of the payment page. The border is a 2-pixel perimeter around the header space, which is 750 pixels wide by 90 pixels high. By default, the color is black.
             * if (cppheaderbordercolor.Value != string.Empty)
             * {
             *  ecDetails.cppHeaderBorderColor = cppheaderbordercolor.Value;
             * }
             * // (Optional) Sets the background color for the header of the payment page. By default, the color is white.
             * if (cppheaderbackcolor.Value != string.Empty)
             * {
             *  ecDetails.cppHeaderBackColor = cppheaderbackcolor.Value;
             * }
             * // (Optional) Sets the background color for the payment page. By default, the color is white.
             * if (cpppayflowcolor.Value != string.Empty)
             * {
             *  ecDetails.cppPayflowColor = cpppayflowcolor.Value;
             * }
             * // (Optional) A label that overrides the business name in the PayPal account on the PayPal hosted checkout pages.
             */
            if (financialGateway.GetAttributeValue("PayPalBrandName") != string.Empty)
            {
                ecDetails.BrandName = financialGateway.GetAttributeValue("PayPalBrandName");
            }

            request.SetExpressCheckoutRequestDetails = ecDetails;

            return(request);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Updates the list.
        /// </summary>
        private void UpdateList()
        {
            using (var rockContext = new RockContext())
            {
                var searchSelections = new Dictionary <string, string>();

                var connectionType = new ConnectionTypeService(rockContext).Get(GetAttributeValue("ConnectionTypeId").AsInteger());
                var qrySearch      = connectionType.ConnectionOpportunities.ToList();

                if (GetAttributeValue("DisplayNameFilter").AsBoolean())
                {
                    if (!string.IsNullOrWhiteSpace(tbSearchName.Text))
                    {
                        searchSelections.Add("tbSearchName", tbSearchName.Text);
                        var searchTerms = tbSearchName.Text.ToLower().SplitDelimitedValues(true);
                        qrySearch = qrySearch.Where(o => searchTerms.Any(t => t.Contains(o.Name.ToLower()) || o.Name.ToLower().Contains(t))).ToList();
                    }
                }

                if (GetAttributeValue("DisplayCampusFilter").AsBoolean())
                {
                    var searchCampuses = cblCampus.SelectedValuesAsInt;
                    if (searchCampuses.Count > 0)
                    {
                        searchSelections.Add("cblCampus", searchCampuses.AsDelimited("|"));
                        qrySearch = qrySearch.Where(o => o.ConnectionOpportunityCampuses.Any(c => searchCampuses.Contains(c.CampusId))).ToList();
                    }
                }

                if (GetAttributeValue("DisplayAttributeFilters").AsBoolean())
                {
                    // Filter query by any configured attribute filters
                    if (AvailableAttributes != null && AvailableAttributes.Any())
                    {
                        var attributeValueService = new AttributeValueService(rockContext);
                        var parameterExpression   = attributeValueService.ParameterExpression;

                        foreach (var attribute in AvailableAttributes)
                        {
                            string filterControlId = "filter_" + attribute.Id.ToString();
                            var    filterControl   = phAttributeFilters.FindControl(filterControlId);
                            if (filterControl != null)
                            {
                                var filterValues = attribute.FieldType.Field.GetFilterValues(filterControl, attribute.QualifierValues, Rock.Reporting.FilterMode.SimpleFilter);
                                var expression   = attribute.FieldType.Field.AttributeFilterExpression(attribute.QualifierValues, filterValues, parameterExpression);
                                if (expression != null)
                                {
                                    searchSelections.Add(filterControlId, filterValues.ToJson());
                                    var attributeValues = attributeValueService
                                                          .Queryable()
                                                          .Where(v => v.Attribute.Id == attribute.Id);

                                    attributeValues = attributeValues.Where(parameterExpression, expression, null);

                                    qrySearch = qrySearch.Where(o => attributeValues.Select(v => v.EntityId).Contains(o.Id)).ToList();
                                }
                            }
                        }
                    }
                }

                string sessionKey = string.Format("ConnectionSearch_{0}", this.BlockId);
                Session[sessionKey] = searchSelections;

                var opportunitySummaries = new List <OpportunitySummary>();
                foreach (var opportunity in qrySearch)
                {
                    opportunitySummaries.Add(new OpportunitySummary
                    {
                        IconCssClass = opportunity.IconCssClass,
                        Name         = opportunity.PublicName,
                        PhotoUrl     = opportunity.PhotoUrl,
                        Description  = opportunity.Description,
                        Summary      = opportunity.Summary,
                        Id           = opportunity.Id
                    });
                }

                var opportunities = opportunitySummaries
                                    .OrderBy(e => e.Name)
                                    .ToList();

                var mergeFields = new Dictionary <string, object>();
                mergeFields.Add("Opportunities", opportunities);
                mergeFields.Add("CurrentPerson", CurrentPerson);

                var pageReference = new PageReference(GetAttributeValue("DetailPage"), null);
                mergeFields.Add("DetailPage", pageReference.BuildUrl());

                lOutput.Text = GetAttributeValue("LavaTemplate").ResolveMergeFields(mergeFields);

                if (GetAttributeValue("SetPageTitle").AsBoolean())
                {
                    string pageTitle = "Connection";
                    RockPage.PageTitle    = pageTitle;
                    RockPage.BrowserTitle = String.Format("{0} | {1}", pageTitle, RockPage.Site.Name);
                    RockPage.Header.Title = String.Format("{0} | {1}", pageTitle, RockPage.Site.Name);
                }

                // show debug info
                if (GetAttributeValue("EnableDebug").AsBoolean() && IsUserAuthorized(Authorization.EDIT))
                {
                    lDebug.Visible = true;
                    lDebug.Text    = mergeFields.lavaDebugInfo();
                }
            }
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BreadCrumb" /> class.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="pageReference">The page reference.</param>
 /// <param name="active">if set to <c>true</c> [active].</param>
 public BreadCrumb(string name, PageReference pageReference, bool active = false)
     : this(name, active)
 {
     Url = pageReference.BuildUrl();
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Handles the Click event of the btnSendRequest control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void btnSendRequest_Click(object sender, EventArgs e)
        {
            if (!Page.IsValid)
            {
                // controls will render error messages
                return;
            }

            int personId = ddlFacilitators.SelectedValueAsInt() ?? 0;

            Person facilitator = new PersonService().Get(personId);

            if (facilitator == null)
            {
                ddlFacilitators.ShowErrorMessage("Facilitator not found");
                return;
            }

            string gradeDetailPageGuid = this.GetAttributeValue("ResidentGradeDetailPage");

            CompetencyPersonProject competencyPersonProject = new ResidencyService <CompetencyPersonProject>().Get(hfCompetencyPersonProjectId.ValueAsInt());

            var userLoginService     = new UserLoginService();
            var facilitatorUserLogin = userLoginService.GetByPersonId(facilitator.Id).FirstOrDefault();

            Uri gradeDetailPageUrl = null;

            if (!string.IsNullOrWhiteSpace(gradeDetailPageGuid))
            {
                PageCache pageCache = PageCache.Read(new Guid(gradeDetailPageGuid));
                if (pageCache != null)
                {
                    Dictionary <string, string> queryString = new Dictionary <string, string>();

                    int routeId = 0;
                    {
                        routeId = pageCache.PageRoutes.FirstOrDefault().Key;
                    }

                    // set Ticks (3rd part) to 0 since this is an emailed request
                    string identifier = hfCompetencyPersonProjectId.Value + "|" + facilitatorUserLogin.Guid + "|0";
                    string gradeKey   = Rock.Security.Encryption.EncryptString(identifier);

                    queryString.Add("competencyPersonProjectId", hfCompetencyPersonProjectId.Value);
                    queryString.Add("gradeKey", Server.UrlEncode(gradeKey));

                    PageReference pageReference = new PageReference(pageCache.Id, routeId, queryString);

                    Uri rootUri = new Uri(this.RootPath);
                    gradeDetailPageUrl = new Uri(rootUri, pageReference.BuildUrl());
                }
            }
            else
            {
                nbWarningMessage.Text = "Ooops! Grading page not configured.";
                return;
            }

            var mergeObjects = new Dictionary <string, object>();

            mergeObjects.Add("Facilitator", facilitator.ToDictionary());
            mergeObjects.Add("Resident", competencyPersonProject.CompetencyPerson.Person.ToDictionary());
            mergeObjects.Add("Project", competencyPersonProject.Project.ToDictionary());

            mergeObjects.Add("GradeDetailPageUrl", gradeDetailPageUrl.ToString());

            var recipients = new Dictionary <string, Dictionary <string, object> >();

            recipients.Add(facilitator.Email, mergeObjects);

            Email email = new Email(com.ccvonline.SystemGuid.EmailTemplate.RESIDENCY_PROJECT_GRADE_REQUEST);

            email.Send(recipients);
        }