public function getReadingHistory($patron, $page = 1, $recordsPerPage = -1, $sortOption = "dueDate") { require_once ROOT_DIR . '/sys/ReadingHistoryEntry.php'; require_once ROOT_DIR . '/services/MyResearch/lib/Resource.php'; //Reading History is stored within VuFind for each patron. global $user; $historyActive = $user->trackReadingHistory == 1; //Get a list of titles for the user. $titles = array(); $readingHistory = new ReadingHistoryEntry(); $readingHistorySql = "SELECT * FROM user_reading_history INNER JOIN resource ON user_reading_history.resourceId = resource.id where userId = {$user->id}"; if ($sortOption == "title") { $readingHistorySql .= " order by title_sort ASC, title ASC"; } elseif ($sortOption == "author") { $readingHistorySql .= " order by author ASC, title ASC"; } elseif ($sortOption == "checkedOut") { $readingHistorySql .= " order by firstCheckoutDate DESC, title ASC"; } elseif ($sortOption == "returned") { $readingHistorySql .= " order by lastCheckoutDate DESC, title ASC"; } elseif ($sortOption == "format") { $readingHistorySql .= " order by format DESC, title ASC"; } //Get count of reading history $readingHistoryCount = new ReadingHistoryEntry(); $readingHistoryCount->query($readingHistorySql); $numTitles = $readingHistoryCount->N; //Get individual titles to display if ($recordsPerPage > 0) { $startRecord = ($page - 1) * $recordsPerPage; $readingHistorySql .= " LIMIT {$startRecord}, {$recordsPerPage}"; } $readingHistory->query($readingHistorySql); if ($readingHistory->N > 0) { //Load additional details for each title global $configArray; // Setup Search Engine Connection $i = 0; $titles = array(); while ($readingHistory->fetch()) { $firstCheckoutDate = $readingHistory->firstCheckoutDate; $firstCheckoutTime = strtotime($firstCheckoutDate); $lastCheckoutDate = $readingHistory->lastCheckoutDate; $lastCheckoutTime = strtotime($lastCheckoutDate); $titles[] = array('recordId' => $readingHistory->record_id, 'source' => $readingHistory->source, 'checkout' => $firstCheckoutDate, 'checkoutTime' => $firstCheckoutTime, 'lastCheckout' => $lastCheckoutDate, 'lastCheckoutTime' => $lastCheckoutTime, 'title' => $readingHistory->title, 'title_sort' => $readingHistory->title_sort, 'author' => $readingHistory->author, 'format' => $readingHistory->format, 'format_category' => $readingHistory->format_category, 'isbn' => $readingHistory->isbn, 'upc' => $readingHistory->upc); } } return array('historyActive' => $historyActive, 'titles' => array_values($titles), 'numTitles' => $numTitles); }