function uc_coupon_tokens in Ubercart Discount Coupons 7.2
Same name and namespace in other branches
- 7.3 uc_coupon.tokens.inc \uc_coupon_tokens()
Implements hook_tokens().
File
- ./
uc_coupon.tokens.inc, line 55 - Token support for uc_coupon.
Code
function uc_coupon_tokens($type, $tokens, $data = array(), $options = array()) {
$sanitize = !empty($options['sanitize']);
$values = array();
switch ($type) {
case 'uc_order':
if (array_key_exists('coupon-code', $tokens) && !empty($data['uc_order']) && isset($data['uc_order']->data['coupon'])) {
$values[$tokens['coupon-code']] = $sanitize ? check_plain($data['uc_order']->data['coupon']) : $data['uc_order']->data['coupon'];
}
break;
case 'uc_coupon':
if (!empty($data['uc_coupon'])) {
$coupon = $data['uc_coupon'];
if (array_key_exists('name', $tokens)) {
$values[$tokens['name']] = $sanitize ? check_plain($coupon->name) : $coupon->name;
}
if (array_key_exists('code', $tokens)) {
$values[$tokens['code']] = $sanitize ? check_plain($coupon->code) : $coupon->code;
}
if (array_key_exists('codes', $tokens)) {
$codes = array();
if ($coupon->bulk) {
for ($id = 0; $id < $coupon->data['bulk_number']; $id++) {
$codes[] = uc_coupon_get_bulk_code($coupon, $id);
}
}
else {
$codes[] = $coupon->code;
}
$values[$tokens['codes']] = implode("\n", $sanitize ? array_walk($codes, 'check_plain') : $codes);
}
if (array_key_exists('value', $tokens)) {
$values[$tokens['value']] = isset($coupon->amount) ? theme('uc_price', array(
'price' => $coupon->amount,
)) : theme('uc_coupon_discount', array(
'coupon' => $coupon,
));
}
}
break;
}
return $values;
}