Changeset b9b67fc in iPeer


Ignore:
Timestamp:
2012-12-13T14:37:56-08:00 (6 years ago)
Author:
Compass <pan.luo@…>
Branches:
3.1.x, dev, hotfix, master, pagodabox, ticket463
Children:
fbf5e40
Parents:
db0c328
git-author:
Compass <pan.luo@…> (12/13/2012 02:11:57 PM)
git-committer:
Compass <pan.luo@…> (12/13/2012 02:37:56 PM)
Message:

Refactor group controller/view and addd tests

Location:
app
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • app/controllers/groups_controller.php

    rdb0c328 rb9b67fc  
    150150    }
    151151
    152 
    153     /**
    154      * goToClassList
    155      * Show a class list of groups
    156      *
    157      * @param mixed $course
    158      *
    159      * @access public
    160      * @return void
    161      */
    162     function goToClassList($course)
    163     {
    164         if (is_numeric($course)) {
    165             $courses = User::getMyCourseList();
    166             if (!empty($courses[$course])) {
    167                 // We need to change the session state to point to this
    168                 // course:
    169                 // Initialize a basic non-funcional AjaxList
    170                 $this->AjaxList->quickSetUp();
    171                 // Clear the state first, we don't want any previous searches/selections.
    172                 $this->AjaxList->clearState();
    173                 // Set and update session state Variable
    174                 $joinFilterSelections->{"Group.course_id"} = $course;
    175                 $this->AjaxList->setStateVariable("joinFilterSelections", $joinFilterSelections);
    176             }
    177         }
    178         // Redirect to list after state modifications (or in case of error)
    179         $this->redirect("/groups/index/".$course);
    180     }
    181 
    182152    /**
    183153     * view
     
    220190    function add ($course_id)
    221191    {
     192        $course = $this->Course->getAccessibleCourseById($course_id, User::get('id'), User::getCourseFilterPermission());
     193        if (!$course) {
     194            $this->Session->setFlash(__('Error: Course does not exist or you do not have permission to view this course.', true));
     195            $this->redirect('/courses');
     196            return;
     197        }
     198
    222199        if (!empty($this->data)) {
    223200            if ($this->Group->save($this->data)) {
    224201                $this->Session->setFlash(__('The group was added successfully.', true), 'good');
    225202                $this->redirect('index/'.$course_id);
    226             }
    227         }
    228 
    229         $course = $this->Course->getAccessibleCourseById($course_id, User::get('id'), User::getCourseFilterPermission());
    230         if (!$course) {
    231             $this->Session->setFlash(__('Error: Course does not exist or you do not have permission to view this course.', true));
    232             $this->redirect('/courses');
     203                return;
     204            }
    233205        }
    234206
     
    270242            $this->Session->setFlash(__('Error: That group does not exist.', true));
    271243            $this->redirect('/courses');
     244            return;
    272245        }
    273246
     
    276249            $this->Session->setFlash(__('Error: Course does not exist or you do not have permission to view this course.', true));
    277250            $this->redirect('/courses');
     251            return;
    278252        }
    279253
     
    285259            }
    286260            $this->redirect('index/'.$this->data['Group']['course_id']);
     261            return;
    287262        }
    288263
     
    312287     * delete
    313288     *
    314      * @param mixed $id
    315      *
    316      * @access public
    317      * @return void
    318      */
    319     function delete ($id = null)
     289     * @param mixed $groupId
     290     *
     291     * @access public
     292     * @return void
     293     */
     294    function delete ($groupId = null)
    320295    {
    321296        // Check whether the course exists
    322         $group = $this->Group->find('first', array('conditions' => array('Group.id' => $id), 'recursive' => 1));
     297        $group = $this->Group->find('first', array('conditions' => array('id' => $groupId), 'contain' => false));
    323298        if (empty($group)) {
    324299            $this->Session->setFlash(__('Error: That group does not exist.', true));
    325300            $this->redirect('/courses');
     301            return;
    326302        }
    327303
     
    330306            $this->Session->setFlash(__('Error: Course does not exist or you do not have permission to view this course.', true));
    331307            $this->redirect('/courses');
    332         }
    333 
    334         if ($this->Group->delete($id)) {
     308            return;
     309        }
     310
     311        if ($this->Group->delete($groupId)) {
    335312            $this->Session->setFlash(__('The group was deleted successfully.', true), 'good');
    336313        } else {
    337314            $this->Session->setFlash(__('Group delete failed.', true));
    338315        }
    339         $this->redirect('index/'.$this->Session->read('ipeerSession.courseId'));
     316        $this->redirect('index/'.$course['Course']['id']);
    340317    }
    341318
     
    375352                unlink($uploadFile);
    376353                //Mass create groups
    377                 $this->addGroupByImport($lines, $courseId);
     354                $this->_addGroupByImport($lines, $courseId);
    378355                // We should never get to this line :-)
    379356            } else {
     
    400377
    401378    /**
    402      * addGroupByImport
     379     * _addGroupByImport
    403380     * Takes an array of imported file lines, and creates groups from them
    404381     *
     
    409386     * @return void
    410387     */
    411     function addGroupByImport($lines, $courseId)
     388    function _addGroupByImport($lines, $courseId)
    412389    {
    413390        // Check for parameters
     
    731708        }
    732709    }
    733 
    734     /**
    735      * sendGroupEmail
    736      *
    737      * @param mixed $courseId
    738      *
    739      * @access public
    740      * @return void
    741      */
    742     function sendGroupEmail ($courseId)
    743     {
    744         if (is_numeric($courseId)) {
    745 
    746         } else {
    747 
    748         }
    749     }
    750710}
  • app/tests/cases/controllers/groups_controller.test.php

    rdb0c328 rb9b67fc  
    106106        $this->assertEqual($result['user_data'][5], '65498451 Ed Student *');
    107107        $this->assertEqual($result['user_data'][26], '19524032 Bill Student');
    108 
    109         //TODO test saving, redirect
     108    }
     109
     110    function testAddWithData() {
     111        // test with instructor account
     112        $this->login = array(
     113            'User' => array(
     114                'username' => 'instructor1',
     115                'password' => md5('ipeeripeer')
     116            )
     117        );
     118        $data = array(
     119            'Group' => array(
     120                'course_id' => 1,
     121                'group_num' => 3,
     122                'group_name' => 'Test1',
     123                'record_status' => 'A',
     124            ),
     125            'Member' => array(26, 31, 32),
     126        );
     127
     128        $this->controller->expectOnce('redirect', array('index/1'));
     129        $this->testAction(
     130            '/groups/add/1',
     131            array('fixturize' => true, 'data' => $data, 'method' => 'post')
     132        );
     133
     134        $model = ClassRegistry::init('Group');
     135        $group = $model->find('first', array( 'conditions' => array('group_name' => 'Test1'), 'contain' => array('Member')));
     136        foreach ($data['Group'] as $key => $expected) {
     137            $this->assertEqual($group['Group'][$key], $expected);
     138        }
     139        $this->assertEqual(count($group['Member']), 3);
     140        $memberIds = Set::extract($group['Member'], '/id');
     141        sort($memberIds);
     142        $this->assertEqual($memberIds, $data['Member']);
     143
     144        $message = $this->controller->Session->read('Message.flash');
     145        $this->assertEqual($message['message'], 'The group was added successfully.');
     146    }
     147
     148    function testAddWithDataToOthersCourse() {
     149        // test with instructor account
     150        $this->login = array(
     151            'User' => array(
     152                'username' => 'instructor2',
     153                'password' => md5('ipeeripeer')
     154            )
     155        );
     156        $data = array(
     157            'Group' => array(
     158                'course_id' => 1,
     159                'group_num' => 3,
     160                'group_name' => 'Test1',
     161                'record_status' => 'A',
     162            ),
     163            'Member' => array(26, 31, 32),
     164        );
     165
     166        $this->controller->expectOnce('redirect', array('/courses'));
     167        $this->testAction(
     168            '/groups/add/1',
     169            array('fixturize' => true, 'data' => $data, 'method' => 'post')
     170        );
     171
     172        $model = ClassRegistry::init('Group');
     173        $group = $model->find('first', array( 'conditions' => array('group_name' => 'Test1'), 'contain' => array('Member')));
     174        $this->assertFalse($group);
     175
     176        $message = $this->controller->Session->read('Message.flash');
     177        $this->assertEqual($message['message'], 'Error: Course does not exist or you do not have permission to view this course.');
    110178    }
    111179
     
    121189        $this->assertFalse(isset($result['user_data'][5]));
    122190        $this->assertEqual($result['user_data'][26], '19524032 Bill Student');
    123 
    124         //TODO test saving, redirect
     191    }
     192
     193    function testEditWithData() {
     194        // test with instructor account
     195        $this->login = array(
     196            'User' => array(
     197                'username' => 'instructor1',
     198                'password' => md5('ipeeripeer')
     199            )
     200        );
     201        $data = array(
     202            'Group' => array(
     203                'id' => 1,
     204                'course_id' => 1,
     205                'group_num' => 3,
     206                'group_name' => 'Test1',
     207                'record_status' => 'I',
     208            ),
     209            'Member' => array(26, 31, 32),
     210        );
     211
     212        $this->controller->expectOnce('redirect', array('index/1'));
     213        $this->testAction(
     214            '/groups/edit/1',
     215            array('fixturize' => true, 'data' => $data, 'method' => 'post')
     216        );
     217
     218        $model = ClassRegistry::init('Group');
     219        $group = $model->find('first', array( 'conditions' => array('id' => 1), 'contain' => array('Member')));
     220        foreach ($data['Group'] as $key => $expected) {
     221            $this->assertEqual($group['Group'][$key], $expected);
     222        }
     223        $this->assertEqual(count($group['Member']), 3);
     224        $memberIds = Set::extract($group['Member'], '/id');
     225        sort($memberIds);
     226        $this->assertEqual($memberIds, $data['Member']);
     227
     228        $message = $this->controller->Session->read('Message.flash');
     229        $this->assertEqual($message['message'], 'The group was updated successfully.');
     230    }
     231
     232    function testEditInvalidGroupId() {
     233        // test with instructor account
     234        $this->login = array(
     235            'User' => array(
     236                'username' => 'instructor1',
     237                'password' => md5('ipeeripeer')
     238            )
     239        );
     240        $data = array(
     241            'Group' => array(
     242                'id' => 999,
     243                'course_id' => 1,
     244                'group_num' => 3,
     245                'group_name' => 'Test1',
     246                'record_status' => 'I',
     247            ),
     248            'Member' => array(26, 31, 32),
     249        );
     250
     251        $this->controller->expectOnce('redirect', array('/courses'));
     252        $this->testAction(
     253            '/groups/edit/999',
     254            array('fixturize' => true, 'data' => $data, 'method' => 'post')
     255        );
     256
     257        $model = ClassRegistry::init('Group');
     258        $group = $model->find('first', array( 'conditions' => array('id' => 999), 'contain' => array('Member')));
     259        $this->assertFalse($group);
     260
     261        $message = $this->controller->Session->read('Message.flash');
     262        $this->assertEqual($message['message'], 'Error: That group does not exist.');
     263    }
     264
     265    function testEditGroupInOthersCourse() {
     266        // test with instructor account
     267        $this->login = array(
     268            'User' => array(
     269                'username' => 'instructor2',
     270                'password' => md5('ipeeripeer')
     271            )
     272        );
     273        $data = array(
     274            'Group' => array(
     275                'id' => 1,
     276                'course_id' => 1,
     277                'group_num' => 3,
     278                'group_name' => 'Test1',
     279                'record_status' => 'I',
     280            ),
     281            'Member' => array(26, 31, 32),
     282        );
     283
     284        $this->controller->expectOnce('redirect', array('/courses'));
     285        $this->testAction(
     286            '/groups/edit/1',
     287            array('fixturize' => true, 'data' => $data, 'method' => 'post')
     288        );
     289
     290        $model = ClassRegistry::init('Group');
     291        $group = $model->find('first', array( 'conditions' => array('id' => 999), 'contain' => array('Member')));
     292        $this->assertFalse($group);
     293
     294        $message = $this->controller->Session->read('Message.flash');
     295        $this->assertEqual($message['message'], 'Error: Course does not exist or you do not have permission to view this course.');
    125296    }
    126297
    127298    function testDelete() {
     299        $this->controller->expectOnce('redirect', array('index/1'));
     300        $this->testAction(
     301            '/groups/delete/1',
     302            array('fixturize' => true, 'method' => 'get')
     303        );
     304
     305        $model = ClassRegistry::init('Group');
     306        $found = $model->find('first', array( 'conditions' => array('id' => 1), 'contain' => false));
     307        $this->assertFalse($found);
     308
     309        $message = $this->controller->Session->read('Message.flash');
     310        $this->assertEqual($message['message'], 'The group was deleted successfully.');
     311    }
     312
     313    function testDeleteInvalidGroup() {
     314        $this->controller->expectOnce('redirect', array('/courses'));
     315        $this->testAction(
     316            '/groups/delete/999',
     317            array('fixturize' => true, 'method' => 'get')
     318        );
     319
     320        $model = ClassRegistry::init('Group');
     321        $found = $model->find('first', array( 'conditions' => array('id' => 999), 'contain' => false));
     322        $this->assertFalse($found);
     323
     324        $message = $this->controller->Session->read('Message.flash');
     325        $this->assertEqual($message['message'], 'Error: That group does not exist.');
     326    }
     327
     328    function testDeleteOthersGroup() {
     329        $this->login = array(
     330            'User' => array(
     331                'username' => 'instructor2',
     332                'password' => md5('ipeeripeer')
     333            )
     334        );
     335        $this->controller->expectOnce('redirect', array('/courses'));
     336        $this->testAction(
     337            '/groups/delete/1',
     338            array('fixturize' => true, 'method' => 'get')
     339        );
     340
     341        $model = ClassRegistry::init('Group');
     342        $found = $model->find('first', array( 'conditions' => array('id' => 1), 'contain' => false));
     343        $this->assertTrue($found);
     344
     345        $message = $this->controller->Session->read('Message.flash');
     346        $this->assertEqual($message['message'], 'Error: Course does not exist or you do not have permission to view this course.');
     347    }
     348
     349    function testImport() {
     350    }
     351
     352    function testExport() {
    128353    }
    129354}
  • app/views/elements/courses/submenu.ctp

    rdb0c328 rb9b67fc  
    2121        'link' => "/groups/import/$course_id"),
    2222      array('name' => 'List Groups',
    23         'link' => "/groups/goToClassList/$course_id"),
    24       array('name' => 'Export Groups Information',
     23        'link' => "/groups/index/$course_id"),
     24      array('name' => 'Export Groups',
    2525        'link' => "/groups/export/$course_id")
    2626    );
  • app/views/elements/groups/group_list_chooser.ctp

    rdb0c328 rb9b67fc  
    2929      <?php
    3030        $options = array(
    31                          'style' => $listStyle,
    32                      'div' => false,
    33                      'label' => false,
    34                      'before' => '',
    35                      'after' => '',
    36                      'separator' => '',
    37                      'between' => '',
    38                      'id' => 'selected_groups' );
    39         if(isset($assigned))
     31            'style' => $listStyle,
     32            'div' => false,
     33            'label' => false,
     34            'before' => '',
     35            'after' => '',
     36            'separator' => '',
     37            'between' => '',
     38            'id' => 'selected_groups' );
     39        if (isset($assigned)) {
    4040          $options['options'] = $assigned;
     41        }
    4142
    4243        echo $this->Form->input('Member.Member', $options);
     
    4445    </td>
    4546</tr>
    46 <tr class="note">
    47     <td colspan="3">
    48      <?php __('Note: Students already in one or more groups are marked')?><br>
    49      <?php __('with * and are listed under those without groups')?>
    50     </td>
    51 </tr>
    5247</table>
  • app/views/groups/edit.ctp

    rdb0c328 rb9b67fc  
    2121<div class="input select">
    2222<?php echo $this->Form->label('', __('Members', true))?>
     23    <div style="margin-left: 14em; width: 28em; text-align:center">
    2324    <?php echo $this->element("groups/group_list_chooser",
    2425                array('all' => $user_data, 'status' => $status,
    2526                      'allName' =>  __("Filtered Students", true), 'selectedName' => __('Students in Group', true)));
    2627    ?>
     28     <font size="2em">
     29     <?php __('Note: Students already in one or more groups are marked')?><br>
     30     <?php __('with * and are listed under those without groups')?>
     31     </font>
     32     </div>
    2733</div>
    2834    <?php echo $this->Form->submit(ucfirst($this->action).__(' Group', true), array(
  • app/views/groups/export.ctp

    rdb0c328 rb9b67fc  
    22<div class="content-container">
    33    <form name="frm" id="frm" method="POST" action="<?php echo $html->url('export/'.$courseId) ?>">
    4       <table class="full-size">
    5         <tr class="tableheader">
    6           <td colspan="2" align="center">Export As</td>
     4      <table class="standardtable">
     5        <tr>
     6          <th colspan="2" align="center">Export As</th>
    77        </tr>
    8         <tr class="tablecell2">
     8        <tr>
    99          <td width="30%">Export Filename:</td><td width="40%"><input type="text" name="file_name" value="<?php if(isset($file_name)) echo $file_name;?>" />.csv</td>
    1010        </tr>
    11         <tr class="tableheader">
    12           <td colspan="2" align="center">Export Group Fields</td>
     11        <tr>
     12          <th colspan="2" align="center">Export Group Fields</th>
    1313        </tr>
    14         <tr><td style="color:darkred; font-size:smaller"> (Please select at least one of the fields)</td></tr>
    15         <tr class="tablecell2">
     14        <tr><td colspan="2" style="color:darkred; font-size:smaller"> (Please select at least one of the fields)</td></tr>
     15        <tr>
    1616          <td width="60%">Include Group Number(s):</td><td><input type="checkbox" name="include_group_numbers" checked /></td>
    1717        </tr>
    18         <tr class="tablecell2">
     18        <tr>
    1919          <td width="60%">Include Group Name(s):</td><td><input type="checkbox" name="include_group_names" checked /></td>
    2020        </tr>
    21         <tr class="tablecell2">
     21        <tr>
    2222          <td width="60%">Include Username(s):</td><td><input type="checkbox" name="include_usernames" checked /></td>
    2323        </tr>
    24         <tr class="tablecell2">
     24        <tr>
    2525          <td width="60%">Include Student Id #:</td><td><input type="checkbox" name="include_student_id" checked /></td>
    2626        </tr>
    27         <tr class="tablecell2">
     27        <tr>
    2828          <td width="60%">Include Student Name(s):</td><td><input type="checkbox" name="include_student_name" checked /></td>
    2929        </tr>
    3030        <?php /*if (User::hasPermission('functions/viewemailaddress')) { ?>
    31             <tr class="tablecell2">
     31            <tr>
    3232              <td>Include Student Email(s):</td><td><input type="checkbox" name="include_student_email" /></td>
    3333            </tr>
    3434        <?php }*/ ?>
    3535        </table>
    36         <table class="full-size">
    37         <tr class="tableheader">
    38           <td colspan="1" align="center">Group Selection</td>
     36        <table class="standardtable">
     37        <tr>
     38          <th>Group Selection</th>
    3939        </tr>
    40         <tr class="tablecell2">
    41           <td align="center">
     40        <tr>
     41          <td>
    4242<?php
    4343echo $this->element("groups/group_list_chooser",
     
    4848          </td>
    4949        </tr>
    50         <tr class="tablecell2">
    51           <td colspan="3" align="center">
     50        <tr>
     51          <td>
    5252<?php echo $this->Form->submit(ucfirst($this->action).__(' Group', true), array('div' => false,
    5353    'onClick' => "processSubmit(document.getElementById('selected_groups'));")) ?>
  • app/views/groups/import_results.ctp

    rdb0c328 rb9b67fc  
    88    to the list of groups, or look below for the results of the import.')?>
    99    <br /> <br />
    10     <input type="button" name="Okay" value="OK" onClick="window.location='<?php echo $this->webroot . "groups/goToClassList/". $courseId ?>'";>
     10    <input type="button" name="Okay" value="OK" onClick="window.location='<?php echo $this->webroot . "groups/index/". $courseId ?>'";>
    1111    </center>
    1212    <br /> <br />
  • app/webroot/css/ipeer.css

    rdb0c328 rb9b67fc  
    14081408}
    14091409
     1410table.group-list-chooser {
     1411    margin: auto;
     1412    border: none;
     1413}
     1414
     1415table.group-list-chooser td{
     1416    border: none;
     1417    background-color: none;
     1418}
     1419
    14101420.group-list-chooser td.middle-column{
    14111421    width: 100px;
Note: See TracChangeset for help on using the changeset viewer.