Index: og_promote.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/og_promote/Attic/og_promote.module,v retrieving revision 1.5.2.1 diff -u -r1.5.2.1 og_promote.module --- og_promote.module 30 Mar 2007 16:59:54 -0000 1.5.2.1 +++ og_promote.module 22 Oct 2007 22:09:26 -0000 @@ -36,7 +36,8 @@ * Implementation of hook_og(). */ function og_promote_og($op, $nid, $uid, $args = array()) { - if (($role_id = variable_get('og_promote_role', 0)) != 0 && in_array($nid, variable_get('og_promote_groups', NULL))) { + $type = _og_promote_get_node_type($nid); + if (($role_id = variable_get('og_promote_role', 0)) != 0 && (in_array($nid, variable_get('og_promote_groups', NULL)) || in_array($type, variable_get('og_promote_group_types', NULL)))) { switch ($op) { case 'user insert': case 'user update': @@ -54,9 +55,19 @@ break; case 'user delete': $groups = variable_get('og_promote_groups', array()); + $group_types = variable_get('og_promote_group_types', array()); $user_groups = array_keys(og_get_subscriptions($uid)); - // check that the user isn't in any of the other groups. - if (in_array($nid, $groups) && !count(array_intersect(array_diff($groups, array(0)), array_diff($user_groups, array($nid))))) { + $user_groups_new = array_diff($user_groups, array($nid)); + $user_group_types_new = array(); + foreach ($user_groups_new as $gid) { + $user_group_types_new[] = _og_promote_get_node_type($gid); + } + drupal_set_message(dprint_r($groups, true)); + drupal_set_message(dprint_r($user_groups_new, true)); + drupal_set_message(dprint_r($group_types, true)); + drupal_set_message(dprint_r($user_group_types_new, true)); + // check that the user isn't in any of the other groups given explicitely or any of the other groups given by content type. + if ((in_array($nid, $groups) || in_array($type, $group_types)) && !(count(array_intersect($groups, $user_groups_new)) + count(array_intersect($group_types, $user_group_types_new)))) { $user = user_load(array('uid' => $uid)); $edit = array(); $edit['roles'] = array(); @@ -86,7 +97,7 @@ } } if (count($role_names)) { - $form['og_promote_role'] = array('#type' => 'radios', '#title' => t('Roles'), '#options' => $role_names, '#default_value' => variable_get('og_promote_role', 0), '#description' => t('Choose a role that users which become members of the groups below should be promoted to. If the member gets unsubscribed, it will be removed from the role.')); + $form['og_promote_role'] = array('#type' => 'radios', '#title' => t('Roles'), '#options' => $role_names, '#default_value' => variable_get('og_promote_role', 0), '#description' => t('Choose a role that users will promoted to if they become member of any of the groups specified below. If the member gets unsubscribed, it will be removed from the role.')); } else { $form['og_promote_role'] = array('#type' => 'item', '#title' => t('No roles'), '#description' => t('You need to define some additional roles to use this module.')); @@ -94,6 +105,17 @@ $options = array(); $values = array(); $types = variable_get('og_node_types', array('og')); + + foreach ($types as $type) { + $options[$type] = node_get_types('name', array('type' => $type)); + } + if (count($options)) { + $form['og_promote_group_types'] = array('#type' => 'checkboxes', '#title' => t('Group content types'), '#options' => $options, '#default_value' => variable_get('og_promote_group_types', array()), '#description' => t('The group content types that are defined for this site.')); + } + else { + $form['og_promote_group_types'] = array('#type' => 'item', '#title' => t('No group content types'), '#options' => $options, '#default_value' => variable_get('og_promote_group_types', array()), '#description' => t('You need to create some group content types.')); + } + foreach ($types as $type) { $result = db_query("SELECT n.nid, n.title, o.* FROM {node} n INNER JOIN {og} o ON n.nid = o.nid WHERE n.type = '%s' ORDER BY n.title", $type); while ($group = db_fetch_object($result)) { @@ -122,3 +144,10 @@ } return system_settings_form($form); } + +/** + * Helper function, returns node type of given node id. + */ +function _og_promote_get_node_type($nid) { + return db_result(db_query('SELECT type FROM {node} WHERE nid = %d', $nid)); +} \ No newline at end of file