View source
<?php
function views_calc_schema() {
$schema['views_calc_fields'] = array(
'fields' => array(
'cid' => array(
'type' => 'serial',
'not null' => TRUE,
'disp-width' => '10',
),
'label' => array(
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
'default' => '',
),
'format' => array(
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
'default' => '',
),
'custom' => array(
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
'default' => '',
),
'base' => array(
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
'default' => '',
),
'tablelist' => array(
'type' => 'text',
'not null' => TRUE,
),
'fieldlist' => array(
'type' => 'text',
'not null' => TRUE,
),
'calc' => array(
'type' => 'text',
'not null' => TRUE,
),
),
'primary key' => array(
'cid',
),
'indexes' => array(
'cid' => array(
'cid',
),
),
);
return $schema;
}
function views_calc_install() {
drupal_install_schema('views_calc');
}
function views_calc_uninstall() {
db_query("DROP TABLE {views_calc_fields}");
variable_del('views_calc_operators');
}
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;
}
function views_calc_update_6000() {
$ret = array();
db_add_field($ret, 'views_calc_fields', 'base', array(
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
'default' => 'node',
));
return $ret;
}