Changeset 11dca66 in iPeer


Ignore:
Timestamp:
2013-08-07T16:07:37-07:00 (4 years ago)
Author:
Compass <pan.luo@…>
Branches:
3.1.x, dev, master
Children:
cdb0e4a
Parents:
4d5a23c
git-author:
mwytang <michael.tang@…> (07/12/2013 02:41:15 PM)
git-committer:
Compass <pan.luo@…> (08/07/2013 04:07:37 PM)
Message:

Fixed courses edit for instructors and tutors

I have fixed unenrolling all courses for instructors and tutors
from courses edit similar to the fix for students. When tutors
are unenrolled using this method, they are also removed from
the groups they are in.

Location:
app
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • app/controllers/users_controller.php

    r4d5a23c r11dca66  
    614614        $this->set('title_for_layout', 'Edit User');
    615615        $enrolCourses = $this->User->getEnrolledCourses($userId);
     616        $tutorCourses = $this->User->getTutorCourses($userId);
     617        $instructors = $this->User->getInstructorCourses($userId);
    616618        $role = $this->User->getRoleName($userId);
    617619
     
    638640                if (!in_array($course, $this->data['Courses']['id'])) {
    639641                    $this->User->removeStudent($userId, $course);
     642                }
     643            }
     644            // unenrol tutor from course, group
     645            foreach ($tutorCourses as $course) {
     646                if (!in_array($course, $this->data['Courses']['id'])) {
     647                    $this->User->removeTutor($userId, $course);
     648                }
     649            }
     650            // unenrol instructor from course
     651            foreach ($instructors as $course) {
     652                if (!in_array($course, $this->data['Courses']['id'])) {
     653                    $this->User->removeInstructor($userId, $course);
    640654                }
    641655            }
  • app/models/user.php

    r4d5a23c r11dca66  
    830830        $id = $this->UserTutor->field('id',
    831831            array('user_id' => $user_id, 'course_id' => $course_id));
     832       
     833        $members = $this->Group->find('all', array('conditions' => array('Member.id' => $user_id, 'course_id' => $course_id)));
     834        foreach ($members as $member) {
     835            $this->GroupsMember->delete($member['GroupsMember']['id']);
     836        }
     837
    832838        return $this->UserTutor->delete($id);
    833839    }
     
    883889    }
    884890
     891    /**
     892     * Get courses a tutor is enrolled in
     893     *
     894     * @param mixed $userId user id
     895     *
     896     * @return list of course ids
     897     */
     898    function getTutorCourses($userId='')
     899    {
     900        $user = $this->find('first', array(
     901            'conditions' => array('User.id' => $userId),
     902            'contain' => array('Tutor')
     903        ));
     904        return Set::extract($user, '/Tutor/id');
     905    }
     906
     907    /**
     908     * Get courses an instructor is enrolled in
     909     *
     910     * @param mixed $userId user id
     911     *
     912     * @return list of course ids
     913     */
     914    function getInstructorCourses($userId='')
     915    {
     916        $user = $this->find('first', array(
     917            'conditions' => array('User.id' => $userId),
     918            'contain' => array('Course')
     919        ));
     920        return Set::extract($user, '/Course/id');
     921    }
     922
    885923    /*********************************
    886924     * Static functions
Note: See TracChangeset for help on using the changeset viewer.