예제 #1
0
        internal void AddEditInfo(Eav.Interfaces.IEntity entity, Dictionary <string, object> dictionary)
        {
            // Add additional information in case we're in edit mode
            var userMayEdit = Sxc?.UserMayEdit ?? false;    // Factory.Resolve<IPermissions>().UserMayEditContent(Sxc?.InstanceInfo);

            if (!userMayEdit)
            {
                return;
            }

            dictionary.Add(Constants.JsonModifiedNodeName, entity.Modified);
            var title = entity.GetBestTitle(Languages);

            if (string.IsNullOrEmpty(title))
            {
                title = "(no title)";
            }
            dictionary.Add(Constants.JsonEntityEditNodeName, entity is IHasEditingData
                    ? (object)new {
                sortOrder   = ((IHasEditingData)entity).SortOrder,
                isPublished = entity.IsPublished,
            }
                    : new {
                entityId = entity.EntityId,
                title,
                isPublished = entity.IsPublished,
            });
        }
예제 #2
0
 public ContentGroup(Eav.Interfaces.IEntity contentGroupEntity, int zoneId, int appId, bool showDrafts, bool versioningEnabled, Log parentLog) : base("CG.Group", parentLog)
 {
     _contentGroupEntity = contentGroupEntity ?? throw new Exception("ContentGroup entity is null. This usually happens when you are duplicating a site, and have not yet imported the other content/apps. If that is your issue, check 2sxc.org/help?tag=export-import");
     _zoneId             = zoneId;
     _appId             = appId;
     _showDrafts        = showDrafts;
     _versioningEnabled = versioningEnabled;
 }
        => UpdateValue(EntityContentBlock.CbPropertyContentGroup, cgGuid.ToString());     // must pre-convert to string, as it's not a reference to an entity in the same app


        internal override void UpdateTitle(Eav.Interfaces.IEntity titleItem)
        {
            if (titleItem?.GetBestTitle() == null)
            {
                return;
            }
            UpdateValue(EntityContentBlock.CbPropertyTitle, titleItem.GetBestTitle());
        }
예제 #4
0
 /// <summary>
 /// Gets a string that represents all entities joined with a comma , separator
 /// Does just include String and Number fields
 /// </summary>
 /// <param name="entity"></param>
 /// <param name="language"></param>
 /// <returns></returns>
 private string GetJoinedAttributes(Eav.Interfaces.IEntity entity, string language)
 {
     return(string.Join(", ",
                        entity.Attributes.Where(x => x.Value.Type == "String" || x.Value.Type == "Number").Select(x => x.Value[language])
                        .Where(a => a != null)
                        .Select(a => StripHtmlAndHtmlDecode(a.ToString()))
                        .Where(x => !String.IsNullOrEmpty(x))) + " ");
 }
예제 #5
0
        /// <summary>
        /// Provides an Adam instance for this item and field
        /// </summary>
        /// <param name="entity">The entity, often Content or similar</param>
        /// <param name="fieldName">The field name, like "Gallery" or "Pics"</param>
        /// <returns>An Adam object for navigating the assets</returns>
        public FolderOfField AsAdam(Eav.Interfaces.IEntity entity, string fieldName)
        {
            var envFs = Factory.Resolve <IEnvironmentFileSystem>();

            if (_adamAppContext == null)
            {
                _adamAppContext = new AdamAppContext(_tenant, App, SxcInstance, Log);
            }
            return(new FolderOfField(envFs, _adamAppContext, entity.EntityGuid, fieldName));
        }
예제 #6
0
        internal Dictionary <string, object> PrepareOldFormat(Eav.Interfaces.IEntity entity)
        {
            // var ser = new Serializer(SxcInstance, _dimensions);
            var dicNew         = GetDictionaryFromEntity(entity);
            var dicToSerialize = ConvertNewSerRelToOldSerRel(dicNew);

            dicToSerialize.Add(Constants.JsonEntityIdNodeName, entity.EntityId);

            return(dicToSerialize);
        }
예제 #7
0
        public override Dictionary <string, object> GetDictionaryFromEntity(Eav.Interfaces.IEntity entity)
        {
            // Do groundwork
            var dictionary = base.GetDictionaryFromEntity(entity);

            AddPresentation(entity, dictionary);
            AddEditInfo(entity, dictionary);

            return(dictionary);
        }
