tripal_natural_diversity.module 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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.nd_geolocation.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. * Implements hook_views_api()
  19. * Purpose: Essentially this hook tells drupal that there is views support for
  20. * for this module which then includes tripal_natural_diversity.views.inc where all the
  21. * views integration code is
  22. *
  23. * @ingroup tripal_natural_diversity
  24. */
  25. function tripal_natural_diversity_views_api() {
  26. return array(
  27. 'api' => 2.0,
  28. );
  29. }
  30. /**
  31. * Implements hook_theme
  32. *
  33. * @ingroup tripal_natural_diversity
  34. */
  35. function tripal_natural_diversity_theme() {
  36. return array(
  37. 'tripal_feature_nd_genotypes' => array(
  38. 'arguments' => array('node' => NULL),
  39. 'template' => 'tripal_feature_nd_genotypes',
  40. ),
  41. 'tripal_stock_nd_genotypes' => array(
  42. 'arguments' => array('node' => NULL),
  43. 'template' => 'tripal_stock_nd_genotypes',
  44. ),
  45. 'tripal_stock_nd_phenotypes' => array(
  46. 'arguments' => array('node' => NULL),
  47. 'template' => 'tripal_stock_nd_phenotypes',
  48. ),
  49. 'tripal_nd_geolocation_base' => array(
  50. 'arguments' => array('node' => NULL),
  51. 'template' => 'tripal_nd_geolocation_base',
  52. ),
  53. 'tripal_nd_geolocation_properties' => array(
  54. 'arguments' => array('node' => NULL),
  55. 'template' => 'tripal_nd_geolocation_properties',
  56. ),
  57. 'tripal_natural_diversity_admin' => array(
  58. 'template' => 'tripal_natural_diversity_admin',
  59. 'arguments' => array(NULL),
  60. 'path' => drupal_get_path('module', 'tripal_natural_diversity') . '/theme'
  61. ),
  62. );
  63. }
  64. /**
  65. * Implements hook_nodeapi().
  66. *
  67. * @ingroup tripal_natural_diversity
  68. */
  69. function tripal_natural_diversity_nodeapi(&$node, $op, $teaser, $page){
  70. switch ($op) {
  71. case 'view':
  72. if ($node->type == 'chado_feature') {
  73. // the tripal_genetic module provides a tripal_feature_genotype
  74. // template. The only difference between them is the addition of
  75. // natural_diversity information by this module's template. Therefore,
  76. // if the tripal_genetic content is present get rid of as this
  77. // module superceeds it.
  78. if (array_key_exists('tripal_feature_genotypes', $node->content)) {
  79. unset($node->content['tripal_feature_genotypes']);
  80. }
  81. $node->content['tripal_feature_nd_genotypes'] = array(
  82. '#value' => theme('tripal_feature_nd_genotypes', $node),
  83. );
  84. }
  85. if ($node->type == 'chado_stock') {
  86. $node->content['tripal_stock_nd_genotypes'] = array(
  87. '#value' => theme('tripal_stock_nd_genotypes', $node),
  88. );
  89. $node->content['tripal_stock_nd_phenotypes'] = array(
  90. '#value' => theme('tripal_stock_nd_phenotypes', $node),
  91. );
  92. }
  93. break;
  94. }
  95. }
  96. /**
  97. *
  98. *
  99. * @ingroup tripal_natural_diversity
  100. */
  101. function tripal_natural_diversity_preprocess_tripal_stock_nd_genotypes(&$variables){
  102. }
  103. /**
  104. * Implements hook_menu
  105. *
  106. * @ingroup tripal_natural_diversity
  107. */
  108. function tripal_natural_diversity_menu() {
  109. $items[ 'admin/tripal/tripal_natural_diversity' ]= array(
  110. 'title' => 'Natural Diversity',
  111. 'description' => ('A module for interfacing the GMOD chado database with Drupal, providing viewing of natural_diversity data'),
  112. 'page callback' => 'theme',
  113. 'page arguments' => array('tripal_natural_diversity_admin'),
  114. 'access arguments' => array('administer site configuration'),
  115. 'type' => MENU_NORMAL_ITEM
  116. );
  117. $items[ 'admin/tripal/tripal_natural_diversity/configuration' ]= array(
  118. 'title' => 'Configuration',
  119. 'page callback' => 'drupal_get_form',
  120. 'page arguments' => array('tripal_natural_diversity_admin'),
  121. 'access arguments' => array('administer site configuration'),
  122. 'type' => MENU_NORMAL_ITEM
  123. );
  124. return $items;
  125. }
  126. /**
  127. * Implements hook_perm()
  128. *
  129. * This function sets the permission for the user to access the information in the database.
  130. * This includes creating, inserting, deleting and updating of information in the database
  131. *
  132. *
  133. * @ingroup tripal_natural_diversity
  134. */
  135. function tripal_natural_diversity_perm() {
  136. return array(
  137. 'access chado_nd_geolocation content',
  138. 'create chado_nd_geolocation content',
  139. 'delete chado_nd_geolocation content',
  140. 'edit chado_nd_geolocation content',
  141. 'adminster tripal natural_diversity',
  142. );
  143. }
  144. /**
  145. * Implement hook_access().
  146. *
  147. * This hook allows node modules to limit access to the node types they define.
  148. *
  149. * @param $op
  150. * The operation to be performed
  151. *
  152. * @param $node
  153. * The node on which the operation is to be performed, or, if it does not yet exist, the
  154. * type of node to be created
  155. *
  156. * @param $account
  157. * A user object representing the user for whom the operation is to be performed
  158. *
  159. * @return
  160. * If the permission for the specified operation is not set then return FALSE. If the
  161. * permission is set then return NULL as this allows other modules to disable
  162. * access. The only exception is when the $op == 'create'. We will always
  163. * return TRUE if the permission is set.
  164. *
  165. * @ingroup tripal_natural_diversity
  166. */
  167. function chado_natural_diversity_access($op, $node, $account) {
  168. if ($op == 'create') {
  169. if (!user_access('create chado_nd_geolocation content', $account)) {
  170. return FALSE;
  171. }
  172. return TRUE;
  173. }
  174. if ($op == 'update') {
  175. if (!user_access('edit chado_nd_geolocation content', $account)) {
  176. return FALSE;
  177. }
  178. }
  179. if ($op == 'delete') {
  180. if (!user_access('delete chado_nd_geolocation content', $account)) {
  181. return FALSE;
  182. }
  183. }
  184. if ($op == 'view') {
  185. if (!user_access('access chado_nd_geolocation content', $account)) {
  186. return FALSE;
  187. }
  188. }
  189. return NULL;
  190. }
  191. /**
  192. * Implementation of hook_node_info().
  193. *
  194. * This node_info, is a simple node that describes the functionallity of the module. It specifies
  195. * that the title(Project Name) and body(Description) set to true so that they information can be
  196. * entered
  197. *
  198. *
  199. * @ingroup tripal_natural_diversity
  200. */
  201. function tripal_natural_diversity_node_info() {
  202. return array(
  203. 'chado_nd_geolocation' => array(
  204. 'name' => t('ND Geolocation'),
  205. 'module' => 'chado_nd_geolocation',
  206. 'description' => t('A module for interfacing the GMOD chado database with Drupal, providing viewing of nd_geolocation'),
  207. 'has_title' => TRUE,
  208. 'title_label' => t('ND Geolocation'),
  209. 'had_body' => FALSE,
  210. 'body_label' => t('Full Description'),
  211. )
  212. );
  213. }