Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply filter to query args Fix #355 #362

Merged
merged 8 commits into from Mar 27, 2014
Merged

Apply filter to query args Fix #355 #362

merged 8 commits into from Mar 27, 2014

Conversation

faishal
Copy link
Contributor

@faishal faishal commented Mar 23, 2014

Add stream_query_args filter with callback WP_Stream_Settings::remove_excluded_record_filter will fix issue.

$where .= $wpdb->prepare( " AND $wpdb->stream.ID IN ($record__in)", '' );
if ( $args[ 'record__in' ] ) {
$record__in = array_filter( (array)$args[ 'record__in' ], 'is_numeric' );
$record__in_format = '(' . substr( str_repeat( ',%d', count( $record__in ) ), 1 ) . ')';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@faishal it might be better to use array_fill here:

$record__in_format = '(' . join( ',' array_fill( 0, count( $record__in ), '%d' ) ) . ')';

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@westonruter Yes it will be better, I will do that changes.

@fjarrett
Copy link
Contributor

@faishal You make an excellent point about applying the filter by default, and I think it's a great idea.

What do you think about adding a hide_excluded argument to the query? And making it true by default.

Then it can be overridden easily like:

stream_query( array( 'hide_excluded' => false ) );

@faishal
Copy link
Contributor Author

faishal commented Mar 24, 2014

@fjarrett That will be good idea. /five

@faishal
Copy link
Contributor Author

faishal commented Mar 24, 2014

All suggested changes are done

if ( strlen( $author__not_in ) ) {
$where .= $wpdb->prepare( " AND $wpdb->stream.author NOT IN ($author__not_in)", '' );
$author__not_in = array_filter( (array)$args[ 'author__not_in' ], 'is_numeric' );
$author__not_in_format = '(' . join( ',', array_fill( 0, count( $author__not_in ), '%d' ) ) . ')';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@faishal This is causing some warnings to appear for me.

Warning: array_fill(): Number of elements must be positive in /srv/www/wordpress-trunk/wp-content/plugins/stream/includes/query.php on line 187
Warning: join(): Invalid arguments passed in /srv/www/wordpress-trunk/wp-content/plugins/stream/includes/query.php on line 187

@faishal
Copy link
Contributor Author

faishal commented Mar 24, 2014

@fjarrett sorry my bad ! Fixed by checking empty array before use array_fill

@fjarrett
Copy link
Contributor

@faishal While testing this, I've been running into some problems with other Stream extensions, namely our Data Exporter project. /cc @lukecarbis

Before we merge this I think we will be forced to expand the scope of this ticket even more and introduce an option for this, which will force users to opt-in to hiding previous records.

Then the default for any Stream query will be whatever this setting is.

screen_shot_2014-03-24_at_5_59_37_pm

What do you think?

@faishal
Copy link
Contributor Author

faishal commented Mar 24, 2014

@fjarrett Yeah, That will be really good option for user to choose whether they want to hide previous records or not. /five

@lukecarbis
Copy link
Contributor

Silly questions:

What if I want to hide all evidence of Frankie Jarrett's existence by hiding his previous records, but I also want to stop recording changes from the Comments connector without hiding previous entries?

If I have not chosen to hide previous records, how do I know when the current exclude settings took effect?

@fjarrett
Copy link
Contributor

@lukecarbis @faishal

  1. You're right, this could be a possible scenario, however, I don't see it being a common use-case. When this type of granular control is desired I think it would be best to allow someone to do it with a custom hook. Or another alternative could be creating a totally separate extension that would handle fine-grained exclusion/visibility control.

  2. You'll know they took effect because new records won't appear for those actions.

But the general idea of leaving the Visibility choice up to the user will help them accomplish 1 of 2 objectives:

  1. Exclude this type of activity from now on.
  2. Exclude this type of activity from now on and hide all previous mention of this activity.

@faishal
Copy link
Contributor Author

faishal commented Mar 26, 2014

@fjarrett done

fjarrett added a commit that referenced this pull request Mar 27, 2014
Apply filter to query args Fix #355
@fjarrett fjarrett merged commit 28878c3 into xwp:develop Mar 27, 2014
@lukecarbis
Copy link
Contributor

I noticed that the Stream filters don't respect the exclude settings.

For example, I set the author exclude to Luke Carbis and set Hide Previous Records to true. Then I view the Stream page (which does not show any of my activity). However, when I view the Authors filter dropdown, I can select the author Luke Carbis. When I filter using this setting, I can see all my activity.

Is this the intended behavior?

@fjarrett
Copy link
Contributor

@lukecarbis Good catch! If the visibility is set to Hide Previous Records then I think excluded items should be omitted from the dropdown filters entirely, as originally discussed in #223

/cc @faishal

@lukecarbis
Copy link
Contributor

@fjarrett @faishal Not only excluded from the dropdown filters, but also excluded from results (because I suppose it's possible to manually type an excluded user ID as a $_GET parameter).

@faishal
Copy link
Contributor Author

faishal commented Apr 1, 2014

@lukecarbis realy good catch. I am working on it.

fjarrett added a commit that referenced this pull request Apr 2, 2014
Fix Stream filter issue with exclude settings #362
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants