[Bb-trac] Re: [bbPress] #657: BB_Query class

bbPress bb-trac at lists.bbpress.org
Wed Jun 6 23:32:23 GMT 2007


#657: BB_Query class
----------------------------+-----------------------------------------------
 Reporter:  mdawaffe        |        Owner:  mdawaffe
     Type:  enhancement     |       Status:  assigned
 Priority:  normal          |    Milestone:  1.0     
Component:  Administration  |      Version:  0.8.1   
 Severity:  normal          |   Resolution:          
 Keywords:                  |  
----------------------------+-----------------------------------------------
Changes (by mdawaffe):

  * owner:  => mdawaffe
  * status:  new => assigned

Comment:

 Attached is a first pass at such a class.

 To use:

 {{{
 $my_query = new BB_Query(
     'topic',
     'topic_author_id=1,2&started=200706&tag_count=>1'
 );
 }}}

 That will grab topics written by user 1 or 2, started in June of 2007 and
 with more than one tag (read it as "tag_count is > 1" NOT "tag_count is >=
 1").

 A description of the valid query parameters can be found in the
 fill_query_vars() method.  Not all are implemented.

 "parse_ints" can be
  1. a single integer: 7 (OR -7 to exclude)
  2. a list of integers: 1,2,-3 (grab those that match 1 or 2 but NOT 3)
  3. a range: >3 OR <4 (one or the other, not both)

 "dates" can be
  1. a year: 2007
  2. a year and month: 2007-06
  3. a year and month and day: 2007-06-01
  4. and so on up to seconds: 2007-06-01 at 13:37:21 (equivalent to
 20070601133721 - punctuation is optional).
  5. a date range: >200701

 All SQL statements are filtered in such a way that rewriting old functions
 to use this class should be backward compatible.

 Example:

 {{{
 // I haven't actually tested this :)
 get_sticky_topics( $forum = false, $display = 1 ) {
     if ( 1 != $display ) // Why is this even here?
         return false;
     $q = array(
         'forum_id' => $forum,
         'sticky' => is_front() ? 'super' : 'forum'
     );

     // Last param makes filters back compat
     $query = new BB_Query( 'topic', $q, 'get_sticky_topics' );
     return $query->topics;
 }
 }}}

 Filters will still be needed for more complicated queries (those with non-
 trivial OR operations for example).  This will hopefully, though, make it
 much easier for plugins to generate their own queries and for plugins to
 modify core queries (there are points in the query generation process
 where a plugin can modify the query parameters of any query without having
 to parse SQL statements).

 We'd write wrappers for the class: {{{bb_get_topics(), bb_get_posts()}}}
 which could then be called in new loop template functions
 {{{bb_topics()}}}, {{{bb_topic()}}}, {{{bb_posts()}}}, {{{bb_post()}}}
 like we do currently in trunk for forums.

-- 
Ticket URL: <http://trac.bbpress.org/ticket/657#comment:1>
bbPress <http://bbpress.org/>
Innovative forum development


More information about the Bb-trac mailing list