123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618 |
- <?php
- require('api/tripal_contact.api.inc');
- require('includes/contact_sync.inc');
- require('includes/tripal_contact.admin.inc');
- require('includes/tripal_contact.form.inc');
- function tripal_contact_views_api() {
- return array(
- 'api' => 2.0,
- );
- }
- function tripal_contact_init() {
- drupal_add_css(drupal_get_path('theme', 'tripal') . '/css/tripal_contact.css');
- }
- function tripal_contact_node_info() {
- return array(
- 'chado_contact' => array(
- 'name' => t('Contact'),
- 'module' => 'chado_contact',
- 'description' => t('A contact from the Chado database'),
- 'title_label' => t('Article Title'),
- 'body_label' => t('Abstract'),
- 'has_title' => TRUE,
- 'has_body' => FALSE,
- ),
- );
- }
- function tripal_contact_menu() {
- $items = array();
- $items[ 'admin/tripal/tripal_contact' ]= array(
- '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'),
- 'access arguments' => array('administer tripal contacts'),
- 'type' => MENU_NORMAL_ITEM
- );
-
- $items['admin/tripal/tripal_contact/configuration'] = array(
- 'title' => 'Configuration',
- 'description' => 'Integration of Chado contacts.',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_contact_admin'),
- 'access arguments' => array('administer tripal contact'),
- 'type' => MENU_NORMAL_ITEM,
- );
-
-
- $items['admin/tripal/tripal_contact/sync'] = array(
- 'title' => ' Sync Contacts',
- 'description' => 'Sync contacts in Chado with Drupal',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_contact_sync_form'),
- 'access arguments' => array('administer tripal contacts'),
- 'type' => MENU_NORMAL_ITEM,
- );
-
-
- $items['tripal_contact/properties/add'] = array(
- 'page callback' => 'tripal_contact_property_add',
- 'access arguments' => array('edit chado_contact content'),
- 'type ' => MENU_CALLBACK,
- );
- $items['tripal_contact/properties/description'] = array(
- 'page callback' => 'tripal_contact_property_get_description',
- 'access arguments' => array('edit chado_contact content'),
- 'type ' => MENU_CALLBACK,
- );
- $items['tripal_contact/properties/minus/%/%'] = array(
- 'page callback' => 'tripal_contact_property_delete',
- 'page arguments' => array(3, 4),
- 'access arguments' => array('edit chado_contact content'),
- 'type ' => MENU_CALLBACK,
- );
-
- return $items;
- }
-
- function tripal_contact_theme() {
- return array(
- 'tripal_contact_base' => array(
- 'arguments' => array('node' => NULL),
- ),
- 'tripal_contact_properties' => array(
- 'arguments' => array('node' => NULL)
- ),
- 'tripal_contact_relationships' => array(
- 'arguments' => array('node' => NULL)
- ),
- 'tripal_contact_publications' => array(
- 'arguments' => array('node' => NULL)
- ),
- 'tripal_contact_admin' => array(
- 'template' => 'tripal_contact_admin',
- 'arguments' => array(NULL),
- 'path' => drupal_get_path('module', 'tripal_contact') . '/theme'
- ),
-
-
- 'chado_contact_node_form' => array(
- 'arguments' => array('form'),
- ),
- );
- }
- function tripal_contact_perm() {
- return array(
- 'access chado_contact content',
- 'create chado_contact content',
- 'delete chado_contact content',
- 'edit chado_contact content',
- 'administer tripal contacts',
- );
- }
- function chado_contact_access($op, $node, $account ) {
- if ($op == 'create') {
- if (!user_access('create chado_contact content', $account)) {
- return FALSE;
- }
- return TRUE;
- }
- if ($op == 'update') {
- if (!user_access('edit chado_contact content', $account)) {
- return FALSE;
- }
- }
- if ($op == 'delete') {
- if (!user_access('delete chado_contact content', $account)) {
- return FALSE;
- }
- }
- if ($op == 'view') {
- if (!user_access('access chado_contact content', $account)) {
- return FALSE;
- }
- }
- return NULL;
- }
- function chado_contact_insert($node) {
-
-
-
- if ($node->contact_id) {
- $contact['contact_id'] = $node->contact_id;
- }
- else {
-
-
- $values = array(
- 'name' => $node->title,
- 'description' => '',
- 'type_id' => $node->type_id
- );
- $options = array('statement_name' => 'ins_contact_nadety');
- $contact = tripal_core_chado_insert('contact', $values, $options);
- if (!$contact) {
- drupal_set_message(t('Could not add the contact'), 'error');
- watchdog('tripal_contact','Could not add the contact', array(), WATCHDOG_ERROR);
- return FALSE;
- }
-
-
- $properties = array();
-
-
- $properties_list = array();
- $sql = "
- SELECT CVTS.cvterm_id, CVTS.name
- FROM {cvtermpath} CVTP
- INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
- INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_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
- ";
- $prop_types = chado_query($sql);
- while ($prop = db_fetch_object($prop_types)) {
- $properties_list[$prop->cvterm_id] = $prop->name;
- }
-
-
-
-
-
- foreach ($node as $name => $value) {
- if (preg_match('/^new_value-(\d+)-(\d+)/', $name, $matches)) {
- $type_id = $matches[1];
- $index = $matches[2];
- $name = $properties_list[$type_id];
- $properties[$name][$index] = trim($value);
- }
- }
- if ($node->new_id and $node->new_value) {
- $type_id = $node->new_id;
- $index = count($properties[$name]);
- $name = $properties_list[$type_id];
- $properties[$name][$index] = trim($node->new_value);
- }
-
- foreach ($properties as $property => $elements) {
- foreach ($elements as $rank => $value) {
-
- $status = tripal_contact_insert_property($contact['contact_id'], $property, $value, FALSE);
- if (!$status) {
- drupal_set_message("Error cannot add property: $property", "error");
- watchdog('t_contact', "Error cannot add property: %prop",
- array('%property' => $property), WATCHDOG_ERROR);
- }
- }
- }
- }
-
- if ($contact) {
-
-
- tripal_contact_insert_property($contact['contact_id'], 'contact_description',
- $node->description, TRUE);
-
-
-
- $contact_id = chado_get_id_for_node('contact', $node->nid) ;
- if (!$contact_id) {
-
- $sql = "INSERT INTO {chado_contact} (nid, vid, contact_id) ".
- "VALUES (%d, %d, %d)";
- db_query($sql, $node->nid, $node->vid, $contact['contact_id']);
- }
- }
- else {
- drupal_set_message(t('Unable to add contact.', 'warning'));
- watchdog('tripal_contact', 'Insert contact: Unable to create contact where values: %values',
- array('%values' => print_r($values, TRUE)), WATCHDOG_WARNING);
- }
- return TRUE;
- }
- function chado_contact_update($node) {
- if ($node->revision) {
-
-
- }
-
- $contact_id = chado_get_id_for_node('contact', $node->nid) ;
-
-
- $sql = "SELECT contact_id FROM {contact} WHERE NOT contact_id = %d AND name = '%s'";
- $contact = db_fetch_object(chado_query($sql, $contact_id, $node->contact_name));
- if ($contact) {
- drupal_set_message(t('A contact with this name already exists. Cannot perform update.'), 'warning');
- return;
- }
-
-
- $match = array(
- 'contact_id' => $contact_id,
- );
- $values = array(
- 'name' => $node->title,
- 'description' => '',
- 'type_id' => $node->type_id
- );
- $status = tripal_core_chado_update('contact', $match, $values);
- if (!$status) {
- drupal_set_message("Error updating contact", "error");
- watchdog('t_contact', "Error updating contact", array(), WATCHDOG_ERROR);
- return;
- }
-
-
- $properties = array();
-
-
- $properties_list = array();
- $sql = "
- SELECT CVTS.cvterm_id, CVTS.name
- FROM {cvtermpath} CVTP
- INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
- INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_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
- ";
- $prop_types = chado_query($sql);
- while ($prop = db_fetch_object($prop_types)) {
- $properties_list[$prop->cvterm_id] = $prop->name;
- }
-
-
-
-
-
-
- foreach ($node as $key => $value) {
- if (preg_match('/^prop_value-(\d+)-(\d+)/', $key, $matches)) {
- $type_id = $matches[1];
- $index = $matches[2];
- $name = $properties_list[$type_id];
- $properties[$name][$index] = trim($value);
- }
- if (preg_match('/^new_value-(\d+)-(\d+)/', $key, $matches)) {
- $type_id = $matches[1];
- $index = $matches[2];
- $name = $properties_list[$type_id];
- $properties[$name][$index] = trim($value);
- }
- }
- if ($node->new_id and $node->new_value) {
- $type_id = $node->new_id;
- $name = $properties_list[$type_id];
- $index = count($properties[$name]);
- $properties[$name][$index] = trim($node->new_value);
- }
-
-
-
- tripal_core_chado_delete('contactprop', array('contact_id' => $contact_id));
- foreach ($properties as $property => $elements) {
- foreach ($elements as $rank => $value) {
- $status = tripal_contact_insert_property($contact_id, $property, $value, FALSE);
- if (!$status) {
- drupal_set_message("Error cannot add property: '$property'", "error");
- watchdog('t_contact', "Error cannot add property: '%prop'",
- array('%prop' => $property), WATCHDOG_ERROR);
- }
- }
- }
-
- tripal_contact_update_property($contact_id, 'contact_description', $node->description, 1);
- }
- function chado_contact_load($node) {
-
- $contact_id = chado_get_id_for_node('contact', $node->nid);
- $values = array('contact_id' => $contact_id);
- $contact = tripal_core_generate_chado_var('contact', $values);
-
- $values = array(
- 'contact_id' => $contact->contact_id,
- 'type_id' => array(
- 'name' => 'contact_description',
- ),
- );
- $options = array(
- 'return_array' => 1,
- 'include_fk' => array('type_id' => 1),
- );
- $description = tripal_core_generate_chado_var('contactprop', $values, $options);
- if (count($description) == 1) {
- $description = tripal_core_expand_chado_vars($description, 'field', 'contactprop.value');
- $contact->description = $description[0]->value;
- }
-
- $additions = new stdClass();
- $additions->contact = $contact;
- return $additions;
- }
- function chado_contact_delete(&$node) {
- $contact_id = chado_get_id_for_node('contact', $node->nid);
-
-
- if (!$contact_id) {
- return;
- }
-
-
- $sql_del = "DELETE FROM {chado_contact} ".
- "WHERE nid = %d ".
- "AND vid = %d";
- db_query($sql_del, $node->nid, $node->vid);
- $sql_del = "DELETE FROM {node_revisions} ".
- "WHERE nid = %d ".
- "AND vid = %d";
- db_query($sql_del, $node->nid, $node->vid);
- $sql_del = "DELETE FROM {node} ".
- "WHERE nid = %d ".
- "AND vid = %d";
- db_query($sql_del, $node->nid, $node->vid);
-
- chado_query("DELETE FROM {contactprop} WHERE contact_id = %d", $contact_id);
- chado_query("DELETE FROM {contact} WHERE contact_id = %d", $contact_id);
- }
- function tripal_contact_preprocess_tripal_contact_relationships(&$variables) {
-
- $contact = $variables['node']->contact;
-
-
-
-
- $sql = "
- SELECT C.name, C.contact_id, CP.nid, CVT.name as rel_type
- FROM contact_relationship PR
- INNER JOIN {contact} C ON PR.object_id = C.contact_id
- INNER JOIN {cvterm} CVT ON PR.type_id = CVT.cvterm_id
- LEFT JOIN public.chado_contact CP ON C.contact_id = CP.contact_id
- WHERE PR.subject_id = %d
- ";
- $as_subject = chado_query($sql, $contact->contact_id);
- $sql = "
- SELECT C.name, C.contact_id, CP.nid, CVT.name as rel_type
- FROM contact_relationship PR
- INNER JOIN {contact} C ON PR.subject_id = C.contact_id
- INNER JOIN {cvterm} CVT ON PR.type_id = CVT.cvterm_id
- LEFT JOIN public.chado_contact CP ON C.contact_id = CP.contact_id
- WHERE PR.object_id = %d
- ";
- $as_object = chado_query($sql, $contact->contact_id);
-
- $relationships = array();
- $relationships['object'] = array();
- $relationships['subject'] = array();
-
- while ($relationship = db_fetch_object($as_object)) {
-
- $rel_type = t(preg_replace('/_/', " ", $relationship->rel_type));
- $sub_type = t(preg_replace('/_/', " ", $relationship->sub_type));
- if (!array_key_exists($rel_type, $relationships['object'])) {
- $relationships['object'][$rel_type] = array();
- }
- if (!array_key_exists($sub_type, $relationships['object'][$rel_type])) {
- $relationships['object'][$rel_type][$sub_type] = array();
- }
- $relationships['object'][$rel_type][$sub_type][] = $relationship;
- }
-
- while ($relationship = db_fetch_object($as_subject)) {
-
- $rel_type = t(preg_replace('/_/', " ", $relationship->rel_type));
- $obj_type = t(preg_replace('/_/', " ", $relationship->obj_type));
- if (!array_key_exists($rel_type, $relationships['subject'])) {
- $relationships['subject'][$rel_type] = array();
- }
- if (!array_key_exists($obj_type, $relationships['subject'][$rel_type])) {
- $relationships['subject'][$rel_type][$obj_type] = array();
- }
- $relationships['subject'][$rel_type][$obj_type][] = $relationship;
- }
- $contact->all_relationships = $relationships;
- }
- function tripal_contact_form_alter(&$form, &$form_state, $form_id) {
- if ($form_id == "chado_contact_node_form") {
- }
- }
|