1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the Tmdb package. |
5
|
|
|
* |
6
|
|
|
* (c) Vincent Faliès <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
* |
11
|
|
|
* @author Vincent Faliès <[email protected]> |
12
|
|
|
* @copyright Copyright (c) 2017 |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace VfacTmdb\Catalogs; |
16
|
|
|
|
17
|
|
|
use VfacTmdb\Interfaces\TmdbInterface; |
18
|
|
|
|
19
|
|
|
use VfacTmdb\Exceptions\TmdbException; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Class to get jobs list with department |
23
|
|
|
* @package Tmdb |
24
|
|
|
* @author Vincent Faliès <[email protected]> |
25
|
|
|
* @copyright Copyright (c) 2017 |
26
|
|
|
*/ |
27
|
|
|
class Jobs |
28
|
|
|
{ |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Tmdb object |
32
|
|
|
* @var TmdbInterface |
33
|
|
|
*/ |
34
|
|
|
protected $tmdb = null; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Constructor |
38
|
|
|
* @param TmdbInterface $tmdb |
39
|
|
|
*/ |
40
|
6 |
|
public function __construct(TmdbInterface $tmdb) |
41
|
|
|
{ |
42
|
6 |
|
$this->tmdb = $tmdb; |
43
|
6 |
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Get job list |
47
|
|
|
* @return \Generator|\stdClass |
48
|
|
|
* @throws TmdbException |
49
|
|
|
*/ |
50
|
6 |
|
public function getList() : \Generator |
51
|
|
|
{ |
52
|
|
|
try { |
53
|
6 |
|
$response = $this->tmdb->getRequest('job/list'); |
54
|
|
|
|
55
|
3 |
|
$results = []; |
56
|
3 |
|
if (isset($response->jobs)) { |
57
|
3 |
|
foreach ($response->jobs as $j) { |
58
|
3 |
|
$result = new \stdClass(); |
59
|
3 |
|
$result->department = $j->department; |
60
|
3 |
|
$result->jobs = $j->job_list; |
61
|
|
|
|
62
|
3 |
|
$results[] = $result; |
63
|
|
|
} |
64
|
|
|
} |
65
|
3 |
|
} catch (TmdbException $ex) { |
66
|
3 |
|
throw $ex; |
67
|
|
|
} |
68
|
3 |
|
return $this->genreItemGenerator($results); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Genre Item generator method |
73
|
|
|
* @param array $results |
74
|
|
|
* @return \Generator |
75
|
|
|
*/ |
76
|
3 |
|
private function genreItemGenerator(array $results) : \Generator |
77
|
|
|
{ |
78
|
3 |
|
foreach ($results as $result) { |
79
|
3 |
|
yield $result; |
80
|
|
|
} |
81
|
3 |
|
} |
82
|
|
|
} |
83
|
|
|
|