I was hoping one of you smart folks could help me out with a little problem I am running into:
I would like to have my users be able to use flag "A" throughout my site. When they navigate to a certain page (probably the /user page) I need to be able to:

  1. Find all of the NID's that the current user has flagged and store them to an array
  2. Flag each NID with flag "B" on behalf of the current user
  3. Unflag "A" for each successful 'reflagging' to "B"

I think I need to use flag_get_user_flags() to return the NID's... but I am not sure, I am just getting into real PHP development (Newb would be fair!). Any nudge in the right direction would be GREATLY appreciated, I have been banging my head into the wall for hours on this!

Comments

quicksketch’s picture

1. Use flag_get_user_flags() like you have found.
2. Loop through and call the flag() function for each piece of content.
3. In that same loop call the flag() function and pass in the $op = 'unflag'.

I don't provide support on writing custom code in the issue queue.

thechanceg’s picture

I see. I think I can pull it off with some trial and error. Thank you for confirming I was using the right function.

thechanceg’s picture

Got it!!!!

Thank you for the great commenting in the flag.module file.

Here is the code that I used:

 <?php 
	$flag_status = flag_get_user_flags('node');
	$flag_status2 = $flag_status[flagA];
	if ($flag_status2) {
	foreach ($flag_status2 as $flaged) {
		global $user;
		$nodeid = $flaged->content_id;
		$newflag = flag_get_flag('flagB');
		$newflag->flag('flag',$nodeid,$user);
		$oldflag = flag_get_flag('flagA');
		$oldflag->flag('unflag',$nodeid,$user);
	}}
	?> 
quicksketch’s picture

Status: Active » Fixed

Super, thanks for the followup.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.