-
Notifications
You must be signed in to change notification settings - Fork 1
/
custom.php
124 lines (111 loc) · 5.47 KB
/
custom.php
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
<?php
function custom_paging()
{
//Starts a conditional statement that determines a search has been run
if (isset($_SERVER['QUERY_STRING'])) {
// Sets the current item ID to the variable $current
$current = metadata('item', 'id');
//Break the query into an array
parse_str($_SERVER['QUERY_STRING'], $queryarray);
//Items don't need the page level
unset($queryarray['page']);
$itemIds = array();
$list = array();
if (isset($queryarray['query'])) {
//We only want to browse previous and next for Items
$queryarray['record_types'] = array('Item');
//Get an array of the texts from the query.
$textlist = get_db()->getTable('SearchText')->findBy($queryarray);
//Loop through the texts ans populate the ids and records.
foreach ($textlist as $value) {
$itemIds[] = $value->record_id;
$record = get_record_by_id($value['record_type'], $value['record_id']);
$list[] = $record;
}
}
elseif (isset($queryarray['advanced'])) {
if (!array_key_exists('sort_field', $queryarray))
{
$queryarray['sort_field'] = 'added';
$queryarray['sort_dir'] = 'd';
}
//Get an array of the items from the query.
$list = get_db()->getTable('Item')->findBy($queryarray);
foreach ($list as $value) {
$itemIds[] = $value->id;
$list[] = $value;
}
}
//Browsing exhibit the rescue with ID 1 items
elseif (strpos($_SERVER['HTTP_REFERER'],'exhibits/show/the-rescue') != false) {
$exhibit_query = "search=&advanced[0][element_id]=&advanced[0][type]=&advanced[0][terms]=&range=&collection=&type=&user=&public=&featured=&exhibit=1&submit_search=Search&sort_field=Dublin+Core%2CDate";
parse_str($exhibit_query, $queryarray);
unset($queryarray['page']);
if (!array_key_exists('sort_field', $queryarray))
{
$queryarray['sort_field'] = 'added';
$queryarray['sort_dir'] = 'd';
}
//Get an array of the items from the query.
$list = get_db()->getTable('Item')->findBy($queryarray);
foreach ($list as $value) {
$itemIds[] = $value->id;
$list[] = $value;
}
}
//Browsing exhibit the committee with ID 2 items
elseif (strpos($_SERVER['HTTP_REFERER'],'exhibits/show/the-committee') != false) {
$exhibit_query = "search=&advanced[0][element_id]=&advanced[0][type]=&advanced[0][terms]=&range=&collection=&type=&user=&public=&featured=&exhibit=2&submit_search=Search&sort_field=Dublin+Core%2CDate";
parse_str($exhibit_query, $queryarray);
unset($queryarray['page']);
if (!array_key_exists('sort_field', $queryarray))
{
$queryarray['sort_field'] = 'added';
$queryarray['sort_dir'] = 'd';
}
//Get an array of the items from the query.
$list = get_db()->getTable('Item')->findBy($queryarray);
foreach ($list as $value) {
$itemIds[] = $value->id;
$list[] = $value;
}
}
//Browsing all items in general
else
{
if (!array_key_exists('sort_field', $queryarray))
{
$queryarray['sort_field'] = 'added';
$queryarray['sort_dir'] = 'd';
}
$list = get_db()->getTable('Item')->findBy($queryarray);
foreach ($list as $value) {
$itemIds[] = $value->id;
}
}
//Update the query string without the page and with the sort_fields
$updatedquery = http_build_query($queryarray);
$updatedquery = preg_replace('/%5B[0-9]+%5D/simU', '%5B%5D', $updatedquery);
// Find where we currently are in the result set
$key = array_search($current, $itemIds);
// If we aren't at the beginning, print a Previous link
if ($key > 0) {
$previousItem = $list[$key - 1];
$previousUrl = record_url($previousItem, 'show') . '?' . $updatedquery;
$text = __('← Previous Item');
echo '<li id="previous-item" class="previous, previous-item"><a href="' . html_escape($previousUrl) . '">' . $text . '</a></li>';
}
// If we aren't at the end, print a Next link
if ($key >= 0 && $key < (count($list) - 1)) {
$nextItem = $list[$key + 1];
$nextUrl = record_url($nextItem, 'show') . '?' . $updatedquery;
$text = __("Next Item →");
echo '<li id="next-item" class="next, next-item"><a href="' . html_escape($nextUrl) . '">' . $text . '</a></li>';
}
} else {
// If a search was not run, then the normal next/previous navigation is displayed.
echo '<li id="previous-item" class="previous">'.link_to_previous_item_show().'</li>';
echo '<li id="next-item" class="next">'.link_to_next_item_show().'</li>';
}
}
?>