Please review this sandbox http://drupal.org/sandbox/bucefal91/1909506 project.
The repository can be found here: git clone http://git.drupal.org/sandbox/bucefal91/1909506.git numeric_field_filter
Drupal version: 7.x
Link for PAReview.sh: http://ventral.org/pareview/httpgitdrupalorgsandboxbucefal911909506git-7...
There are some coding standard errors, but I left them intentionally to follow general views handler naming approach.
Description
Numeric Field Filter introduces ability to filter numeric fields attached to any entity not only against a constant factor (like it does standard views numeric filter), however also to filter against another numeric field attached to the entity.
For example: you have a field "Distance to sea" and a field "Distance to the capital". Using this filter you can build up a view that will get you all the entities that are closer to sea than to its capital, i.e. it allows you to build queries like ...WHERE field_distance_sea > field_distance_capital. It supports all basic operators for number comparison like:
- less than (<)
- less than or equal to (<=)
- equal (=)
- not equal (!=)
- greater than or equal to (>=)
- greater than (>)
- between
- not between
Apart from its ability to filter against values of another field, it also introduces ability of simple mathematical operations between fields before they are compared. Recalling to our previous example, a slightly more advanced version would be to get all entities that are closer to the sea at least by 1.5 times than to its capital. This kind of filtering is also possible with Numeric Field Filter module. Thus it would build a query like ...WHERE field_distance_sea > 1.5 * field_distance_capital. Right now filter allows you to execute the following operations on the fields before comparing them:
- summation (+)
- substraction (-)
- multiplication (*)
- division (/)
I see this module as a useful feature and I will be using this module in one of my projects, that's essentially the reason I created this module.
Comments
Comment #1
abhijeetkalsi commentedHi,
first of all there are quite a few issues to sort out such as indentation, whitespace.
You can find them all here:
http://ventral.org/pareview/httpgitdrupalorgsandboxbucefal911909506git
Here you can check source code whether it meets drupal coding standards or not, and advise you what to change in your code. You can repeat review after your commits, and can fix those errors. And then change your status again.
Also If you want that community reviewer will review your module, that change your status to "Need Review".
Comment #2
bucefal91 commentedThank you for letting me know, I didn't know i have to have the issue status in needs review.
As of the coding standard errors, as I mentioned in the issue post, the only errors it finds is about naming conventions of a views handler and missing doc comments to the methods that views handler overrides. I left naming conventions not in lowerCamel because it's a general method naming convention among all views handler. I did not put docs to the methods it overrides, because the methods are documented in a parent class. If that necessary, though, I can copy the same doc comments, I just do not see much point in doing so.
Comment #3
rob.barnett commentedbucefal91,
First of all great contribution. I did an initial review of your code and at first glance I found the following in numeric_field_filter_handler_filter_numeric.inc:
Line 15: class names should begin with capital letters.
Lines 23 & 31: class properties should use lowerCamel and not underscores.
Review your functions and include doc comments where missing such as with function option_definition(). See http://drupal.org/node/1354 for more information. I recommend using code sniffer which is now into the coder project: http://drupal.org/project/coder.
Comment #4
bucefal91 commentedHi,
Have you read the previous review and my reply? The class name and its methods are called following general naming conventions of views handler, since numeric_field_filter_handler_filter_numeric is one too. For the same reason some methods are not documented - because those are inherited from parent, which is views_handler_filter_numeric, and if you take your time to examine that handler, it doesn't document methods inherited from its parent neither. Thus again, following conventions I prefer not to change the pointed out errors found by code sniffer.
And again, I do not mind renaming class and its methods, and adding doc comments, if it's how it should be done. I just have a feeling that you didn't even check my arguments for keeping things as they are.
Comment #5
rob.barnett commentedbucefal91,
I had read your previous comments about why, however, I have seen projects held up because they don't comply completely with Drupal standards so I'm just trying to help. Also, coder did find the following:
numeric_field_filter_handler_filter_numeric.inc
Line 119: String concatenation should be formatted with a space separating the operators (dot .) and the surrounding terms
$this->query->add_where_expression($this->options['group'], $field . ' ' . $this->operator . ' ' . $this->value['value']);
While minor and nitpicking, I don't know what might hold up your project getting approved so I'm just pointing out what could be "fixed" so you can get your project approved faster. I am not seeing any other errors and no php errors, notices, etc so these should be easy fixes. The code runs properly in my local Drupal set up. You may want to provide documentation beyond your description such as a tutorial on how to apply your filter within views. Not necessary but may be helpful to community members.
Comment #6
rob.barnett commentedFor what it's worth, I would recommend this for full project. The minor issues I pointed out really are minor but addressing them may speed up the approval process. The filters work as expected in my install and it is very useful indeed.
Comment #7
klausiWe are currently quite busy with all the project applications and I can only review projects with a review bonus. Please help me reviewing and I'll take a look at your project right away :-)
Comment #8
heddnThis is a nit, but internal private functions usually begin with an underscore, '_'. Perhaps rename
numeric_field_filter_field_types()to_numeric_field_filter_field_types().Its a code style thing, but have you considered using
if (!=) {}rather thanif (==) {continue;}. I'm referring tocounterpart_field_options()&numeric_field_filter_views_data_alter(). In the second case, you can still account for theisset()condition using anelse.Comment #9
bucefal91 commentedHello, everybody!
Thank for being active on reviewing this module! hurley, I am sorry, I really didn't mean to offend but I just really had a feeling people do not read because they were not referring to what I said, simply suggesting fix those errors. Sorry.
I followed your advice, and now even the inherited methods got documentation comments. And I fixed that error of double space in string concatenation.
I also renamed this function _numeric_field_filter_field_types() to prefixed with "_" as suggested by heddn.
Also, I have introduced some security measures - now I sanitize user input in the filter textfield (the place where you supposedly can enter formula + the placeholder [counterpart-field]). Since the user input is directly entered into SQL via $this->query->add_where_expression() - I find it worth to sanitize input, though I am not sure whether add_where_expression sanitizes anything or not. Additionally by this sanitization filter would be able to "fix" (throw away) any possible syntax errors before inserting string into SQL, however this happens just in a very basic fashion - simply stripping any not allowed symbols.
And another also: I have committed an improved and extended version of the handler. Now when choosing counterpart field you are not only limited to the numeric fields of the base entity. If you have an entity reference field attached to the base entity and you add relationship in views to "join" the referenced entity, now dropdown of available counterpart fields will not only let you pick one from numeric fields of the base entity but also any numeric field of the referenced entity. Putting it simple, now it takes advantage of views relationships to make itself even further flexible.
And lastly. Especially after adding support for views relationships, it got even more complicated. I do think this filter requires some documentation on how to use it. The only thing is that I would like to let it get a little more mature (maybe suddenly we'll figure out some even better approach or whatever) and then, when it got shaped up more or less - at this point write docs because I just don't want to do the same job twice. But you got my word: this module will have documentation... at some point :)
I will be happy to get more input and suggestions on how to develop this module because it does look useful and promising.
Comment #10
aendra commented✗ Automated Review:
275 | ERROR | Inline comments must start with a capital letterReally, that shouldn't hold up promotion.
✗ Manual Review:
Comment #11
bucefal91 commentedHi!
Thanks for checking out the module! You have a verrrrry good catch on multiple field values - I admit, I haven't tested module's behavior with multiple value fields. Definitely I need to at least document behavior, or.. preferrably make it behave on multiple values the same way as views native numeric filter does - to keep the interface consistent and less confusing for the end users.
However, unfortunately you caught me at a bad moment, I've been refactoring module lately, I plan to use it for myself in one of my projects and I need to make it able to filter not only float to float, but also, say, measured value to an unmeasured value, or do comparisons between 2 measured values. I am using MVF module for what I refer to here as "measured value", but I am working on defining a general interface that can be implemented by whoever else to make another field type comparable by the view filter introduced by Numeric Field Filter. I'd like to finish this refactoring and then figure out how to handle multiple values, and then do another round of application for full project.
Thanks again for glancing at the module and saying it's pretty slick :)
Comment #12
bucefal91 commentedI've set down and wrote up some basics of the ideology I hope to implement in the scope of this refactoring. So we are gonna have something like the following:
[base field] [operator] [counterpart field]where [base field] and [counterpart field] are SQL expressions of type [field table alias].[field value column] or something similar, what I want is to be able to "convert" a Field API field into SQL expression that will represent abstract "value column" of that field, once it's done filtering one field against another becomes just as simple as filtering against a constant factor (you just substitute the constant factor with the SQL expression that has been generated for your counterpart field). And [operator] here may be <, >, =, <> (note here: BETWEEN and NOT BETWEEN may be decomposed into 2 basic operators). Once again,[base field] [operator] [counterpart field]this is the skeleton that I hope to implement with the following principles:That's what I hope to have in Numeric Field Filter... with that said, seems like it can be quite powerful and useful; and, what is more, quite flexible to cover many use cases for Drupal community.
People are welcome to argue on those principles and let's find even better approach to solve this task!
Comment #13
bucefal91 commentedI got some news.
I have just finished working on the refactoring, module looks more promising now. I have defined an interface using which other modules may introduce more and more numeric field types that may be inter comparable. Numeric Field Filter out of the box ships with ability to compare field types defined in Number module, however, really soon I hope to update Measured Value Field module and it will integrate with Numeric Field Filter too - this is where you'd be able to see the power of this new version of Numeric Field Filter.. For example. We have a field "distance to sea" measured in either miles or km and we have another field "Population of the town". And let's say we want to compare them in Views. We can do things like "Dinstance to sea in km < population" or "Distance to sea in miles BETWEEN 0.1 * population AND population", etc.
I have checked your point about unlimited cardinality. Views numeric filter behaves in the following manner. If there is a field with unlimited cardinality and there are more than 1 delta which stands the filter's criteria, multiple rows of the same entity will be present in views results, unless Dinstinct option in query settings was set to TRUE. I made sure Numeric Field Filter module follows the same pattern, which seems to be quite resonable as a matter of fact.
The only part here I am not sure of is this one. Let's say we have a field Float1 and a field Float2, both are of unlimited cardinality and are attached to the same entity. If we set up numeric field filter to be Float1 < Float2, it's gonna be confusing, because we'll have a few operands on the left side and a few operands on the right side... and in this kind of situation I am not even sure what would be the best behavior. Maybe somewhere in the settings of this filter we should let the user enter delta of the counterpart field it wants to filter against? (and we might have one extra option there saying "delta wise" so Float1 delta#1 gets compared to Float2 delta#1 and Float1 delta#2 is compared to Float2 delta#2 and so on).
Oh, and one more thing, I gave up trying to make it work as a grouped exposed filter - that's why there is bunch of commented out code - those are my efforts to make it work. This feature is not a real priority for me.
Comment #14
tanzeel commentedVery good work. I just review manual review and couldn't find any thing sub-standard.
Comment #15
kriboogh commentedNice work, seems to do its job :-)
On a side note, how difficult would it be to also make this work for date fields (or any other?); I had a use case the other day where I had to build a view of nodes that where older than the node given by a nid argument. The date to compare to was not the created date, but a datefield in the node content type.
Which actually leads me to an other feature request if its not yet possible. Can I use a view argument as a replacement value? So in stead of using [field] in the formula or value settings use %1 for example to refer to view argument 1.
Nice job.
Comment #16
kriboogh commentedMaybe found one thing, I've got this warning coming up now: (running PHP 5.3, latest Drupal 7 install)
Strict warning: Only variables should be passed by reference in numeric_field_filter_handler_filter_numeric->ensure_my_table() (line 275 of /.../sites/all/modules/custom/numeric_field_filter/views/numeric_field_filter_handler_filter_numeric.inc).
you should put the result of the array_keys into a variable and pass this on to array_pop.
Comment #17
bucefal91 commentedHey there!
Uffff, don't think I've abandonded this sandbox project.. simply I am graudating at univeristy (finally it is about to happen). But I hope within a few weeks I will get time to fix the warning you've come across.
And you have a good point about putting date fields onto these rails, we can convert it into timestamp (I am not sure in what value date module actually stores its columns) and then treat it just like an integer.
And your thought about using an argument instead of a counterpart field is also promising. Definitely there is gotta be a way to implement argument-friendly feature.
I'll reply in more details when I am ready to devote time to this module. For now i am afraid it has to hibernate for a bit of time.
Thank you for reviewing and feedbacking :)
Comment #18
bucefal91 commentedI have fixed that strict warning problem. I guess once again it is eligible for being approved.
Comment #19
bucefal91 commentedI have also added a documentation page for the module. https://drupal.org/node/2025513 and it is also listed as such on the home page of the module https://drupal.org/sandbox/bucefal91/1909506
Comment #20
kscheirerVery nice module - this looks useful for many projects.
Code looks good, I can't find any problems. You could delete
numeric_field_filter_handler_filter_numeric::build_group_validate()if it's not necessary anymore. I agree that the ventral.org reports for the views code are spurious.----
Top Shelf Modules - Enterprise modules from the community for the community.
Comment #21
bucefal91 commentedwiiiiiiiiiii :) Thanks!!!! Then how do I proceed?
It took a bunch of time to get this module approved, but I am glad it is approved now, and I have to admit throughout this "project review" time it was getting better and better.
Comment #22
kscheirerCoder has been updated, errors reported at http://ventral.org/pareview/httpgitdrupalorgsandboxbucefal911909506git. But it's mostly about whitespace and scope modifiers, those are not blockers. It's been almost a month in RTBC.
Thanks for your contribution, bucefal91!
I updated your account to let you promote this to a full project and also create new projects as either a sandbox or a "full" project.
Here are some recommended readings to help with excellent maintainership:
You can find lots more contributors chatting on IRC in #drupal-contribute. So, come hang out and get involved!
Thanks, also, for your patience with the review process. Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.
Thanks to the dedicated reviewer(s) as well.
----
Top Shelf Modules - Crafted, Curated, Contributed.