public function testPieChart()
 {
     $survey = new Survey();
     $survey->setSurveyName("hi");
     $survey->setDescription('stuff');
     $q = new SurveyQuestion();
     $q->setType(QuestionType::YesNo());
     $q->setQuestion("Is the world round?");
     $survey->addQuestion($q);
     $this->manager->createSurvey($survey);
     $max = rand(100, 200);
     $yes = $no = 0;
     for ($i = 0; $i < $max; ++$i) {
         $ans = new SurveyAnswer();
         $val = "No";
         if (rand(0, 1) % 2 == 0) {
             $val = "Yes";
             $yes++;
         } else {
             $no++;
         }
         $ans->setAnswer($val);
         $ans->setAnsweredBy("+12064122496");
         $this->manager->addAnswer($q->getId(), $ans);
     }
     $answers = $this->manager->getAnswers($survey->getId());
     $str = ReportChartFormatter::getChartData($answers->getAnswers($q->getId()), ChartFormats::Pie());
     $this->assertNotNull($str);
     $this->assertContains('{"key":"No","val":' . $no . '}', $str);
     $this->assertContains('{"key":"Yes","val":' . $yes . '}', $str);
 }
Пример #2
0
 /**
  * @param $ans
  * @param SurveyQuestion $question
  */
 function __construct($ans, SurveyQuestion $question)
 {
     switch ($question->getType()->getValue()) {
         case QuestionType::YesNo:
             $this->type = ChartFormats::Pie();
             $this->yuiType = "pie";
             break;
         case QuestionType::StarRating:
             $this->type = ChartFormats::Bar();
             $this->yuiType = "bar";
             break;
         case QuestionType::Text:
             $this->type = ChartFormats::TagCloud();
             $this->yuiType = null;
             break;
     }
     $this->data = ReportChartFormatter::getChartData($ans, $this->type);
     $this->question = $question;
 }