-
Notifications
You must be signed in to change notification settings - Fork 0
/
eventbrite.module
197 lines (185 loc) · 5.77 KB
/
eventbrite.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<?php
// $Id$
/*
* Implementation of hook_menu().
*/
function eventbrite_menu() {
$items['admin/settings/eventbrite'] = array(
'title' => t('Eventbrite Settings'),
'description' => 'Configure Eventbrite API settings',
'page callback' => 'drupal_get_form',
'page arguments' => array('eventbrite_admin_settings'),
'access callback' => 'user_access',
'access arguments' => array('administer site configuration'),
'file' => 'eventbrite.admin.inc',
);
$items['admin/settings/eventbrite/api'] = array(
'title' => t('API Settings'),
'description' => 'Configure Eventbrite API settings',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -1,
);
$items['admin/settings/eventbrite/default-payment'] = array(
'title' => t('Default Payment Settings'),
'description' => t('Configure default payment settings'),
'page callback' => 'drupal_get_form',
'page arguments' => array('eventbrite_payment_default_settings'),
'access callback' => 'user_access',
'access arguments' => array('administer site configuration'),
'file' => 'eventbrite.payment.inc',
'type' => MENU_LOCAL_TASK,
'weight' => 5,
);
/* TOD: Add in venue creation
$items['admin/settings/eventbrite/add-venue'] = array(
'title' => 'Add Venue',
'description' => 'Add an Eventbrite venue',
'page callback' => 'drupal_get_form',
'page arguments' => array('eventbrite_venue'),
'access callback' => 'user_access',
'access arguments' => array('administer eventbrite settings'),
'file' => 'eventbrite.venue.inc',
'type' => MENU_LOCAL_TASK,
'weight' => 4,
);
*/
$items['admin/settings/eventbrite/list-venues'] = array(
'title' => 'List Venues',
'description' => 'List Eventbrite venues',
'page callback' => 'eventbrite_venue_list',
// 'page arguments' => array('eventbrite_admin_settings'),
'access callback' => 'user_access',
'access arguments' => array('administer eventbrite settings'),
'file' => 'eventbrite.venue.inc',
'type' => MENU_LOCAL_TASK,
'weight' => 2,
);
/* TOD: Add in venue editing
$items['admin/settings/eventbrite/list-venues/%'] = array(
'title' => 'Edit Venue',
'description' => 'Edit an Eventbrite venue',
'page callback' => 'drupal_get_form',
'page arguments' => array('eventbrite_venue', 4),
'access callback' => 'user_access',
'access arguments' => array('administer eventbrite settings'),
'file' => 'eventbrite.venue.inc',
'type' => MENU_LOCAL_TASK,
'weight' => 3,
);
*/
return $items;
}
/**
* Implementation of the hook_permissions()
*/
function eventbrite_perm() {
return array('administer eventbrite settings');
}
/*
* Allows a get-oriented operation to called via the Eventbrite API
*/
function eventbrite_get($op, $id = NULL) {
module_load_include('inc', 'eventbrite', 'eventbrite.api');
switch ($op) {
case 'user_list_events':
return _eventbrite_api_get_events();
case 'user_list_venues':
return _eventbrite_api_get_venues();
case 'event_get':
if ($id) {
return _eventbrite_api_get_event($id);
}
break;
case 'user_get':
// This will ge the master user
return _eventbrite_api_get_user();
case 'user_get_by_email':
if ($id) {
return _eventbrite_api_get_user($id, 'email');
}
case 'user_get_by_id':
if ($id) {
return _eventbrite_api_get_user($id, 'user_id');
}
break;
case 'user_get_by_key':
if ($id) {
return _eventbrite_api_get_user($id, 'user_key');
}
break;
}
}
/*
* Allows a save-oriented operation to called via the Eventbrite API
*/
function eventbrite_save($op, $object) {
module_load_include('inc', 'eventbrite', 'eventbrite.api');
switch ($op) {
case 'event_new':
return _eventbrite_api_event_new($object);
case 'event_update':
return _eventbrite_api_event_update($object);
case 'payment_update':
return _eventbrite_api_payment_update($object);
case 'ticket_new':
return _eventbrite_api_ticket_new($object);
case 'ticket_update':
return _eventbrite_api_ticket_update($object);
case 'user_new':
return _eventbrite_api_user_new($object);
}
}
/*
* DEPRECATED
*
* This is a utility function to manage any errors generated over the page request
*
* TODO: Remove this DEPRECATED function as it is not needed and calls to it are in the process of removal
*
* param 1: $error_msg: a error message string. '' when this function is being called to get the errors
* param 2: $error_type: An Eventbrite supplied value used to associate the error with a form element
*/
function eventbrite_errors($error_msg = '', $error_type = '') {
static $errors;
if (!isset($errors)) {
$errors = array();
}
if ($error_msg) {
if ($error_type) {
$errors[$error_type] = $error_msg;
}
else {
$errors[] = $error_msg;
}
}
return $errors;
}
/*
* This function translates offset into the formatting that Eventbrite API is expecting
*/
function eventbrite_timezone_offset($offset) {
$eb_timezone = 'GMT';
$eb_timezone .= ($offset < 0) ? '-' : '+';
$eb_timezone .= (abs($offset) >= 10) ? abs($offset) : '0'. abs($offset);
return $eb_timezone;
}
/*
* This is a function to return user_list_events as a keyed array suitable for option lists
* event_id => event_title
*/
function eventbrite_get_events_options() {
$options = array();
if ($events = eventbrite_get('user_list_events')) {
$options[0] = '';
foreach ($events as $event_id => $event) {
$options[$event_id] = $event->title;
}
}
return $options;
}
/*
* This function returns TRUE if Eventbrite module is set up with valid Eventbrite authentication
*/
function eventbrite_is_valid_auth() {
return variable_get('eventbrite_is_valid_auth', FALSE);
}