Changeset 429
- Timestamp:
- 04/24/08 21:33:43 (9 months ago)
- Location:
- trunk/app
- Files:
-
- 4 modified
-
config/sql/karamelo_postgres.sql (modified) (1 diff)
-
controllers/tests_controller.php (modified) (5 diffs)
-
views/tests/result.ctp (modified) (1 diff)
-
views/tests/view.ctp (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/app/config/sql/karamelo_postgres.sql
r418 r429 589 589 results smallint NOT NULL, 590 590 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) 592 593 ); 593 594 -- Test model tables ends 594 595 595 596 -- Share it! 596 -- Share stuff (docs an5Dd multimedia) with your students 597 597 CREATE TABLE shares ( 598 598 id serial PRIMARY KEY, -
trunk/app/controllers/tests_controller.php
r428 r429 68 68 // the student alredy answered this test? 69 69 $already = $this->Test->Result->field('Result.id', array("Result.user_id"=>$this->Auth->user('id'), "Result.test_id"=>$test_id)); 70 70 71 71 if ($already != null) 72 72 { … … 75 75 exit(); 76 76 } 77 77 78 78 if ( $this->Auth->user() && $this->Auth->user('group_id') == 3) 79 79 { … … 95 95 96 96 $this->set('data', $this->Test->find($conditions, $fields, $order, 2)); 97 }97 } 98 98 99 99 public function result() 100 100 { 101 101 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 104 109 $this->pageTitle = 'Test Results'; 105 110 … … 130 135 if ( $res['Answer']['correct'] == 1) 131 136 { 132 echo 'worth: ' . $res['Question']['worth'].'<br />';133 137 $points += (int) $res['Question']['worth']; 134 138 } … … 137 141 // die('Points: '. $points); 138 142 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 143 148 $this->Test->Result->create(); 144 149 145 150 if ($this->Test->Result->save($this->data['Result']) ) 146 151 { 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 { 153 160 echo "Caught my exception\n" . $e; 154 }161 } 155 162 } 156 163 -
trunk/app/views/tests/result.ctp
r264 r429 1 1 <?php 2 // exit(var_dump($data));3 ?> 2 //exit(debug($data)); 3 $auth = true; 4 4 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; 12 endif; */ 13 14 if ( $auth === true ): 6 15 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>'; 11 17 12 echo '<p>You result was: <b>'.$results['results'].'</b> points. Result has been saved, Thanks!<p>';18 echo $html->div('result', $data['percentage'].'%'); 13 19 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!'); 15 21 16 echo '<p>'. $data['Test']['description'] . '</p>';17 22 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 } 23 else: 24 echo '<p>You must be logged adn belongs to this class to see this exam</p>'; 25 endif; 43 26 44 27 -
trunk/app/views/tests/view.ctp
r428 r429 1 1 <?php 2 // die(debug($data));2 //die(debug($data)); 3 3 4 4 $auth = false; … … 8 8 if ( in_array($v['id'], $session->read('vclassrooms'))): 9 9 $auth = true; 10 $vclassroom_id = $v['id']; 10 11 break; 11 12 endif; … … 24 25 echo $form->hidden('test_id', array('value'=>$data['Test']['id'])); 25 26 echo $form->hidden('blogger_id', array('value'=>$blog['User']['id'])); 27 echo $form->hidden('vclassroom_id', array('value'=>$vclassroom_id )); 26 28 27 $points = 0;29 $maxpoints = 0; 28 30 foreach ($data['Question'] as $val): 29 31 //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>'; 32 36 33 37 $options = array(); // to build options radio buttons … … 45 49 endforeach; 46 50 47 echo $html->para(null, 'Maxim calification: '.$points);48 51 echo $form->end('Send'); 49 52
