function uc_recurring_subscription_overview in UC Recurring Payments and Subscriptions 7.2
Same name and namespace in other branches
- 6.2 modules/uc_recurring_subscription/uc_recurring_subscription.admin.inc \uc_recurring_subscription_overview()
Create the subscription overiew page.
1 string reference to 'uc_recurring_subscription_overview'
- uc_recurring_subscription_menu in modules/
uc_recurring_subscription/ uc_recurring_subscription.module - Implements hook_menu().
File
- modules/
uc_recurring_subscription/ uc_recurring_subscription.admin.inc, line 11 - Uc recurring subscription UI.
Code
function uc_recurring_subscription_overview($form, &$form_state) {
// Warn user if the ubercart API patch not applied.
if (!function_exists('uc_attribute_load_multiple')) {
drupal_set_message(t('This module requires a patch to ubercart, read the <a href="@readme">README.txt</a>', array(
'@readme' => url(drupal_get_path('module', 'uc_recurring_subscription') . '/README.txt'),
)), 'error');
return '';
}
$url = url(drupal_get_path('module', 'uc_recurring_subscription') . '/README.txt');
drupal_add_css(drupal_get_path('module', 'uc_recurring_subscription') . '/uc_recurring_subscription.css');
$product_class = variable_get('uc_recurring_subscription_product_class', 'uc_recurring_subscription');
$result = db_query("SELECT n.nid, n.title\n FROM {node} n\n LEFT JOIN {uc_recurring_subscription} rs ON rs.nid=n.nid\n WHERE n.type = :type\n ORDER BY rs.weight", array(
':type' => $product_class,
));
$roles = user_roles(TRUE);
$form['products']['#tree'] = TRUE;
$form['products']['#theme'] = 'uc_recurring_subscription_products';
foreach ($result as $node) {
$product = node_load($node->nid);
$attribute = uc_attribute_load(variable_get('uc_recurring_subscription_attribute', ''));
// roles
$product_roles = array();
if (!empty($product->subscription->access['subscribe_grant'])) {
$product_roles = array_intersect_key($roles, $product->subscription->access['subscribe_grant']);
}
// payment options
$products = _uc_recurring_subscription_get_product_features($node->nid);
$intervals = array();
foreach ($products as $id => $feature) {
$interval = theme('uc_price', array(
'price' => $feature->fee_amount,
)) . ' - ' . _uc_recurring_subscription_create_attribute_option($feature->regular_interval_value, $feature->regular_interval_unit);
if ($product->attributes[$attribute->aid]->default_option == $feature->option->oid) {
$interval = '<span class="default-option">' . $interval . '</span>';
}
if (module_exists('uc_cart_links')) {
$interval .= ' ' . t('(<a href="@link">cart link</a>)', array(
'@link' => url('cart/add/e-p' . $node->nid . '_q1_a' . $attribute->aid . 'o' . $feature->option->oid . '-isub', array(
'query' => array(
'destination' => 'cart/checkout',
),
'absolute' => TRUE,
)),
));
}
if ($feature->regular_interval_value != $feature->initial_charge_value && $feature->regular_interval_unit != $feature->initial_charge_unit) {
$trial = theme('uc_price', array(
'price' => $product->sell_price,
)) . ' - ' . $feature->initial_charge_value . ' ' . $feature->initial_charge_unit;
}
$intervals[] = $interval;
}
$form['products'][$node->nid]['title'] = array(
'#markup' => l($product->title, 'node/' . $product->nid),
);
$form['products'][$node->nid]['role'] = array(
'#markup' => implode(', ', $product_roles),
);
$form['products'][$node->nid]['trial'] = array(
'#markup' => empty($trial) ? t('None') : $trial,
);
$form['products'][$node->nid]['interval'] = array(
'#markup' => implode('<br/>', $intervals),
);
$form['products'][$node->nid]['operations'] = array(
'#theme' => 'links',
'#links' => array(
array(
'title' => 'edit',
'href' => 'admin/store/subscriptions/' . $node->nid . '/edit',
),
array(
'title' => 'delete',
'href' => 'node/' . $node->nid . '/delete',
'attributes' => array(
'query' => array(
'destination' => 'admin/store/subscriptions',
),
),
),
),
);
$form['products'][$node->nid]['weight'] = array(
'#type' => 'weight',
'#delta' => 10,
'#default_value' => isset($product->subscription) ? $product->subscription->weight : 0,
);
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save order'),
);
return $form;
}