function uc_roles_feature_form in Ubercart 6.2
Same name and namespace in other branches
- 5 uc_roles/uc_roles.module \uc_roles_feature_form()
- 7.3 uc_roles/uc_roles.module \uc_roles_feature_form()
Form builder for hook_product_feature.
See also
uc_roles_feature_form_validate()
uc_roles_feature_form_submit()
1 string reference to 'uc_roles_feature_form'
- uc_roles_product_feature in uc_roles/
uc_roles.module - Implements hook_product_feature().
File
- uc_roles/
uc_roles.module, line 636
Code
function uc_roles_feature_form($form_state, $node, $feature) {
$models = uc_product_get_models($node->nid);
// Check if editing or adding to set default values.
if (!empty($feature)) {
$product_role = db_fetch_object(db_query("SELECT * FROM {uc_roles_products} WHERE pfid = %d", $feature['pfid']));
$default_model = $product_role->model;
$default_role = $product_role->rid;
$default_qty = $product_role->duration;
$default_granularity = $product_role->granularity;
$default_shippable = $product_role->shippable;
$default_by_quantity = $product_role->by_quantity;
if ($product_role->end_time) {
$end_time = array(
'day' => date('j', $product_role->end_time),
'month' => date('n', $product_role->end_time),
'year' => date('Y', $product_role->end_time),
);
$default_end_type = 'abs';
}
else {
$temp = _uc_roles_get_expiration($default_qty, $default_granularity);
$end_time = array(
'day' => date('j', $temp),
'month' => date('n', $temp),
'year' => date('Y', $temp),
);
$default_end_type = 'rel';
}
$form['pfid'] = array(
'#type' => 'value',
'#value' => $feature['pfid'],
);
$form['rpid'] = array(
'#type' => 'value',
'#value' => $product_role->rpid,
);
$default_end_override = $product_role->end_override;
}
else {
$default_model = 0;
$default_role = variable_get('uc_roles_default_role', NULL);
$default_qty = variable_get('uc_roles_default_granularity', 'never') == 'never' ? NULL : variable_get('uc_roles_default_length', NULL);
$default_granularity = variable_get('uc_roles_default_granularity', 'never');
$default_shippable = $node->shippable;
$default_by_quantity = variable_get('uc_roles_default_by_quantity', FALSE);
$end_time = variable_get('uc_roles_default_end_time', array(
'day' => date('j'),
'month' => date('n'),
'year' => date('Y'),
));
$default_end_type = variable_get('uc_roles_default_end_expiration', 'rel');
$default_end_override = FALSE;
}
$roles = _uc_roles_get_choices();
if (!count($roles)) {
$form['no_roles'] = array(
'#value' => t('You need to <a href="!url">create new roles</a> before any can be added as product features.', array(
'!url' => url('admin/user/roles', array(
'query' => 'destination=admin/store/settings/products/edit/features',
)),
)),
'#prefix' => '<p>',
'#suffix' => '</p>',
);
return $form;
}
$form['nid'] = array(
'#type' => 'value',
'#value' => $node->nid,
);
$form['uc_roles_model'] = array(
'#type' => 'select',
'#title' => t('SKU'),
'#default_value' => $default_model,
'#description' => t('This is the SKU of the product that will grant the role.'),
'#options' => $models,
);
$form['uc_roles_role'] = array(
'#type' => 'select',
'#title' => t('Role'),
'#default_value' => $default_role,
'#description' => t('This is the role the customer will receive after purchasing the product.'),
'#options' => $roles,
);
$form['uc_roles_shippable'] = array(
'#type' => 'checkbox',
'#title' => t('Shippable product'),
'#default_value' => $default_shippable,
'#description' => t('Check if this product SKU that uses role assignment is associated with a shippable product.'),
);
$form['role_lifetime'] = array(
'#type' => 'fieldset',
'#title' => t('Expiration period'),
);
$form['role_lifetime']['end_override'] = array(
'#type' => 'checkbox',
'#title' => t('Override the default ending expiration'),
'#default_value' => $default_end_override,
);
$form['role_lifetime']['expiration'] = array(
'#type' => 'select',
'#title' => t('End'),
'#options' => array(
'rel' => t('Relative from activation time'),
'abs' => t('Absolute role ending'),
),
'#default_value' => $default_end_type,
);
$form['role_lifetime']['uc_roles_expire_relative_duration'] = array(
'#type' => 'textfield',
'#default_value' => $default_qty,
'#size' => 4,
'#maxlength' => 4,
'#prefix' => '<div class="expiration">',
'#suffix' => '</div>',
);
$form['role_lifetime']['uc_roles_expire_relative_granularity'] = array(
'#type' => 'select',
'#options' => array(
'never' => t('never'),
'day' => t('day(s)'),
'week' => t('week(s)'),
'month' => t('month(s)'),
'year' => t('year(s)'),
),
'#default_value' => $default_granularity,
'#description' => t('From the time the expiration period started.'),
'#prefix' => '<div class="expiration">',
'#suffix' => '</div>',
);
$form['role_lifetime']['uc_roles_expire_absolute'] = array(
'#type' => 'date',
'#description' => t('When this expiration period will end.'),
);
if ($end_time) {
$form['role_lifetime']['uc_roles_expire_absolute']['#default_value'] = $end_time;
}
$form['role_lifetime']['uc_roles_by_quantity'] = array(
'#type' => 'checkbox',
'#title' => t('Multiply by quantity'),
'#default_value' => $default_by_quantity,
'#description' => t('Check if the role duration should be multiplied by the quantity purchased.'),
);
return uc_product_feature_form($form);
}