Changeset 746

Show
Ignore:
Timestamp:
09/01/08 20:58:25 (3 months ago)
Author:
aarkerio
Message:

Little Bugs fixed

Location:
trunk/app
Files:
3 modified

Legend:

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

    r745 r746  
    7171 { 
    7272  $points = (int) 0; 
     73  $conditions = array('Result.test_id'=>$test_id, 'Result.user_id'=>$user_id, 'Result.vclassroom_id'=>$vclassroom_id); 
     74  $this->Result->unbindAll();  // removeds unnecesary stuff 
     75  $answers    = $this->Result->findAll($conditions);  // get the answers gived by student 
    7376 
    74   $conditions = array('Result.test_id'=>$test_id, 'Result.user_id'=>$user_id, 'Result.vclassroom_id'=>$vclassroom_id); 
    75    
    76   $this->Result->unbindAll();  // removeds unnecesary stuff 
     77  if ( count($answers) < 1):    // test not answer yet 
     78    return null; 
     79  endif; 
    7780 
    78   $answers    = $this->Result->findAll($conditions);  // get the answers gived by student 
    79    
    8081  foreach($answers as $a): 
    81     $question = $this->Question->find(array('Question.id'=>$a['Result']['question_id']), array('worth')); // how much points question have? 
     82    $question = $this->Question->find(array('Question.id'=>$a['Result']['question_id']), array('worth')); //how much points question have? 
    8283    foreach($question['Answer'] as $qa): 
    8384        if ($qa['id'] == $a['Result']['answer_id'] && $qa['question_id'] == $a['Result']['question_id'] && $qa['correct'] == 1): 
  • trunk/app/models/vclassroom.php

    r745 r746  
    140140 { 
    141141   // 1) wee need check tree models: Test, Webquest and Treasures ans results associated to them: 
    142    // Result, ResultTreasure and ResultWebquest, so will get the stundents answer   
     142   // Result, ResultTreasure and ResultWebquest, so will get the students answer   
    143143  try{    
    144144     $record                  = array(); 
     
    151151     // Consult Test Model associated to this Vclassroom 
    152152     $this->TestsVclassroom->bindModel(array('belongsTo'=>array('Test'))); 
    153       
    154153     $conditions        = array('TestsVclassroom.vclassroom_id'=>$vclassroom_id); 
    155154     $fields            = array('TestsVclassroom.test_id', 'TestsVclassroom.id', 'Test.title');  
    156155     $record['tests']   = $this->TestsVclassroom->findAll($conditions, $fields); 
    157      // die(debug($record)); 
    158156 
    159157     // foreach test check in Result model 
    160158     foreach($record['tests'] as $k => $t): 
    161        $record['tests'][$k]['TestsVclassroom']['title'] = $t['Test']['title']; 
    162        $this->Test->Result->unbindAll(); 
    163        $this->Test->Result->bindModel(array('belongsTo'=>array('Question','Test'))); 
    164         
    165        $conditions = array('Result.vclassroom_id'=>$vclassroom_id,'Result.user_id'=>$user_id,'Result.test_id'=>$t['TestsVclassroom']['test_id']); 
    166        $fields     = array('Result.correct', 'Result.answer_id','Question.worth'); 
    167        $results    = $this->Test->Result->findAll($conditions, $fields); 
    168        //debug($results); 
    169        // Get points from answers 
    170        if ( count($results) > 0 ): 
    171             $points     = (int) 0; 
    172        else: 
    173             $points     = null;   //student has not answered this test yet 
    174        endif; 
    175         
    176        foreach($results as $r): 
    177             if ($r['Result']['correct'] == 1): 
    178                   $points     += (int) $r['Question']['worth'];      
    179         endif; 
    180        endforeach; 
    181         
    182        $record['tests'][$k]['TestsVclassroom']['points'] = $points; 
    183      endforeach; 
    184      //die(debug($record['tests'])); 
     159       $record['tests'][$k]['TestsVclassroom']['points'] = $this->Test->getPoints($t['TestsVclassroom']['test_id'], $user_id, $vclassroom_id); 
     160     endforeach; 
     161     // die(debug($record['tests'])); 
    185162 
    186163     // Now Treasure model 
     
    418395   endif;  
    419396 } 
    420  
     397/* 
     398 *  studentPoints  
     399 *    
     400 */ 
    421401 public function studentPoints($user_id, $vclassroom_id) 
    422402 { 
     
    424404     $points  = (int) 0; // student total points in eCourse  
    425405    
    426      // Consult Test Model  
    427      /* $conditions = array('Result.vclassroom_id'=>$vclassroom_id, 'Result.user_id'=>$user_id); 
    428      $fields     = array('Result.points'); 
    429      $tests      = $this->Test->Result->findAll($conditions, $fields); 
     406     // Consult TestsVclassroom  Model  
     407     $conditions = array('TestsVclassroom.vclassroom_id'=>$vclassroom_id); 
     408     $fields     = array('TestsVclassroom.test_id'); 
     409     $tests      = $this->TestsVclassroom->findAll($conditions, $fields); 
     410      
    430411     foreach ($tests as $test): 
    431             $points += (int) $this->Test->getPoints($test['test']['id'], $user_id, $vclassroom_id); 
    432      endforeach; 
    433      die('pints  '. $points);*/ 
     412            $points += (int) $this->Test->getPoints($test['TestsVclassroom']['test_id'], $user_id, $vclassroom_id); 
     413     endforeach; 
    434414      
    435415     // Consult Treasure Model 
     
    456436            $points += $pa['Participation']['points']; 
    457437     endforeach; 
    458    
     438 
     439     // Reports 
     440     $conditions     = array('Report.vclassroom_id'=>$vclassroom_id, 'Report.student_id'=>$user_id); 
     441     $fields         = array('Report.points'); //null;  
     442     $reports        = $this->Report->findAll($conditions, $fields); 
     443     foreach ($reports as $rep): 
     444            $points += $rep['Report']['points']; 
     445     endforeach; 
     446      
    459447     // Webquest 
    460448     $conditions     = array('ResultWebquest.vclassroom_id'=>$vclassroom_id, 'ResultWebquest.user_id'=>$user_id); 
     
    465453     endforeach; 
    466454          
    467      //die(debug($record)); 
     455     //die(debug($points)); 
    468456     return $points; 
    469457  } 
     
    483471   $data        = $this->UsersVclassroom->findAll($conditions, $fields); 
    484472 
    485    if ( $data == null ) 
    486    { 
     473   if ( $data == null ): 
    487474     return null;  
    488    } 
    489    else 
    490    { 
     475   else: 
    491476       $vclassrooms = array(); 
    492  
    493        foreach ($data as $v) 
    494        { 
    495      foreach($v['UsersVclassroom'] as $m) 
    496      { 
    497          array_push($vclassrooms, $m); 
    498      } 
    499        } 
    500    } 
     477       foreach ($data as $v): 
     478      foreach($v['UsersVclassroom'] as $m): 
     479          array_push($vclassrooms, $m); 
     480      endforeach; 
     481       endforeach; 
     482   endif; 
    501483   return $vclassrooms; 
    502484 } 
    503485 
    504   /** 
    505    * Adds a join record between two records of a hasAndBelongsToMany association 
    506    * 
    507    * @param mixed $assoc The name of the HABTM association 
    508    * @param mixed $assoc_ids The associated id or an array of associated ids 
    509    * @param integer $id The id of the record in this model 
    510    * @return boolean Success 
    511    */ 
    512   public function addAssoc($assoc, $assoc_ids, $id = null) 
    513   { 
    514     if ($id != null)  
    515     { 
    516       $this->id = $id; 
    517     } 
    518  
    519     $id = $this->id; 
    520  
    521     if (is_array($this->id))  
    522     { 
    523       $id = $this->id[0]; 
    524     } 
    525          
    526     if ($this->id !== null && $this->id !== false) 
    527     { 
    528       $db =& ConnectionManager::getDataSource($this->useDbConfig); 
    529              
    530       $joinTable = $this->hasAndBelongsToMany[$assoc]['joinTable']; 
    531  
    532       $table = $db->name($db->fullTableName($joinTable)); 
    533              
    534       $keys[] = $this->hasAndBelongsToMany[$assoc]['foreignKey']; 
    535       $keys[] = $this->hasAndBelongsToMany[$assoc]['associationForeignKey']; 
    536       $fields = join(',', $keys); 
    537              
    538       if ( !is_array($assoc_ids) )  
    539       { 
    540     $assoc_ids = array($assoc_ids); 
    541       } 
    542          
    543       // to prevent duplicates 
    544       $this->deleteAssoc($assoc,$assoc_ids,$id); 
    545              
    546       foreach ($assoc_ids as $assoc_id)  
    547       { 
    548     $values[]  = $db->value($id, $this->getColumnType($this->primaryKey)); 
    549     $values[]  = $db->value($assoc_id); 
    550     $values    = join(',', $values); 
    551          
    552         $q = "INSERT INTO {$table} ({$fields}) VALUES ({$values})"; 
    553  
    554         // echo $q; 
    555  
    556     $db->execute($q); 
    557  
    558     unset ($values); 
    559       } 
    560              
    561       return true; 
    562     }  
    563     else  
    564     { 
    565       return false; 
    566     } 
    567   } 
    568  
    569   /** 
    570    * Deletes any join records between two records of a hasAndBelongsToMany association 
    571    * 
    572    * @param integer $id The id of the record in this model 
    573    * @param mixed $assoc The name of the HABTM association 
    574    * @param mixed $assoc_ids The associated id or an array of associated ids 
    575    * @return boolean Success 
    576    */ 
    577   public function deleteAssoc($assoc, $assoc_ids, $id = null) 
    578   { 
    579     if ($id != null)  
    580     { 
    581       $this->id = $id; 
    582     } 
    583  
    584     $id = $this->id; 
    585  
    586     if (is_array($this->id))  
    587     { 
    588       $id = $this->id[0]; 
    589     } 
    590          
    591     if ($this->id !== null && $this->id !== false) { 
    592       $db =& ConnectionManager::getDataSource($this->useDbConfig); 
    593              
    594       $joinTable = $this->hasAndBelongsToMany[$assoc]['joinTable'];     
    595       $table = $db->name($db->fullTableName($joinTable)); 
    596              
    597       $mainKey = $this->hasAndBelongsToMany[$assoc]['foreignKey']; 
    598       $assocKey = $this->hasAndBelongsToMany[$assoc]['associationForeignKey']; 
    599              
    600       if (!is_array($assoc_ids))  
    601       { 
    602     $assoc_ids = array($assoc_ids); 
    603       } 
    604              
    605       foreach ($assoc_ids as $assoc_id)  
    606       { 
    607     $db->execute("DELETE FROM {$table} WHERE {$mainKey} = '{$id}' AND {$assocKey} = '{$assoc_id}'"); 
    608       } 
    609              
    610        return true; 
    611     }  
    612     else  
    613     { 
    614         return false; 
    615     } 
    616   } 
    617486/* 
    618487 *  check if student belongs to class group 
  • trunk/app/views/vclassrooms/admin_record.ctp

    r745 r746  
    3030 
    3131 // Tests 
     32 $test_points = (int) 0; 
    3233 if ( count($data['tests']) > 0 ): 
    3334  echo '<h1>'. __('Tests', true).'</h1>'; 
     
    3839    if ($t['TestsVclassroom']['points'] === null):  // not answered yet 
    3940      e($html->div(null, __('Not answered this test yet', true), array('id'=>$div_id,'style'=>'width:220px;float:left;font-size:7pt;'))); 
    40       e($html->div(null, $t['TestsVclassroom']['title'], array('style'=>'width:350px;float:right;'))); 
     41      e($html->div(null, $t['Test']['title'], array('style'=>'width:350px;float:right;'))); 
    4142    else: 
    4243      e($html->div(null, $t['TestsVclassroom']['points'].' '.__('points',true),array('id'=>$div_id,'style'=>'width:180px;float:left;'))); 
    4344      e('<div style="width:450px;float:right;">'); 
    44       echo $html->link($t['TestsVclassroom']['title'], '#'.$div_id, array('title'=>'View test', 'onclick'=> 
     45      echo $html->link($t['Test']['title'], '#'.$div_id, array('title'=>'View test', 'onclick'=> 
    4546        "window.open('/admin/tests/see/".$data['User']['id']."/".$t['TestsVclassroom']['test_id']."/".$data['Vclassroom']['id']."','mywin','left=20,top=10,width=700,height=700,scrollbars=1,toolbar=0,resizable=1')")) . '&nbsp;&nbsp;'; 
    4647        e('</div>'); 
    4748      endif; 
    4849      e('</div>'); 
     50      $test_points += (int) $t['TestsVclassroom']['points']; 
    4951    endforeach; 
    5052 else: 
     
    5355 
    5456 // Webquests --> ResultWebquest 
    55  $wpoints = (int) 0; // webquest points 
     57 $webquest_points = (int) 0; // webquest points 
    5658 if ( count($data['webquests']) > 0 ): 
    5759   echo '<h1>Webquests</h1>'; 
    5860   foreach ($data['webquests'] as $w): 
    59      $wpoints += $w['ResultWebquest']['points']; 
     61     $webquest_points += $w['ResultWebquest']['points']; 
    6062     $div_id   = 'w'.$w['Webquest']['id']; 
    6163     e('<div style="border:1px dotted gray;padding:4px;margin:2px;height:20px;">'); 
     
    8789  
    8890 // Treasures. Model: Treasure   
    89  $tpoints = (int) 0; // tresure points 
     91 $treasure_points = (int) 0; // tresure points 
    9092 echo '<h1>'. __('Scavengers hunts', true).'</h1>'; 
    9193 if ( count($data['treasures']) > 0 ): 
    9294  foreach ($data['treasures'] as $tr): 
     95     $treasure_points += (int) $tr['ResultTreasure']['points']; 
    9396     $div_id   = 'tr'.$tr['Treasure']['id']; 
    9497     e('<div style="border:1px dotted gray;padding:4px;margin:2px;height:20px;">'); 
     
    120123 // Replies on forums. Model: Topic   
    121124 echo '<h1>'.__('Participations in forums', true).'</h1>'; 
    122  $rpoints = (int) 0; 
     125 $reply_points = (int) 0; 
    123126 if ( count($data['replies']) > 0 ): 
    124127   foreach ($data['replies'] as $re):   
     
    145148        e('</div>');  
    146149       e('</div>'); 
    147        $rpoints += (int) $re['Reply']['points']; 
     150       $reply_points += (int) $re['Reply']['points']; 
    148151    endforeach; 
    149152  e($html->div(null, $html->image('static/loading.gif', array('alt'=>'Loading')), array('style'=>'display:none', 'id'=>'lorep'))); 
     
    153156  
    154157 // Participations, model:  Participation 
    155  $ppoints = (int) 0;  // participation points 
     158 $participation_points = (int) 0;  // participation points 
    156159 echo '<h1>'.__('Participations', true).'</h1>';  
    157160 if ( count($data['participations']) > 0 ): 
     
    159162   e('<div style="border:1px dotted gray;padding:4px;margin:2px;height:20px;">'); 
    160163   $div_id = 'pa'.$p['Participation']['id']; 
    161    $ppoints += $p['Participation']['points']; 
     164   $participation_points += (int) $p['Participation']['points']; 
    162165   
    163166   echo $html->div(null, $p['Participation']['points'].' '.__('points', true), array('id'=>$div_id,'style'=>'width:150px;float:left;')); 
     
    189192  
    190193 // Reports, model:  Report 
    191  $repoints = (int) 0;  // report points 
     194 $report_points = (int) 0;  // report points 
    192195 echo '<h1>'.__('Reports', true).'</h1>';  
    193196 if ( count($data['reports']) > 0 ): 
     
    195198   e('<div style="border:1px dotted gray;padding:4px;margin:2px;height:20px;">'); 
    196199   $div_id = 're'.$r['Report']['id']; 
    197    $repoints += (int) $r['Report']['points']; 
     200   $report_points += (int) $r['Report']['points']; 
    198201   echo $html->div(null, $r['Report']['points'].' '.__('points',true),  array('id'=>$div_id,'style'=>'width:150px;float:left;')); 
    199202 
     
    224227 endif; 
    225228 
    226  echo  $html->div(null, __('Scavengers hunts', true) .' ' .__('points', true) .': '. $tpoints); 
    227  echo  $html->div(null, 'Webquests ' .__('points', true) .': '. $wpoints); 
    228  echo  $html->div(null, __('Replies', true). ' ' .__('points', true) .': '. $rpoints); 
    229  echo  $html->div(null, __('Participations', true) .' '. __('points', true) .': '. $ppoints, array('id'=>'parpoints')); 
    230  echo  $html->div(null, __('Reports', true) .' '. __('points', true) .': '. $repoints, array('id'=>'reppoints')); 
    231   
    232  $points = ($tpoints + $wpoints + $rpoints + $ppoints + $repoints); 
     229 echo  $html->div(null, __('Test', true) .' ' .__('points', true) .': '. $test_points); 
     230 echo  $html->div(null, __('Scavengers hunts', true) .' ' .__('points', true) .': '. $treasure_points); 
     231 echo  $html->div(null, 'Webquests ' .__('points', true) .': '. $webquest_points); 
     232 echo  $html->div(null, __('Replies', true). ' ' .__('points', true) .': '. $reply_points); 
     233 echo  $html->div(null, __('Participations', true) .' '. __('points', true) .': '. $participation_points, array('id'=>'parpoints')); 
     234 echo  $html->div(null, __('Reports', true) .' '. __('points', true) .': '. $report_points, array('id'=>'reppoints')); 
     235  
     236 $points = ($test_points + $treasure_points + $webquest_points + $reply_points + $participation_points + $report_points); 
    233237  
    234238 echo  $ajax->div('totalpoints') .'<b>'.__('Total points', true).': ' . $points .'</b>'. $ajax->divEnd('totalpoints');