/**
  * Create a resource
  *
  * @param  mixed $data
  * @return ApiProblem|mixed
  */
 public function create($data)
 {
     $entity = new ClienteEntity();
     $data = json_decode(json_encode($data), true);
     $entity->exchangeArray($data);
     $data = $entity->getArrayCopy();
     $this->tableGateway->insert($data);
     $data['id'] = $this->tableGateway->getLastInsertValue();
     return $data;
 }
Ejemplo n.º 2
0
 /**
  * @param array $data
  * @return object
  */
 public function create(array $data)
 {
     $this->table->insert($data);
     $id = $this->table->getLastInsertValue();
     $entity = $this->find($id);
     if (!$entity) {
         throw new \Exception("Entity not created?");
     }
     return $entity;
 }
 /**
  * @param AbstractEntity $entity
  * @return $this
  */
 public function persist(AbstractEntity $entity)
 {
     $data = $this->hydrator->extract($entity);
     if ($this->hasIdentity($entity)) {
         $this->gateway->update($data, ['id' => $entity->getId()]);
     } else {
         $this->gateway->insert($data);
         $entity->setId($this->gateway->getLastInsertValue());
     }
     return $this;
 }
Ejemplo n.º 4
0
 /**
  * @param AbstractModel $model
  */
 protected function internalSave(AbstractModel $model)
 {
     $pKey = $this->getPrimaryKey();
     if (isset($model->id)) {
         $this->tableGateway->update($model->toArray(), [$pKey => $model->{$pKey}]);
     } else {
         $this->tableGateway->insert($model->toArray());
         $id = $this->tableGateway->getLastInsertValue();
         $model->{$pKey} = $id;
     }
 }
 /**
  * Insert node
  *
  * @param integer $level
  * @param integer $nearKey
  * @param array $data
  * @param array $filter
  * @param boolean $useTransaction
  * @return integer|string
  */
 protected function insertNode($level, $nearKey, array $data, array $filter = [], $useTransaction = true)
 {
     try {
         if ($useTransaction) {
             $this->tableGateway->getAdapter()->getDriver()->getConnection()->beginTransaction();
         }
         $this->tableGateway->update([$this->left => new Expression('IF (' . $this->left . ' > ?, ' . $this->left . ' + 2, ' . $this->left . ')', [$nearKey]), $this->right => new Expression('IF (' . $this->right . '  > ?, ' . $this->right . ' + 2, ' . $this->right . ')', [$nearKey])], [(new Predicate())->greaterThanOrEqualTo($this->right, $nearKey)] + $filter);
         $leftKey = $nearKey + 1;
         $rightKey = $nearKey + 2;
         $level = $level + 1;
         // insert a new node
         $this->tableGateway->insert([$this->left => $leftKey, $this->right => $rightKey, $this->level => $level] + $data);
         $insertId = $this->tableGateway->getLastInsertValue();
         // update parent info
         if (false !== ($parent = $this->getParentNode($leftKey, $rightKey, $level, $filter))) {
             $this->tableGateway->update([$this->parent => $parent[$this->nodeId]], [$this->nodeId => $insertId]);
         }
         if ($useTransaction) {
             $this->tableGateway->getAdapter()->getDriver()->getConnection()->commit();
         }
     } catch (Exception $e) {
         if ($useTransaction) {
             $this->tableGateway->getAdapter()->getDriver()->getConnection()->rollback();
         }
         ApplicationErrorLogger::log($e);
         return $e->getMessage();
     }
     return $insertId;
 }
