Filtering

thread: 6 messages  |  last: about 5 years ago  |  started: thursday, november 24, 2005, 4:06 pm pst


#1  |  Francisco A. Lozano López (Paterna, Valencia)
Thursday, November 24, 2005, 4:06 PM PST

I think it would be great that a basic filtering for list pages was generated automatically. I've tried myself to add that feature to the template but I haven't had any success.

#2  |  Mike Ho (San Diego, CA) United States of America Qcodo Administrator
Monday, November 28, 2005, 12:26 PM PST

Actually, adding something like auto-generated filtering is pretty non trivial -- especially becuase of the n-squared aspect of filtering.  E.g. if you have 3 items you want to filter against, you will need to figure out how to filter based on all the various combination of those three items.

Moreover, filtering is actually specific business logic to your application - and qcodo's philosophy is to shy away from doing “business logic” generation - but instead, to provide all the necessary building blocks to make it really easy for you to build that business logic. ;^)

For a good example on how to quickly incorporate filtering, check out the Video Demo 2.

#3  |  plemieux (Quebec, Quebec, Canada)
Wednesday, December 7, 2005, 6:40 AM PST

I use another CRUD framework called PHPMyEdit (well, that was before Qcodo... ;) ) where a search field is generated for each column of the list. You can then enter value in as many field as you like and all the LIKE search are concatenated.

This is not as precise as a list filter (like the one shown in video 2) but, imho, it is a good general approach. From a usability standpoint, I don't think I would use such a feature on a “public” interface since it can be a little abstract, but for data management, this is really efficient.

Building such a control is on my To-Do/wish list. All suggestions are welcomed.

#4  |  Mike Ho (San Diego, CA) United States of America Qcodo Administrator
Wednesday, December 7, 2005, 4:26 PM PST

I'm curious on what you could come up with. =)

The issue I run into often with regards to a helper to generate more-custom WHERE clauses includes things like:
* Dealing with NULL
* allowing for <, >, <=, >= and !=
* accomodating the use of LIKE and %
* accomodation the use of FULLTEXT (forgot the syntax)
* Dealing with AND/OR, and nested ANDs/ORs

But i kinda see where you're going with this.  If you could design out a way that on a generated object, you could pass in just some parameters you want to do a search on, i think it'd be a useful candidate to add to the core templates.  So that for any given object, you could do (pardon the pseudocode)

Foo::LoadBySearching(
   (“FirstName LIKE 'John%'”) OR (“FirstName LIKE 'Chris%'”) AND
   (“Age <= 15”) AND
   (“ActiveFlag = 1”)

To find all Foo's who's first name starts with John or Chris, and who is 15 years old or younger, and who's record is Active.

But the key would be to have this method with a straight-forward enough protocol so that it's simple to use, but at the same time feature rich enough to allow for some real usefulness.



On a slightly different note, someone (forgot who it was) made a suggestion once that maybe just to allow a developer to pass in an arbitrary WHERE clause to the Load statmeent, so something like:

Foo::LoadWithWhere(“((first_name LIKE 'John%') OR (last_name LIKE 'Chris%')) AND age <= 15 AND active_flag = 1”);

I'm hesitent to go with this approach because:

1. I feel like it's a security hole just asking to be hit with SQL injenction =)
2. It starts to allow for some sloppier object-oriented design principals
3. I understand that being able to write your own where clauses is very important.  I do it all the time on my projects. =)  So if you need to write custom SQL, why not just write your own load handler, so that it's a much cleaner approach?

   class Foo extends FooGen {
       public static LoadByQualifiedApplicants() {
            $objResult = Application::Database[1]->Query('SELECT * FROM foo WHERE ...');
            /* OK, some people don't like SELECT * -- of course, you can explicitly name columns here, too =) */
            return Foo::InstantiateDbResult($objResult);
       }
   }

This way, the specific logic you are coding to do this specific special where clause is clearly deliniated as a separate business rule (with it's own method).

#5  |  Shannon Pekary (East Palo Alto, CA) United States of America Qcodo Core Contributor
Monday, July 31, 2006, 12:14 PM PDT

I agree that basic filtering would be wonderful.

The Mac, Eudora, Quicken, and other applications have a kind of filter builder that might be a good model. For example, you could have a “+" button, and once you click that, you then get two drop downs. The first for the field name, the second for the type of search, like “contains, starts with, ends with, is”, etc. The third is an open field where you specify criteria.

Pressing plus adds another criteria that is ANDed with the previous.

Granted, this is definitely non-trivial, but would be a fantastic feature.

Other things that would be nice:
- Detect the field type and put in appropriate choices. For example, if a Date field was selected, then the second drop down might read “Before, After, Between”, then if Between was shown, two fields would pop up that would be the outer bounds. Even more complex would be “This Week, Last Week, Last Month”, etc.

- The ability to save a criteria. Obviously, this is even more specific business logic, but this might be done in such a way that it is just a table with a Blob, and you do a PHP stream into the blob of the various criteria. It would need special logic if reading out the stream and the table structure changed it wouldn't crash.

Yes, quite complex, but I think could be done in a general enough way that would be extremely useful to lots of people, and modifiable to fit particular needs. 80-20 rule for sure.

#6  |  Mike Ho (San Diego, CA) United States of America Qcodo Administrator
Monday, July 31, 2006, 7:17 PM PDT

There are a few people who have been trying to work on some solutions that could help out with this.  I know that Martin uploaded a few controls and modules to help out in this area... definitely check out <http://www.qcodo.com/downloads/category.php/3> and feel free to contact/chat with him to see how things are and where things could be going.



Copyright © 2005 - 2012, Quasidea Development, LLC
This open-source framework for PHP is released under the terms of The MIT License.