get('answers'); if (!$raw) return []; return json_decode($raw, true) ?? []; } /** * Enregistre un tableau de réponses en JSON. */ public function setAnswersArray(array $answers): void { $this->set('answers', json_encode($answers, JSON_UNESCAPED_UNICODE)); } /** * Retourne les données optionnelles sous forme de tableau PHP. */ public function getOptionalArray(): array { $raw = $this->get('optional_data'); if (!$raw) return []; return json_decode($raw, true) ?? []; } public function setOptionalArray(array $optional): void { $this->set('optional_data', json_encode($optional, JSON_UNESCAPED_UNICODE)); } /** * Retourne le résultat calculé sous forme de tableau PHP. */ public function getResultArray(): array { $raw = $this->get('result'); if (!$raw) return []; return json_decode($raw, true) ?? []; } public function setResultArray(array $result): void { $this->set('result', json_encode($result, JSON_UNESCAPED_UNICODE)); } /** * Met à jour updated_at automatiquement avant chaque save(). */ public function save($cacheFlag = null): bool { $now = (new \DateTime())->format('Y-m-d H:i:s'); if (!$this->get('created_at')) { $this->set('created_at', $now); } $this->set('updated_at', $now); return parent::save($cacheFlag); } }