I published a user flag on user's profile page with this code:
<?php print flag_create_link('member_i_like', arg(1)); ?>
That seems to work. I can flag a user.
But when I want to unflag, I get the message the user has been flagged.
I've also created a view to list a user's flags/bookmarks with a flag/unflag link. Here I have the same issue. Flagged users cannot be unflagged.
Anyone any ideas?
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | phpMyAdmin.png | 97.8 KB | quicksketch |
Comments
Comment #1
mooffie commentedHow do you know the user hasn't been unflagged? (Perhaps it's only the message that's incorrect.) Refresh the page to find out what really has happened.
Comment #2
altparty commentedThanks for you instant response!
The messages are correct. Checked it more than once. Also the user is still listed on my bookmarks (flags) view.
After refreshing the page I still see the 'unflag' link.
Another strange thing: When I click on the 'unflag' link, the resulting message tells me: "this user has been flagged/bookmarked' (again: the messages have set up correctly).
Comment #3
mitchell commentedAnother way to do this would be setup a view similar to How to setup a "Who's bookmarked this" tab, except you would only display the flag ops field that matched with the first and only line of that user who you're looking at.
The block would then contain the link and you could put it in the sidebar or the content area, for example.
Comment #4
altparty commentedThanks mitchell, but that's not really what I'm looking for. Actually I think I've found the right view, but something isn't working well.
I have a similar view for node bookmarks and that one works correctly.
This is how the output of the 'my bookmarks' with only members listed looks like:
Date Name Edit
17.05.2009 - 11:50 John I don't like this anymore
etc.
I used 'Flags: User flag' as relationship type. When I uncheck 'Include only flagged content' in the relationships dialog, the output show also 'not flagged' content, what is correct. In the 'edit' column I see the option 'I like this' and when I click on it, a bookmark will be created. But I cannot remove the bookmark by clicking the link again. I don't have this problem with my node bookmarks view.
Here's the export of the view. Maybe someone finds something 'strange'...
$view = new view;
$view->name = 'my_bookmarks_users';
$view->description = 'My bookmarks users';
$view->tag = 'flag';
$view->view_php = '';
$view->base_table = 'users';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('relationships', array(
'flag_content_rel' => array(
'label' => 'flag',
'required' => 1,
'flag' => 'member_i_like',
'user_scope' => 'current',
'id' => 'flag_content_rel',
'table' => 'users',
'field' => 'flag_content_rel',
'override' => array(
'button' => 'Override',
),
'relationship' => 'none',
),
));
$handler->override_option('fields', array(
'timestamp' => array(
'label' => 'Date',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'date_format' => 'small',
'custom_date_format' => '',
'exclude' => 0,
'id' => 'timestamp',
'table' => 'flag_content',
'field' => 'timestamp',
'relationship' => 'flag_content_rel',
'override' => array(
'button' => 'Override',
),
),
'name' => array(
'label' => 'Naam',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'link_to_user' => 1,
'overwrite_anonymous' => 0,
'anonymous_text' => '',
'exclude' => 0,
'id' => 'name',
'table' => 'users',
'field' => 'name',
'relationship' => 'none',
),
'ops' => array(
'label' => 'Edit',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'link_type' => '',
'exclude' => 0,
'id' => 'ops',
'table' => 'flag_content',
'field' => 'ops',
'relationship' => 'flag_content_rel',
'override' => array(
'button' => 'Override',
),
),
));
$handler->override_option('sorts', array(
'timestamp' => array(
'order' => 'DESC',
'granularity' => 'second',
'id' => 'timestamp',
'table' => 'flag_content',
'field' => 'timestamp',
'relationship' => 'flag_content_rel',
),
));
$handler->override_option('filters', array(
'status' => array(
'operator' => '=',
'value' => '1',
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'status',
'table' => 'users',
'field' => 'status',
'relationship' => 'none',
),
));
$handler->override_option('access', array(
'type' => 'role',
'role' => array(
'2' => 2,
),
));
$handler->override_option('title', 'Member bookmarks');
$handler->override_option('items_per_page', 25);
$handler->override_option('use_more', 1);
$handler->override_option('style_plugin', 'table');
$handler->override_option('style_options', NULL);
$handler = $view->new_display('page', 'Pagina', 'page_1');
$handler->override_option('items_per_page', 40);
$handler->override_option('use_pager', 'mini');
$handler->override_option('path', 'my/bookmarks/members');
$handler->override_option('menu', array(
'type' => 'none',
'title' => '',
'description' => '',
'weight' => 0,
'name' => 'navigation',
));
$handler->override_option('tab_options', array(
'type' => 'none',
'title' => '',
'description' => '',
'weight' => 0,
));
$handler = $view->new_display('block', 'Blok', 'block_1');
$handler->override_option('fields', array(
'timestamp' => array(
'label' => 'Datum',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'date_format' => 'custom',
'custom_date_format' => 'j.m.Y',
'exclude' => 1,
'id' => 'timestamp',
'table' => 'flag_content',
'field' => 'timestamp',
'relationship' => 'flag_content_rel',
'override' => array(
'button' => 'Use default',
),
),
'name' => array(
'label' => '',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'link_to_user' => 1,
'overwrite_anonymous' => 0,
'anonymous_text' => '',
'exclude' => 0,
'id' => 'name',
'table' => 'users',
'field' => 'name',
'relationship' => 'none',
'override' => array(
'button' => 'Use default',
),
),
'ops' => array(
'label' => 'Bewerken',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'link_type' => 'toggle',
'exclude' => 1,
'id' => 'ops',
'table' => 'flag_content',
'field' => 'ops',
'relationship' => 'flag_content_rel',
'override' => array(
'button' => 'Use default',
),
),
));
$handler->override_option('title', 'My bookmarks');
$handler->override_option('header', '(members)');
$handler->override_option('header_format', '1');
$handler->override_option('header_empty', 0);
$handler->override_option('items_per_page', 5);
$handler->override_option('style_plugin', 'list');
$handler->override_option('style_options', array(
'grouping' => '',
'type' => 'ul',
));
$handler->override_option('block_description', '');
$handler->override_option('block_caching', -1);
Comment #5
quicksketchtruelove-nl, I imported your view and everything worked perfectly (though I changed the flag name to a flag I already had set up on my own site). As I "bookmark" users they show up in the list, then I can visit "my/bookmarks/members" and unbookmark any of them, then they are removed from the list on reload.
It doesn't really seem that this problem is directly related to Views, since you say that this same problem exists on user profile pages when just a normal flag link is printed out. Do any flags on your entire site work, or do they all have this problem? Flags getting "stuck" in a flagged state is an extremely unusual problem, because it means that the flag is being stored somewhere but not able to be removed. I'd suggest disabling any other modules that might be affecting flag (say flag_friend, flag_abuse, flag_weight, flag_actions, rules etc.) that might be affecting flag's behavior. If that doesn't work, disable then uninstall the module, re-enable it to start fresh with clean flag database tables (warning: uninstalling will drop all flag tables and data).
Comment #6
altparty commentedInstalling Flags is not really an option.
I just looked into the Flags tables and saw something strange.
I have 2 flags running:
fid content_type name title roles global options
1 node stuff_i_like Stuff I like 2 0 a:13:{s:10:"flag_short";s:12:"I like this!";s:9:"f...
0 user member_i_like Member I like 2 0 a:10:{s:10:"flag_short";s:12:"I like this!";s:9:"f...
But in the flag_types table I see to kinds of fids: 1 and 65535, and no '0'. Could this be the key to a solution?
Comment #7
quicksketchYes! I think that's it! Sounds like your database got borked somehow. I'd suggest changing BOTH "0" and "65535" to something more reasonable (like "2"). Flag should never insert a new flag at an index of 0 (it starts at 1 and goes up). Is your database set up to have fid be auto_increment in the flags table?
Comment #8
altparty commentedOK, I'll give it a try.
Can you please tell me how a table row for a user flag in the flag_types table should look like?
And...
Where do I have to look at?
Comment #9
altparty commentedProblem solved by changed all fid=0 to fid=2. I deleted all rows with fid=65535 in the flag_types table which seem to have no meaning. Thanks for the support!
I two questions remaining:
1) I have no rows for the user flag in the flag_types table. Is that correct?
2) How do I check whether the auto_increment in the flags table is setup correctly?
Comment #10
quicksketchYes that's right because currently when a user flag is created, all possible roles can be flagged.
In phpMyAdmin open up your database, and in the list of tables click the "flags" table. Then make sure auto_increment is on for the "fid" column. If not, edit the column and add auto_increment (it's a drop-down option under "Extra"). See screenshot.
Another good test is simply making a new flag, then seeing what FID it is assigned in the "flags" table. It should be the next unused number.
Comment #11
altparty commentedThanks again.
I had to add the auto-increment option. I also removed the default value for the 'fid' field which was set on '0'.