Changeset 8cab1df in iPeer


Ignore:
Timestamp:
2013-08-28T11:00:49-07:00 (4 years ago)
Author:
Compass <pan.luo@…>
Branches:
3.1.x, dev, master
Children:
52e0022
Parents:
8f75a27 (diff), d01b528 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'courseBug' of github.com:ubc/iPeer into dev

Conflicts:

app/controllers/users_controller.php
app/models/user.php
app/tests/cases/models/survey_group_member.test.php

Location:
app
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • app/controllers/courses_controller.php

    r8f75a27 r8cab1df  
    208208     * Set all the necessary variables for the Add and Edit form elements.
    209209     *
     210     * @params mixed $courseId courseId - default null (eg. add)
     211     *
    210212     * @return void
    211213     * */
    212     public function _initFormEnv() {
     214    public function _initFormEnv($courseId = 0) {
    213215        // set the list of departments
    214216        if (User::hasPermission('functions/user/superadmin')) {
     
    239241
    240242        $this->set('departments', $departments);
     243       
     244        $currentProf = $this->User->getInstructorsByCourse($courseId);
     245        $currentProf = Set::combine($currentProf, '{n}.User.id', '{n}.User.full_name');
     246        $instructorList = $currentProf + array_diff($instructorList, $currentProf);
    241247
    242248        // set the list of instructors/tutors
     
    294300    public function edit($courseId)
    295301    {
    296         $this->_initFormEnv();
     302        $this->_initFormEnv($courseId);
    297303
    298304        $course = $this->Course->getAccessibleCourseById($courseId, User::get('id'), User::getCourseFilterPermission(), array('Instructor', 'Department'));
  • app/controllers/users_controller.php

    r8f75a27 r8cab1df  
    644644    public function edit($userId = null, $courseId = null) {
    645645        $this->set('title_for_layout', 'Edit User');
    646 
    647646        $enrolCourses = $this->User->getEnrolledCourses($userId);
    648 
     647        $tutorCourses = $this->User->getTutorCourses($userId);
     648        $instructors = $this->User->getInstructorCourses($userId);
    649649        $role = $this->User->getRoleName($userId);
    650650
     
    657657        if ($this->data) {
    658658            $this->data['User'] = array_map('trim', $this->data['User']);
     659            if (!is_array($this->data['Courses']['id'])) {
     660                $this->data['Courses']['id'] = array();
     661            }
     662
     663            // add list of courses the user is enrolled in but the logged
     664            // in user does not have access to so that the user would not
     665            // be unenrolled from the course when their profile is edited.
     666            $append = $this->_notUnenrolCourses($this->Auth->user('id'), $userId);
     667            $this->data['Courses']['id'] = array_merge($this->data['Courses']['id'], $append);
     668
    659669            // unenrol student from course, group, surveygroup
    660670            // only students will go in because only they have records in Enrolment
     
    662672                if (!in_array($course, $this->data['Courses']['id'])) {
    663673                    $this->User->removeStudent($userId, $course);
     674                }
     675            }
     676            // unenrol tutor from course, group
     677            foreach ($tutorCourses as $course) {
     678                if (!in_array($course, $this->data['Courses']['id'])) {
     679                    $this->User->removeTutor($userId, $course);
     680                }
     681            }
     682            // unenrol instructor from course
     683            foreach ($instructors as $course) {
     684                if (!in_array($course, $this->data['Courses']['id'])) {
     685                    $this->User->removeInstructor($userId, $course);
    664686                }
    665687            }
     
    13021324
    13031325    /**
     1326<<<<<<< HEAD
    13041327     * _updateCreatorUpdaterId
    13051328     *
     
    15011524        return $updated;
    15021525    }
     1526
     1527    /**
     1528     * helper function for users/edit, to not unenrol the user being edited from
     1529     * courses the logged user don't have access to
     1530     *
     1531     * @param int $editor
     1532     * @param int $userId
     1533     *
     1534     * @return array of courses to not unenrol
     1535     */
     1536    private function _notUnenrolCourses($editor, $userId)
     1537    {
     1538        $editor = $this->User->findById($editor);
     1539        $user = $this->User->findById($userId);
     1540        $editorCourses = array();
     1541        $userCourses = array();
     1542
     1543        // user's list of courses
     1544        foreach ($user['Course'] as $course) {
     1545            $userCourses[] = $course['id'];
     1546        }
     1547        foreach ($user['Enrolment'] as $course) {
     1548            $userCourses[] = $course['id'];
     1549        }
     1550        foreach ($user['Tutor'] as $course) {
     1551            $userCourses[] = $course['id'];
     1552        }
     1553
     1554        // get editor's list of courses
     1555        $editorCourses = $this->Course->getAccessibleCourses(User::get('id'),
     1556            User::getCourseFilterPermission(), 'list');
     1557
     1558        return array_diff($userCourses, array_keys($editorCourses));
     1559    }
    15031560}
  • app/models/survey_group_member.php

    r8f75a27 r8cab1df  
    1212{
    1313    public $name = 'SurveyGroupMember';
    14    
     14
    1515    public $belongsTo = array(
    1616        'User' => array(
  • app/models/user.php

    r8f75a27 r8cab1df  
    3333    const IMPORT_PASSWORD = '5';
    3434    const GENERATED_PASSWORD = '6';
    35    
     35
    3636    const MERGE_MODEL = '0';
    3737    const MERGE_TABLE = '1';
     
    172172        'student_no_with_full_name' => 'CONCAT_WS(" ", student_no,CONCAT_WS(" ", first_name, last_name))'
    173173    );
    174    
     174
    175175    /** validate the faculty field for user form
    176176     * if user is a faculty admin, or instructor,
     
    385385        $this->displayField = 'student_no_with_full_name';
    386386        return $this->find(
    387             'list', 
     387            'list',
    388388            array(
    389389                'conditions' => array(
     
    555555        return $this->find($type, $params);
    556556    }
    557    
     557
    558558    /**
    559559     * Get list of tutors
     
    784784        $surveys = $this->Event->find('list', array(
    785785            'conditions' => array(
    786                 'course_id' => $course_id, 
    787                 'event_template_type_id' => 3), 
     786                'course_id' => $course_id,
     787                'event_template_type_id' => 3),
    788788            'fields' => array('Event.id')));
    789789        /* query any surveyGroupMember records created based on the above
     
    791791        $members = $this->SurveyGroupMember->find('all', array(
    792792            'conditions' => array(
    793                 'SurveyGroupMember.user_id' => $user_id, 
     793                'SurveyGroupMember.user_id' => $user_id,
    794794                'SurveyGroupSet.survey_id' => $surveys)));
    795795        // remove the records found
     
    803803        return $this->UserEnrol->delete($id);
    804804    }
    805    
     805
    806806    /**
    807807     * unenrolStudent
     
    891891        $id = $this->UserTutor->field('id',
    892892            array('user_id' => $user_id, 'course_id' => $course_id));
     893
     894        $members = $this->Group->find('all', array('conditions' => array('Member.id' => $user_id, 'course_id' => $course_id)));
     895        foreach ($members as $member) {
     896            $this->GroupsMember->delete($member['GroupsMember']['id']);
     897        }
     898
    893899        return $this->UserTutor->delete($id);
    894900    }
     
    898904     *
    899905     * @param mixed $id id
    900      * 
     906     *
    901907     * @access public
    902908     * @return void
     
    935941        ));
    936942    }
    937    
     943
    938944    /**
    939945     * removeOldStudents
    940      * 
     946     *
    941947     * @param mixed $newList  new list of students
    942948     * @param mixed $courseId course id
     
    954960        }
    955961    }
    956    
     962
    957963    /**
    958964     * Get courses a user is enrolled in
     
    965971    {
    966972        $user = $this->find('first', array(
    967             'conditions' => array('User.id' => $userId), 
     973            'conditions' => array('User.id' => $userId),
    968974            'contain' => array('Enrolment')
    969975        ));
    970976        return Set::extract($user, '/Enrolment/id');
    971977    }
    972    
     978
    973979    /**
    974980     * getFullNames
     
    986992        ));
    987993    }
    988    
     994
    989995    /**
    990996     * getUsers
     
    10061012        ));
    10071013    }
    1008    
     1014
    10091015    /**
    10101016     * Get members in a group in event (not including tutors)
     
    10281034            'contain' => array('Role', 'Group')
    10291035        ));
    1030        
     1036
    10311037        $groupMembers = array();
    10321038        foreach($members as $member) {
     
    11881194        }
    11891195    }
    1190    
     1196
    11911197    /**
    11921198     * getDroppedStudentsWithRole
     
    12121218            $dropped[$key] = $dropped[$key] + $drop['User'];
    12131219        }
    1214        
     1220
    12151221        return $dropped;
    12161222    }
  • app/tests/cases/models/survey_group_member.test.php

    r8f75a27 r8cab1df  
    1414        'app.user_enrol', 'app.groups_member', 'app.rubric', 'app.rubrics_lom',
    1515        'app.rubrics_criteria', 'app.rubrics_criteria_comment',
    16         'app.survey_group_member', 'app.oauth_token', 'app.sys_parameter',
     16        'app.oauth_token', 'app.sys_parameter',
    1717        'app.evaluation_simple', 'app.survey_input', 'app.faculty',
    1818        'app.user_faculty', 'app.user_tutor', 'app.department',
Note: See TracChangeset for help on using the changeset viewer.