tripal_organism.chado_node.inc 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711
  1. <?php
  2. /**
  3. * @file
  4. * Implements the organims node content type
  5. */
  6. /**
  7. * Implements hook_node_info().
  8. *
  9. * Provide information to drupal about the node types that we're creating
  10. * in this module
  11. *
  12. * @ingroup tripal_organism
  13. */
  14. function tripal_organism_node_info() {
  15. $nodes = array();
  16. $nodes['chado_organism'] = array(
  17. 'name' => t('Organism'),
  18. 'base' => 'chado_organism',
  19. 'description' => t('An organism'),
  20. 'has_title' => TRUE,
  21. 'locked' => TRUE,
  22. 'chado_node_api' => array(
  23. 'base_table' => 'organism',
  24. 'hook_prefix' => 'chado_organism',
  25. 'record_type_title' => array(
  26. 'singular' => t('Organism'),
  27. 'plural' => t('Organisms')
  28. ),
  29. 'sync_filters' => array(
  30. 'type_id' => FALSE,
  31. 'organism_id' => FALSE,
  32. 'checkboxes' => array('genus', 'species'),
  33. ),
  34. )
  35. );
  36. return $nodes;
  37. }
  38. /**
  39. * Implement hook_node_access().
  40. *
  41. * This hook allows node modules to limit access to the node types they define.
  42. *
  43. * @param $node
  44. * The node on which the operation is to be performed, or, if it does not yet exist, the
  45. * type of node to be created
  46. *
  47. * @param $op
  48. * The operation to be performed
  49. *
  50. *
  51. * @param $account
  52. * A user object representing the user for whom the operation is to be performed
  53. *
  54. * @return
  55. * If the permission for the specified operation is not set then return FALSE. If the
  56. * permission is set then return NULL as this allows other modules to disable
  57. * access. The only exception is when the $op == 'create'. We will always
  58. * return TRUE if the permission is set.
  59. *
  60. * @ingroup tripal_organism
  61. */
  62. function chado_organism_node_access($node, $op, $account) {
  63. $node_type = $node;
  64. if (is_object($node)) {
  65. $node_type = $node->type;
  66. }
  67. if($node_type == 'chado_organism') {
  68. if ($op == 'create') {
  69. if (!user_access('create chado_organism content', $account)) {
  70. return NODE_ACCESS_DENY;
  71. }
  72. return NODE_ACCESS_ALLOW;
  73. }
  74. if ($op == 'update') {
  75. if (!user_access('edit chado_organism content', $account)) {
  76. return NODE_ACCESS_DENY;
  77. }
  78. }
  79. if ($op == 'delete') {
  80. if (!user_access('delete chado_organism content', $account)) {
  81. return NODE_ACCESS_DENY;
  82. }
  83. }
  84. if ($op == 'view') {
  85. if (!user_access('access chado_organism content', $account)) {
  86. return NODE_ACCESS_DENY;
  87. }
  88. }
  89. return NODE_ACCESS_IGNORE;
  90. }
  91. }
  92. /**
  93. * Implement hook_form().
  94. *
  95. * When editing or creating a new node of type 'chado_organism' we need
  96. * a form. This function creates the form that will be used for this.
  97. *
  98. * @ingroup tripal_organism
  99. */
  100. function chado_organism_form($node, $form_state) {
  101. $form = array();
  102. $chado_version = chado_get_version(TRUE);
  103. // we have a file upload element on the form soe we need the multipart encoding type
  104. $form['#attributes']['enctype'] = 'multipart/form-data';
  105. // if the organism is part of the node object then we are editing. If not we are inserting
  106. if (property_exists($node, 'organism')) {
  107. $organism = $node->organism;
  108. // add in the comment since it is a text field and may not be included if too big
  109. $organism = chado_expand_var($organism, 'field', 'organism.comment');
  110. // get form defaults
  111. $abbreviation = property_exists($node, 'abbreviation') ? property_exists($node, 'abbreviation') : $organism->abbreviation;
  112. $genus = property_exists($node, 'genus') ? property_exists($node, 'genus') : $organism->genus;
  113. $species = property_exists($node, 'species') ? property_exists($node, 'species') : $organism->species;
  114. $common_name = property_exists($node, 'common_name') ? property_exists($node, 'common_name') : $organism->common_name;
  115. $description = property_exists($node, 'description') ? property_exists($node, 'description') : $organism->comment;
  116. $organism_image = property_exists($node, 'organism_image') ? property_exists($node, 'organism_image') : '';
  117. // The infraspecific and type_id fields are new to Chado v1.3
  118. if ($chado_version > 1.2) {
  119. $infraspecific_name = property_exists($node, 'infraspecific_name') ? property_exists($node, 'infraspecific_name') : $organism->infraspecific_name;
  120. $type_id = property_exists($node, 'type_id') ? property_exists($node, 'type_id') : $organism->infraspecific_name;
  121. }
  122. // set the organism_id in the form
  123. $form['organism_id'] = array(
  124. '#type' => 'value',
  125. '#value' => $organism->organism_id,
  126. );
  127. $organism_id = $organism->organism_id;
  128. }
  129. else {
  130. // get form defaults
  131. $abbreviation = property_exists($node, 'abbreviation') ? property_exists($node, 'abbreviation') : '';
  132. $genus = property_exists($node, 'genus') ? property_exists($node, 'genus') : '';
  133. $species = property_exists($node, 'species') ? property_exists($node, 'species') : '';
  134. $common_name = property_exists($node, 'common_name') ? property_exists($node, 'common_name') : '';
  135. $description = property_exists($node, 'description') ? property_exists($node, 'description') : '';
  136. $organism_image = property_exists($node, 'organism_image') ? property_exists($node, 'organism_image') : '';
  137. // The infraspecific and type_id fields are new to Chado v1.3
  138. if ($chado_version > 1.2) {
  139. $infraspecific_name = property_exists($node, 'infraspecific_name') ? property_exists($node, 'infraspecific_name') : '';
  140. $type_id = property_exists($node, 'type_id') ? property_exists($node, 'type_id') : '';
  141. }
  142. $organism_id = NULL;
  143. }
  144. $form['genus']= array(
  145. '#type' => 'textfield',
  146. '#title' => t('Genus'),
  147. '#required' => TRUE,
  148. '#default_value' => $genus,
  149. );
  150. $form['species']= array(
  151. '#type' => 'textfield',
  152. '#title' => t('Species'),
  153. '#required' => TRUE,
  154. '#default_value' => $species,
  155. );
  156. // The infraspecific and type_id fields are new to Chado v1.3
  157. if ($chado_version > 1.2) {
  158. $options = array();
  159. $cv = tripal_get_cv(array('name' => 'taxonomic_rank'));
  160. if (!$cv) {
  161. drupal_set_message('The taxonomic_rank vocabulary cannot be found, thus selects for "rank" are not available.', 'warning');
  162. }
  163. else {
  164. $terms = tripal_get_cvterm_select_options($cv->cv_id);
  165. // Unfortunately the taxonomic_rank vocabulary is not properly organized
  166. // such that we an only include terms below 'species'. Therefore we will
  167. // just list them here and hope we haven't missed one.
  168. $valid_terms = array('subspecies', 'varietas', 'subvariety', 'forma', 'subforma');
  169. foreach ($terms as $cvterm_id => $name) {
  170. if (in_array($name, $valid_terms)) {
  171. $options[$cvterm_id] = $name;
  172. }
  173. }
  174. }
  175. $form['type_id']= array(
  176. '#type' => 'select',
  177. '#title' => t('Rank'),
  178. '#required' => TRUE,
  179. '#options' => $options,
  180. '#default_value' => $type_id,
  181. '#description' => t('The scientific name for any taxon
  182. below the rank of species. This field is used for constructing the
  183. full infraspecific name for the organism.')
  184. );
  185. $form['infraspecific_name']= array(
  186. '#type' => 'textfield',
  187. '#title' => t('Infraspecific Name'),
  188. '#required' => TRUE,
  189. '#default_value' => $infraspecific_name,
  190. '#description' => t("The infraspecific name for this organism. When
  191. diplaying the full taxonomic name, this field is appended to the
  192. genus, species and rank."),
  193. );
  194. }
  195. $form['abbreviation']= array(
  196. '#type' => 'textfield',
  197. '#title' => t('Abbreviation'),
  198. '#required' => TRUE,
  199. '#default_value' => $abbreviation,
  200. '#descriptoin' => t('A short abbreviation for this species (e.g. O.sativa)'),
  201. );
  202. $form['common_name']= array(
  203. '#type' => 'textfield',
  204. '#title' => t('Common Name'),
  205. '#required' => TRUE,
  206. '#default_value' => $common_name,
  207. );
  208. $form['description']= array(
  209. '#type' => 'text_format',
  210. '#rows' => 15,
  211. '#title' => t('Description'),
  212. '#default_value' => $description,
  213. );
  214. $form['organism_image']= array(
  215. '#type' => 'managed_file',
  216. '#title' => t('Organism Image'),
  217. '#description' => t('Add an image to display for this organism.'),
  218. '#progress_indicator' => 'bar',
  219. '#upload_location' => 'public://tripal/tripal_organism/images/',
  220. );
  221. // PROPERTIES FORM
  222. //---------------------------------------------
  223. $prop_cv = tripal_get_default_cv('organismprop', 'type_id');
  224. $cv_id = $prop_cv ? $prop_cv->cv_id : NULL;
  225. $details = array(
  226. 'property_table' => 'organismprop', // the name of the prop table
  227. 'chado_id' => $organism_id, // the value of organism_id for this record
  228. 'cv_id' => $cv_id // the cv.cv_id of the cv governing organismprop.type_id
  229. );
  230. // Adds the form elements to your current form
  231. chado_add_node_form_properties($form, $form_state, $details);
  232. // ADDITIONAL DBXREFS FORM
  233. //---------------------------------------------
  234. $details = array(
  235. 'linking_table' => 'organism_dbxref', // the name of the _dbxref table
  236. 'base_foreign_key' => 'organism_id', // the name of the key in your base chado table
  237. 'base_key_value' => $organism_id // the value of organism_id for this record
  238. );
  239. // Adds the form elements to your current form
  240. chado_add_node_form_dbxrefs($form, $form_state, $details);
  241. return $form;
  242. }
  243. /**
  244. * Implementation of hook_validate().
  245. *
  246. * @param $node
  247. * @param $form
  248. * @param $form_state
  249. *
  250. * @ingroup tripal_organism
  251. */
  252. function chado_organism_validate($node, $form, &$form_state) {
  253. // We only want to validate when the node is saved.
  254. // Since this validate can be called on AJAX and Deletion of the node
  255. // we need to make this check to ensure queries are not executed
  256. // without the proper values.
  257. if(property_exists($node, "op") and $node->op != 'Save') {
  258. return;
  259. }
  260. // we are syncing if we do not have a node ID but we do have a organism_id. We don't
  261. // need to validate during syncing so just skip it.
  262. if (!property_exists($node, 'nid') and property_exists($node, 'organism_id') and $node->organism_id != 0) {
  263. return;
  264. }
  265. // remove any white space around values
  266. $node->genus = property_exists($node, 'genus') ? trim($node->genus) : '';
  267. $node->species = property_exists($node, 'species') ? trim($node->species) : '';
  268. $node->abbreviation = property_exists($node, 'abbreviation') ? trim($node->abbreviation) : '';
  269. $node->common_name = property_exists($node, 'common_name') ? trim($node->common_name) : '';
  270. // Validating for an update
  271. if (property_exists($node, 'organism_id')) {
  272. $sql = "
  273. SELECT *
  274. FROM {organism} O
  275. WHERE
  276. genus = :genus AND
  277. species = :species AND NOT
  278. organism_id = :organism_id
  279. ";
  280. $args = array(':genus' => $node->genus, ':species' => $node->species, ':organism_id' => $node->organism_id);
  281. $result = chado_query($sql, $args)->fetchObject();
  282. if ($result) {
  283. form_set_error('genus', t("Update cannot proceed. The organism genus
  284. '$node->genus' and species '$node->species' is already present in the database."));
  285. tripal_report_error('tripal_organism', TRIPAL_WARNING,
  286. 'Update organism: genus and species already exists: %values',
  287. array('%values' => "genus = $node->genus, species = $node->species"));
  288. }
  289. }
  290. // Validating for an insert
  291. else {
  292. $values = array(
  293. 'genus' => $node->genus,
  294. 'species' => $node->species,
  295. );
  296. $organism = chado_select_record('organism', array('organism_id'), $values);
  297. if (sizeof($organism) > 0) {
  298. form_set_error('genus', 'Cannot add the organism with this genus and species.
  299. The organism already exists.');
  300. tripal_report_error('tripal_organism', TRIPAL_WARNING,
  301. 'Insert organism: genus and species already exists: %values',
  302. array('%values' => "genus = $node->genus, species = $node->species"));
  303. }
  304. }
  305. }
  306. /**
  307. * Implements hook_insert().
  308. *
  309. * When a new chado_organism node is created we also need to add information
  310. * to our chado_organism table. This function is called on insert of a new node
  311. * of type 'chado_organism' and inserts the necessary information.
  312. *
  313. * @ingroup tripal_organism
  314. */
  315. function chado_organism_insert($node) {
  316. $organism_id = '';
  317. // if there is an organism_id in the $node object then this must be a sync so
  318. // we can skip adding the organism as it is already there, although
  319. // we do need to proceed with insertion into the chado/drupal linking table.
  320. if (!property_exists($node, 'organism_id')) {
  321. // remove any white space around values
  322. $node->genus = trim($node->genus);
  323. $node->species = trim($node->species);
  324. $node->abbreviation = trim($node->abbreviation);
  325. $node->common_name = trim($node->common_name);
  326. $node->description = trim($node->description['value']);
  327. $values = array(
  328. 'genus' => $node->genus,
  329. 'species' => $node->species,
  330. 'abbreviation' => $node->abbreviation,
  331. 'common_name' => $node->common_name,
  332. 'comment' => $node->description
  333. );
  334. $organism = chado_insert_record('organism', $values);
  335. if (!$organism) {
  336. drupal_set_message(t('Unable to add organism.', 'warning'));
  337. tripal_report_error('tripal_organism', TRIPAL_ERROR, 'Insert Organism: Unable to create organism where values:%values',
  338. array('%values' => print_r($values, TRUE)));
  339. return;
  340. }
  341. $organism_id = $organism['organism_id'];
  342. if ($organism_id) {
  343. // * Properties Form *
  344. $details = array(
  345. 'property_table' => 'organismprop', // the name of the prop table
  346. 'base_table' => 'organism', // the name of your chado base table
  347. 'foreignkey_name' => 'organism_id', // the name of the key in your base table
  348. 'foreignkey_value' => $organism_id // the value of the example_id key
  349. );
  350. chado_update_node_form_properties($node, $details);
  351. // * Additional DBxrefs Form *
  352. $details = array(
  353. 'linking_table' => 'organism_dbxref', // the name of your _dbxref table
  354. 'foreignkey_name' => 'organism_id', // the name of the key in your base table
  355. 'foreignkey_value' => $organism_id // the value of the organism_id key
  356. );
  357. chado_update_node_form_dbxrefs($node, $details);
  358. }
  359. }
  360. else {
  361. $organism_id = $node->organism_id;
  362. }
  363. // Make sure the entry for this organism doesn't already exist in the
  364. // chado_organism table if it doesn't exist then we want to add it.
  365. $check_org_id = chado_get_id_from_nid('organism', $node->nid);
  366. if (!$check_org_id) {
  367. $record = new stdClass();
  368. $record->nid = $node->nid;
  369. $record->vid = $node->vid;
  370. $record->organism_id = $organism_id;
  371. drupal_write_record('chado_organism', $record);
  372. }
  373. // add the image
  374. if (property_exists($node, 'organism_image')) {
  375. chado_organism_add_image($node);
  376. }
  377. }
  378. /**
  379. * Implements hook_update().
  380. *
  381. * @ingroup tripal_organism
  382. */
  383. function chado_organism_update($node) {
  384. // remove any white space around values
  385. $node->genus = trim($node->genus);
  386. $node->species = trim($node->species);
  387. $node->abbreviation = trim($node->abbreviation);
  388. $node->common_name = trim($node->common_name);
  389. $node->description = trim($node->description['value']);
  390. $organism_id = chado_get_id_from_nid('organism', $node->nid);
  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. $match = array(
  396. 'organism_id' => $organism_id,
  397. );
  398. $values = array(
  399. 'genus' => $node->genus,
  400. 'species' => $node->species,
  401. 'abbreviation' => $node->abbreviation,
  402. 'common_name' => $node->common_name,
  403. 'comment' => $node->description
  404. );
  405. $org_status = chado_update_record('organism', $match, $values);
  406. if ( $node->organism_image != '' ) {
  407. chado_organism_add_image($node);
  408. }
  409. // * Properties Form *
  410. $details = array(
  411. 'property_table' => 'organismprop', // the name of the prop table
  412. 'base_table' => 'organism', // the name of your chado base table
  413. 'foreignkey_name' => 'organism_id', // the name of the key in your base table
  414. 'foreignkey_value' => $organism_id // the value of the example_id key
  415. );
  416. chado_update_node_form_properties($node, $details);
  417. // * Additional DBxrefs Form *
  418. $details = array(
  419. 'linking_table' => 'organism_dbxref', // the name of your _dbxref table
  420. 'foreignkey_name' => 'organism_id', // the name of the key in your base table
  421. 'foreignkey_value' => $organism_id // the value of the organism_id key
  422. );
  423. chado_update_node_form_dbxrefs($node, $details);
  424. }
  425. /**
  426. * Adds the image to the organism node and cleans up any old images.
  427. *
  428. * @param $node
  429. * The node object.
  430. */
  431. function chado_organism_add_image($node) {
  432. // If there is already an organism image, then remove it it if
  433. // no other modules are using it
  434. $fid = db_select('file_usage', 'fu')
  435. ->fields('fu', array('fid'))
  436. ->condition('module', 'tripal_organism')
  437. ->condition('type', 'organism_image')
  438. ->condition('id', $node->nid)
  439. ->execute()
  440. ->fetchField();
  441. if ($fid) {
  442. $file = file_load($fid);
  443. file_usage_delete($file, 'tripal_organism', 'organism_image', $node->nid);
  444. file_delete($file);
  445. }
  446. // Save the uploaded file
  447. $file = file_load($node->organism_image);
  448. if ($file) {
  449. $file->status = FILE_STATUS_PERMANENT;
  450. file_save($file);
  451. file_usage_add($file, 'tripal_organism', 'organism_image', $node->nid);
  452. }
  453. }
  454. /**
  455. * Implements hook_delete().
  456. *
  457. * Delete organism from both drupal and chado databases. Check dependency before
  458. * deleting from chado.
  459. *
  460. * @ingroup tripal_organism
  461. */
  462. function chado_organism_delete($node) {
  463. $organism_id = chado_get_id_from_nid('organism', $node->nid);
  464. // if we don't have an organism id for this node then this isn't a node of
  465. // type chado_organism or the entry in the chado_organism table was lost.
  466. if (!$organism_id) {
  467. return;
  468. }
  469. // Remove data from the {chado_organism}, {node}, and {node_revisions} tables
  470. $sql_del = "DELETE FROM {chado_organism} WHERE nid = :nid AND vid = :vid";
  471. db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
  472. $sql_del = "DELETE FROM {node} WHERE nid = :nid AND vid = :vid";
  473. db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
  474. $sql_del = "DELETE FROM {node_revision} WHERE nid = :nid AND vid = :vid";
  475. db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
  476. // Test dependency before deleting from chado database. If a library or
  477. // feature depends on this organism, don't delete it
  478. $sql = "SELECT feature_id FROM {feature} WHERE organism_id = :organism_id";
  479. $check_feature = chado_query($sql, array(':organism_id' => $organism_id))->fetchObject();
  480. $sql = "SELECT library_id FROM {library} WHERE organism_id = :organism_id";
  481. $check_lib = chado_query($sql, array(':organism_id' => $organism_id))->fetchObject();
  482. $sql = "SELECT stock_id FROM {stock} WHERE organism_id = :organism_id";
  483. $check_stock = chado_query($sql, array(':organism_id' => $organism_id))->fetchObject();
  484. if (!$check_lib && !$check_feature && !$check_stock) {
  485. chado_delete_record('organism', array('organism_id' => $organism_id));
  486. }
  487. else {
  488. drupal_set_message(t("Warning: other data depends on this organism. The organism page was removed from this site but the organism was removed from Chado."), 'warning');
  489. }
  490. }
  491. /**
  492. * Implements hook_load().
  493. *
  494. * When a node is requested by the user this function is called to allow us
  495. * to add auxiliary data to the node object.
  496. *
  497. * @ingroup tripal_organism
  498. */
  499. function chado_organism_load($nodes) {
  500. foreach ($nodes as $nid => $node) {
  501. // find the organism and add in the details
  502. $organism_id = chado_get_id_from_nid('organism', $nid);
  503. // if the nid does not have a matching record then skip this node.
  504. // this can happen with orphaned nodes.
  505. if (!$organism_id) {
  506. continue;
  507. }
  508. // build the organism variable
  509. $values = array('organism_id' => $organism_id);
  510. $organism = chado_generate_var('organism', $values);
  511. // add in the description field
  512. $organism = chado_expand_var($organism, 'field', 'organism.comment');
  513. $nodes[$nid]->organism = $organism;
  514. // Now get the title
  515. $node->title = chado_get_node_title($node);
  516. }
  517. }
  518. /**
  519. * Implements hook_node_presave(). Acts on all content types.
  520. *
  521. * @param $node
  522. * The node to be saved
  523. *
  524. * @ingroup tripal_organism
  525. */
  526. function tripal_organism_node_presave($node) {
  527. switch ($node->type) {
  528. // This step is for setting the title for the Drupal node. This title
  529. // is permanent and thus is created to be unique. Title changes provided
  530. // by tokens are generated on the fly dynamically, but the node title
  531. // seen in the content listing needs to be set here. Do not call
  532. // the chado_get_node_title() function here to set the title as the node
  533. // object isn't properly filled out and the function will fail.
  534. case 'chado_organism':
  535. // when syncing the details are not present in the $node object
  536. // as they are when submitted via the form. Therefore, if we do
  537. // not see any field values from the form, we assume this fucntion
  538. // is being called for syncing, so we must set the title accordingly
  539. if (property_exists($node, 'genus')) {
  540. $node->title = $node->genus . " " . $node->species;
  541. }
  542. else if (property_exists($node, 'organism')) {
  543. $node->title = $node->organism->genus . " " . $node->organism->species;
  544. }
  545. break;
  546. }
  547. }
  548. /**
  549. * Implements hook_node_view().
  550. *
  551. * @ingroup tripal_organism
  552. */
  553. function tripal_organism_node_view($node, $view_mode, $langcode) {
  554. switch ($node->type) {
  555. case 'chado_organism':
  556. // Show feature browser and counts
  557. if ($view_mode == 'full') {
  558. $node->content['tripal_organism_base'] = array(
  559. '#theme' => 'tripal_organism_base',
  560. '#node' => $node,
  561. '#tripal_toc_id' => 'base',
  562. '#tripal_toc_title' => 'Overview',
  563. '#weight' => -100,
  564. );
  565. $node->content['tripal_organism_properties'] = array(
  566. '#theme' => 'tripal_organism_properties',
  567. '#node' => $node,
  568. '#tripal_toc_id' => 'properties',
  569. '#tripal_toc_title' => 'Properties',
  570. );
  571. $node->content['tripal_organism_references'] = array(
  572. '#theme' => 'tripal_organism_references',
  573. '#node' => $node,
  574. '#tripal_toc_id' => 'references',
  575. '#tripal_toc_title' => 'Cross References',
  576. );
  577. }
  578. if ($view_mode == 'teaser') {
  579. $node->content['tripal_organism_teaser'] = array(
  580. '#theme' => 'tripal_organism_teaser',
  581. '#node' => $node,
  582. );
  583. }
  584. break;
  585. }
  586. }
  587. /**
  588. * Implements hook_node_insert().
  589. * Acts on all content types.
  590. *
  591. * @ingroup tripal_organism
  592. */
  593. function tripal_organism_node_insert($node) {
  594. switch ($node->type) {
  595. case 'chado_organism':
  596. // find the organism and add in the details
  597. $organism_id = chado_get_id_from_nid('organism', $node->nid);
  598. $values = array('organism_id' => $organism_id);
  599. $organism = chado_generate_var('organism', $values);
  600. $node->organism = $organism;
  601. // Now get the title
  602. $node->title = chado_get_node_title($node);
  603. // Now use the API to set the path.
  604. chado_set_node_url($node);
  605. break;
  606. }
  607. }
  608. /**
  609. * Implements hook_node_update().
  610. * Acts on all content types.
  611. *
  612. * @ingroup tripal_organism
  613. */
  614. function tripal_organism_node_update($node) {
  615. switch ($node->type) {
  616. case 'chado_organism':
  617. // Now get the title.
  618. $node->title = chado_get_node_title($node);
  619. // Now use the API to set the path.
  620. chado_set_node_url($node);
  621. break;
  622. }
  623. }
  624. /**
  625. * Implements [content_type]_chado_node_default_title_format().
  626. *
  627. * Defines a default title format for the Chado Node API to set the titles on
  628. * Chado organism nodes based on chado fields.
  629. */
  630. function chado_organism_chado_node_default_title_format() {
  631. return '[organism.genus] [organism.species]';
  632. }
  633. /**
  634. * Implements hook_chado_node_default_url_format().
  635. *
  636. * Designates a default URL format for organism nodes.
  637. */
  638. function chado_organism_chado_node_default_url_format() {
  639. return '/organism/[organism.genus]/[organism.species]';
  640. }