function userpoints_admin_txn_submit in User Points 7.2
Same name and namespace in other branches
- 5.3 userpoints.module \userpoints_admin_txn_submit()
- 5 userpoints.module \userpoints_admin_txn_submit()
- 5.2 userpoints.module \userpoints_admin_txn_submit()
- 6 userpoints.module \userpoints_admin_txn_submit()
- 7 userpoints.admin.inc \userpoints_admin_txn_submit()
Submit function for userpoints transaction form.
File
- ./
userpoints.admin.inc, line 424 - Admin menu callbacks for userpoints.module.
Code
function userpoints_admin_txn_submit($form, &$form_state) {
global $user;
$transaction = $form_state['userpoints_transaction'];
// Check if this is a new transaction or if we are editing an existing one.
if ($form_state['values']['mode'] == 'add') {
// Set basic properties.
$transaction
->setUid($form_state['values']['txn_user']->uid)
->setTimestamp($form_state['values']['time_stamp']);
// If the transaction should be moderated, set it to pending.
if ($form_state['values']['moderate']) {
$transaction
->pending();
}
// New transactions are always "approved" by the current user.
$transaction
->setApproverUid($user->uid);
// Check for the existence of an expirydate.
if ($form_state['values']['expirydate']) {
$transaction
->setExpiryDate(strtotime($form_state['values']['expirydate']));
}
}
else {
// Updating an existing transaction, load and update values.
$transaction
->setStatus($form_state['values']['status'])
->setMessage(t('Changes to the !points transaction have been saved.', userpoints_translation()));
// Allow to remove expiration date, first set it to 0 and only set it back
// if explicitly set.
$transaction
->setExpiryDate(0);
if (!empty($form_state['values']['expirydate'])) {
$transaction
->setExpiryDate(strtotime($form_state['values']['expirydate']));
}
// If status changed, the current user is the new approver.
if ($transaction
->getStatus() != $form_state['values']['status']) {
$transaction
->setApproverUid($user->uid);
}
}
// Attach field information directly to the userpoints transaction object.
foreach (field_info_instances('userpoints_transaction', $transaction->type) as $instance) {
$field_name = $instance['field_name'];
$transaction->{$field_name} = $form_state['values'][$field_name];
}
field_attach_submit('userpoints_transaction', $transaction, $form, $form_state);
if (!isset($form_state['values']['tid'])) {
// Set default tid if taxonomy is disabled.
$form_state['values']['tid'] = userpoints_get_default_tid();
}
// Set common properties and save the transaction.
$transaction
->setTid($form_state['values']['tid'])
->setPoints($form_state['values']['points'])
->setOperation($form_state['values']['operation'])
->setReference($form_state['values']['reference'])
->setDescription($form_state['values']['description'])
->setEntity($form_state['values']['entity_type'], $form_state['values']['entity_id'])
->save();
$form_state['redirect'] = 'admin/config/people/userpoints';
}