Changeset 578 for trunk/app/models

Show
Ignore:
Timestamp:
06/02/08 09:10:21 (6 months ago)
Author:
aarkerio
Message:

Update

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/app/models/test.php

    r576 r578  
    116116 } 
    117117 
    118  public function getTest($test_id, $user_id, $vclassroom_id) 
     118 public function getTest($user_id, $test_id, $vclassroom_id) 
    119119 { 
    120   $tests = $this->Test->Question->findAll(array('Question.test_id'=>$this->data['Test']['test_id']), $fields); 
    121  
    122     //die(debug($this->data['Test'])); 
    123   
    124     $points  = 0;  
    125  
    126     foreach($this->data['Test'] as $k => $t): 
    127       if ( is_numeric($k) ): 
    128     $res = $this->Test->Question->Answer->find(array('Answer.id'=>$t));  
    129      if ( $res['Answer']['correct'] == 1): 
    130              $points += (int) $res['Question']['worth'];         
    131      endif; 
    132       endif; 
    133     endforeach; 
     120  $conditions = array('Result.user_id'=>$user_id, 'Result.test_id'=>$test_id, 'Result.vclassroom_id'=>$vclassroom_id); 
     121  $this->Result->bindModel(array('belongsTo'=>array('Question', 'Answer'))); 
     122  $fields     = array('Result.id', 'Result.created','Result.question_id','Test.title', 'Question.question', 'Question.worth', 'Answer.answer', 'Answer.correct'); 
     123  $data       = $this->Result->findAll($conditions, $fields); 
    134124     
    135    return $data; 
     125  return $data; 
    136126 } 
    137127