More dataaccess stuff.
[rock.divinelegy.git] / DataAccess / StepMania / SimfileRepository.php
1 <?php
2
3 namespace DataAccess\StepMania;
4
5 use DataAccess\StepMania\ISimfileRepository;
6 use DataAccess\DataMapper\IDataMapper;
7 use DataAccess\Queries\StepMania\ISimfileQueryConstraints;
8 use Domain\Entities\StepMania\ISimfile;
9
10 //TODO: Implement some sort of caching. Probably OK for now not to worry.
11 class SimfileRepository implements ISimfileRepository
12 {
13 private $_dataMapper;
14
15 public function __construct(IDataMapper $dataMapper) {
16 $this->_dataMapper = $dataMapper;
17 }
18
19 public function findById($id) {
20 return $this->_dataMapper->map(
21 'Simfile',
22 'SELECT * FROM %s WHERE id=' . $id
23 );
24 }
25
26 public function findRange($id, $limit)
27 {
28 return $this->_dataMapper->findRange(
29 'Simfile',
30 'SELECT * FROM %s WHERE id>=' . $id . ' LIMIT ' . $limit
31 );
32 }
33
34 public function save(ISimfile $entity) {
35 $this->_dataMapper->save($entity);
36 }
37
38 //TODO: Implement
39 public function remove(ISimfile $entity) {
40 ;
41 }
42
43 public function findByTitle($title, ISimfileQueryConstraints $constraints = NULL)
44 {
45 //TODO: Should I inject a factory, and then make $constraints if it isn't given?
46 if($constraints)
47 {
48 $queryString = $constraints->where('title', 'LIKE', "%%$title%%") //TODO: Should I make a like method that handles adding the %% ?
49 ->applyTo('SELECT * from %s');
50 } else {
51 //It would avoid this, or rather I could put this in the constraints class
52 $queryString = "SELECT * FROM %s WHERE title LIKE '%$title%'";
53 }
54
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
59
60 /**
61 * have this class contain a queryBuilderFactory and then have constraintsClass
62 * go in through methods which act on the query, adding in constraints.
63 */
64 return $this->_dataMapper->map('Simfile', $queryString);
65 }
66
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){}
75 }