| @@ 13-65 (lines=53) @@ | ||
| 10 | * |
|
| 11 | * @author Jacob Bare <[email protected]> |
|
| 12 | */ |
|
| 13 | class HasMany extends Attributes |
|
| 14 | { |
|
| 15 | /** |
|
| 16 | * Extended to also check for dirty states of has-many Collections. |
|
| 17 | * |
|
| 18 | * {@inheritDoc} |
|
| 19 | */ |
|
| 20 | public function areDirty() |
|
| 21 | { |
|
| 22 | if (true === parent::areDirty()) { |
|
| 23 | return true; |
|
| 24 | } |
|
| 25 | foreach ($this->getOriginalAll() as $collection) { |
|
| 26 | if (true === $collection->isDirty()) { |
|
| 27 | return true; |
|
| 28 | } |
|
| 29 | } |
|
| 30 | return false; |
|
| 31 | } |
|
| 32 | ||
| 33 | /** |
|
| 34 | * Extended to also rollback changes of has-many collections. |
|
| 35 | * |
|
| 36 | * {@inheritDoc} |
|
| 37 | */ |
|
| 38 | public function rollback() |
|
| 39 | { |
|
| 40 | parent::rollback(); |
|
| 41 | foreach ($this->getOriginalAll() as $collection) { |
|
| 42 | if ($collection instanceof EmbedCollection) { |
|
| 43 | $collection->rollback(); |
|
| 44 | } |
|
| 45 | } |
|
| 46 | return $this; |
|
| 47 | } |
|
| 48 | ||
| 49 | /** |
|
| 50 | * Overwritten to account for collection change sets. |
|
| 51 | * |
|
| 52 | * {@inheritDoc} |
|
| 53 | */ |
|
| 54 | public function calculateChangeSet() |
|
| 55 | { |
|
| 56 | $set = []; |
|
| 57 | foreach ($this->getOriginalAll() as $key => $collection) { |
|
| 58 | if (false === $collection->isDirty()) { |
|
| 59 | continue; |
|
| 60 | } |
|
| 61 | $set[$key] = $collection->calculateChangeSet(); |
|
| 62 | } |
|
| 63 | return $set; |
|
| 64 | } |
|
| 65 | } |
|
| 66 | ||
| @@ 13-65 (lines=53) @@ | ||
| 10 | * |
|
| 11 | * @author Jacob Bare <[email protected]> |
|
| 12 | */ |
|
| 13 | class HasMany extends Properties |
|
| 14 | { |
|
| 15 | /** |
|
| 16 | * Extended to also check for dirty states of has-many Collections. |
|
| 17 | * |
|
| 18 | * {@inheritDoc} |
|
| 19 | */ |
|
| 20 | public function areDirty() |
|
| 21 | { |
|
| 22 | if (true === parent::areDirty()) { |
|
| 23 | return true; |
|
| 24 | } |
|
| 25 | foreach ($this->getOriginalAll() as $collection) { |
|
| 26 | if (true === $collection->isDirty()) { |
|
| 27 | return true; |
|
| 28 | } |
|
| 29 | } |
|
| 30 | return false; |
|
| 31 | } |
|
| 32 | ||
| 33 | /** |
|
| 34 | * Extended to also rollback changes of has-many collections. |
|
| 35 | * |
|
| 36 | * {@inheritDoc} |
|
| 37 | */ |
|
| 38 | public function rollback() |
|
| 39 | { |
|
| 40 | parent::rollback(); |
|
| 41 | foreach ($this->getOriginalAll() as $collection) { |
|
| 42 | if ($collection instanceof Collection) { |
|
| 43 | $collection->rollback(); |
|
| 44 | } |
|
| 45 | } |
|
| 46 | return $this; |
|
| 47 | } |
|
| 48 | ||
| 49 | /** |
|
| 50 | * Overwritten to account for collection change sets. |
|
| 51 | * |
|
| 52 | * {@inheritDoc} |
|
| 53 | */ |
|
| 54 | public function calculateChangeSet() |
|
| 55 | { |
|
| 56 | $set = []; |
|
| 57 | foreach ($this->getOriginalAll() as $key => $collection) { |
|
| 58 | if (false === $collection->isDirty()) { |
|
| 59 | continue; |
|
| 60 | } |
|
| 61 | $set[$key] = $collection->calculateChangeSet(); |
|
| 62 | } |
|
| 63 | return $set; |
|
| 64 | } |
|
| 65 | } |
|
| 66 | ||