forked from gdoteof/election
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelection.install
299 lines (276 loc) · 8.61 KB
/
election.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
<?php
/*
* implementation of hook_schema
*/
function election_schema(){
$schema['election_cache'] = array(
'description' => 'Table for storing serialized data for specific URIs',
'fields' => array(
'uri' => array(
'description'=> 'The URI for this cached data',
'type' => 'varchar',
'length' => 255,
'not null' => true,
),
'last_update' => array(
'description' => 'The unix time stamp for the creation/last update of this item',
'type' => 'int',
'not null' => true,
'default' => 0,
),
'expires' => array(
'description' => 'The unix time stamp for when this cache item expires.',
'type' => 'int',
'not null' => true,
'default' => 0,
),
'data' => array(
'description' => 'The serialized data for this URI',
'type' => 'text',
'size' => 'medium', //16kb might be too small if we want to get the results for a large tree
'serialize' => TRUE,
'not null' => TRUE,
),
),
'primary key' => array('uri'),
);
$schema['election_results'] = array(
'description' => 'Table for holding the election results for a given district/ballot item',
'fields' => array(
'district_nid' => array(
'description' => 'The unique id for the district',
'type' => 'varchar',
'length' => 63,
'not null' => TRUE,
),
'ballot_item_nid' => array(
'description' => 'The unique id for the ballot item',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'results' => array(
'description' => 'The serialized results for the ballot item',
'type' => 'text',
'not null' => TRUE,
'size' => 'normal',
'serialize' => TRUE,
),
'complete' => array(
'description' => 'Are the results complete?',
'size' => 'tiny',
'not null' => TRUE,
'type' => 'int',
'default' => 0,
),
),
'primary key' => array( 'district_nid', 'ballot_item_nid'),
);
$schema['election_slug'] = array(
'description' => 'Table for holding the compiled slugs (for the URL) of election items',
'fields' => array(
'nid' => array(
'description' => 'The unique id for the item',
'type' => 'int',
'unsigned' => true,
'not null' => TRUE,
),
'slug' => array(
'description' => 'The generated-at-save slug based on the title of the node',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'type' => array(
'description' => 'The node type',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
),
'primary key' => array( 'nid'),
);
$schema['election_algorithm'] = array(
'description' => 'Table for storing the algorithm for determing the winner for a ballot item',
'fields' => array(
'ballot_item_nid' => array(
'description'=> 'The nid of the ballot item',
'type' => 'int',
'not null' => true,
),
'algorithm' => array(
'description' => 'The algorithm to determine the winner',
'type' => 'varchar',
'not null' => true,
'length' => 255,
),
'n' => array(
'description'=> 'The N in the algorithm',
'type' => 'float',
'not null' => true,
),
),
'primary key' => array('ballot_item_nid'),
);
return $schema;
}
/*
* Implementation of hook_install
*/
function election_install(){
drupal_install_schema('election');
_create_elec_ballot_item();
_add_ballot_item_taxo();
_create_elec_district();
_add_district_taxo();
_create_elec_election_event();
_create_elec_election_season();
node_types_rebuild();
$ballot_type_vid = db_result(db_query('SELECT vid FROM {vocabulary} WHERE name="Ballot Item Type"'));
variable_set('elec_ballot_vid', $ballot_type_vid);
$district_type_vid = db_result(db_query('SELECT vid FROM {vocabulary} WHERE name="District Type"'));
variable_set('elec_district_vid', $district_type_vid);
}
function _create_elec_ballot_item(){
$content = array();
$type_name = "<create>";
include "includes/elec_ballot_item.crud.inc";
$form_state = array();
$form = content_copy_import_form($form_state, $type_name);
$form_state['values']['type_name'] = $type_name ? $type_name : '';
$form_state['values']['macro'] = '$content = '. var_export($content, 1) .';';
$form_state['values']['op'] = t('Import');
content_copy_import_form_submit($form, $form_state);
}
function _add_ballot_item_taxo(){
$name = t('Ballot Item Type');
$vocabulary = array(
'name' => $name,
'help' => t('What type of Ballot item?'),
'multiple' => 0,
'required' => 1,
'hierarchy' => 0,
'relations' => 0,
'module' => 'election',
'tags' => 0,
'weight' => -10,
'nodes' => array('elec_ballot_item' => 1),
);
taxonomy_save_vocabulary($vocabulary);
$vid = db_result(db_query('SELECT vid FROM {vocabulary} where name="%s"', $name));
$t1 = array(
'vid' => $vid,
'name' => t('Referendum'),
);
taxonomy_save_term($t1);
$t2 = array(
'vid' => $vid,
'name' => t('Election'),
);
taxonomy_save_term($t2);
}
function _add_district_taxo(){
$name = t('District Type');
$vocabulary = array(
'name' => $name,
'multiple' => 1,
'required' => 0,
'hierarchy' => 0,
'relations' => 0,
'module' => 'election',
'tags' => 0,
'weight' => -10,
'nodes' => array('elec_district' => 1),
);
taxonomy_save_vocabulary($vocabulary);
$vid = db_result(db_query('SELECT vid FROM {vocabulary} where name="%s"', $name));
$t1 = array(
'vid' => $vid,
'name' => t('Ward'),
);
taxonomy_save_term($t1);
$t2 = array(
'vid' => $vid,
'name' => t('Polling Place'),
);
taxonomy_save_term($t2);
$t3 = array(
'vid' => $vid,
'name' => t('Municipality'),
);
taxonomy_save_term($t3);
}
function _create_elec_district(){
$content = array();
$type_name = "<create>";
include "includes/elec_district.crud.inc";
$form_state = array();
$form = content_copy_import_form($form_state, $type_name);
$form_state['values']['type_name'] = $type_name ? $type_name : '';
$form_state['values']['macro'] = '$content = '. var_export($content, 1) .';';
$form_state['values']['op'] = t('Import');
content_copy_import_form_submit($form, $form_state);
}
function _create_elec_election_event(){
$content = array();
$type_name = "<create>";
include "includes/elec_election_event.crud.inc";
$form_state = array();
$form = content_copy_import_form($form_state, $type_name);
$form_state['values']['type_name'] = $type_name ? $type_name : '';
$form_state['values']['macro'] = '$content = '. var_export($content, 1) .';';
$form_state['values']['op'] = t('Import');
content_copy_import_form_submit($form, $form_state);
}
function _create_elec_election_season(){
$content = array();
$type_name = "<create>";
include "includes/elec_election_season.crud.inc";
$form_state = array();
$form = content_copy_import_form($form_state, $type_name);
$form_state['values']['type_name'] = $type_name ? $type_name : '';
$form_state['values']['macro'] = '$content = '. var_export($content, 1) .';';
$form_state['values']['op'] = t('Import');
content_copy_import_form_submit($form, $form_state);
}
function election_uninstall(){
drupal_uninstall_schema('election');
node_type_delete('elec_ballot_item');
node_type_delete('elec_district');
node_type_delete('elec_election_event');
node_type_delete('elec_election_season');
node_types_rebuild();
cache_clear_all();
}
function election_update_6100() {
$ret = array();
db_add_field($ret, 'election_results', 'complete', array('type'=>'int', 'size'=>'tiny','not noll'=>true, 'default'=>0));
return $ret;
}
function election_update_6101() {
$schema['election_algorithm'] = array(
'description' => 'Table for storing the algorithm for determing the winner for a ballot item',
'fields' => array(
'ballot_item_nid' => array(
'description'=> 'The nid of the ballot item',
'type' => 'int',
'not null' => true,
),
'algorithm' => array(
'description' => 'The algorithm to determine the winner',
'type' => 'varchar',
'not null' => true,
'length' => 255,
),
'n' => array(
'description'=> 'The N in the algorithm',
'type' => 'float',
'not null' => true,
),
),
'primary key' => array('ballot_item_nid'),
);
$ret = array();
db_create_table($ret, 'election_algorithm', $schema['election_algorithm']);
return $ret;
}