? require_num_groups_2.diff ? require_num_groups_20.diff ? require_num_groups_22.diff ? require_num_groups_3.diff Index: og_mandatory_group.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/og_mandatory_group/og_mandatory_group.module,v retrieving revision 1.4.2.1 diff -u -p -r1.4.2.1 og_mandatory_group.module --- og_mandatory_group.module 22 Jul 2006 12:40:59 -0000 1.4.2.1 +++ og_mandatory_group.module 27 Sep 2006 01:15:44 -0000 @@ -9,16 +9,72 @@ function og_mandatory_group_help($sectio case 'admin/modules#description': return t('Make one group mandatory for new users.'); case 'admin/settings/og_mandatory_group': - return t('Choose one group that all new users will be put into. You can chose either an open or a closed group. The user will be auto-approved as member of the group.'); + $output = '
'. t('Choose one group that all new users will be put into. You can chose either an open or a closed group. The user will be auto-approved as member of the group.'); + $output .= '
'. t('You may also choose to require the user to join one group in addition to any mandatory group.'). '
'; + return $output; } } /** + * Implementation of hook_form_alter + * + */ +function og_mandatory_group_form_alter ($form_id, &$form) { + + if ($form_id == 'user_register') { + unset($form['og_register']['og_register']['#options'][0]); //temporary fix for OG bug + + $form['og_register']['og_mandatory_in_form'] = array('#type' => 'value', '#value' => FALSE,); + + $group_count = count($form['og_register']['og_register']['#options']); + if ($mandatory_group = variable_get('og_mandatory_group', 0)) { + if (in_array($mandatory_group, array_keys($form['og_register']['og_register']['#options']))) { + $title = $form['og_register']['og_register']['#options'][$mandatory_group]. ' '. t('(This group is mandatory)'); + $form['og_register']['og_mandatory_in_form'] = array( + '#type' => 'checkbox', + '#title' => $title, + '#value' => TRUE, + '#attributes' => array('disabled' => 'disabled'), + ); + unset($form['og_register']['og_register']['#options'][$mandatory_group]); + $group_count--; + $form['og_register'] = array_reverse($form['og_register']); + } + } + if ($group_count > 0 && variable_get('og_mandatory_additional_group', FALSE)) { + if ($mandatory_group) { + $form['og_register']['minimum'] = array ('#value' => t('You must join at least one additional (non-mandatory) group.'),); + } + else { + $form['og_register']['minimum'] = array ('#value' => t('You must join at least one group.'),); + } + } + } +} + +/** * Implementation of hook_user * */ function og_mandatory_group_user($op, &$edit, &$account, $category = NULL) { + + if (!module_exist('og')) { + return; + } switch ($op) { + case 'validate': + if (isset($edit['og_register']) && variable_get('og_mandatory_additional_group', FALSE)) { //only present during registration + unset($edit['og_register'][0]);//temporary fix + if (count($edit['og_register']) > 0 && count(array_filter($edit['og_register'])) < 1) { + if ($edit['og_mandatory_in_form']) { + form_set_error('og_register', "You must join at least one group in addition to the mandatory group"); + } + else { + form_set_error('og_register', "You must join at least one group"); + } + } + } + break; case 'insert': if (($group = variable_get('og_mandatory_group', 0)) != 0) { og_save_subscription($group, $account->uid, array('is_active' => 1)); @@ -29,28 +85,28 @@ function og_mandatory_group_user($op, &$ $headers = "From: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $from"; $groups = ''; - if ($edit['og_register']) { - $result = db_query(db_rewrite_sql('SELECT n.nid, n.title, o.* FROM {node} n INNER JOIN {og} o ON n.nid = o.nid WHERE n.type IN ('. str_pad('', count(variable_get('og_node_types', array('og'))) * 5 - 1, "'%s',") .') AND n.status = 1 AND o.register = 1'), variable_get('og_node_types', array('og'))); - while ($row = db_fetch_object($result)) { - if ($edit['og_register'][$row->nid]) { - switch ($row->selective) { - case OG_OPEN: - $groups .= check_plain($row->title) .' '. t('(open group)'); - break; - case OG_MODERATED: - $groups .= check_plain($row->title) .' '. t('(moderated group)'); - break; - case OG_INVITE_ONLY: - $groups .= check_plain($row->title) .' '. t('(invite only group)'); - break; - case OG_CLOSED: - $groups .= check_plain($row->title) .' '. t('(closed group)'); - break; - } - $groups .= "\n\t". url("node/$row->nid", NULL, NULL, TRUE) ."\n\n"; - } - } - } + if ($edit['og_register']) { + $result = db_query(db_rewrite_sql('SELECT n.nid, n.title, o.* FROM {node} n INNER JOIN {og} o ON n.nid = o.nid WHERE n.type IN ('. str_pad('', count(variable_get('og_node_types', array('og'))) * 5 - 1, "'%s',") .') AND n.status = 1 AND o.register = 1'), variable_get('og_node_types', array('og'))); + while ($row = db_fetch_object($result)) { + if ($edit['og_register'][$row->nid]) { + switch ($row->selective) { + case OG_OPEN: + $groups .= check_plain($row->title) .' '. t('(open group)'); + break; + case OG_MODERATED: + $groups .= check_plain($row->title) .' '. t('(moderated group)'); + break; + case OG_INVITE_ONLY: + $groups .= check_plain($row->title) .' '. t('(invite only group)'); + break; + case OG_CLOSED: + $groups .= check_plain($row->title) .' '. t('(closed group)'); + break; + } + $groups .= "\n\t". url("node/$row->nid", NULL, NULL, TRUE) ."\n\n"; + } + } + } $sql = og_list_users_sql(1, 1); $result = db_query($sql, $group); while ($row = db_fetch_object($result)) { @@ -75,8 +131,7 @@ function og_mandatory_group_user($op, &$ * */ function og_mandatory_group_settings() { - $options = array(); - $values = array(); + $options[0] = theme('placeholder', t('none')); $result = db_query("SELECT n.nid, n.title, o.* FROM {node} n INNER JOIN {og} o ON n.nid = o.nid WHERE (o.selective = %d OR o.selective = %d) ORDER BY n.title", OG_CLOSED, OG_OPEN); while ($group = db_fetch_object($result)) { $options[$group->nid] = check_plain($group->title); @@ -89,8 +144,27 @@ function og_mandatory_group_settings() { break; } } - if (count($options)) { - $form['og_mandatory_group'] = array('#type' => 'radios', '#options' => $options, '#default_value' => variable_get('og_mandatory_group', 0)); - return $form; + $form['groups'] = array( + '#type' => 'fieldset', + '#title' => t('Choose the mandatory group'), + ); + $form['groups']['og_mandatory_group'] = array( + '#type' => 'radios', + '#options' => $options, + '#default_value' => variable_get('og_mandatory_group', 0), + ); + + $form['og_mandatory_additional_group'] = array( + '#type' => 'checkbox', + '#title' => t('Require new users to join at least one group in addition to any mandatory group'), + '#default_value' => variable_get('og_mandatory_additional_group', FALSE), + ); + $form['#validate'] = array('og_mandatory_group_settings_validate' => array()); + return $form; +} + +function og_mandatory_group_settings_validate($form_id, $form_values, $form) { + if (!isset($form['groups']['og_mandatory_group']['#options'][$form_values['og_mandatory_group']])) { + form_set_error('groups', t('Invalid mandatory group- please choose an option from the list.')); } }