tripal_contact.module 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <?php
  2. /**
  3. * @file
  4. * Functions related to general module functionality.
  5. *
  6. * @ingroup tripal_contact
  7. */
  8. /**
  9. * @defgroup tripal_contact Contact Module
  10. * @ingroup tripal_modules
  11. * @{
  12. * Integrates the Chado Contact module with Drupal Nodes & Views
  13. * @}
  14. */
  15. require 'api/tripal_contact.api.inc';
  16. require 'theme/tripal_contact.theme.inc';
  17. require 'includes/tripal_contact.admin.inc';
  18. require 'includes/tripal_contact.chado_node.inc';
  19. /**
  20. * Implements hook_views_api().
  21. * Essentially this hook tells drupal that there is views support for
  22. * for this module which then includes tripal_contact.views.inc where all the
  23. * views integration code is.
  24. *
  25. * @ingroup tripal_contact
  26. */
  27. function tripal_contact_views_api() {
  28. return array(
  29. 'api' => 3.0,
  30. );
  31. }
  32. /**
  33. * Implemets hook_menu().
  34. * Adds menu items for the tripal_contact module menu. This section
  35. * gives the outline for the main menu of the Tripal-contact module
  36. *
  37. * @return
  38. * An array of menu items that is visible within the Drupal Menu, returned as soon
  39. * as the program is ran
  40. *
  41. * @ingroup tripal_contact
  42. */
  43. function tripal_contact_menu() {
  44. $items = array();
  45. $items['admin/tripal/chado/tripal_contact']= array(
  46. 'title' => 'Contacts',
  47. 'description' => ('Model persons, institutes, groups, organizations, etc.'),
  48. 'page callback' => 'tripal_contact_admin_contact_view',
  49. 'access arguments' => array('administer tripal contact'),
  50. 'type' => MENU_NORMAL_ITEM
  51. );
  52. $items['admin/tripal/chado/tripal_contact/configuration'] = array(
  53. 'title' => 'Settings',
  54. 'description' => 'Integration of Chado contacts.',
  55. 'page callback' => 'drupal_get_form',
  56. 'page arguments' => array('tripal_contact_admin'),
  57. 'access arguments' => array('administer tripal contact'),
  58. 'type' => MENU_LOCAL_TASK,
  59. 'weight' => 5
  60. );
  61. $items['admin/tripal/chado/tripal_contact/help']= array(
  62. 'title' => 'Help',
  63. 'description' => ('Help with the contact module.'),
  64. 'page callback' => 'theme',
  65. 'page arguments' => array('tripal_contact_help'),
  66. 'access arguments' => array('administer tripal contact'),
  67. 'type' => MENU_LOCAL_TASK,
  68. 'weight' => 10
  69. );
  70. $items['admin/tripal/chado/tripal_contact/sync'] = array(
  71. 'title' => ' Sync',
  72. 'description' => 'Sync contacts in Chado with Drupal',
  73. 'page callback' => 'drupal_get_form',
  74. 'page arguments' => array('tripal_contact_sync_form'),
  75. 'access arguments' => array('administer tripal contact'),
  76. 'type' => MENU_LOCAL_TASK,
  77. 'weight' => 0
  78. );
  79. $items['admin/tripal/chado/tripal_contact/sync'] = array(
  80. 'title' => ' Sync',
  81. 'description' => 'Create pages on this site for libraries stored in Chado',
  82. 'page callback' => 'drupal_get_form',
  83. 'page arguments' => array('tripal_core_chado_node_sync_form', 'tripal_contact', 'chado_contact'),
  84. 'access arguments' => array('administer tripal contact'),
  85. 'type' => MENU_LOCAL_TASK,
  86. 'weight' => 2
  87. );
  88. return $items;
  89. }
  90. /**
  91. * Implements hook_theme().
  92. * Register themeing functions for this module
  93. *
  94. * @return
  95. * An array of themeing functions to register
  96. *
  97. * @ingroup tripal_contact
  98. */
  99. function tripal_contact_theme($existing, $type, $theme, $path) {
  100. $core_path = drupal_get_path('module', 'tripal_core');
  101. $items = array(
  102. 'node__chado_contact' => array(
  103. 'template' => 'node--chado-generic',
  104. 'render element' => 'node',
  105. 'base hook' => 'node',
  106. 'path' => "$core_path/theme",
  107. ),
  108. 'tripal_contact_base' => array(
  109. 'variables' => array('node' => NULL),
  110. 'template' => 'tripal_contact_base',
  111. 'path' => "$path/theme/tripal_contact",
  112. ),
  113. 'tripal_contact_properties' => array(
  114. 'variables' => array('node' => NULL),
  115. 'template' => 'tripal_contact_properties',
  116. 'path' => "$path/theme/tripal_contact",
  117. ),
  118. 'tripal_contact_relationships' => array(
  119. 'variables' => array('node' => NULL),
  120. 'template' => 'tripal_contact_relationships',
  121. 'path' => "$path/theme/tripal_contact",
  122. ),
  123. 'tripal_contact_publications' => array(
  124. 'variables' => array('node' => NULL),
  125. 'template' => 'tripal_contact_publications',
  126. 'path' => "$path/theme/tripal_contact",
  127. ),
  128. 'tripal_contact_help' => array(
  129. 'template' => 'tripal_contact_help',
  130. 'variables' => array(NULL),
  131. 'path' => "$path/theme",
  132. ),
  133. 'tripal_contact_teaser' => array(
  134. 'variables' => array('node' => NULL),
  135. 'template' => 'tripal_contact_teaser',
  136. 'path' => "$path/theme/tripal_contact",
  137. ),
  138. );
  139. return $items;
  140. }
  141. /**
  142. * Implements hook_block_info().
  143. *
  144. * @ingroup tripal_contact
  145. */
  146. function tripal_contact_block_info() {
  147. $blocks['contbase']['info'] = t('Tripal Contact Details');
  148. $blocks['contbase']['cache'] = 'DRUPAL_NO_CACHE';
  149. $blocks['contprops']['info'] = t('Tripal Contact Properties');
  150. $blocks['contprops']['cache'] = 'DRUPAL_NO_CACHE';
  151. $blocks['contrels']['info'] = t('Tripal Contact Relationships');
  152. $blocks['contrels']['cache'] = 'DRUPAL_NO_CACHE';
  153. $blocks['contpubs']['info'] = t('Tripal Contact Publications');
  154. $blocks['contpubs']['cache'] = 'DRUPAL_NO_CACHE';
  155. return $blocks;
  156. }
  157. /**
  158. * Implements hook_block_view().
  159. * @ingroup tripal_contact
  160. */
  161. function tripal_contact_block_view($delta = '') {
  162. if (user_access('access chado_contact content') and arg(0) == 'node' and is_numeric(arg(1))) {
  163. $nid = arg(1);
  164. $node = node_load($nid);
  165. $block = array();
  166. switch ($delta) {
  167. case 'contbase':
  168. $block['subject'] = t('Overview');
  169. $block['content'] = array(
  170. '#theme' => 'tripal_contact_base',
  171. '#nodes' => $node,
  172. '#title' => '',
  173. );
  174. break;
  175. case 'contprops':
  176. $block['subject'] = t('Properties');
  177. $block['content'] = array(
  178. '#theme' => 'tripal_contact_properties',
  179. '#nodes' => $node,
  180. '#title' => '',
  181. );
  182. break;
  183. case 'contrels':
  184. $block['subject'] = t('Relationships');
  185. $block['content'] = array(
  186. '#theme' => 'tripal_contact_relationships',
  187. '#nodes' => $node,
  188. '#title' => '',
  189. );
  190. break;
  191. case 'contpubs':
  192. $block['subject'] = t('Publications');
  193. $block['content'] = array(
  194. '#theme' => 'tripal_contact_publications',
  195. '#nodes' => $node,
  196. '#title' => '',
  197. );
  198. break;
  199. default :
  200. }
  201. return $block;
  202. }
  203. }
  204. /**
  205. * Implement hook_permission().
  206. *
  207. * @ingroup tripal_contact
  208. */
  209. function tripal_contact_permission() {
  210. return array(
  211. 'access chado_contact content' => array(
  212. 'title' => t('View Contacts'),
  213. 'description' => t('Allow users to view contact pages.'),
  214. ),
  215. 'create chado_contact content' => array(
  216. 'title' => t('Create Contacts'),
  217. 'description' => t('Allow users to create new contact pages.'),
  218. ),
  219. 'delete chado_contact content' => array(
  220. 'title' => t('Delete Contacts'),
  221. 'description' => t('Allow users to delete contact pages.'),
  222. ),
  223. 'edit chado_contact content' => array(
  224. 'title' => t('Edit Contacts'),
  225. 'description' => t('Allow users to edit contact pages.'),
  226. ),
  227. 'adminster tripal contact' => array(
  228. 'title' => t('Administer Contacts'),
  229. 'description' => t('Allow users to administer all contacts.'),
  230. ),
  231. );
  232. }
  233. /**
  234. * Implementation of hook_form_alter().
  235. *
  236. * @ingroup tripal_contact
  237. */
  238. function tripal_contact_form_alter(&$form, &$form_state, $form_id) {
  239. // turn of preview button for insert/updates
  240. if ($form_id == "chado_contact_node_form") {
  241. $form['actions']['preview']['#access'] = FALSE;
  242. }
  243. }