|
@@ -49,7 +49,7 @@ function tripal_contact_views_api() {
|
|
function tripal_contact_init() {
|
|
function tripal_contact_init() {
|
|
drupal_add_js(drupal_get_path('module', 'tripal_contact') . '/theme/js/tripal_contact.js');
|
|
drupal_add_js(drupal_get_path('module', 'tripal_contact') . '/theme/js/tripal_contact.js');
|
|
drupal_add_css(drupal_get_path('module', 'tripal_contact') . '/theme/css/tripal_contact.css');
|
|
drupal_add_css(drupal_get_path('module', 'tripal_contact') . '/theme/css/tripal_contact.css');
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -87,34 +87,44 @@ function tripal_contact_menu() {
|
|
|
|
|
|
$items = array();
|
|
$items = array();
|
|
|
|
|
|
- $items[ 'admin/tripal/tripal_contact' ]= array(
|
|
|
|
|
|
+ $items['admin/tripal/chado/tripal_contact']= array(
|
|
'title' => 'Contacts',
|
|
'title' => 'Contacts',
|
|
- 'description' => ('A module for interfacing the GMOD chado database with Drupal, providing viewing of contacts'),
|
|
|
|
- 'page callback' => 'theme',
|
|
|
|
- 'page arguments' => array('tripal_contact_admin'),
|
|
|
|
|
|
+ 'description' => ('Model persons, institutes, groups, organizations, etc.'),
|
|
|
|
+ 'page callback' => 'tripal_contact_admin_contact_view',
|
|
'access arguments' => array('administer tripal contacts'),
|
|
'access arguments' => array('administer tripal contacts'),
|
|
'type' => MENU_NORMAL_ITEM
|
|
'type' => MENU_NORMAL_ITEM
|
|
);
|
|
);
|
|
-
|
|
|
|
- $items['admin/tripal/tripal_contact/configuration'] = array(
|
|
|
|
- 'title' => 'Configuration',
|
|
|
|
|
|
+
|
|
|
|
+ $items['admin/tripal/chado/tripal_contact/configuration'] = array(
|
|
|
|
+ 'title' => 'Settings',
|
|
'description' => 'Integration of Chado contacts.',
|
|
'description' => 'Integration of Chado contacts.',
|
|
'page callback' => 'drupal_get_form',
|
|
'page callback' => 'drupal_get_form',
|
|
'page arguments' => array('tripal_contact_admin'),
|
|
'page arguments' => array('tripal_contact_admin'),
|
|
'access arguments' => array('administer tripal contact'),
|
|
'access arguments' => array('administer tripal contact'),
|
|
- 'type' => MENU_NORMAL_ITEM,
|
|
|
|
|
|
+ 'type' => MENU_LOCAL_TASK,
|
|
|
|
+ 'weight' => 5
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ $items['admin/tripal/chado/tripal_contact/help']= array(
|
|
|
|
+ 'title' => 'Help',
|
|
|
|
+ 'description' => ('Help with the contact module.'),
|
|
|
|
+ 'page callback' => 'theme',
|
|
|
|
+ 'page arguments' => array('tripal_contact_help'),
|
|
|
|
+ 'access arguments' => array('administer tripal contacts'),
|
|
|
|
+ 'type' => MENU_LOCAL_TASK,
|
|
|
|
+ 'weight' => 10
|
|
);
|
|
);
|
|
-
|
|
|
|
-
|
|
|
|
- $items['admin/tripal/tripal_contact/sync'] = array(
|
|
|
|
- 'title' => ' Sync Contacts',
|
|
|
|
|
|
+
|
|
|
|
+ $items['admin/tripal/chado/tripal_contact/sync'] = array(
|
|
|
|
+ 'title' => ' Sync',
|
|
'description' => 'Sync contacts in Chado with Drupal',
|
|
'description' => 'Sync contacts in Chado with Drupal',
|
|
'page callback' => 'drupal_get_form',
|
|
'page callback' => 'drupal_get_form',
|
|
'page arguments' => array('tripal_contact_sync_form'),
|
|
'page arguments' => array('tripal_contact_sync_form'),
|
|
'access arguments' => array('administer tripal contacts'),
|
|
'access arguments' => array('administer tripal contacts'),
|
|
- 'type' => MENU_NORMAL_ITEM,
|
|
|
|
|
|
+ 'type' => MENU_LOCAL_TASK,
|
|
|
|
+ 'weight' => 0
|
|
);
|
|
);
|
|
-
|
|
|
|
|
|
+
|
|
// AJAX calls for adding/removing properties to a contact
|
|
// AJAX calls for adding/removing properties to a contact
|
|
$items['tripal_contact/properties/add'] = array(
|
|
$items['tripal_contact/properties/add'] = array(
|
|
'page callback' => 'tripal_contact_property_add',
|
|
'page callback' => 'tripal_contact_property_add',
|
|
@@ -132,10 +142,10 @@ function tripal_contact_menu() {
|
|
'access arguments' => array('edit chado_contact content'),
|
|
'access arguments' => array('edit chado_contact content'),
|
|
'type ' => MENU_CALLBACK,
|
|
'type ' => MENU_CALLBACK,
|
|
);
|
|
);
|
|
-
|
|
|
|
|
|
+
|
|
return $items;
|
|
return $items;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Implements hook_theme(): Register themeing functions for this module
|
|
* Implements hook_theme(): Register themeing functions for this module
|
|
*
|
|
*
|
|
@@ -163,12 +173,12 @@ function tripal_contact_theme() {
|
|
'arguments' => array('node' => NULL),
|
|
'arguments' => array('node' => NULL),
|
|
'template' => 'tripal_contact_publications',
|
|
'template' => 'tripal_contact_publications',
|
|
),
|
|
),
|
|
- 'tripal_contact_admin' => array(
|
|
|
|
- 'template' => 'tripal_contact_admin',
|
|
|
|
- 'arguments' => array(NULL),
|
|
|
|
- 'path' => drupal_get_path('module', 'tripal_contact') . '/theme'
|
|
|
|
|
|
+ 'tripal_contact_help' => array(
|
|
|
|
+ 'template' => 'tripal_contact_help',
|
|
|
|
+ 'arguments' => array(NULL),
|
|
|
|
+ 'path' => drupal_get_path('module', 'tripal_contact') . '/theme'
|
|
),
|
|
),
|
|
-
|
|
|
|
|
|
+
|
|
// Themed Forms
|
|
// Themed Forms
|
|
'chado_contact_node_form' => array(
|
|
'chado_contact_node_form' => array(
|
|
'arguments' => array('form'),
|
|
'arguments' => array('form'),
|
|
@@ -263,7 +273,7 @@ function tripal_contact_permissions() {
|
|
* @param $node
|
|
* @param $node
|
|
* The node on which the operation is to be performed, or, if it does not yet exist, the
|
|
* The node on which the operation is to be performed, or, if it does not yet exist, the
|
|
* type of node to be created
|
|
* type of node to be created
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param $op
|
|
* @param $op
|
|
* The operation to be performed
|
|
* The operation to be performed
|
|
*
|
|
*
|
|
@@ -273,7 +283,7 @@ function tripal_contact_permissions() {
|
|
* @return
|
|
* @return
|
|
* If the permission for the specified operation is not set then return FALSE. If the
|
|
* If the permission for the specified operation is not set then return FALSE. If the
|
|
* permission is set then return NULL as this allows other modules to disable
|
|
* permission is set then return NULL as this allows other modules to disable
|
|
- * access. The only exception is when the $op == 'create'. We will always
|
|
|
|
|
|
+ * access. The only exception is when the $op == 'create'. We will always
|
|
* return TRUE if the permission is set.
|
|
* return TRUE if the permission is set.
|
|
*
|
|
*
|
|
*/
|
|
*/
|
|
@@ -317,8 +327,8 @@ function chado_contact_node_access($node, $op, $account ) {
|
|
*
|
|
*
|
|
*/
|
|
*/
|
|
function chado_contact_insert($node) {
|
|
function chado_contact_insert($node) {
|
|
-
|
|
|
|
- // if a contact_id already exists for this node then it already exists in Chado and
|
|
|
|
|
|
+
|
|
|
|
+ // if a contact_id already exists for this node then it already exists in Chado and
|
|
// we get here because we are syncing the node. Therefore, we can skip the insert
|
|
// we get here because we are syncing the node. Therefore, we can skip the insert
|
|
if ($node->contact_id) {
|
|
if ($node->contact_id) {
|
|
$contact['contact_id'] = $node->contact_id;
|
|
$contact['contact_id'] = $node->contact_id;
|
|
@@ -336,12 +346,12 @@ function chado_contact_insert($node) {
|
|
if (!$contact) {
|
|
if (!$contact) {
|
|
drupal_set_message(t('Could not add the contact'), 'error');
|
|
drupal_set_message(t('Could not add the contact'), 'error');
|
|
watchdog('tripal_contact','Could not add the contact', array(), WATCHDOG_ERROR);
|
|
watchdog('tripal_contact','Could not add the contact', array(), WATCHDOG_ERROR);
|
|
- return FALSE;
|
|
|
|
|
|
+ return FALSE;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
// now add the properties
|
|
// now add the properties
|
|
$properties = array(); // stores all of the properties we need to add
|
|
$properties = array(); // stores all of the properties we need to add
|
|
-
|
|
|
|
|
|
+
|
|
// get the list of properties for easy lookup (without doing lots of database queries
|
|
// get the list of properties for easy lookup (without doing lots of database queries
|
|
$properties_list = array();
|
|
$properties_list = array();
|
|
$sql = "
|
|
$sql = "
|
|
@@ -350,16 +360,16 @@ function chado_contact_insert($node) {
|
|
INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
|
|
INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
|
|
INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
|
|
INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
|
|
INNER JOIN {cv} CV ON CVTO.cv_id = CV.cv_id
|
|
INNER JOIN {cv} CV ON CVTO.cv_id = CV.cv_id
|
|
- WHERE
|
|
|
|
- CV.name = 'tripal_contact' AND
|
|
|
|
- NOT CVTO.name = 'Contact Type'
|
|
|
|
- ORDER BY CVTS.name ASC
|
|
|
|
|
|
+ WHERE
|
|
|
|
+ CV.name = 'tripal_contact' AND
|
|
|
|
+ NOT CVTO.name = 'Contact Type'
|
|
|
|
+ ORDER BY CVTS.name ASC
|
|
";
|
|
";
|
|
$prop_types = chado_query($sql);
|
|
$prop_types = chado_query($sql);
|
|
while ($prop = $prop_types->fetchObject()) {
|
|
while ($prop = $prop_types->fetchObject()) {
|
|
$properties_list[$prop->cvterm_id] = $prop->name;
|
|
$properties_list[$prop->cvterm_id] = $prop->name;
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
// get the properties that should be added. Properties are in one of two forms:
|
|
// get the properties that should be added. Properties are in one of two forms:
|
|
// 1) prop_value-[type id]-[index]
|
|
// 1) prop_value-[type id]-[index]
|
|
// 2) new_value-[type id]-[index]
|
|
// 2) new_value-[type id]-[index]
|
|
@@ -377,11 +387,11 @@ function chado_contact_insert($node) {
|
|
$index = count($properties[$name]);
|
|
$index = count($properties[$name]);
|
|
$name = $properties_list[$type_id];
|
|
$name = $properties_list[$type_id];
|
|
$properties[$name][$index] = trim($node->new_value);
|
|
$properties[$name][$index] = trim($node->new_value);
|
|
- }
|
|
|
|
|
|
+ }
|
|
// now add in the properties
|
|
// now add in the properties
|
|
foreach ($properties as $property => $elements) {
|
|
foreach ($properties as $property => $elements) {
|
|
foreach ($elements as $rank => $value) {
|
|
foreach ($elements as $rank => $value) {
|
|
-
|
|
|
|
|
|
+
|
|
$status = tripal_contact_insert_property($contact['contact_id'], $property, $value, FALSE);
|
|
$status = tripal_contact_insert_property($contact['contact_id'], $property, $value, FALSE);
|
|
if (!$status) {
|
|
if (!$status) {
|
|
drupal_set_message("Error cannot add property: $property", "error");
|
|
drupal_set_message("Error cannot add property: $property", "error");
|
|
@@ -389,16 +399,16 @@ function chado_contact_insert($node) {
|
|
array('%property' => $property), WATCHDOG_ERROR);
|
|
array('%property' => $property), WATCHDOG_ERROR);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
// add the record to the chado_contact table in Drupal
|
|
// add the record to the chado_contact table in Drupal
|
|
- if ($contact) {
|
|
|
|
-
|
|
|
|
|
|
+ if ($contact) {
|
|
|
|
+
|
|
// add the description property
|
|
// add the description property
|
|
tripal_contact_insert_property($contact['contact_id'], 'contact_description',
|
|
tripal_contact_insert_property($contact['contact_id'], 'contact_description',
|
|
$node->description, TRUE);
|
|
$node->description, TRUE);
|
|
-
|
|
|
|
|
|
+
|
|
// make sure the entry for this contact doesn't already exist in the chado_contact table
|
|
// make sure the entry for this contact doesn't already exist in the chado_contact table
|
|
// if it doesn't exist then we want to add it.
|
|
// if it doesn't exist then we want to add it.
|
|
$contact_id = chado_get_id_for_node('contact', $node->nid) ;
|
|
$contact_id = chado_get_id_for_node('contact', $node->nid) ;
|
|
@@ -435,17 +445,17 @@ function chado_contact_update($node) {
|
|
// there is no way to handle revisions in Chado but leave
|
|
// there is no way to handle revisions in Chado but leave
|
|
// this here just to make not we've addressed it.
|
|
// this here just to make not we've addressed it.
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
$contact_id = chado_get_id_for_node('contact', $node->nid) ;
|
|
$contact_id = chado_get_id_for_node('contact', $node->nid) ;
|
|
-
|
|
|
|
- // check to see if this contact name doens't already exists.
|
|
|
|
|
|
+
|
|
|
|
+ // check to see if this contact name doens't already exists.
|
|
$sql = "SELECT contact_id FROM {contact} WHERE NOT contact_id = :contact_id AND name = :name";
|
|
$sql = "SELECT contact_id FROM {contact} WHERE NOT contact_id = :contact_id AND name = :name";
|
|
$contact = chado_query($sql, array(':contact_id' => $contact_id, ':name' => $node->contact_name))->fetchObject();
|
|
$contact = chado_query($sql, array(':contact_id' => $contact_id, ':name' => $node->contact_name))->fetchObject();
|
|
if ($contact) {
|
|
if ($contact) {
|
|
drupal_set_message(t('A contact with this name already exists. Cannot perform update.'), 'warning');
|
|
drupal_set_message(t('A contact with this name already exists. Cannot perform update.'), 'warning');
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
// update the contact record
|
|
// update the contact record
|
|
$match = array(
|
|
$match = array(
|
|
'contact_id' => $contact_id,
|
|
'contact_id' => $contact_id,
|
|
@@ -461,10 +471,10 @@ function chado_contact_update($node) {
|
|
watchdog('t_contact', "Error updating contact", array(), WATCHDOG_ERROR);
|
|
watchdog('t_contact', "Error updating contact", array(), WATCHDOG_ERROR);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
// now update the properties
|
|
// now update the properties
|
|
$properties = array(); // stores all of the properties we need to add
|
|
$properties = array(); // stores all of the properties we need to add
|
|
-
|
|
|
|
|
|
+
|
|
// get the list of properties for easy lookup (without doing lots of database queries
|
|
// get the list of properties for easy lookup (without doing lots of database queries
|
|
$properties_list = array();
|
|
$properties_list = array();
|
|
$sql = "
|
|
$sql = "
|
|
@@ -473,16 +483,16 @@ function chado_contact_update($node) {
|
|
INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
|
|
INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
|
|
INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
|
|
INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
|
|
INNER JOIN {cv} CV ON CVTO.cv_id = CV.cv_id
|
|
INNER JOIN {cv} CV ON CVTO.cv_id = CV.cv_id
|
|
- WHERE
|
|
|
|
- CV.name = 'tripal_contact' AND
|
|
|
|
- NOT CVTO.name = 'Contact Type'
|
|
|
|
- ORDER BY CVTS.name ASC
|
|
|
|
|
|
+ WHERE
|
|
|
|
+ CV.name = 'tripal_contact' AND
|
|
|
|
+ NOT CVTO.name = 'Contact Type'
|
|
|
|
+ ORDER BY CVTS.name ASC
|
|
";
|
|
";
|
|
$prop_types = chado_query($sql);
|
|
$prop_types = chado_query($sql);
|
|
while ($prop = $prop_types->fetchObject()) {
|
|
while ($prop = $prop_types->fetchObject()) {
|
|
$properties_list[$prop->cvterm_id] = $prop->name;
|
|
$properties_list[$prop->cvterm_id] = $prop->name;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
// get the properties that should be added. Properties are in one of three forms:
|
|
// get the properties that should be added. Properties are in one of three forms:
|
|
// 1) prop_value-[type id]-[index]
|
|
// 1) prop_value-[type id]-[index]
|
|
// 2) new_value-[type id]-[index]
|
|
// 2) new_value-[type id]-[index]
|
|
@@ -508,7 +518,7 @@ function chado_contact_update($node) {
|
|
$index = count($properties[$name]);
|
|
$index = count($properties[$name]);
|
|
$properties[$name][$index] = trim($node->new_value);
|
|
$properties[$name][$index] = trim($node->new_value);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
// now add in the properties by first removing any the contact
|
|
// now add in the properties by first removing any the contact
|
|
// already has and adding the ones we have
|
|
// already has and adding the ones we have
|
|
tripal_core_chado_delete('contactprop', array('contact_id' => $contact_id));
|
|
tripal_core_chado_delete('contactprop', array('contact_id' => $contact_id));
|
|
@@ -521,8 +531,8 @@ function chado_contact_update($node) {
|
|
array('%prop' => $property), WATCHDOG_ERROR);
|
|
array('%prop' => $property), WATCHDOG_ERROR);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
tripal_contact_update_property($contact_id, 'contact_description', $node->description, 1);
|
|
tripal_contact_update_property($contact_id, 'contact_description', $node->description, 1);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -547,7 +557,7 @@ function chado_contact_load($node) {
|
|
|
|
|
|
// get the contact description and replace the contact.description field with this one
|
|
// get the contact description and replace the contact.description field with this one
|
|
$values = array(
|
|
$values = array(
|
|
- 'contact_id' => $contact->contact_id,
|
|
|
|
|
|
+ 'contact_id' => $contact->contact_id,
|
|
'type_id' => array(
|
|
'type_id' => array(
|
|
'name' => 'contact_description',
|
|
'name' => 'contact_description',
|
|
),
|
|
),
|
|
@@ -556,12 +566,12 @@ function chado_contact_load($node) {
|
|
'return_array' => 1,
|
|
'return_array' => 1,
|
|
'include_fk' => array('type_id' => 1),
|
|
'include_fk' => array('type_id' => 1),
|
|
);
|
|
);
|
|
- $description = tripal_core_generate_chado_var('contactprop', $values, $options);
|
|
|
|
|
|
+ $description = tripal_core_generate_chado_var('contactprop', $values, $options);
|
|
if (count($description) == 1) {
|
|
if (count($description) == 1) {
|
|
- $description = tripal_core_expand_chado_vars($description, 'field', 'contactprop.value');
|
|
|
|
|
|
+ $description = tripal_core_expand_chado_vars($description, 'field', 'contactprop.value');
|
|
$contact->description = $description[0]->value;
|
|
$contact->description = $description[0]->value;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
|
|
|
|
$additions = new stdClass();
|
|
$additions = new stdClass();
|
|
$additions->contact = $contact;
|
|
$additions->contact = $contact;
|
|
@@ -676,7 +686,7 @@ function tripal_contact_preprocess_tripal_contact_relationships(&$variables) {
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
/*
|
|
- *
|
|
|
|
|
|
+ *
|
|
*/
|
|
*/
|
|
function tripal_contact_form_alter(&$form, &$form_state, $form_id) {
|
|
function tripal_contact_form_alter(&$form, &$form_state, $form_id) {
|
|
if ($form_id == "chado_contact_node_form") {
|
|
if ($form_id == "chado_contact_node_form") {
|