示例#1
0
 public function call()
 {
     $tpl = new Template('dashboard_login_body.php');
     $survey_code = strtoupper($this->getArgument('uid'));
     $password = $this->getArgument('pw');
     if ($_SERVER['REQUEST_METHOD'] == 'POST' || $survey_code && $password) {
         $survey_mng = new SurveyManager();
         if (!$survey_code || !$survey_mng->isSurvey($survey_code)) {
             return new Answer('ok', $tpl->process(array('login_error' => 1, 'survey' => $survey_code)), 'html');
         }
         $survey = $survey_mng->getSurvey($survey_code);
         if ($password != $survey->getPassword()) {
             return new Answer('ok', $tpl->process(array('login_error' => 1, 'survey' => $survey_code)), 'html');
         }
         //All ok, login user to survey results
         if (!session_id()) {
             session_start();
         }
         $_SESSION['survey_results'][$survey_code] = 1;
         $tpl = new Template('dashboard_flex_body.php');
         return new Answer('ok', $tpl->process(array('session' => session_id(), 'survey_code' => $survey_code)), 'html');
     }
     return new Answer('ok', $tpl->process(array()), 'html');
 }
示例#2
0
 public function getReport($survey_code)
 {
     $survey_manager = new SurveyManager();
     $survey_obj = $survey_manager->getSurvey($_REQUEST['survey']);
     $sql = "SELECT *,CONVERT_TZ(start_time,'+00:00','-7:00') AS start_time_mst,CONVERT_TZ(end_time,'+00:00','-7:00') AS end_time_mst " . " FROM survey_result LEFT JOIN survey_user_data USING(survey_result_id) where is_removed=0 AND code = '" . mysql_real_escape_string($survey_code) . "'";
     $db = new DB();
     $rows = $db->runQuery($sql);
     $db = new DB();
     $a_question_id = $survey_obj->listQuestionsId();
     $a_header = array('Start', 'End', 'IP', 'Emotion', 'Intensity', 'Verbatim', 'Name', 'Email', 'Phone');
     $a_header = array_merge($a_header, $a_question_id);
     $a_result = array();
     foreach ($rows as $row) {
         $verbatim = $row['verbatim'];
         $a_verbatim = preg_split('/[\\n\\r\\s]+/', $verbatim);
         $verbatim = implode(" ", $a_verbatim);
         $result = array($row['start_time_mst'], $row['end_time_mst'], $row['ip'], $row['emote'], $row['intensity_level'], $verbatim, $row['name'], $row['email'], $row['phone']);
         foreach ($a_question_id as $question_id) {
             $select_question = "SELECT * FROM survey_demo_result where survey_result_id='" . mysql_real_escape_string($row['survey_result_id']) . "' " . " AND question_field = '" . mysql_real_escape_string($question_id) . "' LIMIT 1";
             $q_rows = $db->runQuery($select_question);
             if ($q_rows) {
                 $q_row = $q_rows[0];
                 $val = array_key_exists('answer', $q_row) ? $q_row['answer'] : '';
                 array_push($result, $val);
             } else {
                 array_push($result, '');
             }
         }
         array_push($a_result, $result);
     }
     array_unshift($a_result, $a_header);
     return $a_result;
 }
示例#3
0
 public function call()
 {
     try {
         $survey_code = strtoupper($this->getArgument('survey'));
         $survey_manager = new SurveyManager();
         if (!session_id()) {
             session_start();
         }
         $hex_data = $this->getArgument('h');
         if ($hex_data) {
             $_SESSION['h'] = $hex_data;
         }
         if ($survey_manager->isSurvey($survey_code, true)) {
             $survey = $survey_manager->getSurvey($survey_code);
             $_SESSION['survey_code'] = strtolower($survey_code);
             $_SESSION['start_time'] = time();
             unset($_SESSION['result_id']);
             unset($_SESSION['user_data_id']);
             $survey_tpl = new Template('widget/survey_body.php');
             return new Answer('ok', $survey_tpl->process(array('survey' => $survey, 'not_welcome' => true)), 'html');
         } else {
             $survey_tpl = new Template('widget/not_found.php');
             return new Answer('ok', $survey_tpl->process(array()), 'html');
         }
     } catch (Exception $e) {
         return new Answer('error', $e->getMessage(), 'html');
     }
 }
示例#4
0
 public function testAnswerQuestion()
 {
     $survey = new Survey();
     $survey->setSurveyName("hi");
     $survey->setDescription('stuff');
     $q = new SurveyQuestion();
     $q->setType(QuestionType::StarRating());
     $q->setQuestion("A question");
     $survey->addQuestion($q);
     $this->manager->createSurvey($survey);
     $ss = $this->manager->getSurvey($survey->getId());
     $q = $ss->getQuestions()[0];
     $ans = new SurveyAnswer();
     $ans->setAnswer("awesome!");
     $ans->setAnsweredBy("+12064122496");
     $this->manager->addAnswer($q->getId(), $ans);
     //SurveyEntityManager::testClear();
     $answers = $this->manager->getAnswers($survey->getId());
     $this->assertNotNull($answers);
     $this->assertEquals(1, count($answers));
     $this->assertEquals($answers->getAnswers($q->getId())[0]->getAnswer(), "awesome!");
     $this->assertEquals($answers->getAnswers($q->getId())[0]->getSurveyQuestionId(), $q->getId());
     //add another question
     $q2 = new SurveyQuestion();
     $q2->setType(QuestionType::StarRating());
     $q2->setQuestion("Second question");
     $survey->addQuestion($q2);
     $this->manager->updateSurvey($survey);
     $this->assertNotNull($q2->getId(), "Asserting the second question was saved");
     //Create another survey and question to make sure we do not
     // have leaks.
     $survey2 = new Survey();
     $survey2->setSurveyName("hi2");
     $survey2->setDescription('stuff2');
     $q3 = new SurveyQuestion();
     $q3->setType(QuestionType::StarRating());
     $q3->setQuestion("A question3");
     $survey2->addQuestion($q3);
     $this->manager->createSurvey($survey2);
     //Now lets add a lot more answers!
     $max = rand(1, 10);
     for ($i = 0; $i < $max; ++$i) {
         $ans = new SurveyAnswer();
         $ans->setAnswer("awesome{$i}");
         $ans->setAnsweredBy("+12064122496");
         $this->manager->addAnswer($q->getId(), $ans);
         $ans2 = new SurveyAnswer();
         $ans2->setAnswer("2awesome{$i}");
         $ans2->setAnsweredBy("+12064122496");
         $this->manager->addAnswer($q2->getId(), $ans2);
         $ans3 = new SurveyAnswer();
         $ans3->setAnswer("don't return me");
         $ans3->setAnsweredBy("+12064122496");
         $this->manager->addAnswer($q3->getId(), $ans3);
     }
     $answers = $this->manager->getAnswers($survey->getId());
     $this->assertNotNull($answers);
     $this->assertEquals(1 + $max * 2, $answers->getTotalAnswers());
     $answers = $this->manager->getAnswers($survey2->getId());
     $this->assertNotNull($answers);
     $this->assertEquals($max, $answers->getTotalAnswers());
 }