tripal_featuremap.module 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  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. * Provide information to drupal about the node types that we're creating
  43. * in this module
  44. *
  45. * @ingroup tripal_featuremap
  46. */
  47. function tripal_featuremap_node_info() {
  48. $nodes = array();
  49. $nodes['chado_featuremap'] = array(
  50. 'name' => t('Feature Map'),
  51. 'base' => 'chado_featuremap',
  52. 'description' => t('A map of features from the chado database (e.g. genetic map)'),
  53. 'has_title' => FALSE,
  54. 'title_label' => t('Feature Map'),
  55. 'has_body' => FALSE,
  56. 'body_label' => t('Feature Map Description'),
  57. 'locked' => TRUE,
  58. 'chado_node_api' => array(
  59. 'base_table' => 'featuremap',
  60. 'hook_prefix' => 'chado_featuremap',
  61. 'record_type_title' => array(
  62. 'singular' => t('Feature Map'),
  63. 'plural' => t('Feature Maps')
  64. ),
  65. 'sync_filters' => array(
  66. 'type_id' => FALSE,
  67. 'organism_id' => FALSE
  68. ),
  69. )
  70. );
  71. return $nodes;
  72. }
  73. /**
  74. * Set the permission types that the chado module uses. Essentially we
  75. * want permissionis that protect creation, editing and deleting of chado
  76. * data objects
  77. *
  78. * @ingroup tripal_featuremap
  79. */
  80. function tripal_featuremap_permissions() {
  81. return array(
  82. 'access chado_featuremap content' => array(
  83. 'title' => t('View Maps'),
  84. 'description' => t('Allow users to view map pages.'),
  85. ),
  86. 'create chado_featuremap content' => array(
  87. 'title' => t('Create Maps'),
  88. 'description' => t('Allow users to create new map pages.'),
  89. ),
  90. 'delete chado_featuremap content' => array(
  91. 'title' => t('Delete Maps'),
  92. 'description' => t('Allow users to delete map pages.'),
  93. ),
  94. 'edit chado_featuremap content' => array(
  95. 'title' => t('Edit Maps'),
  96. 'description' => t('Allow users to edit map pages.'),
  97. ),
  98. 'adminster tripal featuremap' => array(
  99. 'title' => t('Administer Maps'),
  100. 'description' => t('Allow users to administer all maps.'),
  101. ),
  102. );
  103. }
  104. /**
  105. * Menu items are automatically added for the new node types created
  106. * by this module to the 'Create Content' Navigation menu item. This function
  107. * adds more menu items needed for this module.
  108. *
  109. * @ingroup tripal_featuremap
  110. */
  111. function tripal_featuremap_menu() {
  112. $items = array();
  113. // The administative settings menu
  114. $items['admin/tripal/chado/tripal_featuremap'] = array(
  115. 'title' => 'Feature Maps',
  116. 'description' => 'A map of features from the chado database (e.g. genetic map)',
  117. 'page callback' => 'tripal_featuremap_admin_featuremaps_listing',
  118. 'access arguments' => array('administer tripal featuremap'),
  119. 'type' => MENU_NORMAL_ITEM,
  120. );
  121. $items['admin/tripal/chado/tripal_featuremap/help'] = array(
  122. 'title' => 'Help',
  123. 'description' => 'Basic Description of Tripal Map Module Functionality',
  124. 'page callback' => 'theme',
  125. 'page arguments' => array('tripal_featuremap_help'),
  126. 'access arguments' => array('administer tripal featuremap'),
  127. 'type' => MENU_LOCAL_TASK,
  128. 'weight' => 10
  129. );
  130. $items['admin/tripal/chado/tripal_featuremap/configuration'] = array(
  131. 'title' => 'Settings',
  132. 'description' => 'Manage integration of Chado maps including associated features.',
  133. 'page callback' => 'drupal_get_form',
  134. 'page arguments' => array('tripal_featuremap_admin'),
  135. 'access arguments' => array('administer tripal featuremap'),
  136. 'type' => MENU_LOCAL_TASK,
  137. 'weight' => 2
  138. );
  139. $items['admin/tripal/chado/tripal_featuremap/sync'] = array(
  140. 'title' => ' Sync',
  141. 'description' => 'Sync featuremaps from Chado with Drupal',
  142. 'page callback' => 'drupal_get_form',
  143. 'page arguments' => array('tripal_core_chado_node_sync_form', 'tripal_featuremap', 'chado_featuremap'),
  144. 'access arguments' => array('administer tripal featuremaps'),
  145. 'type' => MENU_LOCAL_TASK,
  146. 'weight' => 0
  147. );
  148. // Synchronizing maps from Chado to Drupal
  149. $items['chado_sync_featuremaps'] = array(
  150. 'title' => 'Sync Data',
  151. 'page callback' => 'tripal_featuremap_sync_featuremaps',
  152. 'access arguments' => array('administer tripal featuremap'),
  153. 'type' => MENU_CALLBACK
  154. );
  155. // AJAX calls for adding/removing properties to a featuremap
  156. $items['tripal_featuremap/properties/add'] = array(
  157. 'page callback' => 'tripal_featuremap_property_add',
  158. 'access arguments' => array('edit chado_featuremap content'),
  159. 'type ' => MENU_CALLBACK,
  160. );
  161. $items['tripal_featuremap/properties/description'] = array(
  162. 'page callback' => 'tripal_featuremap_property_get_description',
  163. 'access arguments' => array('edit chado_featuremap content'),
  164. 'type ' => MENU_CALLBACK,
  165. );
  166. $items['tripal_featuremap/properties/minus/%/%'] = array(
  167. 'page callback' => 'tripal_featuremap_property_delete',
  168. 'page arguments' => array(3, 4),
  169. 'access arguments' => array('edit chado_featuremap content'),
  170. 'type ' => MENU_CALLBACK,
  171. );
  172. $items['admin/tripal/chado/tripal_featuremap/views/featuremaps/enable'] = array(
  173. 'title' => 'Enable featuremap Administrative View',
  174. 'page callback' => 'tripal_views_admin_enable_view',
  175. 'page arguments' => array('tripal_featuremap_admin_featuremaps', 'admin/tripal/chado/tripal_featuremap'),
  176. 'access arguments' => array('administer tripal featuremap'),
  177. 'type' => MENU_CALLBACK,
  178. );
  179. return $items;
  180. }
  181. /**
  182. * Implements hook_views_api()
  183. * Purpose: Essentially this hook tells drupal that there is views support for
  184. * for this module which then includes tripal_db.views.inc where all the
  185. * views integration code is
  186. *
  187. * @ingroup tripal_featuremap
  188. */
  189. function tripal_featuremap_views_api() {
  190. return array(
  191. 'api' => 2.0,
  192. );
  193. }
  194. /**
  195. * We need to let drupal know about our theme functions and their arguments.
  196. * We create theme functions to allow users of the module to customize the
  197. * look and feel of the output generated in this module
  198. *
  199. * @ingroup tripal_featuremap
  200. */
  201. function tripal_featuremap_theme($existing, $type, $theme, $path) {
  202. $core_path = drupal_get_path('module', 'tripal_core');
  203. $items = array(
  204. 'node__chado_featuremap' => array(
  205. 'template' => 'node--chado-generic',
  206. 'render element' => 'node',
  207. 'base hook' => 'node',
  208. 'path' => "$core_path/theme",
  209. ),
  210. 'tripal_featuremap_base' => array(
  211. 'variables' => array('node' => NULL),
  212. 'template' => 'tripal_featuremap.base',
  213. 'path' => "$path/theme/tripal_featuremap",
  214. ),
  215. 'tripal_featuremap_properties' => array(
  216. 'variables' => array('node' => NULL),
  217. 'template' => 'tripal_featuremap.properties',
  218. 'path' => "$path/theme/tripal_featuremap",
  219. ),
  220. 'tripal_featuremap_featurepos' => array(
  221. 'variables' => array('node' => NULL),
  222. 'template' => 'tripal_featuremap.featurepos',
  223. 'path' => "$path/theme/tripal_featuremap",
  224. ),
  225. 'tripal_featuremap_publication' => array(
  226. 'variables' => array('node' => NULL),
  227. 'template' => 'tripal_featuremap.publication',
  228. 'path' => "$path/theme/tripal_featuremap",
  229. ),
  230. 'tripal_featuremap_references' => array(
  231. 'variables' => array('node' => NULL),
  232. 'template' => 'tripal_featuremap.references',
  233. 'path' => "$path/theme/tripal_featuremap",
  234. ),
  235. 'tripal_featuremap_help' => array(
  236. 'template' => 'tripal_featuremap.help',
  237. 'variables' => array(NULL),
  238. 'path' => "$path/theme",
  239. ),
  240. 'tripal_featuremap_teaser' => array(
  241. 'template' => 'tripal_featuremap.teaser',
  242. 'variables' => array(NULL),
  243. 'path' => "$path/theme/tripal_featuremap",
  244. ),
  245. );
  246. return $items;
  247. }
  248. /**
  249. *
  250. * @ingroup tripal_feature
  251. */
  252. function tripal_featuremap_node_view($node, $view_mode, $langcode) {
  253. switch ($node->type) {
  254. case 'chado_featuremap':
  255. // Show feature browser and counts
  256. if ($view_mode == 'full') {
  257. $node->content['tripal_featuremap_base'] = array(
  258. '#value' => theme('tripal_featuremap_base', array('node' => $node)),
  259. );
  260. $node->content['tripal_featuremap_featurepos'] = array(
  261. '#value' => theme('tripal_featuremap_featurepos', array('node' => $node)),
  262. );
  263. $node->content['tripal_featuremap_properties'] = array(
  264. '#value' => theme('tripal_featuremap_properties', array('node' => $node)),
  265. );
  266. $node->content['tripal_featuremap_publication'] = array(
  267. '#value' => theme('tripal_featuremap_publication', array('node' => $node)),
  268. );
  269. $node->content['tripal_featuremap_references'] = array(
  270. '#value' => theme('tripal_featuremap_references', array('node' => $node)),
  271. );
  272. }
  273. if ($view_mode == 'teaser') {
  274. $node->content['tripal_featuremap_teaser'] = array(
  275. '#value' => theme('tripal_featuremap_teaser', array('node' => $node)),
  276. );
  277. }
  278. break;
  279. }
  280. }
  281. /**
  282. * @ingroup tripal_library
  283. */
  284. function tripal_featuremap_block_info() {
  285. $blocks['mapbase']['info'] = t('Tripal Map Details');
  286. $blocks['mapbase']['cache'] = 'BLOCK_NO_CACHE';
  287. $blocks['mapprops']['info'] = t('Tripal Map Properties');
  288. $blocks['mapprops']['cache'] = 'BLOCK_NO_CACHE';
  289. $blocks['mappos']['info'] = t('Tripal Map Features');
  290. $blocks['mappos']['cache'] = 'BLOCK_NO_CACHE';
  291. $blocks['mappubs']['info'] = t('Tripal Map Publications');
  292. $blocks['mappubs']['cache'] = 'BLOCK_NO_CACHE';
  293. $blocks['maprefs']['info'] = t('Tripal Map References');
  294. $blocks['maprefs']['cache'] = 'BLOCK_NO_CACHE';
  295. return $blocks;
  296. }
  297. /**
  298. * @ingroup tripal_library
  299. */
  300. function tripal_featuremap_block_view($delta = '') {
  301. if (user_access('access chado_library content') and arg(0) == 'node' and is_numeric(arg(1))) {
  302. $nid = arg(1);
  303. $node = node_load($nid);
  304. $block = array();
  305. switch ($delta) {
  306. case 'mapbase':
  307. $block['subject'] = t('Library Details');
  308. $block['content'] = theme('tripal_featuremap_base', $node);
  309. break;
  310. case 'mapprops':
  311. $block['subject'] = t('Properties');
  312. $block['content'] = theme('tripal_featuremap_properties', $node);
  313. break;
  314. case 'mappos':
  315. $block['subject'] = t('Features');
  316. $block['content'] = theme('tripal_featuremap_featurepos', $node);
  317. break;
  318. case 'mappubs':
  319. $block['subject'] = t('Publications');
  320. $block['content'] = theme('tripal_featuremap_publication', $node);
  321. break;
  322. case 'maprefs':
  323. $block['subject'] = t('References');
  324. $block['content'] = theme('tripal_featuremap_references', $node);
  325. break;
  326. default :
  327. }
  328. return $block;
  329. }
  330. }
  331. /**
  332. *
  333. * @ingroup tripal_featuremap
  334. */
  335. function tripal_featuremap_cron() {
  336. }
  337. /**
  338. * Implementation of hook_form_alter()
  339. *
  340. * @param $form
  341. * @param $form_state
  342. * @param $form_id
  343. */
  344. function tripal_featuremap_form_alter(&$form, &$form_state, $form_id) {
  345. // turn of preview button for insert/updates
  346. if ($form_id == "chado_featuremap_node_form") {
  347. $form['actions']['preview']['#access'] = FALSE;
  348. }
  349. }
  350. /**
  351. *
  352. * @param $node
  353. */
  354. function tripal_featuremap_node_presave($node) {
  355. // if this is a chado_featuremap and the $node->featuremap object is set then we
  356. // are syncing and we want to set the node title to be the same as the node name
  357. if ($node->type == 'chado_featuremap' and property_exists($node, 'featuremap')) {
  358. $node->title = $node->featuremap->name;
  359. }
  360. }