Dev version of uc_views

This commit is contained in:
mattbk
2015-10-06 13:57:14 -05:00
parent de57c1b0e6
commit bb1313bad9
52 changed files with 5691 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,435 @@
<?php
/**
* @file
* Default views for uc_views.module.
*/
/**
* Implementation of hook_views_default_views().
*/
function uc_views_views_default_views() {
$view = new view;
$view->name = 'orders';
$view->description = 'Order listing';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'uc_orders';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = TRUE; /* Edit this to false to make a default view enabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('fields', array(
'order_id' => array(
'label' => 'Order id',
'link_to_order' => 1,
'exclude' => 0,
'id' => 'order_id',
'table' => 'uc_orders',
'field' => 'order_id',
'relationship' => 'none',
),
'name' => array(
'label' => 'Name',
'link_to_user' => 1,
'exclude' => 0,
'id' => 'name',
'table' => 'users',
'field' => 'name',
'relationship' => 'none',
),
'primary_email' => array(
'label' => 'Email',
'exclude' => 0,
'id' => 'primary_email',
'table' => 'uc_orders',
'field' => 'primary_email',
'relationship' => 'none',
),
'country_name' => array(
'label' => 'Delivery country',
'exclude' => 0,
'id' => 'country_name',
'table' => 'delivery_countries',
'field' => 'country_name',
'relationship' => 'none',
),
'created' => array(
'label' => 'Date',
'date_format' => 'small',
'custom_date_format' => '',
'exclude' => 0,
'id' => 'created',
'table' => 'uc_orders',
'field' => 'created',
'relationship' => 'none',
),
'order_total' => array(
'label' => 'Total',
'exclude' => 0,
'id' => 'order_total',
'table' => 'uc_orders',
'field' => 'order_total',
'relationship' => 'none',
),
));
$handler->override_option('filters', array(
'uid' => array(
'operator' => 'in',
'value' => '',
'group' => '0',
'exposed' => TRUE,
'expose' => array(
'use_operator' => 0,
'operator' => 'uid_op',
'identifier' => 'uid',
'label' => 'Username',
'optional' => 1,
'remember' => 1,
'reduce' => 0,
),
'id' => 'uid',
'table' => 'users',
'field' => 'uid',
'relationship' => 'none',
),
));
$handler->override_option('access', array(
'type' => 'perm',
'perm' => 'view all orders',
));
$handler->override_option('cache', array(
'type' => 'none',
));
$handler->override_option('title', 'Orders');
$handler->override_option('items_per_page', 25);
$handler->override_option('use_pager', '1');
$handler->override_option('style_plugin', 'table');
$handler->override_option('style_options', array(
'grouping' => '',
'override' => 1,
'sticky' => 0,
'order' => 'desc',
'columns' => array(
'order_id' => 'order_id',
'name' => 'name',
'primary_email' => 'name',
'created' => 'created',
'order_total' => 'order_total',
'country_name' => 'name',
),
'info' => array(
'order_id' => array(
'sortable' => 1,
'separator' => '',
),
'name' => array(
'sortable' => 0,
'separator' => '<br/>',
),
'primary_email' => array(
'separator' => '',
),
'created' => array(
'sortable' => 1,
'separator' => '',
),
'order_total' => array(
'sortable' => 1,
'separator' => '',
),
'country_name' => array(
'sortable' => 1,
'separator' => '',
),
),
'default' => 'order_id',
));
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->override_option('path', 'orders');
$handler->override_option('menu', array(
'type' => 'none',
'title' => '',
'weight' => 0,
'name' => 'navigation',
));
$handler->override_option('tab_options', array(
'type' => 'none',
'title' => '',
'weight' => 0,
));
$views[$view->name] = $view;
if (module_exists('draggableviews')) {
$view = new view;
$view->name = 'product_order';
$view->description = '';
$view->tag = 'Ubercart';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('fields', array(
'title' => array(
'label' => 'Title',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'link_class' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'target' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'html' => 0,
'strip_tags' => 0,
),
'empty' => '',
'hide_empty' => 0,
'empty_zero' => 0,
'link_to_node' => 1,
'exclude' => 0,
'id' => 'title',
'table' => 'node',
'field' => 'title',
'relationship' => 'none',
),
'sell_price' => array(
'label' => 'Sell price',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'link_class' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'target' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'html' => 0,
'strip_tags' => 0,
),
'empty' => '',
'hide_empty' => 0,
'empty_zero' => 0,
'set_precision' => 0,
'precision' => '0',
'decimal' => '.',
'separator' => ',',
'prefix' => '',
'suffix' => '',
'format' => 'uc_price',
'revision' => 'themed',
'exclude' => 0,
'id' => 'sell_price',
'table' => 'uc_products',
'field' => 'sell_price',
'relationship' => 'none',
),
'ordering' => array(
'label' => 'List position',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'link_class' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'target' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'html' => 0,
'strip_tags' => 0,
),
'empty' => '',
'hide_empty' => 0,
'empty_zero' => 0,
'set_precision' => FALSE,
'precision' => 0,
'decimal' => '.',
'separator' => ',',
'prefix' => '',
'suffix' => '',
'exclude' => 0,
'id' => 'ordering',
'table' => 'uc_products',
'field' => 'ordering',
'relationship' => 'none',
),
));
$handler->override_option('sorts', array(
'ordering' => array(
'order' => 'ASC',
'id' => 'ordering',
'table' => 'uc_products',
'field' => 'ordering',
'relationship' => 'none',
),
));
$handler->override_option('filters', array(
'is_product' => array(
'operator' => '=',
'value' => '1',
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'is_product',
'table' => 'uc_products',
'field' => 'is_product',
'relationship' => 'none',
),
'status' => array(
'operator' => '=',
'value' => '1',
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'status',
'table' => 'node',
'field' => 'status',
'relationship' => 'none',
),
'tid' => array(
'operator' => 'or',
'value' => array(),
'group' => '0',
'exposed' => TRUE,
'expose' => array(
'use_operator' => 0,
'operator' => 'tid_op',
'identifier' => 'tid',
'label' => 'Taxonomy term',
'optional' => 1,
'single' => 1,
'remember' => 0,
'reduce' => 0,
),
'type' => 'select',
'limit' => TRUE,
'vid' => variable_get('uc_catalog_vid', 0),
'id' => 'tid',
'table' => 'term_node',
'field' => 'tid',
'hierarchy' => 1,
'relationship' => 'none',
'reduce_duplicates' => 0,
),
));
$handler->override_option('access', array(
'type' => 'perm',
'perm' => 'administer products',
));
$handler->override_option('cache', array(
'type' => 'none',
));
$handler->override_option('title', 'Product display order');
$handler->override_option('items_per_page', 30);
$handler->override_option('use_pager', '1');
$handler->override_option('style_plugin', 'draggabletable');
$handler->override_option('style_options', array(
'override' => 1,
'sticky' => 0,
'order' => 'asc',
'columns' => array(
'title' => 'title',
'sell_price' => 'sell_price',
'ordering' => 'ordering',
),
'info' => array(
'title' => array(
'sortable' => 0,
'separator' => '',
),
'sell_price' => array(
'sortable' => 0,
'separator' => '',
),
'ordering' => array(
'separator' => '',
),
),
'default' => -1,
'tabledrag_order' => array(
'field' => 'ordering',
'handler' => 'ubercart',
),
'tabledrag_order_visible' => array(
'visible' => 0,
),
'tabledrag_hierarchy' => array(
'field' => 'none',
'handler' => 'native',
),
'tabledrag_hierarchy_visible' => array(
'visible' => 0,
),
'draggableviews_depth_limit' => '0',
'draggableviews_repair' => array(
'repair' => 0,
),
'tabledrag_types_add' => 'Add type',
'tabledrag_expand' => array(
'expand_links' => 0,
'collapsed' => 0,
'by_uid' => 0,
),
'draggableviews_extensions' => array(
'extension_top' => '3',
'extension_bottom' => '3',
),
'tabledrag_lock' => array(
'lock' => 0,
),
'draggableviews_default_on_top' => '1',
'draggableviews_button_text' => 'Save order',
'draggableviews_arguments' => array(
'use_args' => 0,
),
));
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->override_option('path', 'admin/store/products/order');
$handler->override_option('menu', array(
'type' => 'none',
'title' => '',
'description' => '',
'weight' => 0,
'name' => 'navigation',
));
$handler->override_option('tab_options', array(
'type' => 'none',
'title' => '',
'description' => '',
'weight' => 0,
'name' => 'navigation',
));
$views[$view->name] = $view;
}
return $views;
}

View File

@ -0,0 +1,78 @@
<?php
/**
* Field handler to provide simple renderer that allows linking to a user from a cart id.
*/
class uc_views_handler_field_cart_user extends views_handler_field {
/**
* Override init function to provide generic option to link to user.
*/
function init(&$view, &$data) {
parent::init($view, $data);
if (!empty($this->options['link_to_user'])) {
$this->additional_fields['cart_id'] = 'cart_id';
}
}
function option_definition() {
$options = parent::option_definition();
$options['link_to_user'] = array('default' => TRUE);
$options['overwrite_anonymous'] = array('default' => TRUE);
$options['anonymous_text'] = array('default' => 'Anonymous', 'translatable' => TRUE);
return $options;
}
/**
* Provide link to node option
*/
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['link_to_user'] = array(
'#title' => t('Link this field to its user'),
'#description' => t('This will override any other link you have set.'),
'#type' => 'checkbox',
'#default_value' => $this->options['link_to_user'],
);
$form['overwrite_anonymous'] = array(
'#title' => t('Overwrite the value to display for anonymous users'),
'#type' => 'checkbox',
'#default_value' => !empty($this->options['overwrite_anonymous']),
'#description' => t('If selected, you will see a field to enter the text to use for anonymous users.'),
);
$form['anonymous_text'] = array(
'#title' => t('Text to display for anonymous users'),
'#type' => 'textfield',
'#default_value' => $this->options['anonymous_text'],
'#process' => array('views_process_dependency'),
'#dependency' => array(
'edit-options-overwrite-anonymous' => array(1),
),
);
}
function render_link($data, $values) {
if (!empty($this->options['link_to_user']) &&
user_access('access user profiles') &&
$values->{$this->aliases['cart_id']} &&
$data !== NULL &&
$data !== '') {
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = "user/" . $values->{$this->aliases['cart_id']};
}
return $data;
}
function render($values) {
$result = db_result(db_query('SELECT name FROM {users} u WHERE u.uid = %d', $values->{$this->field_alias}));
if ($result) {
return $this->render_link($result, $values);
} else {
// If the cart belongs to an unauthenticated user
if (!empty($this->options['overwrite_anonymous'])) {
return check_plain($this->options['anonymous_text']);
} else {
return $values->{$this->field_alias};
}
}
}
}

