/**
  * Fetch the entities
  *
  * @param   int $count The number of matching entities to retrieve
  * @param   int $start The index of the first entity to retrieve
  *
  * @return  array
  */
 public function getItems($count = null, $start = 0)
 {
     $matches = $this->gateway->getAll($this->table);
     $matches = $this->applyConditions($matches);
     $matches = $this->applyOrdering($matches);
     if (!empty($this->columns)) {
         $result = $this->applyColumns($matches);
     } else {
         $result = $this->castToEntity($matches);
     }
     return array_slice($result, $start, $count);
 }
Exemplo n.º 2
0
 /**
  * Insert an entity.
  *
  * @param   object  $entity  The entity to store
  *
  * @return  void
  * @throws  OrmException
  */
 public function insert($entity)
 {
     $entityId = $this->entityRegistry->getEntityId($entity);
     if (empty($entityId)) {
         $id = 0;
         foreach ($this->gateway->getAll($this->tableName) as $row) {
             $id = max($id, $row['id']);
         }
         $this->entityRegistry->setEntityId($entity, $id + 1);
     }
     $this->gateway->insert($this->tableName, $this->builder->reduce($entity));
     $this->builder->resolve($entity);
 }