Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
question.php
1<?php
3
11
13{
14 private $resetVotingResult = true;
15
16 public function setResetVotingResult(bool $bool): void
17 {
18 $this->resetVotingResult = $bool;
19 }
20
24 private $answerCopier = null;
25
30 public function setAnswerCopier(EntityCopier $answerCopier): void
31 {
32 $this->answerCopier = $answerCopier;
33 }
34
43 public function add(Container $container, array $fields)
44 {
45 $result = QuestionTable::add($fields);
46 if ($result->isSuccess())
47 {
48 return $result->getId();
49 }
50 else
51 {
52 $this->result->addErrors($result->getErrors());
53 return false;
54 }
55 }
56
67 public function getFields(Container $container, $entityId)
68 {
69 $queryObject = QuestionTable::getById($entityId);
70 return (($fields = $queryObject->fetch()) ? $fields : []);
71 }
72
80 public function prepareFieldsToCopy(Container $container, array $fields)
81 {
82 unset($fields["ID"]);
83
84 $fields["FIELD_TYPE"] = (int) $fields["FIELD_TYPE"];
85
86 if ($container->getParentId())
87 {
88 $fields["VOTE_ID"] = $container->getParentId();
89 }
90
91 if ($this->resetVotingResult)
92 {
93 unset($fields["COUNTER"]);
94 }
95
96 return $fields;
97 }
98
107 public function copyChildren(Container $container, $entityId, $copiedEntityId)
108 {
109 $results = [];
110
111 $results[] = $this->copyAnswer($entityId, $copiedEntityId);
112
113 return $this->getResult($results);
114 }
115
116 private function copyAnswer(int $questionId, int $copiedQuestionId)
117 {
118 if (!$this->answerCopier)
119 {
120 return new Result();
121 }
122
123 $containerCollection = new ContainerCollection();
124 $queryObject = AnswerTable::getList(["order" => [], "filter" => ["QUESTION_ID" => $questionId]]);
125 while ($question = $queryObject->fetch())
126 {
127 $container = new Container($question["ID"]);
128 $container->setParentId($copiedQuestionId);
129 $containerCollection[] = $container;
130 }
131
132 if (!$containerCollection->isEmpty())
133 {
134 return $this->answerCopier->copy($containerCollection);
135 }
136
137 return new Result();
138 }
139}
setAnswerCopier(EntityCopier $answerCopier)
Definition question.php:30
getFields(Container $container, $entityId)
Definition question.php:67
add(Container $container, array $fields)
Definition question.php:43
copyChildren(Container $container, $entityId, $copiedEntityId)
Definition question.php:107
prepareFieldsToCopy(Container $container, array $fields)
Definition question.php:80