myCRED_Query_Log

Codex / mycred/log / Classes / myCRED_Query_Log

Navigation:

  1. Description
  2. Usage
  3. Properties
  4. Methods
  5. Query Parameters

Description

The myCRED_Query_Log class handles all log queries and optionally present the results by constructing a HTML table.

This class is used in the following myCRED features:

  • The mycred_history shortcode
  • The myCRED Log page in the admin area
  • BuddyPress Points History page
  • Users personal points history page in the admin area

Usage

Default usage:

// The Query
$query = new myCRED_Query_Log( $args );

// Show results
$query->display();

Without the use of $query->display();:

// The Query
$query = new myCRED_Query_Log( $args );

// The loop
if ( $query->have_entries() ) :
	foreach ( $query->result as $query ) {
		$log->the_entry( $query );
	}
else :
	$query->no_entries();
endif;

Properties

  • $args (array)
    Holds the arguments used in the query.
  • $request (string)
    The SQL query generated from the arguments given.
  • $prep (array)
    The argument values that is passed on to $wpdb->prepare();.
  • $result (object)
    The result of the query.
  • $num_rows (int)
    Number of rows in result.
  • $headers (array)
    The table column headers. Unsetting a column header before displaying the result will exclude that column from the generated table.

Example: Exclude the user column from the generated table.

$log = new myCRED_Query_Log( $args );
unset( $log->headers['column-username'] );
$log->display();

Methods

  1. myCRED_Query_Log( $args )Parses given arguments and makes a DB query using the wpdb class. Arguments can be passed either as a string or an array. This method will populate $args, $request, $prep, $result, $num_rows and $headers.
    • $args (string|array)
      Query arguments.
  2. have_entries()Returns true if the query returns results else false.
  3. table_headers()Returns the column headers.
  4. exporter()Renders the log exporter.
    • $title (string) optional
      Export title.
    • $is_profile (bool)
      Determines what label to show with the export options. Should be set to true if the current user viewing the log is viewing their own entries.
  5. display()Renders the log table.
  6. get_display()Returns the generated log table.
  7. the_entry( $entry, $wrap )Renders a entry row.
    • $entry (object) required
      The log entry object.
    • $wrap (string)
      Optional HTML element to wrap around each column. Defaults to TD. Added in 1.1.1
  8. get_the_entry( $entry, $wrap )Returns each columns value for one table row.
    • $entry (object) required
      The log entry object.
    • $wrap (string)
      Optional HTML element to wrap around each column. Defaults to TD. Added in 1.1.1
  9. no_entries()Renders the no entry row.
  10. get_no_entries()Returns the no entry language.
  11. search()Renders the Log Search field.
  12. filter_dates( $url )Outputs the filter by date links.
    • $url (string)
      The URL the users query is redirected to when clicking “Filter”. Should be the current page’s url.

Query Parameters

  • user_id (int)
    Show log entries for a specific user.

Example: Return the log entries of a specific user.

$log = new myCRED_Query_Log( 'user_id=1' );
  • ctype (string)
    Show log entries of a specific cred type. Defaults to mycred_default.
$log = new myCRED_Query_Log( 'ctype=mycred_default' );
  • number (int)
    Number of entires to return. Defaults to 25.

Example: Return the last 50 entries.

$log = new myCRED_Query_Log( 'number=50' );
  • time (string)
    Return log entries according to one of the Time Filters. Available options are:

    • today – show todays entries
    • yesterday – show yesterdays entries
    • thisweek – show this weeks entries
    • thismonth – show this months entries
    • from,to – Using Unix timestamps, entries logged between the two timestamps are returned. The two timestamps must be separated with a comma sign and nothing else.

Example 1: Return todays entries.

$log = new myCRED_Query_Log( 'time=today' );

Example 2: Return a specific users log entries from yesterday.

$log = new myCRED_Query_Log( 'user_id=1&time=yesterday' );
  • ref (string)
    Return log entries for a specific hook reference.

Example: Return all log entries for imports.

$log = new myCRED_Query_Log( 'ref=import' );
  • ref_id (int|string)
    Return entires with a specific reference ID.

Example 1: Return all Cred Transfers made to a specific user.

$log = new myCRED_Query_Log( 'ref=transfer&ref_id=1' );

Example 2: Return all Cred Transfers made from one user to another.

$log = new myCRED_Query_Log( 'user_id=1&ref=transfer&ref_id=2' );
  • amount (array|int|float)
    Return entries with a specific amount passed as a integer or float, or a range using an associative array. Required keys are: start (range start), end (range end) or if you want to make a comparison: num (the amount to compare to) and compare (=, LIKE, NOT LIKE etc.).

Example 1: Return all entries where 10 points were given.

$log = new myCRED_Query_Log( 'amount=10' );

Example 2: Return all entries where points were between 10 and 20.

$log = new myCRED_Query_Log( array( 'amount' => array( 'start' => 10, 'end' => 20 ) ) );

Example 3: Return all entires where anything but 20 points were given.

$log = new myCRED_Query_Log( array( 'amount' => array( 'num' => 20, 'compare' => '!=' ) );
  • s (string)
    Return results with this search string. If the user_id is not used here, only the ref, ref_id and entry columns are searched.

Example: Return all entires where the string foo is found.

$log = new myCRED_Query_Log( 's=foo' );
  • orderby (string)
    Oder the results by a given column. Available columns are: id, blog_id, ref, ref_id, user_id, creds, ctype, entry, data and time. Defaults to time.

Example: Return results and order by id.

$log = new myCRED_Query_Log( 'orderby=id' );
  • order (string)
    Choice of ordering the result either Ascending (ASC) or Descending (DESC). Defaults to DESC.

Example: Return results for a given user in ascending onder.

$log = new myCRED_Query_Log( 'user_id=1&order=ASC' );
  • ids (boolean)
    Choice of only returning the entry ids only (true) or all columns (false). Defaults to all columns (false).

Example: Return only the entry ids for a specific user.

$log = new myCRED_Query_Log( 'user_id=1&ids=true' );

Last edited March 5, 2016