Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
formresponse.php
1<?php
2
4
5
10
11class FormResponse extends Result
12{
14 protected $data = [];
15
17 protected $formBuilder;
18
20 private $currentResponse;
21
23 private $responseCount;
24
29 public function __construct(FormBuilderInterface $formBuilder, Response... $responses)
30 {
31 parent::__construct();
32
33 $this->formBuilder = $formBuilder;
34 $this->currentResponse = 0;
35 $this->responseCount = count($responses);
36
37 foreach ($responses as $response)
38 {
39 if (!$response->isSuccess())
40 {
41 $this->addErrors($response->getErrors());
42 }
43 }
44
45 $this->data = array_values($responses);
46 }
47
54 public function setData(array $data): FormResponse
55 {
56 return new static($this->formBuilder,...$data);
57 }
58
62 public function fetch(): ?LeadAdsForm
63 {
64 if ($this->currentResponse >= $this->responseCount || !$this->isSuccess())
65 {
66 return null;
67 }
68
70 if (!$form = $this->data[$this->currentResponse]->fetch())
71 {
72 ++$this->currentResponse;
73
74 return $this->fetch();
75 }
76
77 return $this->formBuilder->buildForm($form);
78 }
79
83 public function fetchAll(): array
84 {
85 for($fetchResult = array(); null !== $item = $this->fetch();)
86 {
87 $fetchResult[] = $item;
88 }
89
90 return $fetchResult;
91 }
92}
addErrors(array $errors)
Definition result.php:98
__construct(FormBuilderInterface $formBuilder, Response... $responses)