Changeset 33c97f9 in iPeer


Ignore:
Timestamp:
2013-02-13T15:12:39-08:00 (6 years ago)
Author:
Michael Tang <michael.tang@…>
Branches:
3.1.x, dev, master, ticket463
Children:
75ea5ba
Parents:
c55e6a7
Message:

finished implementing the basics for moving students' surveys

The "Move Student" button is only available to "move" the selected
student when a select fields are not empty.

I have also included an option for the user to choose whether they
want to move or copy the student. To move, it means that the survey
results would be "cut and paste" to the destination course's event
and the student would be unenrolled from the source course. If the
copy option is selected a copy of the submission and inputs would
be made with the destination's event id. For both choices, the
student would be enrolled to the destination course if not already.

Location:
app
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • app/controllers/courses_controller.php

    rc55e6a7 r33c97f9  
    344344        if (!empty($this->data)) {
    345345            $data = $this->data['Course'];
    346            
    347             // validation - array filter returns all fields that have a selection
    348             // if the number of selections is not 5 then a field must not be filled
    349             $filter = array_filter($data);
    350             if (count($filter) != 5) {
    351                 $this->Session->setFlash(__('All fields are required.', true));
    352                 $this->redirect('move/'.$courseId);
    353                 return;
    354             }
     346            $move = $data['action'];
     347
    355348            $destSub = $this->EvaluationSubmission->getEvalSubmissionByEventIdSubmitter(
    356349                $data['destSurveys'], $data['submitters']);
    357 
    358350            if (!empty($destSub)) {
    359351                $this->Session->setFlash(__('The student has already submitted to the destination survey', true));
     
    366358            $inputs = $this->SurveyInput->getByEventIdUserId(
    367359                $data['sourceSurveys'], $data['submitters']);
    368 
    369             $sub['EvaluationSubmission']['id'] = null;
     360           
     361            // if choose to copy set id to null
     362            if (!$move) {
     363                $sub['EvaluationSubmission']['id'] = null;
     364            }
    370365            $sub['EvaluationSubmission']['event_id'] = $data['destSurveys'];
    371366            $sInputs = array();
    372367            foreach ($inputs as $input) {
    373368                $tmp = $input['SurveyInput'];
    374                 $tmp['id'] = null;
     369                if (!$move) {
     370                    $tmp['id'] = null;
     371                }
    375372                $tmp['event_id'] = $data['destSurveys'];
    376373                $sInputs[] = $tmp;
    377374            }
    378             $this->EvaluationSubmission->save($sub);
    379             $this->SurveyInput->saveAll($sInputs);
     375            $action = ($move) ? 'moved' : 'copied';
     376            $this->User->id = $data['submitters'];
     377            $student = $this->User->field('full_name');
     378            $this->Course->id = $data['destCourses'];
     379            $to = $this->Course->field('full_name');
     380           
     381            if ($this->EvaluationSubmission->save($sub) && $this->SurveyInput->saveAll($sInputs)) {
     382                $msg = $student.' was successfully '.$action.' to '.$to.'.';
     383            } else {
     384                $this->Session->setFlash(__($student.' was not successfully '.$action.' to '.$from.'.', true));
     385                $this->redirect('move/'.$courseId);
     386                return;
     387            }
     388           
     389            // if student is not enrolled in destination course - enrol them
     390            $enrol = $this->Course->getAccessibleCourseById($data['destCourses'], $data['submitters'], Course::FILTER_PERMISSION_ENROLLED);
     391            if (!$enrol) {
     392                if (!$this->User->addStudent($data['submitters'], $data['destCourses'])) {
     393                    $msg .= ' '.$student.' was unsuccessfully enrolled to '.$to.'.';
     394                }
     395            }
     396
     397            if ($move) {
     398                $this->Course->id = $data['sourceCourses'];
     399                $from = $this->Course->field('full_name');
     400                if (!$this->User->removeStudent($data['submitters'], $data['sourceCourses'])) {
     401                    $msg .= ' '.$student.' was unsuccessfully unenrolled from '.$from.'.';
     402                }
     403            }
     404            $this->Session->setFlash(__($msg, true), 'good');
    380405        }
    381406        // clear data when user is redirected back to this page
     
    426451                $event = $this->Event->findById($this->data['Course']['sourceSurveys']);
    427452                $destCourses = $this->Course->getAccessibleCourses(User::get('id'), User::getCourseFilterPermission(), 'list');
    428                 $enrolCourses = $this->Course->getAccessibleCourses($this->data['Course']['submitters'], Course::FILTER_PERMISSION_ENROLLED, 'list');
    429                 $courses = array_intersect(array_keys($destCourses), array_keys($enrolCourses)); //courses common between user and student
    430453                $destEvents = $this->Event->find('all', array(
    431454                    'conditions' => array(
    432                         'Event.course_id' => $courses,
     455                        'Event.course_id' => array_keys($destCourses),
    433456                        'Event.event_template_type_id' => 3,
    434457                        'Event.template_id' => $event['Event']['template_id']
  • app/views/courses/move.ctp

    rc55e6a7 r33c97f9  
    1 <div id='CourseMove'>
    21<?php
    3 echo $this->Form->create('Course', array('action' => 'move/'.$courseId));
     2echo $this->Form->create('Course', array('id' => 'UserMove', 'action' => 'move/'.$courseId));
    43echo $this->Form->input('sourceCourses', array('empty' => '-- Pick a course --'));
    54echo $this->Form->input('sourceSurveys', array('empty' => '-- Pick a survey --'));
     
    76echo $this->Form->input('destCourses', array('label' => 'Destination Course', 'empty' => '-- Pick a course --'));
    87echo $this->Form->input('destSurveys', array('label' => 'Destination Survey', 'empty' => '-- Pick a survey --'));
    9 echo $this->Form->end('Move Student');
     8echo $this->Form->input('action', array(
     9    'legend' => 'Move or Copy?',
     10    'type' => 'radio',
     11    'options' => array('1' => 'Move', '0' => 'Copy'),
     12    'default' => '1'
     13));
     14echo $this->Form->end(array('label' => 'Move Student', 'id' => 'submit', 'disabled' => 'disabled'));
    1015
    1116//populate source surveys
     
    3540));
    3641?>
    37 </div>
    3842
    3943<script type="text/javascript">
     
    5862            .append('<option value="">-- Pick a survey --</option>');
    5963    });
     64    jQuery("select").change(function() {
     65        var empty = false;
     66        jQuery("select").each(function() {
     67            if(jQuery(this).val() == '') {
     68                empty = true;
     69            }
     70        });
     71        if (empty) {
     72            jQuery("#submit").attr("disabled", "disabled");
     73        } else {
     74            jQuery("#submit").removeAttr("disabled");
     75        }
     76    });
    6077});
    6178
  • app/webroot/css/ipeer.css

    rc55e6a7 r33c97f9  
    663663}
    664664
     665/* courses/move */
     666
     667#UserMove select {
     668    width: 30em;
     669}
     670
    665671/* USERS */
    666672
Note: See TracChangeset for help on using the changeset viewer.