gpt4 book ai didi

orchardcms - Orchard 自定义工作流程事件

转载 作者:行者123 更新时间:2023-12-03 01:26:54 26 4
gpt4 key购买 nike

我在 Orchard 中构建了一个自定义模块,用于创建新的部件、类型和自定义事件,但我正在努力解决我需要做的最后一部分,即创建与 相关的所有内容项的副本特定的父项。

例如,当有人创建“贸易展览”(我的模块中的新类型)时,可以根据它创建各种子页面(方向、供应商 map 等),因为客户端一次运行一个展览。我需要做的是,当他们创建新的贸易展时,我想获取最近的先前展会(我通过 _contentManager.HqlQuery().ForType("TradeShow").ForVersion(VersionOptions 进行操作) .Latest).ForVersion(VersionOptions.Published).List().Last() (肯定这不是最有效的方法,但它有效,五年后记录数将约为 10),然后查找所有与旧节目相关的那些子页面并将它们复制到新的内容项中。它们必须是副本,因为有时他们可能必须引用旧节目的部分,或者它可能会发生变化,等等。所有常见的原因。

如何查找引用事件中先前节目的所有内容项?这是我的事件完整类(class):

using System;
using System.Collections.Generic;
using System.Linq;
using Orchard.Autoroute.Services;
using Orchard.ContentManagement;
using Orchard.Localization;
using Orchard.Projections.Models;
using Orchard.Projections.Services;
using Orchard.Workflows.Models;
using Orchard.Workflows.Services;
using Orchard.Workflows.Activities;

namespace Orchard.Web.Modules.TradeShows.Activities
{
public class TradeShowPublishedActivity : Task
{
private readonly IContentManager _contentManager;
private readonly IAutorouteService _autorouteService;
private readonly IProjectionManager _projectionManager;

public TradeShowPublishedActivity(IContentManager contentManager, IAutorouteService autorouteService, IProjectionManager projectionManager)
{
_contentManager = contentManager;
_autorouteService = autorouteService;
_projectionManager = projectionManager;

T = NullLocalizer.Instance;
}

public Localizer T { get; set; }

public override LocalizedString Category
{
get { return T("Flow"); }
}

public override LocalizedString Description
{
get { return T("Handles the automatic creation of content pages for the new show."); }
}

public override string Name
{
get { return "TradeShowPublished"; }
}

public override string Form
{
get { return null; }
}

public override IEnumerable<LocalizedString> GetPossibleOutcomes(WorkflowContext workflowContext, ActivityContext activityContext)
{
yield return T("Done");
}

public override IEnumerable<LocalizedString> Execute(WorkflowContext workflowContext, ActivityContext activityContext)
{
var priorShow = _contentManager.HqlQuery().ForType("TradeShow").ForVersion(VersionOptions.Latest).ForVersion(VersionOptions.Published).List().Last();
var tradeShowPart = priorShow.Parts.Where(p => p.PartDefinition.Name == "TradeShowContentPart").Single();

//new show alias
//workflowContext.Content.ContentItem.As<Orchard.Autoroute.Models.AutoroutePart>().DisplayAlias

yield return T("Done");
}
}

}

我的 Migrations.cs 文件设置了用于子页面引用父显示的部分,如下所示:

ContentDefinitionManager.AlterPartDefinition("AssociatedTradeShowPart", builder => builder.WithField("Trade Show", cfg => cfg.OfType("ContentPickerField")
.WithDisplayName("Trade Show")
.WithSetting("ContentPickerFieldSettings.Attachable", "true")
.WithSetting("ContentPickerFieldSettings.Description", "Select the trade show this item is for.")
.WithSetting("ContentPickerFieldSettings.Required", "true")
.WithSetting("ContentPickerFieldSettings.DisplayedContentTypes", "TradeShow")
.WithSetting("ContentPickerFieldSettings.Multiple", "false")
.WithSetting("ContentPickerFieldSettings.ShowContentTab", "true")));

然后,我的子页面(目前只有一个,但还会有更多)创建如下:

ContentDefinitionManager.AlterTypeDefinition("ShowDirections", cfg => cfg.DisplayedAs("Show Directions")
.WithPart("AutoroutePart", builder => builder.WithSetting("AutorouteSettings.AllowCustomPattern", "true")
.WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "false")
.WithSetting("AutorouteSettings.PatternDefinitions", "[{Name:'Title', Pattern: '{Content.Slug}', Description: 'international-trade-show'}]")
.WithSetting("AutorouteSettings.DefaultPatternIndex", "0"))
.WithPart("CommonPart", builder => builder.WithSetting("DateEditorSettings.ShowDateEditor", "false"))
.WithPart("PublishLaterPart")
.WithPart("TitlePart")
.WithPart("AssociatedTradeShowPart") /* allows linking to parent show */
.WithPart("ContainablePart", builder => builder.WithSetting("ContainablePartSettings.ShowContainerPicker", "true"))
.WithPart("BodyPart"));

最佳答案

因此,您拥有了贸易展览内容项,下一步将是查找具有 ContentPickerField 的所有部分,然后将该列表过滤到该字段包含您的展览 ID 的部分。

        var items = _contentManager.Query().List().ToList() // Select all content items
.Select(p => (p.Parts
// Select all parts on content items
.Where(f => f.Fields.Where(d =>
d.FieldDefinition.Name == typeof(ContentPickerField).Name &&
// See if any of the fields are ContentPickerFields
(d as ContentPickerField).Ids.ToList().Contains(priorShow.Id)).Any())));
// That field contains the Id of the show

这可能会变得昂贵,具体取决于数据库中有多少内容项。

关于orchardcms - Orchard 自定义工作流程事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27789293/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com