SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Sep 2004
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I need some design suggestions on this problem

    Hi,

    In an application I am currently developing, there is a form which has 3 sections: section 1 (which is required), section 2 (which is optional), section 3 (which is also optional). A section represents a group of form fields, (for example section 1 has a name field, a email field and a country field). Once the form is submitted, the user is redirected to another section which I'll name it section 4 (section 4 also optional). The data gathered through this form is stored in the database and forms what the client calls a lead.

    The backend of this application has a section that lists these leads. Now the client wants to filter that list as follows (i'll assign letters to the sections of the form to make this easier to explain).

    So

    a) section 1 (required)
    b) section 2 (optional)
    c) section 3 (optional)
    d) section 4 (optional)

    1. a) + b) + c) + d) == very hot lead (which means all the sections of the form have been filled by the user)
    2. a) + b) + c) || a) + b) + d) || a) + c) + d) == hot lead (the required section and any two of the optional sections have been filled)
    3. a) + b) || a) + c) || a) + d) == warm lead (the required section and any one of the optional sections have been filled)
    4. a) == cold lead (only the required section has been filled)

    So the client will be able to apply any of the filters above, combinations too, like so: very hot && cold, or very hot && hot && cold, cold etc. and expects to receive the list filtered and sorted accordingly when applying these filters. Besides this there are also other filters like a date range filter, a country filter etc ... So a complete filter could look something like below:

    very hot lead filter && warm lead filter && cold lead filter && date range filter && country filter

    Does anyone have a suggestion on how to approach this problem (links or anything that could help me out)? All I have right now is that those filters will have to be translated some how into an SQL query (I think).

    Thanks in advance.

  2. #2
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The filtering (or QBE) interface usually consists of a table whose columns correspond to the database fields and rows to the OR parts of the query. E.g.
    Code:
    # | name | country | weight
    ----------------------------
      | blah |         | >30
      |      | de      |
    results in the following where clause
    Code:
    WHERE (name = 'blah' AND weight >30) OR (country='de')
    For the 'lead' thing add a virtual 'lead hotness' (?) column to the table and translate it to "COUNT(filled_in_sections)" when you build the query.

  3. #3
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Where you have business rules that are required, optional, or are dependent on other, related rules, then in my view, you are looking at a Specification

    To learn more you are looking for the Specification pattern; I've already pimped Jason's book on another thread, so no more pimping this week, but it's not a difficult pattern to find information on it.

    Your best bet for today, would be to search this very forum... Lots of examples and debate on this pattern. Enjoy your journey

  4. #4
    SitePoint Addict
    Join Date
    Sep 2004
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you both for your responses.

    Dr.Livingston, I was thinking that the Specification pattern would apply here but I wasn't sure ... I just dont know right now how to implement it in the context of helping me generate a sql query (and dont know yet that this is the right way, i was also thinking to validate and select when the user fills the form and then store the lead type in the database, what are your thoughts about this?).

    I read the chapter about Specification in Jason's book and hopefully I'll come up with a flexibile solution (it's very likely that the client will want to add more filters in the future)

  5. #5
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    > ... it's very likely that the client will want to add more filters in the future

    Very likely, so a modular solution is what you are looking for, where each of those rules/filters are decoupled.

    > ... implement it in the context of helping me generate a sql query

    If I were in your position, I would allow those rules/filters to be Visitable so you would do your SQL formatting via one or more visitors; The Visitor pattern would be an ideal candidate in this case...

    If the formatting changes, such as you need to move to a different database, you don't need to make any changes to your application, nor the implementation of your Specifications, just what visitor you use


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •