You are here

function notifications_format_subscription in Notifications 6.3

Same name and namespace in other branches
  1. 6 notifications.module \notifications_format_subscription()
  2. 6.2 notifications.module \notifications_format_subscription()

Format subscription for display

Return value

array() Array with type_name, field_names (array), field_values (array)

3 calls to notifications_format_subscription()
notifications_manage_subscriptions_form in ./notifications.manage.inc
Administer user subscriptions
notifications_multiple_delete_confirm in ./notifications.manage.inc
Form for multiple delete. When account passed check that all subscriptions belong to the user account
notifications_subscription_info_field in ./notifications.pages.inc
Subscription information field for several forms

File

./notifications.module, line 1782
Notifications module

Code

function notifications_format_subscription($subscription, $format = 'short', $html = TRUE) {

  // Build array and add subscription type name
  $info = notifications_subscription_types($subscription->type);
  $names = $values = array();

  // Get field names and values formatting each field
  if (!empty($subscription->fields)) {
    foreach (_notifications_fields($subscription->fields) as $field) {
      $item = notifications_format_subscription_field($field->type, $field->value, $html, $subscription->type);
      $names[] = $item['name'];
      $values[] = $item['value'];
    }
  }

  // If this subscription has a name, use it, otherwise build it using fields and values
  if (!empty($info['name'])) {
    $value_name = $info['name'];
  }
  else {
    $value_name = implode(', ', $values);
  }

  // Now do the formatting
  switch ($format) {
    case 'array':
      return array(
        'type' => $info['title'],
        'name' => $value_name,
        'names' => $names,
        'values' => $values,
      );
    case 'short':
      return t('@type: !values', array(
        '@type' => $info['title'],
        '!values' => $value_name,
      ));
    case 'long':
      return t('Subscription %id of type %type to: !values', array(
        '%id' => $subscription->sid,
        '%type' => $info['title'],
        '!values' => $value_name,
      ));
  }
}