Projet

Général

Profil

Paste
Télécharger (6,34 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / pollfield / pollfield.install @ 62f5c69e

1
<?php
2
/**
3
 * @file
4
 * Install, update, and uninstall functions for the field_example module.
5
 */
6

    
7
/**
8
 * Implements hook_field_schema().
9
 *
10
 * Defines the database schema of the field, using the format used by the
11
 * Schema API.
12
 *
13
 * The data we will store here is just one 7-character element, even
14
 * though the widget presents the three portions separately.
15
 *
16
 * All implementations of hook_field_schema() must be in the module's
17
 * .install file.
18
 *
19
 * @see http://drupal.org/node/146939
20
 * @see schemaapi
21
 * @see hook_field_schema()
22
 * @ingroup field_example
23
 */
24
function pollfield_field_schema($field) {
25
  $columns = array(
26
    'question' => array(
27
      'type' => 'text',
28
      'size' => 'medium',
29
      'not null' => FALSE,
30
    ),
31
    'choice' => array(
32
      'type' => 'text',
33
      'size' => 'medium',
34
      'not null' => FALSE,
35
    ),
36
    'anonymous' => array(
37
      'type' => 'text',
38
      'size' => 'small',
39
      'not null' => FALSE,
40
    ),
41
    'poll_features' => array(
42
      'type' => 'text',
43
      'size' => 'medium',
44
      'not null' => FALSE,
45
    ),
46
    'active' => array(
47
      'type' => 'int',
48
      'unsigned' => TRUE,
49
      'not null' => FALSE,
50
      'default' => 0,
51
    ),
52
    'runtime' => array(
53
      'type' => 'int',
54
      'unsigned' => TRUE,
55
      'not null' => FALSE,
56
      'default' => 0,
57
    ),
58
    'votes' => array(
59
      'type' => 'int',
60
      'unsigned' => TRUE,
61
      'not null' => FALSE,
62
      'default' => 0,
63
    ),
64
  );
65
  $indexes = array();
66
  return array(
67
    'columns' => $columns,
68
    'indexes' => $indexes,
69
  );
70
}
71

    
72
/**
73
 * Implements hook_schema().
74
 *
75
 * @ingroup nodeapi_example
76
 */
77
function pollfield_schema() {
78
  $schema['pollfield'] = array(
79
    'description' => 'Inventory of all pollfields their basic settings',
80
    'fields' => array(
81
      'nid' => array(
82
        'description' => 'Node ID',
83
        'type' => 'int',
84
        'unsigned' => 1,
85
        'default' => 0,
86
      ),
87
      'field_table' => array(
88
        'description' => 'The table where the pollfield is stored',
89
        'type' => 'varchar',
90
        'length' => 255,
91
        'default' => '',
92
      ),
93
      'field_name' => array(
94
        'description' => 'Pollfield name',
95
        'type' => 'varchar',
96
        'length' => 32,
97
        'default' => '',
98
      ),
99
      'field_name_delta' => array(
100
        'description' => 'Delta for multiple fields',
101
        'type' => 'int',
102
        'default' => 0,
103
      ),
104
      'runtime' => array(
105
        'description' => 'Time in seconds a pollfield is scheduled to be active',
106
        'type' => 'int',
107
        'default' => 0,
108
      ),
109
      'active' => array(
110
        'description' => 'Whether the poll is active or not',
111
        'type' => 'int',
112
        'unsigned' => 1,
113
        'default' => 0,
114
      ),
115
    ),
116
    'indexes' => array(
117
      'nid' => array('nid'),
118
      'field_table' => array('field_table'),
119
    ),
120
  );
121

    
122
  $schema['pollfield_votes'] = array(
123
    'description' => 'Pollfield results table',
124
    'fields' => array(
125
      'nid' => array(
126
        'description' => 'Pollfield node ID',
127
        'type' => 'int',
128
        'unsigned' => 1,
129
        'not null' => TRUE,
130
      ),
131
      'field_table' => array(
132
        'description' => 'The table where the pollfield is stored',
133
        'type' => 'varchar',
134
        'length' => 255,
135
        'not null' => TRUE,
136
        'default' => '',
137
      ),
138
      'field_name' => array(
139
        'description' => 'The table where the pollfield is stored',
140
        'type' => 'varchar',
141
        'length' => 32,
142
        'not null' => TRUE,
143
        'default' => '',
144
      ),
145
      'uid' => array(
146
        'description' => 'Voter user ID',
147
        'type' => 'int',
148
        'unsigned' => 1,
149
        'not null' => TRUE,
150
        'default' => 0,
151
      ),
152
      'delta' => array(
153
        'description' => 'Choice',
154
        'type' => 'int',
155
        'not null' => TRUE,
156
        'default' => -1,
157
      ),
158
      'hostname' => array(
159
        'description' => 'Voter hostname',
160
        'type' => 'varchar',
161
        'length' => 128,
162
        'not null' => TRUE,
163
        'default' => '',
164
      ),
165

    
166
      'field_name_delta' => array(
167
        'description' => 'Pollfield delta',
168
        'type' => 'int',
169
        'unsigned' => 1,
170
        'not null' => TRUE,
171
        'default' => 0,
172
      ),
173
      'weight' => array(
174
        'description' => 'Weight for mulitchoice',
175
        'type' => 'int',
176
        'unsigned' => 1,
177
        'not null' => TRUE,
178
        'default' => 0,
179
      ),
180
      'cookie' => array(
181
        'description' => 'Cookie for anonymous voters',
182
        'type' => 'varchar',
183
        'length' => 255,
184
        'not null' => TRUE,
185
        'default' => '',
186
      ),
187
    ),
188
    'indexes' => array(
189
      'nid' => array('nid'),
190
      'uid' => array('uid'),
191
      'field_table' => array('field_table'),
192
      'hostname' => array('hostname'),
193
    ),
194
  );
195

    
196
  return $schema;
197
}
198

    
199
/**
200
 * Changes size of {pollfield_votes}.cookie column.
201
 */
202
function pollfield_update_7001() {
203
  db_change_field('pollfield_votes', 'cookie', 'cookie', array(
204
    'description' => 'Cookie for anonymous voters',
205
    'type' => 'varchar',
206
    'length' => 255,
207
    'not null' => TRUE,
208
    'default' => '',
209
  ));
210
}
211

    
212
/**
213
 * Implements hook_uninstall().
214
 *
215
 * We need to clean up our variables data when uninstalling our module.
216
 *
217
 * Our implementation of nodeapi_example_form_alter() automatically
218
 * creates a nodeapi_example_node_type_<contentType> variable for each node type
219
 * the user wants to rate.
220
 *
221
 * To delete our variables we call variable_del for our variables'
222
 * namespace, 'nodeapi_example_node_type_'. Note that an average module would
223
 * have known variables that it had created, and it could just delete those
224
 * explicitly. For example, see render_example_uninstall(). It's important
225
 * not to delete variables that might be owned by other modules, so normally
226
 * we would just explicitly delete a set of known variables.
227
 *
228
 * hook_uninstall() will only be called when uninstalling a module, not when
229
 * disabling a module. This allows our data to stay in the database if the user
230
 * only disables our module without uninstalling it.
231
 *
232
 * @ingroup nodeapi_example
233
 */
234
function pollfield_uninstall() {
235
  // Simple DB query to get the names of our variables.
236
  $results = db_select('variable', 'v')
237
    ->fields('v', array('name'))
238
    ->condition('name', 'pollfield_%', 'LIKE')
239
    ->execute();
240
  // Loop through and delete each of our variables.
241
  foreach ($results as $result) {
242
    variable_del($result->name);
243
  }
244
}