| 1 | <?php |
|---|
| 2 | /** |
|---|
| 3 | * Karamelo E-Learning Platform |
|---|
| 4 | * Manuel Montoya 2002-2008 |
|---|
| 5 | * GPLv3 manuel<arroba>mononeurona<punto>org |
|---|
| 6 | * @version 0.3 |
|---|
| 7 | */ |
|---|
| 8 | |
|---|
| 9 | App::import('Sanitize'); |
|---|
| 10 | |
|---|
| 11 | class WebquestsController extends AppController { |
|---|
| 12 | |
|---|
| 13 | public $helpers = array('Ajax', 'Fck', 'Gags'); |
|---|
| 14 | |
|---|
| 15 | public $components = array('Edublog'); |
|---|
| 16 | |
|---|
| 17 | public function beforeFilter() |
|---|
| 18 | { |
|---|
| 19 | parent::beforeFilter(); |
|---|
| 20 | $this->Auth->allow(array('display', 'view', 'result')); |
|---|
| 21 | } |
|---|
| 22 | |
|---|
| 23 | public function display($username, $webquest_id) |
|---|
| 24 | { |
|---|
| 25 | $conditions = array("Webquest.status"=>1); |
|---|
| 26 | |
|---|
| 27 | if ($username != null): |
|---|
| 28 | $user_id = $this->Webquest->User->field('id', array("username"=>$username)); |
|---|
| 29 | |
|---|
| 30 | $conditions["Webquest.user_id"] = $user_id; |
|---|
| 31 | else: |
|---|
| 32 | $this->redirect('/'); // go away |
|---|
| 33 | endif; |
|---|
| 34 | |
|---|
| 35 | $this->layout = $this->Edublog->layout($user_id); |
|---|
| 36 | |
|---|
| 37 | $this->Edublog->blog($user_id); // blogger elements |
|---|
| 38 | |
|---|
| 39 | $this->pageTitle = $username . '\'s Webquests'; |
|---|
| 40 | |
|---|
| 41 | $fields = array("id", "title", "introduction", "created"); |
|---|
| 42 | $order = "Webquest.id DESC"; |
|---|
| 43 | $limit = 20; |
|---|
| 44 | |
|---|
| 45 | $this->set('data', $this->Webquest->findAll($conditions, $fields, $order, $limit)); |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | public function view($webquest_id, $vclassroom_id) |
|---|
| 49 | { |
|---|
| 50 | $conditions = array("Webquest.status"=>1, "Webquest.id"=>$webquest_id); |
|---|
| 51 | |
|---|
| 52 | $data = $this->Webquest->find($conditions); |
|---|
| 53 | |
|---|
| 54 | $this->layout = $this->Edublog->layout($data['Webquest']['user_id']); |
|---|
| 55 | |
|---|
| 56 | $this->Edublog->blog($data['Webquest']['user_id']); // blogger elements |
|---|
| 57 | |
|---|
| 58 | $this->pageTitle = $data['Webquest']['title'] . '\'s Webquest'; |
|---|
| 59 | |
|---|
| 60 | // the student alredy answered this webquest? |
|---|
| 61 | if ($this->Webquest->chk($webquest_id, $this->Auth->user('id'), $vclassroom_id) === true): |
|---|
| 62 | $this->set('already', true); |
|---|
| 63 | else: |
|---|
| 64 | $this->set('already', false); |
|---|
| 65 | endif; |
|---|
| 66 | |
|---|
| 67 | // student belongst to this class? |
|---|
| 68 | if ( $this->Auth->user() && $this->Auth->user('group_id') == 3): |
|---|
| 69 | $this->set('belongs', $this->Webquest->Vclassroom->belongs($this->Auth->user('id'), $vclassroom_id)); |
|---|
| 70 | else: |
|---|
| 71 | $this->set('belongs', false); |
|---|
| 72 | endif; |
|---|
| 73 | |
|---|
| 74 | $this->set('data', $data); |
|---|
| 75 | $this->set('vclassroom_id', $vclassroom_id); |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | public function result() |
|---|
| 79 | { |
|---|
| 80 | // adds new blog entries |
|---|
| 81 | if ( !empty($this->data['ResultWebquest']) ) : |
|---|
| 82 | Sanitize::clean($this->data['ResultWebquest']); |
|---|
| 83 | |
|---|
| 84 | $this->data['ResultWebquest']['user_id'] = (int) $this->Auth->user('id'); |
|---|
| 85 | |
|---|
| 86 | if ($this->Webquest->ResultWebquest->save($this->data)): |
|---|
| 87 | $this->msgFlash(__('Data saved', true), |
|---|
| 88 | '/vclassrooms/show/'.$this->data['ResultWebquest']['blogger_id'].'/'.$this->data['ResultWebquest']['vclassroom_id']); |
|---|
| 89 | endif; |
|---|
| 90 | endif; |
|---|
| 91 | } |
|---|
| 92 | /**== ADMIN METHODS ==**/ |
|---|
| 93 | public function admin_points($resultwebquest_id, $sense) |
|---|
| 94 | { |
|---|
| 95 | $points = (int) $this->Webquest->ResultWebquest->field('points', array('ResultWebquest.id'=>$resultwebquest_id)); |
|---|
| 96 | |
|---|
| 97 | $points = ($sense == 'up' ) ? ($points + 1) : ($points - 1); |
|---|
| 98 | |
|---|
| 99 | $this->data['ResultWebquest']['id'] = $resultwebquest_id; |
|---|
| 100 | |
|---|
| 101 | $this->data['ResultWebquest']['points'] = $points; |
|---|
| 102 | |
|---|
| 103 | if ($this->Webquest->ResultWebquest->save($this->data)): |
|---|
| 104 | $this->set('points', $points); |
|---|
| 105 | $this->render('admin_points', 'ajax'); |
|---|
| 106 | endif; |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | public function admin_listing() |
|---|
| 110 | { |
|---|
| 111 | $this->pageTitle = $this->Auth->user('username') . '\'s Webquests'; |
|---|
| 112 | |
|---|
| 113 | $this->layout = 'admin'; |
|---|
| 114 | |
|---|
| 115 | $conditions = array("Webquest.user_id"=>$this->Auth->user('id')); |
|---|
| 116 | $fields = array("Webquest.id", "Webquest.title", "Webquest.status", "Webquest.created"); |
|---|
| 117 | $order = "Webquest.id DESC"; |
|---|
| 118 | $limit = 12; |
|---|
| 119 | |
|---|
| 120 | $this->set('data', $this->Webquest->findAll($conditions, $fields, $order, $limit)); |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| 123 | public function admin_start() |
|---|
| 124 | { |
|---|
| 125 | $this->layout = 'ajax'; |
|---|
| 126 | |
|---|
| 127 | $this->render('admin_start', 'ajax'); |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | public function admin_add() |
|---|
| 131 | { |
|---|
| 132 | $this->layout = 'admin'; |
|---|
| 133 | // adds new blog entries |
|---|
| 134 | if ( !empty($this->data["Webquest"]) ): |
|---|
| 135 | Sanitize::clean($this->data['Webquest']); |
|---|
| 136 | |
|---|
| 137 | $this->data['Webquest']['user_id'] = (int) $this->Auth->user('id'); |
|---|
| 138 | |
|---|
| 139 | if ($this->Webquest->save($this->data)): |
|---|
| 140 | $this->msgFlash(__('Data saved', true), '/admin/webquests/edit/'.$this->Webquest->getLastInsertId()); |
|---|
| 141 | endif; |
|---|
| 142 | endif; |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | public function admin_get($section=null, $webquest_id=null) |
|---|
| 146 | { |
|---|
| 147 | $this->layout = 'ajax'; |
|---|
| 148 | |
|---|
| 149 | if ( !empty($this->data['Webquest']) ) : |
|---|
| 150 | |
|---|
| 151 | Sanitize::clean($this->data['Webquest']); |
|---|
| 152 | |
|---|
| 153 | if ($this->Webquest->save($this->data)): |
|---|
| 154 | $this->set('section', $this->data["Webquest"]["section"]); |
|---|
| 155 | |
|---|
| 156 | $this->set('id', $this->data["Webquest"]["id"]); |
|---|
| 157 | |
|---|
| 158 | $this->set('field', $this->Webquest->field($section, array("Webquest.id"=>$this->data["Webquest"]["id"]))); |
|---|
| 159 | endif; |
|---|
| 160 | else: |
|---|
| 161 | $this->set('section', $section); |
|---|
| 162 | |
|---|
| 163 | $this->set('id', $webquest_id); |
|---|
| 164 | |
|---|
| 165 | $this->set('field', $this->Webquest->field($section, array("Webquest.id"=>$webquest_id))); |
|---|
| 166 | endif; |
|---|
| 167 | |
|---|
| 168 | $this->render('admin_get', 'ajax'); |
|---|
| 169 | } |
|---|
| 170 | |
|---|
| 171 | // see webquest with student results |
|---|
| 172 | public function admin_see($student_id, $webquest_id) |
|---|
| 173 | { |
|---|
| 174 | $this->layout = 'popup'; |
|---|
| 175 | |
|---|
| 176 | $this->set('data', $this->Webquest->getQuest($student_id, $webquest_id)); |
|---|
| 177 | } |
|---|
| 178 | |
|---|
| 179 | public function admin_view($webquest_id) |
|---|
| 180 | { |
|---|
| 181 | $this->layout = 'popup'; |
|---|
| 182 | $conditions = array('Webquest.id'=>$webquest_id, 'Webquest.user_id'=>$this->Auth->user('id')); |
|---|
| 183 | $this->set('data', $this->Webquest->find($conditions, $fields)); |
|---|
| 184 | } |
|---|
| 185 | |
|---|
| 186 | public function admin_edit($webquest_id=null) |
|---|
| 187 | { |
|---|
| 188 | $this->layout = 'admin'; |
|---|
| 189 | |
|---|
| 190 | if ( !empty($this->data['Webquest']) ) |
|---|
| 191 | { |
|---|
| 192 | /* |
|---|
| 193 | |
|---|
| 194 | if ( isset($this->data['Webquest']['introduction'])): |
|---|
| 195 | Sanitize::html($this->data['Webquest']['introduction']); |
|---|
| 196 | endif; |
|---|
| 197 | |
|---|
| 198 | if ( isset($this->data['Webquest']['tasks'])) |
|---|
| 199 | { |
|---|
| 200 | Sanitize::html($this->data['Webquest']['tasks']); |
|---|
| 201 | } |
|---|
| 202 | |
|---|
| 203 | if ( isset($this->data["Webquest"]["process"])) |
|---|
| 204 | { |
|---|
| 205 | Sanitize::->html($this->data["Webquest"]["process"]); |
|---|
| 206 | } |
|---|
| 207 | |
|---|
| 208 | if ( isset($this->data["Webquest"]["roles"])) |
|---|
| 209 | { |
|---|
| 210 | Sanitize::->html($this->data["Webquest"]["roles"]); |
|---|
| 211 | } |
|---|
| 212 | |
|---|
| 213 | if ( isset($this->data["Webquest"]["evaluation"])) |
|---|
| 214 | { |
|---|
| 215 | Sanitize::->html($this->data["Webquest"]["evaluation"]); |
|---|
| 216 | } |
|---|
| 217 | |
|---|
| 218 | if ( isset($this->data["Webquest"]["conclusion"])) |
|---|
| 219 | { |
|---|
| 220 | Sanitize::->html($this->data["Webquest"]["conclusion"]); |
|---|
| 221 | } |
|---|
| 222 | */ |
|---|
| 223 | //exit(var_dump($this->data["Webquest"])); |
|---|
| 224 | |
|---|
| 225 | |
|---|
| 226 | if ($this->Webquest->save($this->data)): |
|---|
| 227 | $this->msgFlash(__('Data saved', true), '/admin/webquests/edit/'.$this->data['Webquest']['id']); |
|---|
| 228 | endif; |
|---|
| 229 | } |
|---|
| 230 | else |
|---|
| 231 | { |
|---|
| 232 | $this->set('wq_title', $this->Webquest->field('title', array("Webquest.id"=>$webquest_id))); |
|---|
| 233 | $this->set('id', $webquest_id); |
|---|
| 234 | } |
|---|
| 235 | } |
|---|
| 236 | |
|---|
| 237 | public function admin_save() |
|---|
| 238 | { |
|---|
| 239 | $this->layout = 'ajax'; |
|---|
| 240 | |
|---|
| 241 | if ( !empty($this->data['Webquest']) ): |
|---|
| 242 | Sanitize::paranoid($this->data['Webquest']['title']); |
|---|
| 243 | Sanitize::html($this->data['Webquest']['introduction']); |
|---|
| 244 | Sanitize::html($this->data['Webquest']['tasks']); |
|---|
| 245 | Sanitize::html($this->data['Webquest']['roles']); |
|---|
| 246 | Sanitize::html($this->data['Webquest']['process']); |
|---|
| 247 | Sanitize::html($this->data['Webquest']['evaluation']); |
|---|
| 248 | Sanitize::html($this->data['Webquest']['conclusion']); |
|---|
| 249 | |
|---|
| 250 | if ($this->Webquest->save($this->data)): |
|---|
| 251 | $this->set('section', $this->data['Webquest']['section']); |
|---|
| 252 | $this->set('id', $this->data['Webquest']['id']); |
|---|
| 253 | |
|---|
| 254 | $this->set('field', $this->Webquest->field($section, array("Webquest.id"=>$this->data['Webquest']['id']))); |
|---|
| 255 | $this->render('admin_get', 'ajax'); |
|---|
| 256 | endif; |
|---|
| 257 | endif; |
|---|
| 258 | } |
|---|
| 259 | // change webquest status published/draft |
|---|
| 260 | public function admin_change($webquest_id, $status) |
|---|
| 261 | { |
|---|
| 262 | $this->data['Webquest']['status'] = ($status == 0 ) ? 1 : 0; |
|---|
| 263 | |
|---|
| 264 | $this->data['Webquest']['id'] = (int) $webquest_id; |
|---|
| 265 | |
|---|
| 266 | if ($this->Webquest->save($this->data, array('validate'=>false))): |
|---|
| 267 | $this->msgFlash(__('Status modified', true), '/admin/webquests/listing'); |
|---|
| 268 | endif; |
|---|
| 269 | } |
|---|
| 270 | /** Select classroom to link*/ |
|---|
| 271 | public function admin_vclassrooms($webquest_id) |
|---|
| 272 | { |
|---|
| 273 | $this->pageTitle = $this->Auth->user('username') . '\'s Webquest'; |
|---|
| 274 | |
|---|
| 275 | $this->layout = 'admin'; |
|---|
| 276 | |
|---|
| 277 | $conditions = array('Vclassroom.user_id'=>$this->Auth->user('id'), 'Vclassroom.status'=>1); |
|---|
| 278 | |
|---|
| 279 | $this->set('data', $this->Webquest->Vclassroom->findAll($conditions)); |
|---|
| 280 | |
|---|
| 281 | //$this->Webquest->unbindModel(array('hasMany'=>array('Question', 'Result'), 'belongsTo'=>array('User'))); |
|---|
| 282 | |
|---|
| 283 | $this->set('webquests',$this->Webquest->VclassroomsWebquest->findAll(array('VclassroomsWebquest.webquest_id' => $webquest_id))); |
|---|
| 284 | |
|---|
| 285 | $this->set('webquest_id', $webquest_id); |
|---|
| 286 | } |
|---|
| 287 | |
|---|
| 288 | public function admin_link2class() |
|---|
| 289 | { |
|---|
| 290 | $this->layout = 'admin'; |
|---|
| 291 | if ( !empty($this->data['VclassroomsWebquest']) ): |
|---|
| 292 | Sanitize::clean($this->data['VclassroomsWebquest']); |
|---|
| 293 | if ( $this->Webquest->VclassroomsWebquest->save($this->data['VclassroomsWebquest'])): |
|---|
| 294 | $this->msgFlash(__('Webquest assigned', true),'/admin/webquests/vclassrooms/'.$this->data['VclassroomsWebquest']['webquest_id']); |
|---|
| 295 | endif; |
|---|
| 296 | endif; |
|---|
| 297 | } |
|---|
| 298 | |
|---|
| 299 | public function admin_unlink2class() |
|---|
| 300 | { |
|---|
| 301 | $this->layout = 'admin'; |
|---|
| 302 | if ( !empty($this->data['VclassroomsWebquest']) ): |
|---|
| 303 | Sanitize::clean($this->data['VclassroomsWebquest']); |
|---|
| 304 | |
|---|
| 305 | if ( $this->Webquest->VclassroomsWebquest->delete($this->data['VclassroomsWebquest']['id'])): |
|---|
| 306 | $this->msgFlash('Webquest unlinked', '/admin/webquests/vclassrooms/'.$this->data['VclassroomsWebquest']['webquest_id']); |
|---|
| 307 | endif; |
|---|
| 308 | endif; |
|---|
| 309 | } |
|---|
| 310 | |
|---|
| 311 | public function admin_delete($webquest_id) |
|---|
| 312 | { |
|---|
| 313 | if ($this->Webquest->del($webquest_id)): |
|---|
| 314 | $this->msgFlash(__('Data removed', true), '/admin/webquests/listing/'); |
|---|
| 315 | endif; |
|---|
| 316 | } |
|---|
| 317 | } |
|---|
| 318 | ?> |
|---|