Changeset 746
- Timestamp:
- 09/01/08 20:58:25 (3 months ago)
- Location:
- trunk/app
- Files:
-
- 3 modified
-
models/test.php (modified) (1 diff)
-
models/vclassroom.php (modified) (7 diffs)
-
views/vclassrooms/admin_record.ctp (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/app/models/test.php
r745 r746 71 71 { 72 72 $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 73 76 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 stuff77 if ( count($answers) < 1): // test not answer yet 78 return null; 79 endif; 77 80 78 $answers = $this->Result->findAll($conditions); // get the answers gived by student79 80 81 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? 82 83 foreach($question['Answer'] as $qa): 83 84 if ($qa['id'] == $a['Result']['answer_id'] && $qa['question_id'] == $a['Result']['question_id'] && $qa['correct'] == 1): -
trunk/app/models/vclassroom.php
r745 r746 140 140 { 141 141 // 1) wee need check tree models: Test, Webquest and Treasures ans results associated to them: 142 // Result, ResultTreasure and ResultWebquest, so will get the stu ndents answer142 // Result, ResultTreasure and ResultWebquest, so will get the students answer 143 143 try{ 144 144 $record = array(); … … 151 151 // Consult Test Model associated to this Vclassroom 152 152 $this->TestsVclassroom->bindModel(array('belongsTo'=>array('Test'))); 153 154 153 $conditions = array('TestsVclassroom.vclassroom_id'=>$vclassroom_id); 155 154 $fields = array('TestsVclassroom.test_id', 'TestsVclassroom.id', 'Test.title'); 156 155 $record['tests'] = $this->TestsVclassroom->findAll($conditions, $fields); 157 // die(debug($record));158 156 159 157 // foreach test check in Result model 160 158 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'])); 185 162 186 163 // Now Treasure model … … 418 395 endif; 419 396 } 420 397 /* 398 * studentPoints 399 * 400 */ 421 401 public function studentPoints($user_id, $vclassroom_id) 422 402 { … … 424 404 $points = (int) 0; // student total points in eCourse 425 405 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 430 411 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; 434 414 435 415 // Consult Treasure Model … … 456 436 $points += $pa['Participation']['points']; 457 437 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 459 447 // Webquest 460 448 $conditions = array('ResultWebquest.vclassroom_id'=>$vclassroom_id, 'ResultWebquest.user_id'=>$user_id); … … 465 453 endforeach; 466 454 467 //die(debug($ record));455 //die(debug($points)); 468 456 return $points; 469 457 } … … 483 471 $data = $this->UsersVclassroom->findAll($conditions, $fields); 484 472 485 if ( $data == null ) 486 { 473 if ( $data == null ): 487 474 return null; 488 } 489 else 490 { 475 else: 491 476 $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; 501 483 return $vclassrooms; 502 484 } 503 485 504 /**505 * Adds a join record between two records of a hasAndBelongsToMany association506 *507 * @param mixed $assoc The name of the HABTM association508 * @param mixed $assoc_ids The associated id or an array of associated ids509 * @param integer $id The id of the record in this model510 * @return boolean Success511 */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 duplicates544 $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 else564 {565 return false;566 }567 }568 569 /**570 * Deletes any join records between two records of a hasAndBelongsToMany association571 *572 * @param integer $id The id of the record in this model573 * @param mixed $assoc The name of the HABTM association574 * @param mixed $assoc_ids The associated id or an array of associated ids575 * @return boolean Success576 */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 else613 {614 return false;615 }616 }617 486 /* 618 487 * check if student belongs to class group -
trunk/app/views/vclassrooms/admin_record.ctp
r745 r746 30 30 31 31 // Tests 32 $test_points = (int) 0; 32 33 if ( count($data['tests']) > 0 ): 33 34 echo '<h1>'. __('Tests', true).'</h1>'; … … 38 39 if ($t['TestsVclassroom']['points'] === null): // not answered yet 39 40 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['Test sVclassroom']['title'], array('style'=>'width:350px;float:right;')));41 e($html->div(null, $t['Test']['title'], array('style'=>'width:350px;float:right;'))); 41 42 else: 42 43 e($html->div(null, $t['TestsVclassroom']['points'].' '.__('points',true),array('id'=>$div_id,'style'=>'width:180px;float:left;'))); 43 44 e('<div style="width:450px;float:right;">'); 44 echo $html->link($t['Test sVclassroom']['title'], '#'.$div_id, array('title'=>'View test', 'onclick'=>45 echo $html->link($t['Test']['title'], '#'.$div_id, array('title'=>'View test', 'onclick'=> 45 46 "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')")) . ' '; 46 47 e('</div>'); 47 48 endif; 48 49 e('</div>'); 50 $test_points += (int) $t['TestsVclassroom']['points']; 49 51 endforeach; 50 52 else: … … 53 55 54 56 // Webquests --> ResultWebquest 55 $w points = (int) 0; // webquest points57 $webquest_points = (int) 0; // webquest points 56 58 if ( count($data['webquests']) > 0 ): 57 59 echo '<h1>Webquests</h1>'; 58 60 foreach ($data['webquests'] as $w): 59 $w points += $w['ResultWebquest']['points'];61 $webquest_points += $w['ResultWebquest']['points']; 60 62 $div_id = 'w'.$w['Webquest']['id']; 61 63 e('<div style="border:1px dotted gray;padding:4px;margin:2px;height:20px;">'); … … 87 89 88 90 // Treasures. Model: Treasure 89 $t points = (int) 0; // tresure points91 $treasure_points = (int) 0; // tresure points 90 92 echo '<h1>'. __('Scavengers hunts', true).'</h1>'; 91 93 if ( count($data['treasures']) > 0 ): 92 94 foreach ($data['treasures'] as $tr): 95 $treasure_points += (int) $tr['ResultTreasure']['points']; 93 96 $div_id = 'tr'.$tr['Treasure']['id']; 94 97 e('<div style="border:1px dotted gray;padding:4px;margin:2px;height:20px;">'); … … 120 123 // Replies on forums. Model: Topic 121 124 echo '<h1>'.__('Participations in forums', true).'</h1>'; 122 $r points = (int) 0;125 $reply_points = (int) 0; 123 126 if ( count($data['replies']) > 0 ): 124 127 foreach ($data['replies'] as $re): … … 145 148 e('</div>'); 146 149 e('</div>'); 147 $r points += (int) $re['Reply']['points'];150 $reply_points += (int) $re['Reply']['points']; 148 151 endforeach; 149 152 e($html->div(null, $html->image('static/loading.gif', array('alt'=>'Loading')), array('style'=>'display:none', 'id'=>'lorep'))); … … 153 156 154 157 // Participations, model: Participation 155 $p points = (int) 0; // participation points158 $participation_points = (int) 0; // participation points 156 159 echo '<h1>'.__('Participations', true).'</h1>'; 157 160 if ( count($data['participations']) > 0 ): … … 159 162 e('<div style="border:1px dotted gray;padding:4px;margin:2px;height:20px;">'); 160 163 $div_id = 'pa'.$p['Participation']['id']; 161 $p points +=$p['Participation']['points'];164 $participation_points += (int) $p['Participation']['points']; 162 165 163 166 echo $html->div(null, $p['Participation']['points'].' '.__('points', true), array('id'=>$div_id,'style'=>'width:150px;float:left;')); … … 189 192 190 193 // Reports, model: Report 191 $repo ints = (int) 0; // report points194 $report_points = (int) 0; // report points 192 195 echo '<h1>'.__('Reports', true).'</h1>'; 193 196 if ( count($data['reports']) > 0 ): … … 195 198 e('<div style="border:1px dotted gray;padding:4px;margin:2px;height:20px;">'); 196 199 $div_id = 're'.$r['Report']['id']; 197 $repo ints += (int) $r['Report']['points'];200 $report_points += (int) $r['Report']['points']; 198 201 echo $html->div(null, $r['Report']['points'].' '.__('points',true), array('id'=>$div_id,'style'=>'width:150px;float:left;')); 199 202 … … 224 227 endif; 225 228 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); 233 237 234 238 echo $ajax->div('totalpoints') .'<b>'.__('Total points', true).': ' . $points .'</b>'. $ajax->divEnd('totalpoints');
