/** * @param array $answers * @param int $pollId * * @return bool|int */ public function saveAnswers(array $answers, $pollId) { $bool = false; foreach ($answers as $row) { if (empty($row['id'])) { if (!empty($row['text']) && !isset($row['delete'])) { $data = ['text' => $this->secure->strEncode($row['text']), 'poll_id' => $pollId]; $bool = $this->answerRepository->insert($data); } } elseif (isset($row['delete'])) { $this->answerRepository->delete((int) $row['id']); } elseif (!empty($row['text'])) { $data = ['text' => $this->secure->strEncode($row['text'])]; $bool = $this->answerRepository->update($data, (int) $row['id']); } } return $bool; }