Skip to content

Commit

Permalink
Refactoring Movie to actually contain the correct model of changes
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfzdotnet committed Feb 8, 2014
1 parent 04ecef8 commit d4e5d7d
Show file tree
Hide file tree
Showing 6 changed files with 303 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Unstable

I'm working extensively on finishing the models/repositories/factories, which should allow you to simply jump in with an API key and implement quickly.

Do expect changes to happen a few times per week until the work is done, however structurally seen things will be built further upon the current base.
You can see the current state [here](PROGRESS.MD).

Help & Donate
--------------
Expand Down
4 changes: 2 additions & 2 deletions examples/movies/model/all.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@
echo "Cast<br/>";

foreach($movie->getCredits()->getCast() as $person) {
echo $imageHelper->getHtml($person->getProfile(), 'w45');
echo $imageHelper->getHtml($person->getProfileImage(), 'w45');
printf(" - %s as %s<br/>", $person->getName(), $person->getCharacter());
}

echo "Crew<br/>";

foreach($movie->getCredits()->getCrew() as $person) {
echo $imageHelper->getHtml($person->getProfile(), 'w45');
echo $imageHelper->getHtml($person->getProfileImage(), 'w45');
printf(" - %s as %s<br/>", $person->getName(), $person->getJob());
}

Expand Down
71 changes: 71 additions & 0 deletions lib/Tmdb/Factory/Common/ChangeFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?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\Common;

use Tmdb\Factory\AbstractFactory;
use Tmdb\Model\Common\Change;
use Tmdb\Model\Common\GenericCollection;

class ChangeFactory extends AbstractFactory
{
/**
* {@inheritdoc}
*/
public function create(array $data = array())
{
$change = new Change();

if (array_key_exists('items', $data)) {
$items = new GenericCollection();

foreach($data['items'] as $item) {
$item = $this->createChangeItem($item);

$items->add(null, $item);
}

$change->setItems($items);
}

return $this->hydrate($change, $data);
}

/**
* Create individual change items
*
* @param array $data
* @return \Tmdb\Model\AbstractModel
*/
private function createChangeItem(array $data = array())
{
return $this->hydrate(new Change\Item(), $data);
}

/**
* {@inheritdoc}
*/
public function createCollection(array $data = array())
{
$collection = new GenericCollection();

if (array_key_exists('changes', $data)) {
$data = $data['changes'];
}

foreach($data as $item) {
$collection->add(null, $this->create($item));
}

return $collection;
}
}
36 changes: 30 additions & 6 deletions lib/Tmdb/Factory/MovieFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
namespace Tmdb\Factory;

use Tmdb\Factory\Common\ChangeFactory;
use Tmdb\Factory\People\CastFactory;
use Tmdb\Factory\People\CrewFactory;
use Tmdb\Model\Common\GenericCollection;
Expand Down Expand Up @@ -40,15 +41,21 @@ class MovieFactory extends AbstractFactory {
*/
private $imageFactory;

/**
* @var ChangeFactory
*/
private $changeFactory;

/**
* Constructor
*/
public function __construct()
{
$this->castFactory = new CastFactory();
$this->crewFactory = new CrewFactory();
$this->genreFactory = new GenreFactory();
$this->imageFactory = new ImageFactory();
$this->castFactory = new CastFactory();
$this->crewFactory = new CrewFactory();
$this->genreFactory = new GenreFactory();
$this->imageFactory = new ImageFactory();
$this->changeFactory = new ChangeFactory();
}

/**
Expand Down Expand Up @@ -126,8 +133,9 @@ public function create(array $data = array())
// if (array_key_exists('lists', $data)) {
// }

// if (array_key_exists('changes', $data)) {
// }
if (array_key_exists('changes', $data)) {
$movie->setChanges($this->getChangeFactory()->createCollection($data['changes']));
}

return $this->hydrate($movie, $data);
}
Expand Down Expand Up @@ -222,5 +230,21 @@ public function getImageFactory()
return $this->imageFactory;
}

/**
* @param \Tmdb\Factory\Common\ChangeFactory $changeFactory
* @return $this
*/
public function setChangeFactory($changeFactory)
{
$this->changeFactory = $changeFactory;
return $this;
}

/**
* @return \Tmdb\Factory\Common\ChangeFactory
*/
public function getChangeFactory()
{
return $this->changeFactory;
}
}
75 changes: 75 additions & 0 deletions lib/Tmdb/Model/Common/Change.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?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\Common;

use Tmdb\Model\AbstractModel;

class Change extends AbstractModel {

/**
* @var string
*/
private $key;

/**
* @var GenericCollection
*/
private $items;

public static $_properties = array(
'key',
);

public function __construct()
{
$this->items = new GenericCollection();
}

/**
* @param \Tmdb\Model\Common\GenericCollection $items
* @return $this
*/
public function setItems($items)
{
$this->items = $items;
return $this;
}

/**
* @return \Tmdb\Model\Common\GenericCollection
*/
public function getItems()
{
return $this->items;
}

/**
* @param string $key
* @return $this
*/
public function setKey($key)
{
$this->key = $key;
return $this;
}

/**
* @return string
*/
public function getKey()
{
return $this->key;
}


}
124 changes: 124 additions & 0 deletions lib/Tmdb/Model/Common/Change/Item.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?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\Common\Change;

use Tmdb\Model\AbstractModel;

class Item extends AbstractModel {

/**
* @var string
*/
private $id;

/**
* @var string
*/
private $action;

/**
* @var \DateTime
*/
private $time;

/**
* @var array
*/
private $value;

public static $_properties = array(
'id',
'action',
'time',
'value'
);

/**
* @param string $action
* @return $this
*/
public function setAction($action)
{
$this->action = $action;
return $this;
}

/**
* @return string
*/
public function getAction()
{
return $this->action;
}

/**
* @param string $id
* @return $this
*/
public function setId($id)
{
$this->id = $id;
return $this;
}

/**
* @return string
*/
public function getId()
{
return $this->id;
}

/**
* @param string|\DateTime $time
* @return $this
*/
public function setTime($time)
{
if (!$time instanceof \DateTime) {
$time = new \DateTime($time);
}

$this->time = $time;
return $this;
}

/**
* @return \DateTime
*/
public function getTime()
{
return $this->time;
}

/**
* @param array $value
* @return $this
*/
public function setValue($value)
{
$this->value = $value;
return $this;
}

/**
* @return array
*/
public function getValue()
{
return $this->value;
}



}

0 comments on commit d4e5d7d

Please sign in to comment.