View File

@ -0,0 +1,93 @@
<?php
/**
* @file
* Views handler: "Add to cart" form as a field if certain conditions are met.
*/
/**
* Display the "Add to cart" form like the product page.
*/
class uc_views_handler_field_conditional_addtocart extends views_handler_field {
/**
* Provide conditions option.
*/
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$options = $this->options;
$form['price_conditions'] = array(
'#title' => t('Price condition'),
'#type' => 'radios',
'#options' => array(
'price_disabled' => t('Disabled'),
'price_enabled' => t('Enabled'),
),
'#default_value' => $options['price_conditions'] ? $options['price_conditions'] : 'price_disabled',
'#weight' => 2,
);
$form['condition_price_operator'] = array(
'#title' => t('Condition (show button if product sell price)'),
'#type' => 'select',
'#options' => array(
'<' => t('Is less than'),
'<=' => t('Is less than or equal to'),
'==' => t('Is equal to'),
'!=' => t('Is not equal to'),
'>=' => t('Is greater than or equal to'),
'>' => t('Is greater than'),
),
'#default_value' => $options['condition_price_operator'] ? $options['condition_price_operator'] : '<',
'#process' => array('views_process_dependency'),
'#dependency' => array('radio:options[price_conditions]' => array('price_enabled')),
'#weight' => 3,
);
$form['condition_price'] = array(
'#title' => t('Price'),
'#type' => 'textfield',
'#default_value' => $options['condition_price'],
'#process' => array('views_process_dependency'),
'#dependency' => array('radio:options[price_conditions]' => array('price_enabled')),
'#weight' => 4,
);
$form['condition_price_default_text'] = array(
'#title' => t('Default text'),
'#description' => t('Text to show in stead of button if conditions are not met.'),
'#type' => 'textfield',
'#default_value' => $options['condition_price_default_text'],
'#process' => array('views_process_dependency'),
'#dependency' => array('radio:options[price_conditions]' => array('price_enabled')),
'#weight' => 5,
);
}
function query() {
$this->ensure_my_table();
$this->add_additional_fields();
}
function render($values) {
if (uc_product_is_product($values->{$this->aliases['type']})) {
$type = node_get_types('type', $values->{$this->aliases['type']});
$module = $type->module;
$product = node_load($values->{$this->aliases['nid']});
$result = '';
if (function_exists('theme_'. $module .'_add_to_cart')) {
$result = theme($module .'_add_to_cart', $product);
}
elseif (function_exists('theme_uc_product_add_to_cart')) {
$result = theme('uc_product_add_to_cart', $product);
}
if($this->options['price_conditions'] == 'price_enabled') {
if(eval('return ('.$product->sell_price.' '.$this->options['condition_price_operator'].' '.$this->options['condition_price'].');')) {
return $result;
} else {
return $this->options['condition_price_default_text'];
}
} else {
return $result;
}
}
}
}

