Save answers.
[platal.git] / modules / survey / survey.inc.php
index 3812d2e..7e715fd 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2010 Polytechnique.org                              *
+ *  Copyright (C) 2003-2011 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -104,6 +104,12 @@ class Survey extends PlDBTableEntry implements SurveyQuestionContainer
         }
     }
 
+    public function clearQuestions()
+    {
+        $this->fetchQuestions = true;
+        $this->questions = array();
+    }
+
     public function addQuestion(SurveyQuestion $question, $pos = null)
     {
         $question->parent = null;
@@ -156,13 +162,24 @@ class Survey extends PlDBTableEntry implements SurveyQuestionContainer
     public function export()
     {
         $export = parent::export();
-        $export['questions'] = array();
+        $export['questions'] = $this->exportQuestions();
+        return $export;
+    }
+
+    public function exportQuestions()
+    {
+        $export = array();
         foreach ($this->questions as $question) {
-            $export['questions'][] = $question->export();
+            $export[] = $question->export();
         }
         return $export;
     }
 
+    public function exportQuestionsToJSON()
+    {
+        return json_encode($this->exportQuestions());
+    }
+
     /* Return an indicator of the progression of the survey:
      *  negative values means 'the survey is not started'
      *  0 means 'the survey is in progress'