예제 #8
0
        private void _constructor(IContentBlock parent, Eav.Interfaces.IEntity cbDefinition)
        {
            Parent = parent;
            ParseContentBlockDefinition(cbDefinition);
            ParentId       = parent.ParentId;
            ContentBlockId = -cbDefinition.EntityId;

            // Ensure we know what portal the stuff is coming from
            Tenant = Parent.App.Tenant;

            ZoneId = Parent.ZoneId;

            AppId = AppHelpers.GetAppIdFromGuidName(ZoneId, _appName); // should be 0 if unknown, must test

            if (AppId == Settings.DataIsMissingInDb)
            {
                _dataIsMissing = true;
                return;
            }

            // 2018-09-22 new, must come before the AppId == 0 check
            SxcInstance = new SxcInstance(this, Parent.SxcInstance.EnvInstance, Parent.SxcInstance.Parameters, Log);

            if (AppId == 0)
            {
                return;
            }

            // 2018-09-22 old
            // try to load the app - if possible
            //App = new App(Tenant, ZoneId, AppId);

            //Configuration = ConfigurationProvider.GetConfigProviderForModule(ParentId, App, SxcInstance);

            // maybe ensure that App.Data is ready
            //var userMayEdit = SxcInstance.UserMayEdit;
            //var publishingEnabled = SxcInstance.Environment.PagePublishing.IsEnabled(Parent.SxcInstance.EnvInstance.Id);
            //App.InitData(userMayEdit, publishingEnabled, Configuration);

            // 2018-09-22 new
            App = new App(Tenant, ZoneId, AppId, ConfigurationProvider.Build(SxcInstance, false), true, Log);

            ContentGroup = App.ContentGroupManager.GetContentGroupOrGeneratePreview(_contentGroupGuid, _previewTemplateGuid);

            // handle cases where the content group is missing - usually because of uncomplete import
            if (ContentGroup.DataIsMissing)
            {
                _dataIsMissing = true;
                App            = null;
                return;
            }

            // use the content-group template, which already covers stored data + module-level stored settings
            SxcInstance.SetTemplateOrOverrideFromUrl(ContentGroup.Template);
        }
예제 #9
0
 internal void AddPresentation(Eav.Interfaces.IEntity entity, Dictionary <string, object> dictionary)
 {
     // Add full presentation object if it has one...because there we need more than just id/title
     if (entity is EntityInContentGroup && !dictionary.ContainsKey(AppConstants.Presentation))
     {
         var entityInGroup = (EntityInContentGroup)entity;
         if (entityInGroup.Presentation != null)
         {
             dictionary.Add(AppConstants.Presentation, GetDictionaryFromEntity(entityInGroup.Presentation));    //, language));
         }
     }
 }
예제 #10
0
        public void UpdateTitle(SxcInstance sxcInstance, Eav.Interfaces.IEntity titleItem)
        {
            Log.Add("update title");

            var languages = sxcInstance.Environment.ZoneMapper.CulturesWithState(sxcInstance.EnvInstance.TenantId,
                                                                                 sxcInstance.ZoneId.Value);

            // Find Module for default language
            var moduleController = new ModuleController();
            var originalModule   = moduleController.GetModule(sxcInstance.EnvInstance.Id);

            foreach (var dimension in languages)
            {
                if (!originalModule.IsDefaultLanguage)
                {
                    originalModule = originalModule.DefaultLanguageModule;
                }

                try // this can sometimes fail, like if the first item is null - https://github.com/2sic/2sxc/issues/817
                {
                    // Break if default language module is null
                    if (originalModule == null)
                    {
                        return;
                    }

                    // Get Title value of Entitiy in current language
                    var titleValue = titleItem.Title[dimension.Key].ToString();

                    // Find module for given Culture
                    var moduleByCulture = moduleController.GetModuleByCulture(originalModule.ModuleID,
                                                                              originalModule.TabID, sxcInstance.EnvInstance.TenantId,
                                                                              DotNetNuke.Services.Localization.LocaleController.Instance.GetLocale(dimension.Key));

                    // Break if no title module found
                    if (moduleByCulture == null || titleValue == null)
                    {
                        return;
                    }

                    moduleByCulture.ModuleTitle = titleValue;
                    moduleController.UpdateModule(moduleByCulture);
                }
                catch
                {
                    // ignored
                }
            }
        }
