/**
  *
  * @param \Zend\Db\TableGateway\AbstractTableGateway $data
  */
 public function init($data)
 {
     if ($data instanceof \Zend\Db\TableGateway\AbstractTableGateway) {
         $this->tableGateway = $data;
         $this->table = $this->tableGateway->getTable();
         $this->select = $data->getDefaultSql();
         $this->setSourceObject($data);
     } else {
         throw new \InvalidArgumentException('A instance of Zend\\Db\\SqlSelect is needed to use this dataSource!');
     }
     if ($this->getServiceLocator()->has('service_cache') && $this->getServiceLocator()->get('cache_metadata')['mode'] == 'enabled') {
         $this->setCache($this->getServiceLocator()->get('service_cache'));
     }
     return $this;
 }
 /**
  * @covers Zend\Db\TableGateway\AbstractTableGateway::__get
  */
 public function test__get()
 {
     $this->table->insert(array('foo'));
     // trigger last insert id update
     $this->assertEquals(10, $this->table->lastInsertValue);
     $this->assertSame($this->mockAdapter, $this->table->adapter);
     //$this->assertEquals('foo', $this->table->table);
 }
 public function delete($id)
 {
     $items = $this->orderItemTableGateway->select(['order_id' => (int) $id]);
     foreach ($items as $item) {
         $this->orderItemTableGateway->delete(['id' => $item->getId()]);
     }
     return $this->tableGateway->delete(['id' => (int) $id]);
 }
Exemplo n.º 4
0
 public function getOrderItems($orderId)
 {
     $itens = $this->orderItemTableGateway->select(['order_id' => $orderId]);
     $retorno = [];
     foreach ($itens as $item) {
         $retorno[$item->getId()] = $item;
     }
     return $retorno;
 }
Exemplo n.º 5
0
 public function insert($set)
 {
     $set['photo'] = $set['photo']['tmp_name'];
     unset($set['password_verify']);
     $set['password'] = md5($set['password']);
     // better than clear text
     //passwords
     return parent::insert($set);
 }
Exemplo n.º 6
0
 /**
  * Initialize
  *
  * @return void
  */
 public function initialize()
 {
     if ($this->isInitialized) {
         return;
     }
     parent::initialize();
     if (null !== $this->rowClass) {
         $resultSetPrototype = $this->getResultSetPrototype();
         $prototype = new $this->rowClass($this->getAdapter());
         if ($prototype instanceof ServiceLocatorAwareInterface) {
             $prototype->setServiceLocator($this->getServiceLocator());
         }
         $resultSetPrototype->setArrayObjectPrototype($prototype);
     }
 }
 public function findByIdUsuario($id, $idUsuario)
 {
     $hydrator = new ClassMethods();
     $hydrator->addStrategy('items', new OrderItemHydratorStrategy(new ClassMethods()));
     $order = $this->TableGateway->select(['id' => (int) $id, 'user_id' => $idUsuario])->current();
     $res = [];
     $items = $this->OrderItemTableGateway->select(['order_id' => $order->getId()]);
     foreach ($items as $item) {
         $order->addItem($item);
     }
     $data = $hydrator->extract($order);
     $res[] = $data;
     $arrayAdapter = new ArrayAdapter($res);
     $ordersColletion = new OrdersCollection($arrayAdapter);
     return $ordersColletion;
 }
 public function delete($id)
 {
     return parent::delete(array($this->primaryKeyField => $id));
 }
Exemplo n.º 9
0
 public function insertItem(array $data)
 {
     $this->orderItemTableGateway->insert($data);
     return $this->orderItemTableGateway->getLastInsertValue();
 }
Exemplo n.º 10
0
 /**
  *update
  *
  *Wrapper for 'update'
  * --------------------
  * Handle the insertion of model objects in addition to the traditional stuff you could pass into TableGateway's insert.
  * 
  * 
  * 
  *
  *@param array|object $set
  *@param string $where
  *
  *@return int
  *
  *
  *
  */
 public function update($set, $where = null)
 {
     if (is_object($set)) {
         // clear out 'id' if we need to
         $data = $set->toArray();
         if (array_key_exists('id', $data)) {
             unset($data['id']);
         }
         return parent::update($set->toArray(), $where);
     } else {
         return parent::update($set, $where);
     }
 }
Exemplo n.º 11
0
 /**
  *  Supprime un objet en base.
  *
  * @param mixed $mObjectOuWhere
  */
 public function delete($mObjectOuWhere)
 {
     $isEntityObjectDelete = $mObjectOuWhere instanceof \Core\Model\AbstractModel;
     if ($isEntityObjectDelete) {
         $object = $mObjectOuWhere;
         $id = is_array($object) ? $object[$this->nomCle] : $object->{$this->nomCle};
         $where = array($this->nomCle => $id);
     } else {
         $where = $mObjectOuWhere;
     }
     $preDeleteMethodName = $this->eventActions[self::PRE_DELETE];
     $postDeleteMethodName = $this->eventActions[self::POST_DELETE];
     if ($isEntityObjectDelete && method_exists($object, $preDeleteMethodName)) {
         $object->{$preDeleteMethodName}($this->getEventManager());
     }
     parent::delete($where);
     if ($isEntityObjectDelete && method_exists($object, $postDeleteMethodName)) {
         $object->{$postDeleteMethodName}($this->getEventManager());
     }
 }
