tripal_featuremap.module 9.7 KB

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