コード例 #1
0
        /// <summary>
        /// Adds all fields.
        /// </summary>
        /// <param name="document">
        /// The document.
        /// </param>
        /// <param name="item">
        /// The item.
        /// </param>
        /// <param name="versionSpecific">
        /// Ignored, must always be true.
        /// </param>
        protected override void AddAllFields([NotNull] Document document, [NotNull] Item item, bool versionSpecific)
        {
            Assert.ArgumentNotNull(document, "document");
            Assert.ArgumentNotNull(item, "item");

            base.AddAllFields(document, item, versionSpecific);

            if (item.Name == "__Standard Values")
            {
                return;
            }

            var fields = item.Fields;

            fields.ReadAll();
            foreach (Data.Fields.Field field in fields)
            {
                if (string.IsNullOrEmpty(field.Key))
                {
                    continue;
                }

                if (field.Type == "Classification")
                {
                    var relations = TaxonomyEngine.GetAllCategories(field.Item, field.Value);
                    foreach (var info in relations.Values)
                    {
                        document.Add(CreateTextField("_categories", ShortID.Encode(info.Category)));
                        continue;
                    }
                }
            }
        }
コード例 #2
0
        protected override void OnLoad(System.EventArgs e)
        {
            base.OnLoad(e);
            UrlHandle     handle        = UrlHandle.Get();
            string        itemId        = handle["itemId"];
            string        taxonomyValue = handle["taxonomyValue"];
            List <string> listValue     = taxonomyValue.Split("|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToList();

            listValue.RemoveAll(str => str.Contains(Sitecore.Data.ID.Null.ToString()));
            taxonomyValue = String.Join("|", listValue.ToArray <string>());
            if (!string.IsNullOrEmpty(taxonomyValue) && !string.IsNullOrEmpty(itemId) && Sitecore.Data.ID.IsID(itemId))
            {
                Item currentItem = Client.ContentDatabase.GetItem(new ID(itemId));
                IOrderedEnumerable <RelationInfo> categories =
                    TaxonomyEngine.GetAllCategories(currentItem, taxonomyValue).Values.OrderBy(info => info.Weight);
                IEnumerable <RelationInfo> setCategories = (from category in categories
                                                            where !category.Calculated
                                                            select category);


                foreach (RelationInfo link in setCategories)
                {
                    GridPanel categoriesPanel = new GridPanel();
                    ResultBox.Controls.Add(categoriesPanel);
                    categoriesPanel.Attributes["class"] = "categoriesPanel";
                    categoriesPanel.Columns             = 100;
                    categoriesPanel.Controls.Add(GetCategoryPanel(link));
                    BuildRelatedCategories(categories, categoriesPanel, link);
                }
            }
            else
            {
                Literal noDataLiteral = new Literal("No taxonomy data could be retrieved.");
                ResultBox.Controls.Add(noDataLiteral);
            }
        }
コード例 #3
0
 public DataService(AppEngine engine)
 {
     AppEngine = engine;
     Engine    = engine.Features.Engine;
 }
コード例 #4
0
        protected override void OK_Click()
        {
            string selected = WebUtil.GetFormValue("categoryTreeview_Selected");

            selected = ShortID.Decode(StringUtil.Mid(selected, 1));
            if (string.IsNullOrEmpty(selected))
            {
                SheerResponse.Alert("Please select a category.");
                return;
            }

            if (Sitecore.Data.ID.IsID(selected))
            {
                UrlHandle handle       = UrlHandle.Get();
                Database  db           = Sitecore.Context.ContentDatabase ?? Sitecore.Context.Database;
                Item      selectedItem = db.GetItem(new ID(selected));
                Item      rootItem     = db.GetItem(new ID(handle["categoriesRootId"]));

                if (selectedItem.TemplateID.ToString() != "{A69C0097-5CE1-435B-99E9-FA2B998D1C70}")
                {
                    string taxValue = handle["value"];
                    if (taxValue.Contains(selectedItem.ID.ToString()))
                    {
                        SheerResponse.Alert("Selected category is already assigned.\nPlease select another category.");
                        return;
                    }

                    if (!string.IsNullOrEmpty(taxValue))
                    {
                        List <string> conflictCategoryNames = new List <string>();

                        List <ID> tagConflicts = TaxonomyEngine.GetConflictTags(selectedItem.ID).ToList();
                        if (tagConflicts.Count > 0)
                        {
                            foreach (ID itemTagId in StringUtil.Split(taxValue, '|', true).Select(id => new ID(StringUtil.GetPrefix(id, ':'))))
                            {
                                if (tagConflicts.Contains(itemTagId))
                                {
                                    CategoryItem categoryItem = new CategoryItem(Client.ContentDatabase.GetItem(itemTagId));
                                    conflictCategoryNames.Add(categoryItem.CategoryName);
                                }
                            }
                        }

                        if (conflictCategoryNames.Count > 0)
                        {
                            CategoryItem categoryItem = new CategoryItem(selectedItem);

                            if (conflictCategoryNames.Count > 3)
                            {
                                SheerResponse.Alert(
                                    string.Format(
                                        Messages.CategoryConflictsWithAlreadyAssignedMoreThanThree,
                                        categoryItem.CategoryName,
                                        StringUtil.Join(conflictCategoryNames.Take(3).Select(categoryName => "  -" + categoryName + "\n"), string.Empty),
                                        conflictCategoryNames.Count - 3));
                            }
                            else
                            {
                                SheerResponse.Alert(
                                    string.Format(
                                        Messages.CategoryConflictsWithAlreadyAssigned,
                                        categoryItem.CategoryName,
                                        StringUtil.Join(conflictCategoryNames.Select(categoryName => "  -" + categoryName + "\n"), string.Empty)));
                            }
                            return;
                        }
                    }
                    SheerResponse.SetDialogValue(selected);
                    base.OK_Click();
                }
                else
                {
                    SheerResponse.Alert("Please select a category.");
                }
            }
        }