tripal_analysis.module 23 KB

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