Ejemplo n.º 6
0
 /**
  * Create easypay trade.
  * @see \Zend\Mvc\Controller\AbstractActionController::indexAction()
  */
 public function indexAction()
 {
     if ($this->verifyRequest()) {
         $this->appendTitle('收银台');
         $this->layout()->setVariable('is_cashier_page', true);
         $dbAdapter = $this->getServiceLocator()->get('Zend\\Db\\Adapter\\Adapter');
         /**
          * Check the parameters if they are valid.
          */
         $parameters = $this->getRequest()->getQuery();
         // if merchant exsist
         // if trade|redirect_url|notify_url|sign empty
         // if price is a floating numberic
         $exception = new \Exception('Parameters is invalid!');
         if (empty(trim($parameters['trade'])) || empty(trim($parameters['redirect_url'])) || empty(trim($parameters['notify_url'])) || empty(trim($parameters['sign']))) {
             throw $exception;
         }
         if (!is_numeric(trim($parameters['price']))) {
             throw $exception;
         }
         $merchant_validator = new \Zend\Validator\Db\NoRecordExists(array('table' => 'merchant', 'field' => 'name', 'adapter' => $dbAdapter));
         if ($merchant_validator->isValid(intval($parameters['merchant']))) {
             throw $exception;
         }
         /**
          * Check if there is an exsist trade.
          */
         $GetMerchantIdByName = $this->getServiceLocator()->get('GetMerchantIdByName');
         $merchant_id = $GetMerchantIdByName($parameters['merchant']);
         $trade = $this->getTrade($merchant_id, trim($parameters['trade']));
         $trade_id = null;
         $payment_interface_type = null;
         if (!empty($trade)) {
             // Trade exsist.
             if ($trade->pay_status) {
                 throw new \Exception('Trade had payed before!');
             } else {
                 // Update the exsist trade
                 $trade->price = trim($parameters['price']);
                 $trade->redirect_url = trim($parameters['redirect_url']);
                 $trade->notify_url = trim($parameters['notify_url']);
                 $trade->save();
                 $trade_id = $trade->id;
                 $payment_interface_type = $trade->payment_interface_type;
             }
         } else {
             // Trade not exsist.
             // Create a new trade
             $tableGateway = new TableGateway('trade', $dbAdapter, new Feature\RowGatewayFeature('id'));
             $tableGateway->insert(array('merchant_id' => $merchant_id, 'merchant_trade_id' => trim($parameters['trade']), 'redirect_url' => trim($parameters['redirect_url']), 'notify_url' => trim($parameters['notify_url']), 'price' => trim($parameters['price']), 'pay_status' => 0, 'create_time' => date('Y-n-j H:i:s', time())));
             $trade_id = $tableGateway->getLastInsertValue();
         }
         return array('price' => trim($parameters['price']), 'merchant' => $parameters['merchant'], 'trade' => trim($parameters['trade']), 'selected_payment' => $payment_interface_type);
     } else {
         throw new \Exception('Bad Reaquest !');
     }
 }
Ejemplo n.º 7
0
 /**
  * Saves the given rating to the storage system.
  *
  * @param Rating $rating The rating to persist.
  */
 public function persist(Rating $rating)
 {
     if ($rating->getId()) {
         $this->gateway->update(array('typeId' => $rating->getTypeId(), 'userId' => $rating->getUserId(), 'rating' => $rating->getRating()), array('id' => $rating->getId()));
     } else {
         $this->gateway->insert(array('typeId' => $rating->getTypeId(), 'userId' => $rating->getUserId(), 'rating' => $rating->getRating()));
         $id = $this->gateway->getLastInsertValue();
         $rating->setId($id);
     }
 }
Ejemplo n.º 8
0
 /**
  * Adds a data
  */
 public function insert()
 {
     $id = $this->table->insert($this->data);
     if (is_null($id)) {
         if (array_key_exists('firephp', $GLOBALS)) {
             $GLOBALS['firephp']->error('Error on query ' . $this->table->getSql()->getSqlPlatform()->getSqlString($this->table->getAdapter()->getPlatform()));
         }
         throw new Exception('Error on query ' . $this->table->getSql()->getSqlPlatform()->getSqlString($this->table->getAdapter()->getPlatform()));
     }
     $this->data[$this->primary] = $this->table->getLastInsertValue();
 }
