tripal_contact.module 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. <?php
  2. /**
  3. * @file
  4. * This file contains the basic functions needed for this drupal module.
  5. * The drupal tripal_contact module maps directly to the chado X module.
  6. *
  7. * For documentation regarding the Chado X module:
  8. * @see http://gmod.org/wiki/Chado_General_Module
  9. */
  10. require('api/tripal_contact.api.inc');
  11. require('includes/contact_sync.inc');
  12. require('includes/tripal_contact.admin.inc');
  13. require('includes/tripal_contact.form.inc');
  14. /**
  15. * @defgroup tripal_contact Contact Module
  16. * @ingroup tripal_modules
  17. * @{
  18. * Currently this module only provides support for integration with Drupal
  19. * views and some support for querying using the Tripal Core API.
  20. *
  21. * This module needs further development to support full management of
  22. * contact information within Chado, and full definitions for foreign
  23. * key relationships in Chado.
  24. * @}
  25. */
  26. /*************************************************************************
  27. * Implements hook_views_api()
  28. * Purpose: Essentially this hook tells drupal that there is views support for
  29. * for this module which then includes tripal_contact.views.inc where all the
  30. * views integration code is
  31. *
  32. * @ingroup tripal_contact
  33. */
  34. function tripal_contact_views_api() {
  35. return array(
  36. 'api' => 2.0,
  37. );
  38. }
  39. /**
  40. *
  41. * @ingroup tripal_contact
  42. */
  43. function tripal_contact_init() {
  44. drupal_add_css(drupal_get_path('theme', 'tripal') . '/css/tripal_contact.css');
  45. }
  46. /**
  47. * Implementation of hook_tripal_contact_node_info().
  48. *
  49. * This node_info, is a simple node that describes the functionallity of the module.
  50. *
  51. */
  52. function tripal_contact_node_info() {
  53. return array(
  54. 'chado_contact' => array(
  55. 'name' => t('Contact'),
  56. 'base' => 'chado_contact',
  57. 'description' => t('A contact from the Chado database'),
  58. 'title_label' => t('Article Title'),
  59. 'body_label' => t('Abstract'),
  60. 'has_title' => TRUE,
  61. 'has_body' => FALSE,
  62. ),
  63. );
  64. }
  65. /**
  66. * Tripal-contact-Menu
  67. *
  68. * Implemets hook_menu(): Adds menu items for the tripal_contact module menu. This section
  69. * gives the outline for the main menu of the Tripal-contact module
  70. *
  71. * @return
  72. * An array of menu items that is visible within the Drupal Menu, returned as soon
  73. * as the program is ran
  74. */
  75. function tripal_contact_menu() {
  76. $items = array();
  77. $items[ 'admin/tripal/tripal_contact' ]= array(
  78. 'title' => 'Contacts',
  79. 'description' => ('A module for interfacing the GMOD chado database with Drupal, providing viewing of contacts'),
  80. 'page callback' => 'theme',
  81. 'page arguments' => array('tripal_contact_admin'),
  82. 'access arguments' => array('administer tripal contacts'),
  83. 'type' => MENU_NORMAL_ITEM
  84. );
  85. $items['admin/tripal/tripal_contact/configuration'] = array(
  86. 'title' => 'Configuration',
  87. 'description' => 'Integration of Chado contacts.',
  88. 'page callback' => 'drupal_get_form',
  89. 'page arguments' => array('tripal_contact_admin'),
  90. 'access arguments' => array('administer tripal contact'),
  91. 'type' => MENU_NORMAL_ITEM,
  92. );
  93. $items['admin/tripal/tripal_contact/sync'] = array(
  94. 'title' => ' Sync Contacts',
  95. 'description' => 'Sync contacts in Chado with Drupal',
  96. 'page callback' => 'drupal_get_form',
  97. 'page arguments' => array('tripal_contact_sync_form'),
  98. 'access arguments' => array('administer tripal contacts'),
  99. 'type' => MENU_NORMAL_ITEM,
  100. );
  101. // AJAX calls for adding/removing properties to a contact
  102. $items['tripal_contact/properties/add'] = array(
  103. 'page callback' => 'tripal_contact_property_add',
  104. 'access arguments' => array('edit chado_contact content'),
  105. 'type ' => MENU_CALLBACK,
  106. );
  107. $items['tripal_contact/properties/description'] = array(
  108. 'page callback' => 'tripal_contact_property_get_description',
  109. 'access arguments' => array('edit chado_contact content'),
  110. 'type ' => MENU_CALLBACK,
  111. );
  112. $items['tripal_contact/properties/minus/%/%'] = array(
  113. 'page callback' => 'tripal_contact_property_delete',
  114. 'page arguments' => array(3, 4),
  115. 'access arguments' => array('edit chado_contact content'),
  116. 'type ' => MENU_CALLBACK,
  117. );
  118. return $items;
  119. }
  120. /**
  121. * Implements hook_theme(): Register themeing functions for this module
  122. *
  123. *
  124. * @return
  125. * An array of themeing functions to register
  126. *
  127. */
  128. function tripal_contact_theme() {
  129. return array(
  130. 'tripal_contact_base' => array(
  131. 'arguments' => array('node' => NULL),
  132. 'template' => 'tripal_contact_base',
  133. ),
  134. 'tripal_contact_properties' => array(
  135. 'arguments' => array('node' => NULL),
  136. 'template' => 'tripal_contact_properties',
  137. ),
  138. 'tripal_contact_relationships' => array(
  139. 'arguments' => array('node' => NULL),
  140. 'template' => 'tripal_contact_relationships',
  141. ),
  142. 'tripal_contact_publications' => array(
  143. 'arguments' => array('node' => NULL),
  144. 'template' => 'tripal_contact_publications',
  145. ),
  146. 'tripal_contact_admin' => array(
  147. 'template' => 'tripal_contact_admin',
  148. 'arguments' => array(NULL),
  149. 'path' => drupal_get_path('module', 'tripal_contact') . '/theme'
  150. ),
  151. // Themed Forms
  152. 'chado_contact_node_form' => array(
  153. 'arguments' => array('form'),
  154. ),
  155. );
  156. }
  157. /**
  158. * @ingroup tripal_library
  159. */
  160. function tripal_contact_block_info() {
  161. $blocks['contbase']['info'] = t('Tripal Contact Details');
  162. $blocks['contbase']['cache'] = BLOCK_NO_CACHE;
  163. $blocks['contprops']['info'] = t('Tripal Contact Properties');
  164. $blocks['contprops']['cache'] = BLOCK_NO_CACHE;
  165. $blocks['contrels']['info'] = t('Tripal Contact Relationships');
  166. $blocks['contrels']['cache'] = BLOCK_NO_CACHE;
  167. $blocks['contpubs']['info'] = t('Tripal Cotact Publications');
  168. $blocks['contpubs']['cache'] = BLOCK_NO_CACHE;
  169. return $blocks;
  170. }
  171. /**
  172. * @ingroup tripal_library
  173. */
  174. function tripal_contact_block_view($delta = '') {
  175. if (user_access('access chado_library content') and arg(0) == 'node' and is_numeric(arg(1))) {
  176. $nid = arg(1);
  177. $node = node_load($nid);
  178. $block = array();
  179. switch ($delta) {
  180. case 'contbase':
  181. $block['subject'] = t('Details');
  182. $block['content'] = theme('tripal_contact_base', $node);
  183. break;
  184. case 'contprops':
  185. $block['subject'] = t('Properties');
  186. $block['content'] = theme('tripal_contact_properties', $node);
  187. break;
  188. case 'contrels':
  189. $block['subject'] = t('Relationships');
  190. $block['content'] = theme('tripal_contact_relationships', $node);
  191. break;
  192. case 'contpubs':
  193. $block['subject'] = t('Publications');
  194. $block['content'] = theme('tripal_contact_publications', $node);
  195. break;
  196. default :
  197. }
  198. return $block;
  199. }
  200. }
  201. /**
  202. * Implement hook_perm().
  203. */
  204. function tripal_contact_permissions() {
  205. return array(
  206. 'access chado_contact content' => array(
  207. 'title' => t('View Contacts'),
  208. 'description' => t('Allow users to view contact pages.'),
  209. ),
  210. 'create chado_contact content' => array(
  211. 'title' => t('Create Contacts'),
  212. 'description' => t('Allow users to create new contact pages.'),
  213. ),
  214. 'delete chado_contact content' => array(
  215. 'title' => t('Delete Contacts'),
  216. 'description' => t('Allow users to delete contact pages.'),
  217. ),
  218. 'edit chado_contact content' => array(
  219. 'title' => t('Edit Contacts'),
  220. 'description' => t('Allow users to edit contact pages.'),
  221. ),
  222. 'adminster tripal contact' => array(
  223. 'title' => t('Administer Contacts'),
  224. 'description' => t('Allow users to administer all contacts.'),
  225. ),
  226. );
  227. }
  228. /**
  229. * Implement hook_access().
  230. *
  231. * This hook allows node modules to limit access to the node types they define.
  232. *
  233. * @param $node
  234. * The node on which the operation is to be performed, or, if it does not yet exist, the
  235. * type of node to be created
  236. *
  237. * @param $op
  238. * The operation to be performed
  239. *
  240. * @param $account
  241. * A user object representing the user for whom the operation is to be performed
  242. *
  243. * @return
  244. * If the permission for the specified operation is not set then return FALSE. If the
  245. * permission is set then return NULL as this allows other modules to disable
  246. * access. The only exception is when the $op == 'create'. We will always
  247. * return TRUE if the permission is set.
  248. *
  249. */
  250. function chado_contact_node_access($node, $op, $account ) {
  251. if ($op == 'create') {
  252. if (!user_access('create chado_contact content', $account)) {
  253. return FALSE;
  254. }
  255. return TRUE;
  256. }
  257. if ($op == 'update') {
  258. if (!user_access('edit chado_contact content', $account)) {
  259. return FALSE;
  260. }
  261. }
  262. if ($op == 'delete') {
  263. if (!user_access('delete chado_contact content', $account)) {
  264. return FALSE;
  265. }
  266. }
  267. if ($op == 'view') {
  268. if (!user_access('access chado_contact content', $account)) {
  269. return FALSE;
  270. }
  271. }
  272. return NULL;
  273. }
  274. /**
  275. * Implementation of tripal_contact_insert().
  276. *
  277. * This function inserts user entered information pertaining to the contact instance into the
  278. * 'contactauthor', 'contactprop', 'chado_contact', 'contact' talble of the database.
  279. *
  280. * @parm $node
  281. * Then node which contains the information stored within the node-ID
  282. *
  283. *
  284. */
  285. function chado_contact_insert($node) {
  286. // if a contact_id already exists for this node then it already exists in Chado and
  287. // we get here because we are syncing the node. Therefore, we can skip the insert
  288. if ($node->contact_id) {
  289. $contact['contact_id'] = $node->contact_id;
  290. }
  291. else {
  292. // we don't want to store the description in the description field as it may be longer than
  293. // 255 characters, so we'll use a property to store this value.
  294. $values = array(
  295. 'name' => $node->title,
  296. 'description' => '',
  297. 'type_id' => $node->type_id
  298. );
  299. $options = array('statement_name' => 'ins_contact_nadety');
  300. $contact = tripal_core_chado_insert('contact', $values, $options);
  301. if (!$contact) {
  302. drupal_set_message(t('Could not add the contact'), 'error');
  303. watchdog('tripal_contact','Could not add the contact', array(), WATCHDOG_ERROR);
  304. return FALSE;
  305. }
  306. // now add the properties
  307. $properties = array(); // stores all of the properties we need to add
  308. // get the list of properties for easy lookup (without doing lots of database queries
  309. $properties_list = array();
  310. $sql = "
  311. SELECT CVTS.cvterm_id, CVTS.name
  312. FROM {cvtermpath} CVTP
  313. INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
  314. INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
  315. INNER JOIN {cv} CV ON CVTO.cv_id = CV.cv_id
  316. WHERE
  317. CV.name = 'tripal_contact' AND
  318. NOT CVTO.name = 'Contact Type'
  319. ORDER BY CVTS.name ASC
  320. ";
  321. $prop_types = chado_query($sql);
  322. while ($prop = $prop_types->fetchObject()) {
  323. $properties_list[$prop->cvterm_id] = $prop->name;
  324. }
  325. // get the properties that should be added. Properties are in one of two forms:
  326. // 1) prop_value-[type id]-[index]
  327. // 2) new_value-[type id]-[index]
  328. // 3) new_id, new_value
  329. foreach ($node as $name => $value) {
  330. if (preg_match('/^new_value-(\d+)-(\d+)/', $name, $matches)) {
  331. $type_id = $matches[1];
  332. $index = $matches[2];
  333. $name = $properties_list[$type_id];
  334. $properties[$name][$index] = trim($value);
  335. }
  336. }
  337. if ($node->new_id and $node->new_value) {
  338. $type_id = $node->new_id;
  339. $index = count($properties[$name]);
  340. $name = $properties_list[$type_id];
  341. $properties[$name][$index] = trim($node->new_value);
  342. }
  343. // now add in the properties
  344. foreach ($properties as $property => $elements) {
  345. foreach ($elements as $rank => $value) {
  346. $status = tripal_contact_insert_property($contact['contact_id'], $property, $value, FALSE);
  347. if (!$status) {
  348. drupal_set_message("Error cannot add property: $property", "error");
  349. watchdog('t_contact', "Error cannot add property: %prop",
  350. array('%property' => $property), WATCHDOG_ERROR);
  351. }
  352. }
  353. }
  354. }
  355. // add the record to the chado_contact table in Drupal
  356. if ($contact) {
  357. // add the description property
  358. tripal_contact_insert_property($contact['contact_id'], 'contact_description',
  359. $node->description, TRUE);
  360. // make sure the entry for this contact doesn't already exist in the chado_contact table
  361. // if it doesn't exist then we want to add it.
  362. $contact_id = chado_get_id_for_node('contact', $node->nid) ;
  363. if (!$contact_id) {
  364. // next add the item to the drupal table
  365. $sql = "INSERT INTO {chado_contact} (nid, vid, contact_id) ".
  366. "VALUES (:nid, :vid, :contact_id)";
  367. db_query($sql, array(':nid'=> $node->nid, ':vid' => $node->vid, ':contact_id' => $contact['contact_id']));
  368. }
  369. }
  370. else {
  371. drupal_set_message(t('Unable to add contact.', 'warning'));
  372. watchdog('tripal_contact', 'Insert contact: Unable to create contact where values: %values',
  373. array('%values' => print_r($values, TRUE)), WATCHDOG_WARNING);
  374. }
  375. return TRUE;
  376. }
  377. /*
  378. *
  379. * Implements hook_update
  380. *
  381. * The purpose of the function is to allow the module to take action when an edited node is being
  382. * updated. It updates any name changes to the database tables that werec reated upon registering a contact.
  383. * As well, the database will be changed, so the user changed information will be saved to the database.
  384. *
  385. * @param $node
  386. * The node being updated
  387. *
  388. * @ingroup tripal_contact
  389. */
  390. function chado_contact_update($node) {
  391. if ($node->revision) {
  392. // there is no way to handle revisions in Chado but leave
  393. // this here just to make not we've addressed it.
  394. }
  395. $contact_id = chado_get_id_for_node('contact', $node->nid) ;
  396. // check to see if this contact name doens't already exists.
  397. $sql = "SELECT contact_id FROM {contact} WHERE NOT contact_id = :contact_id AND name = :name";
  398. $contact = chado_query($sql, array(':contact_id' => $contact_id, ':name' => $node->contact_name))->fetchObject();
  399. if ($contact) {
  400. drupal_set_message(t('A contact with this name already exists. Cannot perform update.'), 'warning');
  401. return;
  402. }
  403. // update the contact record
  404. $match = array(
  405. 'contact_id' => $contact_id,
  406. );
  407. $values = array(
  408. 'name' => $node->title,
  409. 'description' => '',
  410. 'type_id' => $node->type_id
  411. );
  412. $status = tripal_core_chado_update('contact', $match, $values);
  413. if (!$status) {
  414. drupal_set_message("Error updating contact", "error");
  415. watchdog('t_contact', "Error updating contact", array(), WATCHDOG_ERROR);
  416. return;
  417. }
  418. // now update the properties
  419. $properties = array(); // stores all of the properties we need to add
  420. // get the list of properties for easy lookup (without doing lots of database queries
  421. $properties_list = array();
  422. $sql = "
  423. SELECT CVTS.cvterm_id, CVTS.name
  424. FROM {cvtermpath} CVTP
  425. INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
  426. INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
  427. INNER JOIN {cv} CV ON CVTO.cv_id = CV.cv_id
  428. WHERE
  429. CV.name = 'tripal_contact' AND
  430. NOT CVTO.name = 'Contact Type'
  431. ORDER BY CVTS.name ASC
  432. ";
  433. $prop_types = chado_query($sql);
  434. while ($prop = $prop_types->fetchObject()) {
  435. $properties_list[$prop->cvterm_id] = $prop->name;
  436. }
  437. // get the properties that should be added. Properties are in one of three forms:
  438. // 1) prop_value-[type id]-[index]
  439. // 2) new_value-[type id]-[index]
  440. // 3) new_id, new_value
  441. // dpm($node);
  442. foreach ($node as $key => $value) {
  443. if (preg_match('/^prop_value-(\d+)-(\d+)/', $key, $matches)) {
  444. $type_id = $matches[1];
  445. $index = $matches[2];
  446. $name = $properties_list[$type_id];
  447. $properties[$name][$index] = trim($value);
  448. }
  449. if (preg_match('/^new_value-(\d+)-(\d+)/', $key, $matches)) {
  450. $type_id = $matches[1];
  451. $index = $matches[2];
  452. $name = $properties_list[$type_id];
  453. $properties[$name][$index] = trim($value);
  454. }
  455. }
  456. if ($node->new_id and $node->new_value) {
  457. $type_id = $node->new_id;
  458. $name = $properties_list[$type_id];
  459. $index = count($properties[$name]);
  460. $properties[$name][$index] = trim($node->new_value);
  461. }
  462. // now add in the properties by first removing any the contact
  463. // already has and adding the ones we have
  464. tripal_core_chado_delete('contactprop', array('contact_id' => $contact_id));
  465. foreach ($properties as $property => $elements) {
  466. foreach ($elements as $rank => $value) {
  467. $status = tripal_contact_insert_property($contact_id, $property, $value, FALSE);
  468. if (!$status) {
  469. drupal_set_message("Error cannot add property: '$property'", "error");
  470. watchdog('t_contact', "Error cannot add property: '%prop'",
  471. array('%prop' => $property), WATCHDOG_ERROR);
  472. }
  473. }
  474. }
  475. tripal_contact_update_property($contact_id, 'contact_description', $node->description, 1);
  476. }
  477. /**
  478. * Implementation of tripal_contact_load().
  479. *
  480. *
  481. * @param $node
  482. * The node that is to be accessed from the database
  483. *
  484. * @return $node
  485. * The node with the information to be loaded into the database
  486. *
  487. */
  488. function chado_contact_load($node) {
  489. // get the feature details from chado
  490. $contact_id = chado_get_id_for_node('contact', $node->nid);
  491. $values = array('contact_id' => $contact_id);
  492. $contact = tripal_core_generate_chado_var('contact', $values);
  493. // get the contact description and replace the contact.description field with this one
  494. $values = array(
  495. 'contact_id' => $contact->contact_id,
  496. 'type_id' => array(
  497. 'name' => 'contact_description',
  498. ),
  499. );
  500. $options = array(
  501. 'return_array' => 1,
  502. 'include_fk' => array('type_id' => 1),
  503. );
  504. $description = tripal_core_generate_chado_var('contactprop', $values, $options);
  505. if (count($description) == 1) {
  506. $description = tripal_core_expand_chado_vars($description, 'field', 'contactprop.value');
  507. $contact->description = $description[0]->value;
  508. }
  509. $additions = new stdClass();
  510. $additions->contact = $contact;
  511. return $additions;
  512. }
  513. /**
  514. * Implementation of tripal_contact_delete().
  515. *
  516. * This function takes a node and if the delete button has been chosen by the user, the contact
  517. * and it's details will be removed.Following,given the node-ID, the instance will be deleted from
  518. * the 'chado_contact' table.
  519. *
  520. * @parm $node
  521. * Then node which contains the information stored within the node-ID
  522. *
  523. */
  524. function chado_contact_delete(&$node) {
  525. $contact_id = chado_get_id_for_node('contact', $node->nid);
  526. // if we don't have a contact id for this node then this isn't a node of
  527. // type chado_contact or the entry in the chado_contact table was lost.
  528. if (!$contact_id) {
  529. return;
  530. }
  531. // Remove data from {chado_contact}, {node} and {node_revisions} tables of
  532. // drupal database
  533. $sql_del = "DELETE FROM {chado_contact} WHERE nid = :nid AND vid = :vid";
  534. db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
  535. $sql_del = "DELETE FROM {node_revision} WHERE nid = :nid AND vid = :vid";
  536. db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
  537. $sql_del = "DELETE FROM {node} WHERE nid = :nid AND vid = :vid";
  538. db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
  539. // Remove data from contact and contactprop tables of chado database as well
  540. chado_query("DELETE FROM {contactprop} WHERE contact_id = :contact_id", array(':contact_id' => $contact_id));
  541. chado_query("DELETE FROM {contact} WHERE contact_id = :contact_id", array(':contact_id' => $contact_id));
  542. }
  543. /**
  544. *
  545. *
  546. * @ingroup tripal_contact
  547. */
  548. function tripal_contact_preprocess_tripal_contact_relationships(&$variables) {
  549. // we want to provide a new variable that contains the matched contacts.
  550. $contact = $variables['node']->contact;
  551. // normally we would use tripal_core_expand_chado_vars to expand our
  552. // organism object and add in the relationships, however whan a large
  553. // number of relationships are present this significantly slows the
  554. // query, therefore we will manually perform the query
  555. $sql = "
  556. SELECT C.name, C.contact_id, CP.nid, CVT.name as rel_type
  557. FROM contact_relationship PR
  558. INNER JOIN {contact} C ON PR.object_id = C.contact_id
  559. INNER JOIN {cvterm} CVT ON PR.type_id = CVT.cvterm_id
  560. LEFT JOIN public.chado_contact CP ON C.contact_id = CP.contact_id
  561. WHERE PR.subject_id = :contact_id
  562. ";
  563. $as_subject = chado_query($sql, array(':contact_id' => $contact->contact_id));
  564. $sql = "
  565. SELECT C.name, C.contact_id, CP.nid, CVT.name as rel_type
  566. FROM contact_relationship PR
  567. INNER JOIN {contact} C ON PR.subject_id = C.contact_id
  568. INNER JOIN {cvterm} CVT ON PR.type_id = CVT.cvterm_id
  569. LEFT JOIN public.chado_contact CP ON C.contact_id = CP.contact_id
  570. WHERE PR.object_id = :contact_id
  571. ";
  572. $as_object = chado_query($sql, array(':contact_id' => $contact->contact_id));
  573. // combine both object and subject relationshisp into a single array
  574. $relationships = array();
  575. $relationships['object'] = array();
  576. $relationships['subject'] = array();
  577. // iterate through the object relationships
  578. while ($relationship = $as_object->fetchObject()) {
  579. // get the relationship and child types
  580. $rel_type = t(preg_replace('/_/', " ", $relationship->rel_type));
  581. $sub_type = t(preg_replace('/_/', " ", $relationship->sub_type));
  582. if (!array_key_exists($rel_type, $relationships['object'])) {
  583. $relationships['object'][$rel_type] = array();
  584. }
  585. if (!array_key_exists($sub_type, $relationships['object'][$rel_type])) {
  586. $relationships['object'][$rel_type][$sub_type] = array();
  587. }
  588. $relationships['object'][$rel_type][$sub_type][] = $relationship;
  589. }
  590. // now add in the subject relationships
  591. while ($relationship = $as_subject->fetchObject()) {
  592. // get the relationship and child types
  593. $rel_type = t(preg_replace('/_/', " ", $relationship->rel_type));
  594. $obj_type = t(preg_replace('/_/', " ", $relationship->obj_type));
  595. if (!array_key_exists($rel_type, $relationships['subject'])) {
  596. $relationships['subject'][$rel_type] = array();
  597. }
  598. if (!array_key_exists($obj_type, $relationships['subject'][$rel_type])) {
  599. $relationships['subject'][$rel_type][$obj_type] = array();
  600. }
  601. $relationships['subject'][$rel_type][$obj_type][] = $relationship;
  602. }
  603. $contact->all_relationships = $relationships;
  604. }
  605. /*
  606. *
  607. */
  608. function tripal_contact_form_alter(&$form, &$form_state, $form_id) {
  609. if ($form_id == "chado_contact_node_form") {
  610. }
  611. }