Drupal Organic Group 角色数据存储在哪里?我如何访问它?
我为我的组创建了一个自定义角色。 我已将作为该组成员的用户分配给这个特殊角色。 现在,我想通过 PHP 访问用户在组中的角色,但我在任何地方都找不到它。
我仔细研究了用户和组的开发。我可以访问用户是该用户的 group_audience 数组中的组的成员这一事实,但无法访问他们在该组中的角色。
有什么建议吗?
编辑:Drupal 7
I've created a custom Role for my Group.
I've assigned a user, who was a member of the Group, to this special Role.
Now, I want to access a user's Role in the Group via PHP, but I can't find it anywhere.
I've pored over the Devels of both the User and Group. I can access the fact that the user is a member of the group in the user's group_audience array, but not what their role is in that group.
Any advice?
Edit: Drupal 7
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑:首先有一些背景知识,然后是实际答案。
背景
查看我们开发服务器上的 mySQL 数据库,我们的 Drupal 数据库中似乎有一些与 OG 相关的表。我很确定开发服务器上运行的版本是 og-7.x-1.x-dev。
og
og_membership
og_membership_type
og_menu
og_role
og_role_permission
og_users_roles
field_data_og_membership_request
field_revision_og_membership_request
它们的定义如下所示:
(我已从两个
field_*
表中删除了空的 Extras 列,以避免水平滚动。)希望有帮助吗?我的工作方式
我自己在自己的 Drupal 网站上搞乱了这个问题,结果发现
og_membership
为每个组中的每个用户都有一行(我缩写了type,其内容为
og_membership_type_default
):在这一行中,
id
是表og_membership
的自动递增标识符,etid
对应于相关用户的users.uid
,gid
对应于og.gid
有问题的团体。因此,如果我运行查询
,则组 #324 的所有成员都会移动到组 #38(由于导入脚本中的错误,这正是我需要做的)。
我认为您的问题的答案是
og_membership.type
对应于og_membership_type.name
。看看该表:,我认为
og_membership_type.status
对应于og_role.rid
:实际答案
所以我认为您想要的查询是:
其中
$group_id
是相关组的og.gid
。 (出现在 URL 中的 ID 是og.etid
,因此您可能需要向该查询添加另一个join
。Edit: There's some background here first, then the actual answer is after that.
Background
Looking in the mySQL database on our development server, there seems to be a handful of OG-related tables in our Drupal database. I'm pretty sure the version running on the devserver is og-7.x-1.x-dev.
og
og_membership
og_membership_type
og_menu
og_role
og_role_permission
og_users_roles
field_data_og_membership_request
field_revision_og_membership_request
Their definitions look like this:
(I've removed the empty Extras column from the two
field_*
tables to avoid horizontal scrolling.) Hope that helps?My workings
Having just had to mess with this myself on my own Drupal site, it turns out that
og_membership
has a row for each user in each group (I've abbreviated thetype
, which readog_membership_type_default
):In this row, the
id
is an autoincrementing identifier for the tableog_membership
, theetid
corresponds to theusers.uid
for the user in question andgid
corresponds to to theog.gid
for the group in question.So if I run the query
then all the members of group #324 are moved to group #38 (which is what I've just needed to do, due to an error in an import script).
I think the answer to your question is that the
og_membership.type
corresponds to anog_membership_type.name
. Looking at that table:, I think the
og_membership_type.status
corresponds to theog_role.rid
:Actual answer
So I think the query you want is:
where
$group_id
is theog.gid
of the group in question. (The ID that appears in the URL is theog.etid
, so you might want to add anotherjoin
to that query.