Changeset 368
- Timestamp:
- 04/05/08 12:52:08 (9 months ago)
- Location:
- trunk/app
- Files:
-
- 2 added
- 6 modified
-
config/sql/karamelo_postgres.sql (modified) (2 diffs)
-
controllers/tests_controller.php (modified) (4 diffs)
-
controllers/vclassrooms_controller.php (modified) (1 diff)
-
models/test.php (modified) (3 diffs)
-
models/vclassroom.php (modified) (3 diffs)
-
views/tests/admin_listing.ctp (modified) (2 diffs)
-
views/tests/admin_vclassrooms.ctp (added)
-
webroot/img/admin/vgroups-gray.gif (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/app/config/sql/karamelo_postgres.sql
r367 r368 573 573 ); 574 574 --HABTM 575 CREATE TABLE "vclassrooms_treasures" ( 575 CREATE TABLE "treasures_vclassrooms" ( 576 "treasure_id" int NOT NULL REFERENCES treasures(id), 576 577 "vclassroom_id" int NOT NULL REFERENCES vclassrooms(id), 577 "treasure_id" int NOT NULL REFERENCES treasures(id),578 578 PRIMARY KEY ("vclassroom_id", "treasure_id") 579 579 ); … … 590 590 591 591 --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")592 CREATE 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") 596 596 ); 597 597 -
trunk/app/controllers/tests_controller.php
r361 r368 19 19 'limit' => 25, 20 20 'order' => array( 21 'Test.title' => 'asc'21 'Test.title' => 'ASC' 22 22 ) 23 23 ); … … 123 123 } 124 124 125 private function chk($user_id)126 {125 private function chk($user_id) 126 { 127 127 try { 128 128 //exit(var_dump($this->data)); … … 143 143 } 144 144 145 }146 147 private function getResults($questions)148 {149 $this->Test->unbindModel(array( "belongsTo"=>array("User"))); //just few data145 } 146 147 private function getResults($questions) 148 { 149 $this->Test->unbindModel(array('belongsTo'=>array('User'))); //just few data 150 150 151 151 $result = 0; … … 167 167 /** === ADMIN METHODS ==== **/ 168 168 /** Select classroom to link*/ 169 public function admin_vclassrooms( )169 public function admin_vclassrooms($test_id) 170 170 { 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))); 181 182 } 182 183 183 184 public function admin_listing() 184 185 { 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 197 201 public function admin_add() 198 202 { 199 $this->layout = 'admin';200 // add to database201 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 { 213 217 $this->msgFlash('Test saved', '/admin/tests/listing'); 214 }215 else216 {217 die('Something is wrong ');218 }219 }218 } 219 else 220 { 221 die('Something is wrong, please report this bug'); 222 } 223 } 220 224 } 221 225 -
trunk/app/controllers/vclassrooms_controller.php
r367 r368 105 105 $this->set('data', $this->Vclassroom->find($conditions)); 106 106 } 107 // link test107 // link test 108 108 public function admin_display($vclassroom_id) 109 109 { -
trunk/app/models/test.php
r282 r368 8 8 class Test extends AppModel { 9 9 10 public $belongsTo = 'User'; 10 public $belongsTo = array('User' => 11 array('className' => 'User', 12 'conditions' => '', 13 'order' => '', 14 'foreignKey' => 'user_id' 15 ) 16 ); 11 17 12 18 public $hasMany = array( … … 37 43 public $hasAndBelongsToMany = array('Vclassroom' => 38 44 array('className' => 'Vclassroom', 39 'joinTable' => ' vclassrooms_tests',45 'joinTable' => 'tests_vclassrooms', 40 46 'foreignKey' => 'vclassroom_id', 41 47 'associationForeignKey' => 'test_id', … … 53 59 'user_id' => VALID_NOT_EMPTY 54 60 ); 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 } 55 77 } 56 78 ?> -
trunk/app/models/vclassroom.php
r346 r368 12 12 13 13 public $belongsTo = 'Ecourse'; 14 14 15 /* 15 16 public $hasAndBelongsToMany = array( 16 17 'Test' => 17 18 array('className' => 'Test', 18 'joinTable' => ' vclassrooms_tests',19 'joinTable' => 'tests_vclassrooms', 19 20 'foreignKey' => 'vclassroom_id', 20 21 'associationForeignKey' => 'test_id', … … 40 41 'Treasure' => 41 42 array('className' => 'Treasure', 42 'joinTable' => ' vclassrooms_treasures',43 'joinTable' => 'treasures_vclassrooms', 43 44 'foreignKey' => 'vclassroom_id', 44 45 'associationForeignKey' => 'treasure_id', … … 62 63 'deleteQuery' => '' 63 64 ) 64 ); 65 );*/ 65 66 //Check if the user already exist in the classroom 66 67 protected function chkMember($vclassroom_id) -
trunk/app/views/tests/admin_listing.ctp
r361 r368 1 1 <?php 2 //die( debug( $data )); 3 ?> 2 4 <div class="title_section">Tests</div> 3 5 … … 12 14 13 15 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')); 15 17 echo $html->link($val['Test']['title'], '/admin/tests/vclassrooms/'.$val['Test']['id']) . '<br /><br />'; 16 18 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 } 17 30 echo $html->link($html->image('admin/questions_icon.gif', array('alt'=>'Questions')), 18 31 '/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')); 22 35 echo '</div>'; 23 36 }