View File

@ -0,0 +1,84 @@
<?php
/**
* @file
* Views handler: Simpler "Add to cart" form as a field if certain conditions are met.
*/
/**
* Display the simpler Add to cart form like the catalog.
*/
class uc_views_handler_field_conditional_buyitnow extends views_handler_field {
/**
* Provide conditions option.
*/
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$options = $this->options;
$form['price_conditions'] = array(
'#title' => t('Price condition'),
'#type' => 'radios',
'#options' => array(
'price_disabled' => t('Disabled'),
'price_enabled' => t('Enabled'),
),
'#default_value' => $options['price_conditions'] ? $options['price_conditions'] : 'price_disabled',
'#weight' => 2,
);
$form['condition_price_operator'] = array(
'#title' => t('Condition (show button if product sell price)'),
'#type' => 'select',
'#options' => array(
'<' => t('Is less than'),
'<=' => t('Is less than or equal to'),
'==' => t('Is equal to'),
'!=' => t('Is not equal to'),
'>=' => t('Is greater than or equal to'),
'>' => t('Is greater than'),
),
'#default_value' => $options['condition_price_operator'] ? $options['condition_price_operator'] : '<',
'#process' => array('views_process_dependency'),
'#dependency' => array('radio:options[price_conditions]' => array('price_enabled')),
'#weight' => 3,
);
$form['condition_price'] = array(
'#title' => t('Price'),
'#type' => 'textfield',
'#default_value' => $options['condition_price'],
'#process' => array('views_process_dependency'),
'#dependency' => array('radio:options[price_conditions]' => array('price_enabled')),
'#weight' => 4,
);
$form['condition_price_default_text'] = array(
'#title' => t('Default text'),
'#description' => t('Text to show in stead of button if conditions are not met.'),
'#type' => 'textfield',
'#default_value' => $options['condition_price_default_text'],
'#process' => array('views_process_dependency'),
'#dependency' => array('radio:options[price_conditions]' => array('price_enabled')),
'#weight' => 5,
);
}
function query() {
$this->ensure_my_table();
$this->add_additional_fields();
}
function render($values) {
$product = node_load($values->{$this->aliases['nid']});
if (uc_product_is_product($product)) {
if($this->options['price_conditions'] == 'price_enabled') {
if(eval('return ('.$product->sell_price.' '.$this->options['condition_price_operator'].' '.$this->options['condition_price'].');')) {
return drupal_get_form('uc_catalog_buy_it_now_form_'. $values->{$this->aliases['nid']}, $product);
} else {
return $this->options['condition_price_default_text'];
}
} else {
return drupal_get_form('uc_catalog_buy_it_now_form_'. $values->{$this->aliases['nid']}, $product);
}
}
}
}

