tripal_organism.module 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <?php
  2. require_once "api/tripal_organism.api.inc";
  3. require_once "includes/tripal_organism.admin.inc";
  4. require_once "includes/tripal_organism.chado_node.inc";
  5. /**
  6. * @defgroup tripal_organism Organism Module
  7. * @ingroup tripal_modules
  8. * @{
  9. * Integrates the Chado Organism module with Drupal Nodes & Views
  10. * @}
  11. */
  12. /**
  13. *
  14. * @ingroup tripal_organism
  15. */
  16. function tripal_organism_init() {
  17. // add the jGCharts JS and CSS
  18. drupal_add_css(drupal_get_path('module', 'tripal_organism') . '/theme/css/tripal_organism.css');
  19. drupal_add_js(drupal_get_path('module', 'tripal_organism') . '/theme/js/tripal_organism.js');
  20. }
  21. /**
  22. *
  23. * @ingroup tripal_organism
  24. */
  25. function tripal_organism_block_info() {
  26. $blocks['base']['info'] = t('Tripal Organism Details');
  27. $blocks['base']['cache'] = DRUPAL_NO_CACHE;
  28. return $blocks;
  29. }
  30. /**
  31. *
  32. * @ingroup tripal_organism
  33. */
  34. function tripal_organism_block_view($delta = '') {
  35. if (user_access('access chado_feature content') and arg(0) == 'node' and is_numeric(arg(1))) {
  36. $nid = arg(1);
  37. $node = node_load($nid);
  38. $block = array();
  39. switch ($delta) {
  40. case 'base':
  41. $block['subject'] = t('Organism Details');
  42. $block['content'] = theme('tripal_organism_base', $node);
  43. break;
  44. default:
  45. }
  46. return $block;
  47. }
  48. }
  49. /**
  50. * Menu items are automatically added for the new node types created
  51. * by this module to the 'Create Content' Navigation menu item. This function
  52. * adds more menu items needed for this module.
  53. *
  54. * @ingroup tripal_organism
  55. */
  56. function tripal_organism_menu() {
  57. $items = array();
  58. // the administative settings menu
  59. $items['admin/tripal/chado/tripal_organism'] = array(
  60. 'title' => 'Organisms',
  61. 'description' => 'Any living biological entity, such as an animal, plant, fungus, or bacterium.',
  62. 'page callback' => 'tripal_organism_admin_organism_view',
  63. 'access arguments' => array('adminster tripal organism'),
  64. 'type' => MENU_NORMAL_ITEM,
  65. );
  66. $items['admin/tripal/chado/tripal_organism/help'] = array(
  67. 'title' => 'Help',
  68. 'description' => "A description of the Tripal Organism module including a short description of it's usage.",
  69. 'page callback' => 'theme',
  70. 'page arguments' => array('tripal_organism_help'),
  71. 'access arguments' => array('adminster tripal organism'),
  72. 'type' => MENU_LOCAL_TASK,
  73. 'weight' => 10
  74. );
  75. $items['admin/tripal/chado/tripal_organism/configuration'] = array(
  76. 'title' => 'Settings',
  77. 'description' => 'Manage integration of Chado organisms including associated features',
  78. 'page callback' => 'drupal_get_form',
  79. 'page arguments' => array('tripal_organism_admin'),
  80. 'access arguments' => array('adminster tripal organism'),
  81. 'type' => MENU_LOCAL_TASK,
  82. 'weight' => 5
  83. );
  84. $items['admin/tripal/chado/tripal_organism/sync'] = array(
  85. 'title' => ' Sync',
  86. 'description' => 'Create pages on this site for organisms stored in Chado',
  87. 'page callback' => 'drupal_get_form',
  88. 'page arguments' => array('tripal_core_chado_node_sync_form', 'tripal_organism', 'chado_organism'),
  89. 'access arguments' => array('administer tripal organism'),
  90. 'type' => MENU_LOCAL_TASK,
  91. 'weight' => 2
  92. );
  93. $items['admin/tripal/chado/tripal_organism/views/organisms/enable'] = array(
  94. 'title' => 'Enable Organism Administrative View',
  95. 'page callback' => 'tripal_views_admin_enable_view',
  96. 'page arguments' => array('tripal_organism_admin_organisms', 'admin/tripal/chado/tripal_organism'),
  97. 'access arguments' => array('administer tripal organism'),
  98. 'type' => MENU_CALLBACK,
  99. );
  100. return $items;
  101. }
  102. /**
  103. * Implements hook_help()
  104. * Purpose: Adds a help page to the module list
  105. */
  106. function tripal_organism_help ($path, $arg) {
  107. if ($path == 'admin/help#tripal_organism') {
  108. return theme('tripal_organism_help', array());
  109. }
  110. }
  111. /**
  112. * We need to let drupal know about our theme functions and their arguments.
  113. * We create theme functions to allow users of the module to customize the
  114. * look and feel of the output generated in this module
  115. *
  116. * @ingroup tripal_organism
  117. */
  118. function tripal_organism_theme($existing, $type, $theme, $path) {
  119. $core_path = drupal_get_path('module', 'tripal_core');
  120. $items = array(
  121. 'node__chado_organism' => array(
  122. 'template' => 'node--chado-generic',
  123. 'render element' => 'node',
  124. 'base hook' => 'node',
  125. 'path' => "$core_path/theme",
  126. ),
  127. 'tripal_organism_base' => array(
  128. 'variables' => array('node' => NULL),
  129. 'template' => 'tripal_organism_base',
  130. 'path' => "$path/theme/tripal_organism",
  131. ),
  132. 'tripal_organism_properties' => array(
  133. 'variables' => array('node' => NULL),
  134. 'template' => 'tripal_organism_properties',
  135. 'path' => "$path/theme/tripal_organism",
  136. ),
  137. 'tripal_organism_references' => array(
  138. 'variables' => array('node' => NULL),
  139. 'template' => 'tripal_organism_references',
  140. 'path' => "$path/theme/tripal_organism",
  141. ),
  142. 'tripal_organism_teaser' => array(
  143. 'variables' => array('node' => NULL),
  144. 'template' => 'tripal_organism_teaser',
  145. 'path' => "$path/theme/tripal_organism",
  146. ),
  147. 'tripal_organism_help' => array(
  148. 'template' => 'tripal_organism_help',
  149. 'variables' => array(NULL),
  150. 'path' => "$path/theme",
  151. ),
  152. );
  153. return $items;
  154. }
  155. /**
  156. * Set the permission types that the chado module uses. Essentially we
  157. * want permissionis that protect creation, editing and deleting of chado
  158. * data objects
  159. *
  160. *
  161. @ingroup tripal_organism
  162. */
  163. function tripal_organism_permission() {
  164. return array(
  165. 'access chado_organism content' => array(
  166. 'title' => t('View Organisms'),
  167. 'description' => t('Allow users to view organism pages.'),
  168. ),
  169. 'create chado_organism content' => array(
  170. 'title' => t('Create Organisms'),
  171. 'description' => t('Allow users to create new organism pages.'),
  172. ),
  173. 'delete chado_organism content' => array(
  174. 'title' => t('Delete Organisms'),
  175. 'description' => t('Allow users to delete organism pages.'),
  176. ),
  177. 'edit chado_organism content' => array(
  178. 'title' => t('Edit Organisms'),
  179. 'description' => t('Allow users to edit organism pages.'),
  180. ),
  181. 'adminster tripal organism' => array(
  182. 'title' => t('Administer Organisms'),
  183. 'description' => t('Allow users to administer all organisms.'),
  184. ),
  185. );
  186. }
  187. /**
  188. * Implements hook_views_api()
  189. * Purpose: Essentially this hook tells drupal that there is views support for
  190. * for this module which then includes tripal_db.views.inc where all the
  191. * views integration code is
  192. *
  193. * @ingroup tripal_organism
  194. */
  195. function tripal_organism_views_api() {
  196. return array(
  197. 'api' => 2.0,
  198. );
  199. }
  200. /**
  201. *
  202. *
  203. * @ingroup tripal_organism
  204. */
  205. function tripal_organism_job_describe_args($callback, $args) {
  206. $new_args = array();
  207. if ($callback == 'tripal_organism_sync_organisms') {
  208. $organism = tripal_core_chado_select('organism', array('genus', 'species'), array('organism_id' => $args[0]));
  209. $new_args['Organism'] = $organism[0]->genus . " " . $organism[0]->species;
  210. }
  211. return $new_args;
  212. }
  213. /**
  214. * Implementation of hook_form_alter()
  215. *
  216. * @param $form
  217. * @param $form_state
  218. * @param $form_id
  219. */
  220. function tripal_organism_form_alter(&$form, &$form_state, $form_id) {
  221. // turn of preview button for insert/updates
  222. if ($form_id == "chado_organism_node_form") {
  223. $form['actions']['preview']['#access'] = FALSE;
  224. }
  225. }