I'm having trouble trying to add and argument to the activity_comments module. I'd like to be able to add a comment author argument so that activity items (ie, other peoples activity) that you have commented on will appear in your feed also. I've tried adding the below code to activity_comments.views.inc but nothing appears in the view admin panel.

 $data['activity_comments_user']['table']['join'] = array(
    'activity' => array(
      'left_field' => 'aid',
      'field' => 'aid',
    ),
  );
  $data['activity_comments_user']['uid'] = array(
	'title' => t('User'),
	'help' => t("The user which commented."),
	'relationship' => array(
	'base' => 'users',
	'field' => 'uid',
	'handler' => 'views_handler_relationship',
	'label' => t('The user which has commented.'),
	),

	'argument' => array(
	'handler' => 'views_handler_argument_user_uid',
	)
	);

Could someone point out what is wrong with this please?

Thanks

Comments

Scott Reynolds’s picture

Your approach won't ever work, but I think this is something we need to look into implementing. I think, my approach would be the following

function activity_comments_activity_grants($activity) {
  return array(
    'activity_comment' => array($activity->aid)
  );
}

function activity_comments_activity_access_grants($account) {
   $aids = [];
   $result = db_query("SELECT aid FROM {activity_comments} WHERE uid = %d", $account->uid);
   while ($row = db_fetch_object($result)) {
     $aids[] = $row->aid;
   }

  $realm_ids = array();
  if (!empty($aids)) {
    foreach ($aids as $aid) {
      $realm_ids['activity_comment'][] = $aid;
    }
  }
  return $realm_ids;
}

That will give us the Activity Access filter. So give this a try

1.) add that code to the activity_comments.module
2.) Rebuild access records by visiting: /admin/settings/activity and clicking the Rebuild Access Table button
3.) Profit?

oxford-dev’s picture

I'm not using Activity Access in my view though.

I have it set up so that it uses 2 arguments (OR'd using views_or module); user id and user_relationships(requestee user).

I have it set up so that when i view my profile it shows mine and my friends activity but when i view a friends profile, it shows just theirs. My intention was to add another OR'd argument comment uid to also list activity that I had commented on.

oxford-dev’s picture

Turns out the problem wasn't that the activity wasn't appearing in your feed when you comment on it, it will have been there but could have 'dropped off the bottom' so you did not see it and you expect to see it appear at the top of the feed as its a new activity.

My solution to this is to order feeds by 'created' field and then update this value to the current time when ever a comment is added to it. A bit of a hack as it is a 'created' field and not an 'updated' field.

To achieve this I had to hack activity_comments.module and add

db_query("UPDATE {activity} SET created = %d WHERE aid = %d", time(), $form['aid']['#value']);

at line 210.

I have 2 questions now, how can I hook into this from a custom module so I can take that line out of activity module.

I tried creating function MY_MODULE_activity_comments_form_submit($form, &$form_state) {

but it never fires.

I also though hook_submit was no longer used for D6?

Scott Reynolds’s picture

function MY_MODULE_activity_comments_form_alter(&$form, $form_state) {
  $form['#submit'][] = 'MY_MODULE_activity_comments_form_submit';
}

function MY_MODULE_activity_comments_form_submit($form, &$form_state) {
  db_query("UPDATE {activity} SET created = %d WHERE aid = %d", time(), $form['aid']['#value']);
}
pribeh’s picture

Hey Oxford-dev, how did you get your hack to work? I've tried using your hack by entering

db_query("UPDATE {activity} SET created = %d WHERE aid = %d", time(), $form['aid']['#value']);

into activity_comments.module at like 210 but to no avail. The creation date of the activity does not appear to be changing. Am I correct in assuming that your line of code is supposed to change the creation date of the activity?

[update] Nevermind, it's working now. Must have been some sort of cache effect.

Scott Reynolds’s picture

Instead of hacking the activity module, you should use the code i posted above.

pribeh’s picture

Totally. I've gone with using your code instead (as below).

function activity_comment_creation_activity_comments_form_alter(&$form, $form_state) {
  $form['#submit'][] = 'activity_comment_creation_activity_comments_form_submit';
}

function activity_comment_creation_activity_comments_form_submit($form, &$form_state) {
  db_query("UPDATE {activity} SET created = %d WHERE aid = %d", time(), $form['aid']['#value']);
}

Now the odd thing is though that it only seemed to work once. So only on one single comment did an activity's creation date change. For the rest it doesn't seem to be snagging.

pribeh’s picture

Hey Oxford-dev, did you get this working with the alpha version?

pribeh’s picture

I figured out something. It looks like either oxford-dev's hack or Scott's module only work for comments of node-related activities. So if I comment on a node's activity then the activity creation date changes but if I comment on, say, a (FBSS) status' activity then the creation date remains unchanged.

Looking at the code this should work for any activity item. Scott, do you have any idea if there's something specific here about FBSS' integration with Activity that might be an obstacle here?

pribeh’s picture

Nevermind my bantering, it seems to be working perfectly now. I can't tell you what the intermittent issues were but they did exist ;)

pribeh’s picture

Ok, so here's hopefully my last request here. So for me I've finally realized that this code works on the first activity comment posted. So for every first activity comment submitted the creation date of the activity is altered to reflect the time the comment was submitted. Is this the expected behaviour according of this code snippet? And if so, is there any way to allow any activity comment to change the creation date of the corresponding activity?

oxford-dev’s picture

i havnt tested whether it works for subsequent comments yet, should really.

I'm not using alpha, im still using a dev version from around march i think. All releases since then havn't worked for me including the lastest alpha, as as the saying goes, if its not broken, don't fix it.

I should really make an effort to get newer versions working really.

pribeh’s picture

@oxford-dev, I could really use another function as well:

I'd like to change the Activity creation date when a user flags the activity as well (using the activity flag module you helped complete http://drupal.org/node/791524).

Let me know if you have any time to work on something like this oxford-dev. I would be willing to pitch in.

oxford-dev’s picture

Ok, now that you mention is that would be useful to me too.

When I get a bit of time I will look into it. It may be simple to set up a rule for this.

_shy’s picture

Issue summary: View changes
Status: Active » Closed (outdated)

D6 reached its EOL back in February 2016, and there is no active release for D6 for this module anymore.
Development or support is not planned for D6. All D6-related issues are marked as outdated in a bunch.

If the issue remains relevant for D10+ versions, merge requests with proposed solutions for a new module version (D10+) are welcome in a new follow-up issue.

Thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.