function webform_mysql_views_get_view_name in Webform MySQL Views 7
Same name and namespace in other branches
- 6.2 webform_mysql_views.module \webform_mysql_views_get_view_name()
- 6 webform_mysql_views.module \webform_mysql_views_get_view_name()
Get a unique view name from a given string and node ID.
Parameters
$title: The string from which to build the view name.
$nid: The node ID from which to build the view name.
2 calls to webform_mysql_views_get_view_name()
- webform_mysql_views_admin_form in ./
webform_mysql_views.admin.inc - Form builder for the Webform MySQL Views admin form.
- webform_mysql_views_rebuild in ./
webform_mysql_views.module - 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.
File
- ./
webform_mysql_views.module, line 228 - 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_get_view_name($title, $nid) {
global $db_url, $db_prefix;
// Discard non-alphanumeric chars
$title = strtolower(str_replace(' ', '_', $title));
$title = 'webform_views_' . preg_replace('/[^a-z0-9_]/', '', $title);
// Limit the title to the supported 64 character limit.
$title = substr($title, 0, 63 - strlen($nid));
$db_name = substr(parse_url($db_url, PHP_URL_PATH), 1);
// Check whether the default view name is already being used
// (For example duplicate node titles). Append $nid if necessary to ensure
// uniqueness. Table names not escaped as they are not a part of the Drupal DB.
$query = "SELECT COUNT(table_name) AS view_exists FROM information_schema.views where table_schema = '" . $db_name . "' AND table_name = '" . $db_prefix . $title . "'";
$view_exists = db_query($query)
->fetchField();
if ($view_exists) {
return $title . '_' . $nid;
}
return $title;
}