From 73d9ce537da56dff9f668949f27cddde8f33f2e9 Mon Sep 17 00:00:00 2001 From: Michael Roterman Date: Wed, 5 Feb 2014 22:03:31 +0100 Subject: [PATCH] Implementing Jobs --- examples/jobs/model/all.php | 24 ++ lib/Tmdb/Factory/JobsFactory.php | 45 ++ lib/Tmdb/Model/Collection/Jobs.php | 87 ++++ lib/Tmdb/Model/Job.php | 65 +++ lib/Tmdb/Repository/JobsRepository.php | 70 ++++ test/Tmdb/Tests/Factory/JobsFactoryTest.php | 122 ++++++ .../Tests/Repository/JobsRepositoryTest.php | 56 +++ test/Tmdb/Tests/Resources/jobs/list.json | 392 ++++++++++++++++++ 8 files changed, 861 insertions(+) create mode 100644 examples/jobs/model/all.php create mode 100644 lib/Tmdb/Factory/JobsFactory.php create mode 100644 lib/Tmdb/Model/Collection/Jobs.php create mode 100644 lib/Tmdb/Model/Job.php create mode 100644 lib/Tmdb/Repository/JobsRepository.php create mode 100644 test/Tmdb/Tests/Factory/JobsFactoryTest.php create mode 100644 test/Tmdb/Tests/Repository/JobsRepositoryTest.php create mode 100644 test/Tmdb/Tests/Resources/jobs/list.json diff --git a/examples/jobs/model/all.php b/examples/jobs/model/all.php new file mode 100644 index 00000000..75f39a8b --- /dev/null +++ b/examples/jobs/model/all.php @@ -0,0 +1,24 @@ + + * @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); +} \ No newline at end of file diff --git a/lib/Tmdb/Factory/JobsFactory.php b/lib/Tmdb/Factory/JobsFactory.php new file mode 100644 index 00000000..6e8cbb41 --- /dev/null +++ b/lib/Tmdb/Factory/JobsFactory.php @@ -0,0 +1,45 @@ + + * @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; + } +} diff --git a/lib/Tmdb/Model/Collection/Jobs.php b/lib/Tmdb/Model/Collection/Jobs.php new file mode 100644 index 00000000..8e25a59c --- /dev/null +++ b/lib/Tmdb/Model/Collection/Jobs.php @@ -0,0 +1,87 @@ + + * @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; + } +} diff --git a/lib/Tmdb/Model/Job.php b/lib/Tmdb/Model/Job.php new file mode 100644 index 00000000..47a9ebcb --- /dev/null +++ b/lib/Tmdb/Model/Job.php @@ -0,0 +1,65 @@ + + * @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; + } +} diff --git a/lib/Tmdb/Repository/JobsRepository.php b/lib/Tmdb/Repository/JobsRepository.php new file mode 100644 index 00000000..332c462e --- /dev/null +++ b/lib/Tmdb/Repository/JobsRepository.php @@ -0,0 +1,70 @@ + + * @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(); + } +} \ No newline at end of file diff --git a/test/Tmdb/Tests/Factory/JobsFactoryTest.php b/test/Tmdb/Tests/Factory/JobsFactoryTest.php new file mode 100644 index 00000000..3adccc76 --- /dev/null +++ b/test/Tmdb/Tests/Factory/JobsFactoryTest.php @@ -0,0 +1,122 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Tests\Factory; + +use Tmdb\Model\Collection\Jobs; + +class JobFactoryTest extends TestCase +{ + private $jobs; + + public function setUp() + { + $factory = $this->getFactory(); + $data = $this->loadByFile('jobs/list.json'); + + $this->jobs = $factory->createCollection($data); + } + + /** + * @test + */ + public function shouldConstructJobs() + { + $this->assertInstanceOf('Tmdb\Model\Collection\Jobs', $this->jobs); + } + + /** + * @test + */ + public function shouldFilterDepartment() + { + $filteredJobs = $this->jobs->filterByDepartment('Actors'); + + $expectedJobs = array( + 'Actor', + 'Stunt Double', + 'Voice', + 'Cameo', + 'Special Guest' + ); + + foreach($filteredJobs->getJobList() as $filteredJob) { + $this->assertEquals(true, in_array($filteredJob, $expectedJobs)); + } + } + + /** + * @test + */ + public function shouldReturnEmptyDepartmentCollection() + { + $filteredJobs = $this->jobs->filterByDepartment('JOB_DOES_NOT_EXIST')->getAll(); + + $this->assertEquals(true, empty($filteredJobs)); + } + + /** + * @test + */ + public function shouldFilterJobsByDepartment() + { + $filteredJobs = $this->jobs->filterByDepartmentAndReturnJobsList('Actors'); + + $expectedJobs = array( + 'Actor', + 'Stunt Double', + 'Voice', + 'Cameo', + 'Special Guest' + ); + + foreach($filteredJobs as $filteredJob) { + $this->assertEquals(true, in_array($filteredJob, $expectedJobs)); + } + } + + /** + * @test + */ + public function shouldReturnEmptyJobsByDepartmentCollection() + { + $filteredJobs = $this->jobs->filterByDepartmentAndReturnJobsList('JOB_DOES_NOT_EXIST')->getAll(); + + $this->assertEquals(true, empty($filteredJobs)); + } + + /** + * @test + */ + public function shouldFilterByJob() + { + $filteredJobs = $this->jobs->filterByJob('Stunt Double'); + + $this->assertEquals('Actors', $filteredJobs->getDepartment()); + } + + /** + * @test + */ + public function shouldReturnEmptyJobsCollection() + { + $filteredJobs = $this->jobs->filterByJob('JOB_DOES_NOT_EXIST')->getAll(); + + $this->assertEquals(true, empty($filteredJobs)); + } + + + protected function getFactoryClass() + { + return 'Tmdb\Factory\JobsFactory'; + } +} \ No newline at end of file diff --git a/test/Tmdb/Tests/Repository/JobsRepositoryTest.php b/test/Tmdb/Tests/Repository/JobsRepositoryTest.php new file mode 100644 index 00000000..db0177ff --- /dev/null +++ b/test/Tmdb/Tests/Repository/JobsRepositoryTest.php @@ -0,0 +1,56 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Tests\Repository; + +class JobsRepositoryTest extends TestCase +{ + /** + * @test + */ + public function shouldForwardLoad() + { + $repository = $this->getRepositoryWithMockedHttpClient(); + + $repository->load(); + } + + /** + * @test + */ + public function shouldLoadCollection() + { + $repository = $this->getRepositoryWithMockedHttpClient(); + + $repository->loadCollection(); + } + + /** + * @test + */ + public function shouldGetFactory() + { + $repository = $this->getRepositoryWithMockedHttpClient(); + + $this->assertInstanceOf('Tmdb\Factory\JobsFactory', $repository->getFactory()); + } + + protected function getApiClass() + { + return 'Tmdb\Api\Jobs'; + } + + protected function getRepositoryClass() + { + return 'Tmdb\Repository\JobsRepository'; + } +} \ No newline at end of file diff --git a/test/Tmdb/Tests/Resources/jobs/list.json b/test/Tmdb/Tests/Resources/jobs/list.json new file mode 100644 index 00000000..e5d0a05a --- /dev/null +++ b/test/Tmdb/Tests/Resources/jobs/list.json @@ -0,0 +1,392 @@ +{ + "jobs": [ + { + "department": "Writing", + "job_list": [ + "Screenplay", + "Author", + "Novel", + "Characters", + "Theatre Play", + "Adaptation", + "Dialogue", + "Writer", + "Other", + "Storyboard", + "Original Story", + "Scenario Writer", + "Screenstory", + "Musical", + "Idea", + "Story", + "Creative Producer", + "Teleplay", + "Texte", + "Opera", + "Co-Writer" + ] + }, + { + "department": "Directing", + "job_list": [ + "Director", + "Script Supervisor", + "Other", + "Layout", + "Script Coordinator", + "Special Guest Director" + ] + }, + { + "department": "Actors", + "job_list": [ + "Actor", + "Stunt Double", + "Voice", + "Cameo", + "Special Guest" + ] + }, + { + "department": "Camera", + "job_list": [ + "Director of Photography", + "Underwater Camera", + "Camera Operator", + "Still Photographer", + "Camera Department Manager", + "Camera Supervisor", + "Camera Technician", + "Other", + "Grip", + "Steadicam Operator", + "Additional Camera", + "Camera Intern", + "Additional Photography", + "Helicopter Camera" + ] + }, + { + "department": "Editing", + "job_list": [ + "Editor", + "Supervising Film Editor", + "Additional Editing", + "Editorial Manager", + "First Assistant Editor", + "Additional Editorial Assistant", + "Editorial Coordinator", + "Editorial Production Assistant", + "Editorial Services", + "Dialogue Editor", + "Archival Footage Coordinator", + "Archival Footage Research", + "Color Timer", + "Digital Intermediate", + "Other" + ] + }, + { + "department": "Art", + "job_list": [ + "Production Design", + "Art Direction", + "Set Decoration", + "Set Designer", + "Conceptual Design", + "Interior Designer", + "Settings", + "Assistant Art Director", + "Art Department Coordinator", + "Other", + "Art Department Manager", + "Sculptor", + "Art Department Assistant", + "Background Designer", + "Co-Art Director", + "Set Decoration Buyer", + "Production Illustrator", + "Standby Painter", + "Location Scout", + "Leadman", + "Greensman", + "Gun Wrangler", + "Construction Coordinator", + "Construction Foreman", + "Lead Painter", + "Sign Painter" + ] + }, + { + "department": "Costume & Make-Up", + "job_list": [ + "Costume Design", + "Makeup Artist", + "Hairstylist", + "Set Dressing Artist", + "Set Dressing Supervisor", + "Set Dressing Manager", + "Set Dressing Production Assistant", + "Facial Setup Artist", + "Hair Setup", + "Costume Supervisor", + "Set Costumer", + "Makeup Department Head", + "Wigmaker", + "Maske", + "Shoe Design", + "Other", + "Co-Costume Designer" + ] + }, + { + "department": "Production", + "job_list": [ + "Producer", + "Executive Producer", + "Casting", + "Production Manager", + "Unit Production Manager", + "Line Producer", + "Location Manager", + "Other", + "Production Supervisor", + "Production Accountant", + "Production Office Coordinator", + "Finance", + "Executive Consultant", + "Character Technical Supervisor", + "Development Manager", + "Administration", + "Executive In Charge Of Post Production", + "Herstellungsleitung", + "Produzent", + "Production Director", + "Executive In Charge Of Production", + "Publicist" + ] + }, + { + "department": "Sound", + "job_list": [ + "Original Music Composer", + "Sound Designer", + "Sound Editor", + "Sound Director", + "Sound mixer", + "Music Editor", + "Sound Effects Editor", + "Production Sound Mixer", + "Additional Soundtrack", + "Supervising Sound Editor", + "Supervising Sound Effects Editor", + "Sound Re-Recording Mixer", + "Recording Supervision", + "Boom Operator", + "Sound Montage Associate", + "Songs", + "Music", + "ADR & Dubbing", + "Sound Engineer", + "Foley", + "Additional Music Supervisor", + "First Assistant Sound Editor", + "Scoring Mixer", + "Dolby Consultant", + "Tonbearbeitung", + "Other" + ] + }, + { + "department": "Visual Effects", + "job_list": [ + "Animation", + "Visual Effects", + "Chief Technician / Stop-Motion Expert", + "Creature Design", + "Shading", + "Modeling", + "CG Painter", + "Visual Development", + "Animation Manager", + "Animation Director", + "Fix Animator", + "Animation Department Coordinator", + "Animation Fix Coordinator", + "Animation Production Assistant", + "Visual Effects Supervisor", + "Mechanical & Creature Designer", + "Battle Motion Coordinator", + "Animation Supervisor", + "VFX Supervisor", + "Cloth Setup", + "VFX Artist", + "CG Engineer", + "24 Frame Playback", + "Imaging Science", + "I/O Supervisor", + "Visual Effects Producer", + "VFX Production Coordinator", + "I/O Manager", + "Additional Effects Development", + "Color Designer", + "Simulation & Effects Production Assistant", + "Simulation & Effects Artist" + ] + }, + { + "department": "Crew", + "job_list": [ + "Special Effects", + "Post Production Supervisor", + "Second Unit", + "Choreographer", + "Stunts", + "Sound Recordist", + "Stunt Coordinator", + "Special Effects Coordinator", + "Supervising Technical Director", + "Supervising Animator", + "Production Artist", + "Sequence Leads", + "Second Film Editor", + "Temp Music Editor", + "Temp Sound Editor", + "Sequence Supervisor", + "Software Team Lead", + "Software Engineer", + "Documentation & Support", + "Machinist", + "Photoscience Manager", + "Department Administrator", + "Schedule Coordinator", + "Supervisor of Production Resources", + "Production Office Assistant", + "Information Systems Manager", + "Systems Administrators & Support", + "Projection", + "Post Production Assistant", + "Sound Design Assistant", + "Mix Technician", + "Motion Actor", + "Sets & Props Supervisor", + "Compositors", + "Tattooist", + "Sets & Props Artist", + "Motion Capture Artist", + "Sequence Artist", + "Mixing Engineer", + "Special Sound Effects", + "Post-Production Manager", + "Dialect Coach", + "Picture Car Coordinator", + "Property Master", + "Cableman", + "Set Production Assistant", + "Video Assist Operator", + "Unit Publicist", + "Set Medic", + "Stand In", + "Transportation Coordinator", + "Transportation Captain", + "Supervising Art Director", + "Art Direction", + "Stunts Coordinator", + "Post Production Consulting", + "Production Intern", + "Utility Stunts", + "Actor's Assistant", + "Set Production Intern", + "Production Controller", + "Studio Teachers", + "Chef", + "Craft Service", + "Scenic Artist", + "Propmaker", + "Prop Maker", + "Transportation Co-Captain", + "Driver", + "Security", + "Second Unit Cinematographer", + "Loader", + "Manager of Operations", + "Quality Control Supervisor", + "Legal Services", + "Public Relations", + "Score Engineer", + "Translator", + "Title Graphics", + "Telecine Colorist", + "Comic-Zeichner", + "Unit Production Manager", + "Unit Production Manager", + "Animatronic and Prosthetic Effects", + "Martial Arts Choreographer", + "Cinematography", + "Steadycam", + "Regieassistenz", + "Executive Visual Effects Producer", + "Visual Effects Design Consultant", + "Digital Effects Supervisor", + "Digital Producer", + "CG Supervisor", + "Visual Effects Art Director", + "Visual Effects Editor", + "executive in charge of Finance", + "Associate Choreographer", + "Makeup Effects", + "Maskenbildner", + "Redaktion", + "treatment", + "Dramaturgie", + "Lighting Camera", + "Technical Supervisor", + "CGI Supervisor", + "Creative Consultant", + "Script", + "Executive Music Producer", + "Tongestaltung", + "Commissioning Editor", + "Klimatechnik", + "Tiertrainer", + "Additional Writing", + "Additional Music", + "Poem", + "Thanks", + "Szenografie", + "Mischung", + "Titelgestaltung", + "Musikmischung", + "Comic-Zeichner", + "Creator", + "Additional Dialogue", + "Video Game", + "Graphic Novel Illustrator", + "Other", + "Series Writer", + "Radio Play" + ] + }, + { + "department": "Lighting", + "job_list": [ + "Lighting Technician", + "Best Boy Electric", + "Gaffer", + "Lighting Technician", + "Rigging Gaffer", + "Lighting Supervisor", + "Lighting Manager", + "Directing Lighting Artist", + "Master Lighting Artist", + "Lighting Artist", + "Lighting Coordinator", + "Lighting Production Assistant", + "Best Boy Electrician", + "Electrician", + "Rigging Grip", + "Other" + ] + } + ] +} \ No newline at end of file