Changeset 169cf4dd in iPeer
- Timestamp:
- 2012-12-20T17:53:56-08:00 (6 years ago)
- 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)
- Location:
- app
- Files:
-
- 1 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
app/controllers/components/evaluation.php
r2c1f52d r169cf4dd 1897 1897 * @return void 1898 1898 */ 1899 function formatSurveyEvaluationSummary($surveyId =null)1899 function formatSurveyEvaluationSummary($surveyId, $eventId) 1900 1900 { 1901 1901 $this->Survey = ClassRegistry::init('Survey'); … … 1938 1938 for ($j=0; $j < count($questions[$i]['Question']['Responses']); $j++) { 1939 1939 $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, 1941 1941 'question_id' => $questionId, 1942 1942 'response_id' => $responseId))); … … 1948 1948 1949 1949 $responses = $this->SurveyInput->find('all', array( 1950 'conditions' => array('SurveyInput. survey_id' => $surveyId,1950 'conditions' => array('SurveyInput.event_id' => $eventId, 1951 1951 'SurveyInput.question_id' => $questionId), 1952 1952 'fields' => array('response_text', 'user_id') -
app/controllers/evaluations_controller.php
r2c1f52d r169cf4dd 188 188 $this->Session->setFlash(__('Error: Invalid id or you do not have permission to access this event.', true)); 189 189 $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"); 190 195 } 191 196 … … 1039 1044 } 1040 1045 break; 1041 1042 1046 case 3: // View Survey 1043 1047 $studentId = $groupId; 1044 1048 $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 ); 1048 1056 1049 1057 $answers = array(); … … 1052 1060 $answers[$answer['SurveyInput']['question_id']][] = $answer; 1053 1061 } 1054 1062 1063 $this->set('name', $user['User']['full_name']); 1055 1064 $this->set('answers', $answers); 1056 1065 $this->set('questions', $formattedResult['questions']); … … 1058 1067 $this->render('view_survey_results'); 1059 1068 break; 1060 1061 1069 case 4: //View Mix Evaluation 1062 1070 $formattedResult = $this->Evaluation->formatMixevalEvaluationResult($event, $displayFormat); … … 1090 1098 } 1091 1099 } 1092 1093 1094 /**1095 * viewSurveyGroupEvaluationResults1096 *1097 * @param bool $params1098 *1099 * @access public1100 * @return void1101 */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 numeric1110 if (!is_numeric($surveyId) || !is_numeric($surveyGroupId)) {1111 $this->Session->setFlash(__('Error: Invalid Id', true));1112 // may want to redirect to somewhere else1113 $this->redirect('/home/index');1114 }1115 1116 $survey = $this->Survey->find('first', array(1117 'conditions' => array(1118 'Survey.id' => $surveyId1119 )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 1136 1100 1137 1101 /** … … 1665 1629 function viewSurveySummary($eventId) 1666 1630 { 1631 // Check that $eventId is valid 1667 1632 $event = $this->Event->find('first', array( 1668 1633 'conditions' => array( … … 1671 1636 'contain' => false, 1672 1637 )); 1673 1674 // check that $eventId is valid1675 1638 if (null == $event) { 1676 1639 $this->Session->setFlash(__('Error: Invalid event Id', true)); … … 1678 1641 } 1679 1642 1643 // Check that $surveyId is valid 1680 1644 $survey = $this->Survey->find('first', array( 1681 1645 'conditions' => array( … … 1684 1648 'contain' => false, 1685 1649 )); 1686 1687 // check that $surveyId is valid1688 1650 if (null == $survey) { 1689 1651 $this->Session->setFlash(__('Error: Invalid survey Id', true)); … … 1691 1653 } 1692 1654 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()); 1694 1658 if (!$course) { 1695 1659 $this->Session->setFlash(__('Error: Course does not exist or you do not have permission to view this course.', true)); … … 1697 1661 } 1698 1662 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); 1700 1666 1701 1667 $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); 1704 1698 } 1705 1699 -
app/controllers/surveygroups_controller.php
r2c1f52d r169cf4dd 118 118 } 119 119 120 121 /**122 * viewresult123 *124 * @param int $courseId125 * @param int $eventId126 *127 * @access public128 * @return void129 */130 function viewresult($courseId, $eventId=null)131 {132 $surveys = array(); // holds all the surveys' titles in the course133 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 entered148 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 view162 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 course173 $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 182 120 /** 183 121 * 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(); 6 foreach ($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 59 foreach ($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(); 70 foreach ($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 108 foreach ($questionsTable as $question) { 109 echo $html->tableHeaders($question['header'], null, 110 array('colspan' => $colspan)); 111 echo $html->tableCells($question['cells']); 112 } 113 ?> 30 114 </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 133 jQuery(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.