123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- <?php
-
-
-
-
-
-
- require_once 'processes/dbh.inc.php';
-
-
-
-
- $experienceID = mysqli_real_escape_string($connection, trim($_POST['experienceID']));
- $momentID = mysqli_real_escape_string($connection, trim($_POST['momentID']));
- $studentID = mysqli_real_escape_string($connection, trim($_POST['studentID']));
-
-
-
-
- $sqlCountSubcategories = "SELECT DISTINCT S.id
- FROM subcategory AS S
- JOIN question as Q
- JOIN subquestionnair_question AS SQ
- JOIN experience_subquestionnair AS ES
- WHERE S.id = Q.id_subcategory
- AND SQ.id_question = Q.id
- AND SQ.id_subquestionnair = ES.id_subquestionnair
- AND ES.id_experience = '$experienceID';";
- $resultCountSubcategories = mysqli_query($connection, $sqlCountSubcategories);
- $countSubcategories = $resultCountSubcategories->num_rows;
-
-
-
-
- if($studentID === "all") {
-
- $sql = "SELECT S.id AS subcategoryID,
- S.subcategoria AS subcategoryName,
- A.value AS score,
- COUNT(id_student) AS `count`
- FROM subcategory AS S
- LEFT JOIN question AS Q
- ON Q.id_subcategory = S.id
- JOIN answer AS A
- JOIN subquestionnair_question AS SQ
- JOIN experience_subquestionnair AS ES
- -- WHERE Q.id_subcategory = S.id
- WHERE A.id_question = Q.id
- AND A.id_question = SQ.id_question
- AND A.id_subquestionnair = SQ.id_subquestionnair
- AND SQ.id_subquestionnair = ES.id_subquestionnair
- AND ES.id_experience = '$experienceID'
- AND SQ.id_subquestionnair = '$momentID'
- GROUP BY score, subcategoryID
- ORDER BY score, subcategoryID";
-
- } else {
-
- $sql = "SELECT S.id AS subcategoryID,
- S.subcategoria AS subcategoryName,
- A.value AS score,
- COUNT(id_student) AS `count`
- FROM subcategory AS S
- LEFT JOIN question AS Q
- ON Q.id_subcategory = S.id
- JOIN answer AS A
- JOIN subquestionnair_question AS SQ
- JOIN experience_subquestionnair AS ES
- -- WHERE Q.id_subcategory = S.id
- WHERE A.id_question = Q.id
- AND A.id_question = SQ.id_question
- AND A.id_subquestionnair = SQ.id_subquestionnair
- AND SQ.id_subquestionnair = ES.id_subquestionnair
- AND ES.id_experience = '$experienceID'
- AND SQ.id_subquestionnair = '$momentID'
- AND A.id_student = '$studentID' -- 118
- GROUP BY score, subcategoryID
- ORDER BY score, subcategoryID";
-
- }
-
- $result = mysqli_query($connection, $sql);
-
-
-
-
- $datasets = [];
- $dataLabels = [];
- $scoreToIndex = [];
- $i = 0;
- $subcategoryIDToIndex = [];
- $j = 0;
-
-
-
-
- while($row = mysqli_fetch_object($result)) {
-
-
-
-
-
-
- $pointLabel = ($studentID === "all") ? " # of people who answered '" : " # of times student answered '";
-
- if(is_numeric($row->score)) {
- $score = $pointLabel . strval((int)$row->score) . "'";
- } else {
- continue;
- }
-
-
-
- if($subcategoryIDToIndex[$row->subcategoryID] || $subcategoryIDToIndex[$row->subcategoryID] === 0) {
-
-
-
- } else {
-
-
- $dataLabels[] = $row->subcategoryName;
-
-
- $subcategoryIDToIndex[$row->subcategoryID] = $j;
- $j++;
-
- }
-
-
-
-
- if($scoreToIndex[$score] || $scoreToIndex[$score] === 0) {
-
-
-
- } else {
-
-
-
-
-
-
- $scoreToIndex[$score] = $i;
- $i++;
-
-
-
- $datasets[] = [
- 'label' => $score,
- 'data' => array_fill(0, $countSubcategories, 0),
- 'backgroundColor' => '#' . substr(sha1($score), 0, 6),
-
-
- 'stack' => $score
-
- ];
-
- }
-
-
-
- $datasets[$scoreToIndex[$score]]['data'][$subcategoryIDToIndex[$row->subcategoryID]] = (int)$row->count;
-
-
- }
-
-
-
-
-
-
-
- $arr = [
- 'datasets' => $datasets,
- 'dataLabels' => $dataLabels
- ];
-
-
-
- echo header("Content-Type: application/json; charset=utf-8");
- echo json_encode($arr);
|