Changeset e80f477 in iPeer


Ignore:
Timestamp:
2012-12-14T15:29:36-08:00 (6 years ago)
Author:
John Hsu <john.hsu@…>
Branches:
3.1.x, dev, hotfix, master, pagodabox, ticket463
Children:
c88a90a
Parents:
9aa5b63
git-author:
John Hsu <john.hsu@…> (12/14/2012 03:05:19 PM)
git-committer:
John Hsu <john.hsu@…> (12/14/2012 03:29:36 PM)
Message:

Student Home: Upcoming/Submitted/Expired? events.

Determining what surveys are show to students turns out to be a bit more
complicated than I thought due to all the different dates we've got.

Some definitions to show what I'm trying to achieve:

Release period - is the time interval in which students are allowed to
make submissions to the event. This is stored by the release_date_begin
and release_date_end fields in the Event table. And also the is_release
virtual field in the Event model.

Result release period - is the time interval in which students are
allowed to view resulting data from the event. This is stored by the
result_release_date_begin and result_release_date_end fields in the
Events table. And also by the is_result_release virtual field in the
Event model.

Upcoming events - Events that are still within their release period and
which the user haven't made any submissions to.

Submitted events - Events that the user has made a submission to and
hasn't gone past the result release period.

Expired events - Events that the user has not made a submission to and
hasn't gone past the result release period.

Once an event is past its result release period, it will no longer show
up in the student view.

Note that since surveys doesn't have a result release period, I'm using
the release period instead.

Also added a 'summary statistic' second at the top of the student home
page. It'll show the total number of events that needs to be done if
there are any overdue. Standard red, orange, green color background is
used to indicate if the user has anything to worry about.

