| 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 SubjectsController extends AppController |
|---|
| 12 | { |
|---|
| 13 | public $helpers = array('Ajax', 'Gags'); |
|---|
| 14 | |
|---|
| 15 | public $components = array('Portal'); |
|---|
| 16 | |
|---|
| 17 | public function beforeFilter() |
|---|
| 18 | { |
|---|
| 19 | parent::beforeFilter(); |
|---|
| 20 | $this->Auth->allow(array('display', 'view','show', 'panda')); |
|---|
| 21 | } |
|---|
| 22 | |
|---|
| 23 | public function display() |
|---|
| 24 | { |
|---|
| 25 | $this->layout = 'ajax'; |
|---|
| 26 | $conditions = null; |
|---|
| 27 | $fields = array('Subject.id', 'Subject.title', 'Subject.code'); |
|---|
| 28 | $order = 'Subject.title'; |
|---|
| 29 | $limit = null; |
|---|
| 30 | $this->set('data', $this->Subject->findAll($conditions, $fields, $order, $limit)); |
|---|
| 31 | $this->render('qs', 'ajax'); |
|---|
| 32 | } |
|---|
| 33 | |
|---|
| 34 | public function view($code) |
|---|
| 35 | { |
|---|
| 36 | $this->layout = 'portal'; |
|---|
| 37 | $this->Portal->statics(); // Charge Portal components aka Sidebars |
|---|
| 38 | $this->title = __('Subject', true); |
|---|
| 39 | $this->set('data', $this->Subject->getSubject($code)); |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | public function panda() |
|---|
| 43 | { |
|---|
| 44 | $this->title = 'Eastern::egg Panda'; |
|---|
| 45 | return true; |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | /** ==== ADMIN METHODS ==== */ |
|---|
| 49 | |
|---|
| 50 | public function admin_listing() |
|---|
| 51 | { |
|---|
| 52 | $this->layout = 'admin'; |
|---|
| 53 | $this->pageTitle = __('Subjects', true); |
|---|
| 54 | $conditions = null; |
|---|
| 55 | $fields = array('id', 'title', 'code'); |
|---|
| 56 | $order = 'title ASC'; |
|---|
| 57 | $this->set('data', $this->Subject->findAll($conditions, $fields, $order)); |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | public function admin_add() |
|---|
| 61 | { |
|---|
| 62 | $this->layout = 'admin'; |
|---|
| 63 | |
|---|
| 64 | if (!empty($this->data['Subject'])): |
|---|
| 65 | |
|---|
| 66 | Sanitize::clean($this->data['Subject']); |
|---|
| 67 | |
|---|
| 68 | if ($this->Subject->save($this->data)): |
|---|
| 69 | $this->msgFlash(__('Data saved', true),'/admin/subjects/listing'); |
|---|
| 70 | endif; |
|---|
| 71 | endif; |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | public function admin_edit($subject_id = null) |
|---|
| 75 | { |
|---|
| 76 | $this->layout = 'admin'; |
|---|
| 77 | if (empty($this->data['Subject'])): |
|---|
| 78 | $this->data = $this->Subject->read(null, $subject_id); |
|---|
| 79 | else: |
|---|
| 80 | Sanitize::clean($this->data['Subject']); |
|---|
| 81 | |
|---|
| 82 | if ($this->Subject->save($this->data)): |
|---|
| 83 | $this->msgFlash(__('Data saved', true), '/admin/subjects/listing'); |
|---|
| 84 | endif; |
|---|
| 85 | endif; |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | public function admin_delete($subject_id) |
|---|
| 89 | { |
|---|
| 90 | if ( $this->Subject->del($subject_id) ): |
|---|
| 91 | $this->msgFlash(__('Data removed', true),'/admin/subjects/listing'); |
|---|
| 92 | endif; |
|---|
| 93 | } |
|---|
| 94 | } |
|---|
| 95 | ?> |
|---|