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

Contents of /contributions/modules/decisions/decisions.install

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


Revision 1.29 - (show annotations) (download) (as text)
Mon Oct 26 20:41:27 2009 UTC (4 weeks, 3 days ago) by anarcat
Branch: MAIN
CVS Tags: HEAD
Changes since 1.28: +12 -1 lines
File MIME type: text/x-php
#574178 by wonder95 - add option to display options in random order
1 <?php
2
3 /**
4 * @file
5 *
6 * .install file for decisions module
7 */
8
9 // $Id: decisions.install,v 1.28 2008/12/05 03:48:02 anarcat Exp $
10
11 /**
12 * Implementation of hook_install().
13 */
14 function decisions_schema() {
15 $schema['decisions'] = array(
16 'fields' => array(
17 'nid' => array('type' => 'int', 'not null' => TRUE, 'disp-width' => '10'),
18 'mode' => array('type' => 'varchar', 'length' => '32', 'not null' => TRUE),
19 'quorum_abs' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'),
20 'quorum_percent' => array('type' => 'float', 'unsigned' => TRUE, 'length' => '32', 'not null' => TRUE, 'default' => '0'),
21 'uselist' => array('type' => 'int', 'size' => 'tiny', 'not null' => FALSE, 'default' => 0, 'disp-width' => '4'),
22 'active' => array('type' => 'int', 'size' => 'tiny', 'not null' => FALSE, 'default' => 1, 'disp-width' => '4'),
23 'runtime' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'disp-width' => '11'),
24 'maxchoices' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'),
25 'algorithm' => array('type' => 'varchar', 'length' => '100', 'not null' => FALSE),
26 'showvotes' => array('type' => 'int', 'size' => 'tiny', 'not null' => FALSE, 'disp-width' => '4'),
27 'startdate' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'disp-width' => '10')),
28 'randomize' => array('type' => 'int', 'size' => 'tiny', 'not null' => FALSE, 'default' => 1, 'disp-width' => '4'),
29 'primary key' => array('nid'),
30 );
31
32 $schema['decisions_electoral_list'] = array(
33 'fields' => array(
34 'nid' => array('type' => 'int', 'not null' => TRUE, 'disp-width' => '10'),
35 'uid' => array('type' => 'int', 'not null' => TRUE, 'disp-width' => '10')),
36 'primary key' => array('nid', 'uid'),
37 );
38
39 $schema['decisions_choices'] = array(
40 'fields' => array(
41 'nid' => array('type' => 'int', 'not null' => TRUE, 'disp-width' => '10'),
42 'label' => array('type' => 'text', 'not null' => TRUE),
43 'vote_offset' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'disp-width' => '2')),
44 'primary key' => array('nid', 'vote_offset'),
45 'indexes' => array(
46 'vote_offset' => array('vote_offset')),
47 );
48 return $schema;
49 }
50 function decisions_install() {
51 drupal_install_schema('decisions');
52 }
53
54 function decisions_update_1() {
55 switch ($GLOBALS['db_type']) {
56 case 'mysql':
57 case 'mysqli':
58 $items[] = update_sql("ALTER TABLE {decisions} ADD COLUMN showvotes TINYINT DEFAULT '1'");
59 break;
60 }
61 return $items;
62 }
63
64 function decisions_update_2() {
65 switch ($GLOBALS['db_type']) {
66 case 'mysql':
67 case 'mysqli':
68 $items[] = update_sql("ALTER TABLE {decisions} ADD COLUMN active TINYINT DEFAULT '1'");
69 $items[] = update_sql("ALTER TABLE {decisions} ADD COLUMN runtime INT UNSIGNED DEFAULT '0'");
70 $items[] = update_sql("ALTER TABLE {decisions} ADD COLUMN maxchoices INT UNSIGNED");
71 $items[] = update_sql("ALTER TABLE {decisions} ADD COLUMN algorithm VARCHAR(255)");
72 $items[] = update_sql('UPDATE {decisions} SET maxchoices=1 WHERE mode="poll" AND maxchoices is null');
73 $items[] = update_sql("UPDATE {decisions} SET algorithm='runoff' WHERE mode='runoff'");
74 $items[] = update_sql("UPDATE {decisions} SET mode='ranking' WHERE mode='runoff'");
75 $items[] = update_sql("ALTER TABLE {decisions_options} CHANGE COLUMN opttext chtext text");
76 $items[] = update_sql("ALTER TABLE {decisions_options} CHANGE COLUMN optorder chorder int(2)");
77 $items[] = update_sql("RENAME TABLE {decisions_options} TO {decisions_choices}");
78 break;
79 }
80 return $items;
81 }
82
83 function decisions_update_3() {
84 switch ($GLOBALS['db_type']) {
85 case 'mysql':
86 case 'mysqli':
87 $items[] = update_sql("ALTER TABLE {decisions} ADD COLUMN startdate INT unsigned");
88 $items[] = update_sql("ALTER TABLE {decisions_choices} CHANGE COLUMN chtext `label` text NOT NULL");
89 $items[] = update_sql("ALTER TABLE {decisions_choices} CHANGE COLUMN chorder `vote_offset` int(2) default NULL");
90 break;
91 }
92 return $items;
93 }
94
95 function decisions_update_4() {
96 switch ($GLOBALS['db_type']) {
97 case 'mysql':
98 case 'mysqli':
99 $items[] = update_sql("ALTER TABLE {decisions} ADD COLUMN `uselist` tinyint default '0'");
100 break;
101 }
102 return $items;
103 }
104
105 function decisions_update_5() {
106 switch ($GLOBALS['db_type']) {
107 case 'mysql':
108 case 'mysqli':
109 $items[] = update_sql("ALTER TABLE {decisions} MODIFY `quorum` int(10) NOT NULL AFTER mode");
110 $items[] = update_sql("ALTER TABLE {decisions} CHANGE COLUMN quorum `quorum_abs` int(10) unsigned NOT NULL default '0'");
111 $items[] = update_sql("ALTER TABLE {decisions} ADD COLUMN quorum_percent float unsigned NOT NULL default '0' AFTER quorum_abs");
112 break;
113 }
114 return $items;
115 }
116
117 function decisions_update_6000() {
118 switch ($GLOBALS['db_type']) {
119 case 'mysql':
120 case 'mysqli':
121 $items[] = update_sql("ALTER TABLE {decisions} ADD COLUMN `randomize` tinyint default '0'");
122 break;
123 }
124 return $items;
125 }
126
127 /**
128 * Implementation of hook_uninstall().
129 */
130 function decisions_uninstall() {
131 // remove votes from all decisions
132 db_query("DELETE FROM {votingapi_vote} WHERE content_type='decisions'");
133 $result = db_query('SELECT nid FROM {decisions}');
134 while ($obj = db_fetch_object($result)) {
135 node_delete($obj->nid);
136 }
137 drupal_uninstall_schema('decisions');
138 variable_del('decisions_default_mode');
139 variable_del('decisions_default_electoral_list');
140 }

  ViewVC Help
Powered by ViewVC 1.1.2