-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsms_service.inc
114 lines (98 loc) · 2.96 KB
/
sms_service.inc
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
<?php
/**
* @file
* Implements missing alma for checking status on which alerts the user is registered to.
*/
/**
* missing define in alma client
*/
define('ALMA_SERVICE_METHOD_EMAIL', 'email');
/**
* Instead of copying alma to sites/all and maintain it,
* we defind our own methods to implement missing alma integration
*/
class Smsservice extends AlmaClient {
/**
* Implements to check messages service in patron
* (not implemented in original alma module
* only implemented add and remove messages).
*/
function GetPatronInfo($borr_card, $pin_code, $extended = FALSE) {
$path = ($extended) ? 'patron/informationExtended' : 'patron/information';
$info_node = ($extended) ? 'patronInformationExtended' : 'patronInformation';
$doc = $this->request($path, array('borrCard' => $borr_card, 'pinCode' => $pin_code));
$info = $doc->getElementsByTagName($info_node)->item(0);
$data = array(
'sendMethods' => array(),
);
// The missing part.
foreach ($info->getElementsByTagName('sendMethod') as $type) {
$data['sendMethods'][] = array(
'value' => $type->getAttribute('value'),
);
}
return $data;
}
}
/**
* New client
*/
function sms_service_client() {
// This is basically a singleton. We also wait until right before
// instantiating to include our required classes. That seems like a
// decent performance tradeoff instead of loading everything on every
// page load.
static $client;
if (!isset($client)) {
$path = drupal_get_path('module', 'alma');
try {
$client = new Smsservice(variable_get('alma_base_url', ''));
} catch (Exception $e) {
watchdog('alma', 'Constructor error: “@message”', array('@message' => $e->getMessage(), WATCHDOG_ERROR));
return NULL;
}
}
return $client;
}
/**
* New client to invoke custom changes
*/
function sms_service_client_invoke($method) {
$args = func_get_args();
// Lose the method.
array_shift($args);
$client = sms_service_client();
try {
$result = call_user_func_array(array($client, $method), $args);
} catch (Exception $e) {
watchdog('alma', '@method error: “@message”', array('@method' => $method, '@message' => $e->getMessage()), WATCHDOG_ERROR);
throw $e;
}
return $result;
}
/**
* messages/sendMethods for patron
*/
function sms_service_get_patron($creds = NULL, $reset = FALSE, $as_array = FALSE) {
if (is_null($creds)) {
// Get creds, which may throw an exception that login is required.
global $user;
try {
$creds = ding_user_get_creds($user);
} catch (DingProviderAuthException $e) {
return NULL;
}
}
static $patron;
if (!$patron || $reset) {
$info = sms_service_client_invoke('GetPatronInfo', $creds['name'], $creds['pass'], TRUE);
$patron = array(
// The missing part.
'messages' => isset($info['sendMethods']) ? $info['sendMethods'] : '',
);
}
if ($as_array) {
return $patron;
}
return (object) $patron;
}