tripal_featuremap.module 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. <?php
  2. /**
  3. * @file
  4. * Integrates the Chado Map module with Drupal Nodes & Views
  5. */
  6. /**
  7. * @defgroup tripal_featuremap Feature Map Module
  8. * @ingroup tripal_modules
  9. * @{
  10. * Integrates the Chado Map module with Drupal Nodes & Views
  11. * @}
  12. */
  13. require_once 'api/tripal_featuremap.api.inc';
  14. //require_once 'api/tripal_featuremap.DEPRECATED.inc';
  15. require_once 'theme/tripal_featuremap.theme.inc';
  16. require_once 'includes/tripal_featuremap.admin.inc';
  17. require_once 'includes/tripal_featuremap.chado_node.inc';
  18. /**
  19. * Implements hook_help().
  20. * Display help and module information
  21. *
  22. * @param path
  23. * which path of the site we're displaying help
  24. * @param arg
  25. * array that holds the current path as would be returned from arg() function
  26. * @return
  27. * help text for the path
  28. *
  29. * @ingroup tripal_featuremap
  30. */
  31. function tripal_featuremap_help($path, $arg) {
  32. $output = '';
  33. switch ($path) {
  34. case "admin/help#tripal_featuremap":
  35. $output = '<p>'.
  36. t("Displays links to nodes created on this date") .
  37. '</p>';
  38. break;
  39. }
  40. return $output;
  41. }
  42. /**
  43. * Implements hook_permission().
  44. *
  45. * Set the permission types that the chado module uses. Essentially we
  46. * want permissionis that protect creation, editing and deleting of chado
  47. * data objects
  48. *
  49. * @ingroup tripal_featuremap
  50. */
  51. function tripal_featuremap_permission() {
  52. return array(
  53. 'access chado_featuremap content' => array(
  54. 'title' => t('View Maps'),
  55. 'description' => t('Allow users to view map pages.'),
  56. ),
  57. 'create chado_featuremap content' => array(
  58. 'title' => t('Create Maps'),
  59. 'description' => t('Allow users to create new map pages.'),
  60. ),
  61. 'delete chado_featuremap content' => array(
  62. 'title' => t('Delete Maps'),
  63. 'description' => t('Allow users to delete map pages.'),
  64. ),
  65. 'edit chado_featuremap content' => array(
  66. 'title' => t('Edit Maps'),
  67. 'description' => t('Allow users to edit map pages.'),
  68. ),
  69. 'adminster tripal featuremap' => array(
  70. 'title' => t('Administer Maps'),
  71. 'description' => t('Allow users to administer all maps.'),
  72. ),
  73. );
  74. }
  75. /**
  76. * Implements hook_menu().
  77. *
  78. * Menu items are automatically added for the new node types created
  79. * by this module to the 'Create Content' Navigation menu item. This function
  80. * adds more menu items needed for this module.
  81. *
  82. * @ingroup tripal_featuremap
  83. */
  84. function tripal_featuremap_menu() {
  85. $items = array();
  86. // The administative settings menu
  87. $items['admin/tripal/chado/tripal_featuremap'] = array(
  88. 'title' => 'Feature Maps',
  89. 'description' => 'A map of features from the chado database (e.g. genetic map)',
  90. 'page callback' => 'tripal_featuremap_admin_featuremaps_listing',
  91. 'access arguments' => array('administer tripal featuremap'),
  92. 'type' => MENU_NORMAL_ITEM,
  93. );
  94. $items['admin/tripal/chado/tripal_featuremap/help'] = array(
  95. 'title' => 'Help',
  96. 'description' => 'Basic Description of Tripal Map Module Functionality',
  97. 'page callback' => 'theme',
  98. 'page arguments' => array('tripal_featuremap_help'),
  99. 'access arguments' => array('administer tripal featuremap'),
  100. 'type' => MENU_LOCAL_TASK,
  101. 'weight' => 10
  102. );
  103. $items['admin/tripal/chado/tripal_featuremap/configuration'] = array(
  104. 'title' => 'Settings',
  105. 'description' => 'Manage integration of Chado maps including associated features.',
  106. 'page callback' => 'drupal_get_form',
  107. 'page arguments' => array('tripal_featuremap_admin'),
  108. 'access arguments' => array('administer tripal featuremap'),
  109. 'type' => MENU_LOCAL_TASK,
  110. 'weight' => 2
  111. );
  112. $items['admin/tripal/chado/tripal_featuremap/sync'] = array(
  113. 'title' => ' Sync',
  114. 'description' => 'Sync featuremaps from Chado with Drupal',
  115. 'page callback' => 'drupal_get_form',
  116. 'page arguments' => array('tripal_core_chado_node_sync_form', 'tripal_featuremap', 'chado_featuremap'),
  117. 'access arguments' => array('administer tripal featuremap'),
  118. 'type' => MENU_LOCAL_TASK,
  119. 'weight' => 0
  120. );
  121. // Synchronizing maps from Chado to Drupal
  122. $items['chado_sync_featuremaps'] = array(
  123. 'title' => 'Sync Data',
  124. 'page callback' => 'tripal_featuremap_sync_featuremaps',
  125. 'access arguments' => array('administer tripal featuremap'),
  126. 'type' => MENU_CALLBACK
  127. );
  128. $items['admin/tripal/chado/tripal_featuremap/views/featuremaps/enable'] = array(
  129. 'title' => 'Enable featuremap Administrative View',
  130. 'page callback' => 'tripal_views_admin_enable_view',
  131. 'page arguments' => array('tripal_featuremap_admin_featuremaps', 'admin/tripal/chado/tripal_featuremap'),
  132. 'access arguments' => array('administer tripal featuremap'),
  133. 'type' => MENU_CALLBACK,
  134. );
  135. return $items;
  136. }
  137. /**
  138. * Implements hook_views_api().
  139. *
  140. * Essentially this hook tells drupal that there is views support for
  141. * for this module which then includes tripal_featuremap.views.inc where all the
  142. * views integration code is
  143. *
  144. * @ingroup tripal_featuremap
  145. */
  146. function tripal_featuremap_views_api() {
  147. return array(
  148. 'api' => 3.0,
  149. );
  150. }
  151. /**
  152. * Implements hook_theme().
  153. *
  154. * We need to let drupal know about our theme functions and their arguments.
  155. * We create theme functions to allow users of the module to customize the
  156. * look and feel of the output generated in this module
  157. *
  158. * @ingroup tripal_featuremap
  159. */
  160. function tripal_featuremap_theme($existing, $type, $theme, $path) {
  161. $core_path = drupal_get_path('module', 'tripal_core');
  162. $items = array(
  163. 'node__chado_featuremap' => array(
  164. 'template' => 'node--chado-generic',
  165. 'render element' => 'node',
  166. 'base hook' => 'node',
  167. 'path' => "$core_path/theme",
  168. ),
  169. 'tripal_featuremap_base' => array(
  170. 'variables' => array('node' => NULL),
  171. 'template' => 'tripal_featuremap_base',
  172. 'path' => "$path/theme/tripal_featuremap",
  173. ),
  174. 'tripal_featuremap_properties' => array(
  175. 'variables' => array('node' => NULL),
  176. 'template' => 'tripal_featuremap_properties',
  177. 'path' => "$path/theme/tripal_featuremap",
  178. ),
  179. 'tripal_featuremap_featurepos' => array(
  180. 'variables' => array('node' => NULL),
  181. 'template' => 'tripal_featuremap_featurepos',
  182. 'path' => "$path/theme/tripal_featuremap",
  183. ),
  184. 'tripal_featuremap_publication' => array(
  185. 'variables' => array('node' => NULL),
  186. 'template' => 'tripal_featuremap_publication',
  187. 'path' => "$path/theme/tripal_featuremap",
  188. ),
  189. 'tripal_featuremap_references' => array(
  190. 'variables' => array('node' => NULL),
  191. 'template' => 'tripal_featuremap_references',
  192. 'path' => "$path/theme/tripal_featuremap",
  193. ),
  194. 'tripal_featuremap_help' => array(
  195. 'template' => 'tripal_featuremap_help',
  196. 'variables' => array(NULL),
  197. 'path' => "$path/theme",
  198. ),
  199. 'tripal_featuremap_teaser' => array(
  200. 'template' => 'tripal_featuremap_teaser',
  201. 'variables' => array(NULL),
  202. 'path' => "$path/theme/tripal_featuremap",
  203. ),
  204. // templates for the chado_feature node type
  205. 'tripal_feature_featurepos' => array(
  206. 'arguments' => array('node' => NULL),
  207. 'template' => 'tripal_feature_featurepos',
  208. 'path' => "$path/theme/tripal_feature",
  209. ),
  210. );
  211. return $items;
  212. }
  213. /**
  214. * Implements hook_block_info().
  215. *
  216. * @ingroup tripal_featuremap
  217. */
  218. function tripal_featuremap_block_info() {
  219. $blocks['mapbase']['info'] = t('Tripal Map Details');
  220. $blocks['mapbase']['cache'] = 'BLOCK_NO_CACHE';
  221. $blocks['mapprops']['info'] = t('Tripal Map Properties');
  222. $blocks['mapprops']['cache'] = 'BLOCK_NO_CACHE';
  223. $blocks['mappos']['info'] = t('Tripal Map Features');
  224. $blocks['mappos']['cache'] = 'BLOCK_NO_CACHE';
  225. $blocks['mappubs']['info'] = t('Tripal Map Publications');
  226. $blocks['mappubs']['cache'] = 'BLOCK_NO_CACHE';
  227. $blocks['maprefs']['info'] = t('Tripal Map References');
  228. $blocks['maprefs']['cache'] = 'BLOCK_NO_CACHE';
  229. return $blocks;
  230. }
  231. /**
  232. * Implements hook_block_view().
  233. *
  234. * @ingroup tripal_featuremap
  235. */
  236. function tripal_featuremap_block_view($delta = '') {
  237. if (user_access('access chado_library content') and arg(0) == 'node' and is_numeric(arg(1))) {
  238. $nid = arg(1);
  239. $node = node_load($nid);
  240. $block = array();
  241. switch ($delta) {
  242. case 'mapbase':
  243. $block['subject'] = t('Library Details');
  244. $block['content'] = theme('tripal_featuremap_base', $node);
  245. break;
  246. case 'mapprops':
  247. $block['subject'] = t('Properties');
  248. $block['content'] = theme('tripal_featuremap_properties', $node);
  249. break;
  250. case 'mappos':
  251. $block['subject'] = t('Features');
  252. $block['content'] = theme('tripal_featuremap_featurepos', $node);
  253. break;
  254. case 'mappubs':
  255. $block['subject'] = t('Publications');
  256. $block['content'] = theme('tripal_featuremap_publication', $node);
  257. break;
  258. case 'maprefs':
  259. $block['subject'] = t('Cross References');
  260. $block['content'] = theme('tripal_featuremap_references', $node);
  261. break;
  262. default :
  263. }
  264. return $block;
  265. }
  266. }
  267. /**
  268. * Implementation of hook_form_alter()
  269. *
  270. * @param $form
  271. * @param $form_state
  272. * @param $form_id
  273. *
  274. * @ingroup tripal_featuremap
  275. */
  276. function tripal_featuremap_form_alter(&$form, &$form_state, $form_id) {
  277. if ($form_id == "chado_featuremap_node_form") {
  278. // turn of preview button for insert/updates
  279. $form['actions']['preview']['#access'] = FALSE;
  280. //remove the body field
  281. unset($form['body']);
  282. }
  283. }