Skip to:
Content

Opened 7 years ago

Closed 7 years ago

#657 closed enhancement (fixed)

BB_Query class

Reported by: mdawaffe Owned by: mdawaffe
Milestone: 0.8.3 Priority: normal
Severity: normal Version: 0.8.1
Component: Administration Keywords:
Cc:

Description

bbPress has a lot of different functions that select topics or posts is slightly different ways. It'd be nice if we had some master class that built the SQL queries for these functions.

Attachments (2)

bb-query.php (18.5 KB) - added by mdawaffe 7 years ago.
BB_Query class
q.php (399 bytes) - added by mdawaffe 7 years ago.
interface for BB_Query class formatted to run from command line

Download all attachments as: .zip

Change History (18)

comment:1 mdawaffe7 years ago

  • Owner set to mdawaffe
  • Status changed from new to assigned

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@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.

mdawaffe7 years ago

BB_Query class

mdawaffe7 years ago

interface for BB_Query class formatted to run from command line

comment:2 sambauers7 years ago

I'm being picky, but seeing as you are so close to the ISO 8601 date/time standard, you may as well implement it.

http://en.wikipedia.org/wiki/ISO_8601#Combined_representations

Change the "@" separating date and time to an upper-case "T" and you are pretty much there.

comment:3 mdawaffe7 years ago

ISO 8601 times should be understood as well. The parsing function just strips out all non numeric characters.

Well - it looks as though the parsing function needs to be tweaked a bit, but it still works :)

It does not (and would be overkill if it did) understand timezones or repetition. Nor does it understand time intervals other than a particular year, month, day.... Dealing with arbitrary intervals is probably futile too.

comment:4 mdawaffe7 years ago

  • Milestone changed from 1.0 to 0.8.3 & XML-RPC

comment:5 mdawaffe7 years ago

(In [858]) BB_Query class first pass. Use it in functions that select topics. See #657

comment:6 mdawaffe7 years ago

(In [859]) simplify BB_Query vars. See #657

comment:7 mdawaffe7 years ago

(In [876]) Views should use new bb_register_view() function and BB_Query rather than bb_views hook. Will break old code. See #657

comment:8 mdawaffe7 years ago

(In [879]) Experiment with bb_query_from_env(). Only in admin-functions.php for now. See #657

comment:9 mdawaffe7 years ago

(In [880]) implement topic_title, post_text, search queries in BB_Query. See #657

comment:10 mdawaffe7 years ago

(In [881]) Topic search in admin side. See #657 #602

comment:11 mdawaffe7 years ago

(In [884]) move bb_query_from_env() into BB_Query. move bb_topic_search_form() into new BB_Query_Form extends BB_Query. Use them admin side. See #657 #602

comment:12 mdawaffe7 years ago

(In [886]) refactor search. Use BB_Query_Form for relevant, get rid of user search and topic title search see #657. Fixes #658

comment:13 mdawaffe7 years ago

(In [887]) fix BB_Query::query_from_env() for realies. Call the arg allowed. See #657

comment:14 mdawaffe7 years ago

[889]: fix BB_Query for posts with JOIN, tags or favorites. Some more cacheing options in BB_Query. Use BB_Query for post queries.

comment:15 mdawaffe7 years ago

(In [890]) bug in post query: no more view parameter. See #657

comment:16 mdawaffe7 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

Let's call it this done. Individual tickets for individual issues.

Note: See TracTickets for help on using tickets.