You are here

function activity_user in Activity 6

Same name and namespace in other branches
  1. 5.4 activity.module \activity_user()
  2. 6.2 activity.module \activity_user()

Implementation of hook_user().

File

./activity.module, line 387
activity.module

Code

function activity_user($op, &$edit, &$account, $category = NULL) {
  switch ($op) {

    // View activity on user profile page.
    case 'view':
      if (user_access('view public activity') && variable_get('activity_user_profile_records', 5) != 0) {
        drupal_add_css(drupal_get_path('module', 'activity') . '/activity.css');
        $activity = activity_get_activity($account->uid, NULL, variable_get('activity_user_profile_records', 5));
        $activities = array();
        foreach ($activity as $item) {
          $item['delete-link'] = activity_delete_link($item);
          $activities[] = theme('activity', activity_token_replace($item), $item);
        }
        $account->content['activity'] = array(
          '#type' => 'user_profile_category',
          '#title' => t('Activity'),
          '#weight' => 6,
        );
        $account->content['activity'][] = array(
          '#type' => 'user_profile_item',
          '#value' => theme('activity_user_profile_activity', $activities),
        );
      }
      break;

    // Provide a privacy setting to users to opt-out of appearing in activity pages.
    case 'form':
      if ($category == 'account' && variable_get('activity_user_optout', 0)) {
        $form['activity'] = array(
          '#type' => 'fieldset',
          '#title' => t('Activity privacy settings'),
          '#collapsible' => TRUE,
          '#collapsed' => FALSE,
          '#weight' => 6,
        );
        $form['activity']['activity_optout'] = array(
          '#type' => 'checkbox',
          '#title' => t('Do not record my site activity'),
          '#description' => t('If you wish keep your site activity from appearing in the <a href="@activity">activity</a> pages, check the box.', array(
            '@activity' => url('activity'),
          )),
          '#default_value' => isset($edit['activity_optout']) ? $edit['activity_optout'] : '',
        );
      }
      return $form;
      break;
    case 'delete':

      // Delete activity records directly generated by the deleted user
      db_query('DELETE FROM {activity_targets} WHERE aid IN (SELECT aid FROM {activity} WHERE uid = %d)', $account->uid);
      db_query('DELETE FROM {activity} WHERE uid = %d', $account->uid);

      // Delete activity records related to user but not generated by the deleted user
      db_query('DELETE FROM {activity} WHERE aid IN (SELECT aid FROM {activity_targets} WHERE target_uid = %d)', $account->uid);
      db_query('DELETE FROM {activity_targets} WHERE target_uid = %d', $account->uid);
      break;
  }
}