From a7994291a791bd07b48eef3ea62239abf7206f2f Mon Sep 17 00:00:00 2001 From: sdabet Date: Sat, 28 Jun 2014 08:13:48 +0200 Subject: [PATCH 1/2] Added showtimelist method --- PHP/allocine.class.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/PHP/allocine.class.php b/PHP/allocine.class.php index 3232aa0..61133c4 100644 --- a/PHP/allocine.class.php +++ b/PHP/allocine.class.php @@ -68,4 +68,20 @@ public function get($id) return $response; } + + public function showtimelist($zip, $radius) { + // build the params + $params = array( + 'partner' => $this->_partner_key, + 'zip' => $zip, + 'radius' => $radius, + 'format' => 'json', + 'filter' => 'movie' + ); + + // do the request + $response = $this->_do_request('showtimelist', $params); + + return $response; + } } \ No newline at end of file From 66f79569049e469e448224ea205c8d281d0b42bb Mon Sep 17 00:00:00 2001 From: sdabet Date: Sat, 28 Jun 2014 08:15:51 +0200 Subject: [PATCH 2/2] Added script to demonstrate usage of showtimelist --- PHP/showtimelist.php | 62 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 PHP/showtimelist.php diff --git a/PHP/showtimelist.php b/PHP/showtimelist.php new file mode 100644 index 0000000..77fc211 --- /dev/null +++ b/PHP/showtimelist.php @@ -0,0 +1,62 @@ +#!/usr/bin/php +showtimelist($zip, $radius); + +$json = json_decode($response); // Parse the returned json + +$theaters = $json->feed->theaterShowtimes; // Retrieve list of theaters + +$table = array(); // Array of data to display +$max_length = array(0,0,0,0,0); // Array of max column length (to display equal length columns) +$index = 0; // Index of current movie + +// Iterate over all theaters and fill table with movies information +foreach($theaters as $theater){ + $times = $theater->movieShowtimes; + foreach($times as $i => $time){ + // Append times in an array + $horaires = $time->scr; + $today = $horaires[0]; + $formatted_times = array(); + foreach($today->t as $t){ + array_push($formatted_times, $t->{'$'}); + } + + // Populate movie data in a row + $movie = $time->onShow->movie; + $table[$index] = array( + $theater->place->theater->name, + $movie->code, + $movie->title, + $time->version->original ? "VO" : "VF", + implode($formatted_times, ", ") + ); + $index++; + } +} + +// Compute max length for each column +foreach($table as $row){ + foreach($row as $i => $val){ + $max_length[$i] = max($max_length[$i], strlen($val)); + } +} + +// Display results +foreach($table as $row){ + foreach($row as $i => $val){ + printf("%-".$max_length[$i]."s ", utf8_decode($val)); + } + echo "\n"; +}