You are here

friendlist_activity.rules.inc in Heartbeat 6.2

File

user_activity/modules/friendlist_activity/friendlist_activity.rules.inc
View source
<?php

// by Jochen Stals - ONE-agency - www.one-agency.be

# ACTIONS

/**
 * Implementation of hook_rules_action_info().
 * @ingroup rules
 */
function friendlist_activity_rules_action_info() {
  $info = user_activity_rules_action_info();
  $info = array(
    'friendlist_activity_rules_action' => array(
      'label' => t('Logs relational friendlist activity'),
      'eval input' => $info['user_activity_rules_default_action']['eval input'],
      'help' => 'Create a relation between users by logging their activities',
      'module' => 'friendlist activity',
    ),
  );
  return $info;
}

/**
 * Action drupal message configuration form.
 */
function friendlist_activity_rules_action_form($settings, &$form) {
  user_activity_rules_default_action_form($settings, $form);
}

/**
 * Action drupal message configuration form.
 */
function friendlist_activity_rules_action_submit(&$settings, $form, $form_state) {
  user_activity_rules_default_action_submit($settings, $form, $form_state);
}

/**
 * Action Implementation: Log an activity
 *
 * @param array $settings
 * @param array form
 * @param array with two arrays (set_info and variables)
 * @TODO drop the hardcoded arguments
 */
function friendlist_activity_rules_action($settings, $form = array(), $event_info = array()) {

  //dsm(func_get_args());

  // 1. Requester
  $data_requester = array();
  $data_requester['uid'] = $settings['uid_param'];
  $data_requester['uid_target'] = $settings['uid_target_param'];
  $data_requester['message'] = t($settings['message_param']);
  $data_requester['message_concat'] = t($settings['message_concat_param']);
  $data_requester['variables'] = $settings['variables_param'];
  $data_requester['event'] = $settings['event_param'];
  $data_requester['hid'] = heartbeat_event_id($data_requester['event']);

  // decode variables here to preset the arguments
  // username1 and 2 because they are being switched
  // #relation_type because it has to be translated.
  $variables = heartbeat_decode_message_variables($data_requester['variables']);
  $args = array(
    '@username1' => $variables['username1'],
    '@username2' => $variables['username2'],
    '#relation_type' => t($variables['relation_type']),
  );
  user_activity_log($data_requester, $args);

  // 2. Requestee, override requester
  $data_requestee = $data_requester;
  $data_requestee['uid'] = $data_requester['uid_target'];
  $data_requestee['uid_target'] = $data_requester['uid'];
  $args = array(
    '@username1' => $variables['username2'],
    '@username2' => $variables['username1'],
    '#relation_type' => t($variables['relation_type']),
  );

  //dsm($data_requestee);
  user_activity_log($data_requestee, $args);
}

Functions

Namesort descending Description
friendlist_activity_rules_action Action Implementation: Log an activity
friendlist_activity_rules_action_form Action drupal message configuration form.
friendlist_activity_rules_action_info Implementation of hook_rules_action_info().
friendlist_activity_rules_action_submit Action drupal message configuration form.