public function saveAction() { $data = $this->getRequest()->getParam($this->_table); $form = $this->_form; if (isset($data['id'])) { $item = AbstractDbTable::get($this->_table)->findOneById($data['id']); if ($item) { $form->set($item); } } $data['chave'] = ChaveBusiness::chave($data['nome']); if ($form->isValid($data)) { if (!$form->save()) { foreach ($form->getErrorMessages() as $message) { $this->addMessage($message, 'danger'); } } else { if ($data['id'] != '') { $this->addMessage('Editado com sucesso!', 'success'); } else { $this->addMessage('Cadastrado com sucesso!', 'success'); } $this->_redirect('admin/' . str_replace('_', '-', $this->_table)); exit; } } $this->view->form = $form; $this->render('edit'); }
public function setChave($value) { $values = false; if ($_REQUEST) { $values = $_REQUEST[$this->_table]; } if ($values && isset($values) && $value) { $value = ChavePlugin::get($value); $dbtable = AbstractDbTable::get($this->_table); $select = $dbtable->select()->from($this->_table, array('id', 'chave'))->where('chave regexp ?', $value)->order('chave desc'); $fetch = $dbtable->fetchAll($select); $count = 0; $array = array(); if ($fetch->count()) { $count = $fetch->count(); foreach ($fetch as $item) { $array[$item->id] = $item->chave; } if (array_key_exists($values['id'], $array)) { $value = $array[$values['id']]; } elseif (in_array($value, $array)) { $value = $value . '-' . ($count + 1); } } return $value; } return $value; }
protected function getItemCart($cart) { $produtos = array(); $collection = AbstractDbTable::get('produto'); foreach ($cart as $item) { $produto = $collection->produtoById($item['id']); $total = $produto->preco * $item['quantidade']; $imposto = $total * ($produto->imposto / 100); $produtos[] = array('id' => $produto->id, 'nome' => $produto->nome, 'preco' => $produto->preco, 'quantidade' => $item['quantidade'], 'total' => $total, 'imposto' => $imposto); $this->_totalImposto = $this->_totalImposto + $imposto; $this->_totalCompra = $this->_totalCompra + $total; } return $produtos; }
public function saveAction() { $data = $this->getRequest()->getParam($this->_table, false); $item = false; $item = AbstractDbTable::get($this->_table)->findOneById($data['id']); $form = $this->_form; if (isset($data['id'])) { $form->set($item); } if ($form->isValid($data)) { $form->save(); if ($data['id'] != '') { $this->addMessage('Tributo editado com sucesso!', 'success'); } else { $this->addMessage('Tributo cadastrado com sucesso!', 'success'); } $this->_redirect('admin/tributo'); } $this->addMessage('Os campos obrigatórios devem estar preenchidos!', 'warning'); $this->view->form = $form; }
public function findAction() { $session = new Zend_Session_Namespace('find'); $data = $this->getRequest()->getParam($this->_table, false); if (!$data && isset($session->data)) { $data = $session->data; } if ($data) { $session->data = $data; $this->_form->set($data); $this->view->form = $this->_form; $this->view->cols = $this->_cols; $this->view->list = $this->paginator(AbstractDbTable::get($this->_table)->findByForm($this->_form, $this->_select), 10); $this->render('index'); } }
public function indexAction() { $produtos = AbstractDbTable::get('produto'); $this->view->produtos = $produtos->fetchAll(); }
public function getDbOptions($table, $empty_value = '', $where = null) { $options = array('' => $empty_value); $fetch = AbstractDbTable::get($table)->fetchAll($where); foreach ($fetch as $item) { $options[$item->id] = $item; } return $options; }