tripal_analysis.chado_node.inc 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  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. // get the analysis properties
  212. $properties = array();
  213. $properties[] = 'Select a Property';
  214. $sql = "
  215. SELECT DISTINCT CVT.cvterm_id, CVT.name, CVT.definition
  216. FROM {cvterm} CVT
  217. INNER JOIN {cv} ON CVT.cv_id = CV.cv_id
  218. WHERE
  219. CV.name = 'analysis_property' AND
  220. NOT CVT.is_obsolete = 1
  221. ORDER BY CVT.name ASC
  222. ";
  223. $prop_types = chado_query($sql);
  224. while ($prop = $prop_types->fetchObject()) {
  225. $properties[$prop->cvterm_id] = $prop->name;
  226. }
  227. $exclude = array();
  228. $include = array();
  229. $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") . ".");
  230. tripal_core_properties_form($form, $form_state, 'analysisprop', 'analysis_id', 'analysis_property',
  231. $properties, $analysis_id, $exclude, $include, $instructions, 'Properties');
  232. return $form;
  233. }
  234. /**
  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 = tripal_core_chado_select('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 = tripal_core_chado_select('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 = tripal_core_chado_select('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 = tripal_core_chado_select('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 = tripal_core_chado_select('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. * When a new chado_analysis node is created we also need to add information
  337. * to our chado_analysis table. This function is called on insert of a new
  338. * node of type 'chado_analysis' and inserts the necessary information.
  339. *
  340. * @ingroup tripal_analysis
  341. */
  342. function chado_analysis_insert($node) {
  343. $node->analysisname = trim($node->analysisname);
  344. $node->description = trim($node->description);
  345. $node->program = trim($node->program);
  346. $node->programversion = trim($node->programversion);
  347. $node->algorithm = trim($node->algorithm);
  348. $node->sourcename = trim($node->sourcename);
  349. $node->sourceversion = trim($node->sourceversion);
  350. $node->sourceuri = trim($node->sourceuri);
  351. // if there is an analysis_id in the $node object then this must be a sync so
  352. // we can skip adding the analysis as it is already there, although
  353. // we do need to proceed with the rest of the insert
  354. if (!property_exists($node, 'analysis_id')) {
  355. // Create a timestamp so we can insert it into the chado database
  356. $time = $node->timeexecuted;
  357. $month = $time['month'];
  358. $day = $time['day'];
  359. $year = $time['year'];
  360. $timestamp = $month . '/' . $day . '/' . $year;
  361. // insert and then get the newly inserted analysis record
  362. $values = array(
  363. 'name' => $node->analysisname,
  364. 'description' => $node->description,
  365. 'program' => $node->program,
  366. 'programversion' => $node->programversion,
  367. 'algorithm' => $node->algorithm,
  368. 'sourcename' => $node->sourcename,
  369. 'sourceversion' => $node->sourceversion,
  370. 'sourceuri' => $node->sourceuri,
  371. 'timeexecuted' => $timestamp
  372. );
  373. $analysis = tripal_core_chado_insert('analysis', $values);
  374. if (!$analysis) {
  375. drupal_set_message(t('Unable to add analysis.', 'warning'));
  376. watchdog('tripal_analysis', 'Insert analysis: Unable to create analysis where values:%values',
  377. array('%values' => print_r($values, TRUE)), WATCHDOG_ERROR);
  378. return;
  379. }
  380. $analysis_id = $analysis['analysis_id'];
  381. // now add in the properties
  382. $properties = tripal_core_properties_form_retreive($node, 'analysis_property');
  383. foreach ($properties as $property => $elements) {
  384. foreach ($elements as $rank => $value) {
  385. $status = tripal_analysis_insert_property($analysis_id, $property, $value, FALSE, 'analysis_property');
  386. if (!$status) {
  387. drupal_set_message("Error cannot add property: $property", "error");
  388. watchdog('t_analysis', "Error cannot add property: %prop",
  389. array('%property' => $property), WATCHDOG_ERROR);
  390. }
  391. }
  392. }
  393. }
  394. else {
  395. $analysis_id = $node->analysis_id;
  396. }
  397. // Make sure the entry for this analysis doesn't already exist in the
  398. // chado_analysis table if it doesn't exist then we want to add it.
  399. $check_org_id = chado_get_id_for_node('analysis', $node->nid);
  400. if (!$check_org_id) {
  401. $record = new stdClass();
  402. $record->nid = $node->nid;
  403. $record->vid = $node->vid;
  404. $record->analysis_id = $analysis_id;
  405. drupal_write_record('chado_analysis', $record);
  406. }
  407. // add the analysis to the node object for
  408. // use by other analysis modules that may be using this function
  409. $node->analysis = $analysis;
  410. $node->analysis_id = $analysis_id; // we need to set this for children
  411. }
  412. /**
  413. * Removes analysis from the chado database
  414. *
  415. * @param $node
  416. * The node object specifying which chado record to delete
  417. *
  418. * @ingroup tripal_analysis
  419. */
  420. function chado_analysis_delete($node) {
  421. $analysis_id = chado_get_id_for_node('analysis', $node->nid);
  422. // if we don't have an analysis id for this node then this isn't a node of
  423. // type chado_analysis or the entry in the chado_analysis table was lost.
  424. if (!$analysis_id) {
  425. return;
  426. }
  427. // Remove data from the {chado_analysis}, {node}, and {node_revisions} tables
  428. $sql_del = "DELETE FROM {chado_analysis} WHERE nid = :nid AND vid = :vid";
  429. db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
  430. $sql_del = "DELETE FROM {node} WHERE nid = :nid AND vid = :vid";
  431. db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
  432. $sql_del = "DELETE FROM {node_revision} WHERE nid = :nid AND vid = :vid";
  433. db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
  434. //Remove from analysis and analysisprop tables of chado database as well
  435. chado_query("DELETE FROM {analysis} WHERE analysis_id = :analysis_id", array(':analysis_id' => $analysis_id));
  436. }
  437. /**
  438. * Update analyses
  439. *
  440. * @param $node
  441. * The updated node object
  442. *
  443. * @ingroup tripal_analysis
  444. */
  445. function chado_analysis_update($node) {
  446. $node->analysisname = trim($node->analysisname);
  447. $node->description = trim($node->description);
  448. $node->program = trim($node->program);
  449. $node->programversion = trim($node->programversion);
  450. $node->algorithm = trim($node->algorithm);
  451. $node->sourcename = trim($node->sourcename);
  452. $node->sourceversion = trim($node->sourceversion);
  453. $node->sourceuri = trim($node->sourceuri);
  454. // Create a timestamp so we can insert it into the chado database
  455. $time = $node->timeexecuted;
  456. $month = $time['month'];
  457. $day = $time['day'];
  458. $year = $time['year'];
  459. $timestamp = $month . '/' . $day . '/' . $year;
  460. // update the record in Chado
  461. $analysis_id = chado_get_id_for_node('analysis', $node->nid);
  462. $match = array(
  463. 'analysis_id' => $node->analysis_id,
  464. );
  465. $values = array(
  466. 'name' => $node->analysisname,
  467. 'description' => $node->description,
  468. 'program' => $node->program,
  469. 'programversion' => $node->programversion,
  470. 'algorithm' => $node->algorithm,
  471. 'sourcename' => $node->sourcename,
  472. 'sourceversion' => $node->sourceversion,
  473. 'sourceuri' => $node->sourceuri,
  474. 'timeexecuted' => $timestamp,
  475. 'analysis_id' => $analysis_id
  476. );
  477. $status = tripal_core_chado_update('analysis', $match, $values);
  478. if (!$status) {
  479. drupal_set_message(t('Unable to update analysis.', 'warning'));
  480. watchdog('tripal_analysis', 'Update analysis: Unable to update analysis where values: %values',
  481. array('%values' => print_r($values, TRUE)), WATCHDOG_ERROR);
  482. }
  483. // now add in the properties by first removing any the analysis
  484. // already has and adding the ones we have
  485. tripal_core_chado_delete('analysisprop', array('analysis_id' => $analysis_id));
  486. $properties = tripal_core_properties_form_retreive($node, 'analysis_property');
  487. foreach ($properties as $property => $elements) {
  488. foreach ($elements as $rank => $value) {
  489. $status = tripal_analysis_insert_property($analysis_id, $property, $value, FALSE, 'analysis_property');
  490. if (!$status) {
  491. drupal_set_message("Error cannot add property: '$property'", "error");
  492. watchdog('t_analysis', "Error cannot add property: '%prop'",
  493. array('%prop' => $property), WATCHDOG_ERROR);
  494. }
  495. }
  496. }
  497. }
  498. /**
  499. * When a node is requested by the user this function is called to allow us
  500. * to add auxiliary data to the node object.
  501. *
  502. * @ingroup tripal_analysis
  503. */
  504. function chado_analysis_load($nodes) {
  505. foreach ($nodes as $nid => $node) {
  506. // find the analysis and add in the details
  507. $analysis_id = chado_get_id_for_node('analysis', $nid);
  508. // build the analysis variable
  509. $values = array('analysis_id' => $analysis_id);
  510. $analysis = tripal_core_generate_chado_var('analysis', $values);
  511. // add in the description field
  512. $analysis = tripal_core_expand_chado_vars($analysis, 'field', 'analysis.description');
  513. $nodes[$nid]->analysis = $analysis;
  514. }
  515. }
  516. /**
  517. * Implement hook_access().
  518. *
  519. * This hook allows node modules to limit access to the node types they define.
  520. *
  521. * @param $node
  522. * The node on which the operation is to be performed, or, if it does not yet exist, the
  523. * type of node to be created
  524. *
  525. * @param $op
  526. * The operation to be performed
  527. *
  528. * @param $account
  529. * A user object representing the user for whom the operation is to be performed
  530. *
  531. * @return
  532. * If the permission for the specified operation is not set then return FALSE. If the
  533. * permission is set then return NULL as this allows other modules to disable
  534. * access. The only exception is when the $op == 'create'. We will always
  535. * return TRUE if the permission is set.
  536. *
  537. * @ingroup tripal_analysis
  538. */
  539. function chado_analysis_node_access($node, $op, $account) {
  540. if ($op == 'create') {
  541. if (!user_access('create chado_analysis content', $account)) {
  542. return FALSE;
  543. }
  544. return TRUE;
  545. }
  546. if ($op == 'update') {
  547. if (!user_access('edit chado_analysis content', $account)) {
  548. return FALSE;
  549. }
  550. }
  551. if ($op == 'delete') {
  552. if (!user_access('delete chado_analysis content', $account)) {
  553. return FALSE;
  554. }
  555. }
  556. if ($op == 'view') {
  557. if (!user_access('access chado_analysis content', $account)) {
  558. return FALSE;
  559. }
  560. }
  561. return NULL;
  562. }
  563. /**
  564. *
  565. * @ingroup tripal_analysis
  566. */
  567. function tripal_analysis_node_view($node, $view_mode, $langcode) {
  568. switch ($node->type) {
  569. case 'chado_analysis':
  570. // Show feature browser and counts
  571. if ($view_mode == 'full') {
  572. $node->content['tripal_analysis_base'] = array(
  573. '#value' => theme('tripal_analysis_base', array('node' => $node)),
  574. );
  575. $node->content['tripal_analysis_properties'] = array(
  576. '#value' => theme('tripal_analysis_properties', array('node' => $node)),
  577. );
  578. }
  579. if ($view_mode == 'teaser') {
  580. $node->content['tripal_analysis_teaser'] = array(
  581. '#value' => theme('tripal_analysis_teaser', array('node' => $node)),
  582. );
  583. }
  584. break;
  585. }
  586. }
  587. /**
  588. *
  589. * @param $node
  590. */
  591. function tripal_analysis_node_presave($node) {
  592. // If this is an analysis of some type it will should have thre three required
  593. // fields for the Chado analysis table: program, programversion and sourcename.
  594. // So we will set the title for any node that has these three fields
  595. if (property_exists($node, 'program') and
  596. property_exists($node, 'programversion') and
  597. property_exists($node, 'sourcename')) {
  598. if ($node->analysisname) {
  599. $node->title = $node->analysisname;
  600. }
  601. else {
  602. $node->title = "$node->program ($node->programversion) $node->sourcename";
  603. }
  604. }
  605. }