tripal_library.module 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  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. * Provide information to drupal about the node types that we're creating
  15. * in this module
  16. *
  17. * @ingroup tripal_library
  18. */
  19. function tripal_library_node_info() {
  20. $nodes = array();
  21. $nodes['chado_library'] = array(
  22. 'name' => t('Library'),
  23. 'base' => 'chado_library',
  24. 'description' => t('A library from the chado database'),
  25. 'has_title' => FALSE,
  26. 'title_label' => t('Library'),
  27. 'has_body' => FALSE,
  28. 'locked' => TRUE,
  29. 'chado_node_api' => array(
  30. 'base_table' => 'library',
  31. 'hook_prefix' => 'chado_library',
  32. 'record_type_title' => array(
  33. 'singular' => t('Library'),
  34. 'plural' => t('Libraries')
  35. ),
  36. 'sync_filters' => array(
  37. 'type_id' => TRUE,
  38. 'organism_id' => TRUE
  39. ),
  40. )
  41. );
  42. return $nodes;
  43. }
  44. /**
  45. * Set the permission types that the chado module uses. Essentially we
  46. * want permissionis that protect creation, editing and deleting of chado
  47. * data objects
  48. *
  49. * @ingroup tripal_library
  50. */
  51. function tripal_library_permisssions() {
  52. return array(
  53. 'access chado_library content' => array(
  54. 'title' => t('View Libraries'),
  55. 'description' => t('Allow users to view library pages.'),
  56. ),
  57. 'create chado_library content' => array(
  58. 'title' => t('Create Libraries'),
  59. 'description' => t('Allow users to create new library pages.'),
  60. ),
  61. 'delete chado_library content' => array(
  62. 'title' => t('Delete Libraries'),
  63. 'description' => t('Allow users to delete library pages.'),
  64. ),
  65. 'edit chado_library content' => array(
  66. 'title' => t('Edit Libraries'),
  67. 'description' => t('Allow users to edit library pages.'),
  68. ),
  69. 'adminster tripal library' => array(
  70. 'title' => t('Administer Libraries'),
  71. 'description' => t('Allow users to administer all libraries.'),
  72. ),
  73. );
  74. }
  75. /**
  76. * Menu items are automatically added for the new node types created
  77. * by this module to the 'Create Content' Navigation menu item. This function
  78. * adds more menu items needed for this module.
  79. *
  80. * @ingroup tripal_library
  81. */
  82. function tripal_library_menu() {
  83. $items = array();
  84. // The administative settings menu
  85. $items['admin/tripal/chado/tripal_library'] = array(
  86. 'title' => 'Libraries',
  87. 'description' => 'Any biological library. Examples of genomic libraries include BAC, cDNA, FOSMID, etc.',
  88. 'page callback' => 'tripal_library_admin_libraries_listing',
  89. 'access arguments' => array('administer tripal libraries'),
  90. 'type' => MENU_NORMAL_ITEM,
  91. );
  92. $items['admin/tripal/chado/tripal_library/help'] = array(
  93. 'title' => 'Help',
  94. 'description' => 'Basic Description of Tripal Library Module Functionality',
  95. 'page callback' => 'theme',
  96. 'page arguments' => array('tripal_library_help'),
  97. 'access arguments' => array('administer tripal libraries'),
  98. 'type' => MENU_LOCAL_TASK,
  99. 'weight' => 10
  100. );
  101. $items['admin/tripal/chado/tripal_library/configuration'] = array(
  102. 'title' => 'Settings',
  103. 'description' => 'Configure the Tripal Library module',
  104. 'page callback' => 'drupal_get_form',
  105. 'page arguments' => array('tripal_library_admin'),
  106. 'access arguments' => array('administer tripal libraries'),
  107. 'type' => MENU_LOCAL_TASK,
  108. 'weight' => 5
  109. );
  110. $items['admin/tripal/chado/tripal_library/sync'] = array(
  111. 'title' => ' Sync',
  112. 'description' => 'Create pages on this site for libraries stored in Chado',
  113. 'page callback' => 'drupal_get_form',
  114. 'page arguments' => array('tripal_core_chado_node_sync_form', 'tripal_library', 'chado_library'),
  115. 'access arguments' => array('administer tripal libraries'),
  116. 'type' => MENU_LOCAL_TASK,
  117. 'weight' => 0
  118. );
  119. return $items;
  120. // Synchronizing libraries from Chado to Drupal
  121. $items['chado_sync_libraries'] = array(
  122. 'title' => 'Sync Library Data',
  123. 'page callback' => 'tripal_library_sync_libraries',
  124. 'access arguments' => array('administer tripal libraries'),
  125. 'type' => MENU_CALLBACK
  126. );
  127. $items['admin/tripal/chado/tripal_library/views/libraries/enable'] = array(
  128. 'title' => 'Enable Library Administrative View',
  129. 'page callback' => 'tripal_views_admin_enable_view',
  130. 'page arguments' => array('tripal_library_admin_libraries', 'admin/tripal/chado/tripal_library'),
  131. 'access arguments' => array('administer tripal libraries'),
  132. 'type' => MENU_CALLBACK,
  133. );
  134. return $items;
  135. }
  136. /**
  137. * Implements hook_views_api()
  138. * Purpose: Essentially this hook tells drupal that there is views support for
  139. * for this module which then includes tripal_db.views.inc where all the
  140. * views integration code is
  141. *
  142. * @ingroup tripal_library
  143. */
  144. function tripal_library_views_api() {
  145. return array(
  146. 'api' => 2.0,
  147. );
  148. }
  149. /**
  150. * @ingroup tripal_library
  151. */
  152. function tripal_library_node_view($node, $view_mode, $langcode) {
  153. switch ($node->type) {
  154. case 'chado_library':
  155. if ($view_mode == 'full') {
  156. $node->content['tripal_library_base'] = array(
  157. '#value' => theme('tripal_library_base', array('node' => $node)),
  158. );
  159. $node->content['tripal_library_properties'] = array(
  160. '#value' => theme('tripal_library_properties', array('node' => $node)),
  161. );
  162. $node->content['tripal_library_publications'] = array(
  163. '#value' => theme('tripal_library_publications', array('node' => $node)),
  164. );
  165. $node->content['tripal_library_references'] = array(
  166. '#value' => theme('tripal_library_references', array('node' => $node)),
  167. );
  168. $node->content['tripal_library_synonyms'] = array(
  169. '#value' => theme('tripal_library_synonyms', array('node' => $node)),
  170. );
  171. $node->content['tripal_library_terms'] = array(
  172. '#value' => theme('tripal_library_terms', array('node' => $node)),
  173. );
  174. }
  175. if ($view_mode == 'teaser') {
  176. $node->content['tripal_library_teaser'] = array(
  177. '#value' => theme('tripal_library_teaser', array('node' => $node)),
  178. );
  179. }
  180. break;
  181. case 'chado_organism':
  182. if ($view_mode == 'full') {
  183. $node->content['tripal_organism.libraries'] = array(
  184. '#value' => theme('tripal_organism.libraries', array('node' => $node)),
  185. );
  186. }
  187. break;
  188. case 'chado_feature':
  189. if ($view_mode == 'full') {
  190. $node->content['tripal_feature.libraries'] = array(
  191. '#value' => theme('tripal_feature.libraries', array('node' => $node)),
  192. );
  193. }
  194. break;
  195. }
  196. }
  197. /**
  198. * We need to let drupal know about our theme functions and their arguments.
  199. * We create theme functions to allow users of the module to customize the
  200. * look and feel of the output generated in this module
  201. *
  202. * @ingroup tripal_library
  203. */
  204. function tripal_library_theme($existing, $type, $theme, $path) {
  205. $core_path = drupal_get_path('module', 'tripal_core');
  206. $items = array(
  207. 'node__chado_library' => array(
  208. 'template' => 'node--chado-generic',
  209. 'render element' => 'node',
  210. 'base hook' => 'node',
  211. 'path' => "$core_path/theme",
  212. ),
  213. // tripal_library templates
  214. 'tripal_library_base' => array(
  215. 'variables' => array('node' => NULL),
  216. 'template' => 'tripal_library.base',
  217. 'path' => "$path/theme/tripal_library",
  218. ),
  219. 'tripal_library_properties' => array(
  220. 'variables' => array('node' => NULL),
  221. 'template' => 'tripal_library.properties',
  222. 'path' => "$path/theme/tripal_library",
  223. ),
  224. 'tripal_library_publications' => array(
  225. 'variables' => array('node' => NULL),
  226. 'template' => 'tripal_library.publications',
  227. 'path' => "$path/theme/tripal_library",
  228. ),
  229. 'tripal_library_references' => array(
  230. 'variables' => array('node' => NULL),
  231. 'template' => 'tripal_library.references',
  232. 'path' => "$path/theme/tripal_library",
  233. ),
  234. 'tripal_library_synonyms' => array(
  235. 'variables' => array('node' => NULL),
  236. 'template' => 'tripal_library.synonyms',
  237. 'path' => "$path/theme/tripal_library",
  238. ),
  239. 'tripal_library_terms' => array(
  240. 'variables' => array('node' => NULL),
  241. 'template' => 'tripal_library.terms',
  242. 'path' => "$path/theme/tripal_library",
  243. ),
  244. 'tripal_library_help' => array(
  245. 'template' => 'tripal_library.help',
  246. 'variables' => array(NULL),
  247. 'path' => "$path/theme",
  248. ),
  249. // teaser
  250. 'tripal_library_teaser' => array(
  251. 'variables' => array('node' => NULL),
  252. 'template' => 'tripal_library.teaser',
  253. 'path' => "$path/theme/tripal_library",
  254. ),
  255. // tripal_organism templates
  256. 'tripal_organism_libraries' => array(
  257. 'variables' => array('node' => NULL),
  258. 'template' => 'tripal_organism.libraries',
  259. 'path' => "$path/theme/tripal_organism",
  260. ),
  261. // tripal_feature templates
  262. 'tripal_feature_libraries' => array(
  263. 'variables' => array('node' => NULL),
  264. 'template' => 'tripal_feature.libraries',
  265. 'path' => "$path/theme/tripal_feature",
  266. ),
  267. );
  268. return $items;
  269. }
  270. /**
  271. * Implements hook_help()
  272. * Purpose: Adds a help page to the module list
  273. */
  274. function tripal_library_help ($path, $arg) {
  275. if ($path == 'admin/help#tripal_library') {
  276. return theme('tripal_library_help', array());
  277. }
  278. }
  279. /**
  280. * @ingroup tripal_library
  281. */
  282. function tripal_library_block_info() {
  283. $blocks['libreferences']['info'] = t('Tripal Library Cross References');
  284. $blocks['libreferences']['cache'] = DRUPAL_NO_CACHE;
  285. $blocks['libbase']['info'] = t('Tripal Library Details');
  286. $blocks['libbase']['cache'] = DRUPAL_NO_CACHE;
  287. $blocks['libterms']['info'] = t('Tripal Library Terms');
  288. $blocks['libterms']['cache'] = DRUPAL_NO_CACHE;
  289. $blocks['libsynonyms']['info'] = t('Tripal Library Synonyms');
  290. $blocks['libsynonyms']['cache'] = DRUPAL_NO_CACHE;
  291. $blocks['libproperties']['info'] = t('Tripal Library Properties');
  292. $blocks['libproperties']['cache'] = DRUPAL_NO_CACHE;
  293. $blocks['featurelibs']['info'] = t('Tripal Feature Libraries');
  294. $blocks['featurelibs']['cache'] = DRUPAL_NO_CACHE;
  295. $blocks['orglibs']['info'] = t('Tripal Organism Libraries');
  296. $blocks['orglibs']['cache'] = DRUPAL_NO_CACHE;
  297. return $blocks;
  298. }
  299. /**
  300. * @ingroup tripal_library
  301. */
  302. function tripal_library_block_view($delta = '') {
  303. if (user_access('access chado_library content') and arg(0) == 'node' and is_numeric(arg(1))) {
  304. $nid = arg(1);
  305. $node = node_load($nid);
  306. $block = array();
  307. switch ($delta) {
  308. case 'libreferences':
  309. $block['subject'] = t('Cross References');
  310. $block['content'] = theme('tripal_library_references', $node);
  311. break;
  312. case 'libbase':
  313. $block['subject'] = t('Library Details');
  314. $block['content'] = theme('tripal_library_base', $node);
  315. break;
  316. case 'libsynonyms':
  317. $block['subject'] = t('Synonyms');
  318. $block['content'] = theme('tripal_library_synonyms', $node);
  319. break;
  320. case 'libproperties':
  321. $block['subject'] = t('Properties');
  322. $block['content'] = theme('tripal_library_properties', $node);
  323. break;
  324. case 'libterms':
  325. $block['subject'] = t('Library Terms');
  326. $block['content'] = theme('tripal_library_terms', $node);
  327. break;
  328. case 'featurelibs':
  329. $block['subject'] = t('Libraries');
  330. $block['content'] = theme('tripal_feature_libraries', $node);
  331. break;
  332. case 'orglibs':
  333. $block['subject'] = t('Libraries');
  334. $block['content'] = theme('tripal_organism_libraries', $node);
  335. break;
  336. default :
  337. }
  338. return $block;
  339. }
  340. }
  341. /**
  342. *
  343. * @ingroup tripal_library
  344. */
  345. function tripal_library_cron() {
  346. }
  347. /**
  348. * Implementation of hook_form_alter()
  349. *
  350. * @param $form
  351. * @param $form_state
  352. * @param $form_id
  353. */
  354. function tripal_library_form_alter(&$form, &$form_state, $form_id) {
  355. // turn of preview button for insert/updates
  356. if ($form_id == "chado_library_node_form") {
  357. $form['actions']['preview']['#access'] = FALSE;
  358. }
  359. }
  360. /**
  361. *
  362. * @param $node
  363. */
  364. function tripal_library_node_presave($node) {
  365. // if this is a chado_library and the $node->library object is set then we
  366. // are syncing and we want to set the node title to be the same as the node name
  367. if ($node->type == 'chado_library' and property_exists($node, 'library')) {
  368. $node->title = $node->library->name;
  369. }
  370. }