public IEnumerable <TreeNode> GetChildren(string nodeType, string nodeId)
        {
            switch (nodeType)
            {
            case "root":
                return(new[] {
                    GetContentTypesNode()
                });

            case "content-types":
                return(_contentManager.GetContentTypeDefinitions()
                       .Where(d => d.Settings.GetModel <ContentTypeSettings>().Creatable)
                       .OrderBy(d => d.DisplayName)
                       .Select(GetContentTypeNode));

            case "content-type":
                return(_contentManager
                       .Query(VersionOptions.Latest, nodeId)
                       .List()
                       .Where(i => !i.Has <CommonPart>() || i.As <CommonPart>().Container == null)
                       .Select(GetContentItemNode)
                       .OrderBy(i => i.Title));
            }
            if (nodeType.StartsWith("content-item-"))
            {
                var containerId = int.Parse(nodeId);
                return(_contentManager
                       .Query <CommonPart, CommonPartRecord>(VersionOptions.Latest)
                       .Where(i => i.Container.Id == containerId)
                       .List()
                       .Select(i => GetContentItemNode(i.ContentItem))
                       .OrderBy(i => i.Title));
            }
            return(new TreeNode[0]);
        }
        private IEnumerable <Property> GetContentTypeDefinition(string contentTypeName)
        {
            List <Property> properties             = new List <Property>();
            var             contentTypeDefinitions = _contentManager.GetContentTypeDefinitions().Where(c => c.Name == contentTypeName);

            foreach (var contentTypeDefinition in contentTypeDefinitions)
            {
                if (contentTypeDefinition.Parts != null)
                {
                    var part = contentTypeDefinition.Parts.SingleOrDefault(p => p.PartDefinition.Name == contentTypeName);
                    if (part != null)
                    {
                        var fields = part.PartDefinition.Fields;
                        if (fields != null)
                        {
                            foreach (var field in fields)
                            {
                                properties.Add(new Property
                                {
                                    PropertyName = field.Name,
                                    DisplayName  = field.DisplayName,
                                    PropertyType = GetPropertyType(field),
                                    Required     = GetRequired(field)
                                });
                            }
                        }
                    }
                }
            }
            return(properties);
        }
示例#3
0
        public IEnumerable <LayoutPart> GetTemplates()
        {
            var templateTypeNamesQuery = from typeDefinition in _contentManager.GetContentTypeDefinitions()
                                         from typePartDefinition in typeDefinition.Parts
                                         let settings = typePartDefinition.Settings.GetModel <LayoutTypePartSettings>()
                                                        where settings.IsTemplate
                                                        select typeDefinition.Name;

            var templateTypeNames = templateTypeNamesQuery.ToArray();

            return(_contentManager.Query <LayoutPart>(templateTypeNames).List());
        }
