17 private $resetVotingResult =
true;
21 $this->resetVotingResult = $bool;
27 private $questionCopier =
null;
35 $this->questionCopier = $questionCopier;
55 $this->result->addErrors(
$result->getErrors());
71 $queryObject = VoteTable::getById(
$entityId);
86 if ($this->resetVotingResult)
106 $results[] = $this->copyQuestion(
$entityId, $copiedEntityId);
110 if (!$this->resetVotingResult)
118 private function copyQuestion(
int $voteId,
int $copiedVoteId)
120 if (!$this->questionCopier)
127 $queryObject = QuestionTable::getList([
"filter" => [
"VOTE_ID" => $voteId]]);
128 while ($question = $queryObject->fetch())
130 $container =
new Container($question[
"ID"]);
131 $container->setParentId($copiedVoteId);
132 $containerCollection[] = $container;
135 if (!$containerCollection->isEmpty())
137 return $this->questionCopier->copy($containerCollection);
143 private function copyEvents($voteId, $copiedVoteId, Result
$result)
147 $copiedIdsRelation = $this->getCopiedIdsRelation(
$result);
148 $ballots = $this->getEventBallots($voteId, $copiedIdsRelation);
150 $voteBaseCopiedVote =
new VoteBase($copiedVoteId);
151 $eventObject =
new Event($voteBaseCopiedVote);
153 $queryObject = EventTable::getList([
"filter" => [
"VOTE_ID" => $voteId]]);
154 while (
$event = $queryObject->fetch())
156 $ballot = $ballots[
$event[
"ID"]];
159 $event[
"VOTE_ID"] = $copiedVoteId;
161 $eventObject->add(
$event, $ballot,
false);
164 catch (\Exception $exception) {}
167 private function getCopiedIdsRelation(Result
$result)
169 $copiedIdsRelation = [];
171 $resultData =
$result->getData();
172 foreach ($resultData as
$data)
174 array_walk(
$data,
function($item,
$key) use (&$copiedIdsRelation) {
177 $copiedIdsRelation[
"answer"] = $item;
181 $copiedIdsRelation[
$key] = $item;
186 return $copiedIdsRelation;
195 private function getEventBallots($voteId, $copiedIdsRelation)
201 foreach ($copiedIdsRelation as
$key => $value)
209 $answerIds = $answerIds +
$value;
213 $voteBase =
new VoteBase($voteId);
214 foreach ($voteBase->getStatistic() as
$data)
217 foreach (
$data[
"BALLOT"] as $questionId => $answer)
219 foreach ($answer as $answerId => $answerMessage)
221 $ballot[$questionIds[$questionId]] = [
222 $answerIds[$answerId] => $answerMessage
226 $ballots[
$data[
"ID"]] = [
"BALLOT" => $ballot];
getResult(array $results=[])