Guest User

TicketController class

a guest
Oct 3rd, 2014
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.62 KB | None | 0 0
  1. <?php
  2. App::uses('AppController', 'Controller');
  3. /**
  4.  * Tickets Controller
  5.  *
  6.  * @property Ticket $Ticket
  7.  * @property PaginatorComponent $Paginator
  8.  */
  9. class TicketsController extends AppController {
  10.  
  11. /**
  12.  * Components
  13.  *
  14.  * @var array
  15.  */
  16.     public $components = array('Paginator');
  17.  
  18. /**
  19.  * index method
  20.  *
  21.  * @return void
  22.  */
  23.     public function index() {
  24.         $this->Ticket->recursive = 0;
  25.         $this->set('tickets', $this->Paginator->paginate());
  26.     }
  27.  
  28. /**
  29.  * view method
  30.  *
  31.  * @throws NotFoundException
  32.  * @param string $id
  33.  * @return void
  34.  */
  35.     public function view($id = null) {
  36.         if (!$this->Ticket->exists($id)) {
  37.             throw new NotFoundException(__('Invalid ticket'));
  38.         }
  39.         $options = array('conditions' => array('Ticket.' . $this->Ticket->primaryKey => $id));
  40.         $this->set('ticket', $this->Ticket->find('first', $options));
  41.     }
  42.  
  43. /**
  44.  * add method
  45.  *
  46.  * @return void
  47.  */
  48.     public function add() {
  49.         if ($this->request->is('post')) {
  50.             $this->Ticket->create();
  51. #pr($this); die();
  52.             if ($this->Ticket->saveAssociated($this->request->data, array('deep' => true))) {
  53.                 $this->Session->setFlash(__('The ticket has been saved.'));
  54.                 return $this->redirect(array('action' => 'index'));
  55.             } else {
  56.                 $this->Session->setFlash(__('The ticket could not be saved. Please, try again.'));
  57.             }
  58.         }
  59.     }
  60.  
  61. /**
  62.  * edit method
  63.  *
  64.  * @throws NotFoundException
  65.  * @param string $id
  66.  * @return void
  67.  */
  68.     public function edit($id = null) {
  69.         if (!$this->Ticket->exists($id)) {
  70.             throw new NotFoundException(__('Invalid ticket'));
  71.         }
  72.         if ($this->request->is(array('post', 'put'))) {
  73.             if ($this->Ticket->save($this->request->data)) {
  74.                 $this->Session->setFlash(__('The ticket has been saved.'));
  75.                 return $this->redirect(array('action' => 'index'));
  76.             } else {
  77.                 $this->Session->setFlash(__('The ticket could not be saved. Please, try again.'));
  78.             }
  79.         } else {
  80.             $options = array('conditions' => array('Ticket.' . $this->Ticket->primaryKey => $id));
  81.             $this->request->data = $this->Ticket->find('first', $options);
  82.         }
  83.     }
  84.  
  85. /**
  86.  * delete method
  87.  *
  88.  * @throws NotFoundException
  89.  * @param string $id
  90.  * @return void
  91.  */
  92.     public function delete($id = null) {
  93.         $this->Ticket->id = $id;
  94.         if (!$this->Ticket->exists()) {
  95.             throw new NotFoundException(__('Invalid ticket'));
  96.         }
  97.         $this->request->allowMethod('post', 'delete');
  98.         if ($this->Ticket->delete()) {
  99.             $this->Session->setFlash(__('The ticket has been deleted.'));
  100.         } else {
  101.             $this->Session->setFlash(__('The ticket could not be deleted. Please, try again.'));
  102.         }
  103.         return $this->redirect(array('action' => 'index'));
  104.     }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment