<?php
class ChoicesController extends AppController {

	var $name = 'Choices';
	var $helpers = array('Html', 'Form', 'Time');
		
	function beforeFilter(){
	//if ($this->only(array('add', 'edit'))) { $this->__lists(); }
	  parent::beforeFilter();
	}		
	
	function index() {
		$this->Choice->recursive = 0;
		$this->set('choices', $this->paginate());
	}
	

	function view($id = null) {
    $this->idEmptyRedirect($id, 'index');
		$this->set('choice', $this->Choice->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Choice->create();
			if ($this->Choice->save($this->data)) {
				$this->flashSuccess(__('La opción ha sido creada', true), 'index');
			} else {
				$this->flashWarning(__('La opción no pudo ser creada. Corrija los errores e intente de nuevo', true));
			}
		}
	}		

	function edit($id = null) {
    $this->idEmptyRedirect($id, 'index');
		if (!empty($this->data)) {
			if ($this->Choice->save($this->data)) {
				$this->flashSuccess(__('La opción ha sido creada', true), 'index');
			} else {
				$this->flashWarning(__('La opción no pudo ser creada. Corrija los errores e intente de nuevo', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Choice->read(null, $id);
		}
	}		
	
	## Private methods ##
	function __lists() {
//		$roles = $this->Choice->Questionnaire->find('list');
//		$this->set(compact('choices'));
	}		
}
?>