Changeset 466

Show
Ignore:
Timestamp:
05/08/08 19:18:13 (8 months ago)
Author:
aarkerio
Message:

Forums and topics improveds

Location:
trunk/app
Files:
7 modified

Legend:

Unmodified
Added
Removed
  • trunk/app/controllers/tests_controller.php

    r464 r466  
    6464  } 
    6565 
    66   public function view($test_id, $user_id) 
     66  public function view($test_id, $vclassroom_id) 
    6767  { 
    68      // the student alredy answered this test? 
    69      $already = $this->Test->Result->field('Result.id', array("Result.user_id"=>$this->Auth->user('id'), "Result.test_id"=>$test_id)); 
    70       
    71     if ($already != null) 
     68        
     69    if ( $this->Test->chk($test_id, $this->Auth->user('id'), $vclassroom_id) === true ) 
    7270    { 
    7371         $username = $this->Test->User->field('User.username', array("User.id"=>$user_id)); 
     
    7775    if ( $this->Auth->user() && $this->Auth->user('group_id') == 3) 
    7876    { 
    79           $student_id = (int) $this->Auth->user('id'); 
     77     $student_id = (int) $this->Auth->user('id'); 
    8078         $this->Edublog->setSession($student_id); //check if user belongs to class 
    8179    } 
  • trunk/app/controllers/treasures_controller.php

    r441 r466  
    3434    return false;  // go away !! 
    3535 } 
     36 
     37/* 
     38 * check if tresure string is OK, if so, save student data on ResultTreasure model  
     39 * 
     40 */ 
     41  
    3642 public function  chksw() 
    3743 { 
     
    8995 } 
    9096 
    91  public function view($treasure_id) 
     97 public function view($treasure_id, $vclassroom_id) 
    9298 {     
    93       $conditions      = array("Treasure.status"=>1, "Treasure.id"=>$treasure_id); 
    94        
    95       $data            = $this->Treasure->find($conditions); 
     99   if ( $this->Test->chk($test_id, $this->Auth->user('id'), $vclassroom_id) === true ): 
     100         $username = $this->Test->User->field('User.username', array("User.id"=>$user_id)); 
     101     $this->flash('You already have answered this test', '/users/portfolio/'.$username); 
     102   endif; 
     103     
     104   if ( $this->Auth->user() && $this->Auth->user('group_id') == 3): 
     105     $student_id = (int) $this->Auth->user('id'); 
     106         $this->Edublog->setSession($student_id); //check if user belongs to class 
     107   endif; 
     108 
     109   $conditions      = array("Treasure.status"=>1, "Treasure.id"=>$treasure_id); 
     110       
     111   $data            = $this->Treasure->find($conditions); 
    96112     
    97       $this->layout    = $this->Edublog->layout($data['Treasure']['user_id']); 
    98        
    99       $this->pageTitle = 'Treasure Hunt'; 
    100        
    101       $this->Edublog->blog($data['Treasure']['user_id']); // blogger elements 
     113   $this->layout    = $this->Edublog->layout($data['Treasure']['user_id']); 
     114       
     115   $this->pageTitle = 'Treasure Hunt'; 
     116       
     117   $this->Edublog->blog($data['Treasure']['user_id']); // blogger elements 
    102118             
    103       $this->set('data', $data);  
    104  } 
    105  
     119   $this->set('data', $data);  
     120 } 
    106121 
    107122 /**    === ADMIN METHODS  === **/  
  • trunk/app/controllers/webquests_controller.php

    r464 r466  
    6060 } 
    6161 
    62  public function view($webquest_id) 
     62 public function view($webquest_id, $vclassroom_id) 
    6363 {  
    6464   $conditions      = array("Webquest.status"=>1, "Webquest.id"=>$webquest_id); 
     
    6767      
    6868   // the student alredy answered this webquest?    
    69    if ($this->Webquest->chk($webquest_id, $this->Auth->user('id')) === true) 
     69   if ($this->Webquest->chk($webquest_id, $this->Auth->user('id'), $vclassroom_id) === true) 
    7070   { 
    71          $username = $this->Webquest->User->field('User.username', array("User.id"=>$data['Webquest']['user_id'])); 
    72      $this->flash('You already have answered this webquest', '/users/portfolio/'.$username); 
     71    $username = $this->Webquest->User->field('User.username', array("User.id"=>$data['Webquest']['user_id'])); 
     72    $this->flash('You already have answered this webquest', '/vclassrooms/show/'.$data['Webquest']['user_id'].'/'.$data['Webquest']['user_id'); 
    7373   } 
    7474     
  • trunk/app/models/test.php

    r428 r466  
    7575    return $vclassrooms; 
    7676 } 
     77/* 
     78 *  check if studen already found treasure 
     79 *  int treasure_id  
     80 *  int user_id       
     81 *  int vclassroom_id 
     82 *  return boolean 
     83 */ 
     84 public function chk($test_id, $user_id, $vclassroom_id) 
     85 { 
     86    $conditions =  array("Result.user_id"=>$user_id, "Result.test_id"=>$test_id, "Result.vclassroom_id"=>$vclassroom_id); 
     87    $data       =  $this->Result->field('Result.id', $conditions); 
     88    
     89    if ($data != null ): 
     90          return false;    
     91    else: 
     92          return true; 
     93    endif; 
     94 } 
    7795 
    7896 public function chkAnswers($answers, $test_id) 
     
    82100    $result = 0; 
    83101     
    84     foreach($questions as $q_id => $a_id)  // question id and answer id 
    85     { 
     102    foreach($questions as $q_id => $a_id):  // question id and answer id 
    86103         $correct_answer = $this->Test->Question->Answer->field('Answer.correct', array('Answer.id'=>$a_id));   // answer was correct? 
    87104          
    88          if ($correct_answer == 1) 
    89          { 
     105           if ($correct_answer == 1): 
    90106              $worth   = $this->Test->Question->field('Question.worth', array('Question.id'=>$q_id));         // how many points 
    91107              $result += $worth; 
    92          } 
    93     } 
    94     //exit('Result was:' . $result); 
     108           endif; 
     109     endforeach; 
     110    //exit('Result was:' . $result)e 
    95111    return $result;  
    96112  } 
  • trunk/app/models/treasure.php

    r465 r466  
    4242 *  int treasure_id  
    4343 *  int user_id       
     44 *  int vclassroom_id 
    4445 *  return boolean 
    4546 */ 
    46  public function chk($treasure_id, $user_id) 
     47 public function chk($treasure_id, $user_id, $vclassroom_id) 
    4748 { 
    4849  
    49    $conditons = array("ResultTreasure.user_id"=>$user_id, "ResultTreasure.treasure_id"=>$treasure_id);  
     50   $conditons = array("ResultTreasure.user_id"=>$user_id, "ResultTreasure.treasure_id"=>$treasure_id, "ResultTreasure.vclassroom_id"=>$vclassroom_id);  
    5051 
    51    $data      = $this->ResultTreasure->field('ResultTreasure.id', $conditions)); 
     52   $data      = $this->ResultTreasure->field('ResultTreasure.id', $conditions); 
    5253    
    5354   if ($data != null ): 
  • trunk/app/models/webquest.php

    r465 r466  
    5050 *  return boolean 
    5151 */ 
    52   public function chk($webquest_id, $user_id) 
    53   { 
    54     $conditions =  array("ResultWebquest.user_id"=>$user_id, "ResultWebquest.webquest_id"=>$webquest_id); 
     52 public function chk($webquest_id, $user_id, $vclassroom_id) 
     53 { 
     54    $conditions =  array("ResultWebquest.user_id"=>$user_id, "ResultWebquest.webquest_id"=>$webquest_id, "ResultWebquest.vclassroom_id"=>$vclassroom_id); 
    5555    $data       =  $this->ResultWebquest->field('ResultWebquest.id', $conditions); 
    5656    
  • trunk/app/views/vclassrooms/show.ctp

    r461 r466  
    1919     echo  $html->para(null, '<b>Subject</b>: ' . $data['Ecourse']['title']); 
    2020     echo  $html->para(null, '<b>Course description</b>:'. $data['Ecourse']['description']); 
    21       
    22      if ( count($data['Test']) > 0) 
    23      { 
     21 
     22     //  Forums 
     23     if ( count($data['Forum']) > 0): 
     24        echo $html->div('titentry', 'Forums'); 
     25 
     26        foreach($data['Forum'] as $f): 
     27             echo $html->para(null, $html->link($f['title'], '/forums/display/'.$f['id'])); 
     28        endforeach; 
     29    endif; 
     30     
     31    // Tests  
     32    if ( count($data['Test']) > 0): 
    2433       echo $html->div('titentry', 'Quizz Tests'); 
    2534 
    26        foreach($data['Test'] as $t) 
    27        { 
    28          echo $html->para(null, $html->link($t['title'], '/tests/view/'.$t['id'].'/'.$t['user_id'])); 
    29        } 
    30      } 
     35       foreach($data['Test'] as $t): 
     36                echo $html->para(null, $html->link($t['title'], '/tests/view/'.$t['id'].'/'.$data['Vclassroom']['id'])); 
     37       endforeach; 
     38    endif; 
    3139 
    32      if ( count($data['Forum']) > 0) 
    33      { 
    34        echo $html->div('titentry', 'Forums'); 
    35  
    36        foreach($data['Forum'] as $f) 
    37        { 
    38          echo $html->para(null, $html->link($f['title'], '/forums/display/'.$f['id'])); 
    39        } 
    40      } 
    41  
    42      if ( count($data['Webquest']) > 0) 
    43      { 
     40    // Webquests 
     41    if ( count($data['Webquest']) > 0): 
    4442       echo $html->div('titentry', 'Webquests'); 
    4543 
    46        foreach($data['Webquest'] as $wq) 
    47        { 
    48          echo $html->para(null, $html->link($wq['title'], '/webquests/view/'.$wq['id'])); 
    49        } 
    50      } 
     44       foreach($data['Webquest'] as $wq): 
     45         echo $html->para(null, $html->link($wq['title'], '/webquests/view/'.$wq['id'].'/'.$data['Vclassroom']['id'])); 
     46       endforeach; 
     47    endif; 
    5148 
    52      if ( count($data['Treasure']) > 0) 
    53      { 
     49    if ( count($data['Treasure']) > 0): 
    5450       echo $html->div('titentry', 'Treasure Hunts'); 
    5551 
    56        foreach($data['Treasure'] as $t) 
    57        { 
    58          echo $html->para(null, $html->link($t['title'], '/treasures/view/'.$t['id'])); 
    59        } 
    60      } 
    61       echo $ajax->form(); 
     52        foreach($data['Treasure'] as $t): 
     53                echo $html->para(null, $html->link($t['title'], '/treasures/view/'.$t['id'].'/'.$data['Vclassroom']['id'])); 
     54    endforeach; 
     55    endif; 
     56 
     57    echo $ajax->form(); 
    6258      
    63      echo $form->hidden('Participation.vclassroom_id', array('value'=>$data['Vclassroom']['id'])); 
    64      echo $form->hidden('Participation.blogger_id', array('value'=>$blog['User']['id']));  // this to return 
    65      echo $ajax->submit('Start participating', array("url" => "/vclassrooms/participation/",  
     59    echo $form->hidden('Participation.vclassroom_id', array('value'=>$data['Vclassroom']['id'])); 
     60    echo $form->hidden('Participation.blogger_id', array('value'=>$blog['User']['id']));  // this to return 
     61    echo $ajax->submit('Start participating', array("url" => "/vclassrooms/participation/",  
    6662                                         "update"=>"setform", 
    6763                                         "loading" => "Element.show('charging');Element.hide('setform')", 
    6864                                         "complete" => "Element.hide('charging');Effect.Appear('setform')" 
    6965        )); 
    70      echo '</form>';  
    71      // empty ajax div 
    72      echo $ajax->div('setform') . $ajax->divEnd('setform');  
     66    echo '</form>';  
     67    // empty ajax div 
     68    echo $ajax->div('setform') . $ajax->divEnd('setform');  
    7369  } 
    7470