Newer
Older
<?php
/**
* This controller tells a client we provide OAI-PMH protocol and delivers oai-lom-data to harvest.
* Gets initialized due to requests. Validates metadata-prefix and used verb
* and calls a response-template with specified values.
*/
{
public function index_action()
{
$this->set_content_type('text/xml;charset=utf-8');
$this->request_url = Request::url();
$this->currentDate = gmdate(DATE_ATOM);
$allowed_verbs = ['GetRecord', 'Identify', 'ListIdentifiers', 'ListMetadataFormats', 'ListRecords', 'ListSets'];
$allowed_prefix = ['oai_lom-de'];
$request = Request::getInstance();
URLHelper::setBaseUrl($GLOBALS['ABSOLUTE_URI_STUDIP']);
$verb = $request->offsetGet('verb');
if (!empty($verb) && in_array($verb, $allowed_verbs)) {
$verb = lcfirst($verb);
$this->verb = $verb;
} else {
}
$metadataPrefix = $request->offsetGet('metadataPrefix');
if (empty($metadataPrefix) || in_array($metadataPrefix, $allowed_prefix)) {
$this->metadataPrefix = $metadataPrefix;
} else {
if (empty($this->response->body)) {
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
}
}
if ($this->verb && empty($this->response->body)) {
$this->prepareRequest($request, $verb, $metadataPrefix);
}
}
public function prepareRequest($request, $verb)
{
$this->from = $request->offsetGet('from');
$set = $request->offsetGet('set');
switch ($verb) {
case 'getRecord':
$this->prepareGetRecord($request);
break;
case 'identify':
$this->prepareIdentifier();
break;
case 'listIdentifiers':
$this->prepareListIdentifiers($set);
break;
case 'listMetadataFormats':
$this->prepareListMetadataFormats($request, $verb);
break;
case 'listRecords':
$this->prepareListRecords($set);
break;
case 'listSets':
$this->prepareListSets();
break;
}
}
//Prepare responses
public function prepareGetRecord($request)
{
$identifier = $request->offsetGet('identifier');
if($targetMaterial = OERMaterial::find($identifier)) {
$this->targetMaterial = $targetMaterial;
$this->tags = $targetMaterial->getTopics();
$this->vcard = vCard::export(User::find($targetMaterial->user_id));
$this->renderResponse($this->verb);
} else {
}
}
public function prepareListRecords($set)
{
$this->vcards = [];
$tag_collection = [];
if (!empty($set)) {
if (empty($target_set = OERTag::findBySQL('name = ?', [$set]))){
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
}
if ($this->records = OERMaterial::findByTag($set)) {
foreach ($this->records as $key=>$value) {
$tags = $value->getTopics();
for($i=0; $i<sizeof($tags); $i++) {
$tag_collection[$key][$i] = $tags[$i]['name'];
}
}
$this->tags = $tags;
$this->tag_collection = $tag_collection;
$this->set = $set;
$this->vcards[] = vCard::export(User::find($value->user_id));
$this->renderResponse($this->verb);
}
} else {
if ($this->records = OERMaterial::findBySQL('1')) {
foreach ($this->records as $key=>$value) {
$tags = $value->getTopics();
for($i=0; $i<sizeof($tags); $i++) {
$tag_collection[$key][$i] = $tags[$i]['name'];
}
}
$this->vcards[] = vCard::export(User::find($value->user_id));
$this->tag_collection = $tag_collection;
$this->renderResponse($this->verb);
} else {
}
}
}
public function prepareIdentifier()
{
$this->earliest_stamp = $this->getEarliestTime();
if ($identifier = OERTag::findBySQL('1')) {
$this->identifier = $identifier;
$this->renderResponse($this->verb);
} else {
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
}
}
public function prepareListIdentifiers($set)
{
if (!empty($set)) {
$this->set = $set;
$this->records = OERMaterial::findByTag($set);
foreach ($this->records as $key=>$value) {
$tags = $value->getTopics();
for($i=0; $i<sizeof($tags); $i++) {
$tag_collection[$key][$i] = $tags[$i]['name'];
}
}
} else {
$tags = [];
$tag_collection = [];
$this->records = OERMaterial::findBySQL('1');
foreach ($this->records as $key=>$value) {
$tags = $value->getTopics();
for($i=0; $i<sizeof($tags); $i++) {
$tag_collection[$key][$i] = $tags[$i]['name'];
}
}
}
$this->tag_collection = $tag_collection;
$this->renderResponse($this->verb);
}
public function prepareListMetadataFormats($request)
{
//TODO: get the host of current material - meanwhile we take current host
if ($identifier = $request->offsetGet('identifier')) {
if($targetMaterial = OERMaterial::find($identifier)) {
$this->identifier = $identifier;
$this->targetMaterial = $targetMaterial;
$this->renderResponse($this->verb);
} else {
}
} else {
$this->renderResponse($this->verb);
}
}
public function prepareListSets()
{
if ($tags = OERTag::findBySQL('1')) {
$this->tags = $tags;
$this->renderResponse($this->verb);
} else {
}
}
//Render
public function renderResponse($verb)
{
}
//Helper
public function getEarliestTime()
{
$entries = OERHost::findBySQL(
'1=1 ORDER BY mkdate asc',
[]
);
$entry = $entries[0]->mkdate;
return $earliest_stamp = gmdate(DATE_ATOM, $entry);
}
}