示例#1
0
        /// <summary>
        /// Gets the expression.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="serviceInstance">The service instance.</param>
        /// <param name="parameterExpression">The parameter expression.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override Expression GetExpression(Type entityType, IService serviceInstance, ParameterExpression parameterExpression, string selection)
        {
            var settings = new GroupBranchFilterSettings(selection);

            if (!settings.IsValid())
            {
                return(null);
            }

            var groupService = new GroupService((RockContext)serviceInstance.Context);

            // Get the qualifying Groups.
            var parentGroup = groupService.Get(settings.ParentGroupId);

            var groupIdList = GetGroupBranchKeys(groupService, parentGroup, settings.IncludedGroups);

            // Filter by Groups
            var groupsQry = groupService.Queryable().Where(x => groupIdList.Contains(x.Id));

            var qry = groupService.Queryable().Where(g => groupsQry.Any(x => x.Id == g.Id));

            var extractedFilterExpression = FilterExpressionExtractor.Extract <Model.Group>(qry, parameterExpression, "g");

            return(extractedFilterExpression);
        }
示例#2
0
        /// <summary>
        /// Gets the selection.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="controls">The controls.</param>
        /// <returns></returns>
        public override string GetSelection(Type entityType, Control[] controls)
        {
            var settings = new GroupBranchFilterSettings();

            settings.ParentGroupId = ((GroupPicker)controls[0]).SelectedValueAsInt() ?? 0;

            IncludedGroupsSpecifier includedGroups;

            Enum.TryParse(((RockDropDownList)controls[1]).SelectedValue, true, out includedGroups);

            settings.IncludedGroups = includedGroups;

            return(settings.ToSelectionString());
        }
示例#3
0
        /// <summary>
        /// Sets the selection.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="controls">The controls.</param>
        /// <param name="selection">The selection.</param>
        public override void SetSelection(Type entityType, Control[] controls, string selection)
        {
            var settings = new GroupBranchFilterSettings(selection);

            // Parent Group
            if (settings.ParentGroupId > 0)
            {
                ((GroupPicker)controls[0]).SetValue(settings.ParentGroupId);
            }

            // Included Groups
            var ctlIncludedGroups = (RockDropDownList)controls[1];

            ctlIncludedGroups.SelectedValue = settings.IncludedGroups.ToString();
        }
示例#4
0
        /// <summary>
        /// Formats the selection.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override string FormatSelection(Type entityType, string selection)
        {
            string result;

            var settings = new GroupBranchFilterSettings(selection);
            var group    = new GroupService(new RockContext()).Get(settings.ParentGroupId);

            var groupName = (group != null) ? group.Name : "(any)";

            switch (settings.IncludedGroups)
            {
            case IncludedGroupsSpecifier.DescendantsOnly:
                result = string.Format("Is sub-group of: {0}", groupName);
                break;

            default:
                result = string.Format("Is in group branch: {0}", groupName);
                break;
            }

            return(result);
        }
示例#5
0
        /// <summary>
        /// Sets the selection.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="controls">The controls.</param>
        /// <param name="selection">The selection.</param>
        public override void SetSelection( Type entityType, Control[] controls, string selection )
        {
            var settings = new GroupBranchFilterSettings( selection );

            // Parent Group
            if ( settings.ParentGroupId > 0 )
                ( (GroupPicker)controls[0] ).SetValue( settings.ParentGroupId );

            // Included Groups
            var ctlIncludedGroups = (RockDropDownList)controls[1];

            ctlIncludedGroups.SelectedValue = settings.IncludedGroups.ToString();
        }
示例#6
0
        /// <summary>
        /// Gets the selection.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="controls">The controls.</param>
        /// <returns></returns>
        public override string GetSelection( Type entityType, Control[] controls )
        {
            var settings = new GroupBranchFilterSettings();

            settings.ParentGroupId = ( (GroupPicker)controls[0] ).SelectedValueAsInt() ?? 0;

            IncludedGroupsSpecifier includedGroups;

            Enum.TryParse( ( (RockDropDownList)controls[1] ).SelectedValue, true, out includedGroups );

            settings.IncludedGroups = includedGroups;

            return settings.ToSelectionString();
        }
示例#7
0
        /// <summary>
        /// Gets the expression.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="serviceInstance">The service instance.</param>
        /// <param name="parameterExpression">The parameter expression.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override Expression GetExpression( Type entityType, IService serviceInstance, ParameterExpression parameterExpression, string selection )
        {
            var settings = new GroupBranchFilterSettings( selection );

            if ( !settings.IsValid() )
            {
                return null;
            }

            var groupService = new GroupService( (RockContext)serviceInstance.Context );

            // Get the qualifying Groups.
            var parentGroup = groupService.Get( settings.ParentGroupId );

            var groupIdList = GetGroupBranchKeys( groupService, parentGroup, settings.IncludedGroups );

            // Filter by Groups
            var groupsQry = groupService.Queryable().Where( x => groupIdList.Contains( x.Id ) );

            var qry = groupService.Queryable().Where( g => groupsQry.Any( x => x.Id == g.Id ) );

            var extractedFilterExpression = FilterExpressionExtractor.Extract<Model.Group>( qry, parameterExpression, "g" );

            return extractedFilterExpression;
        }
示例#8
0
        /// <summary>
        /// Formats the selection.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override string FormatSelection( Type entityType, string selection )
        {
            string result;

            var settings = new GroupBranchFilterSettings( selection );
            var group = new GroupService( new RockContext() ).Get( settings.ParentGroupId );

            var groupName = ( group != null ) ? group.Name : "(any)";

            switch ( settings.IncludedGroups )
            {
                case IncludedGroupsSpecifier.DescendantsOnly:
                    result = string.Format( "Is sub-group of: {0}", groupName );
                    break;
                default:
                    result = string.Format( "Is in group branch: {0}", groupName );
                    break;
            }

            return result;
        }