View source
<?php
function uc_views_marketing_requirements($phase) {
$requirements = array();
if ($phase == 'install') {
$t = get_t();
if (!@db_query("CREATE VIEW {uc_views_marketing_test} (nid) AS SELECT nid FROM {node}")) {
$requirements['uc_views_marketing']['description'] = $t('Ubercart Views Marketing requires the CREATE VIEW privilege in your database. Please grant this privilege to your database user, or contact your system administrator.');
$requirements['uc_views_marketing']['severity'] = REQUIREMENT_ERROR;
}
else {
db_query("DROP VIEW {uc_views_marketing_test}");
}
}
return $requirements;
}
function uc_views_marketing_schema() {
$schema['uc_order_products_user_vw'] = array(
'description' => t('VIEW'),
'fields' => array(
'nid' => array(
'description' => t('TODO: please describe this field!'),
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'uid' => array(
'description' => t('TODO: please describe this field!'),
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'order_count' => array(
'description' => t('TODO: please describe this field!'),
'type' => 'int',
'size' => 'big',
'not null' => TRUE,
'default' => 0,
),
'avg_qty' => array(
'description' => t('TODO: please describe this field!'),
'type' => 'numeric',
'not null' => FALSE,
'precision' => '10',
'scale' => '4',
),
'sum_qty' => array(
'description' => t('TODO: please describe this field!'),
'type' => 'numeric',
'not null' => FALSE,
'precision' => '28',
'scale' => '0',
),
'max_qty' => array(
'description' => t('TODO: please describe this field!'),
'type' => 'int',
'unsigned' => TRUE,
'size' => 'small',
'not null' => FALSE,
),
'min_qty' => array(
'description' => t('TODO: please describe this field!'),
'type' => 'int',
'unsigned' => TRUE,
'size' => 'small',
'not null' => FALSE,
),
),
);
$schema['uc_order_products_qty_vw'] = array(
'description' => t('VIEW'),
'fields' => array(
'nid' => array(
'description' => t('TODO: please describe this field!'),
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'order_count' => array(
'description' => t('TODO: please describe this field!'),
'type' => 'int',
'size' => 'big',
'not null' => TRUE,
'default' => 0,
),
'avg_qty' => array(
'description' => t('TODO: please describe this field!'),
'type' => 'numeric',
'not null' => FALSE,
'precision' => '10',
'scale' => '4',
),
'sum_qty' => array(
'description' => t('TODO: please describe this field!'),
'type' => 'numeric',
'not null' => FALSE,
'precision' => '28',
'scale' => '0',
),
'max_qty' => array(
'description' => t('TODO: please describe this field!'),
'type' => 'int',
'unsigned' => TRUE,
'size' => 'small',
'not null' => FALSE,
),
'min_qty' => array(
'description' => t('TODO: please describe this field!'),
'type' => 'int',
'unsigned' => TRUE,
'size' => 'small',
'not null' => FALSE,
),
),
);
$schema['uc_order_products_pair_vw'] = array(
'description' => t('VIEW'),
'fields' => array(
'nid' => array(
'description' => t('TODO: please describe this field!'),
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'pair_nid' => array(
'description' => t('TODO: please describe this field!'),
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'pair_sum_qty' => array(
'description' => t('TODO: please describe this field!'),
'type' => 'numeric',
'not null' => FALSE,
'precision' => '28',
'scale' => '0',
),
'order_count' => array(
'description' => t('TODO: please describe this field!'),
'type' => 'int',
'size' => 'big',
'not null' => TRUE,
'default' => 0,
),
),
);
return $schema;
}
function uc_views_marketing_install() {
db_query("CREATE VIEW {uc_order_products_qty_vw} (nid,order_count,avg_qty,sum_qty,max_qty,min_qty) AS SELECT op.nid AS nid, COUNT(op.nid) AS order_count,AVG(op.qty) AS avg_qty, SUM(op.qty) AS sum_qty,MAX(op.qty) AS max_qty, MIN(op.qty) AS min_qty FROM {uc_order_products} op GROUP BY op.nid ORDER BY op.nid");
db_query("CREATE VIEW {uc_order_products_user_vw} (nid,uid,order_count,avg_qty,sum_qty,max_qty,min_qty) AS SELECT op.nid AS nid, o.uid AS uid, COUNT(o.order_id) AS order_count, AVG(op.qty) AS avg_qty, SUM(op.qty) AS sum_qty,MAX(op.qty) AS max_qty, MIN(op.qty) AS min_qty FROM {uc_order_products} op, {uc_orders} o where op.order_id =o.order_id GROUP BY o.uid,op.nid ORDER BY o.uid,op.nid");
db_query("CREATE VIEW {uc_order_products_pair_vw} (nid,pair_nid,pair_sum_qty,order_count) AS SELECT op1.nid AS nid, op2.nid AS pair_nid, SUM(op2.qty) AS pair_sum_qty, COUNT(op2.nid) AS order_count FROM {uc_order_products} op1, {uc_order_products} op2 WHERE op1.order_id = op2.order_id AND op1.nid <> op2.nid GROUP BY op1.nid, pair_nid ORDER BY nid, order_count DESC, pair_sum_qty DESC");
}
function uc_views_marketing_uninstall() {
db_query("DROP VIEW {uc_order_products_qty_vw}");
db_query("DROP VIEW {uc_order_products_user_vw}");
db_query("DROP VIEW {uc_order_products_pair_vw}");
}