tripal_contact.module 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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 contacts'),
  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 contacts'),
  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 contacts'),
  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. // AJAX calls for adding/removing properties to a contact
  95. $items['tripal_contact/properties/add'] = array(
  96. 'page callback' => 'tripal_contact_property_add',
  97. 'access arguments' => array('edit chado_contact content'),
  98. 'type ' => MENU_CALLBACK,
  99. );
  100. $items['tripal_contact/properties/description'] = array(
  101. 'page callback' => 'tripal_contact_property_get_description',
  102. 'access arguments' => array('edit chado_contact content'),
  103. 'type ' => MENU_CALLBACK,
  104. );
  105. $items['tripal_contact/properties/minus/%/%'] = array(
  106. 'page callback' => 'tripal_contact_property_delete',
  107. 'page arguments' => array(3, 4),
  108. 'access arguments' => array('edit chado_contact content'),
  109. 'type ' => MENU_CALLBACK,
  110. );
  111. return $items;
  112. }
  113. /**
  114. * Implements hook_theme(): Register themeing functions for this module
  115. *
  116. *
  117. * @return
  118. * An array of themeing functions to register
  119. *
  120. */
  121. function tripal_contact_theme($existing, $type, $theme, $path) {
  122. $core_path = drupal_get_path('module', 'tripal_core');
  123. $items = array(
  124. 'node__chado_contact' => array(
  125. 'template' => 'node--chado-generic',
  126. 'render element' => 'node',
  127. 'base hook' => 'node',
  128. 'path' => "$core_path/theme",
  129. ),
  130. 'tripal_contact_base' => array(
  131. 'variables' => array('node' => NULL),
  132. 'template' => 'tripal_contact_base',
  133. 'path' => "$path/theme/tripal_contact",
  134. ),
  135. 'tripal_contact_properties' => array(
  136. 'variables' => array('node' => NULL),
  137. 'template' => 'tripal_contact_properties',
  138. 'path' => "$path/theme/tripal_contact",
  139. ),
  140. 'tripal_contact_relationships' => array(
  141. 'variables' => array('node' => NULL),
  142. 'template' => 'tripal_contact_relationships',
  143. 'path' => "$path/theme/tripal_contact",
  144. ),
  145. 'tripal_contact_publications' => array(
  146. 'variables' => array('node' => NULL),
  147. 'template' => 'tripal_contact_publications',
  148. 'path' => "$path/theme/tripal_contact",
  149. ),
  150. 'tripal_contact_help' => array(
  151. 'template' => 'tripal_contact_help',
  152. 'variables' => array(NULL),
  153. 'path' => "$path/theme",
  154. ),
  155. 'tripal_contact_teaser' => array(
  156. 'variables' => array('node' => NULL),
  157. 'template' => 'tripal_contact_teaser',
  158. 'path' => "$path/theme/tripal_contact",
  159. ),
  160. );
  161. return $items;
  162. }
  163. /**
  164. * @ingroup tripal_contact
  165. */
  166. function tripal_contact_block_info() {
  167. $blocks['contbase']['info'] = t('Tripal Contact Details');
  168. $blocks['contbase']['cache'] = 'DRUPAL_NO_CACHE';
  169. $blocks['contprops']['info'] = t('Tripal Contact Properties');
  170. $blocks['contprops']['cache'] = 'DRUPAL_NO_CACHE';
  171. $blocks['contrels']['info'] = t('Tripal Contact Relationships');
  172. $blocks['contrels']['cache'] = 'DRUPAL_NO_CACHE';
  173. $blocks['contpubs']['info'] = t('Tripal Contact Publications');
  174. $blocks['contpubs']['cache'] = 'DRUPAL_NO_CACHE';
  175. return $blocks;
  176. }
  177. /**
  178. * @ingroup tripal_contact
  179. */
  180. function tripal_contact_block_view($delta = '') {
  181. if (user_access('access chado_contact content') and arg(0) == 'node' and is_numeric(arg(1))) {
  182. $nid = arg(1);
  183. $node = node_load($nid);
  184. $block = array();
  185. switch ($delta) {
  186. case 'contbase':
  187. $block['subject'] = t('Details');
  188. $block['content'] = array(
  189. '#theme' => 'tripal_contact_base',
  190. '#nodes' => $node,
  191. '#title' => '',
  192. );
  193. break;
  194. case 'contprops':
  195. $block['subject'] = t('Properties');
  196. $block['content'] = array(
  197. '#theme' => 'tripal_contact_properties',
  198. '#nodes' => $node,
  199. '#title' => '',
  200. );
  201. break;
  202. case 'contrels':
  203. $block['subject'] = t('Relationships');
  204. $block['content'] = array(
  205. '#theme' => 'tripal_contact_relationships',
  206. '#nodes' => $node,
  207. '#title' => '',
  208. );
  209. break;
  210. case 'contpubs':
  211. $block['subject'] = t('Publications');
  212. $block['content'] = array(
  213. '#theme' => 'tripal_contact_publications',
  214. '#nodes' => $node,
  215. '#title' => '',
  216. );
  217. break;
  218. default :
  219. }
  220. return $block;
  221. }
  222. }
  223. /**
  224. * Implement hook_perm().
  225. */
  226. function tripal_contact_permissions() {
  227. return array(
  228. 'access chado_contact content' => array(
  229. 'title' => t('View Contacts'),
  230. 'description' => t('Allow users to view contact pages.'),
  231. ),
  232. 'create chado_contact content' => array(
  233. 'title' => t('Create Contacts'),
  234. 'description' => t('Allow users to create new contact pages.'),
  235. ),
  236. 'delete chado_contact content' => array(
  237. 'title' => t('Delete Contacts'),
  238. 'description' => t('Allow users to delete contact pages.'),
  239. ),
  240. 'edit chado_contact content' => array(
  241. 'title' => t('Edit Contacts'),
  242. 'description' => t('Allow users to edit contact pages.'),
  243. ),
  244. 'adminster tripal contact' => array(
  245. 'title' => t('Administer Contacts'),
  246. 'description' => t('Allow users to administer all contacts.'),
  247. ),
  248. );
  249. }
  250. /**
  251. * Implementation of hook_form_alter()
  252. *
  253. * @param $form
  254. * @param $form_state
  255. * @param $form_id
  256. */
  257. function tripal_contact_form_alter(&$form, &$form_state, $form_id) {
  258. // turn of preview button for insert/updates
  259. if ($form_id == "chado_contact_node_form") {
  260. $form['actions']['preview']['#access'] = FALSE;
  261. }
  262. }