tripal_library.module 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  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.references'] = array(
  163. '#value' => theme('tripal_library.references', array('node' => $node)),
  164. );
  165. $node->content['tripal_library.synonyms'] = array(
  166. '#value' => theme('tripal_library.synonyms', array('node' => $node)),
  167. );
  168. $node->content['tripal_library.terms'] = array(
  169. '#value' => theme('tripal_library.terms', array('node' => $node)),
  170. );
  171. }
  172. if ($view_mode == 'teaser') {
  173. $node->content['tripal_library.teaser'] = array(
  174. '#value' => theme('tripal_library.teaser', array('node' => $node)),
  175. );
  176. }
  177. break;
  178. case 'chado_organism':
  179. if ($view_mode == 'full') {
  180. $node->content['tripal_organism.libraries'] = array(
  181. '#value' => theme('tripal_organism.libraries', array('node' => $node)),
  182. );
  183. }
  184. break;
  185. case 'chado_feature':
  186. if ($view_mode == 'full') {
  187. $node->content['tripal_feature.libraries'] = array(
  188. '#value' => theme('tripal_feature.libraries', array('node' => $node)),
  189. );
  190. }
  191. break;
  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_library
  200. */
  201. function tripal_library_theme($existing, $type, $theme, $path) {
  202. $core_path = drupal_get_path('module', 'tripal_core');
  203. $items = array(
  204. 'node__chado_library' => array(
  205. 'template' => 'node--chado-generic',
  206. 'render element' => 'node',
  207. 'base hook' => 'node',
  208. 'path' => "$core_path/theme",
  209. ),
  210. // tripal_library templates
  211. 'tripal_library.base' => array(
  212. 'variables' => array('node' => NULL),
  213. 'template' => 'tripal_library.base',
  214. 'path' => "$path/theme/tripal_library",
  215. ),
  216. 'tripal_library.properties' => array(
  217. 'variables' => array('node' => NULL),
  218. 'template' => 'tripal_library.properties',
  219. 'path' => "$path/theme/tripal_library",
  220. ),
  221. 'tripal_library.references' => array(
  222. 'variables' => array('node' => NULL),
  223. 'template' => 'tripal_library.references',
  224. 'path' => "$path/theme/tripal_library",
  225. ),
  226. 'tripal_library.synonyms' => array(
  227. 'variables' => array('node' => NULL),
  228. 'template' => 'tripal_library.synonyms',
  229. 'path' => "$path/theme/tripal_library",
  230. ),
  231. 'tripal_library.terms' => array(
  232. 'variables' => array('node' => NULL),
  233. 'template' => 'tripal_library.terms',
  234. 'path' => "$path/theme/tripal_library",
  235. ),
  236. 'tripal_library.help' => array(
  237. 'template' => 'tripal_library.help',
  238. 'variables' => array(NULL),
  239. 'path' => "$path/theme",
  240. ),
  241. // teaser
  242. 'tripal_library.teaser' => array(
  243. 'variables' => array('node' => NULL),
  244. 'template' => 'tripal_library.teaser',
  245. 'path' => "$path/theme/tripal_library",
  246. ),
  247. // tripal_organism templates
  248. 'tripal_organism.libraries' => array(
  249. 'variables' => array('node' => NULL),
  250. 'template' => 'tripal_organism.libraries',
  251. 'path' => "$path/theme/tripal_organism",
  252. ),
  253. // tripal_feature templates
  254. 'tripal_feature.libraries' => array(
  255. 'variables' => array('node' => NULL),
  256. 'template' => 'tripal_feature.libraries',
  257. 'path' => "$path/theme/tripal_feature",
  258. ),
  259. );
  260. return $items;
  261. }
  262. /**
  263. * Implements hook_help()
  264. * Purpose: Adds a help page to the module list
  265. */
  266. function tripal_library_help ($path, $arg) {
  267. if ($path == 'admin/help#tripal_library') {
  268. return theme('tripal_library_help', array());
  269. }
  270. }
  271. /**
  272. * @ingroup tripal_library
  273. */
  274. function tripal_library_block_info() {
  275. $blocks['libreferences']['info'] = t('Tripal Library Cross References');
  276. $blocks['libreferences']['cache'] = DRUPAL_NO_CACHE;
  277. $blocks['libbase']['info'] = t('Tripal Library Details');
  278. $blocks['libbase']['cache'] = DRUPAL_NO_CACHE;
  279. $blocks['libterms']['info'] = t('Tripal Library Terms');
  280. $blocks['libterms']['cache'] = DRUPAL_NO_CACHE;
  281. $blocks['libsynonyms']['info'] = t('Tripal Library Synonyms');
  282. $blocks['libsynonyms']['cache'] = DRUPAL_NO_CACHE;
  283. $blocks['libproperties']['info'] = t('Tripal Library Properties');
  284. $blocks['libproperties']['cache'] = DRUPAL_NO_CACHE;
  285. $blocks['featurelibs']['info'] = t('Tripal Feature Libraries');
  286. $blocks['featurelibs']['cache'] = DRUPAL_NO_CACHE;
  287. $blocks['orglibs']['info'] = t('Tripal Organism Libraries');
  288. $blocks['orglibs']['cache'] = DRUPAL_NO_CACHE;
  289. return $blocks;
  290. }
  291. /**
  292. * @ingroup tripal_library
  293. */
  294. function tripal_library_block_view($delta = '') {
  295. if (user_access('access chado_library content') and arg(0) == 'node' and is_numeric(arg(1))) {
  296. $nid = arg(1);
  297. $node = node_load($nid);
  298. $block = array();
  299. switch ($delta) {
  300. case 'libreferences':
  301. $block['subject'] = t('Cross References');
  302. $block['content'] = theme('tripal_library.references', $node);
  303. break;
  304. case 'libbase':
  305. $block['subject'] = t('Library Details');
  306. $block['content'] = theme('tripal_library.base', $node);
  307. break;
  308. case 'libsynonyms':
  309. $block['subject'] = t('Synonyms');
  310. $block['content'] = theme('tripal_library.synonyms', $node);
  311. break;
  312. case 'libproperties':
  313. $block['subject'] = t('Properties');
  314. $block['content'] = theme('tripal_library.properties', $node);
  315. break;
  316. case 'libterms':
  317. $block['subject'] = t('Library Terms');
  318. $block['content'] = theme('tripal_library.terms', $node);
  319. break;
  320. case 'featurelibs':
  321. $block['subject'] = t('Libraries');
  322. $block['content'] = theme('tripal_feature.libraries', $node);
  323. break;
  324. case 'orglibs':
  325. $block['subject'] = t('Libraries');
  326. $block['content'] = theme('tripal_organism.libraries', $node);
  327. break;
  328. default :
  329. }
  330. return $block;
  331. }
  332. }
  333. /**
  334. *
  335. * @ingroup tripal_library
  336. */
  337. function tripal_library_cron() {
  338. }
  339. /**
  340. * Implementation of hook_form_alter()
  341. *
  342. * @param $form
  343. * @param $form_state
  344. * @param $form_id
  345. */
  346. function tripal_library_form_alter(&$form, &$form_state, $form_id) {
  347. // turn of preview button for insert/updates
  348. if ($form_id == "chado_library_node_form") {
  349. $form['actions']['preview']['#access'] = FALSE;
  350. }
  351. }
  352. /**
  353. *
  354. * @param $node
  355. */
  356. function tripal_library_node_presave($node) {
  357. // if this is a chado_library and the $node->library object is set then we
  358. // are syncing and we want to set the node title to be the same as the node name
  359. if ($node->type == 'chado_library' and property_exists($node, 'library')) {
  360. $node->title = $node->library->name;
  361. }
  362. }