tripal_organism.module 7.1 KB

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