View File

@ -0,0 +1,15 @@
<?php
/**
* @file
* Views handler: Return country name for country id
*/
/**
* Return a country name for country id
*/
class uc_views_handler_field_country extends views_handler_field {
function render($values) {
return uc_country_get_by_id($values->{$this->field_alias});
}
}

View File

@ -0,0 +1,36 @@
<?php
/**
* @file
* Views handler: Product price field.
*/
/**
* Return a formatted price value to display in the View.
*/
class uc_views_handler_field_money_amount extends uc_product_handler_field_price {
function options(&$options) {
parent::options($options);
$options['revision'] = 'themed-original';
}
function render($values) {
if ($this->options['format'] == 'numeric') {
return parent::render($values);
}
if ($this->options['format'] == 'uc_price') {
$context = array(
'revision' => $this->options['revision'],
'type' => 'amount',
'class' => array(
$this->field,
),
'field' => $this->real_field,
);
return uc_price($values->{$this->field_alias}, $context);
}
}
}

View File

@ -0,0 +1,16 @@
<?php
/**
* @file
* Views handler: Return actions for order id - by justindodge
*/
/**
* Return actions for an order
*/
class uc_views_handler_field_order_actions extends views_handler_field {
function render($values) {
$order = uc_order_load($values->{$this->field_alias});
return uc_order_actions($order, true);
}
}

