Beispiel #1
0
        public virtual XPathNodeIterator GetDataSourceIDs(
            string dataSource,
            XPathNodeIterator iterator)
        {
            if (string.IsNullOrEmpty(dataSource))
            {
                return(this.CreateEmptyIterator());
            }

            SC.Xml.Packet packet = new SC.Xml.Packet("values", new string[0]);
            iterator.MoveNext();
            SC.Sharedsource.Web.UI.DataSourceHelper helper =
                new SC.Sharedsource.Web.UI.DataSourceHelper(dataSource, this.GetItem(iterator))
            {
                StoreUISearchResults = true,
            };

            if (helper.Items != null)
            {
                foreach (SC.Data.Items.Item item in helper.Items)
                {
                    if (item != null)
                    {
                        packet.AddElement("value", item.ID.ToString());
                    }
                }
            }

            return(this.GetChildIterator(packet));
        }
Beispiel #2
0
        private XPathNodeIterator GetChildIterator(SC.Xml.Packet packet)
        {
            XPathNavigator navigator = packet.XmlDocument.CreateNavigator();

            navigator.MoveToRoot();
            navigator.MoveToFirstChild();
            return(navigator.SelectChildren(XPathNodeType.Element));
        }
        public virtual XPathNodeIterator SortListField(
            string listField,
            string sortField,
            XPathNodeIterator ni,
            bool reverse)
        {
            Sitecore.Xml.Packet packet   = new Sitecore.Xml.Packet("values");
            XPathNodeIterator   iterator = ni.Clone();

            if (iterator.MoveNext())
            {
                Sitecore.Data.Items.Item item = GetItem(iterator);

                if (item != null)
                {
                    Sitecore.Data.Fields.MultilistField fieldList = item.Fields[listField];

                    if (fieldList != null)
                    {
                        List <Item> itemList = new List <Item>();

                        foreach (Sitecore.Data.Items.Item pointer in fieldList.GetItems())
                        {
                            if (pointer != null)
                            {
                                itemList.Add(pointer);
                            }
                        }

                        Item[] items = itemList.ToArray();
                        Array.Sort(items, new FieldValueComparer(sortField));

                        if (reverse)
                        {
                            Array.Reverse(items);
                        }

                        foreach (Sitecore.Data.Items.Item reference in items)
                        {
                            packet.AddElement("value", reference.ID.ToString());
                        }
                    }
                }
            }

            XPathNavigator navigator = packet.XmlDocument.CreateNavigator()
                                       ?? new XmlDocument().CreateNavigator();

            navigator.MoveToRoot();
            navigator.MoveToFirstChild();
            return(navigator.SelectChildren(XPathNodeType.Element));
        }