Here is the use case:

You want to show activity across the entire site (/activity) but you don't want to show node/comment delete activity...Let's say you are cleaning house in a nasty forum thread or removing spam posts with dodgy node titles...it would be nice to not have those particular posts appear on the activity list.

So there are two things to accomplish here.

First is to extend the activity_get_activity() function to accept negative filters. Right now if you pass in a filter parameter it allows for the creation of an WHERE foo IN ('bar', 'baz') clause for multiple values or WHERE foo = 'bar' clause for single value. If you can include a flag to indicate if negation is desired then we could include the case of a NOT IN clause or != clause.

Second is to allow for the activity_page() function to allow for some or all of the parameters used in the activity_get_activity() function call to be set via the activity admin settings page. In addition to the above mentioned filters suggestion, I may want to set the LIMIT number to 50 instead of 20 or perhaps have a set array of uids to find activity for.

Comments

sirkitree’s picture

Jaydub,

I really like this idea and have run across this scenario myself a few times. I end up taking the short-cut and just removing the entry from the activity table as they've only been piecemeal cases. But this sounds like a great way to handle this problem.

I'm pretty swamped with other things right now so I've no time to really try to hash this out right now, maybe after DrupalCon, but if you hack anything up, please submit it. I'd love to see it and would happily spend a little time reviewing.

jaydub’s picture

Status: Active » Needs review
StatusFileSize
new1.42 KB

Here's a quick pass at adding this in. Let me know what you think.

bcn’s picture

Status: Needs review » Needs work

+1 to the feature, and thanks for the module!

Patch no longer applies cleanly to the latest version (v 1.1.2.2.2.26 ).

jaydub’s picture

StatusFileSize
new1.65 KB

re-rolled

bcn’s picture

Status: Needs work » Needs review

New patch (#4) applies cleanly, but I haven't had time to test yet. Will try to test this out in the next few days.

jdelaune’s picture

Care to give a few real life examples of how this will work? I could probably work it out if I studied the code long enough, but if you pointed me in the right direction it would cut some time out.

Cheers,
~Jordan

jaydub’s picture

I've committed the patch to CVS. The basic idea behind the
patch was to allow for negative filters in activity_get_activity
as it was only possible to filter for inclusion previously.

Here are a few examples of how you can use the filters
to generate your own list of activity

The updated docs for the activity_get_activity function
explain the basic idea:

 * @param $filters
 *   - an array where keys are one of module, type, operation, target_role
 *   - values are arrays of possible values for the keys. The key of the 
 *     array of possible values can be 'include' or 'exclude' to indicate
 *     if the filter is positive or negative
 *     For example:
 *     array('target_role' => array('include' => 'Author'), 'type' => array('include' => 'delete'))
 *     this would find activity where the author had deleted something.
 *     Example 2:
 *     array('target_role' => array('include' => array('Requester', 'Requestee')))
 *     This shows that the values can be arrays as well.
 *     Example 3:
 *     array('module' => array('include' => array('nodeactivity', 'commentactivity')), 'type' => array('exclude' => array('delete', 'unpublish')))

So let's say I want to get activity for nodeactivity but only for the story node type:

$filters = array(
  'module' => array('include' => 'nodeactivity'), 
  'type' => array('include' => 'story')
);
$activities = activity_get_activity(ACTIVITY_ALL, $filters, 20);

I have two filters and both are positive or include filters.

Instead let's say I want to get nodeactivity but get all node types except for page:

$filters = array(
  'module' => array('include' => 'nodeactivity'), 
  'type' => array('exclude' => 'page')
);
$activities = activity_get_activity(ACTIVITY_ALL, $filters, 20);

Here we have one positive filter and one negative filter.

Let's use an array of node types and introduce a filter on
the operation:

$filters = array(
  'module' => array('include' => 'nodeactivity'), 
  'type' => array('include' => array('page', 'story')),
  'operation' => array('exclude' => array('delete')),
);
$activities = activity_get_activity(ACTIVITY_ALL, $filters, 20);

I've include code to attempt to rewrite existing filters to use
the new include/exclude key but if anyone who tries out the
development snapshots can try out their old filters please let
me know if there are problems.

minesota’s picture

 foreach ($filter as $criteria => $values) {
        if (is_array($values)) {
          foreach ($values as $value) {
            $strings[] = "'%s'";
            $params[] = $value;
          }
          $wheres[] = $column . ($criteria == 'exclude' ? ' NOT IN ' : ' IN ') .'('. implode(',', $strings). ')';
        }
        else {
          $wheres[] = $column . ($criteria == 'exclude' ? ' != ' : ' = ') ."'%s'";
          // $values is a string with the single value.
          $params[] = $values;

Say, for example I want to exclude 'image' or 'usernode', how / where I write these in the above ?
Writing 'image' in place of 'NOT IN' does not give result.

jaydub’s picture

The steps in #7 are not helping?

minesota’s picture

Yes they are helping now. Thanks.

minesota’s picture

jaydub’s picture

Version: 5.x-3.x-dev » 6.x-1.x-dev
Component: Code » Documentation
Assigned: Unassigned » jaydub
Category: feature » task
Status: Needs review » Active

Just need to document this on the handbook pages.

sirkitree’s picture

Status: Active » Closed (won't fix)

closing. 1.x no longer supported.