This repository was archived by the owner on Sep 25, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripture.db.inc
More file actions
164 lines (129 loc) · 4.26 KB
/
scripture.db.inc
File metadata and controls
164 lines (129 loc) · 4.26 KB
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
<?php
/**
* Get all known translations
* @return array:
* An array like follows:
* array(
* id => object(
* abbr => 'translation abbreviation',
* name => 'translation name',
* lang => 'langcode',
* ),
* ...,
* )
*/
function scripture_get_translations() {
return db_select('lw_translations', 't')->fields('t')->execute()->fetchAllAssoc('abbr');
}
/**
* Get the info for a translation based on translation id
*/
function scripture_get_translation($abbr) {
return db_select('lw_translations', 't')->fields('t')->condition('abbr',$abbr)->execute()->fetchAssoc();
}
/**
* Retrieve verse from the db based on vid
*/
function scripture_get_verse($vid, $translation = NULL) {
// Try to load the default translation if it is not specified
if (empty($translation)) {
$translation = variable_get('scripture_default_translation', NULL);
}
// Check if a translation is specified
if (empty($translation)) {
drupal_set_message("The default translation is not specified. Don't know which text to load from database.", 'error', FALSE);
return FALSE;
} else {
return db_select('lw_verses', 'v')
->fields('v')
->condition('vid', $vid)
->condition('translation', $translation)
->range(0, 1)
->execute()
->fetchAssoc();
}
}
/**
* Retrieve all verses in a range from the db based on vid
*/
function scripture_get_verses_between($from_vid, $to_vid, $translation = NULL) {
// Try to load the default translation if it is not specified
if (empty($translation)) {
$translation = variable_get('scripture_default_translation', NULL);
}
// Check if a translation is specified
if (empty($translation)) {
drupal_set_message("The default translation is not specified. Don't know which text to load from database.", 'error', FALSE);
return FALSE;
} else {
return db_select('lw_verses', 'v')
->fields('v')
->condition('translation', $translation)
->condition('vid', array($from_vid, $to_vid), 'BETWEEN')
->orderBy('vid', 'ASC')// ordering by versenum does not work, because there are alphanumeric verses in some translations
->execute()
->fetchAllAssoc('vid');
}
}
/**
* Retrieve matching vid from the db
*/
function scripture_get_vid($translation, $booknum, $chapternum, $versenum) {
if (empty($translation))
$translation = variable_get('scripture_default_translation', NULL);
// If translation is set, this function can be used to check if that verse exists in a specific translation.
return db_select('lw_verses', 'v')
->fields('v', array('vid'))
->condition('translation', $translation)
->condition('booknum', $booknum)
->condition('chapternum', $chapternum)
->condition('versenum', $versenum)
->range(0, 1)
->execute()
->fetchField();
}
/**
* Get all book names, keyed by booknumber, for a specific translation
*/
function scripture_get_books($translation = NULL) {
if (empty($translation))
$translation = variable_get('scripture_default_translation', NULL);
if (!empty($translation))
return db_select('lw_books', 'b')->fields('b')->condition('translation', $translation)->execute()->fetchAllAssoc('booknum');
else
return array();
}
/**
* Get book which contains given verse
*/
function scripture_get_book($verse) {
if (empty($verse['translation']))
$translation = variable_get('scripture_default_translation', NULL);
else
$translation = $verse['translation'];
if (!empty($translation))
return db_select('lw_books', 'b')->fields('b')->condition('booknum', $verse['booknum'])->condition('translation', $translation)->range(0, 1)->execute()->fetchAssoc();
else
return array();
}
/**
* Get nodes which reference the given verse range
*/
function scripture_get_nodes($from_vid, $to_vid = NULL) {
if (empty($to_vid)) {
// single verse
$to_vid = $from_vid;
} else {
// verse range
if ($to_vid < $from_vid) {
// error: negative verse range...
return FALSE;
}
}
// TODO: we need some way to quickly inspect all fields of type "Scripture reference"
// $query = new EntityFieldQuery();
// $query
// ->entityCondition('entity_type', 'node')
// ->propertyConfition('status', NODE_PUBLISHED)
// ->fieldConfition('')
}