tripal_natural_diversity.module 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <?php
  2. /**
  3. * @file
  4. * Basic function for the natural diversity module
  5. */
  6. require_once 'theme/tripal_natural_diversity.theme.inc';
  7. require_once 'includes/tripal_natural_diversity.schema.inc';
  8. require_once 'includes/tripal_natural_diversity.admin.inc';
  9. /**
  10. * @defgroup tripal_natural_diversity Natural Diversity Module
  11. * @ingroup tripal_modules
  12. * @{
  13. * Provides functions for managing chado natural diversity data
  14. * @}
  15. */
  16. /**
  17. * Implements hook_permission().
  18. *
  19. * Set the permission types that the chado module uses. Essentially we
  20. * want permissionis
  21. *
  22. * @ingroup tripal_natural_diversity
  23. */
  24. function tripal_natural_diversity_permission() {
  25. return array(
  26. 'administer tripal nd' => array(
  27. 'title' => t('Administer Natural Diversity Module'),
  28. 'description' => t('Allow users to administer the natural diversity module.'),
  29. ),
  30. );
  31. }
  32. /**
  33. * Implements hook_menu().
  34. *
  35. * Menu items are automatically added for the new node types created
  36. * by this module to the 'Create Content' Navigation menu item. This function
  37. * adds more menu items needed for this module.
  38. *
  39. * @ingroup tripal_natural_diversity
  40. */
  41. function tripal_natural_diversity_menu() {
  42. $items = array();
  43. // the administative settings menu
  44. $items['admin/tripal/chado/tripal_natdiv'] = array(
  45. 'title' => 'Natural Diversity Experiments',
  46. 'description' => 'Experiments relating to natural diversity such as genotype and phenotype experiments.',
  47. 'page callback' => 'tripal_natural_diversity_admin_natdiv_view',
  48. 'access arguments' => array('administer tripal nd'),
  49. 'type' => MENU_NORMAL_ITEM,
  50. );
  51. $items['admin/tripal/chado/tripal_natdiv/help'] = array(
  52. 'title' => 'Help',
  53. 'description' => ('Help for the Tripal natural diversity module.'),
  54. 'page callback' => 'theme',
  55. 'page arguments' => array('tripal_natural_diversity_help'),
  56. 'access arguments' => array('administer tripal nd'),
  57. 'type' => MENU_LOCAL_TASK,
  58. 'weight' => 10
  59. );
  60. $items['admin/tripal/chado/tripal_natdiv/views/natdiv_exp/enable'] = array(
  61. 'title' => 'Enable Natural Diversity Administrative View',
  62. 'page callback' => 'tripal_enable_view',
  63. 'page arguments' => array('tripal_natural_diversity_admin_natdiv_exp', 'admin/tripal/chado/tripal_natdiv'),
  64. 'access arguments' => array('administer tripal nd'),
  65. 'type' => MENU_CALLBACK,
  66. );
  67. return $items;
  68. }
  69. /**
  70. * Implements hook_views_api().
  71. *
  72. * Essentially this hook tells drupal that there is views support for
  73. * for this module which then includes tripal_natural_diversity.views.inc where all the
  74. * views integration code is
  75. *
  76. * @ingroup tripal_natural_diversity
  77. */
  78. function tripal_natural_diversity_views_api() {
  79. return array(
  80. 'api' => 3.0,
  81. );
  82. }
  83. /**
  84. * Implements hook_theme().
  85. *
  86. * @ingroup tripal_natural_diversity
  87. */
  88. function tripal_natural_diversity_theme($existing, $type, $theme, $path) {
  89. $core_path = drupal_get_path('module', 'tripal_core');
  90. $items = array(
  91. // tripal_feature templates
  92. 'tripal_feature_nd_genotypes' => array(
  93. 'variables' => array('node' => NULL),
  94. 'template' => 'tripal_feature_nd_genotypes',
  95. 'path' => "$path/theme/templates",
  96. ),
  97. // tripal_stock templates
  98. 'tripal_stock_nd_genotypes' => array(
  99. 'variables' => array('node' => NULL),
  100. 'template' => 'tripal_stock_nd_genotypes',
  101. 'path' => "$path/theme/templates",
  102. ),
  103. 'tripal_stock_nd_phenotypes' => array(
  104. 'variables' => array('node' => NULL),
  105. 'template' => 'tripal_stock_nd_phenotypes',
  106. 'path' => "$path/theme/templates",
  107. ),
  108. 'tripal_natural_diversity_help' => array(
  109. 'template' => 'tripal_natural_diversity_help',
  110. 'variables' => array(NULL),
  111. 'path' => "$path/theme/templates",
  112. ),
  113. );
  114. return $items;
  115. }
  116. /**
  117. * Implements hook_block_info().
  118. *
  119. * @ingroup tripal_library
  120. */
  121. function tripal_natural_diversity_block_info() {
  122. $blocks['ndfgenotype']['info'] = t('Tripal Natural Diversity Feature Genotypes');
  123. $blocks['ndfgenotype']['cache'] = 'BLOCK_NO_CACHE';
  124. $blocks['ndsgenotype']['info'] = t('Tripal Natural Diversity Library Genotypes');
  125. $blocks['ndsgenotype']['cache'] = 'BLOCK_NO_CACHE';
  126. $blocks['ndsphenotype']['info'] = t('Tripal Natural Diversity Stock Phenotypes');
  127. $blocks['ndsphenotype']['cache'] = 'BLOCK_NO_CACHE';
  128. return $blocks;
  129. }
  130. /**
  131. * Implements hook_block_view().
  132. *
  133. * @ingroup tripal_library
  134. */
  135. function tripal_natural_diversity_block_view($delta = '') {
  136. if (user_access('access chado_library content') and arg(0) == 'node' and is_numeric(arg(1))) {
  137. $nid = arg(1);
  138. $node = node_load($nid);
  139. $block = array();
  140. switch ($delta) {
  141. case 'ndfgenotype':
  142. $block['subject'] = t('Genotypes');
  143. $block['content'] = theme('tripal_feature_nd_genotypes', $node);
  144. break;
  145. case 'ndsgenotype':
  146. $block['subject'] = t('Stock Genotypes');
  147. $block['content'] = theme('tripal_stock_nd_genotypes', $node);
  148. break;
  149. case 'ndsphenotype':
  150. $block['subject'] = t('Phenotypes');
  151. $block['content'] = theme('tripal_stock_nd_phenotypes', $node);
  152. break;
  153. default :
  154. }
  155. return $block;
  156. }
  157. }
  158. /**
  159. * Implements hook_node_view(). Acts on all content types.
  160. *
  161. * @ingroup tripal_natural_diversity
  162. */
  163. function tripal_natural_diversity_node_view($node, $view_mode, $langcode) {
  164. switch ($node->type) {
  165. case 'chado_feature':
  166. if ($view_mode == 'full') {
  167. // the tripal_genetic module provides a tripal_feature_genotype
  168. // template. if the tripal_genetic content is present get rid of it as this
  169. // module superceeds it.
  170. if (array_key_exists('tripal_feature_genotypes', $node->content)) {
  171. unset($node->content['tripal_feature_genotypes']);
  172. }
  173. $node->content['tripal_feature_nd_genotypes'] = array(
  174. '#markup' => theme('tripal_feature_nd_genotypes', array('node' => $node)),
  175. '#tripal_toc_id' => 'genotypes',
  176. '#tripal_toc_title' => 'Genotypes',
  177. );
  178. }
  179. break;
  180. case 'chado_stock':
  181. if ($view_mode == 'full') {
  182. // the tripal_genetic module provides a tripal_stock_genotype
  183. // template. if the tripal_genetic content is present get rid of it as this
  184. // module superceeds it.
  185. if (array_key_exists('tripal_stock_genotypes', $node->content)) {
  186. unset($node->content['tripal_stock_genotypes']);
  187. }
  188. $node->content['tripal_stock_nd_genotypes'] = array(
  189. '#markup' => theme('tripal_stock_nd_genotypes', array('node' => $node)),
  190. '#tripal_toc_id' => 'genotypes',
  191. '#tripal_toc_title' => 'Genotypes',
  192. );
  193. $node->content['tripal_stock_nd_phenotypes'] = array(
  194. '#markup' => theme('tripal_stock_nd_phenotypes', array('node' => $node)),
  195. '#tripal_toc_id' => 'phenotypes',
  196. '#tripal_toc_title' => 'Phenotypes',
  197. );
  198. }
  199. break;
  200. }
  201. }