You are here

function webform_mysql_views_rebuild in Webform MySQL Views 7

Same name and namespace in other branches
  1. 6.2 webform_mysql_views.module \webform_mysql_views_rebuild()
  2. 6 webform_mysql_views.module \webform_mysql_views_rebuild()

Rebuild the view for the specified nid, if any. If $add_new is TRUE, will build a new view even if an existing one is not found.

Parameters

$nid: The node ID of the webform whose view should be rebuilt.

boolean $add_new: Indicates whether or not view should be added if it does not already exist.

2 calls to webform_mysql_views_rebuild()
webform_mysql_views_admin_form_submit in ./webform_mysql_views.admin.inc
Form submission handler for the admin form.
webform_mysql_views_component_submit in ./webform_mysql_views.module
Submit handler for the webform component edit/delete forms.

File

./webform_mysql_views.module, line 94
The Webform MySQL Views module allows you to automatically build flattened MySQL views of submitted Webform module data, for convenient use by external applications.

Code

function webform_mysql_views_rebuild($nid, $add_new = FALSE, $view_name = FALSE) {
  global $db_prefix;
  $views = variable_get('webform_mysql_views_views', array());
  $name = NULL;
  if (empty($views[$nid]) && $add_new) {

    // get a name for the new view
    $node = node_load($nid);
    $name = $view_name ? $view_name : webform_mysql_views_get_view_name($node->title, $nid);
    $views[$nid] = $db_prefix . $name;
    variable_set('webform_mysql_views_views', $views);
  }
  if (array_key_exists($nid, $views)) {

    // Remove the $db_prefix from the view name so we don't wind up with double
    // db_prefixes:
    if ($db_prefix) {
      $name = $view_name ? $view_name : substr($views[$nid], strlen($db_prefix));
    }
    else {
      $name = $view_name ? $view_name : $views[$nid];
    }
    $query = webform_mysql_views_build_query($nid, $name);
    db_query($query);
  }
  return $db_prefix . $name;
}