tripal_analysis.module 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  1. <?php
  2. /**
  3. * @file
  4. * Contains all the main hook implementations for the tripal_analysis module
  5. *
  6. * @defgroup tripal_analysis Analysis Module
  7. * @ingroup tripal_modules
  8. * @{
  9. * Provides functions for managing chado analysis' including creating details pages for each one
  10. *
  11. * @}
  12. *
  13. *
  14. */
  15. require('api/tripal_analysis.api.inc');
  16. require('includes/tripal_analysis_privacy.inc');
  17. /**
  18. * Add tripal javascript to page headers
  19. *
  20. * @ingroup tripal_analysis
  21. */
  22. function tripal_analysis_init() {
  23. drupal_add_js(drupal_get_path('theme', 'tripal') . '/js/tripal_analysis.js');
  24. }
  25. /**
  26. * Implementation of hook_menu().
  27. * Entry points and paths of the module
  28. *
  29. * @ingroup tripal_analysis
  30. */
  31. function tripal_analysis_menu() {
  32. //Sync analysis
  33. $items['chado_sync_analyses'] = array(
  34. 'title' => 'Sync Data',
  35. 'page callback' => 'tripal_analysis_sync_analyses',
  36. 'access arguments' => array('administer tripal analyses'),
  37. 'type' => MENU_CALLBACK
  38. );
  39. // Tripal Analysis administrative settings
  40. $items['admin/tripal/tripal_analysis'] = array(
  41. 'title' => 'Analyses',
  42. 'description' => 'Basic Description of Tripal Analysis Module Functionality.',
  43. 'page callback' => 'theme',
  44. 'page arguments' => array('tripal_analysis_admin'),
  45. 'access arguments' => array('administer tripal analyses'),
  46. 'type' => MENU_NORMAL_ITEM,
  47. 'file' => 'includes/tripal_analysis.admin.inc',
  48. );
  49. $items['admin/tripal/tripal_analysis/configuration'] = array(
  50. 'title' => 'Configuration',
  51. 'description' => 'Settings for the displays of analysis results.',
  52. 'page callback' => 'drupal_get_form',
  53. 'page arguments' => array('tripal_analysis_admin'),
  54. 'access arguments' => array('administer tripal analyses'),
  55. 'type' => MENU_NORMAL_ITEM,
  56. 'file' => 'includes/tripal_analysis.admin.inc',
  57. );
  58. return $items;
  59. }
  60. /**
  61. * Provide information to drupal about the node types that we're creating
  62. * in this module
  63. *
  64. * @ingroup tripal_analysis
  65. */
  66. function tripal_analysis_node_info() {
  67. $nodes = array();
  68. $nodes['chado_analysis'] = array(
  69. 'name' => t('Analysis'),
  70. 'module' => 'chado_analysis',
  71. 'description' => t('An analysis from the chado database'),
  72. 'has_title' => FALSE,
  73. 'title_label' => t('Analysis'),
  74. 'has_body' => FALSE,
  75. 'body_label' => t('Analysis Description'),
  76. 'locked' => TRUE
  77. );
  78. return $nodes;
  79. }
  80. /**
  81. * When a new chado_analysis node is created we also need to add information
  82. * to our chado_analysis table. This function is called on insert of a new
  83. * node of type 'chado_analysis' and inserts the necessary information.
  84. *
  85. * @ingroup tripal_analysis
  86. */
  87. function chado_analysis_insert($node) {
  88. global $user;
  89. // Create a timestamp so we can insert it into the chado database
  90. $time = $node->timeexecuted;
  91. $month = $time['month'];
  92. $day = $time['day'];
  93. $year = $time['year'];
  94. $timestamp = $month . '/' . $day . '/' . $year;
  95. // If this analysis already exists then don't recreate it in chado
  96. $analysis_id = $node->analysis_id;
  97. if ($analysis_id) {
  98. $values = array('analysis_id' => $node->analysis_id);
  99. $result = tripal_core_chado_select('analysis', array('analysis_id'), $values);
  100. if($result and count($result) > 0) {
  101. $analysis = $result[0];
  102. }
  103. }
  104. // If the analysis doesn't exist then let's create it in chado.
  105. if (!$analysis) {
  106. // insert and then get the newly inserted analysis record
  107. $values = array(
  108. 'name' => $node->analysisname,
  109. 'description' => $node->description,
  110. 'program' => $node->program,
  111. 'programversion' => $node->programversion,
  112. 'algorithm' => $node->algorithm,
  113. 'sourcename' => $node->sourcename,
  114. 'sourceversion' => $node->sourceversion,
  115. 'sourceuri' => $node->sourceuri,
  116. 'timeexecuted' => $timestamp
  117. );
  118. if (tripal_core_chado_insert('analysis', $values)) {
  119. $analysis = tripal_core_chado_select('analysis', array('*'), $values);
  120. $analysis_id = $analysis[0]->analysis_id;
  121. }
  122. }
  123. // Make sure the entry for this analysis doesn't already exist in the
  124. // chado_analysis table if it doesn't exist then we want to add it.
  125. $node_check_sql = "SELECT * FROM {chado_analysis} ".
  126. "WHERE analysis_id = %d";
  127. $node_check = db_fetch_object(db_query($node_check_sql, $analysis_id));
  128. if (!$node_check) {
  129. // next add the item to the drupal table
  130. $sql = "INSERT INTO {chado_analysis} (nid, vid, analysis_id) ".
  131. "VALUES (%d, %d, %d)";
  132. db_query($sql, $node->nid, $node->vid, $analysis_id);
  133. // Create a title for the analysis node using the unique keys so when the
  134. // node is saved, it will have a title
  135. $record = new stdClass();
  136. // If the analysis has a name, use it as the node title. If not, construct
  137. // the title using program, programversion, and sourcename
  138. if ($node->analysisname) {
  139. $record->title = $node->analysisname;
  140. }
  141. else {
  142. //Construct node title as "program (version)
  143. $record->title = "$node->program ($node->programversion)";
  144. }
  145. $record->nid = $node->nid;
  146. drupal_write_record('node', $record, 'nid');
  147. drupal_write_record('node_revisions', $record, 'nid');
  148. }
  149. // add the analysis to the node object for
  150. // use by other analysis modules that may be using this function
  151. $node->analysis = $analysis;
  152. $node->analysis_id = $analysis_id; // we need to set this for children
  153. }
  154. /**
  155. * Removes analysis from the chado database
  156. *
  157. * @param $node
  158. * The node object specifying which chado record to delete
  159. *
  160. * @ingroup tripal_analysis
  161. */
  162. function chado_analysis_delete($node) {
  163. $analysis_id = chado_get_id_for_node('analysis', $node);
  164. // if we don't have an organism id for this node then this isn't a node of
  165. // type chado_organism or the entry in the chado_organism table was lost.
  166. if (!$analysis_id) {
  167. return;
  168. }
  169. // Remove data from the {chado_analysis}, {node}, and {node_revisions} tables
  170. $sql_del = "DELETE FROM {chado_analysis} ".
  171. "WHERE nid = %d ".
  172. "AND vid = %d";
  173. db_query($sql_del, $node->nid, $node->vid);
  174. $sql_del = "DELETE FROM {node} ".
  175. "WHERE nid = %d ".
  176. "AND vid = %d";
  177. db_query($sql_del, $node->nid, $node->vid);
  178. $sql_del = "DELETE FROM {node_revisions} ".
  179. "WHERE nid = %d ".
  180. "AND vid = %d";
  181. db_query($sql_del, $node->nid, $node->vid);
  182. //Remove from analysis and analysisprop tables of chado database as well
  183. chado_query("DELETE FROM {analysis} WHERE analysis_id = %d", $analysis_id);
  184. }
  185. /**
  186. * Update analyses
  187. *
  188. * @param $node
  189. * The updated node object
  190. *
  191. * @ingroup tripal_analysis
  192. */
  193. function chado_analysis_update($node) {
  194. global $user;
  195. if ($node->revision) {
  196. // TODO -- decide what to do about revisions
  197. }
  198. // Create a timestamp so we can insert it into the chado database
  199. $time = $node->timeexecuted;
  200. $month = $time['month'];
  201. $day = $time['day'];
  202. $year = $time['year'];
  203. $timestamp = $month . '/' . $day . '/' . $year;
  204. // get the analysis_id for this node:
  205. $sql = "SELECT analysis_id ".
  206. "FROM {chado_analysis} ".
  207. "WHERE nid = %d";
  208. $analysis_id = db_fetch_object(db_query($sql, $node->nid))->analysis_id;
  209. $sql = "UPDATE {analysis} ".
  210. "SET name = '%s', ".
  211. " description = '%s', ".
  212. " program = '%s', ".
  213. " programversion = '%s', ".
  214. " algorithm = '%s', ".
  215. " sourcename = '%s', ".
  216. " sourceversion = '%s', ".
  217. " sourceuri = '%s', ".
  218. " timeexecuted = '%s' ".
  219. "WHERE analysis_id = %d ";
  220. chado_query($sql, $node->analysisname, $node->description, $node->program,
  221. $node->programversion, $node->algorithm, $node->sourcename,
  222. $node->sourceversion, $node->sourceuri, $timestamp, $analysis_id);
  223. // Create a title for the analysis node using the unique keys so when the
  224. // node is saved, it will have a title
  225. $record = new stdClass();
  226. // If the analysis has a name, use it as the node title. If not, construct
  227. // the title using program, programversion, and sourcename
  228. if ($node->analysisname) {
  229. $record->title = $node->analysisname;
  230. }
  231. else {
  232. //Construct node title as "program (version)
  233. $record->title = "$node->program ($node->programversion)";
  234. }
  235. $record->nid = $node->nid;
  236. drupal_write_record('node', $record, 'nid');
  237. drupal_write_record('node_revisions', $record, 'nid');
  238. }
  239. /**
  240. * When editing or creating a new node of type 'chado_analysis' we need
  241. * a form. This function creates the form that will be used for this.
  242. *
  243. * @ingroup tripal_analysis
  244. */
  245. function chado_analysis_form($node) {
  246. $analysis = $node->analysis;
  247. // add in the description column. It is a text field and may not be included
  248. // if the text is too big.
  249. $analysis = tripal_core_expand_chado_vars($analysis, 'field', 'analysis.description');
  250. // get form defaults
  251. $analysis_id = $node->analysis_id;
  252. if (!$analysis_id) {
  253. $analysis_id = $analysis->analysis_id;
  254. }
  255. $analysisname = $node->analysisname;
  256. if (!$analysisname) {
  257. $analysisname = $analysis->name;
  258. }
  259. $program = $node->program;
  260. if (!$program) {
  261. $program = $analysis->program;
  262. }
  263. $programversion = $node->programversion;
  264. if (!$programversion) {
  265. $programversion = $analysis->programversion;
  266. }
  267. $algorithm = $node->algorithm;
  268. if (!$algorithm) {
  269. $algorithm = $analysis->algorithm;
  270. }
  271. $sourcename = $node->sourcename;
  272. if (!$sourcename) {
  273. $sourcename = $analysis->sourcename;
  274. }
  275. $sourceversion = $node->sourceversion;
  276. if (!$sourceversion) {
  277. $sourceversion = $analysis->sourceversion;
  278. }
  279. $sourceuri = $node->sourceuri;
  280. if (!$sourceuri) {
  281. $sourceuri = $analysis->sourceuri;
  282. }
  283. $timeexecuted = $node->timeexecuted;
  284. if (!$timeexecuted) {
  285. $timeexecuted = $analysis->timeexecuted;
  286. }
  287. $description = $node->description;
  288. if (!$description) {
  289. $description = $analysis->description;
  290. }
  291. $form = array();
  292. $form['title']= array(
  293. '#type' => 'hidden',
  294. '#default_value' => $node->title,
  295. );
  296. $form['analysis_id']= array(
  297. '#type' => 'hidden',
  298. '#default_value' => $analysis_id,
  299. );
  300. $form['analysisname']= array(
  301. '#type' => 'textfield',
  302. '#title' => t('Analysis Name'),
  303. '#required' => TRUE,
  304. '#default_value' => $analysisname,
  305. '#description' => t("This should be a brief name that
  306. describes the analysis succintly. This name will helps the user find analyses."),
  307. );
  308. $form['program']= array(
  309. '#type' => 'textfield',
  310. '#title' => t('Program'),
  311. '#required' => TRUE,
  312. '#default_value' => $program,
  313. '#description' => t("Program name, e.g. blastx, blastp, sim4, genscan."),
  314. );
  315. $form['programversion']= array(
  316. '#type' => 'textfield',
  317. '#title' => t('Program Version'),
  318. '#required' => TRUE,
  319. '#default_value' => $programversion,
  320. '#description' => t("Version description, e.g. TBLASTX 2.0MP-WashU [09-Nov-2000]. Enter 'n/a' if no version is available."),
  321. );
  322. $form['algorithm']= array(
  323. '#type' => 'textfield',
  324. '#title' => t('Algorithm'),
  325. '#required' => FALSE,
  326. '#default_value' => $algorithm,
  327. '#description' => t("Algorithm name, e.g. blast."),
  328. );
  329. $form['sourcename']= array(
  330. '#type' => 'textfield',
  331. '#title' => t('Source Name'),
  332. '#required' => TRUE,
  333. '#default_value' => $sourcename,
  334. '#description' => t('The name of the source data. This could be a file name, data set name or a
  335. small description for how the data was collected. For long descriptions use the description field below'),
  336. );
  337. $form['sourceversion']= array(
  338. '#type' => 'textfield',
  339. '#title' => t('Source Version'),
  340. '#required' => FALSE,
  341. '#default_value' => $sourceversion,
  342. '#description' => t('If the source dataset has a version, include it here'),
  343. );
  344. $form['sourceuri']= array(
  345. '#type' => 'textfield',
  346. '#title' => t('Source URI'),
  347. '#required' => FALSE,
  348. '#default_value' => $sourceuri,
  349. '#description' => t("This is a permanent URL or URI for the source of the analysis.
  350. Someone could recreate the analysis directly by going to this URI and
  351. fetching the source data (e.g. the blast database, or the training model)."),
  352. );
  353. // Get time saved in chado
  354. $default_time = $timeexecuted;
  355. $year = preg_replace("/^(\d+)-\d+-\d+ .*/", "$1", $default_time);
  356. $month = preg_replace("/^\d+-0?(\d+)-\d+ .*/", "$1", $default_time);
  357. $day = preg_replace("/^\d+-\d+-0?(\d+) .*/", "$1", $default_time);
  358. // If the time is not set, use current time
  359. if (!$default_time) {
  360. $default_time = time();
  361. $year = format_date($default_time, 'custom', 'Y');
  362. $month = format_date($default_time, 'custom', 'n');
  363. $day = format_date($default_time, 'custom', 'j');
  364. }
  365. $form['timeexecuted']= array(
  366. '#type' => 'date',
  367. '#title' => t('Time Executed'),
  368. '#required' => TRUE,
  369. '#default_value' => array(
  370. 'year' => $year,
  371. 'month' => $month,
  372. 'day' => $day,
  373. ),
  374. );
  375. $form['description']= array(
  376. '#type' => 'textarea',
  377. '#rows' => 15,
  378. '#title' => t('Materials & Methods (Description and/or Program Settings)'),
  379. '#required' => FALSE,
  380. '#default_value' => $description,
  381. '#description' => t('Please provide all necessary information to allow
  382. someone to recreate the analysis, including materials and methods
  383. for collection of the source data and performing the analysis'),
  384. );
  385. return $form;
  386. }
  387. /**
  388. * When a node is requested by the user this function is called to allow us
  389. * to add auxiliary data to the node object.
  390. *
  391. * @ingroup tripal_analysis
  392. */
  393. function chado_analysis_load($node) {
  394. // get the feature details from chado
  395. $analysis_id = chado_get_id_for_node('analysis', $node);
  396. $values = array('analysis_id' => $analysis_id);
  397. $analysis = tripal_core_generate_chado_var('analysis', $values);
  398. $additions = new stdClass();
  399. $additions->analysis = $analysis;
  400. return $additions;
  401. }
  402. /**
  403. * This function customizes the view of the chado_analysis node. It allows
  404. * us to generate the markup.
  405. *
  406. * @ingroup tripal_analysis
  407. */
  408. function chado_analysis_view($node, $teaser = FALSE, $page = FALSE) {
  409. // use drupal's default node view:
  410. if (!$teaser) {
  411. $node = node_prepare($node, $teaser);
  412. // When previewing a node submitting form, it shows 'Array' instead of
  413. // correct date format. We need to format the date here
  414. $time = $node->timeexecuted;
  415. if (is_array($time)) {
  416. $month = $time['month'];
  417. $day = $time['day'];
  418. $year = $time['year'];
  419. $timestamp = $year . '-' . $month . '-' . $day;
  420. $node->timeexecuted = $timestamp;
  421. }
  422. }
  423. return $node;
  424. }
  425. /**
  426. * Validates the user input before creating an analysis node
  427. *
  428. * @ingroup tripal_analysis
  429. */
  430. function chado_analysis_validate($node, &$form) {
  431. // use the analysis parent to validate the node
  432. tripal_analysis_validate($node, $form);
  433. }
  434. /**
  435. * This validation is being used for three activities:
  436. * CASE A: Update a node that exists in both drupal and chado
  437. * CASE B: Synchronizing a node from chado to drupal
  438. * CASE C: Inserting a new node that exists in niether drupal nor chado
  439. *
  440. * @ingroup tripal_analysis
  441. */
  442. function tripal_analysis_validate($node, &$form) {
  443. // Only nodes being updated will have an nid already
  444. if (!is_null($node->nid)) {
  445. // CASE A: We are validating a form for updating an existing node
  446. // get the existing node
  447. $values = array('analysis_id' => $node->analysis_id);
  448. $result = tripal_core_chado_select('analysis', array('*'), $values);
  449. $analysis = $result[0];
  450. // if the name has changed make sure it doesn't conflict with an existing name
  451. if($analysis->name != $node->analysisname) {
  452. $values = array('name' => $node->analysisname);
  453. $result = tripal_core_chado_select('analysis', array('analysis_id'), $values);
  454. if($result and count($result) > 0) {
  455. form_set_error('analysisname', 'Cannot update the analysis with this analysis name. An analysis with this name already exists.');
  456. return;
  457. }
  458. }
  459. // if the unique constraint has changed check to make sure it doesn't conflict with an
  460. // existing record
  461. if($analysis->program != $node->program or $analysis->programversion != $node->programversion or
  462. $analysis->sourcename != $node->sourcename) {
  463. $values = array(
  464. 'program' => $node->program,
  465. 'programversion' => $node->programversion,
  466. 'sourcename' => $node->sourcename,
  467. );
  468. $result = tripal_core_chado_select('analysis', array('analysis_id'), $values);
  469. if ($result and count($result) > 0) {
  470. if ($analysis->program != $node->program) {
  471. $field = 'program';
  472. }
  473. if ($analysis->programversion != $node->programversion) {
  474. $field = 'programversion';
  475. }
  476. if ($analysis->sourcename != $node->sourcename) {
  477. $field = 'sourcename';
  478. }
  479. form_set_error($field, 'Cannot update the analysis with this program,
  480. program version and source name. An analysis with these values already exists.');
  481. return;
  482. }
  483. }
  484. }
  485. else{
  486. // To differentiate if we are syncing or creating a new analysis altogther, see if an
  487. // analysis_id already exists
  488. if ($node->analysis_id and $node->analysis_id != 0) {
  489. // CASE B: Synchronizing a node from chado to drupal
  490. // we don't need to do anything.
  491. }
  492. else {
  493. // CASE C: We are validating a form for inserting a new node
  494. // The unique constraint for the chado analysis table is: program, programversion, sourcename
  495. $values = array(
  496. 'program' => $node->program,
  497. 'programversion' => $node->programversion,
  498. 'sourcename' => $node->sourcename,
  499. );
  500. $analysis = tripal_core_chado_select('analysis', array('analysis_id'), $values);
  501. if ($analysis and count($analysis) > 0) {
  502. form_set_error('program', 'Cannot add the analysis with this program,
  503. program version and source name. An analysis with these values already exists.');
  504. return;
  505. }
  506. // make sure we have a unique analysis name. This is not a requirement
  507. // for the analysis table but we use the analysis name for the Drupal node
  508. // title, so it should be unique
  509. $values = array('name' => $node->analysisname);
  510. $result = tripal_core_chado_select('analysis', array('analysis_id'), $values);
  511. if($result and count($result) > 0) {
  512. form_set_error('analysisname', 'Cannot add the analysis with this analysis name. An analysis with this name already exists.');
  513. return;
  514. }
  515. }
  516. }
  517. }
  518. /**
  519. * Display help and module information
  520. * @param path which path of the site we're displaying help
  521. * @param arg array that holds the current path as would be returned from arg()
  522. * function
  523. * @return help text for the path
  524. *
  525. * @ingroup tripal_analysis
  526. */
  527. function tripal_analysis_help($path, $arg) {
  528. $output = '';
  529. switch ($path) {
  530. case "admin/help#tripal_analysis":
  531. $output = '<p>' .
  532. t("Displays links to nodes created on this date") .
  533. '</p>';
  534. break;
  535. }
  536. return $output;
  537. }
  538. /**
  539. * The following function proves access control for users trying to
  540. * perform actions on data managed by this module
  541. *
  542. * @ingroup tripal_analysis
  543. */
  544. function chado_analysis_access($op, $node, $account) {
  545. if ($op == 'create') {
  546. if (!user_access('create chado_analysis content', $account)) {
  547. return FALSE;
  548. }
  549. }
  550. if ($op == 'update') {
  551. if (!user_access('edit chado_analysis content', $account)) {
  552. return FALSE;
  553. }
  554. }
  555. if ($op == 'delete') {
  556. if (!user_access('delete chado_analysis content', $account)) {
  557. return FALSE;
  558. }
  559. }
  560. if ($op == 'view') {
  561. if (!user_access('access chado_analysis content', $account)) {
  562. return FALSE;
  563. }
  564. }
  565. return NULL;
  566. }
  567. /**
  568. * Set the permission types that the chado module uses. Essentially we
  569. * want permissionis that protect creation, editing and deleting of chado
  570. * data objects
  571. *
  572. * @ingroup tripal_analysis
  573. */
  574. function tripal_analysis_perm() {
  575. return array(
  576. 'access chado_analysis content',
  577. 'create chado_analysis content',
  578. 'delete chado_analysis content',
  579. 'edit chado_analysis content',
  580. 'administer tripal analyses',
  581. );
  582. }
  583. /**
  584. * We need to let drupal know about our theme functions and their arguments.
  585. * We create theme functions to allow users of the module to customize the
  586. * look and feel of the output generated in this module
  587. *
  588. * @ingroup tripal_analysis
  589. */
  590. function tripal_analysis_theme() {
  591. return array(
  592. 'tripal_analysis_base' => array(
  593. 'arguments' => array('node' => NULL),
  594. 'template' => 'tripal_analysis_base',
  595. ),
  596. 'tripal_feature_analyses' => array(
  597. 'template' => 'tripal_feature_analyses',
  598. 'arguments' => array('node' => NULL),
  599. ),
  600. 'tripal_analysis_admin' => array(
  601. 'template' => 'tripal_analysis_admin',
  602. 'arguments' => array(NULL),
  603. 'path' => drupal_get_path('module', 'tripal_analysis') . '/theme',
  604. ),
  605. );
  606. }
  607. /**
  608. *
  609. *
  610. * @ingroup tripal_feature
  611. */
  612. function tripal_analysis_block($op = 'list', $delta = 0, $edit=array()) {
  613. switch ($op) {
  614. case 'list':
  615. $blocks['base']['info'] = t('Tripal Analysis Details');
  616. $blocks['base']['cache'] = BLOCK_NO_CACHE;
  617. $blocks['featureblast']['info'] = t('Tripal Feature Analyses');
  618. $blocks['featureblast']['cache'] = BLOCK_NO_CACHE;
  619. return $blocks;
  620. case 'view':
  621. if (user_access('access chado_analysis content') and arg(0) == 'node' and is_numeric(arg(1))) {
  622. $nid = arg(1);
  623. $node = node_load($nid);
  624. $block = array();
  625. switch ($delta) {
  626. case 'base':
  627. $block['subject'] = t('Analysis Details');
  628. $block['content'] = theme('tripal_analysis_base', $node);
  629. break;
  630. case 'tripal_feature_analyses':
  631. $block['subject'] = t('Feature Analyses');
  632. $block['content'] = theme('tripal_feature_analyses', $node);
  633. break;
  634. default :
  635. }
  636. return $block;
  637. }
  638. }
  639. }
  640. /*******************************************************************************
  641. * tripal_analysis_nodeapi()
  642. * HOOK: Implementation of hook_nodeapi()
  643. * Display blast results for allowed node types
  644. */
  645. function tripal_analysis_nodeapi(&$node, $op, $teaser, $page) {
  646. switch ($op) {
  647. case 'view':
  648. if ($teaser) {
  649. return '';
  650. }
  651. // Abort if this node is not one of the types we should show.
  652. if (strcmp($node->type, 'chado_feature') == 0) {
  653. if ($node->build_mode == NODE_BUILD_SEARCH_INDEX) {
  654. // return results for searching
  655. }
  656. else {
  657. // return normal results
  658. $node->content['tripal_feature_analyses'] = array(
  659. '#value' => theme('tripal_feature_analyses', $node),
  660. '#weight' => 8
  661. );
  662. }
  663. }
  664. break;
  665. }
  666. }
  667. /**
  668. * Implements hook_views_api()
  669. * Purpose: Essentially this hook tells drupal that there is views support for
  670. * for this module which then includes tripal_analysis.views.inc where all the
  671. * views integration code is
  672. *
  673. * @ingroup tripal_analysis
  674. */
  675. function tripal_analysis_views_api() {
  676. return array(
  677. 'api' => 2.0,
  678. );
  679. }