果园连接件 [英] Orchard connected parts

查看:65
本文介绍了果园连接件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个复杂的场景,正在尝试使用Orchard CMS零件进行建模.

现在这里是简化版本,可以阐明我的问题.

我有一个零件名称,例如,PersonPart只有一个属性:名称. 我还有另一个包含人员角色的部分,将其命名为PersonRolePart,并且只有一个属性Role

在果园中,我创建了所有适当的管道(处理程序,驱动程序,视图...)

在迁移中,我创建了一个名为Person的新内容类型,其中包含两个部分.

ContentDefinitionManager.AlterTypeDefinition("Person", cfg => cfg
                       .WithPart("PersonPart")
                       .WithPart("PersonRolePart")
                       .WithPart("CommonPart")
                       .Creatable(false)  );

到目前为止,我可以创建一个新人员并编辑两个部分.

我拥有的另一部分是ServicePart,该ServicePart绑定到上面定义的PersonRoleParts中.

现在的问题:

出于报告目的,我需要按PersonRole获取所有服务,并获取属于该角色的人员详细信息,或者换句话说,获取在上面定义的Person复合类型中使用的所有(实际上只有一个)PersonPart.

该怎么做?

现在在非果园世界中,我将在2之间建立简单的1:1关系.

到目前为止,我(失败的)尝试是将PersonRoleRecord_Id字段添加到PersonPartRecord,将PersonRecord_Id添加到Person角色...但是我不知道如何设置驱动程序或处理程序上的ID,因为两者都只能看到自己的部分.

是否可以从驱动程序获取内容类型中其他伙伴的实例?

无法合并人员和角色.场景比这还要复杂,我需要相同的Person部分和3个不同的Role-like部分以用于不同的目的,并且我希望避免重复3次重复的Common Person数据.

另一个想法是创建一个合适的处理程序,但是我不知道如何为虚拟内容类型创建一个处理程序,就像我做的那样.

解决方案

我已设法使用针对另一个问题的建议来解决该问题,该问题解决了另一个问题(验证). 果园CMS-确定模型在内容中是否有效项目驱动程序

所以我的解决方案是在两者上都添加一个处理程序,然后对该部分进行强制转换,并为其他部分设置适当的引用.

        OnPublishing<PersonPart>((context, part) =>{
            var person = part.As<PersonPart>();
            var role= part.As<PersonRolePart>();
            if (person != null && role != null) {
                if (role.Person == null) {
                    role.Person = person.Record;
                }
            }
        });

在这种特定情况下,因为它是1:1的关系,所以我只使用组合部分,两个ID都是相同的,至少如果角色只是一种类型. 我将看到何时创建更多类似角色的部分.

I have a complex scenario that I'm trying to model using Orchard CMS parts.

Now here it is the simplified version to make clear my question.

I have a part name, as example, PersonPart that has just one property: Name. I have another part that contains the person role, name it PersonRolePart and has just one property, Role

In Orchard I have created all the appropriate plumbing (Handlers, Drivers, Views...)

In migrations I created a new content type named Person that contains the two parts.

ContentDefinitionManager.AlterTypeDefinition("Person", cfg => cfg
                       .WithPart("PersonPart")
                       .WithPart("PersonRolePart")
                       .WithPart("CommonPart")
                       .Creatable(false)  );

So far so good, I can create a new person and edit both parts.

Another part that I have is a ServicePart that is bound to one of the PersonRoleParts defined above.

Now the question:

For reporting purpose I need to get all services by PersonRole and get the person details that belong to that role or, in other words, get all the (only one indeed) PersonPart that is used in the Person compound type defined above.

How to do that?

Now in a non-orchard world I would create a simple 1:1 relationship between the 2.

My (failed) attempt so far was to add a PersonRoleRecord_Id field to PersonPartRecord and a PersonRecord_Id to Person role... but I have no idea how to set to correct id on driver or handler since both see just the own part.

Is it possible from driver get an instance of the other fellows parts in content type?

Merge Person and Role is not possible. The scenario is more complex than that and I need same Person Part an 3 different Role-like part for different purposes and I want to avoid duplicate common person data 3 times.

Another idea was to create an appropriate handler but I do not know how to create an Handler for a virtual content type like the one I did.

解决方案

I have managed to solve using the advice on another question that addressed a different problem (validation). Orchard CMS - determining if Model is valid in Content Item Driver

So my solution was to add an handler to both and cast the part and set the appropriate reference to the other part.

        OnPublishing<PersonPart>((context, part) =>{
            var person = part.As<PersonPart>();
            var role= part.As<PersonRolePart>();
            if (person != null && role != null) {
                if (role.Person == null) {
                    role.Person = person.Record;
                }
            }
        });

In this specific case since it is a 1:1 relation so i I use just that combined part, both id are the same, at least if the role is just of one type. I will see when I will create more role-like parts.

这篇关于果园连接件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