tripal_organism.module 7.9 KB

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