You are here

uc_views_marketing.install in Ubercart Views 6.2

Same filename and directory in other branches
  1. 6.3 uc_views_marketing/uc_views_marketing.install

File

uc_views_marketing/uc_views_marketing.install
View source
<?php

/**
 * Implentation of the hook_install().
 */
function uc_views_marketing_install() {

  //Create db views to make agregations on UC tables
  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 `nid`, `pair_nid`  ORDER BY `nid`, `order_count` DESC, `pair_sum_qty` DESC");
}

/**
 * Implentation of the hook_uninstall().
 */
function uc_views_marketing_uninstall() {

  //Remove views created during install
  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}");
}

Functions

Namesort descending Description
uc_views_marketing_install Implentation of the hook_install().
uc_views_marketing_uninstall Implentation of the hook_uninstall().