tripal_contact.module 8.9 KB

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