tripal_featuremap.module 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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. );
  205. return $items;
  206. }
  207. /**
  208. * Implements hook_block_info().
  209. *
  210. * @ingroup tripal_featuremap
  211. */
  212. function tripal_featuremap_block_info() {
  213. $blocks['mapbase']['info'] = t('Tripal Map Details');
  214. $blocks['mapbase']['cache'] = 'BLOCK_NO_CACHE';
  215. $blocks['mapprops']['info'] = t('Tripal Map Properties');
  216. $blocks['mapprops']['cache'] = 'BLOCK_NO_CACHE';
  217. $blocks['mappos']['info'] = t('Tripal Map Features');
  218. $blocks['mappos']['cache'] = 'BLOCK_NO_CACHE';
  219. $blocks['mappubs']['info'] = t('Tripal Map Publications');
  220. $blocks['mappubs']['cache'] = 'BLOCK_NO_CACHE';
  221. $blocks['maprefs']['info'] = t('Tripal Map References');
  222. $blocks['maprefs']['cache'] = 'BLOCK_NO_CACHE';
  223. return $blocks;
  224. }
  225. /**
  226. * Implements hook_block_view().
  227. *
  228. * @ingroup tripal_featuremap
  229. */
  230. function tripal_featuremap_block_view($delta = '') {
  231. if (user_access('access chado_library content') and arg(0) == 'node' and is_numeric(arg(1))) {
  232. $nid = arg(1);
  233. $node = node_load($nid);
  234. $block = array();
  235. switch ($delta) {
  236. case 'mapbase':
  237. $block['subject'] = t('Library Details');
  238. $block['content'] = theme('tripal_featuremap_base', $node);
  239. break;
  240. case 'mapprops':
  241. $block['subject'] = t('Properties');
  242. $block['content'] = theme('tripal_featuremap_properties', $node);
  243. break;
  244. case 'mappos':
  245. $block['subject'] = t('Features');
  246. $block['content'] = theme('tripal_featuremap_featurepos', $node);
  247. break;
  248. case 'mappubs':
  249. $block['subject'] = t('Publications');
  250. $block['content'] = theme('tripal_featuremap_publication', $node);
  251. break;
  252. case 'maprefs':
  253. $block['subject'] = t('References');
  254. $block['content'] = theme('tripal_featuremap_references', $node);
  255. break;
  256. default :
  257. }
  258. return $block;
  259. }
  260. }
  261. /**
  262. * Implementation of hook_form_alter()
  263. *
  264. * @param $form
  265. * @param $form_state
  266. * @param $form_id
  267. *
  268. * @ingroup tripal_featuremap
  269. */
  270. function tripal_featuremap_form_alter(&$form, &$form_state, $form_id) {
  271. if ($form_id == "chado_featuremap_node_form") {
  272. // turn of preview button for insert/updates
  273. $form['actions']['preview']['#access'] = FALSE;
  274. //remove the body field
  275. unset($form['body']);
  276. }
  277. }