示例#4
0
        public string GetContentExportFilePath()
        {
            var settings     = _orchardServices.WorkContext.CurrentSite.As <ContentSyncSettingsPart>();
            var contentTypes = _contentManager.GetContentTypeDefinitions().Select(ctd => ctd.Name).Except(settings.ExcludedContentTypes).ToList();
            var customSteps  = new List <string>();

            _customExportStep.Register(customSteps);
            customSteps = customSteps.Except(settings.ExcludedExportSteps).ToList();

            var exportActionContext = new ExportActionContext();
            var buildRecipeAction   = Resolve <BuildRecipeAction>(action =>
            {
                action.RecipeBuilderSteps = new List <IRecipeBuilderStep>
                {
                    Resolve <ContentStep>(contentStep =>
                    {
                        contentStep.SchemaContentTypes    = contentTypes;
                        contentStep.DataContentTypes      = contentTypes;
                        contentStep.VersionHistoryOptions = Orchard.Recipes.Models.VersionHistoryOptions.Published;
                    }),
                    Resolve <CustomStepsStep>(customStepsStep => customStepsStep.CustomSteps = customSteps),
                    Resolve <SettingsStep>()
                };
            });

            _importExportService.Export(exportActionContext, new IExportAction[] { buildRecipeAction });
            return(_importExportService.WriteExportFile(exportActionContext.RecipeDocument));
        }
        public void GetContentTypesShouldReturnAllTypes()
        {
            // Register the types and obtain them
            ContentTypeDefinition alphaType = new ContentTypeDefinitionBuilder()
                                              .Named(DefaultAlphaName)
                                              .Build();

            ContentTypeDefinition betaType = new ContentTypeDefinitionBuilder()
                                             .Named(DefaultBetaName)
                                             .Build();

            ContentTypeDefinition gammaType = new ContentTypeDefinitionBuilder()
                                              .Named(DefaultGammaName)
                                              .Build();

            ContentTypeDefinition deltaType = new ContentTypeDefinitionBuilder()
                                              .Named(DefaultDeltaName)
                                              .Build();

            _contentDefinitionManager.Setup(contentDefinitionManager => contentDefinitionManager.ListTypeDefinitions())
            .Returns(new List <ContentTypeDefinition> {
                alphaType, betaType, gammaType, deltaType
            });

            var types = _manager.GetContentTypeDefinitions();

            // Validate that the expected types were obtained
            Assert.That(types.Count(), Is.EqualTo(4));
            Assert.That(types, Has.Some.With.Property("Name").EqualTo(DefaultAlphaName));
            Assert.That(types, Has.Some.With.Property("Name").EqualTo(DefaultBetaName));
            Assert.That(types, Has.Some.With.Property("Name").EqualTo(DefaultGammaName));
            Assert.That(types, Has.Some.With.Property("Name").EqualTo(DefaultDeltaName));
        }
        protected override DriverResult Editor(TitlePart part, IUpdateModel updater, dynamic shapeHelper)
        {
            if (!part.ContentItem.Has <ShapePart>())
            {
                return(null);
            }

            updater.TryUpdateModel(part, Prefix, null, null);

            // We need to query for the content type names because querying for content parts has no effect on the database side.
            var contentTypesWithShapePart = _contentManager
                                            .GetContentTypeDefinitions()
                                            .Where(typeDefinition => typeDefinition.Parts.Any(partDefinition => partDefinition.PartDefinition.Name == "ShapePart"))
                                            .Select(typeDefinition => typeDefinition.Name);

            // If ShapePart is only dynamically added to this content type or even this content item then we won't find
            // a corresponding content type definition, so using the current content type too.
            contentTypesWithShapePart = contentTypesWithShapePart.Union(new[] { part.ContentItem.ContentType });

            var existingShapeCount = _contentManager
                                     .Query(VersionOptions.Latest, contentTypesWithShapePart.ToArray())
                                     .Where <TitlePartRecord>(record => record.Title == part.Title && record.ContentItemRecord.Id != part.ContentItem.Id)
                                     .Count();

            if (existingShapeCount > 0)
            {
                updater.AddModelError("ShapeNameAlreadyExists", T("A template with the given name already exists."));
            }

            return(null);
        }
        public ActionResult EditPOST(int id)
        {
            if (!_orchardServices.Authorizer.Authorize(Permissions.ManageContact))
            {
                return(new HttpUnauthorizedResult());
            }

            var  typeDef   = _contentManager.GetContentTypeDefinitions().FirstOrDefault(x => x.Name == contentType);
            bool draftable = typeDef.Settings.GetModel <ContentTypeSettings>().Draftable;

            ContentItem content;

            if (id == 0)
            {
                var newContent = _contentManager.New(contentType);
                // crea sempre in draft per poter pubblicare dopo la valorizzazione dei campi,
                // in modo da aggiornare i dati nelle tabelle fieldIndexRecord
                _contentManager.Create(newContent, VersionOptions.Draft);
                content = newContent;
            }
            else
            {
                content = _contentManager.Get(id);
                // verifica che il contact non sia legato a un utente
                if (content.As <CommunicationContactPart>().UserIdentifier != 0)
                {
                    return(new HttpUnauthorizedResult());
                }
                // forza published a false per poter pubblicare dopo la valorizzazione dei campi,
                // in modo da aggiornare i dati nelle tabelle fieldIndexRecord
                content.VersionRecord.Published = false;
            }

            var model = _contentManager.UpdateEditor(content, this);

            if (!ModelState.IsValid)
            {
                foreach (string key in ModelState.Keys)
                {
                    if (ModelState[key].Errors.Count > 0)
                    {
                        foreach (var error in ModelState[key].Errors)
                        {
                            _notifier.Add(NotifyType.Error, T(error.ErrorMessage));
                        }
                    }
                }
                _orchardServices.TransactionManager.Cancel();
                return(View(model));
            }
            else
            {
                if (!draftable)
                {
                    _contentManager.Publish(content);
                }
            }
            _notifier.Add(NotifyType.Information, T("Contact saved"));
            return(RedirectToAction("Edit", new { id = content.Id }));
        }
