tripal_organism.module 7.8 KB

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