I have been reading through all the tutorials and it seems like I have my relationships setup properly and when I flag a node it gets updated by creating a record in flag_content but the uid within that table is ALWAYS 0 for me.
The flag itself is a node type and global. I changed the UID to that of my own and it showed the proper user flagged, but then I was unable to remove the flagged until I had to change the UID back to 0. The funny thing is when I flag a node the flagged time gets updated properly.
I am new to drupal but I do not think I am doing anything wrong.
My relationship:
Flags by any user
(flag) Flag : user
and when I try to display it :
(flag) flagged time
(flag user) user: name
I think this might be an issue.
| Comment | File | Size | Author |
|---|---|---|---|
| #18 | condition.png | 32.83 KB | wheatpenny |
| #18 | action.png | 32.85 KB | wheatpenny |
| #18 | overview.png | 29.55 KB | wheatpenny |
| #10 | flag-DRUPAL-5.global-flag-uid.patch | 4.76 KB | sun |
Comments
Comment #1
BoGs commentedI think I figured it out for myself on line 396 of the flag.inc - seems like it checks if the flag is global and sets the UID = 0 .... why is that is there some significance?
Comment #2
sirkitree commentedglobal flags do this. sounds like maybe your flag is a global one?
Comment #3
BoGs commentedIt was a global one but then when a user would flag an item and the flag is global wouldnt that restrict them beeing able to view it?
for example I have a Q&A website where I needed to display the user that answered the question and only the first user - is that how it is supposed to be? what is the reasoning behind it?
Comment #4
quicksketchFlag stores the UID of 0 when a flag is global. If you want to store the UID then the flag should not be global. Global flags work identical to the functionality of the "promote to frontpage" or "sticky" options provided by core. If a single user toggles the option, it toggles it globally, for all users, not just for the user that made the node sticky.
Comment #5
BoGs commentedok - but how would you get the data of the user that toggled the global flag (UID)?
Comment #6
quicksketchThat functionality is not supported. After #322034: Have a $flag->access() method is finished, you could do all kinds of things with only allowing an element to be flagged once by any user (and not have the flag be "global"). Then the UID would be recorded and you could make a module that disabled any further flagging on that piece of content by denying access to that flag.
Another option is that Flag already provides a hook_flag() function that a custom module in your site could implement. Then you could use global flags and just record an additional bit of information when elements are flagged. I'm not clear on your exact use-case though, could you describe it further?
Comment #7
jorgeegomez commented@quicksketch, although I'm not the original submitter, I have several use cases for our intranet, where I need some manager to "sign off" on a document, and a case where someone can schedule an event or task and afterwards mark it as done.
I started using global flags (the event is either done or it isn't), but I need to show who was it that marked it as complete.
I'm not clear on the reasoning behind the
$uid = $this->global ? 0 : ...command in flag.inc -- "this applies globally to the node" does not lead to "...therefore we don't need to know who toggled it".Comment #8
quicksketchSounds like you should be using Workflow module for managing when things are in certain states, since that's it's entire purpose.
Comment #9
quicksketchTo further my comment: perhaps it is important to know who flagged a global flag, but at the same time, it's not helpful enough if you really wanted a full solution to that problem. In order to be really useful, you'd need to know not only who flagged the item, but it's history of flagging and why the user did this.
For this reason, I'm hoping to delegate this functionality to the as-of-yet non-existant "flag_history" module. This module would require users to enter a reason for their flagging, and maintain a history of when an item was flagged. However, I'd like to keep the core flag module independent of this functionality. There's nothing stopping it from being written right now, other than a lack of time or need by the maintainers.
Comment #10
sunUsing uid 0 will make flags by anonymous users very hard to implement and maintain. Also, I see no reason why we should force ourselves to loose meta information for stored data.
Attached is a kick-start, against 5.x though.
Note that flag_get_user_flags() is a bit too overloaded currently - I think that parts of it should be flag methods instead, so we can dynamically query with or without $uid, depending on whether a flag is global or not.
Comment #11
quicksketchThe Flag
HistoryNote module provides this functionality and maintains a history as I described in #9: http://drupal.org/project/flag_note, making the need for this particular functionality unnecessary.Comment #12
tomski commentedI found a solution to this issue - it is a little complicated (I am sure it can be done in a more elegant way) but it works and it does not need any hack to the flag node.
First : you need to have the modules CCK and Rules installed.
Second : you create a usereference field in the content type/s you want to be flagged by your global flag and you set it to invisible (if you have permissions by field remember to give view rights to whatever users you need).
Third : you create a rule for the event "a node has been flagged", and you set the global flag you want as reference.
Fourth : you create an action "populate a field", you select te usereference field you have created before and in "Advanced: Specify the fields value with PHP code" you put :
return array(0 => array('uid' => $flagging_user->uid));This will put the uid of the flagging user in your usereference field.
Fifth : in your view now you just need to display the usereference field and you will see for each node who has flagged it.
Comment #13
premanup commentedThank you tomski! Your solution is quite easy and usable.
Comment #14
N4R4YAN commentedReally, really nice workaround.
This is what i was looking for for quite some time.
If i might add something is to contemplate the "unflagging" as well doing the exactly same thing but adding another rule with this condition...
"a node has been unflagged" under whatever flag you are going to manage
and add the same action that is going to clear the field data...
return array(0 => array('uid' => $flagging_user->NULL));I am not the best coder so prorably this could be done in another way but as it is it works like a charm.
Thanks again tomski :)
Comment #15
jami3z commentedAnyone accomplished #12 in D7? I need to do the exact same thing but there doesnt seem to be a "populate a field" action available
Comment #16
wheatpenny commentedYes, I just got #12 to work in D7. The catch I found is that first, under "Conditions" you need to test if the user reference field is present for the flagged node. Then in the Action section, you can "Set a data value" and set the user reference field to the flagging user.
Let me know if screenshots would be clearer.
Also, when I made the "unflag" rule as #14 smartly suggested, I just set the data value to "0" and that returned the user reference field to "- None -."
Comment #17
jami3z commented@stripesandcheckers if you could provide screenshots that would be awesome! cheers
Comment #18
wheatpenny commentedSure thing.
This condition will make the user reference field available to be changed in the Action.
Add an action that sets the user reference field to the flagging user.
Here is an overview screenshot after the Rule is completed: