Changeset 6609ae7 in iPeer


Ignore:
Timestamp:
2012-12-13T14:11:32-08:00 (6 years ago)
Author:
John Hsu <john.hsu@…>
Branches:
3.1.x, dev, hotfix, master, pagodabox, ticket463
Children:
08da167
Parents:
9503c0d
git-author:
John Hsu <john.hsu@…> (12/13/2012 02:04:00 PM)
git-committer:
John Hsu <john.hsu@…> (12/13/2012 02:11:32 PM)
Message:

Student home: fix submitted/upcoming display.

Submitted surveys and evaluations weren't showing up properly due to
improper splitting by the controller. The event model was also using
more queries than necessary to retrive event data.

Changed the Due In/Late? By field display to be color coded (late dates
will be red) and finer grained. Instead of just showing days, it'll now
properly adjust from days to hours/minutes and then finally to
minutes/seconds.

Use the htmlhelper's tableCells function to create the tables.

Location:
app
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • app/controllers/home_controller.php

    r9503c0d r6609ae7  
    4242    {
    4343        if (User::hasPermission('functions/coursemanager')) {
    44             //General Home Rendering for others
     44            // Admins and profs
    4545            $course_list = $this->Course->getAllAccessibleCourses(User::get('id'), User::getCourseFilterPermission(), 'all', array('contain' => array('Event', 'Instructor')));
    4646            $this->set('course_list', $this->_formatCourseList($course_list));
    47         } else {
    48             // student and tutor
    49             $events = $this->Event->getEventsByUserId(User::get('id'));
    50             $submitted = $upcoming = array();
    51             foreach ($events as $event) {
    52                 if (isset($event['EvaluationSubmission']['id'])||$event['Event']['is_ended']) {
    53                     $submitted[] = $event;
    54                 } else {
    55                     $upcoming[] = $event;
     47            return;
     48        }
     49
     50        // Student and tutor
     51       
     52        // TODO
     53        // make sure that submitted surveys CAN be viewed
     54        // make a summary section that tells students if there are any urgently
     55        //  due assignments
     56        $events = $this->Event->getEventsByUserId(User::get('id'));
     57
     58        // mark events as late if past due date
     59        foreach ($events as &$type) {
     60            foreach ($type as &$event) {
     61                if ($event['Event']['due_in'] > 0) {
     62                    $event['late'] = false;
     63                    continue;
     64                }
     65                $event['late'] = true;
     66            }
     67        }
     68
     69        // determine the proper penalty to be applied to a late eval
     70        foreach ($events['Evaluations'] as &$event) {
     71            if (!$event['late'] || empty($event['Penalty'])) {
     72                continue;
     73            }
     74            // convert seconds to days
     75            $daysLate = abs($event['Event']['due_in']) / 86400;
     76            $pctPenalty = 0;
     77            foreach ($event['Penalty'] as $penalty) {
     78                $pctPenalty = $penalty['percent_penalty'];
     79                if ($penalty['days_late'] > $daysLate) {
     80                    break;
    5681                }
    5782            }
    58             $this->set('submitted', $submitted);
    59             $this->set('upcoming', $upcoming);
    60             $this->render('studentIndex');
     83            $event['percent_penalty'] = $pctPenalty;
    6184        }
     85
     86        // format the 'due in' time interval for display
     87        foreach ($events as &$types) {
     88            foreach ($types as &$event) {
     89                $event['Event']['due_in'] = $this->_formatDueIn(
     90                    abs($event['Event']['due_in']));
     91            }
     92        }
     93
     94        $evals = $this->_splitSubmittedEvents($events['Evaluations']);
     95        $surveys = $this->_splitSubmittedEvents($events['Surveys']);
     96        $this->set('evals', $evals);
     97        $this->set('surveys', $surveys);
     98        $this->render('studentIndex');
     99    }
     100
     101    /**
     102     * Take the due interval, which is in seconds, and format
     103     * it something that's easier for users to read.
     104     * */
     105    private function _formatDueIn($seconds)
     106    {
     107        $ret = "";
     108        if ($seconds > 86400) {
     109            $ret = round($seconds / 86400, 1) . __(' days', true);
     110        }
     111        elseif ($seconds < 3600) {
     112            $minutes = (int) ($seconds / 60);
     113            $seconds = $seconds % 60;
     114            $ret = $minutes . __(' minutes ', true) . $seconds
     115                . __(' seconds', true);
     116        }
     117        else {
     118            $hours = (int) ($seconds / 3600);
     119            $minutes = (int) ($seconds % 3600 / 60);
     120            $ret = $hours . __(' hours ', true) . $minutes .
     121                __(' minutes', true);
     122        }
     123        return $ret;
     124    }
     125
     126    /**
     127     * Helper for index to split an array of survey  or
     128     * evaluation events into events that has submissions
     129     * and events that don't have any submissions.
     130     *
     131     * @param array $events - list of events info returned from the event model,
     132     *  each event MUST have an 'EvaluationSubmission' array or this won't work
     133     *
     134     * @return Split the events array into 'upcoming' or 'submitted' categories
     135     * */
     136    private function _splitSubmittedEvents($events)
     137    {
     138        $submitted = $upcoming = array();
     139        foreach ($events as $event) {
     140            if (empty($event['EvaluationSubmission']) ||
     141                $event['Event']['is_ended']
     142            ){
     143                $upcoming[] = $event;
     144            } else {
     145                $submitted[] = $event;
     146            }
     147        }
     148        return array('upcoming' => $upcoming, 'submitted' => $submitted);
    62149    }
    63150
  • app/models/event.php

    r9503c0d r6609ae7  
    149149        $this->virtualFields['student_count'] = sprintf('SELECT count(*) as count FROM group_events as vge RIGHT JOIN groups_members as vgm ON vge.group_id = vgm.group_id WHERE vge.event_id = %s.id', $this->alias);
    150150        $this->virtualFields['completed_count'] = sprintf('SELECT count(*) as count FROM evaluation_submissions as ves WHERE ves.submitted = 1 AND ves.event_id = %s.id', $this->alias);
    151         $this->virtualFields['due_in'] = 'DATEDIFF(due_date, NOW())';
     151        $this->virtualFields['due_in'] = 'TIMESTAMPDIFF(SECOND,NOW(),due_date)';
    152152    }
    153153
     
    550550
    551551    /**
    552      * getEventsByUserId get events that associated with a specific user
    553      *
     552     * Get evaluations and surveys assigned to the given user. Also gets the
     553     * evaluation submission entries made by this specific user.
     554     *
    554555     * @param mixed $userId
    555556     *
     
    559560    function getEventsByUserId($userId)
    560561    {
     562        // get the groups that this user is in
    561563        $groups = $this->Group->find('all', array(
    562564            'conditions' => array('Member.id' => $userId),
     
    565567        $groupIds = Set::extract('/Group/id', $groups);
    566568
    567         // find evaluation events
     569        // find evaluation events based on the groups this user is in
    568570        $evaluationEvents = $this->find('all', array(
    569571            'conditions' => array('Group.id' => $groupIds),
     572            'order' => array('due_in ASC'),
    570573            'contain' => array(
    571574                'Course',
    572575                'Group',
    573576                'Penalty' => array(
    574                     'conditions' => array(
    575                         'OR' => array(
    576                             array('days_late' => 'Event.due_in'),
    577                             array('days_late <' => 0)
    578                         )
    579                     ),
    580                     'order' => array('days_late DESC')
     577                    'order' => array('days_late ASC')
     578                ),
     579                'EvaluationSubmission' => array(
     580                    'conditions' => array('submitter_id' => $userId),
    581581                )
    582582            )
    583583        ));
    584584
    585         // find submission separately, doesn't work within above query
    586         $submissions = $this->GroupEvent->EvaluationSubmission->getEvalSubmissionByGrpEventIdSubmitter(Set::extract('/GroupEvent/id', $evaluationEvents), $userId);
    587         foreach ($submissions as $submission) {
    588             foreach ($evaluationEvents as $key => $event) {
    589                 if ($submission['EvaluationSubmission']['grp_event_id'] == $event['GroupEvent']['id']) {
    590                     $evaluationEvents[$key]['EvaluationSubmission'] = $submission['EvaluationSubmission'];
    591                 }
    592             }
    593         }
    594 
    595         // find survey events
    596         $this->bindModel(array(
    597             'hasOne' => array(
    598                 'EvaluationSubmission' => array('conditions' => array('EvaluationSubmission.submitter_id' => $userId))
    599         )));
     585        // find survey events based on the groups this user is in
    600586        $surveyEvents = $this->find('all', array(
    601587            'conditions' => array('event_template_type_id' => '3'),
     588            'order' => array('due_in ASC'),
    602589            'contain' => array(
    603590                'Course',
    604                 'EvaluationSubmission',
     591                'EvaluationSubmission' => array(
     592                    'conditions' => array('submitter_id' => $userId),
     593                ),
    605594            )
    606595        ));
    607596
    608         // clean up the empty EvaluationSubmissions, Cake put them in even if they are empty
    609         foreach ($surveyEvents as $key => $events) {
    610             if (!isset($events['EvaluationSubmission']['id']) || empty($events['EvaluationSubmission']['id'])) {
    611                 unset($surveyEvents[$key]['EvaluationSubmission']);
    612             }
    613         }
    614 
    615         return array_merge($evaluationEvents, $surveyEvents);
     597        return array('Evaluations' => $evaluationEvents,
     598            'Surveys' => $surveyEvents);
    616599    }
    617600
  • app/views/home/student_index.ctp

    r9503c0d r6609ae7  
    11<?php
    2 $surveyEvents = Set::extract($upcoming, '/Event[event_template_type_id=3]/..');
    3 $evalEvents = Set::extract($upcoming, '/Event[event_template_type_id!=3]/..');
     2function getUpcomingTableArray($html, $events) {
     3    $ret = array();
     4    foreach ($events as $event) {
     5        $tmp = array();
     6        if (isset($event['Group']['group_name'])) {
     7            $tmp[] = $html->link($event['Event']['title'],
     8                '/evaluations/makeEvaluation/'.$event['Event']['id'].'/'.
     9                $event['Group']['id']);
     10            $tmp[] = $event['Group']['group_name'];
     11        }
     12        else {
     13            $tmp[] = $html->link($event['Event']['title'],
     14                '/evaluations/makeEvaluation/'.$event['Event']['id']);
     15        }
     16        $tmp[] = $event['Course']['course'];
     17        $tmp[] = Toolkit::formatDate($event['Event']['due_date']);
     18
     19        $due = $event['Event']['due_in'];
     20        if ($event['late']) {
     21            $penalty = isset($event['percent_penalty']) ?
     22                ', ' . $event['percent_penalty'] . '&#37; penalty' : '';
     23            $tmp[] = "<span class='red'>$due</span>$penalty";
     24        }
     25        else {
     26            $tmp[] = $due;
     27        }
     28
     29        $ret[] = $tmp;
     30    }
     31    return $ret;
     32}
     33
     34$evalUpcoming = getUpcomingTableArray($html, $evals['upcoming']);
     35$surveyUpcoming = getUpcomingTableArray($html, $surveys['upcoming']);
    436?>
    537
    638<h3>Peer Evaluations Due</h3>
    7 <div>
    8     <table class='standardtable'>
     39<table class='standardtable'>
    940    <tr>
    10        <th width='30%'>Event</th>
    11        <th width='10%'>Group</th>
    12        <th width='20%'>Course</th>
    13        <th width='20%'>Due Date</th>
    14        <th width='20%'>Due In/Late By (red)</th>
     41       <th>Event</th>
     42       <th>Group</th>
     43       <th>Course</th>
     44       <th>Due Date</th>
     45       <th>Due In/<span class='red'>Late By</span></th>
    1546    </tr>
    16 
    17 <?php foreach ($evalEvents as $event): ?>
    18 <tr>
    19     <td><?php echo $html->link($event['Event']['title'], '/evaluations/makeEvaluation/'.$event['Event']['id'].'/'.$event['Group']['id'])?></td>
    20     <td><?php echo $event['Group']['group_name']?></td>
    21     <td><?php echo $event['Course']['course']?></td>
    22     <td><?php echo Toolkit::formatDate($event['Event']['due_date'])?></td>
    23     <td><font color="<?php echo $event['Event']['due_in']>0 ? '' : 'red'?>">
    24         <?php echo abs($event['Event']['due_in'])?>
    25         <?php echo ($event['Event']['due_in']<0 && isset($event['Penalty']['id'])) ? $event['Penalty']['percent_penalty'] . '% penalty' : ''?>
    26     </font></td>
    27 </tr>
    28 <?php endforeach; ?>
    29 <?php if (empty($evalEvents)):?>
     47    <?php
     48    echo $html->tableCells($evalUpcoming);
     49    ?>
     50    <?php if (empty($evalUpcoming)):?>
    3051    <tr><td colspan="5" align="center"><b> No peer evaluations due at this time </b></td></tr>
    31 <?php endif; ?>
    32     </table>
    33 </div>
     52    <?php endif; ?>
     53</table>
    3454
    3555<h3>Surveys Due</h3>
    36 <div>
    37     <table class='standardtable'>
     56<table class='standardtable'>
    3857    <tr>
    3958       <th>Event</th>
    40        <th width='20%'>Course</th>
    41        <th width='20%'>Due Date</th>
    42        <th width='20%'>Due In/Late By (red)</th>
     59       <th>Course</th>
     60       <th>Due Date</th>
     61       <th>Due In/<span class='red'>Late By</span></th>
    4362    </tr>
    44 <?php foreach ($surveyEvents as $event): ?>
    45 <tr>
    46     <td><?php echo $html->link($event['Event']['title'], '/evaluations/makeEvaluation/'.$event['Event']['id'])?></td>
    47     <td><?php echo $event['Course']['course']?></td>
    48     <td><?php echo Toolkit::formatDate($event['Event']['due_date'])?></td>
    49     <td><font color="<?php echo $event['Event']['due_in']>0 ? '' : 'red'?>"><?php echo abs($event['Event']['due_in'])?></font></td>
    50 </tr>
    51 <?php endforeach; ?>
    52 <?php if (empty($surveyEvents)):?>
     63    <?php
     64    echo $html->tableCells($surveyUpcoming);
     65    ?>
     66    <?php if (empty($surveyUpcoming)):?>
    5367    <tr><td colspan="5" align="center"><b> No survey due at this time </b></td></tr>
     68    <?php endif; ?>
     69</table>
     70
     71<?php
     72function getSubmittedTableArray($html, $events) {
     73    $ret = array();
     74    foreach ($events as $event) {
     75        if (!$event['Event']['is_released'] &&
     76            !$event['Event']['is_result_released']
     77        ){ // an event that has expired and is no longer relevant
     78            continue;
     79        }
     80        $tmp = array();
     81        if (isset($event['Event']['is_result_released'])) {
     82            $tmp[] = $html->link($event['Event']['title'],
     83                '/evaluations/studentViewEvaluationResult/' .
     84                $event['Event']['id'] . '/' . $event['Group']['id']);
     85            $tmp[] = $event['Event']['result_release_date_end'];
     86        }
     87        elseif ($event['Event']['event_template_type_id'] == 3) {
     88            $tmp[] = $html->link($event['Event']['title'],
     89                '/evaluations/studentViewEvaluationResult/' .
     90                $event['Event']['id']);
     91        }
     92        else {
     93            $tmp[] = $event['Event']['title'];
     94            $tmp[] = "<span class='orangered'>" .
     95                $event['Event']['result_release_date_begin'] . "</span>";
     96        }
     97        if (isset($event['Group']['group_name'])) {
     98            $tmp[] = $event['Group']['group_name'];
     99        }
     100        $tmp[] = $event['Course']['course'];
     101        $tmp[] = Toolkit::formatDate($event['Event']['due_date']);
     102        $tmp[] = $event['EvaluationSubmission'][0]['date_submitted'];
     103        $ret[] = $tmp;
     104    }
     105    return $ret;
     106}
     107
     108$evalSubmitted = getSubmittedTableArray($html, $evals['submitted']);
     109$surveySubmitted = getSubmittedTableArray($html, $surveys['submitted']);
     110?>
     111
     112<h3>Peer Evaluations Submitted</h3>
     113<table class='standardtable'>
     114    <tr>
     115        <th>Event</th>
     116        <th>Viewable <span class='orangered'>Start</span>/End</th>
     117        <th>Group</th>
     118        <th>Course</th>
     119        <th>Due Date</th>
     120        <th>Date Submitted</th>
     121    </tr>
     122<?php echo $html->tableCells($evalSubmitted); ?>
     123<?php if (empty($evalSubmitted)):?>
     124    <tr>
     125        <td colspan="5" align="center">No submitted evaluations available.</td>
     126    </tr>
    54127<?php endif; ?>
    55     </table>
    56 </div>
     128</table>
    57129
    58 <h3>Peer Evaluations/Surveys Submitted or Overdue</h3>
     130<h3>Surveys Submitted</h3>
     131<table class='standardtable'>
     132    <tr>
     133        <th>Event</th>
     134        <th>Course</th>
     135        <th>Due Date</th>
     136        <th>Date Submitted</th>
     137    </tr>
     138<?php echo $html->tableCells($surveySubmitted); ?>
     139<?php if (empty($surveySubmitted)):?>
     140    <tr>
     141        <td colspan="5" align="center">No submitted surveys available.</td>
     142    </tr>
     143<?php endif; ?>
     144</table>
    59145
    60 <div>
    61     <table class='standardtable'>
    62     <tr>
    63         <th width='30%'>Event</th>
    64         <th width='10%'>Group</th>
    65         <th width='20%'>Course</th>
    66         <th width='20%'>Due Date</th>
    67         <th width='20%'>Date Submitted</th>
    68     </tr>
    69 <?php foreach ($submitted as $event): ?>
    70 <tr>
    71     <td>
    72     <?php if (((isset($event['Event']['is_result_released']) && $event['Event']['is_result_released']) ||
    73             !isset($event['Event']['is_result_released'])) && User::hasPermission('functions/viewstudentresults') && isset($event['EvaluationSubmission']['date_submitted'])):?>
    74         <?php $id = $event['Event']['event_template_type_id'] == 3 ? '' : '/'.$event['Group']['id']?>
    75         <?php echo $html->link($event['Event']['title'], '/evaluations/studentViewEvaluationResult/'.$event['Event']['id'].$id)?>
    76     <?php else: ?>
    77         <?php echo $event['Event']['title'] ?>
    78     <?php endif; ?>
    79     </td>
    80     <td><?php echo isset($event['Group']['group_name']) ? $event['Group']['group_name'] : "--"?></td>
    81     <td><?php echo $event['Course']['course']?></td>
    82     <td><?php echo Toolkit::formatDate($event['Event']['due_date'])?></td>
    83     <td><?php echo isset($event['EvaluationSubmission']['date_submitted']) ? Toolkit::formatDate($event['EvaluationSubmission']['date_submitted']):'--'?></td>
    84 </tr>
    85 <?php endforeach; ?>
    86 <?php if (empty($submitted)):?>
    87     <tr><td colspan="5" align="center"><b>No evaluations or survey submitted at this time</b></td></tr>
    88 <?php endif; ?>
    89     </table>
    90 </div>
  • app/webroot/css/ipeer.css

    r9503c0d r6609ae7  
    300300}
    301301
     302.orangered {
     303    color: orangered;
     304}
     305
    302306h1.title {
    303307    margin: 0.5em 0;
Note: See TracChangeset for help on using the changeset viewer.