forked from opendream/hotri
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BiblioStatusHistQuery.php
196 lines (180 loc) · 8.05 KB
/
BiblioStatusHistQuery.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
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
<?php
/* This file is part of a copyrighted work; it is distributed with NO WARRANTY.
* See the file COPYRIGHT.html for more details.
*/
require_once("../shared/global_constants.php");
require_once("../classes/Query.php");
require_once("../classes/BiblioStatusHist.php");
require_once("../classes/SettingsQuery.php");
/******************************************************************************
* BiblioStatusHistQuery data access component for holds on library bibliography copies
*
* @author David Stevens <[email protected]>;
* @version 1.0
* @access public
******************************************************************************
*/
class BiblioStatusHistQuery extends Query {
var $_rowCount = 0;
var $_loc;
function BiblioStatusHistQuery() {
$this->Query();
$this->_loc = new Localize(OBIB_LOCALE,"classes");
}
function getRowCount() {
return $this->_rowCount;
}
/****************************************************************************
* Executes a query to select status history
* @param string $bibid bibid of bibliography status history to select
* @return boolean returns false if error occurs
* @access public
****************************************************************************
*/
function queryByBibid($bibid) {
# setting query that will return all the data
$sql = $this->mkSQL("select biblio_status_hist.*, "
. " biblio.title, biblio.author, "
. " biblio_copy.barcode_nmbr biblio_barcode_nmbr, "
. " member.last_name, member.first_name, "
. " member.barcode_nmbr mbr_barcode_nmbr "
. "from biblio_status_hist, biblio, "
. " biblio_copy, member "
. "where biblio_status_hist.bibid = biblio.bibid "
. " and biblio_status_hist.bibid = biblio_copy.bibid "
. " and biblio_status_hist.copyid = biblio_copy.copyid "
. " and biblio_status_hist.mbrid = member.mbrid "
. " and biblio_status_hist.bibid = %N "
. "order by status_begin_dt desc, biblio_copy.barcode_nmbr ",
$bibid);
if (!$this->_query($sql, $this->_loc->getText("biblioStatusHistQueryErr1"))) {
return false;
}
$this->_rowCount = $this->_conn->numRows();
return true;
}
/****************************************************************************
* Executes a query to select status history
* @param string $mbrid mbrid of member
* @return boolean returns false if error occurs
* @access public
****************************************************************************
*/
function queryByMbrid($mbrid) {
# setting query that will return all the data
$sql = $this->mkSQL("select biblio_status_hist.*, "
. " biblio.title, biblio.author, "
. " biblio_copy.barcode_nmbr biblio_barcode_nmbr, "
. " member.last_name, member.first_name, "
. " member.barcode_nmbr mbr_barcode_nmbr "
. "from biblio_status_hist, biblio, "
. " biblio_copy, member "
. "where biblio_status_hist.bibid = biblio.bibid "
. " and biblio_status_hist.bibid = biblio_copy.bibid "
. " and biblio_status_hist.copyid = biblio_copy.copyid "
. " and biblio_status_hist.mbrid = member.mbrid "
. " and biblio_status_hist.mbrid = %N "
. "order by status_begin_dt desc ",
$mbrid);
if (!$this->_query($sql, $this->_loc->getText("biblioStatusHistQueryErr2"))) {
return false;
}
$this->_rowCount = $this->_conn->numRows();
return true;
}
/****************************************************************************
* Fetches a row from the query result and populates the BiblioStatusHist object.
* @return BiblioStatusHist returns bibliography status history object or false if no more holds to fetch
* @access public
****************************************************************************
*/
function fetchRow() {
$array = $this->_conn->fetchRow();
if ($array == false) {
return false;
}
$hist = new BiblioStatusHist();
$hist->setBibid($array["bibid"]);
$hist->setCopyid($array["copyid"]);
$hist->setBiblioBarcodeNmbr($array["biblio_barcode_nmbr"]);
$hist->setTitle($array["title"]);
$hist->setAuthor($array["author"]);
$hist->setStatusCd($array["status_cd"]);
$hist->setStatusBeginDt($array["status_begin_dt"]);
$hist->setMbrid($array["mbrid"]);
$hist->setLastName($array["last_name"]);
$hist->setFirstName($array["first_name"]);
$hist->setMbrBarcodeNmbr($array["mbr_barcode_nmbr"]);
$hist->setDueBackDt($array["due_back_dt"]);
$hist->setRenewalCount($array["renewal_count"]);
return $hist;
}
/****************************************************************************
* Inserts a new bibliography status history into the biblio_status_hist table.
* @param BiblioStatusHist $hist history to insert
* @access public
****************************************************************************
*/
function insert($hist) {
$sql = $this->mkSQL("insert into biblio_status_hist values "
. "(%N, %N, %Q, sysdate(), ",
$hist->getBibid(), $hist->getCopyid(),
$hist->getStatusCd());
if ($hist->getDueBackDt() != "") {
$sql .= $this->mkSQL("%Q, ", $hist->getDueBackDt());
} else {
$sql .= "null, ";
}
$sql .= $this->mkSQL("%N, %N)", $hist->getMbrid(), $hist->getRenewalCount());
if (!$this->_query($sql, $this->_loc->getText("biblioStatusHistQueryErr3"))) {
return false;
}
$this->_purgeHistory($hist->getMbrid());
return true;
}
/****************************************************************************
* Deletes history from the biblio_status_hist table.
* @param string $bibid bibliography id of history to delete
* @param string $copyid copy id of history to delete.
* @return boolean returns false, if error occurs
* @access public
****************************************************************************
*/
function deleteByBibid($bibid,$copyid) {
$sql = $this->mkSQL("delete from biblio_status_hist "
. "where bibid = %N and copyid = %N",
$bibid, $copyid);
return $this->_query($sql, $this->_loc->getText("biblioStatusHistQueryErr4"));
}
/****************************************************************************
* Deletes history from the biblio_status_hist table.
* @param string $mbrid member id of history to delete
* @return boolean returns false, if error occurs
* @access public
****************************************************************************
*/
function deleteByMbrid($mbrid) {
$sql = $this->mkSQL("delete from biblio_status_hist where mbrid = %N", $mbrid);
return $this->_query($sql, $this->_loc->getText("biblioStatusHistQueryErr5"));
}
/****************************************************************************
* Deletes history from the biblio_status_hist table.
* @param string $mbrid member id of history to delete
* @return boolean returns false, if error occurs
* @access private
****************************************************************************
*/
function _purgeHistory($mbrid) {
$setQ = new SettingsQuery();
$purgeMo = $setQ->getPurgeHistoryAfterMonths($this);
if ($purgeMo == 0) {
return TRUE;
}
$sql = $this->mkSQL("delete from biblio_status_hist where mbrid = %N"
. " and status_begin_dt <= date_add(sysdate(),interval - %N month)",
$mbrid, $purgeMo);
// need to add where clause for purge rule
return $this->_query($sql, $this->_loc->getText("biblioStatusHistQueryErr5"));
}
}
?>