예제 #11
0
        private void _constructor(IContentBlock parent, Eav.Interfaces.IEntity cbDefinition)
        {
            Parent = parent;
            ParseContentBlockDefinition(cbDefinition);
            ParentId       = parent.ParentId;
            ContentBlockId = -cbDefinition.EntityId; // "mod:" + ParentId +  "-ent:" + cbDefinition.EntityId;


            // Ensure we know what portal the stuff is coming from
            PortalSettings = Parent.App.OwnerPortalSettings;

            ZoneId = Parent.ZoneId;


            AppId = AppHelpers.GetAppIdFromGuidName(ZoneId, _appName); // should be 0 if unknown, must test

            if (AppId == Settings.DataIsMissingInDb)
            {
                _dataIsMissing = true;
                return;
            }

            if (AppId != 0)
            {
                // try to load the app - if possible
                App = new App(ZoneId, AppId, PortalSettings);

                Configuration = ConfigurationProvider.GetConfigProviderForModule(ParentId, App, SxcInstance);

                // maybe ensure that App.Data is ready
                App.InitData(SxcInstance.Environment.Permissions.UserMayEditContent, SxcInstance.Environment.PagePublishing /*new Environment.Dnn7.PagePublishing(Log)*/.IsEnabled(Parent.SxcInstance.ModuleInfo.ModuleID), Configuration /* Data.ConfigurationProvider*/);

                ContentGroup = App.ContentGroupManager.GetContentGroupOrGeneratePreview(_contentGroupGuid, _previewTemplateGuid);

                // handle cases where the content group is missing - usually because of uncomplete import
                if (ContentGroup.DataIsMissing)
                {
                    _dataIsMissing = true;
                    App            = null;
                    return;
                }

                // use the content-group template, which already covers stored data + module-level stored settings
                //Template = ContentGroup.Template;
                SxcInstance.SetTemplateOrOverrideFromUrl(ContentGroup.Template);
            }
        }
예제 #12
0
파일: Simple.cs 프로젝트: webworkadmin/2sxc
        internal static IHtmlString Render(IContentBlock parentCb, Eav.Interfaces.IEntity entity, Log parentLog)
        {
            var log = new Log("Htm.Render", parentLog, "simple");

            // if not the expected content-type, just output a hidden html placeholder
            if (entity.Type.Name != Settings.AttributeSetStaticNameContentBlockTypeName)
            {
                log.Add("empty, will return hidden html placeholder");
                return(new HtmlString(string.Format(EmptyMessage, entity.EntityId)));
            }

            // render it
            log.Add("found, will render");
            var cb = new EntityContentBlock(parentCb, entity, log);

            return(cb.SxcInstance.Render());
        }
예제 #13
0
        private Element GetElementFromEntity(Eav.Interfaces.IEntity e)
        {
            var el = new Element
            {
                EntityId = e.EntityId,
                Content  = AsDynamic(e)
            };

            if (e is EntityInContentGroup)
            {
                var c = ((EntityInContentGroup)e);
                el.GroupId      = c.GroupId;
                el.Presentation = c.Presentation == null ? null : AsDynamic(c.Presentation);
                el.SortOrder    = c.SortOrder;
            }

            return(el);
        }
예제 #14
0
        private void ParseContentBlockDefinition(Eav.Interfaces.IEntity cbDefinition)
        {
            ContentBlockEntity = cbDefinition;
            _appName           = ContentBlockEntity.GetBestValue(CbPropertyApp)?.ToString() ?? "";

            string temp = ContentBlockEntity.GetBestValue(CbPropertyContentGroup)?.ToString() ?? "";

            Guid.TryParse(temp, out _contentGroupGuid);

            temp = ContentBlockEntity.GetBestValue(CbPropertyTemplate)?.ToString() ?? "";
            Guid.TryParse(temp, out _previewTemplateGuid);

            temp = ContentBlockEntity.GetBestValue(CbPropertyShowChooser)?.ToString() ?? "";
            bool show;

            if (bool.TryParse(temp, out show))
            {
                ShowTemplateChooser = show;
            }
        }
