Changeset 368

Show
Ignore:
Timestamp:
04/05/08 12:52:08 (9 months ago)
Author:
aarkerio
Message:

vClassrooms ans tests fixed

Location:
trunk/app
Files:
2 added
6 modified

Legend:

Unmodified
Added
Removed
  • trunk/app/config/sql/karamelo_postgres.sql

    r367 r368  
    573573); 
    574574--HABTM 
    575 CREATE TABLE "vclassrooms_treasures" ( 
     575CREATE TABLE "treasures_vclassrooms" ( 
     576  "treasure_id"   int NOT NULL REFERENCES treasures(id), 
    576577  "vclassroom_id" int NOT NULL REFERENCES vclassrooms(id), 
    577   "treasure_id"   int NOT NULL REFERENCES treasures(id), 
    578578  PRIMARY KEY  ("vclassroom_id", "treasure_id") 
    579579); 
     
    590590 
    591591--HABTM 
    592 CREATE TABLE "vclassrooms_tests" ( 
    593   "vclassroom_id" int NOT NULL REFERENCES vclassrooms(id), 
    594   "test_id"   int NOT NULL REFERENCES tests(id), 
    595   PRIMARY KEY  ("vclassroom_id", "test_id") 
     592CREATE TABLE "tests_vclassrooms" ( 
     593 "test_id" int NOT NULL REFERENCES tests(id), 
     594 "vclassroom_id" int NOT NULL REFERENCES vclassrooms(id), 
     595  PRIMARY KEY  ("test_id", "vclassroom_id") 
    596596); 
    597597 
  • trunk/app/controllers/tests_controller.php

    r361 r368  
    1919                          'limit' => 25, 
    2020                          'order' => array( 
    21                                            'Test.title' => 'asc' 
     21                                             'Test.title' => 'ASC' 
    2222                                          ) 
    2323                         ); 
     
    123123} 
    124124 
    125   private function chk($user_id) 
    126   { 
     125 private function chk($user_id) 
     126 { 
    127127    try { 
    128128      //exit(var_dump($this->data)); 
     
    143143    } 
    144144     
    145   } 
    146  
    147   private function getResults($questions) 
    148   { 
    149     $this->Test->unbindModel(array("belongsTo"=>array("User"))); //just few data 
     145 } 
     146 
     147 private function getResults($questions) 
     148 { 
     149    $this->Test->unbindModel(array('belongsTo'=>array('User'))); //just few data 
    150150     
    151151    $result = 0; 
     
    167167 /**   === ADMIN METHODS ====  **/ 
    168168 /** Select classroom to link*/ 
    169  public function admin_vclassrooms() 
     169 public function admin_vclassrooms($test_id) 
    170170 {     
    171       $this->pageTitle = $this->Auth->user('username') . '\'s Classrooms'; 
    172        
    173       $this->layout = 'admin'; 
    174        
    175       $conditions   = array("Test.user_id"=>$this->Auth->user('id')); 
    176       $fields       = array("Webquest.id", "Webquest.title", "Webquest.status", "Webquest.created"); 
    177       $order        = "Test.id DESC"; 
    178       $limit        = 12; 
    179        
    180       $this->set('data', $this->Test->findAll($conditions));  
     171   $this->pageTitle = $this->Auth->user('username') . '\'s Classrooms'; 
     172       
     173   $this->layout = 'admin'; 
     174       
     175   $conditions   = array('Vclassroom.user_id'=>$this->Auth->user('id'), 'Vclassroom.status'=>1); 
     176    
     177   $this->set('data', $this->Test->Vclassroom->findAll($conditions));  
     178 
     179   $this->Test->unbindModel(array('hasMany'=>array('Question', 'Result'), 'belongsTo'=>array('User'))); 
     180 
     181   $this->set('tests',$this->Test->TestsVclassroom->findAll(array('TestsVclassroom.test_id' => $test_id))); 
    181182 } 
    182183     
    183184 public function admin_listing() 
    184185 {    
    185       $this->layout    = 'admin'; 
    186          
    187       $this->pageTitle = 'Tests'; 
    188          
    189       $conditions = array("Test.user_id"=>$this->Auth->user('id')); 
    190          
    191       $fields     = array("Test.id", "Test.user_id", "Test.title", "Test.description", "Test.status"); 
    192          
    193       $order = "Test.id DESC"; 
    194          
    195       $this->set('data', $this->Test->findAll($conditions, $fields, $order)); 
    196  } 
     186   $this->layout    = 'admin'; 
     187         
     188   $this->pageTitle = 'Tests'; 
     189         
     190   $conditions = array('Vclassroom.user_id'=>$this->Auth->user('id')); 
     191         
     192   $fields     = array('Test.id', 'Test.user_id', 'Test.title', 'Test.description', 'Test.status'); 
     193         
     194   $order      = 'Test.id DESC'; 
     195       
     196   $this->Test->unbindModel(array('hasMany'=>array('Question', 'Result'))); 
     197       
     198   $this->set('data', $this->Test->findAll($conditions, $fields, $order)); 
     199 } 
     200  
    197201 public function admin_add()  
    198202 { 
    199        $this->layout    = 'admin'; 
    200        // add to database 
    201        if ( !empty($this->data['Test']) ) 
    202        { 
    203           $this->Sanitize = new Sanitize; 
    204             
    205           $this->Sanitize->clean($this->data['Test']); 
    206             
    207           $this->data['Test']['user_id'] = $this->Auth->user('id'); 
    208             
    209           $this->Test->create();  
    210           //var_dump($this->data['Test']); 
    211       if ( $this->Test->save($this->data["Test"])) 
    212       { 
     203    $this->layout    = 'admin'; 
     204    // add to database 
     205   if ( !empty($this->data['Test']) ) 
     206   { 
     207      $this->Sanitize = new Sanitize; 
     208            
     209      $this->Sanitize->clean($this->data['Test']); 
     210            
     211      $this->data['Test']['user_id'] = $this->Auth->user('id'); 
     212            
     213      $this->Test->create();  
     214      //var_dump($this->data['Test']); 
     215      if ( $this->Test->save($this->data["Test"])) 
     216      { 
    213217               $this->msgFlash('Test saved', '/admin/tests/listing'); 
    214           } 
    215           else 
    216           {  
    217               die('Something is wrong'); 
    218           } 
    219        } 
     218      } 
     219      else 
     220      {  
     221              die('Something is wrong, please report this bug'); 
     222      } 
     223   } 
    220224 } 
    221225  
  • trunk/app/controllers/vclassrooms_controller.php

    r367 r368  
    105105      $this->set('data', $this->Vclassroom->find($conditions)); 
    106106 } 
    107   // link test 
     107 // link test 
    108108 public function admin_display($vclassroom_id) 
    109109 { 
  • trunk/app/models/test.php

    r282 r368  
    88class Test extends AppModel { 
    99    
    10    public $belongsTo = 'User'; 
     10   public $belongsTo = array('User' => 
     11             array('className'  => 'User', 
     12                   'conditions' => '', 
     13                   'order'      => '', 
     14                                 'foreignKey' => 'user_id' 
     15                   ) 
     16             ); 
    1117    
    1218   public $hasMany = array( 
     
    3743    public $hasAndBelongsToMany = array('Vclassroom' => 
    3844                       array('className'             => 'Vclassroom', 
    39                          'joinTable'             => 'vclassrooms_tests', 
     45                         'joinTable'             => 'tests_vclassrooms', 
    4046                         'foreignKey'            => 'vclassroom_id', 
    4147                         'associationForeignKey' => 'test_id', 
     
    5359      'user_id' => VALID_NOT_EMPTY 
    5460   );  
     61    
     62  public function linkClassroom($test_id, $user_id) 
     63  { 
     64    $condition = array('Test.status'=>1, 'Test.user_id'=>$user_id, 'Test.id'=>$test_id); 
     65     
     66    $vclassrooms = array(); 
     67     
     68    $result = $this->find($conditions); 
     69     
     70    foreach ($result['Vclassroom'] as $val) 
     71    { 
     72      $vclassrooms[$val['name']] = $val['id']; 
     73    } 
     74 
     75    return $vclassrooms; 
     76  } 
    5577} 
    5678?> 
  • trunk/app/models/vclassroom.php

    r346 r368  
    1212     
    1313    public $belongsTo = 'Ecourse'; 
    14      
     14 
     15    /* 
    1516    public $hasAndBelongsToMany = array( 
    1617                                        'Test' => 
    1718                       array('className'             => 'Test', 
    18                          'joinTable'             => 'vclassrooms_tests', 
     19                         'joinTable'             => 'tests_vclassrooms', 
    1920                         'foreignKey'            => 'vclassroom_id', 
    2021                         'associationForeignKey' => 'test_id', 
     
    4041                                        'Treasure' => 
    4142                       array('className'             => 'Treasure', 
    42                          'joinTable'             => 'vclassrooms_treasures', 
     43                         'joinTable'             => 'treasures_vclassrooms', 
    4344                         'foreignKey'            => 'vclassroom_id', 
    4445                         'associationForeignKey' => 'treasure_id', 
     
    6263                         'deleteQuery'           => '' 
    6364                         ) 
    64                     ); 
     65                    );*/ 
    6566 //Check if the user already exist in the classroom 
    6667 protected function chkMember($vclassroom_id) 
  • trunk/app/views/tests/admin_listing.ctp

    r361 r368  
    1  
     1<?php 
     2//die( debug( $data )); 
     3?> 
    24<div class="title_section">Tests</div> 
    35 
     
    1214 
    1315  echo '<div style="padding:6px 3px 28px 4px;margin:10px 0 5px 0;border:1px dotted gray;">'; 
    14          echo '<div class="butonright">' .$gags->sendEdit($val['Test']['id'], 'tests') . '</div>'; 
     16         echo $html->div('butonright', $gags->sendEdit($val['Test']['id'], 'tests')); 
    1517         echo $html->link($val['Test']['title'], '/admin/tests/vclassrooms/'.$val['Test']['id']) . '<br /><br />'; 
    1618         echo $html->link('Questions', '/admin/tests/questions/'.$val['Test']['id']); 
     19 
     20         if ( count($val['Vclassroom']) < 1 )  
     21         { 
     22           echo $html->para(null, $html->link( 
     23                                              $html->image('admin/vgroups-gray.gif', array( 
     24                                                                                           'alt'  =>'There is no Classroom assigned for this test',  
     25                                                                                           'title'=>'There is no Classroom assigned for this test' 
     26                                                                                           ) 
     27                                                           ),  
     28                                              '/admin/tests/vclassrooms/'.$val['Test']['id'], null,  null, false)); 
     29         } 
    1730         echo $html->link($html->image('admin/questions_icon.gif', array('alt'=>'Questions')),  
    1831                          '/admin/tests/questions/'.$val['Test']['id'], null, null, false) . '<br />'; 
    19          echo '<p>' . $val['Test']['description']  . '</p>'; 
    20          echo '<p style="margin-left:15px;">Status: '. $html->link($s, '/admin/tests/change/'.$val['Test']['id'].'/'.$val['Test']['status']) . '</p>'; 
    21          echo '<div class="butonright">'. $gags->confirmDel($val['Test']['id'], 'tests') .'</div>'; 
     32         echo $html->para(null, $val['Test']['description']); 
     33         echo $html->para(null, $html->link($s, '/admin/tests/change/'.$val['Test']['id'].'/'.$val['Test']['status'])); 
     34         echo $html->div('butonright',  $gags->confirmDel($val['Test']['id'], 'tests')); 
    2235    echo '</div>'; 
    2336}