示例#8
0
        public IEnumerable <IndexSettingsModel> GetIndexSettings()
        {
            var settings = _cacheManager.Get <string, IEnumerable <IndexSettingsModel> >("Digic.Sitemap.IndexSettings",
                                                                                         ctx =>
            {
                var contentTypes = _contentManager.GetContentTypeDefinitions()
                                   .Where(ctd => ctd.Parts.FirstOrDefault(p => p.PartDefinition.Name == "AutoroutePart") != null)
                                   .ToList();

                var typeNames = contentTypes.Select(t => t.Name).ToArray();

                // Delete everything that no longer corresponds to these allowed content types
                var toDelete = _settingsRepository.Fetch(q => !typeNames.Contains(q.ContentType)).ToList();
                foreach (var record in toDelete)
                {
                    _settingsRepository.Delete(record);
                }
                _settingsRepository.Flush();



                var contentSettings = new List <IndexSettingsModel>();
                foreach (var type in contentTypes)
                {
                    var _type = type;
                    // Get the record, generate a new one if it doesn't exist.
                    SitemapSettingsRecord record = _settingsRepository.Fetch(q => q.ContentType == _type.Name).FirstOrDefault();
                    if (record == null)
                    {
                        record                 = new SitemapSettingsRecord();
                        record.ContentType     = type.Name;
                        record.IndexForDisplay = false;
                        record.IndexForXml     = false;
                        record.Priority        = 3;
                        record.UpdateFrequency = "weekly";
                        _settingsRepository.Create(record);
                    }

                    var model = new IndexSettingsModel()
                    {
                        DisplayName     = type.DisplayName,
                        Name            = type.Name,
                        IndexForDisplay = record.IndexForDisplay,
                        IndexForXml     = record.IndexForXml,
                        Priority        = record.Priority,
                        UpdateFrequency = record.UpdateFrequency
                    };
                    contentSettings.Add(model);
                }


                ctx.Monitor(_signals.When("ContentDefinitionManager"));
                ctx.Monitor(_signals.When("Digic.Sitemap.IndexSettings"));

                return(contentSettings);
            });

            return(settings);
        }
示例#9
0
 public IEnumerable <Tuple <string, string> > GetWidgetTypes()
 {
     return(_contentManager.GetContentTypeDefinitions()
            .Where(contentTypeDefinition => contentTypeDefinition.Settings.ContainsKey("Stereotype") && contentTypeDefinition.Settings["Stereotype"] == "Widget")
            .Select(contentTypeDefinition =>
                    Tuple.Create(
                        contentTypeDefinition.Name,
                        contentTypeDefinition.Settings.ContainsKey("Description") ? contentTypeDefinition.Settings["Description"] : null)));
 }
        private string[] GetMenuWidgetContentTypes()
        {
            var query =
                from typeDefinition in _contentManager.GetContentTypeDefinitions()
                from part in typeDefinition.Parts
                where  part.PartDefinition.Name == typeof(MenuWidgetPart).Name
                select typeDefinition.Name;

            return(query.ToArray());
        }
示例#11
0
        public IList <ContentTypeDefinition> GetForumTypes()
        {
            var name = typeof(ForumPart).Name;

            return(_contentManager
                   .GetContentTypeDefinitions()
                   .Where(x =>
                          x.Parts.Any(p => p.PartDefinition.Name == name))
                   .Select(x => x)
                   .ToList());
        }
 public IEnumerable <MenuItemDescriptor> GetMenuItemTypes()
 {
     return(_contentManager.GetContentTypeDefinitions()
            .Where(contentTypeDefinition => contentTypeDefinition.Settings.ContainsKey("Stereotype") && contentTypeDefinition.Settings["Stereotype"] == "MenuItem")
            .Select(contentTypeDefinition =>
                    new MenuItemDescriptor {
         Type = contentTypeDefinition.Name,
         DisplayName = contentTypeDefinition.DisplayName,
         Description = contentTypeDefinition.Settings.ContainsKey("Description") ? contentTypeDefinition.Settings["Description"] : null
     }));
 }