예제 #15
0
        private void SaveChangedLists(Dictionary <string, List <int?> > values)
        {
            // ensure that there are never more presentations than values
            if (values.ContainsKey(AppConstants.Presentation))
            {
                var contentCount = Content.Count;
                if (values.ContainsKey(AppConstants.Content))
                {
                    contentCount = values[AppConstants.Content].Count;
                }
                if (values[AppConstants.Presentation].Count > contentCount)
                {
                    throw new Exception("Presentation may not contain more items than Content.");
                }
            }

            // 2017-04-01 2dm centralizing eav access
            var dicObj   = values.ToDictionary(x => x.Key, x => x.Value as object);
            var newEnt   = new Entity(_appId, 0, _contentGroupEntity.Type, dicObj);
            var saveOpts = SaveOptions.Build(_zoneId);

            saveOpts.PreserveUntouchedAttributes = true;

            var saveEnt = new EntitySaver(Log).CreateMergedForSaving(_contentGroupEntity, newEnt, saveOpts);

            if (_versioningEnabled)
            {
                // Force saving as draft if needed (if versioning is enabled)
                ((Entity)saveEnt).PlaceDraftInBranch = true;
                ((Entity)saveEnt).IsPublished        = false;
            }

            new AppManager(_zoneId, _appId).Entities.Save(saveEnt, saveOpts);

            // Refresh content group entity (ensures contentgroup is up to date)
            _contentGroupEntity = new ContentGroupManager(_zoneId, _appId, _showDrafts, _versioningEnabled, Log).GetContentGroup(_contentGroupEntity.EntityGuid)._contentGroupEntity;
        }
예제 #16
0
 /// <summary>
 /// Provides an Adam instance for this item and field
 /// </summary>
 /// <param name="entity">The entity, often Content or similar</param>
 /// <param name="fieldName">The field name, like "Gallery" or "Pics"</param>
 /// <returns>An Adam object for navigating the assets</returns>
 public AdamNavigator AsAdam(Eav.Interfaces.IEntity entity, string fieldName)
 => new AdamNavigator(_sxcInstance, App, Dnn.Portal, entity.EntityGuid, fieldName, false);
 internal override void UpdateTitle(Eav.Interfaces.IEntity titleItem)
 {
     Log.Add("update title");
     Factory.Resolve <IMapAppToInstance>().UpdateTitle(SxcContext, titleItem);
 }
예제 #18
0
 /// <inheritdoc />
 /// <summary>
 /// Transform a IEntity to a DynamicEntity as dynamic object
 /// </summary>
 /// <param name="entity"></param>
 /// <returns></returns>
 public dynamic AsDynamic(Eav.Interfaces.IEntity entity) => new DynamicEntity(entity, new[] { Thread.CurrentThread.CurrentCulture.Name }, SxcInstance);
예제 #19
0
        }                                           // must be internal for further use cases

        /// <summary>
        /// Constructor with EntityModel and DimensionIds
        /// </summary>
        public DynamicEntity(Eav.Interfaces.IEntity entityModel, string[] dimensions, SxcInstance sexy)
        {
            Entity      = entityModel;
            _dimensions = dimensions;
            SxcInstance = sexy;
        }
 internal abstract void UpdateTitle(Eav.Interfaces.IEntity titleItem);
예제 #21
0
 public EntityContentBlock(IContentBlock parent, Eav.Interfaces.IEntity cbDefinition, Log parentLog = null) : base(parentLog, "CB.Ent")
     => _constructor(parent, cbDefinition);
예제 #22
0
 public dynamic AsDynamic(Eav.Interfaces.IEntity entity)
 => throw new Exception($"AsDynamic(Eav.Interfaces.IEntity) {NotSupportedIn10}. Please cast your data to ToSic.Eav.Data.IEntity.");
예제 #23
0
 public EntityInContentGroup(Eav.Interfaces.IEntity baseEntity) : base(baseEntity)
 {
 }