tripal_featuremap.module 9.8 KB

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