Changeset af4a71f in iPeer


Ignore:
Timestamp:
2012-12-21T03:10:50-08:00 (5 years ago)
Author:
Compass <pan.luo@…>
Branches:
3.1.x, dev, hotfix, master, pagodabox, ticket463
Children:
42ef5b5
Parents:
1eaa7ac
Message:

Refactor Simple and Rubric CSV export

Location:
app
Files:
2 added
11 edited

Legend:

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

    r1eaa7ac raf4a71f  
    1111class ExportBaseNewComponent extends Object
    1212{
    13 
    14     public $components = array('ExportHelper2');
     13    public $eventType = array('1' => 'Simple Evaluation', '2' => 'Rubrics Evaluation', '4' => 'Mixed Evaluation');
     14    public $components = array('ExportHelper2', 'Penalty');
     15    public $responseModelName = null;
     16    public $responseModel = null;
     17    public $evaluationModelName = null;
     18    public $evaluationModel = null;
    1519
    1620    /**
     
    2428     * @return void
    2529     */
    26     function generateHeader2($params, $eventId, $type)
    27     {
    28         $this->Course = ClassRegistry::init('Course');
    29         $this->Event = ClassRegistry::init('Event');
    30         $this->UserCourse = ClassRegistry::init('UserCourse');
    31         $this->GroupEvent = ClassRegistry::init('GroupEvent');
    32         $this->EvaluationMixeval = ClassRegistry::init('EvaluationMixeval');
    33         $eventType = array('1' => 'Simple Evaluation', '2' => 'Rubrics Evaluation', '4' => 'Mixed Evaluation');
    34 
    35         $courseId = $this->Event->getCourseByEventId($eventId);
    36         $event = $this->Event->getEventById($eventId);
    37         $course = $this->Course->getCourseWithInstructorsById($courseId);
     30    function generateHeader2($params, $event, $type)
     31    {
    3832
    3933        $grid = $this->ExportHelper2->buildExporterGrid(8, 8);
     
    4236
    4337        if (!empty($params['include_course'])) {
    44             $grid[0][$yIndex] = "Course Name : ,,".$course['Course']['title'];
     38            $grid[0][$yIndex] = "Course Name : ,,".$event['Course']['title'];
    4539        }
    4640        if (!empty($params['include_eval_event_names'])) {
     
    5044        if (!empty($params['include_eval_event_type'])) {
    5145            $yIndex++;
    52             $grid[0][$yIndex] = "Evaluation Type : ,,".$eventType[$event['Event']['event_template_type_id']];
     46            $grid[0][$yIndex] = "Evaluation Type : ,,".$this->eventType[$event['Event']['event_template_type_id']];
    5347        }
    5448        if (!empty($params['include_instructors'])) {
    5549            $yIndex++;
    5650            $instructors = array();
    57             foreach ($course['Instructor'] as $instructor) {
     51            foreach ($event['Course']['Instructor'] as $instructor) {
    5852                array_push($instructors, $instructor['full_name']);
    5953            }
     
    8478     * generateHeader
    8579     *
    86      * @param mixed $params  params
    87      * @param mixed $eventId event id
    88      *
    89      * @access public
    90      * @return void
    91      */
    92     function generateHeader($params, $eventId)
    93     {
    94         $this->Course = ClassRegistry::init('Course');
    95         $this->Event = ClassRegistry::init('Event');
    96         $this->User = ClassRegistry::init('User');
    97         $this->UserCourse = ClassRegistry::init('UserCourse');
    98         $this->GroupEvent = ClassRegistry::init('GroupEvent');
    99         $this->EvaluationMixeval = ClassRegistry::init('EvaluationMixeval');
    100         $eventType = array('1' => 'Simple Evaluation', '2' => 'Rubrics Evaluation', '4' => 'Mixed Evaluation');
    101 
    102         $courseId = $this->Event->getCourseByEventId($eventId);
    103         $event = $this->Event->getEventById($eventId);
    104         $course = $this->Course->getCourseWithInstructorsById($courseId);
    105         //$instructors = $this->UserCourse->getInstructors($courseId);
     80     * @param mixed $params params
     81     * @param mixed $event  event
     82     *
     83     * @access public
     84     * @return void
     85     */
     86    function generateHeader($params, $event)
     87    {
    10688        $header = '';
    10789
     
    10991            $header .= "********************************************\n";
    11092            if (!empty($params['include_course'])) {
    111                 $header .= "Course Name : ,,".$course['Course']['title']."\n";
     93                $header .= "Course Name : ,,".$event['Course']['title']."\n";
    11294            }
    11395            if (!empty($params['include_eval_event_names'])) {
     
    11698        }
    11799        if (!empty($params['include_eval_event_type'])) {
    118             $header .= "Evaluation Type : ,,".$eventType[$event['Event']['event_template_type_id']]."\n\n";
     100            $header .= "Evaluation Type : ,,".$this->eventType[$event['Event']['event_template_type_id']]."\n\n";
    119101        }
    120102        if (!empty($params['include_date'])) {
     
    123105        if (!empty($params['include_instructors'])) {
    124106            $header .= "Instructors :,,";
    125             foreach ($course['Instructor'] as $i) {
    126                 if ($this->User->getRoleId($i['id']) == 3) {
    127                     $header .= $i['full_name'].",";
    128                 }
     107            foreach ($event['Course']['Instructor'] as $i) {
     108                $header .= $i['full_name'].",";
    129109            }
    130110        }
     
    138118     * buildSimpleEvaluationScoreTableByEvaluatee
    139119     *
    140      * @param mixed $params      params
    141      * @param mixed $grpEventId  group event id
    142      * @param mixed $evaluateeId evaluatee id
    143      * @param mixed $eventId     event id
    144      *
    145      * @access public
    146      * @return void
    147      */
    148     function buildSimpleEvaluationScoreTableByEvaluatee($params, $grpEventId, $evaluateeId, $eventId)
    149     {
    150         $this->GroupEvent = ClassRegistry::init('GroupEvent');
    151         $this->Group = ClassRegistry::init('Group');
    152         $this->User = ClassRegistry::init('User');
    153         $this->EvaluationSimple = ClassRegistry::init('EvaluationSimple');
    154         $this->Penalty = ClassRegistry::init('Penalty');
    155 
    156         $grpEvent = $this->GroupEvent->getGrpEvent($grpEventId);
    157         $group = $this->Group->getGroupByGroupId($grpEvent['GroupEvent']['group_id']);
    158         $event_info = $this->Event->find(
    159             'first',
    160             array(
    161                 'conditions' => array('Event.id' => $eventId),
    162             )
    163         );
    164         // storing the timestamp of the due date/end date of the event
    165         $event_due = strtotime($event_info['Event']['due_date']);
    166         $event_end = strtotime($event_info['Event']['release_date_end']);
    167 
    168         $groupMembers = $this->ExportHelper2->getGroupMemberHelper($grpEventId);
     120     * @param mixed $params    params
     121     * @param mixed $group     group with group event and member -> role
     122     * @param mixed $evaluatee evaluatee
     123     * @param mixed $event     event
     124     *
     125     * @access public
     126     * @return void
     127     */
     128    function buildSimpleEvaluationScoreTableByEvaluatee($params, $group, $evaluatee, $event, $responses)
     129    {
    169130        // Build grid
    170131        $xDimension = 10;
    171         $yDimensions = count($groupMembers);
     132        $yDimensions = count($group['Member']);
    172133        $grid = $this->ExportHelper2->buildExporterGrid($xDimension, $yDimensions);
    173134        $xPosition = 0;
    174135        $yPosition = 0;
    175136        // Fill in grid Results
    176         $evaluatee = $this->User->findById($evaluateeId);
    177         $yInc = 0; $index = 0;
    178         foreach ($groupMembers as $evaluator) {
     137        $yInc = 0;
     138        foreach ($group['Member'] as $evaluator) {
    179139            $row = array();
    180140            if (!empty($params['include_group_names'])) {
    181                 array_push($row, $group[0]['Group']['group_name']);
     141                array_push($row, $group['Group']['group_name']);
    182142            }
    183143            if (!empty($params['include_student_email'])) {
    184                 array_push($row, $evaluatee['User']['email']);
     144                array_push($row, $evaluatee['email']);
    185145            }
    186146            if (!empty($params['include_student_name'])) {
    187                 array_push($row, $evaluatee['User']['full_name']);
     147                array_push($row, $evaluatee['full_name']);
    188148            }
    189149            if (!empty($params['include_student_id'])) {
    190                 array_push($row, $evaluatee['User']['student_no']);
     150                array_push($row, $evaluatee['student_no']);
    191151            }
    192152            if (!empty($params['include_student_name'])) {
    193                 array_push($row, $evaluator['first_name']." ".$evaluator['last_name']);
     153                array_push($row, $evaluator['full_name']);
    194154            }
    195155            if (!empty($params['include_student_id'])) {
    196156                array_push($row, $evaluator['student_no']);
    197157            }
    198             $simpleEvalResults = $this->EvaluationSimple->getResultsByEvaluatee($grpEventId, $evaluatee['User']['id'], true);
    199             // Save all the submissions; use to find evaluators who haven't submitted yet
    200             $submissionStudentNo = array();
    201             foreach ($simpleEvalResults as $results) {
    202                 array_push($submissionStudentNo, $results['User']['student_no']);
    203             }
    204             // Verify that the evaluator has indeed submitted an evaluator for the current evaluatee; ie the evluator exists in the array
    205             if (!in_array($evaluator['student_no'], $submissionStudentNo)) {
     158
     159            // check if we have a reponse for this evaluator
     160            if (!isset($responses[$evaluatee['id']]) || !array_key_exists($evaluator['id'], $responses[$evaluatee['id']])) {
    206161                $this->ExportHelper2->fillGridHorizonally($grid, $xPosition, $yPosition+$yInc, $row);
    207162                $yInc++;
    208163                continue;
    209164            }
    210             array_push($row, $simpleEvalResults[$index]['EvaluationSimple']['score']);
    211 
    212             $penalty = null;
    213             $event_sub = $this->Event->find(
    214                 'first',
    215                 array(
    216                     'conditions' => array('Event.id' => $eventId),
    217                     'contain' => array('EvaluationSubmission' => array(
    218                         'conditions' => array('EvaluationSubmission.submitter_id' => $evaluateeId)
    219                 )))
     165
     166            $response = $responses[$evaluatee['id']][$evaluator['id']];
     167            array_push($row, $response['EvaluationSimple']['score']);
     168
     169            $penalty = $this->Penalty->calculate(
     170                $event['Event']['due_date'],
     171                $event['Event']['release_date_end'],
     172                $response['EvaluationSubmission']['date_submitted'],
     173                $event['Penalty']
    220174            );
    221             // no submission - if now is after release date end then - gets final deduction
    222             if (empty($event_sub['EvaluationSubmission'])) {
    223                 if (time() > $event_end) {
    224                     $penalty = $this->Penalty->getPenaltyfinal($eventId);
    225                 }
    226             // there is submission - may be on time or late
    227             } else {
    228                 $late_diff = strtotime($event_sub['EvaluationSubmission'][0]['date_submitted']) - $event_due;
    229                 // late
    230                 if (0 < $late_diff) {
    231                     $days_late = $late_diff/(24*60*60);
    232                     $penalty = $this->Penalty->getPenaltyByEventAndDaysLate($eventId, $days_late);
    233                 }
    234             }
    235             if (!empty($penalty)) {
    236                 array_push($row, $penalty['Penalty']['percent_penalty']."%");
     175
     176            if (is_numeric($penalty)) {
     177                array_push($row, $penalty."%");
     178                $finalGrade = $response['EvaluationSimple']['score'] * (1 - ($penalty/100));
    237179            } else {
    238180                array_push($row, "-");
    239             }
    240             $finalGrade = $simpleEvalResults[$index]['EvaluationSimple']['score'] * (1 - ($penalty['Penalty']['percent_penalty']/100));
     181                $finalGrade = $response['EvaluationSimple']['score'];
     182            }
     183
    241184            array_push($row, $finalGrade);
    242185            $this->ExportHelper2->fillGridHorizonally($grid, $xPosition, $yPosition + $yInc, $row);
    243             $index++;
    244186            $yInc++;
    245187        }
     188
    246189        return $this->ExportHelper2->arrayDraw($grid);
    247190    }
     
    258201     * @return void
    259202     */
    260     function buildSimpleEvaluationScoreTableByGroup($params, $grpEventId, $eventId)
    261     {
    262         $groupMembers = $this->ExportHelper2->getGroupMemberWithoutTutorsHelper($grpEventId);
     203    function buildSimpleEvaluationScoreTableByGroup($params, $groupEvent, $event, $results)
     204    {
     205        $this->Group = ClassRegistry::init('Group');
     206        $group = $this->Group->getGroupWithMemberRoleByGroupIdEventId($groupEvent['group_id'], $event['Event']['id']);
    263207        $csv = '';
    264         foreach ($groupMembers as $evaluatee) {
    265             $resultTable = $this->buildSimpleEvaluationScoreTableByEvaluatee($params, $grpEventId, $evaluatee, $eventId);
     208        $responsesByEvaluatee = Set::combine($results, '{n}.EvaluationSimple.evaluator', '{n}', '{n}.EvaluationSimple.evaluatee');
     209        foreach ($group['Member'] as $member) {
     210            // skip the non student member, for now we assume all the evaluatees are students
     211            if ($member['Role']['name'] != 'student') {
     212                continue;
     213            }
     214            $resultTable = $this->buildSimpleEvaluationScoreTableByEvaluatee($params, $group, $member, $event, $responsesByEvaluatee);
    266215            $csv .= $resultTable;
    267216        }
     
    274223     *
    275224     * @param mixed $params  params
    276      * @param mixed $eventId event id
    277      *
    278      * @access public
    279      * @return void
    280      */
    281     function buildSimpleEvaluationScoreTableByEvent($params, $eventId)
    282     {
    283         $this->GroupEvent = ClassRegistry::init('GroupEvent');
     225     * @param mixed $event   event
     226     *
     227     * @access public
     228     * @return void
     229     */
     230    function buildSimpleEvaluationScoreTableByEvent($params, $event, $results)
     231    {
    284232        $csv  = '';
    285         $groupEvents = $this->GroupEvent->getGroupEventByEventId($eventId);
    286         foreach ($groupEvents as $ge) {
    287             $SimpleEvalResultTable =  $this->buildSimpleEvaluationScoreTableByGroup($params, $ge['GroupEvent']['id'], $eventId);
     233        if (empty($event['GroupEvent'])) {
     234            return $csv;
     235        }
     236        foreach ($event['GroupEvent'] as $ge) {
     237            $SimpleEvalResultTable =  $this->buildSimpleEvaluationScoreTableByGroup($params, $ge, $event, $results[$ge['id']]);
    288238            $csv .= $SimpleEvalResultTable."\n";
    289239        }
     
    463413     * @return void
    464414     */
    465     function buildRubricsScoreTableByEvaluatee($params, $grpEventId, $evaluateeId, $eventId)
    466     {
    467         $this->GroupEvent = ClassRegistry::init('GroupEvent');
    468         $this->Group = ClassRegistry::init('Group');
    469         $this->User = ClassRegistry::init('User');
    470         $this->EvaluationRubric = ClassRegistry::init('EvaluationRubric');
    471         $this->Penalty = ClassRegistry::init('Penalty');
    472 
    473         $grpEvent = $this->GroupEvent->getGrpEvent($grpEventId);
    474         $group = $this->Group->getGroupByGroupId($grpEvent['GroupEvent']['group_id']);
    475         $event_info = $this->Event->find(
    476             'first',
    477             array(
    478                 'conditions' => array('Event.id' => $eventId),
    479             )
    480         );
    481         // storing the timestamp of the due date/end date of the event
    482         $event_due = strtotime($event_info['Event']['due_date']);
    483         $event_end = strtotime($event_info['Event']['release_date_end']);
    484 
    485         $groupMembers = $this->ExportHelper2->getGroupMemberHelper($grpEventId);
    486         $questions = $this->ExportHelper2->getEvaluationQuestions($grpEventId);
    487 
    488         // Creat grid
    489         $xDimension = 10 + count($questions);
    490         $yDimensions = count($groupMembers);
    491         $grid = $this->ExportHelper2->buildExporterGrid($xDimension, $yDimensions);
     415    function buildRubricsScoreTableByEvaluatee($params, $group, $evaluatee, $event, $responses)
     416    {
     417        // Build grid
    492418        $xPosition = 0;
    493419        $yPosition = 0;
    494         // Fill in grid with results
    495         $evaluatee = $this->User->findById($evaluateeId);
     420        // Fill in grid Results
    496421        $yInc = 0;
    497         foreach ($groupMembers as $evaluator) {
     422
     423        $xDimension = 10 + count($event['Question']);
     424        $yDimensions = count($group['Member']);
     425        $grid = $this->ExportHelper2->buildExporterGrid($xDimension, $yDimensions);
     426
     427        foreach ($group['Member'] as $evaluator) {
    498428            $row = array();
    499429            if (!empty($params['include_group_names'])) {
    500                 array_push($row, $group[0]['Group']['group_name']);
     430                array_push($row, $group['Group']['group_name']);
    501431            }
    502432            if (!empty($params['include_student_email'])) {
    503                 array_push($row, $evaluatee['User']['email']);
     433                array_push($row, $evaluatee['email']);
    504434            }
    505435            if (!empty($params['include_student_name'])) {
    506                 array_push($row, $evaluatee['User']['full_name']);
     436                array_push($row, $evaluatee['full_name']);
    507437            }
    508438            if (!empty($params['include_student_id'])) {
    509                 array_push($row, $evaluatee['User']['student_no']);
     439                array_push($row, $evaluatee['student_no']);
    510440            }
    511441            if (!empty($params['include_student_name'])) {
     
    515445                array_push($row, $evaluator['student_no']);
    516446            }
    517             $rubricsEvaluation = $this->EvaluationRubric->getEvalRubricByGrpEventIdEvaluatorEvaluatee($grpEventId, $evaluator['id'], $evaluateeId);
    518             // check to see evaluator has sumbitted an evaluation
    519             if (empty($rubricsEvaluation)) {
     447
     448            // check if we have a reponse for this evaluator
     449            if (!isset($responses[$evaluatee['id']]) || !array_key_exists($evaluator['id'], $responses[$evaluatee['id']])) {
    520450                $this->ExportHelper2->fillGridHorizonally($grid, $xPosition, $yPosition+$yInc, $row);
    521451                $yInc++;
    522452                continue;
    523453            }
    524             $rubricsEvalResult = $rubricsEvaluation['EvaluationRubricDetail'];
    525             foreach ($rubricsEvalResult as $result) {
     454
     455            $response = $responses[$evaluatee['id']][$evaluator['id']];
     456            foreach ($response['EvaluationRubricDetail'] as $result) {
    526457                array_push($row, $result['grade']);
    527458            }
    528             array_push($row, $rubricsEvaluation['EvaluationRubric']['score']);
    529 
    530             $penalty = null;
    531             $event_sub = $this->Event->find(
    532                 'first',
    533                 array(
    534                     'conditions' => array('Event.id' => $eventId),
    535                     'contain' => array('EvaluationSubmission' => array(
    536                         'conditions' => array('EvaluationSubmission.submitter_id' => $evaluateeId)
    537                 )))
     459            array_push($row, $response[$this->responseModelName]['score']);
     460
     461            $penalty = $this->Penalty->calculate(
     462                $event['Event']['due_date'],
     463                $event['Event']['release_date_end'],
     464                $response['EvaluationSubmission']['date_submitted'],
     465                $event['Penalty']
    538466            );
    539             // no submission - if now is after release date end then - gets final deduction
    540             if (empty($event_sub['EvaluationSubmission'])) {
    541                 if (time() > $event_end) {
    542                     $penalty = $this->Penalty->getPenaltyfinal($eventId);
    543                 }
    544             // there is submission - may be on time or late
     467
     468            if (is_numeric($penalty)) {
     469                array_push($row, $penalty."%");
     470                $finalGrade = $response[$this->responseModelName]['score'] * (1 - ($penalty/100));
    545471            } else {
    546                 $late_diff = strtotime($event_sub['EvaluationSubmission'][0]['date_submitted']) - $event_due;
    547                 // late
    548                 if (0 < $late_diff) {
    549                     $days_late = $late_diff/(24*60*60);
    550                     $penalty = $this->Penalty->getPenaltyByEventAndDaysLate($eventId, $days_late);
    551                 }
    552             }
    553 
    554             if (!empty($penalty)) {
    555                 array_push($row, $penalty['Penalty']['percent_penalty']."%");
    556             } else {
    557                 array_push($row, "--");
    558             }
    559             $finalGrade = $rubricsEvaluation['EvaluationRubric']['score'] * (1 - ($penalty['Penalty']['percent_penalty']/100));
    560             array_push($row, number_format($finalGrade, 2));
     472                array_push($row, "-");
     473                $finalGrade = $response[$this->responseModelName]['score'];
     474            }
     475
     476            array_push($row, $finalGrade);
    561477            $this->ExportHelper2->fillGridHorizonally($grid, $xPosition, $yPosition + $yInc, $row);
    562478            $yInc++;
     
    576492     * @return void
    577493     */
    578     function buildRubricsEvalTableByGroupEvent($params, $grpEventId, $eventId)
    579     {
    580         $groupMembers = $this->ExportHelper2->getGroupMemberWithoutTutorsHelper($grpEventId);
     494    function buildRubricsEvalTableByGroupEvent($params, $groupEvent, $event, $results)
     495    {
     496        $this->Group = ClassRegistry::init('Group');
     497        $group = $this->Group->getGroupWithMemberRoleByGroupIdEventId($groupEvent['group_id'], $event['Event']['id']);
    581498        $csv = '';
    582         foreach ($groupMembers as $evaluatee) {
    583             $resultTable =  $this->buildRubricsScoreTableByEvaluatee($params, $grpEventId, $evaluatee['id'], $eventId);
     499        $responsesByEvaluatee = Set::combine($results, '{n}.'.$this->responseModelName.'.evaluator', '{n}', '{n}.'.$this->responseModelName.'.evaluatee');
     500        foreach ($group['Member'] as $member) {
     501            // skip the non student member, for now we assume all the evaluatees are students
     502            if ($member['Role']['name'] != 'student') {
     503                continue;
     504            }
     505            $resultTable = $this->buildRubricsScoreTableByEvaluatee($params, $group, $member, $event, $responsesByEvaluatee);
    584506            $csv .= $resultTable;
    585507        }
     
    592514     *
    593515     * @param mixed $params  params
    594      * @param mixed $eventId event id
    595      *
    596      * @access public
    597      * @return void
    598      */
    599     function buildRubricsEvalTableByEventId($params, $eventId)
    600     {
    601         $this->GroupEvent = ClassRegistry::init('GroupEvent');
    602         $groupEvents = $this->GroupEvent->getGroupEventByEventId($eventId);
    603         $csv = '';
    604         foreach ($groupEvents as $ge) {
    605             $resultTable = $this->buildRubricsEvalTableByGroupEvent($params, $ge['GroupEvent']['id'], $eventId);
     516     * @param mixed $event   event
     517     * @param mixed $results results
     518     *
     519     * @access public
     520     * @return void
     521     */
     522    function buildRubricsEvalTableByEventId($params, $event, $results)
     523    {
     524        $csv  = '';
     525        if (empty($event['GroupEvent'])) {
     526            return $csv;
     527        }
     528        foreach ($event['GroupEvent'] as $ge) {
     529            $resultTable =  $this->buildRubricsEvalTableByGroupEvent($params, $ge, $event, $results[$ge['id']]);
    606530            $csv .= $resultTable."\n";
    607531        }
  • app/controllers/components/export_csv.php

    r1eaa7ac raf4a71f  
    104104    }
    105105
    106 
    107     /**
    108      * createMixEvalCsvSubHeader
     106    /**
     107     * createCsvSubHeader
     108     *
     109     * @param mixed $params    params
     110     * @param mixed $questions questions
     111     *
     112     * @access public
     113     * @return void
     114     */
     115    function createCsvSubHeader($params, $questions)
     116    {
     117        $subHeader = '';
     118        $this->creteCsvSubHeaderHelper($params, $subHeader);
     119        foreach ($questions as $key => $question) {
     120            $subHeader .= "Q".($key+1)." ( /".$question['multiplier']."), ";
     121        }
     122        $subHeader .= "Raw Score, Late Penalty, Final Score";
     123        return $subHeader;
     124    }
     125
     126
     127    /**
     128     * createCsv
    109129     *
    110130     * @param mixed $params  params
     
    114134     * @return void
    115135     */
    116     function createMixEvalCsvSubHeader($params, $eventId)
    117     {
    118         $this->Event = ClassRegistry::init('Event');
    119         $this->MixevalsQuestion = ClassRegistry::init('MixevalsQuestion');
    120         $event = $this->Event->getEventById($eventId);
    121         $questions = $this->MixevalsQuestion->getQuestion($event['Event']['template_id'], 'S');
    122 
    123         $subHeader = '';
    124         $this->creteCsvSubHeaderHelper($params, $subHeader);
    125         for ($i=0; $i<count($questions); $i++) {
    126             $subHeader .= "Q".($i+1)." (/".$questions[$i]['MixevalsQuestion']['multiplier']."), ";
    127         }
    128         $subHeader .= "Raw Score, Late Penalty, Final Score";
    129         return $subHeader;
    130     }
    131 
    132 
    133     /**
    134      * createRubricsMixEvalCsvSubHeader
    135      *
    136      * @param mixed $params  params
    137      * @param mixed $eventId event id
    138      *
    139      * @access public
    140      * @return void
    141      */
    142     function createRubricsMixEvalCsvSubHeader($params, $eventId)
    143     {
    144         $this->Event = ClassRegistry::init('Event');
    145         $this->Rubric = ClassRegistry::init('Rubric');
    146         $this->RubricsCriteria = ClassRegistry::init('RubricsCriteria');
    147 
    148         $event = $this->Event->getEventById($eventId);
    149         $rubric = $this->Rubric->getRubricById($event['Event']['template_id']);
    150         $rubricCriterias = $this->RubricsCriteria->getCriteria($rubric['Rubric']['id']);
    151 
    152         $subHeader = '';
    153         $this->creteCsvSubHeaderHelper($params, $subHeader);
    154         for ($i=1; $i<=$rubric['Rubric']['criteria']; $i++) {
    155             $rubricCriteriaMark = $rubricCriterias[$i-1]['RubricsCriteria']['multiplier'];
    156             $subHeader .= "Q".$i." ( /".$rubricCriteriaMark."), ";
    157         }
    158         $subHeader .= "Raw Score, Late Penalty, Final Score";
    159         return $subHeader;
    160     }
    161 
    162 
    163     /**
    164      * createSimpleCsvSubHeader
    165      *
    166      * @param mixed $params params
    167      *
    168      * @access public
    169      * @return void
    170      */
    171     function createSimpleCsvSubHeader($params)
    172     {
    173         $subHeader = '';
    174         $this->creteCsvSubHeaderHelper($params, $subHeader);
    175         $subHeader .= "Raw Grade";
    176         $subHeader .= ",Mark Penalty";
    177         $subHeader .= ",Final Grade";
    178         return $subHeader;
    179     }
    180 
    181 
    182     /**
    183      * createCsv
    184      *
    185      * @param mixed $params  params
    186      * @param mixed $eventId event id
    187      *
    188      * @access public
    189      * @return void
    190      */
    191     function createCsv($params, $eventId)
    192     {
    193         $this->GroupEvent = ClassRegistry::init('GroupEvent');
    194         $this->Event = ClassRegistry::init('Event');
    195 
    196         $event = $this->Event->getEventById($eventId);
    197 
    198         $groupEvents = $this->GroupEvent->getGroupsByEventId($eventId);
     136    function createCsv($params, $event)
     137    {
     138        $contain = array(1 => false, 2 => array('EvaluationRubricDetail'), 4 => array('EvaluationMixevalDetail'));
    199139        $csv = '';
    200         $eventHeader = $this->generateHeader($params, $eventId);
     140        $eventHeader = $this->generateHeader($params, $event);
    201141        $csv = $eventHeader."\n";
     142        $groupEvents = $event['GroupEvent'];
     143        $groupEventIds = Set::extract($groupEvents, '/id');
     144        $this->responseModelName = EvaluationResponseBase::$types[$event['Event']['event_template_type_id']];
     145        $this->responseModel = ClassRegistry::init($this->responseModelName);
     146        $this->evaluationModelName = EvaluationBase::$types[$event['Event']['event_template_type_id']];
     147        $this->evaluationModel = ClassRegistry::init($this->evaluationModelName);
     148        $results = $this->responseModel->getSubmittedResultsByGroupEvent($groupEventIds, $contain[$event['Event']['event_template_type_id']]);
     149        $results = Set::combine($results, '{n}.'.$this->responseModelName.'.id', '{n}', '{n}.'.$this->responseModelName.'.grp_event_id');
     150        $evaluation = $this->evaluationModel->getEvaluation($event['Event']['template_id']);
     151        $event = array_merge($event, $evaluation);
     152
     153        $subHeader = $this->createCsvSubHeader($params, $event['Question']);
     154        $csv .= $subHeader."\n\n";
    202155
    203156        switch($event['Event']['event_template_type_id']) {
    204157        case 1:
    205             $subHeader = $this->createSimpleCsvSubHeader($params);
    206             $csv .= $subHeader."\n\n";
    207             $resultTable = $this->buildSimpleEvaluationScoreTableByEvent($params, $eventId);
     158            $resultTable = $this->buildSimpleEvaluationScoreTableByEvent($params, $event, $results);
    208159            $csv .= $resultTable;
    209160            break;
    210161
    211162        case 2:
    212             $subHeader = $this->createRubricsMixEvalCsvSubHeader($params, $eventId);
    213             $csv .= $subHeader."\n\n";
    214             $resultTable = $this->buildRubricsEvalTableByEventId($params, $eventId);
     163            $resultTable = $this->buildRubricsEvalTableByEventId($params, $event, $results);
    215164            $csv .= $resultTable;
    216165            break;
    217166
    218167        case 4:
    219             $subHeader = $this->createMixEvalCsvSubHeader($params, $eventId);
    220             $csv .= $subHeader."\n\n";
    221168            foreach ($groupEvents as $ge) {
    222                 $resultTable = $this->buildMixedEvalScoreTableByGroupEvent($params, $ge['GroupEvent']['id'], $eventId);
     169                $resultTable = $this->buildMixedEvalScoreTableByGroupEvent($params, $ge['id'], $event['Event']['id']);
    223170                $csv .= $resultTable;
    224171            }
     
    228175        return $csv;
    229176    }
    230 
    231 
    232     /**
    233      * createExcel
    234      *
    235      * @param mixed $params  params
    236      * @param mixed $eventId event id
    237      *
    238      * @access public
    239      * @return void
    240      */
    241     function createExcel($params, $eventId)
    242     {
    243         $this->Event = ClassRegistry::init('Event');
    244         $this->Group = ClassRegistry::init('Group');
    245         // Prepare header.
    246         $CSV = '';
    247         $header = $this->generateHeader($params, $eventId);
    248         $CSV .= $header."\n";
    249         $groupEvents = $this->GroupEvent->getGroupEventByEventId($eventId);
    250         $event = $this->Event->getEventById($eventId);
    251         switch($event['Event']['event_template_type_id']){
    252             // Simple Evaluation
    253         case 1 :
    254             for ($i=0; $i<count($groupEvents); $i++) {
    255                 $group = $this->Group->getGroupByGroupId($groupEvents[$i]['GroupEvent']['group_id']);
    256                 $grpEventId = $groupEvents[$i]['GroupEvent']['id'];
    257                 $groupMembers = $this->GroupEvent->getGroupMembers($grpEventId);
    258                 if (!empty($params['include_group_names'])) {
    259                     $CSV .= "Group Name : ".$group[0]['Group']['group_name']."\n";
    260                 }
    261                 if (!empty($params['simple_eval_grade_table'])) {
    262                     $simpleResults = $this->buildSimpleEvalResults($groupEvents[$i]['GroupEvent']['id'], $params);
    263                     $CSV .= $simpleResults."\n\n";
    264                 }
    265                 if (!empty($params['simple_evaluator_comment'])) {
    266                     $CSV .= "Simple Evaluation Comments :\n\n";
    267                     foreach ($groupMembers as $evaluatee) {
    268                         $simpleEvalComments = $this->buildSimpleOrRubricsCommentByEvaluatee($grpEventId, $evaluatee['GroupsMembers']['user_id'], $params, 'S');
    269                         $CSV .= $simpleEvalComments."\n";
    270                     }
    271                 }
    272             }
    273             break;
    274 
    275             //Rubrics Evaluation Event
    276         case 2:
    277             for ($i=0; $i<count($groupEvents); $i++) {
    278                 $grpEventId = $groupEvents[$i]['GroupEvent']['id'];
    279                 $group = $this->Group->getGroupByGroupId($groupEvents[$i]['GroupEvent']['group_id']);
    280                 $groupMembers = $this->GroupEvent->getGroupMembers($grpEventId);
    281                 if (!empty($params['include_group_names'])) {
    282                     $CSV .= "Group Name : ".$group[0]['Group']['group_name']."\n\n";
    283                 }
    284                 if (!empty($params['rubric_criteria_marks'])) {
    285                     $CSV .= "Rubrics Evaluation Grade Tables:\n\n";
    286                     $gradeTable = $this->buildRubricsResultTable($params, $grpEventId);
    287                     $CSV .= $gradeTable."\n";
    288                 }
    289                 if (!empty($params['rubric_general_comments'])) {
    290                     $CSV .= "Rubrics General Comments\n\n";
    291                     foreach ($groupMembers as $evaluatee) {
    292                         $rubricGeneralComments = $this->buildSimpleOrRubricsCommentByEvaluatee($grpEventId, $evaluatee['GroupsMembers']['user_id'], $params, 'R');
    293                         $CSV .= $rubricGeneralComments."\n";
    294                     }
    295                 }
    296             }
    297             return $CSV;
    298             break;
    299 
    300             // Mixed Evaluation Event
    301         case 4 :
    302             for ($i=0; $i<count($groupEvents); $i++) {
    303                 $grpEventId = $groupEvents[$i]['GroupEvent']['id'];
    304                 $group = $this->Group->getGroupByGroupId($groupEvents[$i]['GroupEvent']['group_id']);
    305                 $groupMembers = $this->GroupEvent->getGroupMembers($grpEventId);
    306                 if (!empty($params['include_group_names'])) {
    307                     $CSV .= "Group Name : ".$group[0]['Group']['group_name']."\n\n\n";
    308                 }
    309                 if (!empty($params['include_mixeval_grades'])) {
    310                     $CSV .= "Part 1: Licket Scale Questions Grade Table :\n\n";
    311                     $gradeTable = $this->buildMixevalResult($params, $groupEvents[$i]['GroupEvent']['id'], $groupMembers[$i]['GroupsMembers']['id']);
    312                     $CSV .= $gradeTable."\n\n";
    313                 }
    314                 if (!empty($params['include_mixeval_question_comment'])) {
    315                     $CSV .= "Part 2: Comment Question Results :\n\n";
    316                     $questionComments = $this->buildMixEvalQuestionCommentTable($params, $grpEventId);
    317                     $CSV .= $questionComments."\n\n";
    318                 }
    319             }
    320             break;
    321 
    322         default: throw new Exception("Event id input seems to be invalid!");
    323         }
    324         return $CSV;
    325     }
    326 
    327177
    328178    /**
  • app/controllers/components/export_excel.php

    r1eaa7ac raf4a71f  
    617617     * @return void
    618618     */
    619     function createExcel($params, $eventId)
     619    function createExcel($params, $event)
    620620    {
    621621        // Prepare header.
    622         $header = $this->generateHeader2($params, $eventId, 'fsa');
     622        $header = $this->generateHeader2($params, $event, 'fsa');
    623623        $this->_drawToExcelSheetAtCoordinates($header, $this->cursor['x'], $this->cursor['y']);
    624624        $this->_setFontSizeVertically(1, count($header[0])-1, 'A', 16);
    625625        $this->cursor['y'] += (count($header[0]));
    626         $groupEvents = $this->GroupEvent->getGroupEventByEventId($eventId);
    627         $event = $this->Event->getEventById($eventId);
     626        $groupEvents = $event['GroupEvent'];
    628627        switch($event['Event']['event_template_type_id']){
     628        case 1 :
    629629            // Simple Evaluation
    630         case 1 :
    631630            for ($i=0; $i<count($groupEvents); $i++) {
    632                 $group = $this->Group->getGroupByGroupId($groupEvents[$i]['GroupEvent']['group_id']);
    633                 $grpEventId = $groupEvents[$i]['GroupEvent']['id'];
     631                $group = $this->Group->getGroupByGroupId($groupEvents[$i]['group_id']);
     632                $grpEventId = $groupEvents[$i]['id'];
    634633                $groupMembers = $this->GroupEvent->getGroupMembers($grpEventId);
    635634                $groupMembersNoTutors = $this->ExportHelper2->getGroupMemberWithoutTutorsHelper($grpEventId);
  • app/controllers/evaluations_controller.php

    r1eaa7ac raf4a71f  
    232232    function export($type, $id)
    233233    {
    234         // Make sure the present user has Permission
    235         if (!User::hasPermission('functions/evaluation/export')) {
    236             $this->Session->setFlash(__('Error: You do not have permission to export evaluation results', true));
    237             $this->redirect('/home');
    238         }
    239 
    240234        // $type must be course or event
    241235        if ('course' != $type && 'event' != $type) {
    242236            $this->Session->setFlash('Error: Invalid export type', true);
    243237            $this->redirect('/courses');
     238            return;
    244239        } else if (!is_numeric($id)) {
    245240            $this->Session->setFlash(__('Error: Invalid id', true));
    246241            $this->redirect('/courses');
     242            return;
    247243        }
    248244
     
    291287            $this->autoRender = false;
    292288
     289            if (!($event = $this->Event->getAccessibleEventById($this->params['form']['event_id'], User::get('id'), User::getCourseFilterPermission(), array('Course' => array('Instructor'), 'GroupEvent', 'EventTemplateType', 'Penalty' => array('order' => array('days_late ASC')))))) {
     290                $this->Session->setFlash(__('Error: That event does not exist or you dont have access to it', true));
     291                $this->redirect('index');
     292                return;
     293            }
     294
    293295            $fileName = isset($this->params['form']['file_name']) && !empty($this->params['form']['file_name']) ? $this->params['form']['file_name']:date('m.d.y');
    294296            switch($this->params['form']['export_type']) {
    295297            case "csv" :
    296                 $fileContent = $this->ExportCsv->createCsv($this->params['form'], $this->params['form']['event_id']);
     298                $fileContent = $this->ExportCsv->createCsv($this->params['form'], $event);
    297299                break;
    298300            case "excel" :
    299                 $fileContent = $this->ExportExcel->createExcel($this->params['form'], $this->params['form']['event_id']);
     301                $fileContent = $this->ExportExcel->createExcel($this->params['form'], $event);
    300302                break;
    301303            default :
     
    304306            header('Content-Type: application/csv');
    305307            header('Content-Disposition: attachment; filename=' . $fileName . '.csv');
     308            $this->log($this->User->getDataSource()->getLog(false, false), 'debug');
    306309            echo $fileContent;
    307             //    }
    308310        } else {
    309311            // Set up data
     
    317319     * @param mixed $eventId  event id
    318320     * @param mixed $objectId object id
     321     *
    319322     * @access public
    320323     * @return void
  • app/models/evaluation_base.php

    r1eaa7ac raf4a71f  
    1212class EvaluationBase extends AppModel
    1313{
     14    public static $types = array(1 => 'SimpleEvaluation', 2 => 'Rubric', 4 => 'Mixeval');
    1415    public $name = 'EvaluationBase';
    1516    public $actsAs = array('ExtendAssociations', 'Containable', 'Habtamable', 'Traceable');
     
    198199        return $userPenalty;
    199200    }
    200 
    201 
    202201}
  • app/models/evaluation_rubric.php

    r1eaa7ac raf4a71f  
    11<?php
     2App::import('Model', 'EvaluationResponseBase');
     3
    24/**
    35 * EvaluationRubric
     
    911 * @license   MIT {@link http://www.opensource.org/licenses/MIT}
    1012 */
    11 class EvaluationRubric extends AppModel
     13class EvaluationRubric extends EvaluationResponseBase
    1214{
    1315    public $name = 'EvaluationRubric';
    14     public $actsAs = array('Traceable');
     16    public $useTable = null;
    1517
    1618    public $hasMany = array(
  • app/models/evaluation_simple.php

    r1eaa7ac raf4a71f  
    11<?php
     2App::import('Model', 'EvaluationResponseBase');
    23
    34/**
     
    1011 * @license   MIT {@link http://www.opensource.org/licenses/MIT}
    1112 */
    12 class EvaluationSimple extends AppModel
     13class EvaluationSimple extends EvaluationResponseBase
    1314{
    1415    public $name = 'EvaluationSimple';
    15     public $actsAs = array('Traceable');
     16    public $useTable = null;
    1617
    1718    public $belongsTo = array(
     
    3435    function getEvalMarkByGrpEventIdEvaluatorEvaluatee($grpEventId=null, $evaluator=null, $evaluatee=null)
    3536    {
    36         //return $this->find('grp_event_id='.$grpEventId.' AND evaluator='.$evaluator.' AND evaluatee='.$evaluatee);
    3737        return $this->find('first', array(
    3838            'conditions' => array('grp_event_id' => $grpEventId, 'evaluator' => $evaluator, 'evaluatee' => $evaluatee)
     
    5252    function getResultsByEvaluator($grpEventId=null, $evaluator=null)
    5353    {
    54         //return $this->find('all', 'grp_event_id='.$grpEventId.' AND evaluator='.$evaluator);
    5554        return $this->find('all', array(
    5655            'conditions' => array('grp_event_id' => $grpEventId, 'evaluator' => $evaluator)
  • app/models/group_event.php

    r1eaa7ac raf4a71f  
    3636        'EvaluationSubmission' => array(
    3737            'className' => 'EvaluationSubmission',
     38            'conditions' => '',
     39            'order' => '',
     40            'dependent' => true,
     41            'foreignKey' => 'grp_event_id'
     42        ),
     43        'EvaluationSimple' => array(
     44            'className' => 'EvaluationSimple',
    3845            'conditions' => '',
    3946            'order' => '',
  • app/models/rubric.php

    r1eaa7ac raf4a71f  
    333333        return $ret;
    334334    }
     335
     336    public function getEvaluation($id)
     337    {
     338        $eval = $this->find('first', array('conditions' => array($this->alias.'.id' => $id), 'contain' => 'RubricsCriteria'));
     339        if ($eval) {
     340            $eval['Question'] = $eval['RubricsCriteria'];
     341            unset($eval['RubricsCriteria']);
     342        }
     343
     344        return $eval;
     345    }
    335346}
  • app/models/simple_evaluation.php

    r1eaa7ac raf4a71f  
    2929        ),
    3030    );
    31    
     31
    3232    public $validate = array(
    3333        'availability' => array(
     
    3737    );
    3838
     39    public function getEvaluation($id)
     40    {
     41        $eval = $this->find('first', array('conditions' => array($this->alias.'.id' => $id), 'contain' => false));
     42        if ($eval) {
     43            $eval['Question'] = array();
     44        }
     45
     46        return $eval;
     47    }
    3948}
  • app/vendors/shells/create_acl.php

    r1eaa7ac raf4a71f  
    125125        $eval = $this->Acl->Aco->save();
    126126        $eval['Aco']['id'] = $this->Acl->Aco->id;
    127 
    128         $this->Acl->Aco->create(array('parent_id' => $eval['Aco']['id'], 'model' => null, 'alias' => 'export'));
    129         $this->Acl->Aco->save();
    130127
    131128        // functions/email
Note: See TracChangeset for help on using the changeset viewer.