-
Notifications
You must be signed in to change notification settings - Fork 0
/
biblio_list_template.php
167 lines (153 loc) · 6.84 KB
/
biblio_list_template.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
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
<?php
/**
* Template for Biblio List
* name of memberID text field must be: memberID
* name of institution text field must be: institution
*
* Copyright (C) 2015 Arie Nugraha ([email protected])
* Create by Eddy Subratha ([email protected])
*
* Slims 8 (Akasia)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
$label_cache = array();
/**
*
* Format bibliographic item list for OPAC display
*
* @param object $dbs
* @param array $biblio_detail
* @param int $n
* @param array $settings
* @param array $return_back
*
* @return string
*/
function biblio_list_format($dbs, $biblio_detail, $n, $settings = array(), &$return_back = array()) {
global $label_cache, $sysconf;
// init output var
$output = '';
$title = $biblio_detail['title'];
$biblio_id = $biblio_detail['biblio_id'];
$detail_url = SWB.'index.php?p=show_detail&id='.$biblio_id.'&keywords='.$settings['keywords'];
$cite_url = SWB.'index.php?p=cite&id='.$biblio_id.'&keywords='.$settings['keywords'];
// $title_link = '<a href="'.$detail_url.'" class="titleField" itemprop="name" property="name" title="'.__('View record detail description for this title').'">'.$title.'</a>';
// image thumbnail
$images_loc = 'images/docs/'.$biblio_detail['image'];
$thumb_url = './lib/minigalnano/createthumb.php?filename='.urlencode($images_loc).'&width=120';
// notes
$notes = getNotes($dbs, $biblio_id);
$custom_field = '';
$i = 0;
$expand = true;
if ($settings['enable_custom_frontpage'] AND $settings['custom_fields']) {
$custom_field = '<dl class="row text-sm">';
foreach ($settings['custom_fields'] as $field => $field_opts) {
if ($field_opts[0] == 1) {
$custom_field .= '<dt class="col-sm-3">'.$field_opts[1].'</dt><dd class="col-sm-9">'.(trim($biblio_detail[$field]) !== '' ? $biblio_detail[$field] : '-').'</dd>';
$i++;
}
}
$custom_field .= '</dl>';
}
if (empty($notes)) {
$notes = $custom_field;
$expand = false;
}
// availability
$availability = getAvailability($dbs, $biblio_id);
$class_avail = ($availability > 0) ? '' : 'text-danger';
// authors
$_authors = isset($biblio_detail['author'])?$biblio_detail['author']:biblio_list_model::getAuthors($dbs, $biblio_id, true);
$_authors_string = '';
if ($_authors) {
if (!is_array($_authors)) {
$_authors = explode('-', $_authors);
}
foreach ($_authors as $a) {
$a = trim($a);
$_authors_string .= '<a href="index.php?author='.urlencode($a).'&search=Search" itemprop="name" property="name" class="btn btn-outline-secondary btn-rounded">'.$a.'</a>';
}
}
$output .= '<div class="card item border-0 elevation-1 mb-6">';
$output .= '<div class="card-body">';
$output .= '<div class="row">';
$output .= '<div class="col-12 col-md-2">';
$output .= '<img src="'.$thumb_url.'" alt="cover" class="img-fluid rounded" />';
$output .= '</div>'; // -- close col-2
$output .= '<div class="col-8">';
$output .= '<h5><a title="'.__('View record detail description for this title').'" class="card-link text-dark" href="'.$detail_url.'">'.addEllipsis($title, 80).'</a></h5>';
$output .= '<div class="d-flex authors flex-wrap py-2">';
$output .= $_authors_string;
$output .= '</div>'; // -- close d-flex authors flex-wrap
$output .= '<p>'.$notes.'</p>';
$output .= '<div id="expand-'.$biblio_id.'" class="collapse py-2 collapse-detail">'.$custom_field.'</div>';
$output .= '</div>'; // -- close col-8
$output .= '<div class="col-2 hidden md:block">';
$output .= '<div class="card availability cursor-pointer">';
$output .= '<div class="card-body pt-3 pb-2 px-1">';
$output .= '<div class="d-flex availability-content flex-column">';
$output .= '<span class="label">'.__('Availability').'</span>';
$output .= '<span class="value '.$class_avail.'">'.$availability.'</span>';
$output .= '</div>'; // -- close d-flex flex-column
$output .= '<div class="add-to-chart align-items-center justify-content-center flex-column" data-biblio="'.$biblio_id.'">';
$output .= '<span class="add-to-chart label">'.__('Add to basket').'</span>';
$output .= '<span class="value"><i class="fas fa-plus"></i></span>';
$output .= '</div>'; // -- close d-flex flex-column
$output .= '</div>'; // -- close card-body pt-3 pb-2 px-1
$output .= '</div>'; // -- close card availability
$output .= '<a class="btn btn-outline-primary btn-block mt-2 btn-sm" href="'.$detail_url.'">'.__('View Detail').'</a>';
$output .= '<a class="btn btn-outline-secondary btn-block mt-2 btn-sm openPopUp citationLink" href="'.$cite_url.'" title="'.str_replace('{title}', substr($title, 0, 50) , __('Citation for: {title}')).'" target="_blank">'.__('Cite').'</a>';
$output .= '</div>'; // -- close col-2
$output .= '</div>'; // -- close row
if ($i > 0 && $expand) {
$output .= '<div class="expand"><a id="btn-expand-'.$biblio_id.'" class="flex justify-center text-decoration-none py-2" data-toggle="collapse" href="#expand-'.$biblio_id.'" role="button" aria-expanded="false" aria-controls="expand-'.$biblio_id.'"><i class="fas fa-angle-double-down"></i></a></div>';
}
$output .= '</div>';
$output .= '</div>';
// debug
// $output .= '<code>'.json_encode($biblio_detail).'</code>';
return $output;
}
function getNotes($dbs, $biblio_id)
{
$query = $dbs->query('SELECT notes FROM biblio WHERE biblio_id = ' . $biblio_id);
$data = $query->fetch_row();
return addEllipsis($data[0], 200);
}
function addEllipsis($string, $length, $end='…')
{
if (strlen($string) > $length)
{
$length -= strlen($end);
$string = substr($string, 0, $length);
$string .= $end;
}
return $string;
}
function getAvailability($dbs, $biblio_id)
{
// get total number of this biblio items/copies
$_item_q = $dbs->query('SELECT COUNT(*) FROM item WHERE biblio_id='.$biblio_id);
$_item_c = $_item_q->fetch_row();
// get total number of currently borrowed copies
$_borrowed_q = $dbs->query('SELECT COUNT(*) FROM loan AS l INNER JOIN item AS i'
.' ON l.item_code=i.item_code WHERE l.is_lent=1 AND l.is_return=0 AND i.biblio_id='.$biblio_id);
$_borrowed_c = $_borrowed_q->fetch_row();
// total available
$_total_avail = $_item_c[0]-$_borrowed_c[0];
return $_total_avail;
}