private static function decode(string $data) { $qcm = null; try { //Transformation json en tableau associatif $data = json_decode($data, true); // var_dump($data); //Création des questions $questions = array(); $tmp = $data['questions']; foreach ($tmp as $value) { $question = new Question($value['enonce'], $value['multi'], $value['indice']); foreach ($value['reponses'] as $response) { $question->addReponse($response['label'], $response['correct']); } array_push($questions, $question); } //Création du qcm $qcm = new QCM(-1, $_SESSION['user']->getId(), $questions, $data['name'], $data['description'], $data['startDate'], $data['endDate']); $qcm->save(); } catch (Exception $e) { $qcm = null; } return $qcm; }
public static function getById($id) { $id = (int) $id; $db = new QCMAdapterDB(); $item = $db->findById('NoOneCareAboutHim', $id); return !is_null($item) ? new QCM($item['id'], $item['owner'], Question::loadFromDB($item['reponses']), $item['name'], $item['desc'], $item['date_start'], $item['date_end']) : null; }