function webform_mysql_views_get_view_name in Webform MySQL Views 6
Same name and namespace in other branches
- 6.2 webform_mysql_views.module \webform_mysql_views_get_view_name()
- 7 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.
1 call to webform_mysql_views_get_view_name()
- 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 381 - 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));
// Remove multiple concurrent underscores to tidy up the name.
$title = preg_replace('/__+/', '_', $title);
$title = 'webform_views_' . preg_replace('/[^a-z0-9_]/', '', $title);
// Limit the title to the maximum allowed table name length in MySQL.
$title = substr($title, 0, WEBFORM_MYSQL_VIEWS_MAXSIZE);
$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.
$view_exists = db_result(db_query("SELECT COUNT(table_name) AS view_exists FROM information_schema.views where table_schema = '%s' AND table_name = '%s%s'", $db_name, $db_prefix, $title));
if (!empty($view_exists)) {
$title = substr($title, 0, WEBFORM_MYSQL_VIEWS_MAXSIZE - strlen($nid) - 1) . '_' . $nid;
}
return $title;
}