-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathoclcClient.php
More file actions
106 lines (95 loc) · 2.92 KB
/
oclcClient.php
File metadata and controls
106 lines (95 loc) · 2.92 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
<?php
/*
* Convernience class for displaying data objects returned by the KB Api.
* Created by terrywbrady at OCLC Developer House 2014.
*/
class oclcClient {
public $page;
public $serviceOpt;
public $pageOpt;
public function __construct($page, $get) {
$this->page = $page;
$this->serviceOpt = array();
$this->pageOpt = array("page" => $page);
foreach($get as $k => $v) {
$this->pageOpt[$k] = $v;
if ($k == "mode") continue;
if ($k == "uid") continue;
$this->serviceOpt[$k] = $v;
}
}
public function getKey($k, $def = "") {
if (isset($this->pageOpt[$k])) {
return $this->pageOpt[$k];
}
return $def;
}
public function hasKey($k) {
$mode = $this->getKey($k);
return ($mode != "");
}
public function writeHomeLink() {
echo "<div><a href='{$this->page}'>Home</a></div>";
}
public function getPaginationSummary($result, $title) {
$this->writeLink($result->getPaginationUrl($result->pager->firstPageIndex), "<<");
$this->writeLink($result->getPaginationUrl($result->pager->prevPageIndex), "<");
$result->pager->getPaginationSummary($title);
$this->writeLink($result->getPaginationUrl($result->pager->nextPageIndex), ">");
$this->writeLink($result->getPaginationUrl($result->pager->lastPageIndex), ">>");
}
public function writeLink($url, $label) {
if ($url == null) return;
echo "<a href='{$url}'>{$label}</a> ";
}
public function getTable($result) {
if (is_array($result->data)) {
$this->getDataTable($result);
} else {
$this->getDetailTable($result);
}
}
public function getDetailTable($result) {
echo "<table><tr><th>Property</th><th>Value</th></tr>";
$row = $result->data;
foreach($result->header as $col) {
echo "<tr><th>{$col->name}</th><td>";
$val = $row->getVal($col->id);
$link = $row->getLinkOptions($col->id);
$url = $this->page . oclcService::makeQuery($link);
if (count($link) > 0) echo "<a href='{$url}'>";
echo $val;
if (count($link) > 0) echo "</a>";
echo "</td></tr>";
}
echo "</table>";
}
public function getDataTable($result) {
echo "<table><tr>";
foreach($result->header as $col) {
if (!$col->summaryView) continue;
echo "<th>{$col->name}</th>";
}
echo "</tr>";
foreach($result->data as $row) {
echo "<tr>";
$first = true;
foreach($result->header as $col) {
if (!$col->summaryView) continue;
$val = $row->getVal($col->id);
$tag = ($first) ? "th" : "td";
$link = $row->getLinkOptions($col->id);
$url = $this->page . oclcService::makeQuery($link);
echo "<{$tag}>";
if (count($link) > 0) echo "<a href='{$url}'>";
echo $val;
if (count($link) > 0) echo "</a>";
echo "</{$tag}>";
$first = false;
}
echo "</tr>";
}
echo "</table>";
}
}
?>