/[drupal]/contributions/modules/uts/uts.install
ViewVC logotype

Contents of /contributions/modules/uts/uts.install

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.21 - (show annotations) (download) (as text)
Mon Jan 12 01:17:17 2009 UTC (10 months, 1 week ago) by boombatower
Branch: MAIN
CVS Tags: DRUPAL-6--1-0-RC1, DRUPAL-6--1-0, HEAD
Changes since 1.20: +4 -4 lines
File MIME type: text/x-php
Hard-code node type option settings.
1 <?php
2 // $Id: uts.install,v 1.20 2008/09/05 19:26:47 boombatower Exp $
3 /**
4 * @file
5 * Create database structure and remove when uninstalled.
6 *
7 * Copyright 2008 by Jimmy Berry ("boombatower", http://drupal.org/user/214218)
8 */
9
10 /**
11 * Implementation of hook_schema().
12 */
13 function uts_schema() {
14 $schema = array();
15 $schema['uts_study'] = array(
16 'description' => t('The base table for a study.'),
17 'fields' => array(
18 'nid' => array(
19 'description' => t('Reference to node.'),
20 'type' => 'int',
21 'unsigned' => TRUE,
22 'not null' => TRUE
23 ),
24 'vid' => array(
25 'description' => t('Reference to node version.'),
26 'type' => 'int',
27 'unsigned' => TRUE,
28 'not null' => TRUE
29 ),
30 'study_status' => array(
31 'description' => t('The status of the study.'),
32 'type' => 'int',
33 'unsigned' => TRUE,
34 'not null' => TRUE
35 ),
36 'study_type' => array(
37 'description' => t('The type of study.'),
38 'type' => 'int',
39 'unsigned' => TRUE,
40 'not null' => TRUE
41 ),
42 'participant_count' => array(
43 'description' => t('The maximum number of participants that can participate in a study.'),
44 'type' => 'int',
45 'unsigned' => TRUE,
46 'not null' => TRUE
47 ),
48 'audience_role' => array(
49 'description' => t('The role of the audience for this study.'),
50 'type' => 'int',
51 'unsigned' => TRUE,
52 'not null' => TRUE
53 ),
54 'audience_level' => array(
55 'description' => t('The experience level of the audience for this study.'),
56 'type' => 'int',
57 'unsigned' => TRUE,
58 'not null' => TRUE
59 ),
60 'base_environment' => array(
61 'description' => t('Reference to the base environment to use when participats begin a study.'),
62 'type' => 'int',
63 'unsigned' => TRUE,
64 'not null' => TRUE
65 )
66 ),
67 'indexes' => array(
68 'nid' => array('nid')
69 ),
70 'primary key' => array('vid')
71 );
72 $schema['uts_study_data'] = array(
73 'description' => t('The data plug-ins used by a study.'),
74 'fields' => array(
75 'study_nid' => array(
76 'description' => t('The study a data plug-in is related to.'),
77 'type' => 'int',
78 'unsigned' => TRUE,
79 'not null' => TRUE
80 ),
81 'name' => array(
82 'description' => t('The machine name of data plug-in module.'),
83 'type' => 'varchar',
84 'not null' => TRUE,
85 'length' => 255,
86 'default' => ''
87 ),
88 'required' => array(
89 'description' => t('The data plug-in is required.'),
90 'type' => 'int',
91 'unsigned' => TRUE,
92 'not null' => TRUE
93 )
94 ),
95 'indexes' => array(
96 'study_nid' => array('study_nid')
97 ),
98 'primary key' => array('study_nid', 'name')
99 );
100 $schema['uts_task'] = array(
101 'description' => t('The base table for a task which is related to a study.'),
102 'fields' => array(
103 'nid' => array(
104 'description' => t('Reference to node.'),
105 'type' => 'int',
106 'unsigned' => TRUE,
107 'not null' => TRUE
108 ),
109 'vid' => array(
110 'description' => t('Reference to node version.'),
111 'type' => 'int',
112 'unsigned' => TRUE,
113 'not null' => TRUE
114 ),
115 'study_nid' => array(
116 'description' => t('The study a task is related to.'),
117 'type' => 'int',
118 'unsigned' => TRUE,
119 'not null' => FALSE
120 ),
121 'max_time' => array(
122 'description' => t('The maximum time allowed for a task to be completed.'),
123 'type' => 'int',
124 'unsigned' => FALSE,
125 'not null' => TRUE
126 ),
127 'weight' => array(
128 'description' => t('The weight of a task used for ordering.'),
129 'type' => 'int',
130 'unsigned' => TRUE,
131 'not null' => FALSE
132 )
133 ),
134 'indexes' => array(
135 'study_nid' => array('study_nid'),
136 'nid' => array('nid')
137 ),
138 'primary key' => array('vid')
139 );
140 $schema['uts_session'] = array(
141 'description' => t('Table for storing participant session data.'),
142 'fields' => array(
143 'session_id' => array(
144 'description' => t('The ID used to reference session.'),
145 'type' => 'varchar',
146 'not null' => TRUE,
147 'length' => 60,
148 'default' => ''
149 ),
150 'study_nid' => array(
151 'description' => t('The study a session is related to.'),
152 'type' => 'int',
153 'unsigned' => TRUE,
154 'not null' => TRUE
155 ),
156 'complete' => array(
157 'description' => t('The session is complete.'),
158 'type' => 'int',
159 'unsigned' => TRUE,
160 'not null' => TRUE
161 ),
162 'current_task' => array(
163 'description' => t('The ID of the current task being worked on.'),
164 'type' => 'int',
165 'unsigned' => FALSE,
166 'not null' => TRUE
167 ),
168 'start_time' => array(
169 'description' => t('The start timestamp for the current task.'),
170 'type' => 'int',
171 'unsigned' => FALSE,
172 'not null' => FALSE
173 )
174 ),
175 'indexes' => array(
176 'study_nid' => array('study_nid')
177 ),
178 'primary key' => array('session_id')
179 );
180 $schema['uts_session_task'] = array(
181 'description' => t('Table for storing participant session data.'),
182 'fields' => array(
183 'session_id' => array(
184 'description' => t('The session the record is related to.'),
185 'type' => 'varchar',
186 'not null' => TRUE,
187 'length' => 60,
188 'default' => ''
189 ),
190 'task_nid' => array(
191 'description' => t('The task NID that record relates to.'),
192 'type' => 'int',
193 'unsigned' => FALSE,
194 'not null' => TRUE
195 ),
196 'start_time' => array(
197 'description' => t('The start timestamp for the task.'),
198 'type' => 'int',
199 'unsigned' => FALSE,
200 'not null' => TRUE
201 ),
202 'stop_time' => array(
203 'description' => t('The stop timestamp for the task.'),
204 'type' => 'int',
205 'unsigned' => FALSE,
206 'not null' => TRUE
207 )
208 ),
209 'primary key' => array('session_id', 'task_nid')
210 );
211 $schema['uts_environment'] = array(
212 'description' => t('Table for storing base environments.'),
213 'fields' => array(
214 'nid' => array(
215 'description' => t('Reference to node.'),
216 'type' => 'int',
217 'unsigned' => TRUE,
218 'not null' => TRUE
219 ),
220 'prefix' => array(
221 'description' => t('The prefixed used for the environment.'),
222 'type' => 'varchar',
223 'not null' => TRUE,
224 'length' => 60,
225 'default' => ''
226 )
227 ),
228 'primary key' => array('nid')
229 );
230 return $schema;
231 }
232
233 /**
234 * Implementation of hook_requirements().
235 */
236 function uts_requirements($phase) {
237 global $uts_installed;
238
239 $requirements = array();
240 $requirements['uts_settings_code'] = array(
241 'title' => t('UTS settings.php code'),
242 'description' => t('You must add code to the setting.php file. Please read the
243 <a href="!install">INSTALL.txt</a> file in the uts module directory for more details.',
244 array('!install' => url(drupal_get_path('module', 'uts') . '/INSTALL.txt'))),
245 'value' => (isset($uts_installed) ? t('Installed') : t('Missing')),
246 'severity' => (isset($uts_installed) ? REQUIREMENT_OK : REQUIREMENT_ERROR)
247 );
248
249 return $requirements;
250 }
251
252 /**
253 * Implementation of hook_install().
254 */
255 function uts_install() {
256 // Create tables.
257 drupal_install_schema('uts');
258
259 // Set content-type workflow settings.
260 $workflow = array('status');
261 variable_set('node_options_' . 'uts_study', $workflow);
262 variable_set('node_options_' . 'uts_task', $workflow);
263 variable_set('node_options_' . 'uts_environment', $workflow);
264 }
265
266 /**
267 * Implementation of hook_uninstall().
268 */
269 function uts_uninstall() {
270 // Since node hooks won't be called data must be removed manually.
271 // Remove all session data, tasks, studies, and environments.
272 $sessions = uts_session_load_all();
273 foreach ($sessions as $session_id) {
274 $session = uts_session_load($session_id);
275 uts_environment_destroy($session_id);
276 }
277 drupal_set_message(t('@count session(s) destroyed.', array('@count' => count($sessions))));
278
279 $tasks = uts_tasks_load();
280 foreach ($tasks as $task) {
281 node_delete($task->nid);
282 }
283
284 $studies = uts_studies_load();
285 foreach ($studies as $study) {
286 node_delete($study->nid);
287 }
288
289 $environments = uts_environments_load();
290 foreach ($environments as $environment) {
291 $prefix = db_result(db_query('SELECT prefix
292 FROM {uts_environment}
293 WHERE nid = %d', $environment->nid));
294
295 if ($prefix) {
296 uts_environment_destroy($prefix);
297 }
298 node_delete($environment);
299 }
300
301 // Remove tables.
302 drupal_uninstall_schema('uts');
303
304 // Remove variables.
305 variable_del('uts_environment_admin_name');
306 variable_del('uts_environment_admin_pass');
307
308 variable_del('node_options_' . UTS_STUDY);
309 variable_del('node_options_' . UTS_TASK);
310 variable_del('node_options_' . UTS_ENVIRONMENT);
311 }

  ViewVC Help
Powered by ViewVC 1.1.2