View source
<?php
function views_calc_install() {
global $db_type;
switch ($db_type) {
case 'mysql':
case 'mysqli':
$ret[] = db_query("CREATE TABLE if not exists {views_calc_fields} (\n cid int(10) unsigned NOT NULL default '0',\n label varchar(255),\n format varchar(255),\n custom varchar(255),\n tablelist text,\n fieldlist text,\n calc text,\n KEY (cid)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */");
break;
case 'postgres':
$ret[] = db_query("CREATE TABLE if not exists {views_calc_fields} (\n cid int(10) unsigned NOT NULL default '0',\n label varchar(255),\n format varchar(255),\n custom varchar(255),\n tablelist text,\n fieldlist text,\n calc text,\n KEY (cid)\n ) ");
break;
}
}
function views_calc_uninstall() {
$view_calcs = (array) variable_get('views_calc_vid', '');
foreach ($view_calcs as $view_id) {
variable_del('views_calc_' . $view_id . '_col');
variable_del('views_calc_' . $view_id . '_col_calc');
variable_del('views_calc_' . $view_id . '_row');
variable_del('views_calc_' . $view_id . '_row_calc');
}
variable_del('views_calc_vid');
variable_del('views_calc_operators');
db_query("DROP TABLE {views_calc_fields}");
}
function views_calc_update_1() {
$ret = array();
include_once drupal_get_path('module', 'views') . '/views.module';
include_once drupal_get_path('module', 'views_calc') . '/views_calc.module';
$view_calcs = (array) variable_get('views_calc_vid', '');
foreach ($view_calcs as $view_id) {
if ($view = views_get_view($view_id)) {
$cols = (array) variable_get('views_calc_' . $view->vid . '_col', '');
$new_cols = array();
foreach ($cols as $col) {
foreach ($view->field as $field) {
if ($field['queryname'] == $col) {
$new_cols[] = $field['fullname'];
}
}
}
variable_set('views_calc_' . $view->vid . '_col', $new_cols);
$rows = (array) variable_get('views_calc_' . $view->vid . '_row', '');
$new_rows = array();
foreach ($rows as $row) {
foreach ($view->field as $field) {
if ($field['queryname'] == $col) {
$new_rows[] = $field['fullname'];
}
}
}
variable_set('views_calc_' . $view->vid . '_row', $new_rows);
$col_calc = (array) variable_get('views_calc_' . $view->vid . '_col_calc', '');
foreach ($col_calc as $calc) {
if ($calc == 'AVERAGE') {
$new_calcs[] = 'AVG';
}
else {
$new_calcs[] = $calc;
}
}
variable_set('views_calc_' . $view->vid . '_col_calc', $new_calcs);
$row_calc = (array) variable_get('views_calc_' . $view->vid . '_row_calc', '');
foreach ($row_calc as $calc) {
if ($calc == 'AVERAGE') {
$new_calcs[] = 'AVG';
}
else {
$new_calcs[] = $calc;
}
}
variable_set('views_calc_' . $view->vid . '_row_calc', $new_calcs);
}
}
return $ret;
}
function views_calc_update_2() {
$ret = array();
global $db_type;
switch ($db_type) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("CREATE TABLE if not exists {views_calc_fields} (\n cid int(10) unsigned NOT NULL default '0',\n label varchar(255),\n format varchar(255),\n custom varchar(255),\n tablelist text,\n fieldlist text,\n calc text,\n KEY (cid)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */");
break;
case 'postgres':
$ret[] = update_sql("CREATE TABLE if not exists {views_calc_fields} (\n cid int(10) unsigned NOT NULL default '0',\n label varchar(255),\n format varchar(255),\n custom varchar(255),\n tablelist text,\n fieldlist text,\n calc text,\n KEY (cid)\n ) ");
break;
}
return $ret;
}