tripal_analysis.chado_node.inc 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  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. 'base_foreign_key' => 'analysis_id', // the name of the key in your base chado table
  227. 'base_key_value' => $analysis_id, // the value of analysis_id for this record
  228. 'cv_name' => 'analysis_property', // the cv.name of the cv governing analysisprop.type_id
  229. 'fieldset_title' => 'Properties',
  230. 'additional_instructions' => $instructions
  231. );
  232. chado_add_node_form_properties($form, $form_state, $details);
  233. return $form;
  234. }
  235. /**
  236. * Implements hook_validate().
  237. * Validates the user input before creating an analysis node
  238. *
  239. * @ingroup tripal_analysis
  240. */
  241. function chado_analysis_validate($node, $form, &$form_state) {
  242. // use the analysis parent to validate the node
  243. tripal_analysis_validate($node, $form, $form_state);
  244. }
  245. /**
  246. * This validation is being used for three activities:
  247. * CASE A: Update a node that exists in both drupal and chado
  248. * CASE B: Synchronizing a node from chado to drupal
  249. * CASE C: Inserting a new node that exists in niether drupal nor chado
  250. *
  251. * @ingroup tripal_analysis
  252. */
  253. function tripal_analysis_validate($node, $form, &$form_state) {
  254. // remove surrounding white-space on submitted values
  255. $node->analysisname = trim($node->analysisname);
  256. $node->description = trim($node->description);
  257. $node->program = trim($node->program);
  258. $node->programversion = trim($node->programversion);
  259. $node->algorithm = trim($node->algorithm);
  260. $node->sourcename = trim($node->sourcename);
  261. $node->sourceversion = trim($node->sourceversion);
  262. $node->sourceuri = trim($node->sourceuri);
  263. // if this is a delete then don't validate
  264. if($node->op == 'Delete') {
  265. return;
  266. }
  267. // we are syncing if we do not have a node ID but we do have a analysis_id. We don't
  268. // need to validate during syncing so just skip it.
  269. if (is_null($node->nid) and property_exists($node, 'analysis_id') and $node->analysis_id != 0) {
  270. return;
  271. }
  272. // Validating for an update
  273. if (!is_null($node->nid)) {
  274. // get the existing node
  275. $values = array('analysis_id' => $node->analysis_id);
  276. $result = chado_select_record('analysis', array('*'), $values);
  277. $analysis = $result[0];
  278. // if the name has changed make sure it doesn't conflict with an existing name
  279. if ($analysis->name != $node->analysisname) {
  280. $values = array('name' => $node->analysisname);
  281. $result = chado_select_record('analysis', array('analysis_id'), $values);
  282. if ($result and count($result) > 0) {
  283. form_set_error('analysisname', 'Cannot update the analysis with this analysis name. An analysis with this name already exists.');
  284. return;
  285. }
  286. }
  287. // if the unique constraint has changed check to make sure it doesn't conflict with an
  288. // existing record
  289. if ($analysis->program != $node->program or $analysis->programversion != $node->programversion or
  290. $analysis->sourcename != $node->sourcename) {
  291. $values = array(
  292. 'program' => $node->program,
  293. 'programversion' => $node->programversion,
  294. 'sourcename' => $node->sourcename,
  295. );
  296. $result = chado_select_record('analysis', array('analysis_id'), $values);
  297. if ($result and count($result) > 0) {
  298. if ($analysis->program != $node->program) {
  299. $field = 'program';
  300. }
  301. if ($analysis->programversion != $node->programversion) {
  302. $field = 'programversion';
  303. }
  304. if ($analysis->sourcename != $node->sourcename) {
  305. $field = 'sourcename';
  306. }
  307. form_set_error($field, 'Cannot update the analysis with this program,
  308. program version and source name. An analysis with these values already exists.');
  309. return;
  310. }
  311. }
  312. }
  313. // Validating for an insert
  314. else {
  315. $values = array(
  316. 'program' => $node->program,
  317. 'programversion' => $node->programversion,
  318. 'sourcename' => $node->sourcename,
  319. );
  320. $analysis = chado_select_record('analysis', array('analysis_id'), $values);
  321. if ($analysis and count($analysis) > 0) {
  322. form_set_error('program', 'Cannot add the analysis with this program,
  323. program version and source name. An analysis with these values already exists.');
  324. return;
  325. }
  326. // make sure we have a unique analysis name. This is not a requirement
  327. // for the analysis table but we use the analysis name for the Drupal node
  328. // title, so it should be unique
  329. $values = array('name' => $node->analysisname);
  330. $result = chado_select_record('analysis', array('analysis_id'), $values);
  331. if ($result and count($result) > 0) {
  332. form_set_error('analysisname', 'Cannot add the analysis with this analysis name. An analysis with this name already exists.');
  333. return;
  334. }
  335. }
  336. }
  337. /**
  338. * Implements hook_insert().
  339. * When a new chado_analysis node is created we also need to add information
  340. * to our chado_analysis table. This function is called on insert of a new
  341. * node of type 'chado_analysis' and inserts the necessary information.
  342. *
  343. * @ingroup tripal_analysis
  344. */
  345. function chado_analysis_insert($node) {
  346. $node->analysisname = trim($node->analysisname);
  347. $node->description = trim($node->description);
  348. $node->program = trim($node->program);
  349. $node->programversion = trim($node->programversion);
  350. $node->algorithm = trim($node->algorithm);
  351. $node->sourcename = trim($node->sourcename);
  352. $node->sourceversion = trim($node->sourceversion);
  353. $node->sourceuri = trim($node->sourceuri);
  354. // if there is an analysis_id in the $node object then this must be a sync so
  355. // we can skip adding the analysis as it is already there, although
  356. // we do need to proceed with the rest of the insert
  357. if (!property_exists($node, 'analysis_id')) {
  358. // Create a timestamp so we can insert it into the chado database
  359. $time = $node->timeexecuted;
  360. $month = $time['month'];
  361. $day = $time['day'];
  362. $year = $time['year'];
  363. $timestamp = $month . '/' . $day . '/' . $year;
  364. // insert and then get the newly inserted analysis record
  365. $values = array(
  366. 'name' => $node->analysisname,
  367. 'description' => $node->description,
  368. 'program' => $node->program,
  369. 'programversion' => $node->programversion,
  370. 'algorithm' => $node->algorithm,
  371. 'sourcename' => $node->sourcename,
  372. 'sourceversion' => $node->sourceversion,
  373. 'sourceuri' => $node->sourceuri,
  374. 'timeexecuted' => $timestamp
  375. );
  376. $analysis = chado_insert_record('analysis', $values);
  377. if (!$analysis) {
  378. drupal_set_message(t('Unable to add analysis.', 'warning'));
  379. tripal_report_error('tripal_analysis', TRIPAL_ERROR, 'Insert analysis: Unable to create analysis where values:%values',
  380. array('%values' => print_r($values, TRUE)));
  381. return;
  382. }
  383. $analysis_id = $analysis['analysis_id'];
  384. // now add in the properties
  385. $details = array(
  386. 'property_table' => 'analysisprop',
  387. 'base_table' => 'analysis',
  388. 'foreignkey_name' => 'analysis_id',
  389. 'foreignkey_value' => $analysis_id
  390. );
  391. chado_update_node_form_properties($node, $details);
  392. }
  393. else {
  394. $analysis_id = $node->analysis_id;
  395. }
  396. // Make sure the entry for this analysis doesn't already exist in the
  397. // chado_analysis table if it doesn't exist then we want to add it.
  398. $check_org_id = chado_get_id_from_nid('analysis', $node->nid);
  399. if (!$check_org_id) {
  400. $record = new stdClass();
  401. $record->nid = $node->nid;
  402. $record->vid = $node->vid;
  403. $record->analysis_id = $analysis_id;
  404. drupal_write_record('chado_analysis', $record);
  405. }
  406. // add the analysis to the node object for
  407. // use by other analysis modules that may be using this function
  408. $node->analysis = $analysis;
  409. $node->analysis_id = $analysis_id; // we need to set this for children
  410. }
  411. /**
  412. * Implements hook_delete().
  413. * Removes analysis from the chado database.
  414. *
  415. * @ingroup tripal_analysis
  416. */
  417. function chado_analysis_delete($node) {
  418. $analysis_id = chado_get_id_from_nid('analysis', $node->nid);
  419. // if we don't have an analysis id for this node then this isn't a node of
  420. // type chado_analysis or the entry in the chado_analysis table was lost.
  421. if (!$analysis_id) {
  422. return;
  423. }
  424. // Remove data from the {chado_analysis}, {node}, and {node_revisions} tables
  425. $sql_del = "DELETE FROM {chado_analysis} WHERE nid = :nid AND vid = :vid";
  426. db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
  427. $sql_del = "DELETE FROM {node} WHERE nid = :nid AND vid = :vid";
  428. db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
  429. $sql_del = "DELETE FROM {node_revision} WHERE nid = :nid AND vid = :vid";
  430. db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
  431. //Remove from analysis and analysisprop tables of chado database as well
  432. chado_query("DELETE FROM {analysis} WHERE analysis_id = :analysis_id", array(':analysis_id' => $analysis_id));
  433. }
  434. /**
  435. * Implements hook_update().
  436. * Update analyses
  437. *
  438. * @ingroup tripal_analysis
  439. */
  440. function chado_analysis_update($node) {
  441. $node->analysisname = trim($node->analysisname);
  442. $node->description = trim($node->description);
  443. $node->program = trim($node->program);
  444. $node->programversion = trim($node->programversion);
  445. $node->algorithm = trim($node->algorithm);
  446. $node->sourcename = trim($node->sourcename);
  447. $node->sourceversion = trim($node->sourceversion);
  448. $node->sourceuri = trim($node->sourceuri);
  449. // Create a timestamp so we can insert it into the chado database
  450. $time = $node->timeexecuted;
  451. $month = $time['month'];
  452. $day = $time['day'];
  453. $year = $time['year'];
  454. $timestamp = $month . '/' . $day . '/' . $year;
  455. // update the record in Chado
  456. $analysis_id = chado_get_id_from_nid('analysis', $node->nid);
  457. $match = array(
  458. 'analysis_id' => $node->analysis_id,
  459. );
  460. $values = array(
  461. 'name' => $node->analysisname,
  462. 'description' => $node->description,
  463. 'program' => $node->program,
  464. 'programversion' => $node->programversion,
  465. 'algorithm' => $node->algorithm,
  466. 'sourcename' => $node->sourcename,
  467. 'sourceversion' => $node->sourceversion,
  468. 'sourceuri' => $node->sourceuri,
  469. 'timeexecuted' => $timestamp,
  470. 'analysis_id' => $analysis_id
  471. );
  472. $status = chado_update_record('analysis', $match, $values);
  473. if (!$status) {
  474. drupal_set_message(t('Unable to update analysis.', 'warning'));
  475. tripal_report_error('tripal_analysis', TRIPAL_ERROR, 'Update analysis: Unable to update analysis where values: %values',
  476. array('%values' => print_r($values, TRUE)));
  477. }
  478. // now add in the properties by first removing any the analysis
  479. // already has and adding the ones we have
  480. $details = array(
  481. 'property_table' => 'analysisprop',
  482. 'base_table' => 'analysis',
  483. 'foreignkey_name' => 'analysis_id',
  484. 'foreignkey_value' => $analysis_id
  485. );
  486. chado_update_node_form_properties($node, $details);
  487. }
  488. /**
  489. * Implements hook_load().
  490. * When a node is requested by the user this function is called to allow us
  491. * to add auxiliary data to the node object.
  492. *
  493. * @ingroup tripal_analysis
  494. */
  495. function chado_analysis_load($nodes) {
  496. foreach ($nodes as $nid => $node) {
  497. // find the analysis and add in the details
  498. $analysis_id = chado_get_id_from_nid('analysis', $nid);
  499. // build the analysis variable
  500. $values = array('analysis_id' => $analysis_id);
  501. $analysis = chado_generate_var('analysis', $values);
  502. // add in the description field
  503. $analysis = chado_expand_var($analysis, 'field', 'analysis.description');
  504. $nodes[$nid]->analysis = $analysis;
  505. }
  506. }
  507. /**
  508. * Implements hook_access().
  509. *
  510. * This hook allows node modules to limit access to the node types they define.
  511. *
  512. * @param $node
  513. * The node on which the operation is to be performed, or, if it does not yet exist, the
  514. * type of node to be created
  515. *
  516. * @param $op
  517. * The operation to be performed
  518. *
  519. * @param $account
  520. * A user object representing the user for whom the operation is to be performed
  521. *
  522. * @return
  523. * If the permission for the specified operation is not set then return FALSE. If the
  524. * permission is set then return NULL as this allows other modules to disable
  525. * access. The only exception is when the $op == 'create'. We will always
  526. * return TRUE if the permission is set.
  527. *
  528. * @ingroup tripal_analysis
  529. */
  530. function chado_analysis_node_access($node, $op, $account) {
  531. if ($op == 'create') {
  532. if (!user_access('create chado_analysis content', $account)) {
  533. return FALSE;
  534. }
  535. return TRUE;
  536. }
  537. if ($op == 'update') {
  538. if (!user_access('edit chado_analysis content', $account)) {
  539. return FALSE;
  540. }
  541. }
  542. if ($op == 'delete') {
  543. if (!user_access('delete chado_analysis content', $account)) {
  544. return FALSE;
  545. }
  546. }
  547. if ($op == 'view') {
  548. if (!user_access('access chado_analysis content', $account)) {
  549. return FALSE;
  550. }
  551. }
  552. return NULL;
  553. }
  554. /**
  555. * Implements hook_node_view().
  556. * Called for all node types.
  557. *
  558. * @ingroup tripal_analysis
  559. */
  560. function tripal_analysis_node_view($node, $view_mode, $langcode) {
  561. switch ($node->type) {
  562. case 'chado_analysis':
  563. // Show feature browser and counts
  564. if ($view_mode == 'full') {
  565. $node->content['tripal_analysis_base'] = array(
  566. '#markup' => theme('tripal_analysis_base', array('node' => $node)),
  567. '#tripal_toc_id' => 'base',
  568. '#tripal_toc_title' => 'Overview',
  569. '#weight' => -100,
  570. );
  571. $node->content['tripal_analysis_properties'] = array(
  572. '#markup' => theme('tripal_analysis_properties', array('node' => $node)),
  573. '#tripal_toc_id' => 'properties',
  574. '#tripal_toc_title' => 'Properties',
  575. );
  576. }
  577. if ($view_mode == 'teaser') {
  578. $node->content['tripal_analysis_teaser'] = array(
  579. '#markup' => theme('tripal_analysis_teaser', array('node' => $node)),
  580. );
  581. }
  582. break;
  583. }
  584. }
  585. /**
  586. * Implements hook_node_presave().
  587. * Called for all node types.
  588. *
  589. * @ingroup tripal_analysis
  590. */
  591. function tripal_analysis_node_presave($node) {
  592. $name = '';
  593. $program = '';
  594. $programversion = '';
  595. $sourcename = '';
  596. // If this is an analysis of some type it will should have three required
  597. // fields for the Chado analysis table: program, programversion and sourcename.
  598. // So we will set the title for any node that has these three fields. Some extension
  599. // modules will use this module as a type of "inherited" class, so we don't know
  600. // for sure when type of analysis we have. If this is a sync then
  601. if (property_exists($node, 'program') and
  602. property_exists($node, 'programversion') and
  603. property_exists($node, 'sourcename')) {
  604. $name = $node->analysisname;
  605. $program = $node->program;
  606. $programversion = $node->programversion;
  607. $sourcename = $node->sourcename;
  608. // now construct the title
  609. $node->title = "$program ($programversion) $sourcename";
  610. if ($name) {
  611. $node->title = $name;
  612. }
  613. }
  614. else if (property_exists($node, 'analysis')) {
  615. $name = $node->analysis->name;
  616. $program = $node->analysis->program;
  617. $programversion = $node->analysis->programversion;
  618. $sourcename = $node->analysis->sourcename;
  619. // now construct the title
  620. $node->title = "$program ($programversion) $sourcename";
  621. if ($name) {
  622. $node->title = $name;
  623. }
  624. }
  625. }