示例#13
0
        public IEnumerable <ITax> GetTaxes()
        {
            var taxTypes = _contentManager
                           .GetContentTypeDefinitions()
                           .Where(d => d.Parts.Any(p => p.PartDefinition.Name == "ZipCodeTaxPart"))
                           .Select(d => d.Name)
                           .ToArray();

            return(_contentManager
                   .Query <ZipCodeTaxPart>(taxTypes)
                   .ForVersion(VersionOptions.Published)
                   .List());
        }
示例#14
0
 public IEnumerable <string> GetContentTypes()
 {
     try
     {
         var contentTypes = _contentManager.GetContentTypeDefinitions();
         return(from c in contentTypes
                select c.Name);
     }
     catch (Exception ex)
     {
         Logger.Error(ex, "An error occurred while get content types.");
         throw;
     }
 }
        public void Describe(DescribeContext context)
        {
            context.For("Content", T("Content Items"), T("Content Items"))
            .Token("Id", T("Content Id"), T("Numeric primary key value of content."))
            .Token("Author", T("Content Author"), T("Person in charge of the content."), "User")
            .Token("Date", T("Content Date"), T("Date the content was created."), "DateTime")
            .Token("Identity", T("Identity"), T("Identity of the content."))
            .Token("ContentType", T("Content Type"), T("The name of the item Content Type."), "TypeDefinition")
            .Token("DisplayText", T("Display Text"), T("Title of the content."), "Text")
            .Token("DisplayUrl", T("Display Url"), T("Url to display the content."), "Url")
            .Token("EditUrl", T("Edit Url"), T("Url to edit the content."), "Url")
            .Token("Container", T("Container"), T("The container Content Item."), "Content")
            .Token("Body", T("Body"), T("The body text of the content item."), "Text")
            ;

            // Token descriptors for fields
            foreach (var typeDefinition in _contentManager.GetContentTypeDefinitions())
            {
                foreach (var typePart in typeDefinition.Parts)
                {
                    if (!typePart.PartDefinition.Fields.Any())
                    {
                        continue;
                    }

                    var partContext = context.For("Content");
                    foreach (var partField in typePart.PartDefinition.Fields)
                    {
                        var field     = partField;
                        var tokenName = "Fields." + typePart.PartDefinition.Name + "." + field.Name;

                        // the token is chained with the technical name
                        partContext.Token(tokenName, T("{0} {1}", typePart.PartDefinition.Name, field.Name), T("The content of the {0} field.", partField.DisplayName), field.Name);
                    }
                }
            }

            context.For("TextField", T("Text Field"), T("Tokens for Text Fields"))
            .Token("Length", T("Length"), T("The length of the field."));

            context.For("Url", T("Url"), T("Tokens for Urls"))
            .Token("Absolute", T("Absolute"), T("Absolute url."), "Text");

            context.For("TypeDefinition", T("Type Definition"), T("Tokens for Content Types"))
            .Token("Name", T("Name"), T("Name of the content type."))
            .Token("DisplayName", T("Display Name"), T("Display name of the content type."), "Text")
            .Token("Parts", T("Parts"), T("List of the attached part names."))
            .Token("Fields", T("Fields"), T("Fields for each of the attached parts. For example, Fields.Page.Approved."));
        }
示例#16
0
 public IEnumerable <SelectListItem> ContentTypeOptions(string[] selectedTypes)
 {
     foreach (var type in _contentManager.GetContentTypeDefinitions())
     {
         if (type.Parts.Any(p => p.PartDefinition.Name.Equals("AutoroutePart")))
         {
             yield return(new SelectListItem
             {
                 Text = type.DisplayName,
                 Value = type.Name,
                 Selected = selectedTypes.Contains(type.Name)
             });
         }
     }
 }
