tripal_organism.module 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. * Provides functions for managing chado organisms including creating details pages for each one
  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_teaser' => array(
  133. 'variables' => array('node' => NULL),
  134. 'template' => 'tripal_organism_teaser',
  135. 'path' => "$path/theme/tripal_organism",
  136. ),
  137. 'tripal_organism_help' => array(
  138. 'template' => 'tripal_organism_help',
  139. 'variables' => array(NULL),
  140. 'path' => "$path/theme",
  141. ),
  142. );
  143. return $items;
  144. }
  145. /**
  146. * Set the permission types that the chado module uses. Essentially we
  147. * want permissionis that protect creation, editing and deleting of chado
  148. * data objects
  149. *
  150. *
  151. @ingroup tripal_organism
  152. */
  153. function tripal_organism_permission() {
  154. return array(
  155. 'access chado_organism content' => array(
  156. 'title' => t('View Organisms'),
  157. 'description' => t('Allow users to view organism pages.'),
  158. ),
  159. 'create chado_organism content' => array(
  160. 'title' => t('Create Organisms'),
  161. 'description' => t('Allow users to create new organism pages.'),
  162. ),
  163. 'delete chado_organism content' => array(
  164. 'title' => t('Delete Organisms'),
  165. 'description' => t('Allow users to delete organism pages.'),
  166. ),
  167. 'edit chado_organism content' => array(
  168. 'title' => t('Edit Organisms'),
  169. 'description' => t('Allow users to edit organism pages.'),
  170. ),
  171. 'adminster tripal organism' => array(
  172. 'title' => t('Administer Organisms'),
  173. 'description' => t('Allow users to administer all organisms.'),
  174. ),
  175. );
  176. }
  177. /**
  178. * Implements hook_views_api()
  179. * Purpose: Essentially this hook tells drupal that there is views support for
  180. * for this module which then includes tripal_db.views.inc where all the
  181. * views integration code is
  182. *
  183. * @ingroup tripal_organism
  184. */
  185. function tripal_organism_views_api() {
  186. return array(
  187. 'api' => 2.0,
  188. );
  189. }
  190. /**
  191. *
  192. *
  193. * @ingroup tripal_organism
  194. */
  195. function tripal_organism_job_describe_args($callback, $args) {
  196. $new_args = array();
  197. if ($callback == 'tripal_organism_sync_organisms') {
  198. $organism = tripal_core_chado_select('organism', array('genus', 'species'), array('organism_id' => $args[0]));
  199. $new_args['Organism'] = $organism[0]->genus . " " . $organism[0]->species;
  200. }
  201. return $new_args;
  202. }
  203. /**
  204. * Implementation of hook_form_alter()
  205. *
  206. * @param $form
  207. * @param $form_state
  208. * @param $form_id
  209. */
  210. function tripal_organism_form_alter(&$form, &$form_state, $form_id) {
  211. // turn of preview button for insert/updates
  212. if ($form_id == "chado_organism_node_form") {
  213. $form['actions']['preview']['#access'] = FALSE;
  214. }
  215. }