1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace rolb\CFilm; |
4
|
|
|
|
5
|
|
|
class CFilms |
6
|
|
|
{ |
7
|
|
|
private $apikey; |
8
|
|
|
private $date; |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* CFilms constructor. |
14
|
|
|
* @param $apikey |
15
|
|
|
* @param $date |
16
|
|
|
*/ |
17
|
4 |
|
public function __construct($apikey, $date) |
18
|
|
|
{ |
19
|
4 |
|
$this->apikey = $apikey; |
20
|
4 |
|
$this->date = $date; |
21
|
4 |
|
} |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Renders the html |
26
|
|
|
*/ |
27
|
1 |
|
public function program() |
28
|
|
|
{ |
29
|
1 |
|
$data = $this->getProg(); |
30
|
|
|
|
31
|
1 |
|
$html = '<div class="date"> Stockholms Filmfestival Programme ' . $this->date . '<br></div>'; |
32
|
|
|
|
33
|
1 |
|
foreach($data as $value) { |
34
|
|
|
|
35
|
1 |
|
$filmid = $value["filmId"]; |
36
|
|
|
|
37
|
1 |
|
$html .= '<br><div class="ftime">' . substr(htmlentities($value["eventTime"]), 0, -3) . '</div>'; |
38
|
|
|
|
39
|
1 |
|
$html .= '<div class="fname"><a href="sthlmfilms?film=' . $filmid . '">' . htmlentities($value["eventName_en"]) . '</a></div>'; |
40
|
|
|
|
41
|
1 |
|
$html .= '<div class="fvenue">Venue: ' . htmlentities($value["venueName"]) . '</div>'; |
42
|
|
|
|
43
|
1 |
|
$html .= '<br>'; |
44
|
|
|
|
45
|
1 |
|
} |
46
|
|
|
|
47
|
1 |
|
return $html; |
48
|
|
|
} |
49
|
|
|
|
50
|
1 |
|
public function filmInfo($filmid) |
51
|
|
|
{ |
52
|
1 |
|
$filmdata = $this->getFilm($filmid); |
53
|
|
|
|
54
|
1 |
|
$html = ''; |
55
|
1 |
|
$html .= '<br><div class="ftitle">' . htmlentities($filmdata["filmName"]) . '</div>'; |
56
|
1 |
|
$html .= '<br><div class="fdir"> Director: ' . htmlentities($filmdata["filmDirector"]) . '</div>'; |
57
|
1 |
|
$html .= '<br><div class="flength">' . htmlentities($filmdata["filmLength"]) . ' minutes </div>'; |
58
|
1 |
|
$html .= '<br><div class="finfo">' . htmlentities($filmdata["filmDescription_en"]) . '</div>'; |
59
|
1 |
|
$html .= '<br><div class="flink"> <iframe width="420" height="315"src="https://www.youtube.com/embed/' . htmlentities($filmdata["filmYoutubeId"]) . '"></iframe></div>'; |
60
|
|
|
|
61
|
1 |
|
return $html; |
62
|
|
|
} |
63
|
|
|
|
64
|
2 |
View Code Duplication |
private function getProg() |
|
|
|
|
65
|
|
|
{ |
66
|
|
|
|
67
|
2 |
|
$result = file_get_contents("http://api.stockholmfilmfestival.se/v1/events/date_list/format/json/date/" |
68
|
2 |
|
. $this->date . "/API-Key/" . $this->apikey); |
69
|
|
|
|
70
|
2 |
|
return json_decode($result, true); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
|
74
|
2 |
View Code Duplication |
private function getFilm($filmid) |
|
|
|
|
75
|
|
|
{ |
76
|
|
|
|
77
|
2 |
|
$result = file_get_contents("http://api.stockholmfilmfestival.se/v1/films/film/film_id/" |
78
|
2 |
|
. $filmid . "/API-Key/" . $this->apikey . "/format/json/"); |
79
|
|
|
|
80
|
2 |
|
return json_decode($result, true); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.