tripal_natural_diversity.module 6.4 KB

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