You are here

function views_calc_update_1 in Views Calc 6

Same name and namespace in other branches
  1. 5 views_calc.install \views_calc_update_1()
  2. 6.3 views_calc.install \views_calc_update_1()

Convert the queryname stored in the variable to the fullname so we can access both the fieldname and the tablename from the selections.

Change the calc 'AVERAGE' to 'AVG' to match the db function.

File

./views_calc.install, line 41

Code

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;
}