示例#17
0
        public string GetContentExportFilePath()
        {
            var settings = _orchardServices.WorkContext.CurrentSite.As <ContentSyncSettingsPart>();

            var contentTypes = _contentManager.GetContentTypeDefinitions().Select(ctd => ctd.Name).Except(settings.ExcludedContentTypes).ToList();

            var customSteps = new List <string>();

            _customExportStep.Register(customSteps);
            customSteps = customSteps.Except(settings.ExcludedExportSteps).ToList();

            return(_importExportService.Export(contentTypes, new ExportOptions {
                CustomSteps = customSteps, ExportData = true, ExportMetadata = true, ExportSiteSettings = false, VersionHistoryOptions = VersionHistoryOptions.Published
            }));
        }
示例#18
0
        public void Exporting(ExportContext context)
        {
            if (!context.ExportOptions.CustomSteps.Contains("ContentTrim"))
            {
                return;
            }

            var xmlElement          = new XElement("ContentTrim");
            var contentTypesElement = new XElement("ContentTypes");

            var settings = _orchardServices.WorkContext.CurrentSite.As <ContentSyncSettingsPart>();

            var contentTypeNames = _contentManager.GetContentTypeDefinitions().Select(ctd => ctd.Name).Except(settings.ExcludedContentTypes).ToList();

            foreach (var contentType in contentTypeNames)
            {
                contentTypesElement.Add(new XElement("add", new XAttribute("type", contentType)));
            }

            xmlElement.Add(contentTypesElement);

            var contentToKeepElement = new XElement("ContentToKeep");

            foreach (var identityPart in _contentManager.Query <IdentityPart>(contentTypeNames.ToArray()).List())
            {
                contentToKeepElement.Add(new XElement("add", new XAttribute("identifier", identityPart.Identifier)));
            }

            xmlElement.Add(contentToKeepElement);

            var rootElement = context.Document.Descendants("Orchard").FirstOrDefault();

            if (rootElement == null)
            {
                var ex = new OrchardException(T("Could not export the content to trim because the document passed via the Export Context did not contain a node called 'Orchard'. The document was malformed."));
                Logger.Error(ex, ex.Message);
                throw ex;
            }

            rootElement.Add(xmlElement);
        }
示例#19
0
        protected override DriverResult Editor(ContentSyncSettingsPart part, dynamic shapeHelper)
        {
            return(ContentShape("Parts_ContentSyncSettings_Edit",
                                () => {
                var customSteps = new List <string>();
                _customExportSteps.Register(customSteps);

                part.AllContentTypes = _contentManager.GetContentTypeDefinitions().OrderBy(ctd => ctd.Name).Select(ctd => new SelectableItem <string> {
                    Item = ctd.Name, IsSelected = part.ExcludedContentTypes.Contains(ctd.Name)
                }).ToList();
                part.AllExportSteps = customSteps.OrderBy(n => n).Select(cs => new SelectableItem <string> {
                    Item = cs, IsSelected = part.ExcludedExportSteps.Contains(cs)
                }).ToList();
                part.AllSiteSettings = GetExportableSettings().OrderBy(n => n).Select(p => new SelectableItem <string> {
                    Item = p, IsSelected = part.ExcludedSiteSettings.Contains(p)
                }).ToList();

                return shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: part, Prefix: Prefix);
            })
                   .OnGroup("Content Sync"));
        }
示例#20
0
 public ContentTypeDefinition GetContentTypeDefinition(string type)
 {
     return((from t in _contentManager.GetContentTypeDefinitions()
             where t.Name == type
             select t).FirstOrDefault());
 }
示例#21
0
 public IEnumerable <ContentTypeDefinition> GetAllTermTypes()
 {
     return(_contentManager.GetContentTypeDefinitions().Where(t => t.Parts.Any(p => p.PartDefinition.Name.Equals(typeof(TermPart).Name))));
 }
 public IEnumerable <string> GetObjectiveContentTypes()
 {
     return(_contentManager.GetContentTypeDefinitions()
            .Where(contentDefinition => contentDefinition.Parts.Any(part => part.PartDefinition.Name == "ObjectivePart"))
            .Select(contentDefinition => contentDefinition.Name));
 }