View File

@ -0,0 +1,20 @@
<?php
/**
* @file
* Order balance field handler
*/
class uc_views_handler_field_order_balance extends uc_views_handler_field_money_amount {
function query() {
$this->ensure_my_table();
$this->add_additional_fields();
}
function render($values) {
$order->order_id = $values->{$this->aliases['order_id']};
$order->order_total = $values->{$this->aliases['order_total']};
$values->{$this->field_alias} = uc_payment_balance($order);
return parent::render($values);
}
}

View File

@ -0,0 +1,28 @@
<?php
/**
* @file
* CC data views field handler
*/
class uc_views_handler_field_order_cc_data extends views_handler_field {
function render($values) {
// Initialize the encryption key and class.
$key = uc_credit_encryption_key();
$crypt = new uc_encryption_class;
$data = unserialize($values->{$this->field_alias});
$cc_data = $data['cc_data'];
// In recent ubercart versions, they base64_encode() the payment details
// before encrypting. We can detect encoded data by the lack of colons,
// due to base64's limited character set.
// see uc_credit_cache()
$decrypted_data = $crypt->decrypt($key, $cc_data);
if (strpos($decrypted_data, ':') === FALSE) {
$decrypted_data = base64_decode($decrypted_data);
}
$cc_data = unserialize($decrypted_data);
return $cc_data[$this->definition['cc field']];
}
}

View File

@ -0,0 +1,26 @@
<?php
/**
* @file
* Ordel total cost field handler
*/
class uc_views_handler_field_order_cost extends uc_views_handler_field_money_amount {
function construct() {
parent::construct();
$this->additional_fields['order_id'] = 'order_id';
}
function query() {
$this->ensure_my_table();
$this->add_additional_fields();
//do nothing else with the query, we'll be retrieving the information from the db
}
function render($values) {
$this->field_alias = 'order_cost';
$cost = db_result(db_query("SELECT SUM(qty * cost) FROM {uc_order_products} WHERE order_id = %d", $values->{$this->aliases['order_id']}));
$values->{$this->field_alias} = $cost;
return parent::render($values);
}
}

