tripal_organism.module 7.4 KB

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