Changeset d412b67 in iPeer


Ignore:
Timestamp:
2012-12-26T01:51:42-08:00 (5 years ago)
Author:
Compass <pan.luo@…>
Branches:
3.1.x, dev, hotfix, master, pagodabox, ticket463
Children:
0fd968e
Parents:
bf81fcd
Message:

Add faculty filter on instructor list on course page

Instructors/Admins? should only see the instructors within their faculty
when adding/editing course

Location:
app
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • app/controllers/courses_controller.php

    rbf81fcd rd412b67  
    193193            // superadmin permission means you see all departments regardless
    194194            $departments = $this->Course->Department->find('list');
    195             $this->set('departments', $departments);
    196 
     195            $instructorList = $this->User->getInstructors('list', array());
    197196        } else {
    198197            // need to limit the departments this user can see
     
    213212                $departments = $this->Course->Department->find('list');
    214213            }
    215             $this->set('departments', $departments);
     214            $facultyIds = Set::extract($uf, '/UserFaculty/faculty_id');
     215            $instructorList = $this->User->getInstructorListByFaculty($facultyIds);
    216216        }
    217217        // set the list available statuses
     
    219219        $this->set('statusOptions', $statusOptions);
    220220
     221        $this->set('departments', $departments);
     222
    221223        // set the list of instructors
    222         $instructors = $this->User->getInstructors('all', array('User.username'));
    223         $instructorlist = array();
    224 
    225         // need to display names to user, not ids
    226         $this->set('instructorSelected', '');
    227         foreach ($instructors as $i) {
    228             $instructorlist[$i['User']['id']] = $i['User']['full_name'];
    229             // we want to have ourself selected as default
    230             if ($i['User']['id'] == $this->Auth->user('id')) {
    231                 $this->set('instructorSelected', $i['User']['id']);
    232             }
    233         }
    234 
    235         $this->set('instructors', $instructorlist);
     224        $this->set('instructors', $instructorList);
    236225    }
    237226
  • app/models/user.php

    rbf81fcd rd412b67  
    506506     * @return list of instructors
    507507     * */
    508     function getInstructors($type, $params)
     508    function getInstructors($type, $params = array())
    509509    {
    510510        $defaults = array('order' => $this->alias.'.last_name');
     
    536536
    537537    /**
     538     * getInstructorListByFaculty
     539     * get instructors within faculty
     540     *
     541     * @param mixed $facultyId
     542     *
     543     * @access public
     544     * @return void
     545     */
     546    function getInstructorListByFaculty($facultyId)
     547    {
     548        $users = $this->find('all', array(
     549            'conditions' => array('Role.id' => 3, 'Faculty.id' => $facultyId),
     550            'fields' => array($this->alias.'.id', $this->displayField),
     551            'contain' => array('Faculty', 'Role'),
     552            'order' => $this->alias.'.last_name',
     553        ));
     554
     555        $userList = Set::combine($users, '{n}.User.id', '{n}.User.'.$this->displayField);
     556
     557        return $userList;
     558    }
     559
     560    /**
    538561     * Get current logged in user
    539562     *
  • app/views/courses/add.ctp

    rbf81fcd rd412b67  
    66<?php echo $this->Form->input('title');?>
    77<div class="help-text"><?php __('Course title, e.g. Technical Communication')?></div>
    8 <?php echo $this->Form->input('Instructor', array('selected' => $instructorSelected));?>
     8<?php echo $this->Form->input('Instructor', array('selected' => User::get('id')));?>
    99<div class="help-text"><?php __('Holding "ctrl" or "command" key to select multiple instructors.')?></div>
    1010
Note: See TracChangeset for help on using the changeset viewer.