コード例 #1
0
        private void updateCategories(Document doc, Post post, Channel userChannel)
        {
            if (userChannel.FieldCategoriesAlias != null && userChannel.FieldCategoriesAlias != "")
            {
                ContentType  blogPostType = ContentType.GetByAlias(userChannel.DocumentTypeAlias);
                PropertyType categoryType = blogPostType.getPropertyType(userChannel.FieldCategoriesAlias);

                String[]            categories    = post.categories;
                string              categoryValue = "";
                interfaces.IUseTags tags          = UseTags(categoryType);
                if (tags != null)
                {
                    tags.RemoveTagsFromNode(doc.Id);
                    for (int i = 0; i < categories.Length; i++)
                    {
                        tags.AddTagToNode(doc.Id, categories[i]);
                    }
                }
                else
                {
                    for (int i = 0; i < categories.Length; i++)
                    {
                        PreValue pv = new PreValue(categoryType.DataTypeDefinition.Id, categories[i]);
                        categoryValue += pv.Id + ",";
                    }
                }
                if (categoryValue.Length > 0)
                {
                    categoryValue = categoryValue.Substring(0, categoryValue.Length - 1);
                }

                doc.getProperty(userChannel.FieldCategoriesAlias).Value = categoryValue;
            }
        }
コード例 #2
0
        private static void UpdateCategories(Document doc, Post post, Channel userChannel)
        {
            if (userChannel.FieldCategoriesAlias != null && userChannel.FieldCategoriesAlias != "")
            {
                ContentType  blogPostType = ContentType.GetByAlias(userChannel.DocumentTypeAlias);
                PropertyType categoryType = blogPostType.getPropertyType(userChannel.FieldCategoriesAlias);

                String[]            categories    = post.categories;
                string              categoryValue = "";
                interfaces.IUseTags tags          = UseTags(categoryType);
                if (tags != null)
                {
                    tags.RemoveTagsFromNode(doc.Id);
                    for (int i = 0; i < categories.Length; i++)
                    {
                        tags.AddTagToNode(doc.Id, categories[i]);
                    }
                    //If the IUseTags provider manually set the property value to something on the IData interface then we should persist this
                    //code commented as for some reason, even though the IUseTags control is setting IData.Value it is null here
                    //could be a cache issue, or maybe it's a different instance of the IData or something, rather odd
                    //doc.getProperty(userChannel.FieldCategoriesAlias).Value = categoryType.DataTypeDefinition.DataType.Data.Value;

                    //Instead, set the document property to CSV of the tags - this WILL break custom editors for tags which don't adhere to the
                    //pseudo standard that the .Value of the property contains CSV tags.
                    doc.getProperty(userChannel.FieldCategoriesAlias).Value = string.Join(",", categories);
                }
                else
                {
                    for (int i = 0; i < categories.Length; i++)
                    {
                        PreValue pv = new PreValue(categoryType.DataTypeDefinition.Id, categories[i]);
                        categoryValue += pv.Id + ",";
                    }
                    if (categoryValue.Length > 0)
                    {
                        categoryValue = categoryValue.Substring(0, categoryValue.Length - 1);
                    }

                    doc.getProperty(userChannel.FieldCategoriesAlias).Value = categoryValue;
                }
            }
        }