tripal_library.module 9.3 KB

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