tripal_library.module 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  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. * Implement hook_access().
  77. *
  78. * This hook allows node modules to limit access to the node types they define.
  79. *
  80. * @param $node
  81. * The node on which the operation is to be performed, or, if it does not yet exist, the
  82. * type of node to be created
  83. *
  84. * @param $op
  85. * The operation to be performed
  86. *
  87. * @param $account
  88. * A user object representing the user for whom the operation is to be performed
  89. *
  90. * @return
  91. * If the permission for the specified operation is not set then return FALSE. If the
  92. * permission is set then return NULL as this allows other modules to disable
  93. * access. The only exception is when the $op == 'create'. We will always
  94. * return TRUE if the permission is set.
  95. *
  96. * @ingroup tripal_library
  97. */
  98. function chado_library_node_access($node, $op, $account) {
  99. if ($op == 'create') {
  100. if (!user_access('create chado_library content', $account)) {
  101. return FALSE;
  102. }
  103. return TRUE;
  104. }
  105. if ($op == 'update') {
  106. if (!user_access('edit chado_library content', $account)) {
  107. return FALSE;
  108. }
  109. }
  110. if ($op == 'delete') {
  111. if (!user_access('delete chado_library content', $account)) {
  112. return FALSE;
  113. }
  114. }
  115. if ($op == 'view') {
  116. if (!user_access('access chado_library content', $account)) {
  117. return FALSE;
  118. }
  119. }
  120. return NULL;
  121. }
  122. /**
  123. * Menu items are automatically added for the new node types created
  124. * by this module to the 'Create Content' Navigation menu item. This function
  125. * adds more menu items needed for this module.
  126. *
  127. * @ingroup tripal_library
  128. */
  129. function tripal_library_menu() {
  130. $items = array();
  131. // The administative settings menu
  132. $items['admin/tripal/chado/tripal_library'] = array(
  133. 'title' => 'Libraries',
  134. 'description' => 'Any biological library. Examples of genomic libraries include BAC, cDNA, FOSMID, etc.',
  135. 'page callback' => 'tripal_library_admin_libraries_listing',
  136. 'access arguments' => array('administer tripal libraries'),
  137. 'type' => MENU_NORMAL_ITEM,
  138. );
  139. $items['admin/tripal/chado/tripal_library/help'] = array(
  140. 'title' => 'Help',
  141. 'description' => 'Basic Description of Tripal Library Module Functionality',
  142. 'page callback' => 'theme',
  143. 'page arguments' => array('tripal_library.help'),
  144. 'access arguments' => array('administer tripal libraries'),
  145. 'type' => MENU_LOCAL_TASK,
  146. 'weight' => 10
  147. );
  148. $items['admin/tripal/chado/tripal_library/configuration'] = array(
  149. 'title' => 'Settings',
  150. 'description' => 'Configure the Tripal Library module',
  151. 'page callback' => 'drupal_get_form',
  152. 'page arguments' => array('tripal_library_admin'),
  153. 'access arguments' => array('administer tripal libraries'),
  154. 'type' => MENU_LOCAL_TASK,
  155. 'weight' => 5
  156. );
  157. $items['admin/tripal/chado/tripal_library/sync'] = array(
  158. 'title' => ' Sync',
  159. 'description' => 'Create pages on this site for libraries stored in Chado',
  160. 'page callback' => 'drupal_get_form',
  161. 'page arguments' => array('tripal_core_chado_node_sync_form', 'tripal_library', 'chado_library'),
  162. 'access arguments' => array('administer tripal libraries'),
  163. 'type' => MENU_LOCAL_TASK,
  164. 'weight' => 0
  165. );
  166. return $items;
  167. // Synchronizing libraries from Chado to Drupal
  168. $items['chado_sync_libraries'] = array(
  169. 'title' => 'Sync Library Data',
  170. 'page callback' => 'tripal_library_sync_libraries',
  171. 'access arguments' => array('administer tripal libraries'),
  172. 'type' => MENU_CALLBACK
  173. );
  174. $items['admin/tripal/chado/tripal_library/views/libraries/enable'] = array(
  175. 'title' => 'Enable Library Administrative View',
  176. 'page callback' => 'tripal_views_admin_enable_view',
  177. 'page arguments' => array('tripal_library_admin_libraries', 'admin/tripal/chado/tripal_library'),
  178. 'access arguments' => array('administer tripal libraries'),
  179. 'type' => MENU_CALLBACK,
  180. );
  181. return $items;
  182. }
  183. /**
  184. * Implements hook_views_api()
  185. * Purpose: Essentially this hook tells drupal that there is views support for
  186. * for this module which then includes tripal_db.views.inc where all the
  187. * views integration code is
  188. *
  189. * @ingroup tripal_library
  190. */
  191. function tripal_library_views_api() {
  192. return array(
  193. 'api' => 2.0,
  194. );
  195. }
  196. /**
  197. * @ingroup tripal_library
  198. */
  199. function tripal_library_node_view($node, $view_mode, $langcode) {
  200. switch ($node->type) {
  201. case 'chado_library':
  202. if ($view_mode == 'full') {
  203. $node->content['tripal_library.base'] = array(
  204. '#value' => theme('tripal_library.base', array('node' => $node)),
  205. );
  206. $node->content['tripal_library.properties'] = array(
  207. '#value' => theme('tripal_library.properties', array('node' => $node)),
  208. );
  209. $node->content['tripal_library.references'] = array(
  210. '#value' => theme('tripal_library.references', array('node' => $node)),
  211. );
  212. $node->content['tripal_library.synonyms'] = array(
  213. '#value' => theme('tripal_library.synonyms', array('node' => $node)),
  214. );
  215. $node->content['tripal_library.terms'] = array(
  216. '#value' => theme('tripal_library.terms', array('node' => $node)),
  217. );
  218. }
  219. if ($view_mode == 'teaser') {
  220. $node->content['tripal_library.teaser'] = array(
  221. '#value' => theme('tripal_library.teaser', array('node' => $node)),
  222. );
  223. }
  224. break;
  225. case 'chado_organism':
  226. if ($view_mode == 'full') {
  227. $node->content['tripal_organism.libraries'] = array(
  228. '#value' => theme('tripal_organism.libraries', array('node' => $node)),
  229. );
  230. }
  231. break;
  232. case 'chado_feature':
  233. if ($view_mode == 'full') {
  234. $node->content['tripal_feature.libraries'] = array(
  235. '#value' => theme('tripal_feature.libraries', array('node' => $node)),
  236. );
  237. }
  238. break;
  239. }
  240. }
  241. /**
  242. * We need to let drupal know about our theme functions and their arguments.
  243. * We create theme functions to allow users of the module to customize the
  244. * look and feel of the output generated in this module
  245. *
  246. * @ingroup tripal_library
  247. */
  248. function tripal_library_theme($existing, $type, $theme, $path) {
  249. $core_path = drupal_get_path('module', 'tripal_core');
  250. $items = array(
  251. 'node__chado_library' => array(
  252. 'template' => 'node--chado-generic',
  253. 'render element' => 'node',
  254. 'base hook' => 'node',
  255. 'path' => "$core_path/theme",
  256. ),
  257. // tripal_library templates
  258. 'tripal_library.base' => array(
  259. 'variables' => array('node' => NULL),
  260. 'template' => 'tripal_library.base',
  261. 'path' => "$path/theme/tripal_library",
  262. ),
  263. 'tripal_library.properties' => array(
  264. 'variables' => array('node' => NULL),
  265. 'template' => 'tripal_library.properties',
  266. 'path' => "$path/theme/tripal_library",
  267. ),
  268. 'tripal_library.references' => array(
  269. 'variables' => array('node' => NULL),
  270. 'template' => 'tripal_library.references',
  271. 'path' => "$path/theme/tripal_library",
  272. ),
  273. 'tripal_library.synonyms' => array(
  274. 'variables' => array('node' => NULL),
  275. 'template' => 'tripal_library.synonyms',
  276. 'path' => "$path/theme/tripal_library",
  277. ),
  278. 'tripal_library.terms' => array(
  279. 'variables' => array('node' => NULL),
  280. 'template' => 'tripal_library.terms',
  281. 'path' => "$path/theme/tripal_library",
  282. ),
  283. 'tripal_library.help' => array(
  284. 'template' => 'tripal_library.help',
  285. 'variables' => array(NULL),
  286. 'path' => "$path/theme",
  287. ),
  288. // teaser
  289. 'tripal_library.teaser' => array(
  290. 'variables' => array('node' => NULL),
  291. 'template' => 'tripal_library.teaser',
  292. 'path' => "$path/theme/tripal_library",
  293. ),
  294. // tripal_organism templates
  295. 'tripal_organism.libraries' => array(
  296. 'variables' => array('node' => NULL),
  297. 'template' => 'tripal_organism.libraries',
  298. 'path' => "$path/theme/tripal_organism",
  299. ),
  300. // tripal_feature templates
  301. 'tripal_feature.libraries' => array(
  302. 'variables' => array('node' => NULL),
  303. 'template' => 'tripal_feature.libraries',
  304. 'path' => "$path/theme/tripal_feature",
  305. ),
  306. );
  307. return $items;
  308. }
  309. /**
  310. * Implements hook_help()
  311. * Purpose: Adds a help page to the module list
  312. */
  313. function tripal_library_help ($path, $arg) {
  314. if ($path == 'admin/help#tripal_library') {
  315. return theme('tripal_library_help', array());
  316. }
  317. }
  318. /**
  319. * @ingroup tripal_library
  320. */
  321. function tripal_library_block_info() {
  322. $blocks['libreferences']['info'] = t('Tripal Library Cross References');
  323. $blocks['libreferences']['cache'] = DRUPAL_NO_CACHE;
  324. $blocks['libbase']['info'] = t('Tripal Library Details');
  325. $blocks['libbase']['cache'] = DRUPAL_NO_CACHE;
  326. $blocks['libterms']['info'] = t('Tripal Library Terms');
  327. $blocks['libterms']['cache'] = DRUPAL_NO_CACHE;
  328. $blocks['libsynonyms']['info'] = t('Tripal Library Synonyms');
  329. $blocks['libsynonyms']['cache'] = DRUPAL_NO_CACHE;
  330. $blocks['libproperties']['info'] = t('Tripal Library Properties');
  331. $blocks['libproperties']['cache'] = DRUPAL_NO_CACHE;
  332. $blocks['featurelibs']['info'] = t('Tripal Feature Libraries');
  333. $blocks['featurelibs']['cache'] = DRUPAL_NO_CACHE;
  334. $blocks['orglibs']['info'] = t('Tripal Organism Libraries');
  335. $blocks['orglibs']['cache'] = DRUPAL_NO_CACHE;
  336. return $blocks;
  337. }
  338. /**
  339. * @ingroup tripal_library
  340. */
  341. function tripal_library_block_view($delta = '') {
  342. if (user_access('access chado_library content') and arg(0) == 'node' and is_numeric(arg(1))) {
  343. $nid = arg(1);
  344. $node = node_load($nid);
  345. $block = array();
  346. switch ($delta) {
  347. case 'libreferences':
  348. $block['subject'] = t('Cross References');
  349. $block['content'] = theme('tripal_library_references', $node);
  350. break;
  351. case 'libbase':
  352. $block['subject'] = t('Library Details');
  353. $block['content'] = theme('tripal_library_base', $node);
  354. break;
  355. case 'libsynonyms':
  356. $block['subject'] = t('Synonyms');
  357. $block['content'] = theme('tripal_library_synonyms', $node);
  358. break;
  359. case 'libproperties':
  360. $block['subject'] = t('Properties');
  361. $block['content'] = theme('tripal_library_properties', $node);
  362. break;
  363. case 'libterms':
  364. $block['subject'] = t('Library Terms');
  365. $block['content'] = theme('tripal_library_terms', $node);
  366. break;
  367. case 'featurelibs':
  368. $block['subject'] = t('Libraries');
  369. $block['content'] = theme('tripal_feature_libraries', $node);
  370. break;
  371. case 'orglibs':
  372. $block['subject'] = t('Libraries');
  373. $block['content'] = theme('tripal_organism_libraries', $node);
  374. break;
  375. default :
  376. }
  377. return $block;
  378. }
  379. }
  380. /**
  381. *
  382. * @ingroup tripal_library
  383. */
  384. function tripal_library_cron() {
  385. }
  386. /**
  387. * Implementation of hook_form_alter()
  388. *
  389. * @param $form
  390. * @param $form_state
  391. * @param $form_id
  392. */
  393. function tripal_library_form_alter(&$form, &$form_state, $form_id) {
  394. // turn of preview button for insert/updates
  395. if ($form_id == "chado_library_node_form") {
  396. $form['actions']['preview']['#access'] = FALSE;
  397. }
  398. }