View File

@ -0,0 +1,52 @@
<?php
/**
* @file
* Views handler: Full name field handler (first and last)
*/
/**
* Return the full name
*/
class uc_views_handler_field_order_fullname extends views_handler_field {
function option_definition() {
$options = parent::option_definition();
$options['format'] = array('default' => 'first_last');
return $options;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['format'] = array(
'#title' => t('Format'),
'#type' => 'select',
'#options' => array(
'first_last' => t('First Last'),
'last_c_first' => t('Last, First'),
'last_first' => t('Last First'),
),
'#default_value' => $this->options['format'],
);
}
function query() {
$this->ensure_my_table();
$this->add_additional_fields();
}
function render($values) {
$prefix = $this->definition['prefix'];
$first = check_plain($values->{$this->aliases[$prefix . '_first_name']});
$last = check_plain($values->{$this->aliases[$prefix . '_last_name']});
switch ($this->options['format']) {
case 'last_first':
return "$last $first";
case 'last_c_first':
return "$last, $first";
case 'first_last':
return "$first $last";
}
}
}

View File

@ -0,0 +1,48 @@
<?php
/**
* @file
* Contains the basic 'order' field handler.
*/
/**
* Field handler to provide simple renderer that allows linking to the order adminstration page.
*/
class uc_views_handler_field_order_id extends views_handler_field {
function option_definition() {
$options = parent::option_definition();
$options['link_to_order'] = array('default' => FALSE);
return $options;
}
/**
* Provide link to order adminstration page
*/
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['link_to_order'] = array(
'#title' => t('Link this field to the order view.'),
'#description' => t('The link will go to the admin view if the user has "view all orders" permission, or the user view if the order belongs to the current user and they have "view own orders" permission. This will override any other link you have set.'),
'#type' => 'checkbox',
'#default_value' => !empty($this->options['link_to_order']),
);
}
function render($values) {
global $user;
$this->options['alter']['make_link'] = FALSE;
if (!empty($this->options['link_to_order']) && $values->{$this->field_alias}) {
if (user_access('view all orders')) {
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = "admin/store/orders/" . $values->{$this->field_alias};
}
elseif ($values->{$this->aliases['uid']} == $user->uid && user_access('view own orders')) {
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = 'user/' . $user->uid . '/order/' . $values->{$this->field_alias};
}
}
return parent::render($values);
}
}

View File

@ -0,0 +1,15 @@
<?php
/**
* @file
* Views handler: Order status field.
*/
/**
* Return a human readable text for order status to display in the View.
*/
class uc_views_handler_field_order_status extends views_handler_field {
function render($values) {
return uc_order_status_data($values->{$this->field_alias}, 'title');
}
}

View File

@ -0,0 +1,53 @@
<?php
/**
* @file
* Views handler: Order total weight
*/
/**
* Return the full name
*/
class uc_views_handler_field_order_weight extends views_handler_field_numeric {
function option_definition() {
$options = parent::option_definition();
$options['weight_units'] = array('default' => variable_get('uc_weight_unit', 'lb'));
return $options;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['weight_units'] = array('#type' => 'select',
'#title' => t('Unit of measurement'),
'#default_value' => $this->options['weight_units'],
'#options' => array(
'lb' => t('Pounds'),
'kg' => t('Kilograms'),
'oz' => t('Ounces'),
'g' => t('Grams'),
),
);
}
function query() {
$this->ensure_my_table();
$this->add_additional_fields();
}
function render($values) {
$oid = $values->{$this->aliases['order_id']};
$order = uc_order_load($oid);
$total = 0;
// TODO: Replace this for a mysql query like the cost field handler
foreach ($order->products as $product) {
$unit_conversion = uc_weight_conversion($product->weight_units, $this->options['weight_units']);
$total += $product->qty * $product->weight * $unit_conversion;
}
$this->field_alias = 'order_weight';
$values->{$this->field_alias} = $total;
return parent::render($values);
}
}

View File

