Overview

Namespaces

  • rsanchez
    • Deep
      • App
        • EE
        • Laravel
          • Facade
      • Collection
      • Hydrator
      • Model
      • Plugin
      • Relations
      • Repository

Classes

  • AbstractHydrator
  • AssetsHydrator
  • DateHydrator
  • ExplodeHydrator
  • FileHydrator
  • GridHydrator
  • HydratorFactory
  • MatrixHydrator
  • ParentsHydrator
  • PipeHydrator
  • PlayaHydrator
  • RelationshipHydrator
  • SiblingsHydrator
  • WysiwygHydrator

Interfaces

  • HydratorInterface
  • Overview
  • Namespace
  • Class
  • Tree
 1: <?php
 2: 
 3: /**
 4:  * Deep
 5:  *
 6:  * @package      rsanchez\Deep
 7:  * @author       Rob Sanchez <info@robsanchez.com>
 8:  */
 9: 
10: namespace rsanchez\Deep\Hydrator;
11: 
12: use Illuminate\Database\Eloquent\Model;
13: use rsanchez\Deep\Collection\EntryCollection;
14: use rsanchez\Deep\Collection\RelationshipCollection;
15: use rsanchez\Deep\Model\AbstractProperty;
16: use rsanchez\Deep\Model\AbstractEntity;
17: use rsanchez\Deep\Hydrator\AbstractHydrator;
18: use rsanchez\Deep\Model\RelationshipEntry;
19: 
20: /**
21:  * Hydrator for the Parent Relationships
22:  */
23: class ParentsHydrator extends AbstractHydrator
24: {
25:     /**
26:      * @var \rsanchez\Deep\Model\RelationshipEntry
27:      */
28:     protected $model;
29: 
30:     /**
31:      * {@inheritdoc}
32:      */
33:     public function __construct(EntryCollection $collection, $fieldtype, RelationshipEntry $model)
34:     {
35:         parent::__construct($collection, $fieldtype);
36: 
37:         $this->model = $model;
38: 
39:         $this->relationshipCollection = $this->model->parents($collection->modelKeys())->get();
40: 
41:         foreach ($this->relationshipCollection as $entry) {
42:             if (! isset($this->entries[$entry->child_id])) {
43:                 $this->entries[$entry->child_id] = array();
44:             }
45: 
46:             $this->entries[$entry->child_id][] = $entry;
47:         }
48: 
49:         // add these entry IDs to the main collection
50:         $collection->addEntryIds($this->relationshipCollection->modelKeys());
51:     }
52: 
53:     /**
54:      * {@inheritdoc}
55:      */
56:     public function hydrate(AbstractEntity $entity, AbstractProperty $property)
57:     {
58:         $entries = isset($this->entries[$entity->getId()]) ? $this->entries[$entity->getId()] : array();
59: 
60:         $value = $this->relationshipCollection->createChildCollection($entries);
61: 
62:         $entity->setAttribute($property->getName(), $value);
63: 
64:         return $value;
65:     }
66: }
67: 
API documentation generated by ApiGen 2.8.0