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;
 }