-
Notifications
You must be signed in to change notification settings - Fork 0
/
tripal_ws_brapi.module
144 lines (124 loc) · 4.97 KB
/
tripal_ws_brapi.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
/**
* @file
* The main functionality of this module.
*/
$dir_class = 'class/';
$module = 'tripal_ws_brapi';
// Include helper functions.
module_load_include('inc', 'tripal_ws_brapi', 'includes/api');
// Include helper classes.
// Class to identify resource from a url.
module_load_include('inc', $module, $dir_class . 'helper class/TripalWebServiceResourceIdentifier');
// Class handle response result.
module_load_include('inc', $module, $dir_class . 'helper class/TripalWebServiceResponse');
// Include base classes.
// Base call/request class.
module_load_include('inc', $module, $dir_class . 'TripalWebServiceCall');
// Class for custom calls (non database).
module_load_include('inc', $module, $dir_class . 'TripalWebServiceCustomCall');
// Class for db calls (database).
module_load_include('inc', $module, $dir_class . 'TripalWebServiceDatabaseCall');
// Class for search calls (database).
module_load_include('inc', $module, $dir_class . 'TripalWebServiceSearchCall');
/**
* Implements hook_menu().
*/
function tripal_ws_brapi_menu() {
$items = [];
$module = tripal_ws_get_module_info();
// To add level to menu location, ie. host/[web-services/another-level]/brapi or
// set value to blank to set menu level directly to host/brapi/.
// @see configuration page.
$menu_level = variable_get($module['module'] . '_menu_level');
$base_menu_location = ($menu_level == '') ? 'brapi' : trim($menu_level) . '/brapi';
$items[ $base_menu_location ] = [
'title' => 'Tripal Web Services API',
'page callback' => 'tripal_ws_vocabulary_handle_request',
'access arguments' => ['access content'],
'type' => MENU_CALLBACK,
];
//////////////////////////////////////////////////////////////////////////
// Configuration pages:
$path_tripal_extension = 'admin/tripal/extension/tripalwsbrapi';
// Configuration page. List all calls.
$items[ $path_tripal_extension . '/configure' ] = [
'title' => 'Tripal Web Service - BrAPI',
'description' => t('Interface to configure calls'),
'page callback' => 'drupal_get_form',
'page arguments' => ['tripal_ws_configure'],
'access arguments' => ['access administration pages'],
'file' => 'includes/forms/configuration.form.inc',
'type' => MENU_NORMAL_ITEM,
];
// General module configuration.
$items[ $path_tripal_extension . '/configure/module' ] = [
'title' => 'Configure Tripal Web Service - BrAPI',
'description' => t('Interface to configure calls'),
'page callback' => 'drupal_get_form',
'page arguments' => ['tripal_ws_configure_module', 3],
'access arguments' => ['access administration pages'],
'file' => 'includes/forms/configuration.form.inc',
'type' => MENU_LOCAL_TASK,
'weight' => 1,
];
// Configure version.
$items[ $path_tripal_extension . '/configure/version' ] = [
'title' => 'BrAPI Version',
'description' => t('Interface to configure version'),
'page callback' => 'drupal_get_form',
'page arguments' => ['tripal_ws_configure_version'],
'access arguments' => ['access administration pages'],
'file' => 'includes/forms/configuration.form.inc',
'type' => MENU_LOCAL_TASK,
'weight' => 2,
];
// Configure a call.
$items[ $path_tripal_extension . '/configure/call' ] = [
'title' => 'BrAPI Calls',
'description' => t('Interface to configure calls'),
'page callback' => 'drupal_get_form',
'page arguments' => ['tripal_ws_configure_call'],
'access arguments' => ['access administration pages'],
'file' => 'includes/forms/configuration.form.inc',
'type' => MENU_LOCAL_TASK,
'weight' => 3,
];
// Manage search request
$items[ $path_tripal_extension . '/configure/search' ] = [
'title' => 'Search Request Log',
'description' => t('Interface to manage search request'),
'page callback' => 'drupal_get_form',
'page arguments' => ['tripal_ws_manage_search'],
'access arguments' => ['access administration pages'],
'file' => 'includes/forms/configuration.form.inc',
'type' => MENU_LOCAL_TASK,
'weight' => 4,
];
return $items;
}
/**
* Function callback (page callback), begin processing call request.
*/
if (!function_exists('tripal_ws_vocabulary_handle_request')) {
function tripal_ws_vocabulary_handle_request() {
// Identify all resources required.
$resource = new TripalWebserviceResourceIdentifier();
$call_asset = get_object_vars($resource);
// Call asset data stucture.
// @see class/helper class/TripalWebServiceResourceIdentifier.
/*
// DEBUG.
print '<pre>';
print_r($call_asset);
print '</pre>';
*/
// Load call class file.
$call = tripal_ws_load_call($call_asset);
// Response.
if (class_exists($call)) {
$response = new $call($call_asset);
$response->prepareResponse();
}
}
}