@ -0,0 +1,15 @@
<?php
/**
* @file
* Views handler: Return zone name for zone id
*/
/**
* Return a zone name for zone id
*/
class uc_views_handler_field_zone extends views_handler_field {
function render($values) {
return uc_zone_get_by_id($values->{$this->field_alias});
}
}

View File

@ -0,0 +1,27 @@
<?php
/**
* Filter handler for the current cart.
*/
class uc_views_handler_filter_cart_current extends views_handler_filter_boolean_operator {
function construct() {
parent::construct();
$this->value_value = t("Is the current user's cart");
}
function query() {
$this->ensure_my_table();
$where = "$this->table_alias.$this->real_field ";
if (empty($this->value)) {
$where .= '<> "***CURRENT_CART_ID***"';
if ($this->accept_null) {
$where = '(' . $where . " OR $this->table_alias.$this->real_field IS NULL)";
}
}
else {
$where .= '= "***CURRENT_CART_ID***"';
}
$this->query->add_where($this->options['group'], $where);
}
}

View File

@ -0,0 +1,21 @@
<?php
/**
* Filter by country code
*/
class uc_views_handler_filter_country extends views_handler_filter_in_operator {
function get_value_options() {
if (!isset($this->value_options)) {
$this->value_title = t('Country');
$result = db_query("SELECT country_id,country_name FROM {uc_countries} WHERE version > 0 ORDER BY country_name");
while ($country = db_fetch_array($result)) {
$options[$country['country_id']] = $country['country_name'];
}
if (count($options) == 0) {
$options[] = t('No countries found.');
}
$this->value_options = $options;
}
}
}

View File

@ -0,0 +1,35 @@
<?php
/**
* @file
* Original patch by psy
* Views handler: Return payment method name for payment method id
*/
/**
* Filter by payment method
*
*/
class uc_views_handler_filter_payment_method extends views_handler_filter_in_operator {
function get_value_options() {
if (!isset($this->value_options)) {
$this->value_title = t('Payment Method');
$this->value_options = _distinct_payment_methods(); // $method;
}
}
}
/**
*_distinct_payment_methods()
*returns an array of DISTINCT payment methods from the uc_oders table
*/
function _distinct_payment_methods() {
$methods = array();
$result = db_query("SELECT DISTINCT payment_method AS payment_methods FROM {uc_orders}");
while ($pm = db_fetch_object($result)) {
$methods[$pm->payment_methods] = $pm->payment_methods;
}
return $methods;
}

View File

@ -0,0 +1,21 @@
<?php
/**
* Filter by zone code
*/
class uc_views_handler_filter_zone extends views_handler_filter_in_operator {
function get_value_options() {
if (!isset($this->value_options)) {
$this->value_title = t('Zone');
$result = db_query("SELECT zone_id,zone_name FROM {uc_zones} ORDER BY zone_country_id,zone_name");
while ($zone = db_fetch_array($result)) {
$options[$zone['zone_id']] = $zone['zone_name'];
}
if (count($options) == 0) {
$options[] = t('No zones found.');
}
$this->value_options = $options;
}
}
}

View File

@ -0,0 +1,19 @@
<?php
// $Id:
/**
* @file
* Patch by hanoii
* Contains the node view row style plugin.
*/
/**
* Plugin which performs a node_view on the resulting object.
*
* Most of the code on this object is in the theme function.
*/
class uc_views_plugin_row_invoice_view extends views_plugin_row {
// Basic properties that let the row style follow relationships.
var $base_table = 'uc_orders';
var $base_field = 'order_id';
}

View File

@ -0,0 +1,18 @@
<?php
/**
* Filter by order status
* Thank you river_t for the Patch!
*/
class views_handler_filter_order_status extends views_handler_filter_in_operator {
function get_value_options() {
if (!isset($this->value_options)) {
$this->value_title = t('Order Status');
$statuses = uc_order_status_list();
foreach ($statuses as $status => $name) {
$options[$name['id']] = $name['title'];
}
$this->value_options = $options;
}
}
}