Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/Collection/AbstractTitleCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,18 @@ public function hasCustomFields()
return false;
}

/**
* Determine if all items in the collection are fully hydrated
*
* @return bool
*/
public function isHydrated()
{
return $this->reduce(function ($carry, $item) {
return $carry && $item->hydrated;
}, true);
}

/**
* {@inheritdoc}
*/
Expand Down
4 changes: 3 additions & 1 deletion src/Hydrator/AbstractHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,7 @@ public function preload(array $entryIds)
/**
* {@inheritdoc}
*/
abstract public function hydrate(AbstractEntity $entity, AbstractProperty $property);
public function hydrate(AbstractEntity $entity, AbstractProperty $property) {
$entity->hydrated = true;
}
}
2 changes: 2 additions & 0 deletions src/Hydrator/AssetsHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ public function preload(array $entryIds)
*/
public function hydrate(AbstractEntity $entity, AbstractProperty $property)
{
parent::hydrate($entity, $property);

if (isset($this->selections[$entity->getType()][$entity->getId()][$property->getId()])) {
$value = $this->selections[$entity->getType()][$entity->getId()][$property->getId()];
} else {
Expand Down
2 changes: 2 additions & 0 deletions src/Hydrator/DateHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class DateHydrator extends AbstractHydrator
*/
public function hydrate(AbstractEntity $entity, AbstractProperty $property)
{
parent::hydrate($entity, $property);

$value = $entity->getAttribute($property->getIdentifier());

$value = $value ? Carbon::createFromFormat('U', $value) : null;
Expand Down
2 changes: 2 additions & 0 deletions src/Hydrator/ExplodeHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class ExplodeHydrator extends AbstractHydrator
*/
public function hydrate(AbstractEntity $entity, AbstractProperty $property)
{
parent::hydrate($entity, $property);

$value = $entity->getAttribute($property->getIdentifier());

$value = $value ? explode("\n", $value) : null;
Expand Down
2 changes: 2 additions & 0 deletions src/Hydrator/FileHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ public function preload(array $entryIds)
*/
public function hydrate(AbstractEntity $entity, AbstractProperty $property)
{
parent::hydrate($entity, $property);

$value = $entity->getAttribute($property->getIdentifier());

$value = $value && isset($this->files[$value]) ? $this->files[$value] : null;
Expand Down
2 changes: 2 additions & 0 deletions src/Hydrator/GridHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ public function preload(array $entryIds)
*/
public function hydrate(AbstractEntity $entity, AbstractProperty $property)
{
parent::hydrate($entity, $property);

$value = isset($this->sortedRows[$entity->getId()][$property->getId()]) ? $this->sortedRows[$entity->getId()][$property->getId()] : new GridRowCollection();

$entity->setAttribute($property->getName(), $value);
Expand Down
2 changes: 2 additions & 0 deletions src/Hydrator/MatrixHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ public function preload(array $entryIds)
*/
public function hydrate(AbstractEntity $entity, AbstractProperty $property)
{
parent::hydrate($entity, $property);

$value = isset($this->sortedRows[$entity->getId()][$property->getId()]) ? $this->sortedRows[$entity->getId()][$property->getId()] : new MatrixRowCollection();

$entity->setAttribute($property->getName(), $value);
Expand Down
2 changes: 2 additions & 0 deletions src/Hydrator/ParentsHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public function __construct(ConnectionInterface $db, EntryCollection $collection
*/
public function hydrate(AbstractEntity $entity, AbstractProperty $property)
{
parent::hydrate($entity, $property);

$entries = isset($this->entries[$entity->getId()]) ? $this->entries[$entity->getId()] : array();

$value = $this->relationshipCollection->createChildCollection($entries);
Expand Down
2 changes: 2 additions & 0 deletions src/Hydrator/PipeHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class PipeHydrator extends AbstractHydrator
*/
public function hydrate(AbstractEntity $entity, AbstractProperty $property)
{
parent::hydrate($entity, $property);

$value = $entity->getAttribute($property->getIdentifier());

$value = $value ? explode("|", $value) : null;
Expand Down
2 changes: 2 additions & 0 deletions src/Hydrator/PlayaHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public function __construct(ConnectionInterface $db, EntryCollection $collection
*/
public function hydrate(AbstractEntity $entity, AbstractProperty $property)
{
parent::hydrate($entity, $property);

$entries = isset($this->entries[$entity->getType()][$entity->getId()][$property->getId()])
? $this->entries[$entity->getType()][$entity->getId()][$property->getId()] : array();

Expand Down
2 changes: 2 additions & 0 deletions src/Hydrator/RelationshipHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public function __construct(ConnectionInterface $db, EntryCollection $collection
*/
public function hydrate(AbstractEntity $entity, AbstractProperty $property)
{
parent::hydrate($entity, $property);

$entries = isset($this->entries[$entity->getType()][$entity->getId()][$property->getId()])
? $this->entries[$entity->getType()][$entity->getId()][$property->getId()] : array();

Expand Down
2 changes: 2 additions & 0 deletions src/Hydrator/SiblingsHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public function __construct(ConnectionInterface $db, EntryCollection $collection
*/
public function hydrate(AbstractEntity $entity, AbstractProperty $property)
{
parent::hydrate($entity, $property);

$value = isset($this->entries[$entity->getId()]) ? $this->entries[$entity->getId()] : array();

$value = $this->relationshipCollection->createChildCollection($entries);
Expand Down
2 changes: 2 additions & 0 deletions src/Hydrator/WysiwygHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public function __construct(ConnectionInterface $db, EntryCollection $collection
*/
public function hydrate(AbstractEntity $entity, AbstractProperty $property)
{
parent::hydrate($entity, $property);

$value = $this->parse($entity->getAttribute($property->getIdentifier()));

$entity->setAttribute($property->getName(), $value);
Expand Down
7 changes: 7 additions & 0 deletions src/Model/AbstractEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
*/
abstract class AbstractEntity extends Model
{

/**
* Entity hydration state
* @var bool
*/
protected $hydrated = false;

/**
* Get the entity ID (eg. entry_id or row_id)
* @return string|int
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function newCollection(array $models = array())

$collection = call_user_func($method, $models, self::$channelRepository, self::$fieldRepository);

if ($models) {
if ($models && !$collection->isHydrated()) {
$this->hydrateCollection($collection);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Model/Title.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public function newCollection(array $models = array())

/**
* Loop through all the hydrators to set Entry custom field attributes
* @param \rsanchez\Deep\Collection\TitleCollection $collection
* @param \rsanchez\Deep\Collection\AbstractTitleCollection $collection
* @return void
*/
public function hydrateCollection(AbstractTitleCollection $collection)
Expand Down