tripal_contact.module 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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. }
  37. /**
  38. * Tripal-contact-Menu
  39. *
  40. * Implemets hook_menu(): Adds menu items for the tripal_contact module menu. This section
  41. * gives the outline for the main menu of the Tripal-contact module
  42. *
  43. * @return
  44. * An array of menu items that is visible within the Drupal Menu, returned as soon
  45. * as the program is ran
  46. */
  47. function tripal_contact_menu() {
  48. $items = array();
  49. $items['admin/tripal/chado/tripal_contact']= array(
  50. 'title' => 'Contacts',
  51. 'description' => ('Model persons, institutes, groups, organizations, etc.'),
  52. 'page callback' => 'tripal_contact_admin_contact_view',
  53. 'access arguments' => array('administer tripal contact'),
  54. 'type' => MENU_NORMAL_ITEM
  55. );
  56. $items['admin/tripal/chado/tripal_contact/configuration'] = array(
  57. 'title' => 'Settings',
  58. 'description' => 'Integration of Chado contacts.',
  59. 'page callback' => 'drupal_get_form',
  60. 'page arguments' => array('tripal_contact_admin'),
  61. 'access arguments' => array('administer tripal contact'),
  62. 'type' => MENU_LOCAL_TASK,
  63. 'weight' => 5
  64. );
  65. $items['admin/tripal/chado/tripal_contact/help']= array(
  66. 'title' => 'Help',
  67. 'description' => ('Help with the contact module.'),
  68. 'page callback' => 'theme',
  69. 'page arguments' => array('tripal_contact_help'),
  70. 'access arguments' => array('administer tripal contact'),
  71. 'type' => MENU_LOCAL_TASK,
  72. 'weight' => 10
  73. );
  74. $items['admin/tripal/chado/tripal_contact/sync'] = array(
  75. 'title' => ' Sync',
  76. 'description' => 'Sync contacts in Chado with Drupal',
  77. 'page callback' => 'drupal_get_form',
  78. 'page arguments' => array('tripal_contact_sync_form'),
  79. 'access arguments' => array('administer tripal contact'),
  80. 'type' => MENU_LOCAL_TASK,
  81. 'weight' => 0
  82. );
  83. $items['admin/tripal/chado/tripal_contact/sync'] = array(
  84. 'title' => ' Sync',
  85. 'description' => 'Create pages on this site for libraries stored in Chado',
  86. 'page callback' => 'drupal_get_form',
  87. 'page arguments' => array('tripal_core_chado_node_sync_form', 'tripal_contact', 'chado_contact'),
  88. 'access arguments' => array('administer tripal contact'),
  89. 'type' => MENU_LOCAL_TASK,
  90. 'weight' => 2
  91. );
  92. return $items;
  93. }
  94. /**
  95. * Implements hook_theme(): Register themeing functions for this module
  96. *
  97. *
  98. * @return
  99. * An array of themeing functions to register
  100. *
  101. */
  102. function tripal_contact_theme($existing, $type, $theme, $path) {
  103. $core_path = drupal_get_path('module', 'tripal_core');
  104. $items = array(
  105. 'node__chado_contact' => array(
  106. 'template' => 'node--chado-generic',
  107. 'render element' => 'node',
  108. 'base hook' => 'node',
  109. 'path' => "$core_path/theme",
  110. ),
  111. 'tripal_contact_base' => array(
  112. 'variables' => array('node' => NULL),
  113. 'template' => 'tripal_contact_base',
  114. 'path' => "$path/theme/tripal_contact",
  115. ),
  116. 'tripal_contact_properties' => array(
  117. 'variables' => array('node' => NULL),
  118. 'template' => 'tripal_contact_properties',
  119. 'path' => "$path/theme/tripal_contact",
  120. ),
  121. 'tripal_contact_relationships' => array(
  122. 'variables' => array('node' => NULL),
  123. 'template' => 'tripal_contact_relationships',
  124. 'path' => "$path/theme/tripal_contact",
  125. ),
  126. 'tripal_contact_publications' => array(
  127. 'variables' => array('node' => NULL),
  128. 'template' => 'tripal_contact_publications',
  129. 'path' => "$path/theme/tripal_contact",
  130. ),
  131. 'tripal_contact_help' => array(
  132. 'template' => 'tripal_contact_help',
  133. 'variables' => array(NULL),
  134. 'path' => "$path/theme",
  135. ),
  136. 'tripal_contact_teaser' => array(
  137. 'variables' => array('node' => NULL),
  138. 'template' => 'tripal_contact_teaser',
  139. 'path' => "$path/theme/tripal_contact",
  140. ),
  141. );
  142. return $items;
  143. }
  144. /**
  145. * @ingroup tripal_contact
  146. */
  147. function tripal_contact_block_info() {
  148. $blocks['contbase']['info'] = t('Tripal Contact Details');
  149. $blocks['contbase']['cache'] = 'DRUPAL_NO_CACHE';
  150. $blocks['contprops']['info'] = t('Tripal Contact Properties');
  151. $blocks['contprops']['cache'] = 'DRUPAL_NO_CACHE';
  152. $blocks['contrels']['info'] = t('Tripal Contact Relationships');
  153. $blocks['contrels']['cache'] = 'DRUPAL_NO_CACHE';
  154. $blocks['contpubs']['info'] = t('Tripal Contact Publications');
  155. $blocks['contpubs']['cache'] = 'DRUPAL_NO_CACHE';
  156. return $blocks;
  157. }
  158. /**
  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_perm().
  206. */
  207. function tripal_contact_permissions() {
  208. return array(
  209. 'access chado_contact content' => array(
  210. 'title' => t('View Contacts'),
  211. 'description' => t('Allow users to view contact pages.'),
  212. ),
  213. 'create chado_contact content' => array(
  214. 'title' => t('Create Contacts'),
  215. 'description' => t('Allow users to create new contact pages.'),
  216. ),
  217. 'delete chado_contact content' => array(
  218. 'title' => t('Delete Contacts'),
  219. 'description' => t('Allow users to delete contact pages.'),
  220. ),
  221. 'edit chado_contact content' => array(
  222. 'title' => t('Edit Contacts'),
  223. 'description' => t('Allow users to edit contact pages.'),
  224. ),
  225. 'adminster tripal contact' => array(
  226. 'title' => t('Administer Contacts'),
  227. 'description' => t('Allow users to administer all contacts.'),
  228. ),
  229. );
  230. }
  231. /**
  232. * Implementation of hook_form_alter()
  233. *
  234. * @param $form
  235. * @param $form_state
  236. * @param $form_id
  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. }