Beispiel #1
0
        public string RenderTemplate([NakedBody] string template, [FromUri] string additionalMergeObjects = null)
        {
            Rock.Lava.CommonMergeFieldsOptions lavaOptions = new Lava.CommonMergeFieldsOptions();
            lavaOptions.GetPageContext             = false;
            lavaOptions.GetPageParameters          = false;
            lavaOptions.GetCurrentPerson           = true;
            lavaOptions.GetCampuses                = true;
            lavaOptions.GetLegacyGlobalMergeFields = false;
            var currentPerson = GetPerson();

            Dictionary <string, object> mergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields(null, currentPerson, lavaOptions);

            if (additionalMergeObjects != null)
            {
                var additionalMergeObjectList = additionalMergeObjects.Split(',').Select(a => a.Split('|')).Where(a => a.Length == 3).Select(a => new
                {
                    EntityTypeId = a[0].AsInteger(),
                    MergeKey     = a[1],
                    EntityId     = a[2].AsInteger()
                }).ToList();

                foreach (var additionalMergeObject in additionalMergeObjectList)
                {
                    var entityTypeType = EntityTypeCache.Get(additionalMergeObject.EntityTypeId)?.GetEntityType();
                    if (entityTypeType != null)
                    {
                        var dbContext       = Rock.Reflection.GetDbContextForEntityType(entityTypeType);
                        var serviceInstance = Rock.Reflection.GetServiceForEntityType(entityTypeType, dbContext);
                        if (serviceInstance != null)
                        {
                            System.Reflection.MethodInfo getMethod = serviceInstance.GetType().GetMethod("Get", new Type[] { typeof(int) });
                            var mergeObjectEntity = getMethod.Invoke(serviceInstance, new object[] { additionalMergeObject.EntityId }) as Rock.Data.IEntity;

                            if (mergeObjectEntity != null)
                            {
                                bool canView = true;
                                if (mergeObjectEntity is Rock.Security.ISecured)
                                {
                                    canView = (mergeObjectEntity as Rock.Security.ISecured).IsAuthorized(Rock.Security.Authorization.VIEW, currentPerson);
                                }

                                if (canView)
                                {
                                    mergeFields.Add(additionalMergeObject.MergeKey, mergeObjectEntity);
                                }
                            }
                        }
                    }
                }
            }

            return(template.ResolveMergeFields(mergeFields, currentPerson));
        }
Beispiel #2
0
        public string RenderTemplate( [NakedBody] string template )
        {
            Rock.Lava.CommonMergeFieldsOptions lavaOptions = new Lava.CommonMergeFieldsOptions();
            lavaOptions.GetPageContext = false;
            lavaOptions.GetPageParameters = false;
            lavaOptions.GetCurrentPerson = true;
            lavaOptions.GetCampuses = true;
            lavaOptions.GetLegacyGlobalMergeFields = false;

            Dictionary<string, object> mergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields(null, GetPerson(), lavaOptions);

            return template.ResolveMergeFields( mergeFields );
        }
Beispiel #3
0
        public string RenderTemplate([NakedBody] string template)
        {
            Rock.Lava.CommonMergeFieldsOptions lavaOptions = new Lava.CommonMergeFieldsOptions();
            lavaOptions.GetPageContext             = false;
            lavaOptions.GetPageParameters          = false;
            lavaOptions.GetCurrentPerson           = true;
            lavaOptions.GetCampuses                = true;
            lavaOptions.GetLegacyGlobalMergeFields = false;

            Dictionary <string, object> mergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields(null, GetPerson(), lavaOptions);

            return(template.ResolveMergeFields(mergeFields));
        }
Beispiel #4
0
        /// <summary>
        /// Gets the values.
        /// </summary>
        /// <param name="configurationValues">The configuration values.</param>
        /// <returns></returns>
        public static Dictionary<string, string> GetConfiguredValues( Dictionary<string, ConfigurationValue> configurationValues )
        {
            var items = new Dictionary<string, string>();

            if ( configurationValues.ContainsKey( "values" ) )
            {
                string listSource = configurationValues["values"].Value;

                var options = new Lava.CommonMergeFieldsOptions();
                options.GetLegacyGlobalMergeFields = false;
                var mergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields( null, null, options );

                listSource = listSource.ResolveMergeFields( mergeFields );

                if ( listSource.ToUpper().Contains( "SELECT" ) && listSource.ToUpper().Contains( "FROM" ) )
                {
                    var tableValues = new List<string>();
                    DataTable dataTable = Rock.Data.DbService.GetDataTable( listSource, CommandType.Text, null );
                    if ( dataTable != null && dataTable.Columns.Contains( "Value" ) && dataTable.Columns.Contains( "Text" ) )
                    {
                        foreach ( DataRow row in dataTable.Rows )
                        {
                            items.AddOrIgnore( row["value"].ToString(), row["text"].ToString() );
                        }
                    }
                }

                else
                {
                    foreach ( string keyvalue in listSource.Split( new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries ) )
                    {
                        var keyValueArray = keyvalue.Split( new char[] { '^' }, StringSplitOptions.RemoveEmptyEntries );
                        if ( keyValueArray.Length > 0 )
                        {
                            items.AddOrIgnore( keyValueArray[0].Trim(), keyValueArray.Length > 1 ? keyValueArray[1].Trim() : keyValueArray[0].Trim() );
                        }
                    }
                }
            }

            return items;
        }
Beispiel #5
0
        /// <summary>
        /// Gets the values.
        /// </summary>
        /// <param name="configurationValues">The configuration values.</param>
        /// <returns></returns>
        public static Dictionary <string, string> GetConfiguredValues(Dictionary <string, ConfigurationValue> configurationValues)
        {
            var items = new Dictionary <string, string>();

            if (configurationValues.ContainsKey("values"))
            {
                string listSource = configurationValues["values"].Value;

                var options = new Lava.CommonMergeFieldsOptions();
                options.GetLegacyGlobalMergeFields = false;
                var mergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields(null, null, options);

                listSource = listSource.ResolveMergeFields(mergeFields);

                if (listSource.ToUpper().Contains("SELECT") && listSource.ToUpper().Contains("FROM"))
                {
                    var       tableValues = new List <string>();
                    DataTable dataTable   = Rock.Data.DbService.GetDataTable(listSource, CommandType.Text, null);
                    if (dataTable != null && dataTable.Columns.Contains("Value") && dataTable.Columns.Contains("Text"))
                    {
                        foreach (DataRow row in dataTable.Rows)
                        {
                            items.AddOrIgnore(row["value"].ToString(), row["text"].ToString());
                        }
                    }
                }

                else
                {
                    foreach (string keyvalue in listSource.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                    {
                        var keyValueArray = keyvalue.Split(new char[] { '^' }, StringSplitOptions.RemoveEmptyEntries);
                        if (keyValueArray.Length > 0)
                        {
                            items.AddOrIgnore(keyValueArray[0].Trim(), keyValueArray.Length > 1 ? keyValueArray[1].Trim() : keyValueArray[0].Trim());
                        }
                    }
                }
            }

            return(items);
        }