tripal_organism.module 22 KB

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