-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathopen_badges.install
337 lines (319 loc) · 10.2 KB
/
open_badges.install
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
<?php
/**
* @file
* @brief Open Badges install file
*
* This file contains all the installation functions of the schema, tables and variables
* used by the module.
*
* @author Jeff Robbins (jjeff), http://drupal.org/user/17190
* @author Chad Phillips (hunmonk), http://drupal.org/user/22079
* @author Heine Deelstra (Heine), http://drupal.org/user/17943
* @author Nuno Veloso (nunoveloso18), http://drupal.org/user/80656
* @author Richard Skinner (Likeless), http://drupal.org/user/310635
*
* @warning For more information on licensing, read the LICENCE.txt file.
*
*/
include 'open_badges_constants.inc';
/**
* Implements hook_schema().
*/
function open_badges_schema() {
$schema = array();
$schema['open_badges_badges'] = array(
'description' => 'Defines the user badges themselves (image, weight etc.)',
'fields' => array(
'bid' => array(
'description' => t('Original badge ID'),
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'name' => array(
'description' => t('Badge name'),
'type' => 'varchar',
'length' => 50,
'not null' => TRUE,
'default' => '',
),
'image' => array(
'description' => t('Associated image. Can be a full URL, or a relative path for the image library.'),
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'criteria' => array(
'description' => t('URL to the description of the badge and criteria for earning the badge.'),
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'description' => array(
'description' => t('Short description of the badge. (Maximum of 128 characters)'),
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
),
'issuername' => array(
'description' => t('Human-readable name of the issuing agent. (i.e,. "Boy Scouts")'),
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'issuerorg' => array(
'description' => t('Organization for which the badge is being issued. (i.e., "Troop #218")'),
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'default' => '',
),
'issuercontact' => array(
'description' => t('A human-monitored email address associated with the issuer.'),
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'default' => '',
),
'issuerurl' => array(
'description' => t('URL for the issuer. Defaults to the root issuing domain if not provided.'),
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'default' => '',
),
'weight' => array(
'description' => t('Order in list'),
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'tid' => array(
'description' => t('Optional associated taxonomn term id'),
'type' => 'int',
'not null' => FALSE,
'unsigned' => TRUE,
),
'unhideable' => array(
'description' => t('If this is 1, the badge cannot be hidden by being moved down in weight. It will always show up.'),
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
'fixedweight' => array(
'description' => t('If this is 1, the badge cannot have a user assigned weight, regardless of settings.'),
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
'doesnotcounttolimit' => array(
'description' => t('If this is 1, the badge does not count towards the limit for number of badges to display per user.'),
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array('bid'),
'indexes' => array(
'bid_weight_name' => array('bid', 'weight', 'name'),
'weight_name' => array('weight', 'name'),
'tid_name' => array('tid', 'name'),
)
);
$schema['open_badges_roles'] = array(
'description' => 'Stores which roles grant which badges.',
'fields' => array(
'rid' => array(
'description' => t('Role ID'),
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'bid' => array(
'description' => t('Badge ID'),
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
),
'primary key' => array('bid', 'rid'),
);
$schema['open_badges_user_preferences'] = array(
'description' => 'Stores whether user has allowed sharing of badges with Mozilla OBI.',
'fields' => array(
'uid' => array(
'description' => t('User ID'),
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'userallowsharing' => array(
'description' => t('The user\'s decision whether to share badges with the Mozilla OBI.'),
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => OPEN_BADGES_USER_DECISION_NONE,
),
'useremails' => array(
'description' => t('The user\'s decision whether to opt out of future email notifications.'),
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => OPEN_BADGES_USER_DECISION_YES,
),
),
'primary key' => array('uid'),
);
$schema['open_badges_user'] = array(
'description' => 'Stores which users have which badges.',
'fields' => array(
'uid' => array(
'description' => t('User ID'),
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'bid' => array(
'description' => t('Badge ID'),
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'bakedimage' => array(
'description' => t('Local path of the "baked" badge image returned from Mozilla OBI.'),
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'state' => array(
'description' => t('State of this badge in the Mozilla OBI process of "baking", sharing, etc.'),
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => OPEN_BADGES_STATE_UNDEFINED,
),
'usernotified' => array(
'description' => t('If this is 1, the user has been notified that the badge has been issued.'),
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
'allowdisplay' => array(
'description' => t('Whether the user has chosen to allow the badge to be displayed locally.'),
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => OPEN_BADGES_USER_DECISION_NONE,
),
'assertionurl' => array(
'description' => t('Private, non-deterministic, persistent URL given to Mozilla OBI when "baking" a badge.'),
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'default' => '',
),
'type' => array(
'description' => t("Whether set as part of the role ('role'), or individually assigned ('user')"),
'type' => 'varchar',
'length' => 20,
'not null' => TRUE,
'default' => '',
),
'evidenceurl' => array(
'description' => t('URL with information about how this user earned this badge.'),
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'default' => '',
),
'issuedate' => array(
'description' => t('Date when the badge was issued. Defaults to the current date.'),
'type' => 'int',
'not null' => TRUE,
'default' => '0',
),
'expirationdate' => array(
'description' => t('Date when the badge expires. The default is that the badge does not expire.'),
'type' => 'int',
'not null' => TRUE,
'default' => '0',
),
'userweight' => array(
'description' => t('Order in list, as set by user.'),
'type' => 'int',
'not null' => FALSE,
),
),
'primary key' => array('bid', 'uid', 'type', 'issuedate'),
'indexes' => array(
'uid_bid' => array('uid', 'bid'),
'uid_weight' => array('uid', 'userweight'),
'type' => array('type'),
'assertionurl' => array('assertionurl'),
),
);
return $schema;
}
/**
* Implements hook_install().
*/
function open_badges_install() {
drupal_install_schema('open_badges');
}
/**
* Implements hook_uninstall().
*/
function open_badges_uninstall() {
// Delete badge image files.
$dir = file_create_path('open_badges');
if ($dir) {
$files = file_scan_directory($dir, '.*\.(gif|jpg|jpeg|png)', array('.', '..', 'CVS'), 0, FALSE);
foreach ($files as $file) {
file_delete($file->filename);
}
}
// Delete the badges directory.
if (file_exists($dir)) {
rmdir($dir);
}
// Delete baked badge files.
$dir = file_create_path('open_badges_baked');
if ($dir) {
$files = file_scan_directory($dir, '.*\.(gif|jpg|jpeg|png)', array('.', '..', 'CVS'), 0, FALSE);
foreach ($files as $file) {
file_delete($file->filename);
}
}
// Delete the badges directory.
if (file_exists($dir)) {
rmdir($dir);
}
drupal_uninstall_schema('open_badges');
variable_del('open_badges_defaultissuername');
variable_del('open_badges_imagecache');
variable_del('open_badges_nobadges');
variable_del('open_badges_showone');
variable_del('open_badges_showblocked');
variable_del('open_badges_userweight');
variable_del('open_badges_vid');
}
/**
* Implements hook_update_N()
* new DB structure
function open_badges_update_6001() {
$ret = array();
db_drop_primary_key($ret, 'open_badges_user');
db_add_primary_key($ret, 'open_badges_user', array('bid', 'uid', 'type'));
db_add_index($ret, 'open_badges_user', 'type', array('type'));
return $ret;
}
*/