-
Notifications
You must be signed in to change notification settings - Fork 0
/
linticketCalendarClient.php
170 lines (133 loc) · 4.76 KB
/
linticketCalendarClient.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
<?php
require_once(__DIR__ . '/calendarClient.php');
class linticketCalendarClient extends calendarClient {
/**
* Holds url of event server
*/
private $url;
public function __construct ($url) {
parent::__construct();
$this->url = $url;
}
/**
* This function will get the data from the server
* and cache it for a period, say 5 seconds.
* It will handle the data as json.
* @param string $action At what action should the query be used on
* @param array $arguments Arguments used in the query
* @param bool $rawString Whether the function should return the result via json_decode() or not (raw string)
* @param bool $enableCache Whether the function should use or not use cache, if cache is turned on.
* @param integer $cacheTime seconds, if this particular request should have a different cache lifetime than ordinary.
* @return mixed
*/
private function getData (array $arguments, $rawString = false, $enableCache = true, $cacheTime = null) {
$queryArgs = '?';
// Putting together the query string
$singleValueParams = array('Maks', 'StartFra', 'StartDato');
foreach ($singleValueParams as $singleValue) {
if (array_key_exists($singleValue, $arguments)) {
$queryArgs .= $singleValue . '=' . $arguments[$singleValue] . '&';
unset($arguments[$singleValue]);
}
}
foreach ($arguments as $key => $valueArray) {
if (!empty($v)) {
if (!is_array($valueArray)) {
$valueArray = array($valueArray);
}
foreach ($valueArray as $value) {
$queryArgs .= $key . '[' . $value . ']=on&';
}
}
}
$queryArgs = substr($queryArgs, 0, -1);
$urlComplete = $this->url . $queryArgs;
error_log(__CLASS__ . '->' . __FUNCTION__ . ':' . $urlComplete);
$data = $this->getContent($urlComplete);
if ($rawString) {
return $data;
} else {
return json_decode($data);
}
}
/**
* This implementation of eventList will interpret limit and offset as unix timestamps.
* This is because of LinTicket's method of query which is based around start and end dates.
* It appears the query is not limited by limit or offset in the actual query, but the limit and offset
* is only applied after the query has been executed. If you want to get all events
* it is recommended you use limit and offset as unix timestamps.
*
* Return list of filtered events
* @param array $args Array of arguments to pass on to backend.
* @param limit will be interpreted as seconds
* @param offset will be interpreted as unix timestamp
* @return array
*/
public function eventList (array $filter, $limit = 10, $offset = 0) {
if (empty($filter['Maks'])) {
$filter['Maks'] = $limit;
}
if (empty($filter['StartFra'])) {
$filter['StartFra'] = $offset;
}
if (!empty($filter['noCurrentEvents']) && $filter['noCurrentEvents'] == 1) {
unset($filter['noCurrentEvents']);
$filter['StartDato'] = '1990-01-01';
}
$res = $this->getData($filter);
$findings = (object) array(
'data' => $res,
'count' => count($res),
'limit' => $limit,
'offset' => $offset,
'totalCount' => 0
);
if ($findings->count == $findings->limit) {
$findings->totalCount = $findings->offset + 2*$findings->limit;
} else {
$findings->totalCount = $findings->offset + $findings->limit;
}
return $findings;
}
public function event($id, array $args = array()) {
$res = $this->getData(array('Arr' => $id));
if (count($res) > 0) {
return $res[0];
} else {
return array();
}
}
public function translate($eventObject) {
$metaNames = array(
"linticket_arrid" => "id",
"linticket_link" => "url",
//"linticket_ical" => "ical",
"linticket_navn" => "title", // not to be stored as actual meta data
"linticket_teaser" => "lead_paragraph", // not to be stored as actual meta data
"linticket_tekst" => "description", // not to be stored as actual meta data
"linticket_dato" => "start_date",
"linticket_starttid" => "start_time",
"linticket_datoslutt" => "end_date",
"linticket_slutttid" => "end_time",
"linticket_stedid" => "common_location_id",
"linticket_sted" => "common_location_name",
//"linticket_location_id" => "location_id",
"linticket_arrangoerid" => "arranger_id",
"linticket_arrangoernavn" => "arranger_name",
"linticket_arrangerbilde" => "arranger_logo",
"linticket_bilde" => "primary_picture_url",
"linticket_priser" => "covercharge",
"linticket_eventlastchanged" => "updated_at",
);
$metaData = array();
$this->addMetaToPostArray($metaNames, $eventObject, $metaData, 'linticket');
if (!isset($metaData['dak_event_covercharge'])) {
$metaData['dak_event_covercharge'] = "";
}
$metaData['dak_event_ical'] = str_replace("json", "ical", $metaData['dak_event_url']);
return $metaData;
}
public function extractCategories($eventObject) {
return array();
}
}