tripal_organism.module 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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 'api/tripal_organism.DEPRECATED.inc';
  8. require_once 'includes/tripal_organism.admin.inc';
  9. require_once 'includes/tripal_organism.chado_node.inc';
  10. /**
  11. * @defgroup tripal_organism Organism Module
  12. * @ingroup tripal_modules
  13. * @{
  14. * Integrates the Chado Organism module with Drupal Nodes & Views
  15. * @}
  16. */
  17. /**
  18. * Implements hook_block_info().
  19. *
  20. * @ingroup tripal_organism
  21. */
  22. function tripal_organism_block_info() {
  23. $blocks['base']['info'] = t('Tripal Organism Details');
  24. $blocks['base']['cache'] = DRUPAL_NO_CACHE;
  25. return $blocks;
  26. }
  27. /**
  28. * Implements hook_block_view().
  29. *
  30. * @ingroup tripal_organism
  31. */
  32. function tripal_organism_block_view($delta = '') {
  33. if (user_access('access chado_feature content') and arg(0) == 'node' and is_numeric(arg(1))) {
  34. $nid = arg(1);
  35. $node = node_load($nid);
  36. $block = array();
  37. switch ($delta) {
  38. case 'base':
  39. $block['subject'] = t('Organism Details');
  40. $block['content'] = theme('tripal_organism_base', $node);
  41. break;
  42. default:
  43. }
  44. return $block;
  45. }
  46. }
  47. /**
  48. * Implements hook_menu().
  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. * Adds a help page to the module list
  105. *
  106. * @ingroup tripal_organism
  107. */
  108. function tripal_organism_help ($path, $arg) {
  109. if ($path == 'admin/help#tripal_organism') {
  110. return theme('tripal_organism_help', array());
  111. }
  112. }
  113. /**
  114. * Implements hook_theme().
  115. *
  116. * We need to let drupal know about our theme functions and their arguments.
  117. * We create theme functions to allow users of the module to customize the
  118. * look and feel of the output generated in this module
  119. *
  120. * @ingroup tripal_organism
  121. */
  122. function tripal_organism_theme($existing, $type, $theme, $path) {
  123. $core_path = drupal_get_path('module', 'tripal_core');
  124. $items = array(
  125. 'node__chado_organism' => array(
  126. 'template' => 'node--chado-generic',
  127. 'render element' => 'node',
  128. 'base hook' => 'node',
  129. 'path' => "$core_path/theme",
  130. ),
  131. 'tripal_organism_base' => array(
  132. 'variables' => array('node' => NULL),
  133. 'template' => 'tripal_organism_base',
  134. 'path' => "$path/theme/tripal_organism",
  135. ),
  136. 'tripal_organism_properties' => array(
  137. 'variables' => array('node' => NULL),
  138. 'template' => 'tripal_organism_properties',
  139. 'path' => "$path/theme/tripal_organism",
  140. ),
  141. 'tripal_organism_references' => array(
  142. 'variables' => array('node' => NULL),
  143. 'template' => 'tripal_organism_references',
  144. 'path' => "$path/theme/tripal_organism",
  145. ),
  146. 'tripal_organism_teaser' => array(
  147. 'variables' => array('node' => NULL),
  148. 'template' => 'tripal_organism_teaser',
  149. 'path' => "$path/theme/tripal_organism",
  150. ),
  151. 'tripal_organism_help' => array(
  152. 'template' => 'tripal_organism_help',
  153. 'variables' => array(NULL),
  154. 'path' => "$path/theme",
  155. ),
  156. );
  157. return $items;
  158. }
  159. /**
  160. * Implements hook_permission().
  161. *
  162. * Set the permission types that the chado module uses. Essentially we
  163. * want permissionis that protect creation, editing and deleting of chado
  164. * data objects
  165. *
  166. * @ingroup tripal_organism
  167. */
  168. function tripal_organism_permission() {
  169. return array(
  170. 'access chado_organism content' => array(
  171. 'title' => t('View Organisms'),
  172. 'description' => t('Allow users to view organism pages.'),
  173. ),
  174. 'create chado_organism content' => array(
  175. 'title' => t('Create Organisms'),
  176. 'description' => t('Allow users to create new organism pages.'),
  177. ),
  178. 'delete chado_organism content' => array(
  179. 'title' => t('Delete Organisms'),
  180. 'description' => t('Allow users to delete organism pages.'),
  181. ),
  182. 'edit chado_organism content' => array(
  183. 'title' => t('Edit Organisms'),
  184. 'description' => t('Allow users to edit organism pages.'),
  185. ),
  186. 'adminster tripal organism' => array(
  187. 'title' => t('Administer Organisms'),
  188. 'description' => t('Allow users to administer all organisms.'),
  189. ),
  190. );
  191. }
  192. /**
  193. * Implements hook_views_api().
  194. *
  195. * Essentially this hook tells drupal that there is views support for
  196. * for this module which then includes tripal_db.views.inc where all the
  197. * views integration code is
  198. *
  199. * @ingroup tripal_organism
  200. */
  201. function tripal_organism_views_api() {
  202. return array(
  203. 'api' => 3.0,
  204. );
  205. }
  206. /**
  207. * Implements hook_job_describe_args().
  208. *
  209. * @ingroup tripal_organism
  210. */
  211. function tripal_organism_job_describe_args($callback, $args) {
  212. $new_args = array();
  213. if ($callback == 'tripal_organism_sync_organisms') {
  214. $organism = chado_select_record('organism', array('genus', 'species'), array('organism_id' => $args[0]));
  215. $new_args['Organism'] = $organism[0]->genus . " " . $organism[0]->species;
  216. }
  217. return $new_args;
  218. }
  219. /**
  220. * Implementation of hook_form_alter().
  221. *
  222. * @param $form
  223. * @param $form_state
  224. * @param $form_id
  225. *
  226. * @ingroup tripal_organism
  227. */
  228. function tripal_organism_form_alter(&$form, &$form_state, $form_id) {
  229. if ($form_id == "chado_organism_node_form") {
  230. // turn of preview button for insert/updates
  231. $form['actions']['preview']['#access'] = FALSE;
  232. //remove the body field
  233. unset($form['body']);
  234. }
  235. }