Changeset 429

Show
Ignore:
Timestamp:
04/24/08 21:33:43 (9 months ago)
Author:
aarkerio
Message:

Tests and answers

Location:
trunk/app
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/app/config/sql/karamelo_postgres.sql

    r418 r429  
    589589   results smallint NOT NULL, 
    590590   test_id int NOT NULL REFERENCES tests(id) ON DELETE CASCADE, 
    591    PRIMARY KEY (user_id, test_id) 
     591   vclassroom_id int NOT NULL REFERENCES vclassrooms(id) ON DELETE CASCADE, 
     592   PRIMARY KEY (user_id, test_id, vclassroom_id) 
    592593); 
    593594-- Test model tables ends 
    594595 
    595  
    596 -- Share it! 
     596-- Share stuff (docs an5Dd multimedia) with your students 
    597597CREATE TABLE shares ( 
    598598id serial PRIMARY KEY, 
  • trunk/app/controllers/tests_controller.php

    r428 r429  
    6868     // the student alredy answered this test? 
    6969     $already = $this->Test->Result->field('Result.id', array("Result.user_id"=>$this->Auth->user('id'), "Result.test_id"=>$test_id)); 
    70  
     70      
    7171     if ($already != null) 
    7272     { 
     
    7575         exit(); 
    7676     } 
    77  
     77     
    7878    if ( $this->Auth->user() && $this->Auth->user('group_id') == 3) 
    7979    { 
     
    9595 
    9696    $this->set('data', $this->Test->find($conditions, $fields, $order, 2)); 
    97   } 
     97 } 
    9898 
    9999 public function result() 
    100100 {  
    101101 try { 
    102     // die(debug($this->data['Test'])); 
    103  
     102   //die(debug($this->data['Test'])); 
     103    if ( $this->Auth->user() && $this->Auth->user('group_id') == 3) 
     104    { 
     105       $student_id = (int) $this->Auth->user('id'); 
     106           $this->Edublog->setSession($student_id); //check if user belongs to class 
     107    } 
     108     
    104109    $this->pageTitle = 'Test Results'; 
    105110     
     
    130135         if ( $res['Answer']['correct'] == 1)        
    131136     { 
    132             echo 'worth: ' . $res['Question']['worth'].'<br />'; 
    133137            $points += (int) $res['Question']['worth'];         
    134138         } 
     
    137141    // die('Points:  '. $points); 
    138142          
    139     $this->data['Result']['test_id'] =  $this->data['Question']['test_id']; 
    140  
    141     $this->data['Result']['user_id']    = $this->Auth->user('id'); 
    142     $this->data['Result']['user_id']    = $points;   
     143    $this->data['Result']['user_id']        = $this->Auth->user('id'); 
     144    $this->data['Result']['results']        = $points; 
     145    $this->data['Result']['test_id']        = $this->data['Test']['test_id'];  
     146    $this->data['Result']['vclassroom_id']  = $this->data['Test']['vclassroom_id']; 
     147 
    143148    $this->Test->Result->create(); 
    144149       
    145150    if ($this->Test->Result->save($this->data['Result']) ) 
    146151    { 
    147          $this->set('data',     $this->Test->find($conditions, null, null, 2)); 
    148          $this->set('results', $this->data['Result']); 
    149     } 
    150     }  
    151     catch (Exception $e)  
    152     { 
     152         $this->data['Test']['results']          = $points; 
     153         $maxpoints = (int) $this->data['Test']['maxpoints']; 
     154         $this->data['Test']['percentage']        = number_format( ( ($points / $maxpoints)*100), 2, '.', ''); 
     155         $this->set('data', $this->data['Test']); 
     156    } 
     157  } 
     158  catch (Exception $e)  
     159  { 
    153160      echo "Caught my exception\n" . $e; 
    154     }    
     161  }    
    155162 } 
    156163 
  • trunk/app/views/tests/result.ctp

    r264 r429  
    11<?php 
    2 // exit(var_dump($data)); 
    3 ?> 
     2//exit(debug($data)); 
     3$auth = true; 
    44 
    5 <div style="font-size:18pt;padding:5px;boder:1px solid #c0c0c0"> <?php echo $blog["User"]["username"]; ?>'s Exam</div> 
     5/* if ( $session->check('vclassrooms') ): 
     6   foreach($data['Vclassroom'] as $v): 
     7       if ( in_array($v['id'], $session->read('vclassrooms'))): 
     8              $auth = true;  
     9          break; 
     10       endif; 
     11   endforeach; 
     12endif; */ 
     13  
     14if ( $auth === true ): 
    615 
    7 <?php 
    8 if ( $othAuth->sessionValid() && $othAuth->user('group_id') == 3) 
    9 { 
    10  echo '<h2>' . $othAuth->user('username') .'\'s results </h2>'; 
     16 echo '<h2>' . $cU['User']['username'] .'\'s results </h2>'; 
    1117 
    12  echo '<p>You result was: <b>'.$results['results'].'</b> points. Result has been saved, Thanks!<p>'; 
     18 echo $html->div('result', $data['percentage'].'%'); 
    1319 
    14  echo '<h1>'. $data['Test']['title'] . '</h1>'; 
     20 echo $html->para(null, 'You result was: <b>'.$data['results'].'</b> from ' .$data['maxpoints'] .' possible score. Result has been saved, Thanks!'); 
    1521 
    16  echo '<p>'.  $data['Test']['description'] . '</p>'; 
    1722 
    18  foreach ($data['Question'] as $val) 
    19  { 
    20    //exit(var_dump($val)); 
    21    echo '<div>'; 
    22    echo '<div style="font-size:14pt;margin:5px 0 6px 0">' . $val['question'] .' '. $val['worth']  .'</div>';  
    23      
    24    $total = 0; 
    25  
    26    foreach ($val["Answer"] as $v) 
    27    { 
    28        // $v['id'] = $v['answer']; 
    29   
    30        echo 'Your answer was:'; 
    31    } 
    32  
    33    
    34     echo '<br /><b>Hint was</b>: <i>' .  $val['hint']  . '</i><br /><br />'; 
    35     echo '</div>'; 
    36  } 
    37  
    38 } 
    39 else 
    40 { 
    41   echo '<p>You must be logged to see this exam</p>'; 
    42 } 
     23else: 
     24  echo '<p>You must be logged adn belongs to this class to see this exam</p>'; 
     25endif; 
    4326 
    4427 
  • trunk/app/views/tests/view.ctp

    r428 r429  
    11<?php 
    2 // die(debug($data)); 
     2//die(debug($data)); 
    33 
    44$auth = false; 
     
    88       if ( in_array($v['id'], $session->read('vclassrooms'))): 
    99              $auth = true; 
     10              $vclassroom_id = $v['id'];  
    1011          break; 
    1112       endif; 
     
    2425  echo $form->hidden('test_id', array('value'=>$data['Test']['id'])); 
    2526  echo $form->hidden('blogger_id', array('value'=>$blog['User']['id'])); 
     27  echo $form->hidden('vclassroom_id', array('value'=>$vclassroom_id )); 
    2628 
    27 $points = 0;   
     29  $maxpoints = 0;   
    2830  foreach ($data['Question'] as $val): 
    2931    //exit(debug($val)); 
    30     $points += (int) $val['worth']; 
    31        echo '<div>'; 
     32    $maxpoints += (int) $val['worth']; 
     33    echo $html->para(null, 'Maxim calification: ' . $maxpoints); 
     34    echo $form->hidden('maxpoints', array('value'=>$maxpoints)); 
     35    echo '<div>'; 
    3236        
    3337          $options = array(); // to build options radio buttons 
     
    4549  endforeach; 
    4650  
    47   echo $html->para(null, 'Maxim calification: '.$points); 
    4851  echo $form->end('Send'); 
    4952