tripal_analysis.chado_node.inc 24 KB

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