tripal_library.module 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. <?php
  2. /**
  3. * @file
  4. * Integrates the Chado Library module with Drupal Nodes & Views
  5. */
  6. /**
  7. * @defgroup tripal_library Library Module
  8. * @ingroup tripal_modules
  9. * @{
  10. * Integrates the Chado Library module with Drupal Nodes & Views
  11. * @}
  12. */
  13. require_once 'api/tripal_library.DEPRECATED.inc';
  14. require_once 'theme/tripal_library.theme.inc';
  15. require_once 'includes/tripal_library.admin.inc';
  16. require_once 'includes/tripal_library.chado_node.inc';
  17. /**
  18. * Implements hook_permission().
  19. *
  20. * Set the permission types that the chado module uses. Essentially we
  21. * want permissionis that protect creation, editing and deleting of chado
  22. * data objects
  23. *
  24. * @ingroup tripal_library
  25. */
  26. function tripal_library_permisssion() {
  27. return array(
  28. 'access chado_library content' => array(
  29. 'title' => t('View Libraries'),
  30. 'description' => t('Allow users to view library pages.'),
  31. ),
  32. 'create chado_library content' => array(
  33. 'title' => t('Create Libraries'),
  34. 'description' => t('Allow users to create new library pages.'),
  35. ),
  36. 'delete chado_library content' => array(
  37. 'title' => t('Delete Libraries'),
  38. 'description' => t('Allow users to delete library pages.'),
  39. ),
  40. 'edit chado_library content' => array(
  41. 'title' => t('Edit Libraries'),
  42. 'description' => t('Allow users to edit library pages.'),
  43. ),
  44. 'adminster tripal library' => array(
  45. 'title' => t('Administer Libraries'),
  46. 'description' => t('Allow users to administer all libraries.'),
  47. ),
  48. );
  49. }
  50. /**
  51. * Implements hook_menu().
  52. *
  53. * Menu items are automatically added for the new node types created
  54. * by this module to the 'Create Content' Navigation menu item. This function
  55. * adds more menu items needed for this module.
  56. *
  57. * @ingroup tripal_library
  58. */
  59. function tripal_library_menu() {
  60. $items = array();
  61. // The administative settings menu
  62. $items['admin/tripal/chado/tripal_library'] = array(
  63. 'title' => 'Libraries',
  64. 'description' => 'Any biological library. Examples of genomic libraries include BAC, cDNA, FOSMID, etc.',
  65. 'page callback' => 'tripal_library_admin_libraries_listing',
  66. 'access arguments' => array('administer tripal library'),
  67. 'type' => MENU_NORMAL_ITEM,
  68. );
  69. $items['admin/tripal/chado/tripal_library/help'] = array(
  70. 'title' => 'Help',
  71. 'description' => 'Basic Description of Tripal Library Module Functionality',
  72. 'page callback' => 'theme',
  73. 'page arguments' => array('tripal_library_help'),
  74. 'access arguments' => array('administer tripal library'),
  75. 'type' => MENU_LOCAL_TASK,
  76. 'weight' => 10
  77. );
  78. $items['admin/tripal/chado/tripal_library/configuration'] = array(
  79. 'title' => 'Settings',
  80. 'description' => 'Configure the Tripal Library module',
  81. 'page callback' => 'drupal_get_form',
  82. 'page arguments' => array('tripal_library_admin'),
  83. 'access arguments' => array('administer tripal library'),
  84. 'type' => MENU_LOCAL_TASK,
  85. 'weight' => 5
  86. );
  87. $items['admin/tripal/chado/tripal_library/sync'] = array(
  88. 'title' => ' Sync',
  89. 'description' => 'Create pages on this site for libraries stored in Chado',
  90. 'page callback' => 'drupal_get_form',
  91. 'page arguments' => array('chado_node_sync_form', 'tripal_library', 'chado_library'),
  92. 'access arguments' => array('administer tripal library'),
  93. 'type' => MENU_LOCAL_TASK,
  94. 'weight' => 2
  95. );
  96. $items['admin/tripal/chado/tripal_library/views/libraries/enable'] = array(
  97. 'title' => 'Enable Library Administrative View',
  98. 'page callback' => 'tripal_views_admin_enable_view',
  99. 'page arguments' => array('tripal_library_admin_libraries', 'admin/tripal/chado/tripal_library'),
  100. 'access arguments' => array('administer tripal library'),
  101. 'type' => MENU_CALLBACK,
  102. );
  103. return $items;
  104. }
  105. /**
  106. * Implements hook_search_biological_data_views().
  107. *
  108. * Adds the described views to the "Search Biological Data" Page created by Tripal Views
  109. */
  110. function tripal_library_search_biological_data_views() {
  111. return array(
  112. 'tripal_library_user_library' => array(
  113. 'machine_name' => 'tripal_library_user_library',
  114. 'human_name' => 'Libraries',
  115. 'description' => 'Biological library including BAC, cDNA, FOSMID, etc.',
  116. 'link' => 'chado/library'
  117. ),
  118. );
  119. }
  120. /**
  121. * Implements hook_views_api().
  122. *
  123. * Essentially this hook tells drupal that there is views support for
  124. * for this module which then includes tripal_db.views.inc where all the
  125. * views integration code is
  126. *
  127. * @ingroup tripal_library
  128. */
  129. function tripal_library_views_api() {
  130. return array(
  131. 'api' => 3.0,
  132. );
  133. }
  134. /**
  135. * Implements hook_theme().
  136. *
  137. * We need to let drupal know about our theme functions and their arguments.
  138. * We create theme functions to allow users of the module to customize the
  139. * look and feel of the output generated in this module
  140. *
  141. * @ingroup tripal_library
  142. */
  143. function tripal_library_theme($existing, $type, $theme, $path) {
  144. $core_path = drupal_get_path('module', 'tripal_core');
  145. $items = array(
  146. 'node__chado_library' => array(
  147. 'template' => 'node--chado-generic',
  148. 'render element' => 'node',
  149. 'base hook' => 'node',
  150. 'path' => "$core_path/theme",
  151. ),
  152. // tripal_library templates
  153. 'tripal_library_base' => array(
  154. 'variables' => array('node' => NULL),
  155. 'template' => 'tripal_library_base',
  156. 'path' => "$path/theme/tripal_library",
  157. ),
  158. 'tripal_library_properties' => array(
  159. 'variables' => array('node' => NULL),
  160. 'template' => 'tripal_library_properties',
  161. 'path' => "$path/theme/tripal_library",
  162. ),
  163. 'tripal_library_publications' => array(
  164. 'variables' => array('node' => NULL),
  165. 'template' => 'tripal_library_publications',
  166. 'path' => "$path/theme/tripal_library",
  167. ),
  168. 'tripal_library_references' => array(
  169. 'variables' => array('node' => NULL),
  170. 'template' => 'tripal_library_references',
  171. 'path' => "$path/theme/tripal_library",
  172. ),
  173. 'tripal_library_synonyms' => array(
  174. 'variables' => array('node' => NULL),
  175. 'template' => 'tripal_library_synonyms',
  176. 'path' => "$path/theme/tripal_library",
  177. ),
  178. 'tripal_library_terms' => array(
  179. 'variables' => array('node' => NULL),
  180. 'template' => 'tripal_library_terms',
  181. 'path' => "$path/theme/tripal_library",
  182. ),
  183. 'tripal_library_help' => array(
  184. 'template' => 'tripal_library_help',
  185. 'variables' => array(NULL),
  186. 'path' => "$path/theme",
  187. ),
  188. // teaser
  189. 'tripal_library_teaser' => array(
  190. 'variables' => array('node' => NULL),
  191. 'template' => 'tripal_library_teaser',
  192. 'path' => "$path/theme/tripal_library",
  193. ),
  194. // tripal_organism templates
  195. 'tripal_organism_libraries' => array(
  196. 'variables' => array('node' => NULL),
  197. 'template' => 'tripal_organism_libraries',
  198. 'path' => "$path/theme/tripal_organism",
  199. ),
  200. // tripal_feature templates
  201. 'tripal_feature_libraries' => array(
  202. 'variables' => array('node' => NULL),
  203. 'template' => 'tripal_feature_libraries',
  204. 'path' => "$path/theme/tripal_feature",
  205. ),
  206. );
  207. return $items;
  208. }
  209. /**
  210. * Implements hook_help().
  211. * Adds a help page to the module list
  212. *
  213. * @ingroup tripal_library
  214. */
  215. function tripal_library_help ($path, $arg) {
  216. if ($path == 'admin/help#tripal_library') {
  217. return theme('tripal_library_help', array());
  218. }
  219. }
  220. /**
  221. * Implements hook_block_info().
  222. *
  223. * @ingroup tripal_library
  224. */
  225. function tripal_library_block_info() {
  226. $blocks['libreferences']['info'] = t('Tripal Library Cross References');
  227. $blocks['libreferences']['cache'] = DRUPAL_NO_CACHE;
  228. $blocks['libbase']['info'] = t('Tripal Library Details');
  229. $blocks['libbase']['cache'] = DRUPAL_NO_CACHE;
  230. $blocks['libterms']['info'] = t('Tripal Library Terms');
  231. $blocks['libterms']['cache'] = DRUPAL_NO_CACHE;
  232. $blocks['libsynonyms']['info'] = t('Tripal Library Synonyms');
  233. $blocks['libsynonyms']['cache'] = DRUPAL_NO_CACHE;
  234. $blocks['libproperties']['info'] = t('Tripal Library Properties');
  235. $blocks['libproperties']['cache'] = DRUPAL_NO_CACHE;
  236. $blocks['featurelibs']['info'] = t('Tripal Feature Libraries');
  237. $blocks['featurelibs']['cache'] = DRUPAL_NO_CACHE;
  238. $blocks['orglibs']['info'] = t('Tripal Organism Libraries');
  239. $blocks['orglibs']['cache'] = DRUPAL_NO_CACHE;
  240. return $blocks;
  241. }
  242. /**
  243. * Implements hook_block_view().
  244. *
  245. * @ingroup tripal_library
  246. */
  247. function tripal_library_block_view($delta = '') {
  248. if (user_access('access chado_library content') and arg(0) == 'node' and is_numeric(arg(1))) {
  249. $nid = arg(1);
  250. $node = node_load($nid);
  251. $block = array();
  252. switch ($delta) {
  253. case 'libreferences':
  254. $block['subject'] = t('Cross References');
  255. $block['content'] = theme('tripal_library_references', $node);
  256. break;
  257. case 'libbase':
  258. $block['subject'] = t('Library Details');
  259. $block['content'] = theme('tripal_library_base', $node);
  260. break;
  261. case 'libsynonyms':
  262. $block['subject'] = t('Synonyms');
  263. $block['content'] = theme('tripal_library_synonyms', $node);
  264. break;
  265. case 'libproperties':
  266. $block['subject'] = t('Properties');
  267. $block['content'] = theme('tripal_library_properties', $node);
  268. break;
  269. case 'libterms':
  270. $block['subject'] = t('Library Terms');
  271. $block['content'] = theme('tripal_library_terms', $node);
  272. break;
  273. case 'featurelibs':
  274. $block['subject'] = t('Libraries');
  275. $block['content'] = theme('tripal_feature_libraries', $node);
  276. break;
  277. case 'orglibs':
  278. $block['subject'] = t('Libraries');
  279. $block['content'] = theme('tripal_organism_libraries', $node);
  280. break;
  281. default :
  282. }
  283. return $block;
  284. }
  285. }
  286. /**
  287. * Implementation of hook_form_alter().
  288. *
  289. * @param $form
  290. * @param $form_state
  291. * @param $form_id
  292. *
  293. * @ingroup tripal_library
  294. */
  295. function tripal_library_form_alter(&$form, &$form_state, $form_id) {
  296. if ($form_id == "chado_library_node_form") {
  297. // turn of preview button for insert/updates
  298. $form['actions']['preview']['#access'] = FALSE;
  299. //remove the body field
  300. unset($form['body']);
  301. }
  302. }