tripal_contact.module 7.8 KB

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