Ejemplo n.º 9
0
 /**
  * Сохраняет объект в таблице
  *
  * @param EntityInterface $object
  * @throws \Exception
  */
 public function save(EntityInterface $object)
 {
     $data = array();
     foreach ($this->fields as $field) {
         $data[$field] = $object->{$field};
     }
     $id = $object->getKeyValue();
     if (null === $id) {
         $this->tableGateway->insert($data);
         $object->{$object->getKeyName()} = $this->tableGateway->getLastInsertValue();
     } else {
         if ($this->getByKey($id, $object->getKeyName())) {
             $this->tableGateway->update($data, array($object->getKeyName() => $id));
         } else {
             throw new \Exception('row with ' . $id . ' id does not exist');
         }
     }
 }
Ejemplo n.º 10
0
 /**
  * {@inheritdoc}
  *
  * {@inheritdoc}
  */
 public function create($itemData, $rewriteIfExist = false)
 {
     $identifier = $this->getIdentifier();
     $adapter = $this->dbTable->getAdapter();
     // begin Transaction
     $errorMsg = 'Can\'t start insert transaction';
     $adapter->getDriver()->getConnection()->beginTransaction();
     try {
         if (isset($itemData[$identifier]) && $rewriteIfExist) {
             $errorMsg = 'Can\'t delete item with "id" = ' . $itemData[$identifier];
             $this->dbTable->delete(array($identifier => $itemData[$identifier]));
         }
         $errorMsg = 'Can\'t insert item';
         $rowsCount = $this->dbTable->insert($itemData);
         $adapter->getDriver()->getConnection()->commit();
     } catch (\Exception $e) {
         $adapter->getDriver()->getConnection()->rollback();
         throw new DataStoresException($errorMsg, 0, $e);
     }
     $id = $this->dbTable->getLastInsertValue();
     $newItem = array_merge(array($identifier => $id), $itemData);
     return $newItem;
 }
Ejemplo n.º 11
0
 protected function _create($itemData, $rewriteIfExist = false)
 {
     $identifier = $this->getIdentifier();
     if ($rewriteIfExist) {
         if (isset($itemData[$identifier])) {
             $this->deleteIfExist($itemData, $identifier);
         } else {
             if (isset($itemData[0]) && isset($itemData[0][$identifier])) {
                 foreach ($itemData as $item) {
                     $this->deleteIfExist($item, $identifier);
                 }
             }
         }
     }
     $this->dbTable->insert($itemData);
     if (!isset($itemData[$identifier])) {
         $id = $this->dbTable->getLastInsertValue();
         $newItem = $this->read($id);
     } else {
         $newItem = $itemData;
     }
     return $newItem;
 }
Ejemplo n.º 12
0
 /**
  * @covers Zend\Db\TableGateway\TableGateway::getLastInsertValue
  */
 public function testGetLastInsertValue()
 {
     $this->table->insert(array('foo' => 'bar'));
     $this->assertEquals(10, $this->table->getLastInsertValue());
 }
Ejemplo n.º 13
0
 public function save($version)
 {
     $this->tableGateway->insert(['version' => $version]);
     return $this->tableGateway->getLastInsertValue();
 }
Ejemplo n.º 14
0
 public function index05Action()
 {
     $table = "user";
     $adapter = $this->getServiceLocator()->get("db_books");
     $tableGateway = new TableGateway($table, $adapter);
     $insertObj = new Insert("user");
     $insertObj->columns(array("name", "email"))->values(array("name" => "Armasky", "email" => "*****@*****.**"));
     $tableGateway->insertWith($insertObj);
     //last record inserted
     echo $tableGateway->getLastInsertValue();
     return false;
 }
Ejemplo n.º 15
0
 public function addSimpleData($table, $data)
 {
     $tableGateway = new TableGateway($table, $this->dbAdapter);
     $tableGateway->insert($data);
     return $tableGateway->getLastInsertValue();
 }