Exemplo n.º 12
0
 /**
  * Initialize
  *
  * @return void
  */
 public function initialize()
 {
     if ($this->isInitialized) {
         return;
     }
     // Special case for PostgreSQL sequences:
     if ($this->adapter->getDriver()->getDatabasePlatformName() == "Postgresql") {
         $cfg = $this->getServiceLocator()->getServiceLocator()->get('config');
         $maps = isset($cfg['vufind']['pgsql_seq_mapping']) ? $cfg['vufind']['pgsql_seq_mapping'] : null;
         if (isset($maps[$this->table])) {
             $this->featureSet = new Feature\FeatureSet();
             $this->featureSet->addFeature(new Feature\SequenceFeature($maps[$this->table][0], $maps[$this->table][1]));
         }
     }
     parent::initialize();
     if (null !== $this->rowClass) {
         $resultSetPrototype = $this->getResultSetPrototype();
         $resultSetPrototype->setArrayObjectPrototype($this->initializeRowPrototype());
     }
 }
 public function rollbackTransaction()
 {
     $this->tableGateway->getAdapter()->getDriver()->getConnection()->rollback();
 }
Exemplo n.º 14
0
 /**
  * {@inheritDoc}
  */
 public function select($where = null)
 {
     if (!$this->isInitialized) {
         $this->initialize();
     }
     if (null === $where) {
         return $this->sql->select();
     }
     return parent::select($where);
 }
 public function delete($id)
 {
     $this->tableGateway->delete(['id' => (int) $id]);
     return true;
 }
 public function update($id, $client)
 {
     $this->tableGateway->update((array) $client, ['id' => (int) $id]);
     return $this->findById($id);
 }
 /**
  * Delete object from database
  *
  * @param mixed $objectOrWhere
  */
 public function delete($objectOrWhere)
 {
     $isEntityObjectDelete = $objectOrWhere instanceof \VisioCrudModeler\Model\TableGateway\Entity\AbstractEntity;
     if ($isEntityObjectDelete) {
         $object = $objectOrWhere;
         $id = is_array($object) ? $object[$this->keyName] : $object->{$this->keyName};
         $where = array($this->keyName => $id);
     } else {
         $where = $objectOrWhere;
     }
     $preDeleteMethodName = $this->eventActions[self::PRE_DELETE];
     $postDeleteMethodName = $this->eventActions[self::POST_DELETE];
     if ($isEntityObjectDelete && method_exists($object, $preDeleteMethodName)) {
         $object->{$preDeleteMethodName}($this->getEventManager());
     }
     parent::delete($where);
     if ($isEntityObjectDelete && method_exists($object, $postDeleteMethodName)) {
         $object->{$postDeleteMethodName}($this->getEventManager());
     }
 }
 public function fetchAll()
 {
     $rowset = $this->select();
     $data = array();
     foreach ($rowset as $row) {
         $data[] = $row;
     }
     return $data;
 }
 public function updateRecord($id, $data)
 {
     $ret = $this->update($data, array($this->pk => $id));
     if ($ret <= 0) {
         throw new CommonException(array('messageId' => 'globals.query.record_not_found', 'parms' => array('id' => $id), EXCEPTION_ERRORKEY => 404));
     }
     $ret = array('rowcount' => $ret);
     return $ret;
 }
 public function insertRecord($data)
 {
     try {
         parent::insert($data);
         // If the entity has a sequence on the PK then I am going to try
         // and retrieve that generated value to send it back
         if ($this->hasSequence()) {
             $ret = $this->getLastInsertValue();
             if ($ret <= 0) {
                 throw new CommonException(array('messageId' => 'globals.query.record_not_created', 'parms' => array('id' => implode(' - ', $data)), EXCEPTION_ERRORKEY => 500));
             }
         } else {
             // No sequence, then I send back the PK value
             // If PK value does not exist, then I will send 1
             $ret = isset($data[$this->pk]) ? $data[$this->pk] : 1;
         }
         return $ret;
     } catch (CommonException $ce) {
Exemplo n.º 19
0
 public function delete($id)
 {
     return parent::delete(array($this->pk => $id));
 }
 public function update(array $data, $id)
 {
     $this->tableGateway->update($data, ['id' => $id]);
     return $id;
 }
Exemplo n.º 21
0
 public function initialize()
 {
     if ($this->isInitialized) {
         return;
     }
     if (!$this->adapter) {
         $this->adapter = $this->getServiceLocator()->get('Zend\\Db\\Adapter\\Adapter');
     }
     $this->initTableName();
     parent::initialize();
 }