tripal_analysis.module 24 KB

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