tripal_natural_diversity.module 5.9 KB

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