File: D:/HostingSpaces/SBogers10/kooken.komma.pro/app/Components/ComponentArea/ComponentAreaSaveState.php
<?php
namespace App\Components\ComponentArea;
use App\Components\Component\ComponentSaveState;
/**
* Class DynamicGroupsSectionSaveState
*
* Represents data that can be saved and loaded for a component area.
* the same as its javascript twin.
*
* @package App\Components\Components
*/
class ComponentAreaSaveState implements \JsonSerializable
{
/**
* @var ComponentSaveState[]
*/
private $componentSaveStates;
public function __construct()
{
$this->componentSaveStates = [];
}
/**
* Specify data which should be serialized to JSON
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php
* @return mixed data which can be serialized by <b>json_encode</b>,
* which is a value of any type other than a resource.
* @since 5.4.0
*/
public function jsonSerialize()
{
return $this->componentSaveStates;
}
/**
* @param string $json
* @return ComponentAreaSaveState
*/
public static function fromJsonString(string $json)
{
$dataArray = json_decode($json, true);
if($dataArray === null) throw new \InvalidArgumentException('DynamicGroupsSectionSaveState:fromString The given data string could not be decoded since it was no json string');
$instance = new self;
$componentAreaCount = count($dataArray);
for($index = 0; $index < $componentAreaCount; $index++)
{
$currentDynamicGroupSaveStateArray = $dataArray[$index];
$currentDynamicGroupSaveState = ComponentSaveState::fromArray($currentDynamicGroupSaveStateArray);
$instance->componentSaveStates[] = $currentDynamicGroupSaveState;
}
return $instance;
}
/**
* @param ComponentSaveState $dynamicGroupSaveState
*/
public function addComponentSaveState(ComponentSaveState $dynamicGroupSaveState)
{
$this->componentSaveStates[] = $dynamicGroupSaveState;
}
/**
* @param int $index
* @return ComponentSaveState|mixed
*/
public function getComponentSaveStateAt(int $index)
{
return $this->componentSaveStates[$index];
}
/**
* @return int
*/
public function getComponentsCount()
{
return count($this->componentSaveStates);
}
/**
* @return ComponentSaveState[]|array
*/
public function getComponentSaveStates()
{
return $this->componentSaveStates;
}
/**
* @return int
*/
public function getHighestComponentSortOrder(): int
{
$highest = 0;
foreach($this->getComponentSaveStates() as $componentSaveState) {
/** @var ComponentSaveState $componentSaveState*/
if($componentSaveState->getSortOrder() > $highest) $highest = $componentSaveState->getSortOrder();
}
return $highest;
}
}