tripal_natural_diversity.module 6.9 KB

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