-
Notifications
You must be signed in to change notification settings - Fork 4
/
ting_search_context.install
201 lines (191 loc) · 5.88 KB
/
ting_search_context.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
<?php
/**
* @file
* Install file the Ting search context.
*/
/**
* Implements hook_schema().
*/
function ting_search_context_schema() {
$schema = array();
// TODO: Do we need more database indexes?
$schema['ting_search_context_contexts'] = array(
'description' => 'A table to hold the system and user defined contexts',
'fields' => array(
'context_id' => array(
'description' => 'Primary key: Unique context ID',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'type' => array(
'description' => 'The type of this context (machine-readable)',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
),
'name' => array(
'description' => 'A human-readable name of the context',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
// A machine-name identifier of the system context - or the parent system
// context if this is a subject context.
// Will not be set for search string contexts, since they dont have a
// parent (se below).
'context' => array(
'description' => 'The machine-name of the context.',
'type' => 'varchar',
'length' => 32,
),
// We allow administrators to create more specific versions of certain
// system contexts, by associating one or more subjects to the context.
'subjects' => array(
'description' => 'A comma-separated list of the subjects of this context.',
'type' => 'varchar',
// TODO: Is this enough???
'length' => 255,
),
// Administrators can also extend the system by creating search string
// contexts. Search contexts doesn't have a context and subject value.
// Unlike subjects contexts, search string contexts doesn't have a parent.
// The context is just the search string.
'search' => array(
'description' => 'The search string of this context.',
'type' => 'varchar',
// TODO: Is this enough???
'length' => 255,
),
),
'primary key' => array('context_id'),
// Enforce unique contexts on the database level.
'unique keys' => array(
'subject' => array('context', 'subjects'),
'search' => array('search'),
),
);
$schema['ting_search_context_nodes_rated'] = array(
'description' => 'Stores information about nodes rated, thus managing the state of the context rating system',
'fields' => array(
'context_id' => array(
'description' => 'The ID of the context the node is rated in',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'nid' => array(
'description' => 'The ID of the node being rated',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'rating' => array(
'description' => 'The rating of the node in the context specified by context_id',
'type' => 'int',
'size' => 'tiny',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 1,
),
),
'primary key' => array('context_id', 'nid'),
'foreign keys' => array(
'context' => array(
'table' => 'ting_search_context_contexts',
'columns' => array('context_id' => 'context_id'),
),
'node' => array(
'table' => 'node',
'columns' => array('nid' => 'nid'),
),
),
'indexes' => array(
'nid' => array('nid'),
),
);
return $schema;
}
/**
* Implements hook_install().
*/
function ting_search_context_install() {
_ting_search_context_install_system_contexts();
}
/**
* Implements hook_unintstall().
*/
function ting_search_context_uninstall() {
variable_del('ting_search_context_position');
variable_del('ting_search_context_fallback_images');
}
/**
* Install the module's system contexts in the database.
*
* System contexts needs to live in the database, so they can be used to rate
* nodes in the same way as user-defined contexts (they need a context_id).
*/
function _ting_search_context_install_system_contexts() {
$system_contexts = array(
'film' => array(
'name' => 'Film',
'context' => 'film',
),
'musik' => array(
'name' => 'Musik',
'context' => 'musik',
),
'lydbøger' => array(
'name' => 'Lydbøger',
'context' => 'lydbøger',
),
'voksen_fag' => array(
'name' => 'Voksen faglitteratur',
'context' => 'voksen_fag',
),
'voksen_skøn' => array(
'name' => 'Voksen skønlitteratur',
'context' => 'voksen_skøn',
),
'børne_fag' => array(
'name' => 'Børne faglitteratur',
'context' => 'børne_fag',
),
'børne_skøn' => array(
'name' => 'Børne skønlitteratur',
'context' => 'børne_skøn',
),
'neutral' => array(
'name' => 'Neutral',
'context' => 'neutral',
),
);
foreach ($system_contexts as $system_context) {
$system_context += array('type' => 'system');
$context_id = db_insert('ting_search_context_contexts')
->fields($system_context)
->execute();
watchdog('ting_search_context', 'Installed system context: %name', array(
'%name' => $system_context['name'],
), WATCHDOG_INFO);
}
}
/**
* Implements hook_disable().
*/
function ting_search_context_disable() {
// Make sure our admin view is completely removed from the system when the
// module is disabled. Since we are using handlers defined in this module in
// trying to use it after disable will result in errors.
if ($view = views_get_view('ting_search_context_rate_nodes')) {
$view->delete(TRUE);
}
if ($view = views_get_view('ting_search_context_contexts')) {
$view->delete(TRUE);
}
views_invalidate_cache();
}