public function testBarChart() { $survey = new Survey(); $survey->setSurveyName("hi"); $survey->setDescription('stuff'); $q = new SurveyQuestion(); $q->setType(QuestionType::StarRating()); $q->setQuestion("how would you rate the event?"); $survey->addQuestion($q); $this->manager->createSurvey($survey); $max = rand(100, 200); $ratings = array(1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0); for ($i = 0; $i < $max; ++$i) { $ans = new SurveyAnswer(); $rand = rand(1, 5); $ratings[$rand]++; $ans->setAnswer($rand); $ans->setAnsweredBy("+12064122496"); $this->manager->addAnswer($q->getId(), $ans); } $answers = $this->manager->getAnswers($survey->getId()); $str = ReportChartFormatter::getChartData($answers->getAnswers($q->getId()), ChartFormats::Bar()); $this->assertNotNull($str); foreach ($ratings as $key => $rating) { $this->assertContains('{"key":' . $key . ',"val":' . $rating . '}', $str); } }
/** * @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; }