tripal_analysis.chado_node.inc 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. <?php
  2. /**
  3. * Provide information to drupal about the node types that we're creating
  4. * in this module
  5. *
  6. * @ingroup tripal_analysis
  7. */
  8. function tripal_analysis_node_info() {
  9. $nodes = array();
  10. $nodes['chado_analysis'] = array(
  11. 'name' => t('Analysis'),
  12. 'base' => 'chado_analysis',
  13. 'description' => t('An analysis'),
  14. 'has_title' => FALSE,
  15. 'title_label' => t('Analysis'),
  16. 'locked' => TRUE,
  17. 'chado_node_api' => array(
  18. 'base_table' => 'analysis',
  19. 'hook_prefix' => 'chado_analysis',
  20. 'record_type_title' => array(
  21. 'singular' => t('Analysis'),
  22. 'plural' => t('Analyses')
  23. ),
  24. 'sync_filters' => array(
  25. 'type_id' => FALSE,
  26. 'organism_id' => FALSE,
  27. 'checkboxes' => array('name'),
  28. ),
  29. )
  30. );
  31. return $nodes;
  32. }
  33. /**
  34. * When editing or creating a new node of type 'chado_analysis' we need
  35. * a form. This function creates the form that will be used for this.
  36. *
  37. * @ingroup tripal_analysis
  38. */
  39. function chado_analysis_form($node, &$form_state) {
  40. $form = array();
  41. // Default values can come in the following ways:
  42. //
  43. // 1) as elements of the $node object. This occurs when editing an existing analysis
  44. // 2) in the $form_state['values'] array which occurs on a failed validation or
  45. // ajax callbacks from non submit form elements
  46. // 3) in the $form_state['input'[ array which occurs on ajax callbacks from submit
  47. // form elements and the form is being rebuilt
  48. //
  49. // set form field defaults
  50. $analysis_id = null;
  51. $analysisname = '';
  52. $program = '';
  53. $programversion = '';
  54. $algorithm = '';
  55. $sourcename = '';
  56. $sourceversion = '';
  57. $sourceuri = '';
  58. $timeexecuted = '';
  59. $description = '';
  60. $d_removed = array(); // lists removed properties
  61. $num_new = 0; // the number of new rows
  62. // if we are editing an existing node then the analysis is already part of the node
  63. if (property_exists($node, 'analysis')) {
  64. $analysis = $node->analysis;
  65. $analysis = tripal_core_expand_chado_vars($analysis, 'field', 'analysis.description');
  66. $analysis_id = $analysis->analysis_id;
  67. // get form defaults
  68. $analysisname = $analysis->name;
  69. $program = $analysis->program;
  70. $programversion = $analysis->programversion;
  71. $algorithm = $analysis->algorithm;
  72. $sourcename = $analysis->sourcename;
  73. $sourceversion = $analysis->sourceversion;
  74. $sourceuri = $analysis->sourceuri;
  75. $timeexecuted = $analysis->timeexecuted;
  76. $description = $analysis->description;
  77. // set the analysis_id in the form
  78. $form['analysis_id'] = array(
  79. '#type' => 'value',
  80. '#value' => $analysis->analysis_id,
  81. );
  82. }
  83. // if we are re constructing the form from a failed validation or ajax callback
  84. // then use the $form_state['values'] values
  85. if (array_key_exists('values', $form_state)) {
  86. $analysisname = $form_state['values']['analysisname'];
  87. $program = $form_state['values']['program'];
  88. $programversion = $form_state['values']['programversion'];
  89. $algorithm = $form_state['values']['algorithm'];
  90. $sourcename = $form_state['values']['sourcename'];
  91. $sourceversion = $form_state['values']['sourceversion'];
  92. $sourceuri = $form_state['values']['sourceuri'];
  93. $timeexecuted = $form_state['values']['timeexecuted'];
  94. $description = $form_state['values']['description'];
  95. $d_removed = $form_state['values']['removed'];
  96. $num_new = $form_state['values']['num_new'] ? $form_state['values']['num_new'] : 0;
  97. }
  98. // if we are re building the form from after submission (from ajax call) then
  99. // the values are in the $form_state['input'] array
  100. if (array_key_exists('input', $form_state) and !empty($form_state['input'])) {
  101. $analysisname = $form_state['input']['analysisname'];
  102. $program = $form_state['input']['program'];
  103. $programversion = $form_state['input']['programversion'];
  104. $algorithm = $form_state['input']['algorithm'];
  105. $sourcename = $form_state['input']['sourcename'];
  106. $sourceversion = $form_state['input']['sourceversion'];
  107. $sourceuri = $form_state['input']['sourceuri'];
  108. $timeexecuted = $form_state['input']['timeexecuted'];
  109. $description = $form_state['input']['description'];
  110. $d_removed = $form_state['input']['removed'];
  111. $num_new = $form_state['input']['num_new'] ? $form_state['input']['num_new'] : 0;
  112. }
  113. $form['title']= array(
  114. '#type' => 'value',
  115. '#default_value' => $node->title,
  116. );
  117. $form['instructions'] = array(
  118. '#markup' => t('<b>Note</b>: When adding any type of data it is good to associate it with
  119. an analysis so that site visitors can identify the source of the data including
  120. necessary materials and methods. The fields below imply that all analyses
  121. are derived from some software package. But, data can also be derived via retreival
  122. from an external source or an analysis pipeline with multipel software components.
  123. In these cases, provide values for the fields below that best makes sense
  124. '),
  125. );
  126. $form['analysisname']= array(
  127. '#type' => 'textfield',
  128. '#title' => t('Analysis Name'),
  129. '#required' => TRUE,
  130. '#default_value' => $analysisname,
  131. '#description' => t("This should be a brief name that
  132. describes the analysis succintly. This name will helps the user find analyses."),
  133. );
  134. $form['program']= array(
  135. '#type' => 'textfield',
  136. '#title' => t('Program, Pipeline Name or Method Name'),
  137. '#required' => TRUE,
  138. '#default_value' => $program,
  139. '#description' => t("Program name, e.g. blastx, blastp, sim4, genscan. If the analysis was not derived from a software package, provide a very brief description of the pipeline or method."),
  140. );
  141. $form['programversion']= array(
  142. '#type' => 'textfield',
  143. '#title' => t('Program, Pipeline or Method version'),
  144. '#required' => TRUE,
  145. '#default_value' => $programversion,
  146. '#description' => t("Version description, e.g. TBLASTX 2.0MP-WashU [09-Nov-2000]. Enter 'n/a' if no version is available or applicable."),
  147. );
  148. $form['algorithm']= array(
  149. '#type' => 'textfield',
  150. '#title' => t('Algorithm'),
  151. '#required' => FALSE,
  152. '#default_value' => $algorithm,
  153. '#description' => t("Algorithm name, e.g. blast."),
  154. );
  155. $form['sourcename']= array(
  156. '#type' => 'textfield',
  157. '#title' => t('Source Name'),
  158. '#required' => TRUE,
  159. '#default_value' => $sourcename,
  160. '#description' => t('The name of the source data. This could be a file name, data set name or a
  161. small description for how the data was collected. For long descriptions use the description field below'),
  162. );
  163. $form['sourceversion']= array(
  164. '#type' => 'textfield',
  165. '#title' => t('Source Version'),
  166. '#required' => FALSE,
  167. '#default_value' => $sourceversion,
  168. '#description' => t('If the source dataset has a version, include it here'),
  169. );
  170. $form['sourceuri']= array(
  171. '#type' => 'textfield',
  172. '#title' => t('Source URI'),
  173. '#required' => FALSE,
  174. '#default_value' => $sourceuri,
  175. '#description' => t("This is a permanent URL or URI for the source of the analysis.
  176. Someone could recreate the analysis directly by going to this URI and
  177. fetching the source data (e.g. the blast database, or the training model)."),
  178. );
  179. // Get time saved in chado
  180. $default_time = $timeexecuted;
  181. $year = preg_replace("/^(\d+)-\d+-\d+ .*/", "$1", $default_time);
  182. $month = preg_replace("/^\d+-0?(\d+)-\d+ .*/", "$1", $default_time);
  183. $day = preg_replace("/^\d+-\d+-0?(\d+) .*/", "$1", $default_time);
  184. // If the time is not set, use current time
  185. if (!$default_time) {
  186. $default_time = REQUEST_TIME;
  187. $year = format_date($default_time, 'custom', 'Y');
  188. $month = format_date($default_time, 'custom', 'n');
  189. $day = format_date($default_time, 'custom', 'j');
  190. }
  191. $form['timeexecuted']= array(
  192. '#type' => 'date',
  193. '#title' => t('Time Executed'),
  194. '#required' => TRUE,
  195. '#default_value' => array(
  196. 'year' => $year,
  197. 'month' => $month,
  198. 'day' => $day,
  199. ),
  200. );
  201. $form['description']= array(
  202. '#type' => 'textarea',
  203. '#rows' => 15,
  204. '#title' => t('Materials & Methods (Description and/or Program Settings)'),
  205. '#required' => FALSE,
  206. '#default_value' => $description,
  207. '#description' => t('Please provide all necessary information to allow
  208. someone to recreate the analysis, including materials and methods
  209. for collection of the source data and performing the analysis'),
  210. );
  211. $exclude = array();
  212. $include = array();
  213. // Properties Form
  214. // ----------------------------------
  215. $instructions = t('To add additional properties to the drop down. ' . l("Add terms to the analysis_property vocabulary", "admin/tripal/chado/tripal_cv/cvterm/add") . ".");
  216. $details = array(
  217. 'property_table' => 'analysisprop', // the name of the prop table
  218. 'base_foreign_key' => 'analysis_id', // the name of the key in your base chado table
  219. 'base_key_value' => $analysis_id, // the value of analysis_id for this record
  220. 'cv_name' => 'analysis_property', // the cv.name of the cv governing analysisprop.type_id
  221. 'fieldset_title' => 'Properties',
  222. 'additional_instructions' => $instructions
  223. );
  224. chado_node_properties_form($form, $form_state, $details);
  225. return $form;
  226. }
  227. /**
  228. * Validates the user input before creating an analysis node
  229. *
  230. * @ingroup tripal_analysis
  231. */
  232. function chado_analysis_validate($node, $form, &$form_state) {
  233. // use the analysis parent to validate the node
  234. tripal_analysis_validate($node, $form, $form_state);
  235. }
  236. /**
  237. * This validation is being used for three activities:
  238. * CASE A: Update a node that exists in both drupal and chado
  239. * CASE B: Synchronizing a node from chado to drupal
  240. * CASE C: Inserting a new node that exists in niether drupal nor chado
  241. *
  242. * @ingroup tripal_analysis
  243. */
  244. function tripal_analysis_validate($node, $form, &$form_state) {
  245. // remove surrounding white-space on submitted values
  246. $node->analysisname = trim($node->analysisname);
  247. $node->description = trim($node->description);
  248. $node->program = trim($node->program);
  249. $node->programversion = trim($node->programversion);
  250. $node->algorithm = trim($node->algorithm);
  251. $node->sourcename = trim($node->sourcename);
  252. $node->sourceversion = trim($node->sourceversion);
  253. $node->sourceuri = trim($node->sourceuri);
  254. // if this is a delete then don't validate
  255. if($node->op == 'Delete') {
  256. return;
  257. }
  258. // we are syncing if we do not have a node ID but we do have a analysis_id. We don't
  259. // need to validate during syncing so just skip it.
  260. if (is_null($node->nid) and property_exists($node, 'analysis_id') and $node->analysis_id != 0) {
  261. return;
  262. }
  263. // Validating for an update
  264. if (!is_null($node->nid)) {
  265. // get the existing node
  266. $values = array('analysis_id' => $node->analysis_id);
  267. $result = tripal_core_chado_select('analysis', array('*'), $values);
  268. $analysis = $result[0];
  269. // if the name has changed make sure it doesn't conflict with an existing name
  270. if ($analysis->name != $node->analysisname) {
  271. $values = array('name' => $node->analysisname);
  272. $result = tripal_core_chado_select('analysis', array('analysis_id'), $values);
  273. if ($result and count($result) > 0) {
  274. form_set_error('analysisname', 'Cannot update the analysis with this analysis name. An analysis with this name already exists.');
  275. return;
  276. }
  277. }
  278. // if the unique constraint has changed check to make sure it doesn't conflict with an
  279. // existing record
  280. if ($analysis->program != $node->program or $analysis->programversion != $node->programversion or
  281. $analysis->sourcename != $node->sourcename) {
  282. $values = array(
  283. 'program' => $node->program,
  284. 'programversion' => $node->programversion,
  285. 'sourcename' => $node->sourcename,
  286. );
  287. $result = tripal_core_chado_select('analysis', array('analysis_id'), $values);
  288. if ($result and count($result) > 0) {
  289. if ($analysis->program != $node->program) {
  290. $field = 'program';
  291. }
  292. if ($analysis->programversion != $node->programversion) {
  293. $field = 'programversion';
  294. }
  295. if ($analysis->sourcename != $node->sourcename) {
  296. $field = 'sourcename';
  297. }
  298. form_set_error($field, 'Cannot update the analysis with this program,
  299. program version and source name. An analysis with these values already exists.');
  300. return;
  301. }
  302. }
  303. }
  304. // Validating for an insert
  305. else {
  306. $values = array(
  307. 'program' => $node->program,
  308. 'programversion' => $node->programversion,
  309. 'sourcename' => $node->sourcename,
  310. );
  311. $analysis = tripal_core_chado_select('analysis', array('analysis_id'), $values);
  312. if ($analysis and count($analysis) > 0) {
  313. form_set_error('program', 'Cannot add the analysis with this program,
  314. program version and source name. An analysis with these values already exists.');
  315. return;
  316. }
  317. // make sure we have a unique analysis name. This is not a requirement
  318. // for the analysis table but we use the analysis name for the Drupal node
  319. // title, so it should be unique
  320. $values = array('name' => $node->analysisname);
  321. $result = tripal_core_chado_select('analysis', array('analysis_id'), $values);
  322. if ($result and count($result) > 0) {
  323. form_set_error('analysisname', 'Cannot add the analysis with this analysis name. An analysis with this name already exists.');
  324. return;
  325. }
  326. }
  327. }
  328. /**
  329. * When a new chado_analysis node is created we also need to add information
  330. * to our chado_analysis table. This function is called on insert of a new
  331. * node of type 'chado_analysis' and inserts the necessary information.
  332. *
  333. * @ingroup tripal_analysis
  334. */
  335. function chado_analysis_insert($node) {
  336. $node->analysisname = trim($node->analysisname);
  337. $node->description = trim($node->description);
  338. $node->program = trim($node->program);
  339. $node->programversion = trim($node->programversion);
  340. $node->algorithm = trim($node->algorithm);
  341. $node->sourcename = trim($node->sourcename);
  342. $node->sourceversion = trim($node->sourceversion);
  343. $node->sourceuri = trim($node->sourceuri);
  344. // if there is an analysis_id in the $node object then this must be a sync so
  345. // we can skip adding the analysis as it is already there, although
  346. // we do need to proceed with the rest of the insert
  347. if (!property_exists($node, 'analysis_id')) {
  348. // Create a timestamp so we can insert it into the chado database
  349. $time = $node->timeexecuted;
  350. $month = $time['month'];
  351. $day = $time['day'];
  352. $year = $time['year'];
  353. $timestamp = $month . '/' . $day . '/' . $year;
  354. // insert and then get the newly inserted analysis record
  355. $values = array(
  356. 'name' => $node->analysisname,
  357. 'description' => $node->description,
  358. 'program' => $node->program,
  359. 'programversion' => $node->programversion,
  360. 'algorithm' => $node->algorithm,
  361. 'sourcename' => $node->sourcename,
  362. 'sourceversion' => $node->sourceversion,
  363. 'sourceuri' => $node->sourceuri,
  364. 'timeexecuted' => $timestamp
  365. );
  366. $analysis = tripal_core_chado_insert('analysis', $values);
  367. if (!$analysis) {
  368. drupal_set_message(t('Unable to add analysis.', 'warning'));
  369. watchdog('tripal_analysis', 'Insert analysis: Unable to create analysis where values:%values',
  370. array('%values' => print_r($values, TRUE)), WATCHDOG_ERROR);
  371. return;
  372. }
  373. $analysis_id = $analysis['analysis_id'];
  374. // now add in the properties
  375. $details = array(
  376. 'property_table' => 'analysisprop',
  377. 'base_table' => 'analysis',
  378. 'foreignkey_name' => 'analysis_id',
  379. 'foreignkey_value' => $analysis_id
  380. );
  381. chado_node_properties_form_update_properties($node, $details);
  382. }
  383. else {
  384. $analysis_id = $node->analysis_id;
  385. }
  386. // Make sure the entry for this analysis doesn't already exist in the
  387. // chado_analysis table if it doesn't exist then we want to add it.
  388. $check_org_id = chado_get_id_for_node('analysis', $node->nid);
  389. if (!$check_org_id) {
  390. $record = new stdClass();
  391. $record->nid = $node->nid;
  392. $record->vid = $node->vid;
  393. $record->analysis_id = $analysis_id;
  394. drupal_write_record('chado_analysis', $record);
  395. }
  396. // add the analysis to the node object for
  397. // use by other analysis modules that may be using this function
  398. $node->analysis = $analysis;
  399. $node->analysis_id = $analysis_id; // we need to set this for children
  400. }
  401. /**
  402. * Removes analysis from the chado database
  403. *
  404. * @param $node
  405. * The node object specifying which chado record to delete
  406. *
  407. * @ingroup tripal_analysis
  408. */
  409. function chado_analysis_delete($node) {
  410. $analysis_id = chado_get_id_for_node('analysis', $node->nid);
  411. // if we don't have an analysis id for this node then this isn't a node of
  412. // type chado_analysis or the entry in the chado_analysis table was lost.
  413. if (!$analysis_id) {
  414. return;
  415. }
  416. // Remove data from the {chado_analysis}, {node}, and {node_revisions} tables
  417. $sql_del = "DELETE FROM {chado_analysis} WHERE nid = :nid AND vid = :vid";
  418. db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
  419. $sql_del = "DELETE FROM {node} WHERE nid = :nid AND vid = :vid";
  420. db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
  421. $sql_del = "DELETE FROM {node_revision} WHERE nid = :nid AND vid = :vid";
  422. db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
  423. //Remove from analysis and analysisprop tables of chado database as well
  424. chado_query("DELETE FROM {analysis} WHERE analysis_id = :analysis_id", array(':analysis_id' => $analysis_id));
  425. }
  426. /**
  427. * Update analyses
  428. *
  429. * @param $node
  430. * The updated node object
  431. *
  432. * @ingroup tripal_analysis
  433. */
  434. function chado_analysis_update($node) {
  435. $node->analysisname = trim($node->analysisname);
  436. $node->description = trim($node->description);
  437. $node->program = trim($node->program);
  438. $node->programversion = trim($node->programversion);
  439. $node->algorithm = trim($node->algorithm);
  440. $node->sourcename = trim($node->sourcename);
  441. $node->sourceversion = trim($node->sourceversion);
  442. $node->sourceuri = trim($node->sourceuri);
  443. // Create a timestamp so we can insert it into the chado database
  444. $time = $node->timeexecuted;
  445. $month = $time['month'];
  446. $day = $time['day'];
  447. $year = $time['year'];
  448. $timestamp = $month . '/' . $day . '/' . $year;
  449. // update the record in Chado
  450. $analysis_id = chado_get_id_for_node('analysis', $node->nid);
  451. $match = array(
  452. 'analysis_id' => $node->analysis_id,
  453. );
  454. $values = array(
  455. 'name' => $node->analysisname,
  456. 'description' => $node->description,
  457. 'program' => $node->program,
  458. 'programversion' => $node->programversion,
  459. 'algorithm' => $node->algorithm,
  460. 'sourcename' => $node->sourcename,
  461. 'sourceversion' => $node->sourceversion,
  462. 'sourceuri' => $node->sourceuri,
  463. 'timeexecuted' => $timestamp,
  464. 'analysis_id' => $analysis_id
  465. );
  466. $status = tripal_core_chado_update('analysis', $match, $values);
  467. if (!$status) {
  468. drupal_set_message(t('Unable to update analysis.', 'warning'));
  469. watchdog('tripal_analysis', 'Update analysis: Unable to update analysis where values: %values',
  470. array('%values' => print_r($values, TRUE)), WATCHDOG_ERROR);
  471. }
  472. // now add in the properties by first removing any the analysis
  473. // already has and adding the ones we have
  474. $details = array(
  475. 'property_table' => 'analysisprop',
  476. 'base_table' => 'analysis',
  477. 'foreignkey_name' => 'analysis_id',
  478. 'foreignkey_value' => $analysis_id
  479. );
  480. chado_node_properties_form_update_properties($node, $details);
  481. }
  482. /**
  483. * When a node is requested by the user this function is called to allow us
  484. * to add auxiliary data to the node object.
  485. *
  486. * @ingroup tripal_analysis
  487. */
  488. function chado_analysis_load($nodes) {
  489. foreach ($nodes as $nid => $node) {
  490. // find the analysis and add in the details
  491. $analysis_id = chado_get_id_for_node('analysis', $nid);
  492. // build the analysis variable
  493. $values = array('analysis_id' => $analysis_id);
  494. $analysis = tripal_core_generate_chado_var('analysis', $values);
  495. // add in the description field
  496. $analysis = tripal_core_expand_chado_vars($analysis, 'field', 'analysis.description');
  497. $nodes[$nid]->analysis = $analysis;
  498. }
  499. }
  500. /**
  501. * Implement hook_access().
  502. *
  503. * This hook allows node modules to limit access to the node types they define.
  504. *
  505. * @param $node
  506. * The node on which the operation is to be performed, or, if it does not yet exist, the
  507. * type of node to be created
  508. *
  509. * @param $op
  510. * The operation to be performed
  511. *
  512. * @param $account
  513. * A user object representing the user for whom the operation is to be performed
  514. *
  515. * @return
  516. * If the permission for the specified operation is not set then return FALSE. If the
  517. * permission is set then return NULL as this allows other modules to disable
  518. * access. The only exception is when the $op == 'create'. We will always
  519. * return TRUE if the permission is set.
  520. *
  521. * @ingroup tripal_analysis
  522. */
  523. function chado_analysis_node_access($node, $op, $account) {
  524. if ($op == 'create') {
  525. if (!user_access('create chado_analysis content', $account)) {
  526. return FALSE;
  527. }
  528. return TRUE;
  529. }
  530. if ($op == 'update') {
  531. if (!user_access('edit chado_analysis content', $account)) {
  532. return FALSE;
  533. }
  534. }
  535. if ($op == 'delete') {
  536. if (!user_access('delete chado_analysis content', $account)) {
  537. return FALSE;
  538. }
  539. }
  540. if ($op == 'view') {
  541. if (!user_access('access chado_analysis content', $account)) {
  542. return FALSE;
  543. }
  544. }
  545. return NULL;
  546. }
  547. /**
  548. *
  549. * @ingroup tripal_analysis
  550. */
  551. function tripal_analysis_node_view($node, $view_mode, $langcode) {
  552. switch ($node->type) {
  553. case 'chado_analysis':
  554. // Show feature browser and counts
  555. if ($view_mode == 'full') {
  556. $node->content['tripal_analysis_base'] = array(
  557. '#value' => theme('tripal_analysis_base', array('node' => $node)),
  558. );
  559. $node->content['tripal_analysis_properties'] = array(
  560. '#value' => theme('tripal_analysis_properties', array('node' => $node)),
  561. );
  562. }
  563. if ($view_mode == 'teaser') {
  564. $node->content['tripal_analysis_teaser'] = array(
  565. '#value' => theme('tripal_analysis_teaser', array('node' => $node)),
  566. );
  567. }
  568. break;
  569. }
  570. }
  571. /**
  572. *
  573. * @param $node
  574. */
  575. function tripal_analysis_node_presave($node) {
  576. // If this is an analysis of some type it will should have three required
  577. // fields for the Chado analysis table: program, programversion and sourcename.
  578. // So we will set the title for any node that has these three fields. Some extension
  579. // modules will use this module as a type of "inherited" class, so we don't know
  580. // for sure when type of analysis we have.
  581. if (property_exists($node, 'program') and
  582. property_exists($node, 'programversion') and
  583. property_exists($node, 'sourcename')) {
  584. $name = '';
  585. $program = '';
  586. $programversion = '';
  587. $sourcename = '';
  588. if (property_exists($node, 'analysis')) {
  589. $name = $node->analysis->name;
  590. $program = $node->analysis->program;
  591. $programversion = $node->analysis->programversion;
  592. $sourcename = $node->analysis->sourcename;
  593. }
  594. else {
  595. $name = $node->analysisname;
  596. $program = $node->program;
  597. $programversion = $node->programversion;
  598. $sourcename = $node->sourcename;
  599. }
  600. // now construct the title
  601. if ($name) {
  602. $node->title = $name;
  603. }
  604. else {
  605. $node->title = "$program ($programversion) $sourcename";
  606. }
  607. }
  608. }