Closed (fixed)
Project:
Flag
Version:
6.x-1.1
Component:
Documentation
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
3 Feb 2009 at 18:31 UTC
Updated:
30 Jan 2012 at 08:55 UTC
I am making a content template, and would like to get the users who flagged a node (non-global flags) when the node is being displayed. How would I go about that? On reading the API page I found how to get the number of people who flagged, but not how to find their uid's (I will be using that to find some information from the user's profiles for display alongside the document).
Comments
Comment #1
mariusooms commentedThis is what I use (code provided by Moofie) to display the user pictures. You can display anything from the user though.
Hope this helps.
On the subject though, I wish I could make this loop through an ajax check so it would update in real time when you add yourself. Is that even possible?
Regards,
Marius
Comment #2
mooffie commentedSure it's possible. See Triggering JavaScript actions.
Comment #3
mooffie commented@Ninja,
See the handbook for instructions on how to do this with Views. Then you can embed the view in your node.
@Marius,
Note that your code lists all users who flagged this node, whether they "bookmark"ed it or "spam"ed it. To filter for a specific flag you need to examine $data. Perhaps somebody should explain this in a handbook page. (I remember that you used D5 when you asked your question, so Views wasn't applicable for you because D5's Views can't list users.)
Comment #4
mooffie commented(Well, the handbook actually explains how to produce a list of users in D5. But I agree that coding stuff ourselves is sometimes easier.)
Comment #5
mariusooms commentedGreat news...I see the handbook has all kinds of new stuff!
Regards as always,
Marius
Comment #6
mariusooms commentedHi mooffie...I'm having a relatively small problem.
I have a block configured and set to refresh using the code from the handbook. The view is working correctly, however the content halts on the newHtml somewhere. The old content disappears, but is not replaced by the new content. On manual refresh the changes are shown.
Now...messing with view, I noticed if I remove the argument to load "Node ID from URL" the view is refreshing by ajax correctly (removing and adding). The only problem with this is, obviously, that I'm letting the view pull data from all the nodes.
Any idea what I'm doing wrong? I looked over it myself for quite some time now and really can not figure it out.
Regards,
Marius
Comment #7
mooffie commentedYou took the code from the hanbdook. That code asks Drupal for a block. Nothing more. The URL Views sees is "component/block/views/my_great_view", not "node/123", so it can't extract the node ID, because it isn't there. That's the problem.
A very quick way to solve this:
Say the URL you're constructing in that JS code is "component/block/views/my_great_view". Change it to "component/block/views/my_great_view/123", where that number is the node number. Then type "arg(4)" in the PHP code for the argument.
====
There's a different way to solve this. A better way. Views 2.x already has AJAX capabilities. So it shouldn't be hard to add to it a function to refresh a view (from JavaScript). Open a "feature request". If this gets accepted, refreshing a view would entail only one line of JS code.
Maybe Views already has this feature. I don't know. I haven't touched Drupal in months.
(Yet another solution is to enhance the "component" module. Or to look for a better module.)
Comment #8
mariusooms commentedFirst thanks for thinking with me here...especially when not being involved with Drupal for some time (I know how that feels).
I did that like this:
The 70 is not dynamic at the moment, it's just to test this current solution.
Finally to make sure, I de-select "Node id from URL" and set it to "PHP Code" and just type arg(4) for the code there? After doing that the block view doesn't return a value anymore.
I also opened a request at the views module in hope that it offers a better existing solution.
Regards,
Marius
ps. Sorry to bug you with this, I wish it just worked.
Comment #9
mooffie commentedSome things to try:
Comment #10
mariusooms commentedGot it...should have known that myself :)
Okay, the views argument works I see result for both adding and removing a flag.
Yeah...I have it set up like that. The empty text is not showing either.
Regards,
Marius
Maybe this is not the route to go? I also opened a request in views issue queue (http://drupal.org/node/369693) and this is what merlinofchaos said:
The problem for me is I know squat about javascript. Also, it is a purely aesthetic request and I can live with it not working for blocks, but it would add a professional touch to the sites functionality.
Comment #11
mooffie commentedYeah, that's definitely the way to go. Views 2.x already has AJAX capabilities so there isn't a reason to re-invent the wheel with that 'component' module.
I won't be able to help here further, because I can't run Drupal on my system. 'ajax_view.js' should ultimately have a 'refresh()' utility method. It's a pity I can't provide a patch. Maybe some developer will see the need and do so.
===
Mmmm... So when you type in the address bar all works alright, but it's only the JS that doens't work? Strange, because the JS just mimics the former. Perhaps you have a JS syntax error.
Comment #12
mariusooms commentedThanks mooffie,
I will hold on and wait till there is a solution for the ajax_view.js.
Regards,
Marius
Comment #13
ShutterFreak commentedHere's some code I used to identify users that flagged a given node as relevant (custom flag "relevance"). In the "node.tpl.php" template file I wrote a code snippet that only displays this information for one specific user role (called 'privileged user'), and I group the users based on an "organization" field that I added in their user profile:
I opted for sorting the entries per organization (via
ksort()), and within an organization per user name (viasort()). The data are rendered as an unordered list with one bullet per organization.Comment #14
grigori commentedplease tell me where is the HANDBOOK ?? i cannot fin it!
Comment #15
sirkitree commentedGo the main module page... of any project. Click the link that says "Read documentation" underneath "Resources".
Comment #16
grigori commentedi did that, didn't help i still think i there is somethig wrong with this coz i tried on houndreds different way to set up my view to display the users who flag node and still doesn;t show what it suppose to
if there was actually instruction in the handbook how to do it...that different story
must be something wrong with this
Comment #17
grigori commentedcontinue....form previous post
i got
Relationships
Flags: ownit by current user (ownit is just a name, could be bookmark)
Flags: User's flagged content ownit
Arguments
(user flagged content) Flags: Content ID
Fields
User: Name
Filters
(user flagged content) Flags: Flagged True
and this is displaying:
ewahalladin
ewahalladin
ewahalladin
ewahalladin
ewahalladin
ewahalladin
root
root
root
root
root
root
root
root
root
root
root
root
root
root
and should only:
ewahalladin
root
Comment #18
mooffie commentedGreg, the handbook page you're looking for is:
How to setup a "Who's bookmarked this" tab
It seems that your "Flags: Content ID" argument is optional and you didn't provide it. You have to type some node ID, e.g. "25", at the appropriate place in the URL (or, into the "arguments" box of View's "live preview").
Comment #19
mooffie commentedIt seems there's a temporary(?) problem on Drupal.org. Normally, under each page are listed its child pages. But this doesn't happen at the moment. That's why you don't see links to further info on the handbook's front-page. That's why I provided a direct link to the Views recipe you're after.
Comment #20
grigori commentedfirstly - thank you for help
so ok i did like it said in the handbook notes (thanks for that)
but there is this thing i am interesting in:
"If your view work correctly, you can easily turn it into a block. Add a "Block" display. Since blocks don't get arguments from the URL, you'll have to add the "Node ID from URL" default argument. Lastly, enable your block (via "Administer >> Site building >> Blocks")."especially the part
you'll have to add the "Node ID from URL" default argumentwhat is this
from URL? when i click on argument Node ID (it actually Node: Nid) how can i setup this?Action to take if argument is not present:
Display all values (i suppose)
Validator:
?
flaggable node ?
faggable user ?
--------------------------------------------------------------
there is another thing
on the handbook it says that we have 2 options:
1)
2)
BUT !!
if you consider BLOCK
If your view work correctly, you can easily turn it into a block. Add a "Block" display. Since blocks don't get arguments from the URL, you'll have to add the "Node ID from URL" default argument. Lastly, enable your block (via "Administer >> Site building >> Blocks").you cannot go for option 1 because in user-type view in Arguments we dont have option Node : Nid
so we go to option 2
we set up view (default) we add
1)relationship:
Flags: ownit by any user
(flag) Flags: User
2) Arguments:
Node: Nid
3) Fields:
(Flag user) User: Name
(flag) Flags: Flagged time
and know we want this in block right?
so we need this argument "Node ID from URL" but We already have it !? or dont we?
is this "Node ID from URL" = Node: Nid
or i should add bock display and add another node: nid
it is confuzing and it is not working !!! please tell me what i am doing wrong
Comment #21
grigori commentedthis is what i have after following the handbook:
http://www.freeimagehosting.net/uploads/8b94e02ad4.jpg
[not really what i want, is it?]
Comment #22
mooffie commentedDid it work?
===
No. You don't need to add any other argument.
You need to configure the *existing* argument.
That's close, but it isn't this setting. Well, maybe it is. There's a setting that lets you pick a value for the argument. There are several possibilities there, among them the "Node ID from URL" one.
The problem is that I'm not running Drupal and therefore I can't instruct you in the exact mouse-clicks to carry out. If you attach a screenshot here of the argument's setting page I might be able to help.
(BTW: Alternatively, there's also a "PHP code" possibility, which let's you type the PHP code to produce the argument value. You could type
return arg(1);there and this would be about the same as the "Node ID from URL" solution.)That's a very good point. Perhaps that "Node ID from URL" doesn't exist for user-type views. I tend to believe it does exist.
Comment #23
walker2238 commentedRegarding this snippet...
HOw can I limit the output to a given number.. same... last 10 results?
Comment #24
mariusooms commentedMoofie's reply to that code :
and he's right...you can now do this easily in views. So the code is no longer necessary.
Regards,
Marius
Comment #25
fabrizioprocopio commentedI thought to post here instead to open a new issue.
Relating the guide
http://drupal.org/node/326308
I do not know how I go on about the 4th point.
What have I put in the title of argumet?
the example
node/%/whodoesn't let me catch what I have to do
I'm not a php coder, not even a views2 champion user :-)
Last answer relate to that guide: always in 4th point, in argument what I choose for validation filed?
thanks by now
for your time
fab
P.S.: My answers they may be OT since it could be a views' stuff too
but being essentially related also to flag module I thought to ask to you: very active on helping
Comment #26
mitchell commentedSee: How to setup a "Who's bookmarked this" tab.
Comment #27
amir simantov commentedFollowing #22
I was messing with it a while, as well. Then got a an answer from yhager - what there is to do is indeed to edit the argument, and keep on like this:
Under "Action to take if argument is not present" choose "Provide default argument"
Then continue as muffie explained:
Under "Default argument type" choose "Node ID from URL"
Amir
Comment #29
hansrossel commentedIf you get duplicates like in #17, it means you made a node view, while it should be a user view.