teamDtoList)) { foreach ($this->teamDtoList as $teamDto) { $teamList[] = $teamDto->toArray(); } } if (!empty($this->facilityDtoList)) { foreach ($this->facilityDtoList as $facilityDto) { $facilityList[] = $facilityDto->toArray(); } } return [ 'id' => $this->id ?? null, 'dateStart' => !empty($this->dateStart) ? $this->dateStart->format('Y-m'): null, 'leagueId' => $this->leagueId ?? null, 'teamList' => $teamList, 'facilityList' => $facilityList, 'active' => $this->active ?? null ]; } public function fillFromArray(array $dataList): void { if (isset($dataList['id'])) { $this->id = (int) $dataList['id']; } if (!empty($dataList['dateStart'])) { $dateStart = \DateTime::createFromFormat('Y-m' ,$dataList['dateStart']); if ($dateStart) { $this->dateStart = $dateStart; } } if (isset($dataList['active'])) { $this->active = $dataList['active']; } if (isset($dataList['teamList'])) { foreach ($dataList['teamList'] as $teamName) { $teamDto = new TeamDto(); $teamDto->name = $teamName; $this->teamDtoList[] = $teamDto; } } if (!empty($dataList['facilityList'])) { foreach ($dataList['facilityList'] as $facilityItem) { $facilityDto = new FacilityDto(); $facilityDto->fillFromArray($facilityItem); $this->facilityDtoList[] = $facilityDto; } } if (isset($dataList['gameList'])) { foreach ($dataList['gameList'] as $gameItem) { $gameDto = new GameDto(); $gameDto->fillFromArray($gameItem); $this->gameDtoList[] = $gameDto; } } } public function fillFromObject(Season $seasonObj): void { if ($seasonObj->getId() !== null) { $this->id = $seasonObj->getId(); } if ($seasonObj->getDateStart() !== null) { $this->dateStart = $seasonObj->getDateStart(); } $leagueObj = $seasonObj->getLeague(); if ($leagueObj !== null) { $this->leagueId = $leagueObj->getId(); } if ($leagueObj->isActive() !== null) { $this->active = $leagueObj->isActive(); } } /** * @throws ValidationException */ public function validate(): void { if (!empty($this->validationErrors)) { throw new ValidationException($this->validationErrors); } } }