Changeset 169cf4dd in iPeer


Ignore:
Timestamp:
2012-12-20T17:53:56-08:00 (5 years ago)
Author:
John Hsu <john.hsu@…>
Branches:
3.1.x, dev, hotfix, master, pagodabox, ticket463
Children:
ba59c6a
Parents:
2c1f52d
git-author:
John Hsu <john.hsu@…> (12/20/2012 04:16:13 PM)
git-committer:
John Hsu <john.hsu@…> (12/20/2012 05:53:56 PM)
Message:

Merge survey results page.

Survey results had 2 pages, one with the summary and one with the
individual responses. I've merged them together and patched them to work
with us using event_id instead of survey_id now in SurveyInput?.

Still to be done: Patch survey submission so that it uses event_id
instead of survey_id.

Location:
app
Files:
1 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • app/controllers/components/evaluation.php

    r2c1f52d r169cf4dd  
    18971897     * @return void
    18981898     */
    1899     function formatSurveyEvaluationSummary($surveyId=null)
     1899    function formatSurveyEvaluationSummary($surveyId, $eventId)
    19001900    {
    19011901        $this->Survey = ClassRegistry::init('Survey');
     
    19381938                for ($j=0; $j < count($questions[$i]['Question']['Responses']); $j++) {
    19391939                    $responseId = $questions[$i]['Question']['Responses']['response_'.$j]['id'];
    1940                     $answerCount = $this->SurveyInput->find('count', array('conditions' => array('survey_id' => $surveyId,
     1940                    $answerCount = $this->SurveyInput->find('count', array('conditions' => array('event_id' => $eventId,
    19411941                        'question_id' => $questionId,
    19421942                        'response_id' => $responseId)));
     
    19481948
    19491949                $responses = $this->SurveyInput->find('all', array(
    1950                     'conditions' => array('SurveyInput.survey_id' => $surveyId,
     1950                    'conditions' => array('SurveyInput.event_id' => $eventId,
    19511951                    'SurveyInput.question_id' => $questionId),
    19521952                    'fields' => array('response_text', 'user_id')
  • app/controllers/evaluations_controller.php

    r2c1f52d r169cf4dd  
    188188            $this->Session->setFlash(__('Error: Invalid id or you do not have permission to access this event.', true));
    189189            $this->redirect('index');
     190        }
     191
     192        // Survey Results are on a different page for now
     193        if ($event['Event']['event_template_type_id'] == 3) {
     194            $this->redirect("viewSurveySummary/$eventId");
    190195        }
    191196
     
    10391044            }
    10401045            break;
    1041 
    10421046        case 3: // View Survey
    10431047            $studentId = $groupId;
    10441048            $formattedResult = $this->Evaluation->formatSurveyEvaluationResult($event, $studentId);
    1045             $user = $this->User->find('first', array('conditions' => array('User.id' => $studentId)));
    1046             $username = $user['User']['username'];
    1047             $this->set('title_for_layout', $this->Course->getCourseName($courseId).' > '.$event['Event']['title'].' > '.$username. __("'s Results ", true));
     1049            $user = $this->User->find(
     1050                'first',
     1051                array(
     1052                    'conditions' => array('User.id' => $studentId),
     1053                    'contain' => false
     1054                )
     1055            );
    10481056
    10491057            $answers = array();
     
    10521060                $answers[$answer['SurveyInput']['question_id']][] = $answer;
    10531061            }
    1054 
     1062           
     1063            $this->set('name', $user['User']['full_name']);
    10551064            $this->set('answers', $answers);
    10561065            $this->set('questions', $formattedResult['questions']);
     
    10581067            $this->render('view_survey_results');
    10591068            break;
    1060 
    10611069        case 4:  //View Mix Evaluation
    10621070            $formattedResult = $this->Evaluation->formatMixevalEvaluationResult($event, $displayFormat);
     
    10901098        }
    10911099    }
    1092 
    1093 
    1094     /**
    1095      * viewSurveyGroupEvaluationResults
    1096      *
    1097      * @param bool $params
    1098      *
    1099      * @access public
    1100      * @return void
    1101      */
    1102     function viewSurveyGroupEvaluationResults($params=null)
    1103     {
    1104         $this->autoRender = false;
    1105 
    1106         $surveyId = strtok($params, ';');
    1107         $surveyGroupId = strtok(';');
    1108 
    1109         // check to see if the ids are numeric
    1110         if (!is_numeric($surveyId) || !is_numeric($surveyGroupId)) {
    1111             $this->Session->setFlash(__('Error: Invalid Id', true));
    1112             // may want to redirect to somewhere else
    1113             $this->redirect('/home/index');
    1114         }
    1115 
    1116         $survey = $this->Survey->find('first', array(
    1117             'conditions' => array(
    1118                 'Survey.id' => $surveyId
    1119             )
    1120         ));
    1121 
    1122         $courseId = $survey['Survey']['course_id'];
    1123 
    1124         $course = $this->Course->getAccessibleCourseById($courseId, User::get('id'), User::getCourseFilterPermission());
    1125         if (!$course) {
    1126             $this->Session->setFlash(__('Error: Course does not exist or you do not have permission to view this course.', true));
    1127             $this->redirect('index');
    1128         }
    1129 
    1130         $formattedResult = $this->Evaluation->formatSurveyGroupEvaluationResult($surveyId, $surveyGroupId);
    1131 
    1132         $this->set('questions', $formattedResult);
    1133         $this->render('view_survey_summary');
    1134     }
    1135 
    11361100
    11371101    /**
     
    16651629    function viewSurveySummary($eventId)
    16661630    {
     1631        // Check that $eventId is valid
    16671632        $event = $this->Event->find('first', array(
    16681633            'conditions' => array(
     
    16711636            'contain' => false,
    16721637        ));
    1673 
    1674         // check that $eventId is valid
    16751638        if (null == $event) {
    16761639            $this->Session->setFlash(__('Error: Invalid event Id', true));
     
    16781641        }
    16791642
     1643        // Check that $surveyId is valid
    16801644        $survey = $this->Survey->find('first', array(
    16811645            'conditions' => array(
     
    16841648            'contain' => false,
    16851649        ));
    1686 
    1687         // check that $surveyId is valid
    16881650        if (null == $survey) {
    16891651            $this->Session->setFlash(__('Error: Invalid survey Id', true));
     
    16911653        }
    16921654
    1693         $course = $this->Course->getAccessibleCourseById($survey['Survey']['course_id'], User::get('id'), User::getCourseFilterPermission());
     1655        // Check that course is accessible by user
     1656        $course = $this->Course->getAccessibleCourseById(
     1657            $event['Event']['course_id'], User::get('id'), User::getCourseFilterPermission());
    16941658        if (!$course) {
    16951659            $this->Session->setFlash(__('Error: Course does not exist or you do not have permission to view this course.', true));
     
    16971661        }
    16981662
    1699         $formattedResult = $this->Evaluation->formatSurveyEvaluationSummary($survey['Survey']['id']);
     1663        // Prepare data to pass to view
     1664        $formattedResult = $this->Evaluation->formatSurveyEvaluationSummary(
     1665            $survey['Survey']['id'], $eventId);
    17001666
    17011667        $this->set('questions', $formattedResult);
    1702         $this->set('breadcrumb', $this->breadcrumb->push(array('course' => $course['Course']))
    1703             ->push(array('survey' => $survey['Survey']))->push(__('Summary', true)));
     1668        $this->set('breadcrumb',
     1669            $this->breadcrumb->push(array('course' => $course['Course']))
     1670            ->push(array('survey' => $survey['Survey']))
     1671            ->push(__('Summary', true)));
     1672
     1673        // Get enrolment data for the individual responses
     1674        $course = $this->Course->find(
     1675            'first',
     1676            array(
     1677                'conditions' => array('id' => $course['Course']['id']),
     1678                'contain' => array('Enrol')
     1679            )
     1680        );
     1681        $submissions = $this->SurveyInput->findAllByEventId($eventId);
     1682        // add submission status for each enroled user
     1683        foreach ($course['Enrol'] as $key => $student) {
     1684            $course['Enrol'][$key]['submitted'] = false;
     1685            foreach ($submissions as $submission) {
     1686                if ($student['id'] == $submission['SurveyInput']['user_id']) {
     1687                    $course['Enrol'][$key]['submitted'] = true;
     1688                    break;
     1689                }
     1690            }
     1691        }
     1692
     1693        // TODO check that survey submissions are still going through
     1694        // TODO check that all SurveyInput calls don't have survey_id hardcoded
     1695        // somewhere
     1696        $this->set('students', $course['Enrol']);
     1697        $this->set('eventId', $eventId);
    17041698    }
    17051699
  • app/controllers/surveygroups_controller.php

    r2c1f52d r169cf4dd  
    118118    }
    119119
    120 
    121     /**
    122      * viewresult
    123      *
    124      * @param int $courseId
    125      * @param int $eventId
    126      *
    127      * @access public
    128      * @return void
    129      */
    130     function viewresult($courseId, $eventId=null)
    131     {
    132         $surveys = array(); // holds all the surveys' titles in the course
    133 
    134         $course = $this->Course->getAccessibleCourseById($courseId, User::get('id'), User::getCourseFilterPermission(), array(
    135             'Event' => 'event_template_type_id = 3',
    136             'Enrol' => array(
    137                 'fields' => array('id', 'username', 'full_name', 'student_no', 'email'),
    138                 'Submission'
    139             )
    140         ));
    141         if (!$course) {
    142             $this->Session->setFlash(__('Error: Course does not exist or you do not have permission to view this course.', true));
    143             $this->redirect('/courses');
    144         }
    145 
    146         $eventIds = Set::extract($course['Event'], '/id');
    147         // if an event id is entered
    148         if ($eventId != null) {
    149             if (!in_array($eventId, $eventIds)) {
    150                 $eventId = null;
    151             }
    152         } else {
    153             $eventId = array_shift($eventIds);
    154         }
    155 
    156         if (null == $eventId) {
    157             $this->Session->setFlash(__('Error: Invalid course ID or event ID.', true));
    158             $this->redirect('index/'.$courseId);
    159         }
    160 
    161         //filtering for the data to be printed in the view
    162         foreach ($course['Enrol'] as $key => $student) {
    163             $course['Enrol'][$key]['submitted'] = 'Not Submitted';
    164             foreach ($student['Submission'] as $submission) {
    165                 if ($submission['event_id'] == $eventId) {
    166                     $course['Enrol'][$key]['submitted'] = $submission['date_submitted'];
    167                     break;
    168                 }
    169             }
    170         }
    171 
    172         // for populating the drop down menu to switch to different surveys in the course
    173         $surveys = Set::combine($course['Event'], '{n}.id', '{n}.title');
    174 
    175         $this->set('breadcrumb', $this->breadcrumb->push(array('course' => $course['Course']))->push(__('View Survey Result', true)));
    176         $this->set('view', $course['Enrol']);
    177         $this->set('courseId', $courseId);
    178         $this->set('eventId', $eventId);
    179         $this->set('surveysList', $surveys);
    180     }
    181 
    182120    /**
    183121     * makegroups
  • app/views/evaluations/view_survey_summary.ctp

    r2c1f52d r169cf4dd  
    1 <table class="standardtable">
    2     <tr><th><?php __('Team Maker Survey Summary')?></th></tr>
    3     <tr>
    4         <td>
    5     <?php if( !empty($questions)):?>
    6     <?php foreach ($questions as $question): $question = $question['Question'];?>
    7         <div style="text-align: left;">Q<?php echo $question['number']?>: <?php echo $question['prompt']?></div>
    8         <div>
    9             <table border="0">
    10             <?php if($question['type'] == 'M' || $question['type'] == 'C'): ?>
    11                 <?php if( !empty($question['Responses'])):?>
    12                     <?php foreach ($question['Responses'] as $index => $value):?>
    13                         <?php $percent = $question['total_response'] != 0 ? round(($value['count']/$question['total_response'])*100): 0;?>
    14                         <tr><td width="250"><?php echo $value['response']?></td><td width="30"><?php echo $value['count']?></td><td> <?php echo $percent?>% </td><td><?php echo $html->image("evaluations/bar.php?per=".$percent,array('alt'=>$percent))?></td></tr>
    15                     <?php endforeach;?>
    16                 <?php endif; ?>
    17             <?php elseif( $question['type'] == 'S' || $question['type'] == 'L'): ?>
    18                 <?php if( !empty($question['Responses'])):?>
    19                     <?php foreach ($question['Responses'] as $index => $value):?>
    20                         <tr valign="top"><td width="250"><?php echo $value['user_name']?></td><td width="15"></td><td><i><?php echo $value['response_text']?></i><td></tr>
    21                     <?php endforeach;?>
    22                 <?php endif; ?>
    23             <?php endif; ?>
    24             </table>
    25         </div>
    26     <?php endforeach; ?>
    27     <?php endif; ?>
    28         </td>
    29     </tr>
     1<?php
     2// Survey Summary data
     3$count = 1;
     4$colspan = 4; // total number of columns for when we want only 1 cell
     5$questionsTable = array();
     6foreach ($questions as $question) {
     7    $tmp = array();
     8    $question = $question['Question'];
     9    if (isset($question['total_response'])) {
     10        // Processing a multiple choice response
     11        // header
     12        $totalResponses = $question['total_response'];
     13        $tmp['header'][] = "$count. " . $question['prompt'] . ' (' .
     14            $totalResponses . ' '. __('responses', true) . ')';
     15
     16        // responses
     17        foreach ($question['Responses'] as $response) {
     18            $cells = array();
     19            // processing a multiple choice question's response
     20            $count = $response['count'];
     21            $percent = $totalResponses > 0 ?
     22                $percent = round($count / $totalResponses * 100) : 0;
     23            $cells[] = $response['response'];
     24            $cells[] = $count;
     25            $cells[] = $percent;
     26            $cells[] = $html->image(
     27                "evaluations/bar.php?per=" . $percent, array('alt'=>$percent));
     28            $tmp['cells'][] = $cells;
     29        }
     30    }
     31    else {
     32        // Processing a single or multi-line text response
     33        // header
     34        $totalResponses = count($question['Responses']);
     35        $tmp['header'][] = "$count. " . $question['prompt'] . ' (' .
     36            $totalResponses . ' '. __('responses', true) . ')';
     37
     38        // responses
     39        $responders = "";
     40        foreach ($question['Responses'] as $response) {
     41            $responders .= $response['user_name']
     42                . ', ';
     43        }
     44        $responders = trim($responders, ", ");
     45        $cells = array();
     46        $cells[] = __('Responders', true) . ":";
     47        $cells[] = array($responders, array('colspan' => $colspan - 1));
     48        $tmp['cells'][] = $cells;
     49    }
     50
     51    $count++;
     52    $questionsTable[] = $tmp;
     53}
     54
     55// Individual Response data
     56$headers = array('id', 'username', 'full_name', 'email', 'student_no', 'submitted');
     57$displayHeaders = array();
     58// display email only if the user has access to it
     59foreach ($headers as $key => $header) {
     60    if ($header == 'email' &&
     61        !User::hasPermission('functions/viewemailaddresses')
     62    ) {
     63        unset($headers[$key]);
     64        continue;
     65    }
     66    $displayHeaders[] = Inflector::humanize($header);
     67}
     68
     69$displayCells = array();
     70foreach ($students as $student) {
     71    $tmp = array();
     72    foreach ($headers as $header) {
     73        if ($header == 'email' &&
     74            !User::hasPermission('functions/viewemailaddresses')
     75        ) {
     76            continue;
     77        }
     78        // link to view user information
     79        else if ($header == 'username') {
     80            $tmp[] = $html->link(
     81                $student[$header],
     82                '/users/view/'.$student['id'],
     83                array('target' => '_blank')
     84            );
     85        }
     86        // link to view this user's submission if available
     87        else if ($header == 'submitted') {
     88            $tmp[] = $student[$header] ?
     89                $html->link(__('Result', true),
     90                    "/evaluations/viewEvaluationResults/$eventId/" .
     91                    $student['id'],
     92                    array('target' => '_blank')
     93                ) :
     94                __('Not Submitted', true);
     95        }
     96        else {
     97            $tmp[] = $student[$header];
     98        }
     99    }
     100    $displayCells[] = $tmp;
     101}
     102?>
     103
     104<h2>Survey Summary</h2>
     105
     106<table class='standardtable leftalignedtable'>
     107<?php
     108foreach ($questionsTable as $question) {
     109    echo $html->tableHeaders($question['header'], null,
     110        array('colspan' => $colspan));
     111    echo $html->tableCells($question['cells']);
     112}
     113?>
    30114</table>
     115
     116<h2>Individual Responses</h2>
     117
     118<table id="individualResponses">
     119    <thead>
     120    <?php
     121    echo $html->tableHeaders($displayHeaders);
     122    ?>
     123    </thead>
     124    <tbody>
     125    <?php
     126    echo $html->tableCells($displayCells);
     127    ?>
     128    </tbody>
     129</table>
     130
     131<script type="text/javascript">
     132// enable all the nice sorting, search pagination, etc, hide the user id field
     133jQuery(document).ready(function() {
     134    var oTable= jQuery('#individualResponses').dataTable( {
     135        "sPaginationType" : "full_numbers",
     136        "aoColumnDefs" : [
     137            {"bSearchable": false, "bVisible": false, "bSortable": false, "aTargets": [0] },
     138        ],
     139        "aaSorting" :[[1, 'asc']]
     140    });
     141});
     142</script>
     143
Note: See TracChangeset for help on using the changeset viewer.