-
Notifications
You must be signed in to change notification settings - Fork 20
/
SearchClient.php
125 lines (105 loc) · 3.27 KB
/
SearchClient.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
<?php
use Opencast\Models\OCConfig;
class SearchClient extends OCRestClient
{
public static $me;
public $serviceName = 'Search';
public function __construct($config_id = 1)
{
if ($config = OCConfig::getConfigForService('search', $config_id)) {
parent::__construct($config);
} else {
throw new Exception (_('Die Konfiguration wurde nicht korrekt angegeben'));
}
}
/**
* getEpisodes() - retrieves episode metadata for a given series identifier
* from connected Opencast
*
* @param string series_id Identifier for a Series
*
* @return array response of episodes
*/
public function getEpisodes($series_id, $refresh = false)
{
$cache = StudipCacheFactory::getCache();
$cache_key = 'oc_episodesforseries/' . $series_id;
$episodes = $cache->read($cache_key);
if ($refresh || $episodes === false || $GLOBALS['perm']->have_perm('dozent')) {
$service_url = "/episode.json?sid=" . $series_id . "&q=&episodes=true&sort=&limit=0&offset=0";
$x = "search-results";
if ($search = $this->getJSON($service_url)) {
$episodes = $search->$x->result;
if (!is_array($episodes)) {
$episodes = [$episodes];
}
$cache->write($cache_key, serialize($episodes), 7200);
return $episodes ?: [];
} else {
return [];
}
} else {
return unserialize($episodes) ?: [];
}
}
/**
* getSeries() - retrieves episode metadata for a given series identifier from conntected Opencast-Matterhorn Core
*
* @param string series_id Identifier for a Series
*
* @return array response of series
*/
public function getSeries($series_id)
{
$service_url = "/series.json?id={$series_id}&episodes=true&series=true";
if ($search = $this->getJSON($service_url)) {
//$x = "search-results";
//$episodes = $search->$x->result;
return $search;
}
}
/**
* getAllSeries() - retrieves episode metadata for a given series identifier from conntected Opencast-Matterhorn
* Core
*
* @param void
*
* @return array response of series
*/
public function getAllSeries()
{
$service_url = "/series.json";
if ($series = $this->getJSON($service_url)) {
$x = "search-results";
if (is_array($series->$x->result)) {
return $series->$x->result;
} else {
return [$series->$x->result];
}
} else {
return false;
}
}
// other functions
/**
* getEpisodeCount -
*
* @param string series_id Identifier for a Series
*
* @return int number of episodes
*/
public function getEpisodeCount($series_id)
{
if ($series = $this->getSeries($series_id)) {
$x = "search-results";
$count = $series->$x->total;
return intval($count);
}
}
public function getBaseURL()
{
$base = $this->base_url;
$url = preg_replace('/\/search/', '', $base);
return $url;
}
}