function userpoints_view_transaction in User Points 7
Same name and namespace in other branches
- 7.2 userpoints.pages.inc \userpoints_view_transaction()
Menu callback; display details about a specific transaction.
Parameters
$transaction: Transaction object.
Return value
Render-able array with all the information about this transaction.
1 string reference to 'userpoints_view_transaction'
- userpoints_menu in ./
userpoints.module - Implements hook_menu().
File
- ./
userpoints.pages.inc, line 216 - Menu callbacks for userpoints.module.
Code
function userpoints_view_transaction($transaction) {
drupal_add_css(drupal_get_path('module', 'userpoints') . '/userpoints.css');
drupal_set_title(t('View transaction #@txn_id', array(
'@txn_id' => $transaction->txn_id,
)));
$css_stati = array(
USERPOINTS_TXN_STATUS_APPROVED => 'approved',
USERPOINTS_TXN_STATUS_DECLINED => 'declined',
USERPOINTS_TXN_STATUS_PENDING => 'pending',
);
$classes = 'userpoints-view-' . $css_stati[$transaction->status] . ' userpoints-view-category-' . $transaction->tid . ' userpoints-view-' . ($transaction->points > 0 ? 'positive' : 'negative');
if (!empty($transaction->expirydate)) {
$classes .= $transaction->expired ? ' userpoints-view-expired' : ' userpoints-view-not-expired';
}
$content = array(
'#prefix' => '<div class="userpoints-view-transaction ' . $classes . '">',
'#suffix' => '</div>',
);
$content['details'] = array(
'#theme' => 'userpoints_view_category',
'#title' => t('Details'),
'#weight' => 0,
'#attributes' => array(
'class' => array(
'userpoints-group-details',
),
),
);
$content['details']['user'] = array(
'#theme' => 'userpoints_view_item',
'#title' => t('User'),
'#value' => theme('username', array(
'account' => $transaction->user,
)),
'#weight' => 0,
'#attributes' => array(
'class' => array(
'userpoints-item-user',
),
),
);
$content['details']['points'] = array(
'#theme' => 'userpoints_view_item',
'#title' => t('!Points', userpoints_translation()),
'#value' => $transaction->points,
'#weight' => 10,
'#attributes' => array(
'class' => array(
'userpoints-item-points',
),
),
);
$content['details']['category'] = array(
'#theme' => 'userpoints_view_item',
'#title' => t('Category'),
'#value' => $transaction->category,
'#weight' => 20,
'#attributes' => array(
'class' => array(
'userpoints-item-category',
),
),
);
$content['details']['reason'] = array(
'#theme' => 'userpoints_view_item',
'#title' => t('Reason'),
'#value' => userpoints_create_description($transaction, array(
'truncate' => FALSE,
)),
'#weight' => 30,
'#attributes' => array(
'class' => array(
'userpoints-item-reason',
),
),
);
$content['details']['transaction'] = array(
'#theme' => 'userpoints_view_item',
'#title' => t('Transaction ID'),
'#value' => $transaction->txn_id,
'#weight' => 40,
'#attributes' => array(
'class' => array(
'userpoints-item-transaction',
),
),
);
$content['status'] = array(
'#theme' => 'userpoints_view_category',
'#title' => t('Status'),
'#weight' => 10,
'#attributes' => array(
'class' => array(
'userpoints-group-status',
),
),
);
$stati = userpoints_txn_status();
$content['status']['status'] = array(
'#theme' => 'userpoints_view_item',
'#title' => t('Approval status'),
'#value' => $stati[$transaction->status],
'#weight' => 0,
'#attributes' => array(
'class' => array(
'userpoints-item-status',
),
),
);
$content['status']['date'] = array(
'#theme' => 'userpoints_view_item',
'#title' => t('Creation date'),
'#value' => format_date($transaction->time_stamp),
'#weight' => 10,
'#attributes' => array(
'class' => array(
'userpoints-item-date',
),
),
);
$content['status']['changed'] = array(
'#theme' => 'userpoints_view_item',
'#title' => t('Last modified'),
'#value' => format_date($transaction->changed),
'#weight' => 20,
'#attributes' => array(
'class' => array(
'userpoints-item-changed',
),
),
);
if (!empty($transaction->expirydate)) {
$content['status']['expiration_status'] = array(
'#theme' => 'userpoints_view_item',
'#title' => t('Expiration status'),
'#value' => $transaction->expired ? t('Expired') : t('Not expired'),
'#weight' => 20,
'#attributes' => array(
'class' => array(
'userpoints-item-expiration-status',
),
),
);
$content['status']['expiration_date'] = array(
'#theme' => 'userpoints_view_item',
'#title' => t('Expiration date'),
'#value' => format_date($transaction->expirydate),
'#weight' => 30,
'#attributes' => array(
'class' => array(
'userpoints-item-points-expiration-date',
),
),
);
}
if (!empty($transaction->parent_txn_id)) {
$parent_transaction = userpoints_transaction_load($transaction->parent_txn_id);
$parent = l(userpoints_create_description($parent_transaction, array(
'link' => FALSE,
)), 'userpoints/view/' . $transaction->parent_txn_id, array(
'html' => TRUE,
));
}
$child_txn_ids = db_query('SELECT txn_id FROM {userpoints_txn} WHERE parent_txn_id = :txn_id', array(
':txn_id' => $transaction->txn_id,
))
->fetchCol();
$children = array();
foreach ($child_txn_ids as $child_txn_id) {
$child_transaction = userpoints_transaction_load($child_txn_id);
$children[] = l(userpoints_create_description($child_transaction, array(
'link' => FALSE,
)), 'userpoints/view/' . $child_txn_id, array(
'html' => TRUE,
));
}
$children = !empty($children) ? theme('item_list', array(
'items' => $children,
)) : '';
if (!empty($parent) || !empty($children)) {
$content['related'] = array(
'#theme' => 'userpoints_view_category',
'#title' => t('Related !points transactions', userpoints_translation()),
'#weight' => 20,
'#attributes' => array(
'class' => array(
'userpoints-group-related',
),
),
);
if (!empty($parent)) {
$content['related']['parent'] = array(
'#theme' => 'userpoints_view_item',
'#title' => t('Prior transaction'),
'#value' => $parent,
'#weight' => 0,
'#attributes' => array(
'class' => array(
'userpoints-item-parent',
),
),
);
}
if (!empty($children)) {
$content['related']['children'] = array(
'#theme' => 'userpoints_view_item',
'#title' => t('Follow-up transactions'),
'#value' => $children,
'#weight' => 10,
'#attributes' => array(
'class' => array(
'userpoints-item-children',
),
),
);
}
}
if (userpoints_admin_access('edit')) {
$content['admin'] = array(
'#theme' => 'userpoints_view_category',
'#title' => t('Admin'),
'#weight' => 30,
'#attributes' => array(
'class' => array(
'userpoints-group-admin',
),
),
);
if (!empty($transaction->approver_uid)) {
$content['admin']['moderator'] = array(
'#theme' => 'userpoints_view_item',
'#title' => t('Moderator'),
'#value' => theme('username', array(
'account' => user_load($transaction->approver_uid),
)),
'#weight' => 0,
'#attributes' => array(
'class' => array(
'userpoints-item-moderator',
),
),
);
}
if (!empty($transaction->description)) {
$content['admin']['description_manual'] = array(
'#theme' => 'userpoints_view_item',
'#title' => t('Description (manually entered)'),
'#value' => $transaction->description,
'#weight' => 10,
'#attributes' => array(
'class' => array(
'userpoints-item-description-manual',
),
),
);
$content['admin']['description_generated'] = array(
'#theme' => 'userpoints_view_item',
'#title' => t('Description (auto generated)'),
'#value' => userpoints_create_description($transaction, array(
'skip_description' => TRUE,
'truncate' => FALSE,
)),
'#weight' => 20,
'#attributes' => array(
'class' => array(
'userpoints-item-description-generated',
),
),
);
}
$content['admin']['operation'] = array(
'#theme' => 'userpoints_view_item',
'#title' => t('Operation'),
'#value' => $transaction->operation,
'#weight' => 30,
'#attributes' => array(
'class' => array(
'userpoints-item-operation',
),
),
);
if (!empty($transaction->reference)) {
$content['admin']['reference'] = array(
'#theme' => 'userpoints_view_item',
'#title' => t('Internal reference'),
'#value' => $transaction->reference,
'#weight' => 40,
'#attributes' => array(
'class' => array(
'userpoints-item-reference',
),
),
);
}
$content['admin']['actions'] = array(
'#theme' => 'userpoints_view_item',
'#title' => t('Actions'),
'#value' => userpoints_get_transaction_actions($transaction, FALSE),
'#weight' => 50,
'#attributes' => array(
'class' => array(
'userpoints-item-actions',
),
),
);
}
return $content;
}