function tripal_add_site
3.x tripal_ws.api.inc | tripal_add_site($name, $url, $version, $description) |
Adds a new site to the web services table.
Parameters
$name: Name of site to be included.
$url: URL of site to be added.
$version: Version of the API being used. default to 1
$description: A description of the site and any additional info that would be helpful for admins.
Return value
TRUE if the site is successfully added, FALSE otherwise.
Related topics
File
- tripal_ws/
api/ tripal_ws.api.inc, line 130 - This file provides the Tripal Web Services API: a set of functions for interacting with the Tripal Web Services.
Code
function tripal_add_site($name, $url, $version, $description) {
$check_url = NULL;
$check_name = NULL;
$write_to_db = TRUE;
// When inserting a record.
$check_url =
db_select('tripal_sites', 'ts')
->fields('ts', array('id'))
->condition('url', $url)
->condition('version', $version)
->execute()
->fetchField();
$check_name =
db_select('tripal_sites', 'ts')
->fields('ts', array('id'))
->condition('name', $name)
->execute()
->fetchField();
if ($check_url) {
drupal_set_message(t('The URL and version is used by another site.'), 'error');
$write_to_db = FALSE;
}
if ($check_name) {
drupal_set_message(t('The name is used by another site.'), 'error');
$write_to_db = FALSE;
}
if ($write_to_db === TRUE) {
db_insert('tripal_sites')
->fields(array(
'name' => $name,
'url' => $url,
'version' => $version,
'description' => $description
))
->execute();
drupal_set_message(t('Tripal site \'' . $name . '\' has been added.'));
return $write_to_db;
}
return $write_to_db;
}