Drupal Organic Group 角色数据存储在哪里?我如何访问它?

发布于 2024-12-02 12:30:52 字数 213 浏览 3 评论 0原文

我为我的组创建了一个自定义角色。 我已将作为该组成员的用户分配给这个特殊角色。 现在,我想通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤独岁月 2024-12-09 12:30:52

编辑:首先有一些背景知识,然后是实际答案。

背景

查看我们开发服务器上的 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

它们的定义如下所示:

mysql> describe og;
+-------------+------------------+------+-----+---------+----------------+
| Field       | Type             | Null | Key | Default | Extra          |
+-------------+------------------+------+-----+---------+----------------+
| gid         | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| etid        | int(10) unsigned | NO   | MUL | 0       |                |
| entity_type | varchar(32)      | NO   |     |         |                |
| label       | varchar(255)     | NO   |     |         |                |
| state       | int(11)          | NO   |     | 1       |                |
| created     | int(11)          | NO   |     | 0       |                |
+-------------+------------------+------+-----+---------+----------------+
6 rows in set (0.02 sec)

mysql> describe og_membership;
+-------------+------------------+------+-----+---------+----------------+
| Field       | Type             | Null | Key | Default | Extra          |
+-------------+------------------+------+-----+---------+----------------+
| id          | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| type        | varchar(255)     | NO   |     |         |                |
| etid        | int(10) unsigned | NO   | MUL | 0       |                |
| entity_type | varchar(32)      | NO   |     |         |                |
| gid         | int(11)          | NO   | MUL | NULL    |                |
| state       | varchar(255)     | YES  |     |         |                |
| created     | int(11)          | NO   |     | 0       |                |
+-------------+------------------+------+-----+---------+----------------+
7 rows in set (0.00 sec)

mysql> describe og_membership_type;
+-------------+--------------+------+-----+---------+----------------+
| Field       | Type         | Null | Key | Default | Extra          |
+-------------+--------------+------+-----+---------+----------------+
| id          | int(11)      | NO   | PRI | NULL    | auto_increment |
| name        | varchar(255) | NO   | UNI |         |                |
| description | varchar(255) | NO   |     |         |                |
| status      | tinyint(4)   | NO   |     | 1       |                |
| module      | varchar(255) | YES  |     | NULL    |                |
+-------------+--------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)

mysql> describe og_menu;
+-----------+--------------+------+-----+---------+-------+
| Field     | Type         | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+-------+
| gid       | int(11)      | NO   | PRI | NULL    |       |
| menu_name | varchar(128) | NO   | PRI |         |       |
+-----------+--------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

mysql> describe og_role;
+-------+------------------+------+-----+---------+----------------+
| Field | Type             | Null | Key | Default | Extra          |
+-------+------------------+------+-----+---------+----------------+
| rid   | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| gid   | int(11)          | NO   |     | NULL    |                |
| name  | varchar(64)      | NO   |     |         |                |
+-------+------------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)

mysql> describe og_role_permission;
+------------+------------------+------+-----+---------+-------+
| Field      | Type             | Null | Key | Default | Extra |
+------------+------------------+------+-----+---------+-------+
| rid        | int(10) unsigned | NO   | PRI | NULL    |       |
| permission | varchar(64)      | NO   | PRI |         |       |
| module     | varchar(255)     | NO   |     |         |       |
+------------+------------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql> describe og_users_roles;
+-------+------------------+------+-----+---------+-------+
| Field | Type             | Null | Key | Default | Extra |
+-------+------------------+------+-----+---------+-------+
| uid   | int(10) unsigned | NO   | PRI | 0       |       |
| rid   | int(10) unsigned | NO   | PRI | 0       |       |
| gid   | int(11)          | NO   | PRI | NULL    |       |
+-------+------------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql> describe field_data_og_membership_request;
+------------------------------+------------------+------+-----+---------+
| Field                        | Type             | Null | Key | Default |
+------------------------------+------------------+------+-----+---------+
| entity_type                  | varchar(128)     | NO   | PRI |         |
| bundle                       | varchar(128)     | NO   | MUL |         |
| deleted                      | tinyint(4)       | NO   | PRI | 0       |
| entity_id                    | int(10) unsigned | NO   | PRI | NULL    |
| revision_id                  | int(10) unsigned | YES  | MUL | NULL    |
| language                     | varchar(32)      | NO   | PRI |         |
| delta                        | int(10) unsigned | NO   | PRI | NULL    |
| og_membership_request_value  | longtext         | YES  |     | NULL    |
| og_membership_request_format | varchar(255)     | YES  | MUL | NULL    |
+------------------------------+------------------+------+-----+---------+
9 rows in set (0.00 sec)

