protected function getValueParamForPos(DataTable $data, $pos, $separator = ',') { $values = $data->getValuesForPosition($pos); //urlEncode... array_walk($values, '\\SaadTazi\\GChartBundle\\Chart\\BaseChart::urlEncode'); return implode($separator, $values); }
public function demo3Action() { //how to deal with 0 values #2 $dataTable = new DataTable\DataTable(); $dataTable->addColumn('', 'My title', 'string'); $dataTable->addColumnObject(new DataTable\DataColumn('total', 'Caption', 'number')); $dataTable->addRow(array('Lable', 10)); $dataTable->addRow(array('Lable', 0)); $dataTable->addRow(array('Lable', 0)); $dataTable->addRow(array('Lable', 5)); $dataTable->addRow(array('Lable', 0)); var_dump($dataTable); return $this->render('SaadTaziGChartBundle:Demo:demo3.html.twig', array('dt' => $dataTable->toArray())); }
public function showTeacherAction($filter = null) { $filterArray = array(); if ($filter != null) { array_push($filterArray, explode(".", $filter)); $filterArray = $filterArray[0]; $i = 0; foreach ($filterArray as $Afilter) { $filterArray[$i] = array_map('intval', explode(",", $Afilter)); $i++; } } //Number of questions in the survey $NUMBEROFQUESTIONS = 10; //Questions in the survey $resultQuestionsArray = ['Antall svar per skole', 'Klassetrinn', 'Det var nyttig å ha vektorassistentene i klassen.', 'Vektorassistentene var kvalifiserte for jobben.', 'Det var for mange studentassistenter tilstede.', 'Det var god kontakt og informasjonsflyt på forhånd.', 'Jeg ønsker at prosjektet fortsetter.', 'Jeg tror elevene har blitt mer motivert for matematikk som følge av prosjektet.', 'Arbeidsbelastningen ble mindre når vektorassistentene var på skolen.', 'Undervisning ble bedre tilpasset for elevene.', 'Har du noen kommentarer om vektorprogrammet som vi kan bruke videre?']; //Connects with the SurveyTecher entity $repositorySurvey = $this->getDoctrine()->getRepository('AppBundle:SurveyTeacher'); //Connects with the School entity $repositorySchool = $this->getDoctrine()->getRepository('AppBundle:School'); //Finds numeber of surveys if ($filter != null) { $numberOfSurveys = $repositorySurvey->NumOfSurveysFiltered($filterArray); } else { //Finds number of survey answers for each school $numberOfSurveys = $repositorySurvey->NumOfSurveys(); } //Finds the textual feedback $feedBack = $repositorySurvey->allFeedback(); //Creates the DataTable with two columns $schoolChart = new DataTable(); $schoolChart->addColumn('1', 'Alternantive', 'string'); $schoolChart->addColumn('2', 'Quantity', 'number'); //Loops through the schools foreach ($repositorySchool->findAll() as $school) { //Finds the names for the schools $schoolName = $repositorySchool->find($school)->getName(); if ($filter != null) { $schoolNumber = $repositorySurvey->NumOfSchoolsByIdFiltered($school, $filterArray); } else { //Finds number of survey answers for each school $schoolNumber = $repositorySurvey->NumOfSchoolsBySchool($school); } //Adds the information in the DataTable $schoolChart->addRow([$schoolName, intval($schoolNumber)]); } //Creates two arrays that will be sent into the twig, with the information form the surveys, and the questions. $diagramArray[0] = $schoolChart->toArray(); $questionArray[0] = $resultQuestionsArray[0]; //Loop through the question for ($diagramCounter = 1; $diagramCounter < $NUMBEROFQUESTIONS; $diagramCounter++) { //creates a new dataTable for the information from the surveys $chart = new DataTable(); $chart->addColumn('1', 'Question', 'string'); $chart->addColumn('2', 'Quantity', 'number'); //Sets the correct alternatives for the respective questions if ($diagramCounter == 1) { $ALTERNATIVEARRAY = ['8. Klasse', '9. Klasse', '10. Klasse']; $NUMBEROFALTERNATIVES = 3; } else { $ALTERNATIVEARRAY = ['Helt enig', 'Noe enig', 'Nøytral', 'Noe uenig', 'Helt Uenig']; $NUMBEROFALTERNATIVES = 5; } for ($alternativeCounter = 1; $alternativeCounter < $NUMBEROFALTERNATIVES + 1; $alternativeCounter++) { $alternative = $ALTERNATIVEARRAY[$alternativeCounter - 1]; if ($filter != null) { $answerNumber = $repositorySurvey->NumOfAnswersByQuestionIdAndAlternativesFiltered($diagramCounter, $alternativeCounter, $filterArray); } else { $answerNumber = $repositorySurvey->NumOfAnswersByQuestionIdAndAlternatives($diagramCounter, $alternativeCounter); } $chart->addRow([$alternative, intval($answerNumber)]); } $diagramArray[$diagramCounter] = $chart->toArray(); $questionArray[$diagramCounter] = $resultQuestionsArray[$diagramCounter - 1]; } $questionArray[10] = $resultQuestionsArray[9]; return $this->render('survey/survey_data.html.twig', array('id' => 'teacher', 'diagram' => $diagramArray, 'question' => $questionArray, 'numSurveys' => $numberOfSurveys, 'feedback' => $feedBack, 'info' => "Lærerundersøkelsene")); }
public function resultSurveyAction(Survey $survey) { $surveyTakenList = $this->getDoctrine()->getRepository('AppBundle:SurveyTaken')->findBySurvey($survey); //ADD SCHOOL CHART $schoolCompletedCount = array(); foreach ($surveyTakenList as $surveyTaken) { $school = $surveyTaken->getSchool()->getName(); if (array_key_exists($school, $schoolCompletedCount)) { $schoolCompletedCount[$school]++; } else { $schoolCompletedCount[$school] = 1; } } $chart = new DataTable(); $chart->addColumn('1', 'Label', 'string'); $chart->addColumn('2', 'Quantity', 'number'); $alternativeArray = array_keys($schoolCompletedCount); foreach ($alternativeArray as $alternative) { $chart->addRow([$alternative, $schoolCompletedCount[$alternative]]); } $diagramArray[] = $chart->toArray(); $questionArray[] = 'Skole'; //SCHOOL CHART END $lablesArray = array(); $questionsArray = array(); $textQuestionArray = array(); $textQAarray = array(); $counter = 0; //Create question charts foreach ($survey->getSurveyQuestions() as $question) { if ($question->getType() != "text") { array_push($lablesArray, $question->getQuestion()); array_push($questionsArray, $question); } else { $textQuestionArray[] = $question; } } foreach ($textQuestionArray as $textQuestion) { $questionText = $textQuestion->getQuestion(); $textQAarray[$questionText] = array(); foreach ($textQuestion->getAnswers() as $answer) { $textQAarray[$questionText][] = $answer->getAnswer(); } } foreach ($questionsArray as $question) { $chart = new DataTable(); $chart->addColumn('1', 'Label', 'string'); $chart->addColumn('2', 'Quantity', 'number'); $alternativeArray = $question->getAlternatives(); foreach ($alternativeArray as $alternative) { $alternative = $alternative->getAlternative(); $num = 0; foreach ($question->getAnswers() as $answer) { if ($answer->getAnswer() == $alternative) { $num++; } } $chart->addRow([$alternative, intval($num)]); } $diagramArray[] = $chart->toArray(); $questionArray[] = $lablesArray[$counter]; $counter++; } return $this->render('survey/survey_result.html.twig', array('textAnswers' => $textQAarray, 'numAnswered' => sizeof($surveyTakenList), 'survey' => $survey, 'diagram' => $diagramArray, 'question' => $questionArray)); }
public function showAction() { $NUMBEROFCHARTS = 7; $lablesArray = ["Semester", "Kjønn", "Har vært vektorassistent tidligere", "Antall tatt opp", "Studieår", "Studie", "Avdeling"]; $repositoryApplicationStatistic = $this->getDoctrine()->getRepository('AppBundle:ApplicationStatistic'); $repositorySemester = $this->getDoctrine()->getRepository('AppBundle:Semester'); $repositoryFieldOfStudy = $this->getDoctrine()->getRepository('AppBundle:FieldOfStudy'); $repositoryDepartment = $this->getDoctrine()->getRepository('AppBundle:Department'); $numberOfApplications = $repositoryApplicationStatistic->NumOfApplications(); for ($diagramCounter = 0; $diagramCounter < $NUMBEROFCHARTS; $diagramCounter++) { $chart = new DataTable(); $chart->addColumn('1', 'Label', 'string'); $chart->addColumn('2', 'Quantity', 'number'); $AlternativeArray = []; if ($diagramCounter == 0) { $semesterCounter = 0; foreach ($repositorySemester->findAllSemesters() as $semester) { array_push($AlternativeArray, $semester->getName() . ' ' . $semester->getDepartment()->getShortName()); $alternative = $AlternativeArray[$semesterCounter]; $semesterNumber = $repositoryApplicationStatistic->NumOfSemester($semester); $chart->addRow([$alternative, intVal($semesterNumber)]); $semesterCounter++; } } elseif ($diagramCounter == 1) { $AlternativeArray = ['Gutt', 'Jente']; for ($alternativeCounter = 0; $alternativeCounter < count($AlternativeArray); $alternativeCounter++) { $alternative = $AlternativeArray[$alternativeCounter]; $genderNumber = $repositoryApplicationStatistic->numOfGender($alternativeCounter); $chart->addRow([$alternative, intval($genderNumber)]); } } elseif ($diagramCounter == 2) { $AlternativeArray = ['Nei', 'Ja']; for ($alternativeCounter = 0; $alternativeCounter < count($AlternativeArray); $alternativeCounter++) { $alternative = $AlternativeArray[$alternativeCounter]; $participationNumber = $repositoryApplicationStatistic->NumOfPreviousParticipation($alternativeCounter); $chart->addRow([$alternative, intval($participationNumber)]); } } elseif ($diagramCounter == 3) { $AlternativeArray = ['Ikke tatt opp', 'Tatt opp']; for ($alternativeCounter = 0; $alternativeCounter < count($AlternativeArray); $alternativeCounter++) { $alternative = $AlternativeArray[$alternativeCounter]; $acceptedNumber = $repositoryApplicationStatistic->NumOfAccepted($alternativeCounter); $chart->addRow([$alternative, intval($acceptedNumber)]); } } elseif ($diagramCounter == 4) { $AlternativeArray = ['1', '2', '3', '4', '5']; for ($alternativeCounter = 0; $alternativeCounter < count($AlternativeArray); $alternativeCounter++) { $alternative = "" . $AlternativeArray[$alternativeCounter] . ". året"; $acceptedNumber = $repositoryApplicationStatistic->NumOfYearOfStudy($alternativeCounter + 1); $chart->addRow([$alternative, intval($acceptedNumber)]); } } elseif ($diagramCounter == 5) { $semesterCounter = 0; foreach ($repositoryFieldOfStudy->findAllFieldOfStudy() as $fieldOfStudy) { array_push($AlternativeArray, $fieldOfStudy->getName()); $alternative = $AlternativeArray[$semesterCounter]; $fieldOfStudyNumber = $repositoryApplicationStatistic->NumOfFieldOfStudy($fieldOfStudy); $chart->addRow([$alternative, intVal($fieldOfStudyNumber)]); $semesterCounter++; } } else { $semesterCounter = 0; foreach ($repositoryDepartment->findAllDepartments() as $department) { array_push($AlternativeArray, $department->getShortName()); $alternative = $AlternativeArray[$semesterCounter]; $semesterNumber = $repositoryApplicationStatistic->NumOfDepartment($department->getId()); $chart->addRow([$alternative, intVal($semesterNumber)]); $semesterCounter++; } } $diagramArray[$diagramCounter] = $chart->toArray(); $questionArray[$diagramCounter] = $lablesArray[$diagramCounter]; } return $this->render('statistics/statistics.html.twig', array('diagram' => $diagramArray, 'question' => $questionArray)); }
public function testFromSimpleMatrix() { $matrix = array(array('row1', 1, true, new \DateTime('2010-01-14')), array('row2', 3, false, new \DateTime('2010-02-15')), array('row3', 4, true, new \DateTime('2010-03-16')), array('row4', null, true, null)); $dataTable1 = DataTable::fromSimpleMatrix($matrix, false); //var_dump($dataTable1->toArray());die(); $this->assertEquals($dataTable1->toArray(), array('cols' => array(array('id' => 'id0', 'label' => 'c0', 'type' => 'string'), array('id' => 'id1', 'label' => 'c1', 'type' => 'number'), array('id' => 'id2', 'label' => 'c2', 'type' => 'boolean'), array('id' => 'id3', 'label' => 'c3', 'type' => 'datetime')), 'rows' => array(array('c' => array(array('v' => 'row1'), array('v' => 1), array('v' => true), array('v' => "[new Date](2010,1,14,0,00,00)[new Date]"))), array('c' => array(array('v' => 'row2'), array('v' => 3), array('v' => false), array('v' => "[new Date](2010,2,15,0,00,00)[new Date]"))), array('c' => array(array('v' => 'row3'), array('v' => 4), array('v' => true), array('v' => "[new Date](2010,3,16,0,00,00)[new Date]"))), array('c' => array(array('v' => 'row4'), array(), array('v' => true), array()))), 'p' => array())); $matrix2 = array(array('col1', 'col2', 'col3'), array('row1', 3, true), array('row2', null, null), array(null, 4, false)); $dataTable2 = DataTable::fromSimpleMatrix($matrix2, true); $this->assertEquals($dataTable2->toArray(), array('cols' => array(array('id' => 'id0', 'label' => 'col1', 'type' => 'string'), array('id' => 'id1', 'label' => 'col2', 'type' => 'number'), array('id' => 'id2', 'label' => 'col3', 'type' => 'boolean')), 'rows' => array(array('c' => array(array('v' => 'row1'), array('v' => 3), array('v' => true))), array('c' => array(array('v' => 'row2'), array(), array())), array('c' => array(array(), array('v' => 4), array('v' => false)))), 'p' => array())); }