A Mac coming from Obj-C... you must be just a little frustrated with
phps OO support :)

I put the models I have and a controller method, as an example, in the
bin for you to take a look at and laugh at as you please.
http://bin.cakephp.org/view/1027493569

The code can be re-factored and improved a lot. I just wrote it in
desperate haste a good while ago and have not had a cause to revisit
it since.

I forgot to put in the fields model (stored the searchable fields and
their types). That part will probably be replaced by som automatic
schema mapping but in my case I still have is as a table. The model
has no special features.
For your reference here is the table for that:
CREATE TABLE `fields` (
  `id` int(11) unsigned NOT NULL auto_increment,
  `display_name` varchar(255) default NULL,
  `type` varchar(255) default NULL,
  `field_name` varchar(255) default NULL,
  `model` varchar(255) default '',
  `created` datetime default NULL,
  `modified` datetime default NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8



On Oct 30, 5:13 pm, mario <[EMAIL PROTECTED]> wrote:
> Thanks Martin.
>
> That gave me a bit of an idea of what I'm going to
> do. And yes I want to know the specific details on how
> you implemented it. It would also be good if I could see
> some snippets of your code (model,controller,view) to further
> understand what you're trying to explain.
>
> Btw, I'm actually a mac developer but I'm still new in cakephp. =)
>
> On Oct 30, 8:36 am, "[EMAIL PROTECTED]"
>
> <[EMAIL PROTECTED]> wrote:
> > First I'll admit I did not read through all your code. But I think I
> > get what you are doing.
>
> > I created a filtering system about a year ago. I wanted/needed
> > something that worked a bit like the find feature in Mac OS X Finder,
> > or in some SQL-GUIs I have used. If you have see this you know what I
> > am talking about. I also needed these to be saved and recalled later.
>
> > Anyway.
> > I ended up with something that is a lot more streamlined in the
> > controller but with a bit more work done in the Models.
>
> > Filter is the whole search setup for a particular search.
> > Rule is a single filtering rule.
> > Filter hasMany Rule
>
> > One Rule can have:
> > - a property to filter
> > - an operator
> > - a value entered by the user
>
> > End result might be "email ends with gmail.com" for a single rule.
> > Adding more rules to a Filter would narrow the search using "AND".
> > This turned out the be very flexible. A filter can be attached to any
> > other model and do filtering on it.
>
> > The rule model contained a big data array with different operators
> > (sql fragments) for different types of data. Since humans want to
> > filter numbers differently from email addresses I created a number of
> > these preset custom fragments that could be selected from drop-downs
> > in the gui. The rule model also contained a method for converting the
> > stored parameters (field, match, value) to an sql fragment for a given
> > model.
>
> > Some examples of fragments:
> > $this->types['Text']['equals'] = '%s LIKE \'%s\'';
> > $this->types['Text']['contains'] = '%s LIKE \'%%%s%%\'';
> > $this->types['Text']['starts_with'] = '%s LIKE \'%s%%\'';
> > $this->types['Text']['ends_with'] = '%s LIKE \'%%%s\'';
> > $this->types['Date']['days_ago'] = 'FLOOR(DATEDIFF(CURDATE(),
> > DATE(%s))) = \'%s\'';
> > $this->types['Date']['weeks_ago'] = 'FLOOR(DATEDIFF(CURDATE(),
> > DATE(%s))/7) = \'%s\'';
>
> > Each field is mapped to a type. Datetime fields becomes the "Date"
> > type. Text fields could be set to email or anything but defaults to
> > "Text".
>
> > The filter code was nothing special. The only special method there was
> > "getFilterFor($model_name)" which gathers the results from each rule.
>
> > The reason for this setup was partly flexibility and partly the GUI. I
> > really wanted a humane gui. No wildcards or pseudo-sql. Simple selects
> > and meaningful words. Looking back it is not a very difficult setup
> > but it did take some time to come up with the right way to set it all
> > up.
>
> > I hope that gives you some ideas.
> > Let me know if you want a few more boring details of the
> > implementation.
>
> > /Martin
>
> > On Oct 30, 3:43 pm, mario <[EMAIL PROTECTED]> wrote:
>
> > > Hello everyone,
>
> > > I'm planning to include filters in my new project wherein it will
> > > allow the user to filter or show only the information that he/she
> > > wants. Of course there would be a search form
> > > (textfield,combobox,checkbox, submit button) for this relative to my
> > > tables' fieldnames in the database.
>
> > > I've already done this before on my recent project using cakephp. I
> > > will post some of my code snippets here for you to make some
> > > suggestion and for me to find out if what I'm doing is correct or not.
> > > I'm also looking forward on recommendations on how to improve my
> > > filtering process (which I'm gonna use on my next project).
>
> > > Here is the code snippet of my controller (I've placed the filters in
> > > my index view):
> > > ---------------------------------------------------------------------------
> > >  ----------
> > >         function index($title = null, $location = null, $date_from = null,
> > > $date_to = null) {
> > >                 if (empty($this->data) &&
> > >                                 (!$title || ($title == 'allTitle')) &&
> > >                                 (!$location || $location == 
> > > 'allLocation') &&
> > >                                 (!$date_from || !$date_to))
> > >                 {
> > >                         $this->paginate['Exhibit'] = array(
> > >                                                 'limit' => 1,
> > >                                                 'page' => 1,
> > >                                                 'order' => array 
> > > ('Exhibit.title' => 'asc')
> > >                                 );
> > >                         $this->set('exhibits', $this->paginate());
> > >                         $this->set('reportTitle',null);
> > >                         $this->set('reportLocation',null);
> > >                         $this->set('reportDateFrom',null);
> > >                         $this->set('reportDateTo',null);
> > >                 }
> > >                 else
> > >                 {
> > >                         if(!$title || $title == 'allTitle')
> > >                         {
> > >                                 $title = $this->data['Search']['title'];
> > >                         }
> > >                         else
> > >                         {
> > >                                 $this->data['Search']['title'] = $title;
> > >                         }
> > >                         if(!$location || $location == 'allLocation')
> > >                         {
> > >                                 $location = 
> > > $this->data['Search']['location'];
> > >                         }
> > >                         else
> > >                         {
> > >                                 $this->data['Search']['location'] = 
> > > $location;
> > >                         }
> > >                         if(!$date_from)
> > >                         {
> > >                                 $date_from = 
> > > $this->data['Search']['date_from'];
> > >                         }
> > >                         else
> > >                         {
> > >                                 $this->data['Search']['date_from'] = 
> > > $date_from;
> > >                         }
> > >                         if(!$date_to)
> > >                         {
> > >                                 $date_to = 
> > > $this->data['Search']['date_to'];
> > >                         }
> > >                         else
> > >                         {
> > >                                 $this->data['Search']['date_to'] = 
> > > $date_to;
> > >                         }
>
> > >                         if($title != '')
> > >                         {
> > >                                 $this->set('reportTitle',$title);
> > >                         }
> > >                         else
> > >                         {
> > >                                 $this->set('reportTitle','allTitle');
> > >                         }
>
> > >                         if($location != '')
> > >                         {
> > >                                 $this->set('reportLocation',$location);
> > >                         }
> > >                         else
> > >                         {
> > >                                 
> > > $this->set('reportLocation','allLocation');
> > >                         }
>
> > >                         if($date_from == '' || $date_to == '')
> > >                         {
> > >                                 $this->paginate['Exhibit'] = array(
> > >                                                         'conditions'=> 
> > > array("Exhibit.title LIKE '%$title%'",
> > >                                                                           
> > >                       "Exhibit.location LIKE '%$location%'"),
> > >                                                         'limit' => 1,
> > >                                                         'page' => 1,
> > >                                                         'order' => array 
> > > ('Exhibit.title' => 'asc')
> > >                                         );
> > >                                 $this->set('exhibits', $this->paginate());
>
> > >                                 $this->set('reportDateFrom',null);
> > >                                 $this->set('reportDateTo',null);
> > >                         }
> > >                         else
> > >                         {
> > >                                 $token_date_from = explode("/", 
> > > $date_from);
> > >                                 if(count($token_date_from) == 3)
> > >                                 {
> > >                                         $date_from = 
> > > $token_date_from[2].'-'.$token_date_from[1].'-'.
>
> ...
>
> read more »
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to