mysql> describe field_revision_og_membership_request;
+------------------------------+------------------+------+-----+---------+
| Field                        | Type             | Null | Key | Default |
+------------------------------+------------------+------+-----+---------+
| entity_type                  | varchar(128)     | NO   | PRI |         |
| bundle                       | varchar(128)     | NO   | MUL |         |
| deleted                      | tinyint(4)       | NO   | PRI | 0       |
| entity_id                    | int(10) unsigned | NO   | PRI | NULL    |
| revision_id                  | int(10) unsigned | NO   | PRI | NULL    |
| language                     | varchar(32)      | NO   | PRI |         |
| delta                        | int(10) unsigned | NO   | PRI | NULL    |
| og_membership_request_value  | longtext         | YES  |     | NULL    |
| og_membership_request_format | varchar(255)     | YES  | MUL | NULL    |
+------------------------------+------------------+------+-----+---------+
9 rows in set (0.00 sec)

(我已从两个 field_* 表中删除了空的 Extras 列,以避免水平滚动。)希望有帮助吗?

我的工作方式

我自己在自己的 Drupal 网站上搞乱了这个问题,结果发现 og_membership 为每个组中的每个用户都有一行(我缩写了 type,其内容为 og_membership_type_default):

mysql> select * from og_membership where gid = 324 and etid = 182905;
+--------+-----------------+--------+-------------+-----+-------+------------+
| id     | type            | etid   | entity_type | gid | state | created    |
+--------+-----------------+--------+-------------+-----+-------+------------+
| 223562 | og_m..._default | 182905 | user        | 324 | 1     | 1329388409 |
+--------+-----------------+--------+-------------+-----+-------+------------+
1 row in set (0.01 sec)

在这一行中,id 是表 og_membership 的自动递增标识符, etid 对应于相关用户的 users.uidgid 对应于 og.gid有问题的团体。

因此,如果我运行查询

update og_membership set gid = 38 where gid = 324;

,则组 #324 的所有成员都会移动到组 #38(由于导入脚本中的错误,这正是我需要做的)。

认为您的问题的答案是og_membership.type对应于og_membership_type.name。看看该表:

mysql> select * from og_membership_type;
+----+----------------------------+-------------+--------+--------+
| id | name                       | description | status | module |
+----+----------------------------+-------------+--------+--------+
|  1 | og_membership_type_default | Default     |      2 | og     |
+----+----------------------------+-------------+--------+--------+
1 row in set (0.00 sec)

,我认为 og_membership_type.status 对应于 og_role.rid

mysql> select * from og_role;
+-----+-----+----------------------+
| rid | gid | name                 |
+-----+-----+----------------------+
|   1 |   0 | non-member           |
|   2 |   0 | member               |
|   3 |   0 | administrator member |
+-----+-----+----------------------+
3 rows in set (0.00 sec)

实际答案

所以我认为您想要的查询是:

select og_role.name
from og_role
    inner join og_membership_type on og_role.rid = og_membership_type.status
    inner join og_membership on og_membership_type.name = og_membership.type
where og_membership.gid = $group_id;

其中 $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:

mysql> describe og;
+-------------+------------------+------+-----+---------+----------------+
| Field       | Type             | Null | Key | Default | Extra          |
+-------------+------------------+------+-----+---------+----------------+
| gid         | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| etid        | int(10) unsigned | NO   | MUL | 0       |                |
| entity_type | varchar(32)      | NO   |     |         |                |
| label       | varchar(255)     | NO   |     |         |                |
| state       | int(11)          | NO   |     | 1       |                |
| created     | int(11)          | NO   |     | 0       |                |
+-------------+------------------+------+-----+---------+----------------+
6 rows in set (0.02 sec)

mysql> describe og_membership;
+-------------+------------------+------+-----+---------+----------------+
| Field       | Type             | Null | Key | Default | Extra          |
+-------------+------------------+------+-----+---------+----------------+
| id          | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| type        | varchar(255)     | NO   |     |         |                |
| etid        | int(10) unsigned | NO   | MUL | 0       |                |
| entity_type | varchar(32)      | NO   |     |         |                |
| gid         | int(11)          | NO   | MUL | NULL    |                |
| state       | varchar(255)     | YES  |     |         |                |
| created     | int(11)          | NO   |     | 0       |                |
+-------------+------------------+------+-----+---------+----------------+
7 rows in set (0.00 sec)

mysql> describe og_membership_type;
+-------------+--------------+------+-----+---------+----------------+
| Field       | Type         | Null | Key | Default | Extra          |
+-------------+--------------+------+-----+---------+----------------+
| id          | int(11)      | NO   | PRI | NULL    | auto_increment |
| name        | varchar(255) | NO   | UNI |         |                |
| description | varchar(255) | NO   |     |         |                |
| status      | tinyint(4)   | NO   |     | 1       |                |
| module      | varchar(255) | YES  |     | NULL    |                |
+-------------+--------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)

mysql> describe og_menu;
+-----------+--------------+------+-----+---------+-------+
| Field     | Type         | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+-------+
| gid       | int(11)      | NO   | PRI | NULL    |       |
| menu_name | varchar(128) | NO   | PRI |         |       |
+-----------+--------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

