Created
October 9, 2015 17:48
-
-
Save juanwilde/0226dff7094b5db6eb55 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Created by PhpStorm. | |
* User: Juan | |
* Date: 10/7/2015 | |
* Time: 8:15 PM | |
*/ | |
class indexController extends customersController | |
{ | |
private $_customers; | |
public function __construct() | |
{ | |
parent::__construct(); | |
$this->_customers = $this->loadModel('index'); | |
} | |
public function index() | |
{ | |
$this->_acl->access('admin_access'); | |
$this->_view->assign('title', 'Listado de Clientes'); | |
$this->_view->assign('customers', $this->_customers->getCustomers()); | |
$this->_view->render('index'); | |
} | |
public function add() | |
{ | |
$this->_acl->access('admin_access'); | |
$this->_view->assign('title', 'Añadir Cliente'); | |
$this->_view->setJs(array('ajax')); | |
if ($this->getInt('save') == 1) { | |
$this->_view->assign('data', $_POST); | |
if (!$this->getAlphaNum('name')) { | |
$this->_view->assign('_error', 'Debes introducir un nombre'); | |
$this->_view->render('new', 'index'); | |
exit; | |
} | |
if (!$this->getPostParam('phone')) { | |
$this->_view->assign('_error', 'Debes introducir un teléfono'); | |
$this->_view->render('new', 'index'); | |
exit; | |
} | |
if (!$this->getPostParam('pass')) { | |
$this->_view->assign('_error', 'Debes introducir una contraseña o indicar que no hay'); | |
$this->_view->render('new', 'index'); | |
exit; | |
} | |
if (!$this->getPostParam('status')) { | |
$this->_view->assign('_error', 'Debes introducir un estado de reparación'); | |
$this->_view->render('new', 'index'); | |
exit; | |
} | |
if($this->_customers->addCustomer($this->getAlphaNum('name'), $this->getAlphaNum('lastname'), | |
$this->getAlphaNum('phone'), $this->getPostParam('pass'), $this->getPostParam('equipment'), | |
$this->getPostParam('notes'), $this->getPostParam('status'), $this->getPostParam('email'))) { | |
$this->_view->assign('data', false); | |
$this->_view->assign('_message', 'Ficha creada con éxito!'); | |
$this->_view->render('index'); | |
exit; | |
} else { | |
$this->_view->assign('_error', 'Se ha producido un error a crear la ficha...'); | |
$this->_view->render('new', 'index'); | |
exit; | |
} | |
} | |
$this->_view->render('new'); | |
} | |
public function edit($id) | |
{ | |
$this->_acl->access('admin_access'); | |
$this->_view->assign('title', 'Editar datos de cliente'); | |
$this->_view->setJs(array('ajax')); | |
$this->_view->assign('customer', $this->_customers->getCustomer($id)); | |
$this->_view->render('edit'); | |
} | |
public function delete($id) { | |
$this->_acl->access('admin_access'); | |
if($this->_customers->deleteCustomer($id)) { | |
$this->_view->assign('_message', 'Ficha borrada con éxito!'); | |
$this->_view->assign('title', 'Listado de Clientes'); | |
$this->_view->assign('customers', $this->_customers->getCustomers()); | |
$this->_view->render('index'); | |
exit; | |
} else { | |
$this->_view->assign('_error', 'Error al borrar la ficha...'); | |
$this->_view->assign('title', 'Listado de Clientes'); | |
$this->_view->assign('customers', $this->_customers->getCustomers()); | |
$this->_view->render('index'); | |
exit; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment