ACC SHELL
<?php
/**
* IndexController
*
* @author
* @version
*/
require_once 'Zend/Controller/Action.php';
class KlientController extends TF_Controller_Action
{
/**
* The default action - show the home page
*/
public function indexAction ()
{
$model = new Client();
$filterForm = new Form_Filter_Client();
$wheres = array();
if($this->_getParam('filter')){
if($filterForm->isValid($_GET)){
$wheres = $filterForm->getValues();
}
}
$this->view->filterForm = $filterForm;
$this->view->data = $model->getAll($wheres);
}
public function upravitAction()
{
$id = $this->_getParam('id',-1);
$model = new Client();
$item = $model->find($id)->current();
$form = $this->view->form = new Form_Client();
if ($this->_request->isPost()) {
if ($form->isValid($_POST)) {
$vals = (object)$form->getValues();
$item->client_name = $vals->client_name;
$item->email = $vals->email;
$item->mobile = $vals->mobile;
$item->phone = $vals->phone;
$item->contact_person = $vals->contact_person;
$item->ic = $vals->ic;
$item->information = $vals->information;
$item->note = $vals->note;
$item->business_scope_id = $vals->business_scope_id;
$item->save();
$this->_addFlashMessage('Upraveno');
$this->_helper->redirector('index');
}
} else {
$form->populate($item->toArray());
}
}
public function detailAction()
{
$id = $this->_getParam('id',-1);
$model = new Client();
$this->view->item = $model->getAll(array('client.id'=>$id))->getItem(0);
}
public function pridatAction()
{
$model = new Client();
$item = $model->createRow();
$form = $this->view->form = new Form_Client();
if ($this->_request->isPost()) {
if ($form->isValid($_POST)) {
$vals = (object)$form->getValues();
$item->client_name = $vals->client_name;
$item->email = $vals->email;
$item->mobile = $vals->mobile;
$item->phone = $vals->phone;
$item->contact_person = $vals->contact_person;
$item->ic = $vals->ic;
$item->information = $vals->information;
$item->note = $vals->note;
$item->business_scope_id = $vals->business_scope_id;
$item->save();
$this->_addFlashMessage('Přidáno');
$this->_helper->redirector('index');
}
}
}
public function smazatAction()
{
$id = $this->_getParam('id',-1);
$model = new Client();
$item = $model->find($id)->current();
try{
$item->delete();
$this->_addFlashMessage('Smazáno');
} catch (Zend_Db_Exception $e) {
if (strpos($e->getMessage(), 'SQLSTATE[HY000]: General error: 1451') !== false) {
$this->_addFlashMessage('Tento záznam nelze smazat. Pravděpodobně existují záznamy v jiných tabulkách, které ho používají.', 'error');
} else {
throw $e;
}
}
$this->_helper->redirector('index');
}
}
ACC SHELL 2018