I'm not sure if this is a bug or intentional, but when setting a filter for a flag counter less than 5 (for example), items with 1-4 flags will appear but items without any flags will be left out.
I wanted to use this for an "inappropriate" flag that would automatically remove content after a certain number of users flagged it as inappropriate, but right now the filter only allows "mildly" inappropriate content through...
I'm guessing the result of whatever function is called to retrieve the number of flag counts defaults to NULL when there are no flags associated with a node, but maybe it would be more helpful if the returned value was 0? I'm not a PHP expert, so I'm not sure how difficult this would be to change/if there's a good reason not to...
Comment | File | Size | Author |
---|---|---|---|
#17 | views_or_null_311210.patch | 2.43 KB | mmilo |
#15 | views_or_null.patch | 2.42 KB | mmilo |
#13 | views_or_null.patch | 2.45 KB | mooffie |
#12 | views_or_null.patch | 19.99 KB | mmilo |
#11 | views_or_null.patch | 20.01 KB | mmilo |
Comments
Comment #1
mooffie CreditAttribution: mooffie commentedThat's an SQL issue. Since the "count" column is NULL (for items never flagged), the expression
count < 5
evaluates to NULL, which is false. So the record isn't shown.Things to investigate:
1. How are the CCK people handle this same issue? (I'm refering to CCK's Numeric field)
2. Perhaps a newer views_handler_filter_numeric is smart enough to deal with a NULL?
Comment #2
mitchell CreditAttribution: mitchell commentedComment #3
quicksketchLike Mooffie said a while back, this is because of the way SQL works. NULL is not less than 1, it just doesn't exist. To fix this, the Views views_handler_filter_numeric class has to support creating a query that does a "WHERE field < 5 OR field IS NULL". Flag (and many other modules) will then gain the ability to list content that is either less than a certain value or 0.
Comment #4
cerup CreditAttribution: cerup commentedIs there a way to override this then? I'd also like the ability to filter by 'is below value or null'.
Comment #5
larowlanHi
Patch is attached that adds the following additional operators to the numeric filter:
Lee
Comment #6
quicksketchPerhaps a checkbox to "Include NULL rows" would be preferable to adding 5 additional options in the select list? Thanks for the patch either way though.
Comment #7
larowlanyeah good point, I needed this in a hurry and only needed one of the five but after writing it thought I should help others in the same bind out so added the other four, it would have been better your way, if I get time I'll redo it but that's not likely to be till next month at least.
Comment #8
ari-meetai CreditAttribution: ari-meetai commented+1
Comment #9
scarvajal CreditAttribution: scarvajal commentedSubscribing
Comment #10
bojanz CreditAttribution: bojanz commentedquicksketch's #6 is the way to go here, I think.
Comment #11
mmilo CreditAttribution: mmilo commentedHere's a patch as per #6, applied to views-6.x-2.12 (6.x-2.x-dev yields an error with relationships and I can't use it, as some refactoring seems to be in progress).
Includes a checkbox that checks for NULL values.
(My knowledge of Views coding is pretty limited, so hopefully this is correct)
Comment #12
mmilo CreditAttribution: mmilo commentedUgh, left a dpm() in there.
Comment #13
mooffie CreditAttribution: mooffie commented@mmilo: Here's a re-roll of your patch. View it to understand that yours wasn't generated correctly.
Comment #14
bojanz CreditAttribution: bojanz commentedallownull needs to be allow_null.
There are coding standard violations (IF without braces for example)
Not valid english. Try "Equates the value of NULL rows to zero." or "Treats NULL as zero."
Comment #15
mmilo CreditAttribution: mmilo commented@bojanz Can't say I agree it's invalid english - it would treat a NULL value the same as if it was a ZERO value. Changed it anyways.
Don't know what you're referring to when you say 'IF without braces' either? Could you point this out in the patch?
@mooffie Odd, I didn't look over the patch, weird it did that.
Comment #16
bojanz CreditAttribution: bojanz commentedAlso:
Opening brace comes in the same line as the function / switch.
Thanks, we are almost there!
Comment #17
mmilo CreditAttribution: mmilo commentedDoh, I read "braces" as "parentheses".
Comment #18
kenianbei CreditAttribution: kenianbei commentedsubscribe
Comment #19
merlinofchaos CreditAttribution: merlinofchaos commentedCommitted to 6.x-3.x -- doesn't apply to 7.x, for hopefully obvious reasons.
This hilites that the add_where on this filter needs to change. In the New World ORder we aren't allowed to assume an AND when adding multiple where clauses. We need to fix that. Created an issue for that here: http://drupal.org/node/1101876
Comment #20
drupalexio CreditAttribution: drupalexio commentedThis issue is about 6.x-3.x, not about 7.x-3.x.
Comment #21
dawehnerWell the patch got already committed to 6.x-3.x but wasn't ported to 7.x-3.x yet, so the issue status was correct
Comment #22
divined CreditAttribution: divined commentedand exposed filter support?
Comment #23
divined CreditAttribution: divined commentedFor 7.x last patch + change op_simple function, and don't change op_between..
and change check_for_null function:
Comment #24
David_Rothstein CreditAttribution: David_Rothstein commentedRelated issue, but for contextual filters: #2411811: Add an "OR IS NULL" option to contextual filters