Drupal有机组角色数据存储在哪里?我该如何访问它?

时间:2011-08-31 22:20:18

标签: drupal-7 organic-groups

我已为我的群组创建了自定义角色。 我已经为该特殊角色分配了一个用户,该用户是该组的成员。 现在,我想通过PHP访问组中的用户角色,但我无法在任何地方找到它 我仔细研究了用户和组的级别。我可以在用户的​​group_audience数组中访问用户是该组的成员这一事实,但不能访问他们的角色在该组中的内容。

有什么建议吗?

编辑:Drupal 7

1 个答案:

答案 0 :(得分:3)

编辑:首先有一些背景,然后实际答案就在那之后。

背景

查看我们的开发服务器上的mySQL数据库,我们的Drupal数据库中似乎有一些与OG相关的表。我很确定在devserver上运行的版本是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,其中读取{ {1}}):

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对应于相关用户的etidusers.uid }对应于相关论坛的gid

所以,如果我运行查询

og.gid

然后组#324的所有成员都被移动到组#38(这是我刚才需要做的,因为导入脚本中有错误。)

认为 您的问题的答案是update og_membership set gid = 38 where gid = 324; 对应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。 (网址中显示的ID是og.gid,因此您可能希望向该查询添加另一个og.etid