-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #144 from tigranmaestro/master
Fix & Update `template` Examples (Part 2)
- Loading branch information
Showing
9 changed files
with
366 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
namespace Renderforest\Template\Duration\Collection; | ||
|
||
use Renderforest\Base\CollectionBase; | ||
use Renderforest\Template\Duration\Duration; | ||
|
||
/** | ||
* Class DurationCollection | ||
* @package Renderforest\Template\Duration\Collection | ||
*/ | ||
class DurationCollection extends CollectionBase | ||
{ | ||
/** | ||
* @var Duration[] | ||
*/ | ||
private $durations; | ||
|
||
/** | ||
* @var Duration[] | ||
*/ | ||
private $durationsAssocArray; | ||
|
||
/** | ||
* DurationCollection constructor. | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->durations = []; | ||
$this->durationsAssocArray = []; | ||
|
||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* @param Duration $duration | ||
* @return DurationCollection | ||
*/ | ||
private function add(Duration $duration): DurationCollection | ||
{ | ||
$this->iteratorItems[] = $duration; | ||
$this->durations[] = $duration; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @param string $durationCollectionJson | ||
*/ | ||
public function exchangeJson(string $durationCollectionJson) | ||
{ | ||
$durationCollectionArrayData = json_decode($durationCollectionJson, true); | ||
|
||
$durationCollectionArrayData = $durationCollectionArrayData['data']; | ||
|
||
$this->exchangeArray($durationCollectionArrayData); | ||
} | ||
|
||
/** | ||
* @param array $durationCollectionArrayData | ||
*/ | ||
public function exchangeArray(array $durationCollectionArrayData) | ||
{ | ||
foreach ($durationCollectionArrayData as $durationArrayData) { | ||
$duration = new Duration(); | ||
$duration->exchangeArray($durationArrayData); | ||
|
||
$this->add($duration); | ||
} | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getArrayCopy(): array | ||
{ | ||
$arrayCopy = []; | ||
|
||
foreach ($this->durations as $duration) { | ||
$arrayCopy[] = $duration->getArrayCopy(); | ||
} | ||
|
||
return $arrayCopy; | ||
} | ||
} |
Oops, something went wrong.