tripal_analysis.chado_node.inc 24 KB

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