Location:
app
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • app/controllers/home_controller.php

    r9aa5b63 re80f477  
    4949
    5050        // 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
    5651        $events = $this->Event->getEventsByUserId(User::get('id'));
    5752
     
    9287        }
    9388
     89        // remove non-current events and split into upcoming/submitted/expired
    9490        $evals = $this->_splitSubmittedEvents($events['Evaluations']);
    9591        $surveys = $this->_splitSubmittedEvents($events['Surveys']);
     92
     93        // calculate summary statistics
     94        $numOverdue = 0;
     95        $numDue = 0;
     96        $numDue = sizeof($evals['upcoming']) + sizeof($surveys['upcoming']);
     97        // only evals can have overdue events right now
     98        foreach ($evals['upcoming'] as $e) {
     99            $e['late'] ? $numOverdue++ : '';
     100        }
     101
     102
    96103        $this->set('evals', $evals);
    97104        $this->set('surveys', $surveys);
     105        $this->set('numOverdue', $numOverdue);
     106        $this->set('numDue', $numDue);
    98107        $this->render('studentIndex');
    99108    }
     
    125134
    126135    /**
    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.
     136     * Helper to filter events into 3 different categories and to
     137     * discard inactive events.
     138     *
     139     * The 3 categories are: Upcoming, Submitted, Expired
     140     *
     141     * - Upcoming are events that the user can still make submissions for.
     142     * - Submitted are events that the user has already made a submission.
     143     * - Expired are events that the user hasn't made and can no longer make
     144     * submissions, but they can still view results from their peers.
     145     *
     146     * An evaluation is considered inactive once past its result release
     147     * period. A survey is considered inactive once past its release period.
    130148     *
    131149     * @param array $events - list of events info returned from the event model,
    132150     *  each event MUST have an 'EvaluationSubmission' array or this won't work
    133151     *
    134      * @return Split the events array into 'upcoming' or 'submitted' categories
     152     * @return Discard inactive events and then split the remaining events
     153     * into upcoming, submitted, and expired.
    135154     * */
    136155    private function _splitSubmittedEvents($events)
    137156    {
    138         $submitted = $upcoming = array();
     157        $submitted = $upcoming = $expired = array();
    139158        foreach ($events as $event) {
    140             if (empty($event['EvaluationSubmission']) ||
    141                 $event['Event']['is_ended']
    142             ){
     159            if (empty($event['EvaluationSubmission']) &&
     160                $event['Event']['is_released']
     161            ) { // can only take surveys during the release period
    143162                $upcoming[] = $event;
    144             } else {
     163            }
     164            else if (!empty($event['EvaluationSubmission']) &&
     165                strtotime('NOW') <
     166                strtotime($event['Event']['result_release_date_end'])
     167            ) { // has submission and can or will be able to view results soon
     168                // note that we're not using is_released or is_result_released
     169                // because of an edge case where if there is a period of time
     170                // between the release and result release period, the evaluation
     171                // will disappear from view
    145172                $submitted[] = $event;
    146173            }
    147         }
    148         return array('upcoming' => $upcoming, 'submitted' => $submitted);
     174            else if (!empty($event['EvaluationSubmission']) &&
     175                $event['Event']['is_released']
     176            ) {
     177                // special case for surveys, which doesn't have
     178                // result_release_date_end
     179                $submitted[] = $event;
     180            }
     181            else if (empty($event['EvaluationSubmission']) &&
     182                strtotime('NOW') <
     183                strtotime($event['Event']['result_release_date_end'])
     184            ) { // student did not do the survey within the allowed time
     185                // but we should still let them view results
     186                $expired[] = $event;
     187            }
     188        }
     189        return array('upcoming' => $upcoming,
     190            'submitted' => $submitted,
     191            'expired' => $expired
     192        );
    149193    }
    150194
  • app/models/event.php

    r9aa5b63 re80f477  
    175175                    $currentDate < strtotime($event['Event']['result_release_date_end']));
    176176            }
     177            else {
     178                // since surveys have no result release period
     179                $results[$key]['Event']['is_result_released'] = false;
     180            }
    177181            if (isset($event['Event']['release_date_end'])) {
    178182                $results[$key]['Event']['is_ended']  =
    179183                    ($currentDate > strtotime($event['Event']['release_date_end']));
     184            }
     185            // is_ended for surveys
     186            if ($event['Event']['event_template_type_id'] == 3) {
     187                $results[$key]['Event']['is_ended']  =
     188                    ($currentDate > strtotime($event['Event']['due_date']));
    180189            }
    181190        }
  • app/tests/cases/controllers/home_controller.test.php

    r9aa5b63 re80f477  
    113113        );
    114114        $result = $this->testAction('/home/index', array('return' => 'vars'));
     115
     116        // summary statistics
     117        $this->assertEqual($result['numOverdue'], 0);
     118        $this->assertEqual($result['numDue'], 5);
     119
     120        // evaluations
    115121        $upcoming = Set::sort($result['evals']['upcoming'], '{n}.Event.id',
    116122            'asc');
    117123        $submitted = Set::sort($result['evals']['submitted'], '{n}.Event.id',
    118124            'asc');
    119         $this->assertEqual(count($upcoming), 6);
    120         $this->assertEqual(count($submitted), 1);
     125        $expired = Set::sort($result['evals']['expired'], '{n}.Event.id',
     126            'asc');
     127        $this->assertEqual(count($upcoming), 3);
     128        $this->assertEqual(count($submitted), 2);
     129        $this->assertEqual(count($expired), 2);
    121130
    122131        $this->assertEqual(Set::extract('/Event/id', $upcoming),
    123             array(1,2,3,7,8,9));
     132            array(1,2,3));
    124133        $this->assertEqual(Set::extract('/Event/id', $submitted),
    125             array(6));
     134            array(6,8));
     135        $this->assertEqual(Set::extract('/Event/id', $expired),
     136            array(7,9));
     137
     138        // surveys
     139        $upcoming = Set::sort($result['surveys']['upcoming'], '{n}.Event.id',
     140            'asc');
     141        $submitted = Set::sort($result['surveys']['submitted'], '{n}.Event.id',
     142            'asc');
     143        $this->assertEqual(count($upcoming), 2);
     144        $this->assertEqual(count($submitted), 0);
     145
     146        $this->assertEqual(Set::extract('/Event/id', $upcoming),
     147            array(4,5));
     148        $this->assertEqual(Set::extract('/Event/id', $submitted),
     149            array());
    126150    }
    127151}
  • app/views/home/student_index.ctp

    r9aa5b63 re80f477  
     1<div id='StudentHome'>
    12<?php
    23function getUpcomingTableArray($html, $events) {
     
    3435$evalUpcoming = getUpcomingTableArray($html, $evals['upcoming']);
    3536$surveyUpcoming = getUpcomingTableArray($html, $surveys['upcoming']);
     37
     38function getNonUpcomingTableArray($html, $events) {
     39    $ret = array();
     40    foreach ($events as $event) {
     41        $tmp = array();
     42        if (isset($event['Event']['is_result_released']) &&
     43            $event['Event']['is_result_released']
     44        ) { // we're in the result release period, so link to the results
     45            $tmp[] = $html->link($event['Event']['title'],
     46                '/evaluations/studentViewEvaluationResult/' .
     47                $event['Event']['id'] . '/' . $event['Group']['id']);
     48            $tmp[] = $event['Event']['result_release_date_end'];
     49        }
     50        else if ($event['Event']['event_template_type_id'] == 3) {
     51            // this is a survey, no release period, so link to the results
     52            $tmp[] = $html->link($event['Event']['title'],
     53                '/evaluations/studentViewEvaluationResult/' .
     54                $event['Event']['id']);
     55        }
     56        else {
     57            // we're not in the result release period, notify user when they can
     58            // view the results
     59            $tmp[] = $event['Event']['title'];
     60            $tmp[] = "<span class='orangered'>" .
     61                $event['Event']['result_release_date_begin'] . "</span>";
     62        }
     63        if (isset($event['Group']['group_name'])) {
     64            // NOTE: surveys don't have group names
     65            $tmp[] = $event['Group']['group_name'];
     66        }
     67        $tmp[] = $event['Course']['course'];
     68        $tmp[] = Toolkit::formatDate($event['Event']['due_date']);
     69        if (!empty($event['EvaluationSubmission'])) {
     70            // expired events have no submissions
     71            $tmp[] = $event['EvaluationSubmission'][0]['date_submitted'];
     72        }
     73        $ret[] = $tmp;
     74    }
     75    return $ret;
     76}
     77
     78$evalSubmitted = getNonUpcomingTableArray($html, $evals['submitted']);
     79$surveySubmitted = getNonUpcomingTableArray($html, $surveys['submitted']);
     80$evalExpired = getNonUpcomingTableArray($html, $evals['expired']);
     81// note that we have this section for completeness, but currently,
     82// surveys are removed once past the due date, so unless the student
     83// made a submission, it won't show up
     84$surveyExpired = getNonUpcomingTableArray($html, $surveys['expired']);
     85
     86if ($numOverdue) {
     87    echo "<div class='eventSummary overdue'>$numOverdue Overdue Events</div>";
     88}
     89if ($numDue) {
     90    echo "<div class='eventSummary pending'>$numDue Pending Events Total</div>";
     91}
     92else {
     93    echo "<div class='eventSummary alldone'>No Events Pending</div>";
     94}
    3695?>
    3796
    38 <h3>Peer Evaluations Due</h3>
     97
     98<h2>Peer Evaluations</h2>
     99<h3>Due</h3>
    39100<table class='standardtable'>
    40101    <tr>
     
    45106       <th>Due In/<span class='red'>Late By</span></th>
    46107    </tr>
    47     <?php
    48     echo $html->tableCells($evalUpcoming);
     108    <?php 
     109    echo $html->tableCells($evalUpcoming); 
    49110    ?>
    50111    <?php if (empty($evalUpcoming)):?>
     
    53114</table>
    54115
    55 <h3>Surveys Due</h3>
    56 <table class='standardtable'>
    57     <tr>
    58        <th>Event</th>
    59        <th>Course</th>
    60        <th>Due Date</th>
    61        <th>Due In/<span class='red'>Late By</span></th>
    62     </tr>
    63     <?php
    64     echo $html->tableCells($surveyUpcoming);
    65     ?>
    66     <?php if (empty($surveyUpcoming)):?>
    67     <tr><td colspan="5" align="center"><b> No survey due at this time </b></td></tr>
    68     <?php endif; ?>
    69 </table>
    70 
    71 <?php
    72 function 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>
     116<h3>Submitted</h3>
    113117<table class='standardtable'>
    114118    <tr>
     
    128132</table>
    129133
    130 <h3>Surveys Submitted</h3>
     134<?php if (!empty($evalExpired)):?>
     135<h3>Expired With No Submission</h3>
     136<table class='standardtable'>
     137    <tr>
     138        <th>Event</th>
     139        <th>Viewable <span class='orangered'>Start</span>/End</th>
     140        <th>Group</th>
     141        <th>Course</th>
     142        <th>Due Date</th>
     143    </tr>
     144<?php echo $html->tableCells($evalExpired); ?>
     145</table>
     146<?php endif; ?>
     147
     148<h2>Surveys</h2>
     149<h3>Due</h3>
     150<table class='standardtable'>
     151    <tr>
     152       <th>Event</th>
     153       <th>Course</th>
     154       <th>Due Date</th>
     155       <th>Due In/<span class='red'>Late By</span></th>
     156    </tr>
     157    <?php
     158    echo $html->tableCells($surveyUpcoming);
     159    ?>
     160    <?php if (empty($surveyUpcoming)):?>
     161    <tr><td colspan="4" align="center"><b> No survey due at this time </b></td></tr>
     162    <?php endif; ?>
     163</table>
     164
     165<h3>Submitted</h3>
    131166<table class='standardtable'>
    132167    <tr>
     
    139174<?php if (empty($surveySubmitted)):?>
    140175    <tr>
    141         <td colspan="5" align="center">No submitted surveys available.</td>
     176        <td colspan="4" align="center">No submitted surveys available.</td>
    142177    </tr>
    143178<?php endif; ?>
    144179</table>
    145180
     181<?php if (!empty($surveyExpired)):?>
     182<h3>Expired With No Submission</h3>
     183<table class='standardtable'>
     184    <tr>
     185        <th>Event</th>
     186        <th>Course</th>
     187        <th>Due Date</th>
     188    </tr>
     189<?php echo $html->tableCells($surveyExpired); ?>
     190</table>
     191<?php endif; ?>
     192
     193</div>
  • app/webroot/css/ipeer.css

    r9aa5b63 re80f477  
    393393
    394394/* HOME */
     395/* for admins and instructors */
    395396.course {
    396397    margin-bottom: 1em;
     
    462463#short_help li {
    463464    padding-bottom: 0.5em;
     465}
     466
     467/* student home */
     468
     469#StudentHome .eventSummary {
     470    text-align: center;
     471    padding: 0.3em;
     472    margin-bottom: 0.1em;
     473}
     474
     475#StudentHome .overdue {
     476    background: lightcoral;
     477}
     478
     479#StudentHome .pending {
     480    background: lightsalmon;
     481}
     482
     483#StudentHome .alldone {
     484    background: lightgreen;
    464485}
    465486
Note: See TracChangeset for help on using the changeset viewer.