tripal_organism.module 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. <?php
  2. require_once "api/tripal_organism.api.inc";
  3. require_once "includes/tripal_organism.admin.inc";
  4. require_once "includes/organism_sync.inc";
  5. /**
  6. * @file
  7. * @defgroup tripal_organism Organism Module
  8. * @ingroup tripal_modules
  9. */
  10. /**
  11. *
  12. * @ingroup tripal_organism
  13. */
  14. function tripal_organism_init() {
  15. // add the jGCharts JS and CSS
  16. drupal_add_css(drupal_get_path('module', 'tripal_organism') . '/theme/css/tripal_organism.css');
  17. drupal_add_js(drupal_get_path('module', 'tripal_organism') . '/theme/js/tripal_organism.js');
  18. }
  19. /**
  20. * Provide information to drupal about the node types that we're creating
  21. * in this module
  22. *
  23. * @ingroup tripal_organism
  24. */
  25. function tripal_organism_node_info() {
  26. $nodes = array();
  27. $nodes['chado_organism'] = array(
  28. 'name' => t('Organism'),
  29. 'base' => 'chado_organism',
  30. 'description' => t('An organism'),
  31. 'has_title' => FALSE,
  32. 'title_label' => t('Organism'),
  33. 'locked' => TRUE
  34. );
  35. return $nodes;
  36. }
  37. /**
  38. *
  39. * @ingroup tripal_organism
  40. */
  41. function tripal_organism_block_info() {
  42. $blocks['base']['info'] = t('Tripal Organism Details');
  43. $blocks['base']['cache'] = DRUPAL_NO_CACHE;
  44. $blocks['description']['info'] = t('Tripal Organism Description');
  45. $blocks['description']['cache'] = DRUPAL_NO_CACHE;
  46. $blocks['image']['info'] = t('Tripal Organism Image');
  47. $blocks['image']['cache'] = DRUPAL_NO_CACHE;
  48. return $blocks;
  49. }
  50. /**
  51. *
  52. * @ingroup tripal_organism
  53. */
  54. function tripal_organism_block_view($delta = '') {
  55. if (user_access('access chado_feature content') and arg(0) == 'node' and is_numeric(arg(1))) {
  56. $nid = arg(1);
  57. $node = node_load($nid);
  58. $block = array();
  59. switch ($delta) {
  60. case 'base':
  61. $block['subject'] = t('Organism Details');
  62. $block['content'] = theme('tripal_organism_base', $node);
  63. break;
  64. case 'description':
  65. $block['subject'] = t('Organism Description');
  66. $block['content'] = theme('tripal_organism_description', $node);
  67. break;
  68. case 'image':
  69. $block['subject'] = t('Organism Image');
  70. $block['content'] = theme('tripal_organism_image', $node);
  71. break;
  72. default:
  73. }
  74. return $block;
  75. }
  76. }
  77. /**
  78. * Menu items are automatically added for the new node types created
  79. * by this module to the 'Create Content' Navigation menu item. This function
  80. * adds more menu items needed for this module.
  81. *
  82. * @ingroup tripal_organism
  83. */
  84. function tripal_organism_menu() {
  85. $items = array();
  86. // the administative settings menu
  87. $items['admin/tripal/chado/tripal_organism'] = array(
  88. 'title' => 'Organisms',
  89. 'description' => 'Any living biological entity, such as an animal, plant, fungus, or bacterium.',
  90. 'page callback' => 'tripal_organism_admin_organism_view',
  91. 'access arguments' => array('adminster tripal organism'),
  92. 'type' => MENU_NORMAL_ITEM,
  93. );
  94. $items['admin/tripal/chado/tripal_organism/help'] = array(
  95. 'title' => 'Help',
  96. 'description' => "A description of the Tripal Organism module including a short description of it's usage.",
  97. 'page callback' => 'theme',
  98. 'page arguments' => array('tripal_organism_help'),
  99. 'access arguments' => array('adminster tripal organism'),
  100. 'type' => MENU_LOCAL_TASK,
  101. );
  102. $items['admin/tripal/chado/tripal_organism/configuration'] = array(
  103. 'title' => 'Settings',
  104. 'description' => 'Manage integration of Chado organisms including associated features',
  105. 'page callback' => 'drupal_get_form',
  106. 'page arguments' => array('tripal_organism_admin'),
  107. 'access arguments' => array('adminster tripal organism'),
  108. 'type' => MENU_LOCAL_TASK,
  109. );
  110. $items['admin/tripal/chado/tripal_organism/sync'] = array(
  111. 'title' => 'Sync',
  112. 'description' => 'Sync Chado organisms with Drupal',
  113. 'page callback' => 'drupal_get_form',
  114. 'page arguments' => array('tripal_organism_sync'),
  115. 'access arguments' => array('adminster tripal organism'),
  116. 'type' => MENU_LOCAL_TASK,
  117. );
  118. $items['admin/tripal/chado/tripal_organism/views/organisms/enable'] = array(
  119. 'title' => 'Enable Organism Administrative View',
  120. 'page callback' => 'tripal_views_admin_enable_view',
  121. 'page arguments' => array('tripal_organism_admin_organisms', 'admin/tripal/chado/tripal_organism'),
  122. 'access arguments' => array('administer tripal_bulk_loader'),
  123. 'type' => MENU_CALLBACK,
  124. );
  125. return $items;
  126. }
  127. /**
  128. * Implements hook_help()
  129. * Purpose: Adds a help page to the module list
  130. */
  131. function tripal_organism_help ($path, $arg) {
  132. if ($path == 'admin/help#tripal_organism') {
  133. return theme('tripal_organism_help', array());
  134. }
  135. }
  136. /**
  137. * We need to let drupal know about our theme functions and their arguments.
  138. * We create theme functions to allow users of the module to customize the
  139. * look and feel of the output generated in this module
  140. *
  141. * @ingroup tripal_organism
  142. */
  143. function tripal_organism_theme($existing, $type, $theme, $path) {
  144. $core_path = drupal_get_path('module', 'tripal_core');
  145. $items = array(
  146. 'node__chado_organism' => array(
  147. 'template' => 'node--chado-generic',
  148. 'render element' => 'node',
  149. 'base hook' => 'node',
  150. 'path' => "$core_path/theme",
  151. ),
  152. 'tripal_organism_base' => array(
  153. 'variables' => array('node' => NULL),
  154. 'template' => 'tripal_organism_base',
  155. 'path' => "$path/theme/tripal_organism",
  156. ),
  157. 'tripal_organism_description' => array(
  158. 'variables' => array('node' => NULL),
  159. 'template' => 'tripal_organism_description',
  160. 'path' => "$path/theme/tripal_organism",
  161. ),
  162. 'tripal_organism_image' => array(
  163. 'variables' => array('node' => NULL),
  164. 'template' => 'tripal_organism_image',
  165. 'path' => "$path/theme/tripal_organism",
  166. ),
  167. 'tripal_organism_teaser' => array(
  168. 'variables' => array('node' => NULL),
  169. 'template' => 'tripal_organism_teaser',
  170. 'path' => "$path/theme/tripal_organism",
  171. ),
  172. 'tripal_organism_help' => array(
  173. 'template' => 'tripal_organism_help',
  174. 'variables' => array(NULL),
  175. 'path' => "$path/theme",
  176. ),
  177. );
  178. return $items;
  179. }
  180. /**
  181. *
  182. * @ingroup tripal_feature
  183. */
  184. function tripal_organism_node_view($node, $view_mode, $langcode) {
  185. switch ($node->type) {
  186. case 'chado_organism':
  187. // Show feature browser and counts
  188. if ($view_mode == 'full') {
  189. $node->content['tripal_organism_base'] = array(
  190. '#value' => theme('tripal_organism_base', array('node' => $node)),
  191. );
  192. }
  193. if ($view_mode == 'teaser') {
  194. $node->content['tripal_organism_teaser'] = array(
  195. '#value' => theme('tripal_organism_teaser', array('node' => $node)),
  196. );
  197. }
  198. break;
  199. }
  200. }
  201. /**
  202. * Set the permission types that the chado module uses. Essentially we
  203. * want permissionis that protect creation, editing and deleting of chado
  204. * data objects
  205. *
  206. *
  207. @ingroup tripal_organism
  208. */
  209. function tripal_organism_permission() {
  210. return array(
  211. 'access chado_organism content' => array(
  212. 'title' => t('View Organisms'),
  213. 'description' => t('Allow users to view organism pages.'),
  214. ),
  215. 'create chado_organism content' => array(
  216. 'title' => t('Create Organisms'),
  217. 'description' => t('Allow users to create new organism pages.'),
  218. ),
  219. 'delete chado_organism content' => array(
  220. 'title' => t('Delete Organisms'),
  221. 'description' => t('Allow users to delete organism pages.'),
  222. ),
  223. 'edit chado_organism content' => array(
  224. 'title' => t('Edit Organisms'),
  225. 'description' => t('Allow users to edit organism pages.'),
  226. ),
  227. 'adminster tripal organism' => array(
  228. 'title' => t('Administer Organisms'),
  229. 'description' => t('Allow users to administer all organisms.'),
  230. ),
  231. );
  232. }
  233. /**
  234. * Implements hook_views_api()
  235. * Purpose: Essentially this hook tells drupal that there is views support for
  236. * for this module which then includes tripal_db.views.inc where all the
  237. * views integration code is
  238. *
  239. * @ingroup tripal_organism
  240. */
  241. function tripal_organism_views_api() {
  242. return array(
  243. 'api' => 3.0,
  244. );
  245. }
  246. /**
  247. *
  248. *
  249. * @ingroup tripal_organism
  250. */
  251. function tripal_organism_job_describe_args($callback, $args) {
  252. $new_args = array();
  253. if ($callback == 'tripal_organism_sync_organisms') {
  254. $organism = tripal_core_chado_select('organism', array('genus', 'species'), array('organism_id' => $args[0]));
  255. $new_args['Organism'] = $organism[0]->genus . " " . $organism[0]->species;
  256. }
  257. return $new_args;
  258. }
  259. /**
  260. * Implement hook_access().
  261. *
  262. * This hook allows node modules to limit access to the node types they define.
  263. *
  264. * @param $node
  265. * The node on which the operation is to be performed, or, if it does not yet exist, the
  266. * type of node to be created
  267. *
  268. * @param $op
  269. * The operation to be performed
  270. *
  271. *
  272. * @param $account
  273. * A user object representing the user for whom the operation is to be performed
  274. *
  275. * @return
  276. * If the permission for the specified operation is not set then return FALSE. If the
  277. * permission is set then return NULL as this allows other modules to disable
  278. * access. The only exception is when the $op == 'create'. We will always
  279. * return TRUE if the permission is set.
  280. *
  281. * @ingroup tripal_organism
  282. */
  283. function chado_organism_node_access($node, $op, $account) {
  284. if ($op == 'create') {
  285. if (!user_access('create chado_organism content', $account)) {
  286. return FALSE;
  287. }
  288. return TRUE;
  289. }
  290. if ($op == 'update') {
  291. if (!user_access('edit chado_organism content', $account)) {
  292. return FALSE;
  293. }
  294. }
  295. if ($op == 'delete') {
  296. if (!user_access('delete chado_organism content', $account)) {
  297. return FALSE;
  298. }
  299. }
  300. if ($op == 'view') {
  301. if (!user_access('access chado_organism content', $account)) {
  302. return FALSE;
  303. }
  304. }
  305. return NULL;
  306. }
  307. /**
  308. * Implementation of hook_validate
  309. *
  310. * @param $node
  311. * @param $form
  312. * @param $form_state
  313. *
  314. * @ingroup tripal_organism
  315. */
  316. function chado_organism_validate($node, $form, &$form_state) {
  317. // remove any white space around values
  318. $node->genus = trim($node->genus);
  319. $node->species = trim($node->species);
  320. $node->abbreviation = trim($node->abbreviation);
  321. $node->common_name = trim($node->common_name);
  322. $node->description = trim($node->description);
  323. // if this is an update, we want to make sure that a different organism doesn't
  324. // already have this genus and speces
  325. if (property_exists($node, 'organism_id')) {
  326. $sql = "
  327. SELECT *
  328. FROM {organism} O
  329. WHERE
  330. genus = :genus AND
  331. species = :species AND NOT
  332. organism_id = :organism_id
  333. ";
  334. $args = array(':genus' => $node->genus, ':species' => $node->species, ':organism_id' => $node->organism_id);
  335. $result = chado_query($sql, $args)->fetchObject();
  336. if ($result) {
  337. form_set_error('genus', t("Update cannot proceed. The organism genus
  338. '$node->genus' and species '$node->species' is already present in the database."));
  339. watchdog('tripal_organism',
  340. 'Update organism: genus and species already exists: %values',
  341. array('%values' => "genus = $node->genus, species = $node->species"),
  342. WATCHDOG_WARNING);
  343. }
  344. }
  345. // if this is an insert then check to make sure the genus and species are unique
  346. else {
  347. $values = array(
  348. 'genus' => $node->genus,
  349. 'species' => $node->species,
  350. );
  351. $organism = tripal_core_chado_select('organism', array('organism_id'), $values);
  352. if (sizeof($organism) > 0) {
  353. form_set_error('genus', 'Cannot add the organism with this genus and species.
  354. The organism already exists.');
  355. watchdog('tripal_organism',
  356. 'Insert organism: genus and species already exists: %values',
  357. array('%values' => "genus = $node->genus, species = $node->species"),
  358. WATCHDOG_WARNING);
  359. }
  360. }
  361. }
  362. /**
  363. * When a new chado_organism node is created we also need to add information
  364. * to our chado_organism table. This function is called on insert of a new node
  365. * of type 'chado_organism' and inserts the necessary information.
  366. *
  367. * @ingroup tripal_organism
  368. */
  369. function chado_organism_insert($node) {
  370. // remove any white space around values
  371. $node->genus = trim($node->genus);
  372. $node->species = trim($node->species);
  373. $node->abbreviation = trim($node->abbreviation);
  374. $node->common_name = trim($node->common_name);
  375. $node->description = trim($node->description);
  376. // if there is an organism_id in the $node object then this must be a sync so
  377. // we can skip adding the organism as it is already there, although
  378. // we do need to proceed with the rest of the insert
  379. if (!property_exists($node,'organism_id')) {
  380. $values = array(
  381. 'genus' => $node->genus,
  382. 'species' => $node->species,
  383. 'abbreviation' => $node->abbreviation,
  384. 'common_name' => $node->common_name,
  385. 'comment' => $node->description
  386. );
  387. $organism = tripal_core_chado_insert('organism', $values);
  388. if (!$organism) {
  389. drupal_set_message(t('Unable to add organism.', 'warning'));
  390. watchdog('tripal_organism', 'Insert Organism: Unable to create organism where values:%values',
  391. array('%values' => print_r($values, TRUE)), WATCHDOG_ERROR);
  392. return;
  393. }
  394. $organism_id = $organism['organism_id'];
  395. }
  396. else {
  397. $organism_id = $node->organism_id;
  398. }
  399. // Make sure the entry for this organism doesn't already exist in the
  400. // chado_organism table if it doesn't exist then we want to add it.
  401. $check_org_id = chado_get_id_for_node('organism', $node->nid);
  402. if (!$check_org_id) {
  403. $record = new stdClass();
  404. $record->nid = $node->nid;
  405. $record->vid = $node->vid;
  406. $record->organism_id = $organism_id;
  407. drupal_write_record('chado_organism', $record);
  408. }
  409. // set the title for the node
  410. $record = new stdClass();
  411. $record->title = "$node->genus $node->species";
  412. $record->nid = $node->nid;
  413. drupal_write_record('node', $record, 'nid');
  414. drupal_write_record('node_revisions', $record, 'nid');
  415. // add the image
  416. chado_organism_add_image($node);
  417. }
  418. /**
  419. * Update organisms
  420. *
  421. * @ingroup tripal_organism
  422. */
  423. function chado_organism_update($node) {
  424. // remove any white space around values
  425. $node->genus = trim($node->genus);
  426. $node->species = trim($node->species);
  427. $node->abbreviation = trim($node->abbreviation);
  428. $node->common_name = trim($node->common_name);
  429. $node->description = trim($node->description);
  430. if ($node->revision) {
  431. // there is no way to handle revisions in Chado but leave
  432. // this here just to make not we've addressed it.
  433. }
  434. $match = array(
  435. 'organism_id' => chado_get_id_for_node('organism', $node->nid),
  436. );
  437. $values = array(
  438. 'genus' => $node->genus,
  439. 'species' => $node->species,
  440. 'abbreviation' => $node->abbreviation,
  441. 'common_name' => $node->common_name,
  442. 'comment' => $node->description
  443. );
  444. $org_status = tripal_core_chado_update('organism', $match, $values);
  445. // set the title for the node
  446. $record = new stdClass();
  447. $record->title = "$node->genus $node->species";
  448. $record->nid = $node->nid;
  449. drupal_write_record('node', $record, 'nid');
  450. drupal_write_record('node_revisions', $record, 'nid');
  451. // add the image
  452. chado_organism_add_image($node);
  453. }
  454. /**
  455. * Delete organism from both drupal and chado databases. Check dependency before
  456. * deleting from chado.
  457. *
  458. * @ingroup tripal_organism
  459. */
  460. function chado_organism_delete($node) {
  461. $organism_id = chado_get_id_for_node('organism', $node->nid);
  462. // if we don't have an organism id for this node then this isn't a node of
  463. // type chado_organism or the entry in the chado_organism table was lost.
  464. if (!$organism_id) {
  465. return;
  466. }
  467. // Remove data from the {chado_organism}, {node}, and {node_revisions} tables
  468. $sql_del = "DELETE FROM {chado_organism} WHERE nid = :nid AND vid = :vid";
  469. db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
  470. $sql_del = "DELETE FROM {node} WHERE nid = :nid AND vid = :vid";
  471. db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
  472. $sql_del = "DELETE FROM {node_revision} WHERE nid = ':nid' AND vid = ':vid'";
  473. db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
  474. // Test dependency before deleting from chado database. If a library or
  475. // feature depends on this organism, don't delete it
  476. $sql = "SELECT feature_id FROM {feature} WHERE organism_id = :organism_id";
  477. $check_feature = chado_query($sql, array(':organism_id' => $organism_id))->fetchObject();
  478. $sql = "SELECT library_id FROM {library} WHERE organism_id = :organism_id";
  479. $check_lib = chado_query($sql, array(':organism_id' => $organism_id))->fetchObject();
  480. if (!$check_lib && !$check_feature) {
  481. tripal_core_chado_delete('organism', array('organism_id' => $organism_id));
  482. }
  483. else {
  484. drupal_set_message(t("Organism deleted from drupal. Warning: at least one " .
  485. "library or feature depends on this organism. It was not removed from chado."));
  486. }
  487. }
  488. /**
  489. *
  490. *
  491. * @ingroup tripal_organism
  492. */
  493. function chado_organism_add_image($node) {
  494. // check to see if a file was uploaded. If so then copy it to the images
  495. // directory for display with the organism
  496. if (isset($_FILES['files']) &&
  497. $_FILES['files']['name']['organism_image'] &&
  498. is_uploaded_file($_FILES['files']['tmp_name']['organism_image'])) {
  499. // make sure the destination directory exists
  500. $dest = tripal_file_directory_path() . "/tripal_organism/images";
  501. file_prepare_directory($dest, FILE_CREATE_DIRECTORY);
  502. // now move the file
  503. $validators = array('file_validate_is_image' => array());
  504. $destination = "public://tripal/tripal_organism/images/";
  505. $file = file_save_upload('organism_image', $validators, $destination);
  506. if (!$file) {
  507. drupal_set_message(t("Organism image was not uploaded."));
  508. }
  509. else {
  510. file_move($file, $destination . "/" . $node->nid . ".jpg", FILE_EXISTS_REPLACE);
  511. }
  512. }
  513. }
  514. /**
  515. * When editing or creating a new node of type 'chado_organism' we need
  516. * a form. This function creates the form that will be used for this.
  517. *
  518. * @ingroup tripal_organism
  519. */
  520. function chado_organism_form($node, $form_state) {
  521. $form = array();
  522. // we have a file upload element on the form soe we need the multipart encoding type
  523. $form['#attributes']['enctype'] = 'multipart/form-data';
  524. // if the organism is part of the node object then we are editing. If not we are inserting
  525. if (property_exists($node, 'organism')) {
  526. $organism = $node->organism;
  527. // add in the comment since it is a text field and may not be included if too big
  528. $organism = tripal_core_expand_chado_vars($organism, 'field', 'organism.comment');
  529. // get form defaults
  530. $abbreviation = property_exists($node, 'abbreviation') ? property_exists($node, 'abbreviation') : $organism->abbreviation;
  531. $genus = property_exists($node, 'genus') ? property_exists($node, 'genus') : $organism->genus;
  532. $species = property_exists($node, 'species') ? property_exists($node, 'species') : $organism->species;
  533. $common_name = property_exists($node, 'common_name') ? property_exists($node, 'common_name') : $organism->common_name;
  534. $description = property_exists($node, 'description') ? property_exists($node, 'description') : $organism->comment;
  535. $organism_image = property_exists($node, 'organism_image') ? property_exists($node, 'organism_image') : '';
  536. // set the organism_id in the form
  537. $form['organism_id'] = array(
  538. '#type' => 'value',
  539. '#value' => $organism->organism_id,
  540. );
  541. }
  542. else {
  543. // get form defaults
  544. $abbreviation = property_exists($node, 'abbreviation') ? property_exists($node, 'abbreviation') : '';
  545. $genus = property_exists($node, 'genus') ? property_exists($node, 'genus') : '';
  546. $species = property_exists($node, 'species') ? property_exists($node, 'species') : '';
  547. $common_name = property_exists($node, 'common_name') ? property_exists($node, 'common_name') : '';
  548. $description = property_exists($node, 'description') ? property_exists($node, 'description') : '';
  549. $organism_image = property_exists($node, 'organism_image') ? property_exists($node, 'organism_image') : '';
  550. }
  551. $form['abbreviation']= array(
  552. '#type' => 'textfield',
  553. '#title' => t('Abbreviation'),
  554. '#required' => TRUE,
  555. '#default_value' => $abbreviation,
  556. );
  557. $form['genus']= array(
  558. '#type' => 'textfield',
  559. '#title' => t('Genus'),
  560. '#required' => TRUE,
  561. '#default_value' => $genus,
  562. );
  563. $form['species']= array(
  564. '#type' => 'textfield',
  565. '#title' => t('Species'),
  566. '#required' => TRUE,
  567. '#default_value' => $species,
  568. );
  569. $form['common_name']= array(
  570. '#type' => 'textfield',
  571. '#title' => t('Common Name'),
  572. '#required' => TRUE,
  573. '#default_value' => $common_name,
  574. );
  575. $form['description']= array(
  576. '#type' => 'textarea',
  577. '#rows' => 15,
  578. '#title' => t('Description'),
  579. '#default_value' => $description,
  580. );
  581. $form['organism_image']= array(
  582. '#type' => 'file',
  583. '#title' => t('Organism Image'),
  584. '#description' => 'Add an image for this organism',
  585. '#progress_indicator' => 'bar',
  586. );
  587. return $form;
  588. }
  589. /**
  590. * When a node is requested by the user this function is called to allow us
  591. * to add auxiliary data to the node object.
  592. *
  593. * @ingroup tripal_organism
  594. */
  595. function chado_organism_load($nodes) {
  596. foreach ($nodes as $nid => $node) {
  597. // find the organism and add in the details
  598. $organism_id = chado_get_id_for_node('organism', $nid);
  599. // build the organism variable
  600. $values = array('organism_id' => $organism_id);
  601. $organism = tripal_core_generate_chado_var('organism', $values);
  602. // add in the description field
  603. $organism = tripal_core_expand_chado_vars($organism, 'field', 'organism.comment');
  604. $nodes[$nid]->organism = $organism;
  605. }
  606. }