我想知道是否有一个好的模块——如果有的话,我还想要一些指示——关于如何将用户分组。
基本上每增加 10 个人,我希望他们被添加到一个分配有编号的组中。每个小组还分配了一名辅导员,他可能被分配到多个小组。我还需要随意从组中添加/删除人员并在组之间交换成员。
有什么建议么?
我想知道是否有一个好的模块——如果有的话,我还想要一些指示——关于如何将用户分组。
基本上每增加 10 个人,我希望他们被添加到一个分配有编号的组中。每个小组还分配了一名辅导员,他可能被分配到多个小组。我还需要随意从组中添加/删除人员并在组之间交换成员。
有什么建议么?
Create a vocabulary named 'User Groups'. Goto admin/config/people/accounts/fields and add a taxonomy term field for the user.
<?php
function mymodule_user_presave(&$edit, $account, $category) {
$termname = int($account->uid / 10);
if(!empty(taxonomy_get_term_by_name(termname)){
$newterm = new stdClass();
$newterm->name = $termname;
$newterm->vid = 5; the vid of the vocabulary 'User group which you should create manually'
taxonomy_term_save(($newterm); If the terms already exists, it will just remain the same.
$edit['data']['field_user_group'] = $newterm->tid;
}
?>
So for every user in the range of multiples of 10 it will assign a single term. Eg for users with uid from 0 to 9 will be assigned with the term name 0, 10-19 with 1 and so on.
Since all users are just tagged with a name for the group, from the admin interface. For each of these tags you can also assign a user.
Note : The code is just for the concept, it is not exact or tested.