--- og_multiple_mandatory_groups_by_role.module 2009-09-14 12:04:29.257943800 -0400 +++ og_multiple_mandatory_groups_by_role.20090915.module 2009-09-14 17:38:18.133622100 -0400 @@ -65,7 +65,7 @@ function og_multiple_mandatory_groups_by 'page arguments' => array('og_multiple_mandatory_groups_by_role_main'), 'access callback' => 'user_access', 'access arguments' => array('administer og mandatory groups by role'), - 'type' => MENU_NORMAL_ITEM, + 'type' => MENU_NORMAL_ITEM ); $items['admin/og/og_multiple_mandatory_groups_by_role/overview'] = array( //tab to take us to main settings page @@ -75,9 +75,20 @@ function og_multiple_mandatory_groups_by 'access callback' => 'user_access', 'access arguments' => array('administer og mandatory groups by role'), 'type' => MENU_DEFAULT_LOCAL_TASK, - 'weight' => -10, + 'weight' => 0 ); + $items['admin/og/og_multiple_mandatory_groups_by_role/groups'] = array( //assign mandatory groups for each role under administration + 'title' => 'Available Groups', + 'description' => 'Decide which groups are available to make mandatory.', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('og_multiple_mandatory_groups_by_role_groups'), + 'access callback' => 'user_access', + 'access arguments' => array('administer og mandatory groups by role'), + 'type' => MENU_LOCAL_TASK, + 'weight' => 5 + ); + $items['admin/og/og_multiple_mandatory_groups_by_role/admin'] = array( //assign mandatory groups for each role under administration 'title' => 'Assign Groups', 'description' => 'Assign which groups you\'d like to be mandatory for each role.', @@ -86,6 +97,7 @@ function og_multiple_mandatory_groups_by 'access callback' => 'user_access', 'access arguments' => array('administer og mandatory groups by role'), 'type' => MENU_LOCAL_TASK, + 'weight' => 10 ); $items['admin/og/og_multiple_mandatory_groups_by_role/admin/%og_multiple_mandatory_groups_by_role_admin'] = array( //assign mandatory groups for each role under administration @@ -96,6 +108,7 @@ function og_multiple_mandatory_groups_by 'access callback' => 'user_access', 'access arguments' => array('administer og mandatory groups by role'), 'type' => MENU_LOCAL_TASK, + 'weight' => 10 ); $items['admin/og/og_multiple_mandatory_groups_by_role/delete'] = array( //delete a role from mandatory group management @@ -104,7 +117,7 @@ function og_multiple_mandatory_groups_by 'page arguments' => array('og_multiple_mandatory_groups_by_role_confirm_delete'), 'access callback' => 'user_access', 'access arguments' => array('administer og mandatory groups by role'), - 'type' => MENU_CALLBACK, + 'type' => MENU_CALLBACK ); $items['admin/og/og_multiple_mandatory_groups_by_role/delete_unsubscribe'] = array( //delete a role from mandatory group management @@ -113,26 +126,16 @@ function og_multiple_mandatory_groups_by 'page arguments' => array('og_multiple_mandatory_groups_by_role_confirm_delete_unsub'), 'access callback' => 'user_access', 'access arguments' => array('administer og mandatory groups by role'), - 'type' => MENU_CALLBACK, - ); - - $items['admin/og/og_multiple_mandatory_groups_by_role/groups'] = array( //assign mandatory groups for each role under administration - 'title' => 'Available Groups', - 'description' => 'Decide which groups are available to make mandatory.', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('og_multiple_mandatory_groups_by_role_groups'), - 'access callback' => 'user_access', - 'access arguments' => array('administer og mandatory groups by role'), - 'type' => MENU_LOCAL_TASK, + 'type' => MENU_CALLBACK ); $items['admin/og/og_multiple_mandatory_groups_by_role/groups_delete'] = array( //delete a group from available groups list 'title' => 'Delete group from availability list', 'page callback' => 'drupal_get_form', - 'page arguments' => array('og_multiple_mandatory_groups_by_role_group_confirm_delete'), + 'page arguments' => array('og_multiple_mandatory_groups_by_role_group_confirm_delete',4), 'access callback' => 'user_access', 'access arguments' => array('administer og mandatory groups by role'), - 'type' => MENU_CALLBACK, + 'type' => MENU_CALLBACK ); $items['admin/og/og_multiple_mandatory_groups_by_role/groups_delete_unsubscribe'] = array( //delete a group from available groups list @@ -141,7 +144,7 @@ function og_multiple_mandatory_groups_by 'page arguments' => array('og_multiple_mandatory_groups_by_role_group_confirm_delete_unsubscribe'), 'access callback' => 'user_access', 'access arguments' => array('administer og mandatory groups by role'), - 'type' => MENU_CALLBACK, + 'type' => MENU_CALLBACK ); return $items; @@ -492,11 +495,19 @@ function og_multiple_mandatory_groups_by */ function og_multiple_mandatory_groups_by_role_admin_submit($form, &$form_state) { $error = FALSE; + $og_groups = array(); $hold_updates = array(); $all_users = array(); $old = array(); $retro = $form_state['values']['roles']['retro']; - + + //fetch titles for all og groups + $sql = "SELECT o.nid, n.title FROM {node} n INNER JOIN {og} o ON n.nid = o.nid ORDER BY o.nid ASC"; + $results = db_query($sql); + while ($result = db_fetch_object($results)) { + $og_groups[$result->nid] = $result->title; + } + foreach (element_children($form_state['values']['roles']) as $role) { //for some reason, if we have a role without assignments and we save, erroneous values are added in sequence. //by unsetting any 0 index we find, this doesn't happen -- might not be happening in D6, so we could take it out!!! @@ -517,10 +528,11 @@ function og_multiple_mandatory_groups_by //collect info on users so we don't unsubscribe from groups on accident; we always overwrite subscriptions, but only add unsubscriptions when a subscription doesn't exist //first get all users and set groups to subscribe and unsubscribe from if (key_exists('All users', $hold_updates)) { - $sql = "SELECT u.uid FROM {users} u WHERE u.uid > 1 ORDER BY u.uid ASC"; + $sql = "SELECT u.uid, u.name FROM {users} u WHERE u.uid > 1 ORDER BY u.uid ASC"; $results = db_query($sql); while ($result = db_fetch_object($results)) { foreach ($hold_updates['All users'] as $group => $val) { + $all_users[$result->uid]['name'] = $result->name; if (($group == $val) && (($val != $old['All users'][$group]) || $retro)) {//either we're forcing the update (retro==1) or something changed $all_users[$result->uid][$group] = $val; } @@ -592,13 +604,13 @@ function og_multiple_mandatory_groups_by if (($gid == $value) && !$results) { //only subscribe if no subscription exists og_save_subscription($gid, $user_id, array('is_active' => 1)); if (user_access('administer users')) { - drupal_set_message(t('The user %uid has been subscribed to group %gid.', array('%uid' => $user_id, '%gid' => $gid))); + drupal_set_message(t('The user \'%user\' has been subscribed to group \'%group\'.', array('%user' => $all_users[$user_id]['name'], '%group' => $og_groups[$gid]))); } } elseif (($gid != $value) && $results && !in_array($gid, $all_users[$user_id]['owns'])) { //only unsubscribe if a subscription exists og_delete_subscription($gid, $user_id); if (user_access('administer users')) { - drupal_set_message(t('The user %uid has been unsubscribed from group %gid.', array('%uid' => $user_id, '%gid' => $gid))); + drupal_set_message(t('The user \'%user\' has been unsubscribed from group \'%group\'.', array('%user' => $all_users[$user_id]['name'], '%group' => $og_groups[$gid]))); } } } @@ -628,7 +640,7 @@ function og_multiple_mandatory_groups_by drupal_set_message(t('There was an error processing the data. Try again, or contact your site administrator.'), 'error'); } else { - drupal_set_message(t('The changes have been saved.')); + drupal_set_message(t('All assignments have been processed.')); } } //function og_multiple_mandatory_groups_by_role_admin_submit() @@ -643,18 +655,23 @@ function og_multiple_mandatory_groups_by if ($admin = user_access('administer og mandatory groups by role')) { $option_result = db_query("SELECT n.nid, n.title, o.* FROM {node} n INNER JOIN {og} o ON n.nid = o.nid WHERE (o.og_selective = %d OR o.og_selective = %d) ORDER BY n.title", OG_CLOSED, OG_OPEN); - while ($group = db_fetch_object($option_result)) { - $options[$group->nid] = $group->title; - switch ($group->selective) { - case OG_OPEN: - $options[$group->nid] .= ' | ' .t('Open group, users can unsubscribe.'); - break; - case OG_CLOSED: - $options[$group->nid] .= ' | ' .t('Closed group, users can not leave.'); - break; - } + if( db_affected_rows($option_result) <= 0 ) { + $options = array( "" => "(no groups enabled)" ); } - + else { + while ($group = db_fetch_object($option_result)) { + $options[$group->nid] = $group->title; + switch ($group->og_selective) { + case OG_OPEN: + $options[$group->nid] .= ' | ' .t('Open group, users can unsubscribe.'); + break; + case OG_CLOSED: + $options[$group->nid] .= ' | ' .t('Closed group, users can not leave.'); + break; + } + } + } + $added = _og_multiple_mandatory_groups_by_groups_get_added(); foreach ($added as $group_id => $name) {//remove from the select, groups we're already working with if (array_key_exists($group_id, $options)) { @@ -748,10 +765,11 @@ function theme_og_multiple_mandatory_gro /** * Returns a confirmation page for deleting a group from the mandatory group availability table. * + * @param array $a API array. * @param integer $gid Value of group to be deleted; passed in from path. * @return array $form The GID is passed to the submit. */ -function og_multiple_mandatory_groups_by_role_group_confirm_delete($gid= NULL) { +function og_multiple_mandatory_groups_by_role_group_confirm_delete($a,$gid=NULL) { if ($gid == NULL) { drupal_goto('admin/og/og_multiple_mandatory_groups_by_role/groups'); return; @@ -795,10 +813,11 @@ function og_multiple_mandatory_groups_by /** * Returns a confirmation page for deleting a group from the mandatory group availability table. * + * @param array $a API array. * @param integer $gid Value of group to be deleted; passed in from path. * @return array $form The GID is passed to the submit. */ -function og_multiple_mandatory_groups_by_role_group_confirm_delete_unsubscribe($gid= NULL) { +function og_multiple_mandatory_groups_by_role_group_confirm_delete_unsubscribe($a,$gid=NULL) { if ($gid == NULL) { drupal_goto('admin/og/og_multiple_mandatory_groups_by_role/groups'); return; @@ -839,7 +858,7 @@ function og_multiple_mandatory_groups_by } $dbquery = db_query('DELETE FROM {og_multi_mand_groups_role_groups} WHERE gid = %d', $form_state['values']['gid']); if ($dbquery) { - drupal_set_message(t('The group %gid has been removed from the mandatory group availability table.', array('%gid' => $form_state['values']['name']))); + drupal_set_message(t('The group \'%gid\' has been removed from the mandatory group availability table.', array('%gid' => $form_state['values']['name']))); watchdog('content', 'og_multiple_mandatory_groups_by_role_groups: deleted %gid.', array('%gid' => $form_state['values']['name'])); } $return_address = 'admin/og/og_multiple_mandatory_groups_by_role/groups';