tripal_organism.module 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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('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_search_biological_data_views().
  104. *
  105. * Adds the described views to the "Search Biological Data" Page created by Tripal Views
  106. */
  107. function tripal_organism_search_biological_data_views() {
  108. return array(
  109. 'tripal_organism_user_organisms' => array(
  110. 'machine_name' => 'tripal_organism_user_organisms',
  111. 'human_name' => 'Organisms',
  112. 'description' => 'Any living biological entity, such as an animal, plant, fungus, or bacterium.',
  113. 'link' => 'chado/organism'
  114. ),
  115. );
  116. }
  117. /**
  118. * Implements hook_help().
  119. * Adds a help page to the module list
  120. *
  121. * @ingroup tripal_organism
  122. */
  123. function tripal_organism_help ($path, $arg) {
  124. if ($path == 'admin/help#tripal_organism') {
  125. return theme('tripal_organism_help', array());
  126. }
  127. }
  128. /**
  129. * Implements hook_theme().
  130. *
  131. * We need to let drupal know about our theme functions and their arguments.
  132. * We create theme functions to allow users of the module to customize the
  133. * look and feel of the output generated in this module
  134. *
  135. * @ingroup tripal_organism
  136. */
  137. function tripal_organism_theme($existing, $type, $theme, $path) {
  138. $core_path = drupal_get_path('module', 'tripal_core');
  139. $items = array(
  140. 'node__chado_organism' => array(
  141. 'template' => 'node--chado-generic',
  142. 'render element' => 'node',
  143. 'base hook' => 'node',
  144. 'path' => "$core_path/theme",
  145. ),
  146. 'tripal_organism_base' => array(
  147. 'variables' => array('node' => NULL),
  148. 'template' => 'tripal_organism_base',
  149. 'path' => "$path/theme/tripal_organism",
  150. ),
  151. 'tripal_organism_properties' => array(
  152. 'variables' => array('node' => NULL),
  153. 'template' => 'tripal_organism_properties',
  154. 'path' => "$path/theme/tripal_organism",
  155. ),
  156. 'tripal_organism_references' => array(
  157. 'variables' => array('node' => NULL),
  158. 'template' => 'tripal_organism_references',
  159. 'path' => "$path/theme/tripal_organism",
  160. ),
  161. 'tripal_organism_teaser' => array(
  162. 'variables' => array('node' => NULL),
  163. 'template' => 'tripal_organism_teaser',
  164. 'path' => "$path/theme/tripal_organism",
  165. ),
  166. 'tripal_organism_help' => array(
  167. 'template' => 'tripal_organism_help',
  168. 'variables' => array(NULL),
  169. 'path' => "$path/theme",
  170. ),
  171. );
  172. return $items;
  173. }
  174. /**
  175. * Implements hook_permission().
  176. *
  177. * Set the permission types that the chado module uses. Essentially we
  178. * want permissionis that protect creation, editing and deleting of chado
  179. * data objects
  180. *
  181. * @ingroup tripal_organism
  182. */
  183. function tripal_organism_permission() {
  184. return array(
  185. 'access chado_organism content' => array(
  186. 'title' => t('View Organisms'),
  187. 'description' => t('Allow users to view organism pages.'),
  188. ),
  189. 'create chado_organism content' => array(
  190. 'title' => t('Create Organisms'),
  191. 'description' => t('Allow users to create new organism pages.'),
  192. ),
  193. 'delete chado_organism content' => array(
  194. 'title' => t('Delete Organisms'),
  195. 'description' => t('Allow users to delete organism pages.'),
  196. ),
  197. 'edit chado_organism content' => array(
  198. 'title' => t('Edit Organisms'),
  199. 'description' => t('Allow users to edit organism pages.'),
  200. ),
  201. 'adminster tripal organism' => array(
  202. 'title' => t('Administer Organisms'),
  203. 'description' => t('Allow users to administer all organisms.'),
  204. ),
  205. );
  206. }
  207. /**
  208. * Implements hook_views_api().
  209. *
  210. * Essentially this hook tells drupal that there is views support for
  211. * for this module which then includes tripal_db.views.inc where all the
  212. * views integration code is
  213. *
  214. * @ingroup tripal_organism
  215. */
  216. function tripal_organism_views_api() {
  217. return array(
  218. 'api' => 3.0,
  219. );
  220. }
  221. /**
  222. * Implements hook_job_describe_args().
  223. *
  224. * @ingroup tripal_organism
  225. */
  226. function tripal_organism_job_describe_args($callback, $args) {
  227. $new_args = array();
  228. if ($callback == 'tripal_organism_sync_organisms') {
  229. $organism = chado_select_record('organism', array('genus', 'species'), array('organism_id' => $args[0]));
  230. $new_args['Organism'] = $organism[0]->genus . " " . $organism[0]->species;
  231. }
  232. return $new_args;
  233. }
  234. /**
  235. * Implementation of hook_form_alter().
  236. *
  237. * @param $form
  238. * @param $form_state
  239. * @param $form_id
  240. *
  241. * @ingroup tripal_organism
  242. */
  243. function tripal_organism_form_alter(&$form, &$form_state, $form_id) {
  244. // turn of preview button for insert/updates
  245. if ($form_id == "chado_organism_node_form") {
  246. $form['actions']['preview']['#access'] = FALSE;
  247. }
  248. }