mysql> describe og_role;
+-------+------------------+------+-----+---------+----------------+
| Field | Type             | Null | Key | Default | Extra          |
+-------+------------------+------+-----+---------+----------------+
| rid   | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| gid   | int(11)          | NO   |     | NULL    |                |
| name  | varchar(64)      | NO   |     |         |                |
+-------+------------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)

mysql> describe og_role_permission;
+------------+------------------+------+-----+---------+-------+
| Field      | Type             | Null | Key | Default | Extra |
+------------+------------------+------+-----+---------+-------+
| rid        | int(10) unsigned | NO   | PRI | NULL    |       |
| permission | varchar(64)      | NO   | PRI |         |       |
| module     | varchar(255)     | NO   |     |         |       |
+------------+------------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql> describe og_users_roles;
+-------+------------------+------+-----+---------+-------+
| Field | Type             | Null | Key | Default | Extra |
+-------+------------------+------+-----+---------+-------+
| uid   | int(10) unsigned | NO   | PRI | 0       |       |
| rid   | int(10) unsigned | NO   | PRI | 0       |       |
| gid   | int(11)          | NO   | PRI | NULL    |       |
+-------+------------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql> describe field_data_og_membership_request;
+------------------------------+------------------+------+-----+---------+
| Field                        | Type             | Null | Key | Default |
+------------------------------+------------------+------+-----+---------+
| entity_type                  | varchar(128)     | NO   | PRI |         |
| bundle                       | varchar(128)     | NO   | MUL |         |
| deleted                      | tinyint(4)       | NO   | PRI | 0       |
| entity_id                    | int(10) unsigned | NO   | PRI | NULL    |
| revision_id                  | int(10) unsigned | YES  | MUL | NULL    |
| language                     | varchar(32)      | NO   | PRI |         |
| delta                        | int(10) unsigned | NO   | PRI | NULL    |
| og_membership_request_value  | longtext         | YES  |     | NULL    |
| og_membership_request_format | varchar(255)     | YES  | MUL | NULL    |
+------------------------------+------------------+------+-----+---------+
9 rows in set (0.00 sec)

mysql> describe field_revision_og_membership_request;
+------------------------------+------------------+------+-----+---------+
| Field                        | Type             | Null | Key | Default |
+------------------------------+------------------+------+-----+---------+
| entity_type                  | varchar(128)     | NO   | PRI |         |
| bundle                       | varchar(128)     | NO   | MUL |         |
| deleted                      | tinyint(4)       | NO   | PRI | 0       |
| entity_id                    | int(10) unsigned | NO   | PRI | NULL    |
| revision_id                  | int(10) unsigned | NO   | PRI | NULL    |
| language                     | varchar(32)      | NO   | PRI |         |
| delta                        | int(10) unsigned | NO   | PRI | NULL    |
| og_membership_request_value  | longtext         | YES  |     | NULL    |
| og_membership_request_format | varchar(255)     | YES  | MUL | NULL    |
+------------------------------+------------------+------+-----+---------+
9 rows in set (0.00 sec)

(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 the type, which read og_membership_type_default):

mysql> select * from og_membership where gid = 324 and etid = 182905;
+--------+-----------------+--------+-------------+-----+-------+------------+
| id     | type            | etid   | entity_type | gid | state | created    |
+--------+-----------------+--------+-------------+-----+-------+------------+
| 223562 | og_m..._default | 182905 | user        | 324 | 1     | 1329388409 |
+--------+-----------------+--------+-------------+-----+-------+------------+
1 row in set (0.01 sec)

In this row, the id is an autoincrementing identifier for the table og_membership, the etid corresponds to the users.uid for the user in question and gid corresponds to to the og.gid for the group in question.

So if I run the query

update og_membership set gid = 38 where gid = 324;

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 an og_membership_type.name. Looking at that table:

mysql> select * from og_membership_type;
+----+----------------------------+-------------+--------+--------+
| id | name                       | description | status | module |
+----+----------------------------+-------------+--------+--------+
|  1 | og_membership_type_default | Default     |      2 | og     |
+----+----------------------------+-------------+--------+--------+
1 row in set (0.00 sec)

, I think the og_membership_type.status corresponds to the og_role.rid:

mysql> select * from og_role;
+-----+-----+----------------------+
| rid | gid | name                 |
+-----+-----+----------------------+
|   1 |   0 | non-member           |
|   2 |   0 | member               |
|   3 |   0 | administrator member |
+-----+-----+----------------------+
3 rows in set (0.00 sec)

Actual answer

So I think the query you want is:

select og_role.name
from og_role
    inner join og_membership_type on og_role.rid = og_membership_type.status
    inner join og_membership on og_membership_type.name = og_membership.type
where og_membership.gid = $group_id;

where $group_id is the og.gid of the group in question. (The ID that appears in the URL is the og.etid, so you might want to add another join to that query.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文