tripal_contact.module 7.6 KB

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