5 use DataAccess\IFileRepository
;
6 use DataAccess\DataMapper\IDataMapper
;
7 use DataAccess\Queries\IQueryBuilderFactory
;
9 class FileRepository
implements IFileRepository
12 private $_queryBuilderFactory;
14 public function __construct(IDataMapper
$dataMapper, IQueryBuilderFactory
$queryBuilderFactory) {
15 $this->_dataMapper
= $dataMapper;
16 $this->_queryBuilderFactory
= $queryBuilderFactory;
19 public function findById($id) {
20 $queryBuilder = $this->_queryBuilderFactory
->createInstance();
21 $queryBuilder->where('id', '=', $id);
23 $results = $this->_dataMapper
->map(
28 return reset($results);
31 public function findAll()
33 $queryBuilder = $this->_queryBuilderFactory
->createInstance();
34 $queryBuilder->where('id', '>', 0);
36 return $this->_dataMapper
->map(
42 public function findRange($id, $limit)
44 return $this->_dataMapper
->findRange(
46 'SELECT * FROM %s WHERE id>=' . $id . ' LIMIT ' . $limit
50 public function findByHash($hash)
52 $queryBuilder = $this->_queryBuilderFactory
->createInstance();
53 $queryBuilder->where('hash', '=', "$hash");
55 $results = $this->_dataMapper
->map(
60 //XXX: Hack. Sometimes instead of getting a real array back we get the
61 //lazyload thing because I was an idiot with the database. Originally
62 //I simply did return reset($results) but if we don't have an array that
63 //won't work. So instead do a foreach (lazyload thing is iterable) and just
64 //return the first element.
66 //XXX: Disregard, I fixed the DB at home so that wasn't an issue and never
67 //put it up on the live server. Idiot.
68 return reset($results);
71 public function save(\Domain\Entities\IFile
$file) {
72 return $this->_dataMapper
->save($file);