/// <summary>
        /// Initializes the controls.
        /// </summary>
        /// <param name="container">The controls container.</param>
        /// <param name="definition">The content view definition.</param>
        protected override void InitializeControls(GenericContainer container, IContentViewDefinition definition)
        {
            var masterDefinition = definition as IContentViewMasterDefinition;

            if (masterDefinition != null)
            {
                var query = this.Manager.GetProducts();
                if (masterDefinition.AllowUrlQueries.HasValue && masterDefinition.AllowUrlQueries.Value)
                {
                    query = this.EvaluateUrl(query, "Date", "PublicationDate", this.Host.UrlEvaluationMode, this.Host.UrlKeyPrefix);
                    query = this.EvaluateUrl(query, "Author", "Owner", this.Host.UrlEvaluationMode, this.Host.UrlKeyPrefix);
                    query = this.EvaluateUrl(query, "Taxonomy", string.Empty, typeof(ProductItem), this.Host.UrlEvaluationMode, this.Host.UrlKeyPrefix);
                }

                int?totalCount  = 0;
                int?itemsToSkip = 0;
                if (masterDefinition.AllowPaging.HasValue && masterDefinition.AllowPaging.Value)
                {
                    itemsToSkip = this.GetItemsToSkipCount(masterDefinition.ItemsPerPage, this.Host.UrlEvaluationMode, this.Host.UrlKeyPrefix);
                }

                CultureInfo uiCulture = null;
                if (AppSettings.CurrentSettings.Multilingual)
                {
                    uiCulture = System.Globalization.CultureInfo.CurrentUICulture;
                }
                //the filter is adapted to the implementation of ILifecycleDataItemGeneric, so the culture is taken in advance when filtering published items.
                this.FilterExpression = ContentHelper.AdaptMultilingualFilterExpression(this.FilterExpression);
                var filterExpression = DefinitionsHelper.GetFilterExpression(this.FilterExpression, this.AdditionalFilter);
                query = Telerik.Sitefinity.Data.DataProviderBase.SetExpressions(
                    query,
                    filterExpression,
                    masterDefinition.SortExpression,
                    uiCulture,
                    itemsToSkip,
                    masterDefinition.ItemsPerPage,
                    ref totalCount);

                this.IsEmptyView = (totalCount == 0);

                if (totalCount == 0)
                {
                    this.NewsList.Visible = false;
                }
                else
                {
                    this.ConfigurePager(totalCount.Value, masterDefinition);
                    this.NewsList.DataSource = query.ToList();
                    this.NewsList.PreRender += new EventHandler(NewsList_PreRender);
                }
            }
        }
Esempio n. 2
0
        private IQueryable <IDataItem> GetRelatedItems(IDataItem relatedItem, int page, ref int?totalCount)
        {
            var manager           = this.GetManager();
            var relatedDataSource = manager.Provider as IRelatedDataSource;

            if (relatedDataSource == null)
            {
                return(Enumerable.Empty <IDataItem>().AsQueryable());
            }

            //// Тhe filter is adapted to the implementation of ILifecycleDataItemGeneric, so the culture is taken in advance when filtering published items.
            var filterExpression = ContentHelper.AdaptMultilingualFilterExpression(this.FilterExpression);
            int?skip             = (page - 1) * this.ItemsPerPage;

            var relatedItems = relatedDataSource.GetRelatedItems(this.RelatedItemType, this.RelatedItemProviderName, relatedItem.Id, this.RelatedFieldName, this.ContentType, ContentLifecycleStatus.Live, filterExpression, this.SortExpression, skip, this.ItemsPerPage, ref totalCount, this.RelationTypeToDisplay)
                               .OfType <IDataItem>();

            return(relatedItems);
        }