| @@ 7-83 (lines=77) @@ | ||
| 4 | ||
| 5 | use Aura\Sql\ConnectionLocator; |
|
| 6 | ||
| 7 | class MysqlBookRepository implements BookRepositoryInterface |
|
| 8 | { |
|
| 9 | ||
| 10 | /** @var ConnectionLocator */ |
|
| 11 | protected $connections; |
|
| 12 | ||
| 13 | /** |
|
| 14 | * @param ConnectonLocator $connections |
|
| 15 | */ |
|
| 16 | public function __construct(ConnectionLocator $connections) |
|
| 17 | { |
|
| 18 | $this->connections = $connections; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @param integer $id |
|
| 23 | * |
|
| 24 | * @return array|false |
|
| 25 | */ |
|
| 26 | public function getBookById($id) |
|
| 27 | { |
|
| 28 | $query = " |
|
| 29 | SELECT `id`, `title`, `author`, `image`, `date_read` AS `date` |
|
| 30 | FROM `jpemeric_stream`.`book` |
|
| 31 | WHERE `id` = :id |
|
| 32 | LIMIT 1"; |
|
| 33 | $bindings = [ |
|
| 34 | 'id' => $id, |
|
| 35 | ]; |
|
| 36 | ||
| 37 | return $this |
|
| 38 | ->connections |
|
| 39 | ->getRead() |
|
| 40 | ->fetchOne($query, $bindings); |
|
| 41 | } |
|
| 42 | ||
| 43 | /** |
|
| 44 | * @param string $title |
|
| 45 | * @param string $author |
|
| 46 | * |
|
| 47 | * @return array|false |
|
| 48 | */ |
|
| 49 | public function getBookByFields($title, $author) |
|
| 50 | { |
|
| 51 | $query = " |
|
| 52 | SELECT * |
|
| 53 | FROM `jpemeric_stream`.`book` |
|
| 54 | WHERE `title` = :title AND `author` = :author |
|
| 55 | LIMIT 1"; |
|
| 56 | $bindings = [ |
|
| 57 | 'title' => $title, |
|
| 58 | 'author' => $author, |
|
| 59 | ]; |
|
| 60 | ||
| 61 | return $this |
|
| 62 | ->connections |
|
| 63 | ->getRead() |
|
| 64 | ->fetchOne($query, $bindings); |
|
| 65 | } |
|
| 66 | ||
| 67 | /** |
|
| 68 | * @return array|false |
|
| 69 | */ |
|
| 70 | public function getUnmappedBooks() |
|
| 71 | { |
|
| 72 | $query = " |
|
| 73 | SELECT `id`, `date` |
|
| 74 | FROM `jpemeric_stream`.`book` |
|
| 75 | LEFT JOIN `jpemeric_stream`.`post` |
|
| 76 | ON `post`.`type_id` = `book`.`id` AND `post`.`id` IS NULL"; |
|
| 77 | ||
| 78 | return $this |
|
| 79 | ->connections |
|
| 80 | ->getRead() |
|
| 81 | ->fetchAll($query); |
|
| 82 | } |
|
| 83 | } |
|
| 84 | ||
| @@ 8-86 (lines=79) @@ | ||
| 5 | use Aura\Sql\ConnectionLocator; |
|
| 6 | use DateTimeInterface; |
|
| 7 | ||
| 8 | class MysqlDistanceRepository implements DistanceRepositoryInterface |
|
| 9 | { |
|
| 10 | ||
| 11 | /** @var ConnectionLocator */ |
|
| 12 | protected $connections; |
|
| 13 | ||
| 14 | /** |
|
| 15 | * @param ConnectonLocator $connections |
|
| 16 | */ |
|
| 17 | public function __construct(ConnectionLocator $connections) |
|
| 18 | { |
|
| 19 | $this->connections = $connections; |
|
| 20 | } |
|
| 21 | ||
| 22 | /** |
|
| 23 | * @param integer $id |
|
| 24 | * |
|
| 25 | * @return array|false |
|
| 26 | */ |
|
| 27 | public function getDistanceById($id) |
|
| 28 | { |
|
| 29 | $query = " |
|
| 30 | SELECT * |
|
| 31 | FROM `jpemeric_stream`.`distance` |
|
| 32 | WHERE `id` = :id |
|
| 33 | LIMIT 1"; |
|
| 34 | $bindings = [ |
|
| 35 | 'id' => $id, |
|
| 36 | ]; |
|
| 37 | ||
| 38 | return $this |
|
| 39 | ->connections |
|
| 40 | ->getRead() |
|
| 41 | ->fetchOne($query, $bindings); |
|
| 42 | } |
|
| 43 | ||
| 44 | /** |
|
| 45 | * @param DateTimeInterface $date |
|
| 46 | * @param string $type |
|
| 47 | * @param double $mileage |
|
| 48 | * |
|
| 49 | * @return array|false |
|
| 50 | */ |
|
| 51 | public function getDistanceByFields(DateTimeInterface $date, $type, $mileage) |
|
| 52 | { |
|
| 53 | $query = " |
|
| 54 | SELECT * |
|
| 55 | FROM `jpemeric_stream`.`distance` |
|
| 56 | WHERE `date` = :date AND `type` = :type AND `mileage` = :mileage |
|
| 57 | LIMIT 1"; |
|
| 58 | $bindings = [ |
|
| 59 | 'date' => $date->format('Y-m-d H:i:s'), |
|
| 60 | 'type' => $type, |
|
| 61 | 'mileage' => $mileage, |
|
| 62 | ]; |
|
| 63 | ||
| 64 | return $this |
|
| 65 | ->connections |
|
| 66 | ->getRead() |
|
| 67 | ->fetchOne($query, $bindings); |
|
| 68 | } |
|
| 69 | ||
| 70 | /** |
|
| 71 | * @return array|false |
|
| 72 | */ |
|
| 73 | public function getUnmappedDistances() |
|
| 74 | { |
|
| 75 | $query = " |
|
| 76 | SELECT `id`, `date` |
|
| 77 | FROM `jpemeric_stream`.`distance` |
|
| 78 | LEFT JOIN `jpemeric_stream`.`post` |
|
| 79 | ON `post`.`type_id` = `distance`.`id` AND `post`.`id` IS NULL"; |
|
| 80 | ||
| 81 | return $this |
|
| 82 | ->connections |
|
| 83 | ->getRead() |
|
| 84 | ->fetchAll($query); |
|
| 85 | } |
|
| 86 | } |
|
| 87 | ||
| @@ 8-84 (lines=77) @@ | ||
| 5 | use Aura\Sql\ConnectionLocator; |
|
| 6 | use DateTimeInterface; |
|
| 7 | ||
| 8 | class MysqlTwitterRepository implements TwitterRepositoryInterface |
|
| 9 | { |
|
| 10 | ||
| 11 | /** @var ConnectionLocator */ |
|
| 12 | protected $connections; |
|
| 13 | ||
| 14 | /** |
|
| 15 | * @param ConnectonLocator $connections |
|
| 16 | */ |
|
| 17 | public function __construct(ConnectionLocator $connections) |
|
| 18 | { |
|
| 19 | $this->connections = $connections; |
|
| 20 | } |
|
| 21 | ||
| 22 | /** |
|
| 23 | * @param integer $id |
|
| 24 | * |
|
| 25 | * @return array|false |
|
| 26 | */ |
|
| 27 | public function getTwitterById($id) |
|
| 28 | { |
|
| 29 | $query = " |
|
| 30 | SELECT * |
|
| 31 | FROM `jpemeric_stream`.`twitter` |
|
| 32 | WHERE `id` = :id |
|
| 33 | LIMIT 1"; |
|
| 34 | $bindings = [ |
|
| 35 | 'id' => $id, |
|
| 36 | ]; |
|
| 37 | ||
| 38 | return $this |
|
| 39 | ->connections |
|
| 40 | ->getRead() |
|
| 41 | ->fetchOne($query, $bindings); |
|
| 42 | } |
|
| 43 | ||
| 44 | /** |
|
| 45 | * @param DateTimeInterface $date |
|
| 46 | * @param string $text |
|
| 47 | * |
|
| 48 | * @return array|false |
|
| 49 | */ |
|
| 50 | public function getTwitterByFields(DateTimeInterface $date, $text) |
|
| 51 | { |
|
| 52 | $query = " |
|
| 53 | SELECT * |
|
| 54 | FROM `jpemeric_stream`.`twitter` |
|
| 55 | WHERE `date` = :date AND `text` = :text |
|
| 56 | LIMIT 1"; |
|
| 57 | $bindings = [ |
|
| 58 | 'date' => $date->format('Y-m-d H:i:s'), |
|
| 59 | 'text' => $text, |
|
| 60 | ]; |
|
| 61 | ||
| 62 | return $this |
|
| 63 | ->connections |
|
| 64 | ->getRead() |
|
| 65 | ->fetchOne($query, $bindings); |
|
| 66 | } |
|
| 67 | ||
| 68 | /** |
|
| 69 | * @return array|false |
|
| 70 | */ |
|
| 71 | public function getUnmappedTwitters() |
|
| 72 | { |
|
| 73 | $query = " |
|
| 74 | SELECT `id`, `date` |
|
| 75 | FROM `jpemeric_stream`.`twitter` |
|
| 76 | LEFT JOIN `jpemeric_stream`.`post` |
|
| 77 | ON `post`.`type_id` = `twitter`.`id` AND `post`.`id` IS NULL"; |
|
| 78 | ||
| 79 | return $this |
|
| 80 | ->connections |
|
| 81 | ->getRead() |
|
| 82 | ->fetchAll($query); |
|
| 83 | } |
|
| 84 | } |
|
| 85 | ||