tripal_organism.module 7.9 KB

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