tripal_contact.module 7.4 KB

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