tripal_natural_diversity.module 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <?php
  2. require_once('api/tripal_natural_diversity.api.inc');
  3. require_once('theme/tripal_natural_diversity.theme.inc');
  4. require_once('includes/tripal_natural_diversity.schema.inc');
  5. require_once('includes/tripal_natural_diversity.admin.inc');
  6. /**
  7. * @file
  8. * This file contains the basic functions needed for this drupal module.
  9. * The drupal tripal_natural_diversity module maps directly to the chado X module.
  10. *
  11. * For documentation regarding the Chado X module:
  12. * @see http://gmod.org/wiki/Chado_General_Module
  13. *
  14. * @defgroup tripal_natural_diversity Natural Diversity Module
  15. * @ingroup tripal_modules
  16. */
  17. /**
  18. * Menu items are automatically added for the new node types created
  19. * by this module to the 'Create Content' Navigation menu item. This function
  20. * adds more menu items needed for this module.
  21. *
  22. * @ingroup tripal_natural_diversity
  23. */
  24. function tripal_natural_diversity_menu() {
  25. $items = array();
  26. // the administative settings menu
  27. $items['admin/tripal/chado/tripal_natdiv'] = array(
  28. 'title' => 'Natural Diversity Experiments',
  29. 'description' => 'Experiments relating to natural diversity such as genotype and phenotype experiments.',
  30. 'page callback' => 'tripal_natural_diversity_admin_natdiv_view',
  31. 'access arguments' => array('adminster tripal natural_diversity'),
  32. 'type' => MENU_NORMAL_ITEM,
  33. );
  34. $items['admin/tripal/chado/tripal_natdiv/help'] = array(
  35. 'title' => 'Help',
  36. 'description' => ('Help for the Tripal natural diversity module.'),
  37. 'page callback' => 'theme',
  38. 'page arguments' => array('tripal_natural_diversity_help'),
  39. 'access arguments' => array('administer tripal natual_diversity'),
  40. 'type' => MENU_LOCAL_TASK,
  41. 'weight' => 10
  42. );
  43. $items['admin/tripal/chado/tripal_natdiv/views/natdiv_exp/enable'] = array(
  44. 'title' => 'Enable Natural Diversity Administrative View',
  45. 'page callback' => 'tripal_views_admin_enable_view',
  46. 'page arguments' => array('tripal_natural_diversity_admin_natdiv_exp', 'admin/tripal/chado/tripal_natdiv'),
  47. 'access arguments' => array('administer tripal natural_diversity'),
  48. 'type' => MENU_CALLBACK,
  49. );
  50. return $items;
  51. }
  52. /**
  53. * Implements hook_views_api()
  54. * Purpose: Essentially this hook tells drupal that there is views support for
  55. * for this module which then includes tripal_natural_diversity.views.inc where all the
  56. * views integration code is
  57. *
  58. * @ingroup tripal_natural_diversity
  59. */
  60. function tripal_natural_diversity_views_api() {
  61. return array(
  62. 'api' => 3.0,
  63. );
  64. }
  65. /**
  66. * Implements hook_theme
  67. *
  68. * @ingroup tripal_natural_diversity
  69. */
  70. function tripal_natural_diversity_theme($existing, $type, $theme, $path) {
  71. $core_path = drupal_get_path('module', 'tripal_core');
  72. $items = array(
  73. // tripal_feature templates
  74. 'tripal_feature_nd_genotypes' => array(
  75. 'variables' => array('node' => NULL),
  76. 'template' => 'tripal_feature.nd_genotypes',
  77. 'path' => "$path/theme/tripal_feature",
  78. ),
  79. // tripal_stock templates
  80. 'tripal_stock_nd_genotypes' => array(
  81. 'variables' => array('node' => NULL),
  82. 'template' => 'tripal_stock.nd_genotypes',
  83. 'path' => "$path/theme/tripal_stock",
  84. ),
  85. 'tripal_stock_nd_phenotypes' => array(
  86. 'variables' => array('node' => NULL),
  87. 'template' => 'tripal_stock.nd_phenotypes',
  88. 'path' => "$path/theme/tripal_stock",
  89. ),
  90. 'tripal_natural_diversity_help' => array(
  91. 'template' => 'tripal_natural_diversity.help',
  92. 'variables' => array(NULL),
  93. 'path' => "$path/theme",
  94. ),
  95. );
  96. return $items;
  97. }
  98. /**
  99. * @ingroup tripal_library
  100. */
  101. function tripal_natural_diversity_block_info() {
  102. $blocks['ndfgenotype']['info'] = t('Tripal Natural Diversity Feature Genotypes');
  103. $blocks['ndfgenotype']['cache'] = 'BLOCK_NO_CACHE';
  104. $blocks['ndsgenotype']['info'] = t('Tripal Natural Diversity Library Genotypes');
  105. $blocks['ndsgenotype']['cache'] = 'BLOCK_NO_CACHE';
  106. $blocks['ndsphenotype']['info'] = t('Tripal Natural Diversity Stock Phenotypes');
  107. $blocks['ndsphenotype']['cache'] = 'BLOCK_NO_CACHE';
  108. return $blocks;
  109. }
  110. /**
  111. * @ingroup tripal_library
  112. */
  113. function tripal_natural_diversity_block_view($delta = '') {
  114. if (user_access('access chado_library content') and arg(0) == 'node' and is_numeric(arg(1))) {
  115. $nid = arg(1);
  116. $node = node_load($nid);
  117. $block = array();
  118. switch ($delta) {
  119. case 'ndfgenotype':
  120. $block['subject'] = t('Genotypes');
  121. $block['content'] = theme('tripal_feature_nd_genotypes', $node);
  122. break;
  123. case 'ndsgenotype':
  124. $block['subject'] = t('Stock Genotypes');
  125. $block['content'] = theme('tripal_stock_nd_genotypes', $node);
  126. break;
  127. case 'ndsphenotype':
  128. $block['subject'] = t('Phenotypes');
  129. $block['content'] = theme('tripal_stock_nd_phenotypes', $node);
  130. break;
  131. default :
  132. }
  133. return $block;
  134. }
  135. }
  136. /**
  137. *
  138. * @ingroup tripal_natural_diversity
  139. */
  140. function tripal_natural_diversity_node_view($node, $view_mode, $langcode) {
  141. if ($node->type == 'chado_feature') {
  142. // the tripal_genetic module provides a tripal_feature_genotype
  143. // template. The only difference between them is the addition of
  144. // project information by this module's template. Therefore,
  145. // if the tripal_genetic content is present get rid of it as this
  146. // module superceeds it.
  147. if ($view_mode == 'full') {
  148. if (array_key_exists('tripal_feature_genotypes', $node->content)) {
  149. unset($node->content['tripal_feature_genotypes']);
  150. }
  151. $node->content['tripal_feature_nd_genotypes'] = array(
  152. '#value' => theme('tripal_feature_nd_genotypes', array('node' => $node)),
  153. );
  154. }
  155. }
  156. if ($node->type == 'chado_stock') {
  157. if ($view_mode == 'full') {
  158. $node->content['tripal_stock_nd_genotypes'] = array(
  159. '#value' => theme('tripal_stock_nd_genotypes', array('node' => $node)),
  160. );
  161. $node->content['tripal_stock_nd_phenotypes'] = array(
  162. '#value' => theme('tripal_stock_nd_phenotypes', array('node' => $node)),
  163. );
  164. }
  165. }
  166. break;
  167. }