3 namespace DataAccess\StepMania
;
5 use DataAccess\StepMania\ISimfileRepository
;
6 use DataAccess\DataMapper\IDataMapper
;
7 use DataAccess\Queries\StepMania\ISimfileQueryConstraints
;
8 use Domain\Entities\StepMania\ISimfile
;
10 //TODO: Implement some sort of caching. Probably OK for now not to worry.
11 class SimfileRepository
implements ISimfileRepository
15 public function __construct(IDataMapper
$dataMapper) {
16 $this->_dataMapper
= $dataMapper;
19 public function findById($id) {
20 return $this->_dataMapper
->map(
22 'SELECT * FROM %s WHERE id=' . $id
26 public function findRange($id, $limit)
28 return $this->_dataMapper
->findRange(
30 'SELECT * FROM %s WHERE id>=' . $id . ' LIMIT ' . $limit
34 public function save(ISimfile
$entity) {
35 $this->_dataMapper
->save($entity);
39 public function remove(ISimfile
$entity) {
43 public function findByTitle($title, ISimfileQueryConstraints
$constraints = NULL
)
45 //TODO: Should I inject a factory, and then make $constraints if it isn't given?
48 $queryString = $constraints->where('title', 'LIKE', "%%$title%%") //TODO: Should I make a like method that handles adding the %% ?
49 ->applyTo('SELECT * from %s');
51 //It would avoid this, or rather I could put this in the constraints class
52 $queryString = "SELECT * FROM %s WHERE title LIKE '%$title%'";
55 //is it better to pass in constraints object?
56 //could have a default "select * from %s" in the constraints object which could be overwritten via a method.
57 //-no more need for applyTo, just go $constratints->getQuery
58 //maybe it should no longer be constraints but instead queryBuilder
61 * have this class contain a queryBuilderFactory and then have constraintsClass
62 * go in through methods which act on the query, adding in constraints.
64 return $this->_dataMapper
->map('Simfile', $queryString);
67 public function findByArtist($artist){}
68 public function findByBpm($high, $low){}
69 public function findByStepArtist($artistName){}
70 public function findByLightMeter($feet){}
71 public function findByBeginnerMeter($feet){}
72 public function findByMediumMeter($feet){}
73 public function findByHardMeter($feet){}
74 public function findByExpertMeter($feet){}