Hi,

would be great to assign a task to a og-group, so the user can fast assign a task to many people :D

dono if the autocomplet-function even search for thos groups?

Comments

ragesoft’s picture

Title: group assignment - assign a task to a organic group » group assignment - assign a task to a organic group or based on a cck field

need to extand this request:

i'm using custom cck-fields in user-profil.
this field is called: "profil_group"
its a dropdown with pre-defined groups.

would be great, to assign a to do to one of this groups, too!

is this possible?

AlexisWilke’s picture

CCK is quite difficult to work with. It's not very well written, API wise. (and these are lists of lists of lists, something of the sort as it is mapped to the forms, it includes the form hacks... it's annoying. 8-) )

I would think it would be easier to assign to a role (i.e. all the users in that role.) Then having one role per OG group would resolve the issue (maybe a bit annoying but then we would not directly depend on OG, which I know nothing about, btw.)

I'd accept a patch or rather, a new sub-module that does just that.

Thank you.
Alexis Wilke

capellic’s picture

I'd like to add my two cents here and I may be repeating already understood functionality in this request.

To be able to add a task for each of the members in a given group would be a great addition -- not a task at the group level (the group is going to pick up trash on Saturday), but to assign the same task to everybody in the group (bring a gift for the toy drive). Adding that task to specific roles (as mentioned in #2) in the group would be even more useful. (Note that there are the typical roles we use everyday in a Drupal install and then there are roles privy to OG -- OG User Roles (og_user_roles) -- but I'm not sure you have to be concerned with that module since that's for granting permissions within a group. But maybe it *would* be a good idea to consider this module since you may not want every system role in that select list -- only those relevant at the group level?

capellic’s picture

I came up with some code that's working for my particular situation using hook_form_alter. I needed a way to override the auto-complete fields for assigning to users and instead use a list of checkboxes which is all the users of a given group. This relies on GID being passed in when adding a new node or the node being associated with a group when editing. This all assumes that the node has been posted to a group. If not, it behaves in it's default capacity.

I think this code could be used to create a new module to be included in the to_do project to allow for OG interaction.

// Only invoke if OG is enabled
if (function_exists(og_list_users_sql)) {

	// Four our uses, we only need one GID
	$gid = intval($_REQUEST['gids'][0]);

	// If there is no GID, figure out which group this node belongs to
	if ($gid === 0) {
		$res = og_get_node_groups_result(arg(1));
		$obj = db_fetch_object($res);
		$gid = $obj->group_nid;
	}

	// Query the group for the members
	$sql = og_list_users_sql(1, 0, NULL);
	$res = db_query($sql, $gid);
	
	// Get the list of existing members
	$members = array();
	while ($row = db_fetch_object($res)) {
		$row_user = user_load(array('name' => $row->name));
		if ($row_user->uid != $user->uid) {
			$members[$row_user->uid] = $row->name;
		}
	}

	// Get list of existing users assigned to this node
	$users_selection = array();
	if ($form['nid']['#value'] > 0) {
		$node = node_load(arg(1));	
		foreach ($node->assigned_users as $uid => $name) {
			if ($uid != $user->uid) {
				$users_selection[$uid] = $uid;
			}
		}
	}					
}


// Buid list if there are members. This ensures the default behavior isn't 
// overwritten in the cases where the node is posted outside a group.
if (count($members) > 0) {
	$form['assignment']['assigned_users'] = array(
		'#type' => 'checkboxes',
		'#title' => t('Assigned to'),
		'#default_value' => $users_selection,
		'#options' => $members,
		'#description' => t('Unselect the users that should be have this To do item assigned to them.'),
		'#weight' => -10,
	);

	// Hide the auto complete forms before converting them to checkboxes
	for ($i=0; $i<3; $i++) {
		$form['assignment']['new_user' . $i]['#type'] = 'hidden';
	}
   }
}
charles.holtzkampf’s picture

thanks this is briliant, I will definitely be using this module.

AlexisWilke’s picture

Note that if you can create a sub-module and offer a .tar.gz or .patch for it, then I could include such code (#4) in the to_do module. Call it something like to_do_og.module and .info as required.

Thank you.
Alexis

charles.holtzkampf’s picture

Would it be possible to add realnames to the module, so if one has realnames installed and configured ot provides you with the list of members with their realnames instead of just the username.

Charles

AntiNSA’s picture

I am really looking for a way to assign all group members to a to do item.... anyone found out how?