This repository has been archived by the owner on May 2, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathding_eresource.install
93 lines (80 loc) · 2.55 KB
/
ding_eresource.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
<?php
/**
* @file
* Installation code for ding_eresource.
*/
/**
* Implements of hook_install().
*/
function ding_eresource_install() {
$t = get_t();
// Configuration for the e-resource specific vocabularies.
$vocabularies = array(
'eresource_category' => array(
'name' => $t('E-Resource category'),
'help' => $t('Pick a category for the e-resource'),
'relations' => 1,
'hierarchy' => 0,
'multiple' => 1,
'required' => 1,
'tags' => 0,
'weight' => -5,
),
'eresource_availablity' => array(
'name' => $t('E-Resource availability'),
'help' => $t('Where/how can the e-resource be accessed?'),
'relations' => 1,
'hierarchy' => 0,
'multiple' => 0,
'required' => 1,
'tags' => 0,
'weight' => 0,
),
);
foreach ($vocabularies as $key => $v) {
// Create the vocabulary if it does not exist already.
$variable_name = 'ding_eresource_' . $key . '_vid';
if (!($vid = variable_get($variable_name, FALSE)) ||
!taxonomy_vocabulary_load($vid)) {
db_query("INSERT INTO {vocabulary} (name, help, relations, hierarchy, multiple, required, tags, module, weight)
VALUES ('%s', '%s', %d, %d, %d, %d, %d, '%s', %d)",
$v['name'], $v['help'], $v['relations'], $v['hierarchy'], $v['multiple'], $v['required'], $v['tags'],
'ding_resource', $v['weight']
);
$vid = db_last_insert_id('vocabulary', 'vid');
// Store the vid for future reference.
variable_set($variable_name, $vid);
db_query("INSERT INTO {vocabulary_node_types} (vid, type) VALUES (%d, '%s')",
$vid, 'eresource');
}
}
// Bind e-resources to existing tag vocabulary.
db_query(
"INSERT INTO {vocabulary_node_types} (vid, type) VALUES (%d, '%s')",
2, 'eresource'
);
// This module needs to be "heavier" than Views, since it redefines
// Views templates.
db_query("UPDATE {system} SET weight = 11 WHERE name = 'ding_eresource'");
}
/**
* Make this module "heavier" than Views so we can override its templates.
*/
function ding_eresource_update_6101() {
$ret = array();
$ret[] = update_sql("UPDATE {system} SET weight = 11 WHERE name = 'ding_eresource'");
return $ret;
}
/**
* Set sticky on eresource nodes to reflect out usage of weight.
*
* With weight.module, -100 represents a weight of 0;
*/
function ding_eresource_update_6102() {
$ret = array();
$ret[] = update_sql("
UPDATE {node} SET sticky = -100
WHERE type = 'eresource' AND sticky = 0
");
return $ret;
}