Esempio n. 1
0
 /**
  *
  * @param \Accounting\Model\Account $item
  */
 public function save($item)
 {
     $data = array('parentId' => $item->getParentId() ?: null, 'companyId' => $item->getCompanyId() ?: null, 'type' => $item->getType(), 'code' => $item->getCode(), 'name' => $item->getName(), 'status' => $item->getStatus(), 'remain' => $item->getRemain(), 'createdById' => $item->getCreatedById(), 'createdDateTime' => $item->getCreatedDateTime());
     /* @var $dbAdapter \Zend\Db\Adapter\Adapter */
     $dbAdapter = $this->getServiceLocator()->get('dbAdapter');
     /* @var $dbSql \Zend\Db\Sql\Sql */
     $dbSql = $this->getServiceLocator()->get('dbSql');
     if (!$item->getId()) {
         $insert = $this->getDbSql()->insert(self::TABLE_NAME);
         $insert->values($data);
         $query = $dbSql->buildSqlString($insert);
         /* @var $results \Zend\Db\Adapter\Driver\Pdo\Result */
         $results = $dbAdapter->query($query, $dbAdapter::QUERY_MODE_EXECUTE);
         $item->setId($results->getGeneratedValue());
     } else {
         $update = $this->getDbSql()->update(self::TABLE_NAME);
         $update->set($data);
         $update->where(['id' => (int) $item->getId()]);
         $query = $dbSql->buildSqlString($update);
         $results = $dbAdapter->query($query, $dbAdapter::QUERY_MODE_EXECUTE);
     }
     return $results;
 }
 public function deleteAction()
 {
     $id = $this->params()->fromQuery('id');
     $account = new Account();
     $account->setId($id);
     $accountMapper = $this->getServiceLocator()->get('Accounting\\Model\\AccountMapper');
     if (!$accountMapper->get($account)) {
         return $this->page404();
     }
     $auth = $this->getServiceLocator()->get('Authorize\\Service\\Authorize');
     if ($account->getCreatedById() == $this->user()->getIdentity() || $this->user()->getUser()->isAdmin()) {
         $accountMapper->delete($account);
         $jsonModel = new JsonModel();
         $jsonModel->setVariables(['code' => 1, 'messages' => ['Đã xóa thành công.']]);
         return $jsonModel;
     } else {
         $jsonModel = new JsonModel();
         $jsonModel->setVariables(['code' => 0, 'messages' => ['Bạn không có quyền xóa.']]);
         return $jsonModel;
     }
     return $this->redirect()->toUrl('/accounting');
 }