forked from php-tmdb/api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0790840
commit 73d9ce5
Showing
8 changed files
with
861 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
/** | ||
* This file is part of the Tmdb PHP API created by Michael Roterman. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @package Tmdb | ||
* @author Michael Roterman <[email protected]> | ||
* @copyright (c) 2013, Michael Roterman | ||
* @version 0.0.1 | ||
*/ | ||
require_once('../../../vendor/autoload.php'); | ||
require_once('../../../apikey.php'); | ||
|
||
$token = new \Tmdb\ApiToken(TMDB_API_KEY); | ||
$client = new \Tmdb\Client($token); | ||
|
||
$repository = new \Tmdb\Repository\JobsRepository($client); | ||
$jobs = $repository->loadCollection(); | ||
|
||
foreach($jobs as $job) { | ||
var_dump($job); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
/** | ||
* This file is part of the Tmdb PHP API created by Michael Roterman. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @package Tmdb | ||
* @author Michael Roterman <[email protected]> | ||
* @copyright (c) 2013, Michael Roterman | ||
* @version 0.0.1 | ||
*/ | ||
namespace Tmdb\Factory; | ||
|
||
use Tmdb\Model\Collection\Jobs; | ||
use Tmdb\Model\Job; | ||
|
||
class JobsFactory extends AbstractFactory | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function create(array $data = array()) | ||
{ | ||
return $this->hydrate(new Job(), $data); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function createCollection(array $data = array()) | ||
{ | ||
$collection = new Jobs(); | ||
|
||
if (array_key_exists('jobs', $data)) { | ||
$data = $data['jobs']; | ||
} | ||
|
||
foreach($data as $item) { | ||
$collection->add(null, $this->create($item)); | ||
} | ||
|
||
return $collection; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
/** | ||
* This file is part of the Tmdb PHP API created by Michael Roterman. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @package Tmdb | ||
* @author Michael Roterman <[email protected]> | ||
* @copyright (c) 2013, Michael Roterman | ||
* @version 0.0.1 | ||
*/ | ||
namespace Tmdb\Model\Collection; | ||
|
||
use Tmdb\Model\Common\GenericCollection; | ||
|
||
class Jobs extends GenericCollection { | ||
|
||
/** | ||
* Filter by department | ||
* | ||
* @param string $department | ||
* @return $this | ||
*/ | ||
public function filterByDepartment($department) | ||
{ | ||
$result = $this->filter( | ||
function($key, $value) use ($department) { | ||
if ($value->getDepartment() == $department) { return true; } | ||
} | ||
); | ||
|
||
if ($result && 1 === count($result)) { | ||
return array_shift($result->toArray()); | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* Filter by department and return the jobs collection | ||
* | ||
* @param string $department | ||
* @return $this | ||
*/ | ||
public function filterByDepartmentAndReturnJobsList($department) | ||
{ | ||
$result = $this->filter( | ||
function($key, $value) use ($department) { | ||
if ($value->getDepartment() == $department) { return true; } | ||
} | ||
); | ||
|
||
if ($result && 1 === count($result)) { | ||
$data = array_shift($result->toArray()); | ||
|
||
return $data->getJobList(); | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* Filter by job | ||
* | ||
* @param string $filterByJob | ||
* @return $this | ||
*/ | ||
public function filterByJob($filterByJob) | ||
{ | ||
$result = $this->filter( | ||
function($key, $value) use ($filterByJob) { | ||
$jobList = $value->getJobList(); | ||
|
||
foreach($jobList as $job) { | ||
if ($filterByJob == $job) { return true; } | ||
} | ||
} | ||
); | ||
|
||
if ($result && 1 === count($result)) { | ||
return array_shift($result->toArray()); | ||
} | ||
|
||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
/** | ||
* This file is part of the Tmdb PHP API created by Michael Roterman. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @package Tmdb | ||
* @author Michael Roterman <[email protected]> | ||
* @copyright (c) 2013, Michael Roterman | ||
* @version 0.0.1 | ||
*/ | ||
namespace Tmdb\Model; | ||
|
||
class Job extends AbstractModel { | ||
|
||
public static $_properties = array( | ||
'department', | ||
'job_list' | ||
); | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $department; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $jobList; | ||
|
||
/** | ||
* @param string $department | ||
* @return $this | ||
*/ | ||
public function setDepartment($department) | ||
{ | ||
$this->department = $department; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getDepartment() | ||
{ | ||
return $this->department; | ||
} | ||
|
||
/** | ||
* @param array $jobList | ||
* @return $this | ||
*/ | ||
public function setJobList(array $jobList) | ||
{ | ||
$this->jobList = $jobList; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getJobList() | ||
{ | ||
return $this->jobList; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
/** | ||
* This file is part of the Tmdb PHP API created by Michael Roterman. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @package Tmdb | ||
* @author Michael Roterman <[email protected]> | ||
* @copyright (c) 2013, Michael Roterman | ||
* @version 0.0.1 | ||
*/ | ||
namespace Tmdb\Repository; | ||
|
||
use Tmdb\Factory\JobsFactory; | ||
use Tmdb\Model\Collection\Jobs; | ||
use Tmdb\Model\Job; | ||
|
||
class JobsRepository extends AbstractRepository { | ||
/** | ||
* @param array $parameters | ||
* @param array $headers | ||
* @return Job | ||
*/ | ||
public function load(array $parameters = array(), array $headers = array()) { | ||
return $this->loadCollection($parameters, $headers); | ||
} | ||
|
||
/** | ||
* Get the list of jobs. | ||
* | ||
* @param array $parameters | ||
* @param array $headers | ||
* @return Jobs|Job[] | ||
*/ | ||
public function loadCollection(array $parameters = array(), array $headers = array()) | ||
{ | ||
return $this->createCollection( | ||
$this->getApi()->getJobs($parameters, $headers) | ||
); | ||
} | ||
|
||
/** | ||
* Create an collection of an array | ||
* | ||
* @param $data | ||
* @return Jobs|Job[] | ||
*/ | ||
private function createCollection($data){ | ||
return $this->getFactory()->createCollection($data); | ||
} | ||
|
||
/** | ||
* Return the related API class | ||
* | ||
* @return \Tmdb\Api\Jobs | ||
*/ | ||
public function getApi() | ||
{ | ||
return $this->getClient()->getJobsApi(); | ||
} | ||
|
||
/** | ||
* @return JobsFactory | ||
*/ | ||
public function getFactory() | ||
{ | ||
return new JobsFactory(); | ||
} | ||
} |
Oops, something went wrong.