| @@ 7-44 (lines=38) @@ | ||
| 4 | ||
| 5 | use Aura\Sql\ConnectionLocator; |
|
| 6 | ||
| 7 | class MysqlIntroductionRepository implements IntroductionRepository |
|
| 8 | { |
|
| 9 | ||
| 10 | /** @var Aura\Sql\ConnectionLocator */ |
|
| 11 | protected $connections; |
|
| 12 | ||
| 13 | /** |
|
| 14 | * @param Aura\Sql\ConnectionLocator |
|
| 15 | */ |
|
| 16 | public function __construct(ConnectionLocator $connections) |
|
| 17 | { |
|
| 18 | $this->connections = $connections; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @param string $type |
|
| 23 | * @param string $value |
|
| 24 | * |
|
| 25 | * @return array|false |
|
| 26 | */ |
|
| 27 | public function findByType($type, $value = '') |
|
| 28 | { |
|
| 29 | $query = " |
|
| 30 | SELECT `title`, `content`, `image` |
|
| 31 | FROM `jpemeric_blog`.`introduction` |
|
| 32 | WHERE `type` = :type AND `value` = :value |
|
| 33 | LIMIT 1"; |
|
| 34 | $bindings = [ |
|
| 35 | 'type' => $type, |
|
| 36 | 'value' => $value, |
|
| 37 | ]; |
|
| 38 | ||
| 39 | return $this |
|
| 40 | ->connections() |
|
| 41 | ->getRead() |
|
| 42 | ->fetchOne($query, $bindings); |
|
| 43 | } |
|
| 44 | } |
|
| 45 | ||
| @@ 7-45 (lines=39) @@ | ||
| 4 | ||
| 5 | use Aura\Sql\ConnectionLocator; |
|
| 6 | ||
| 7 | class MysqlPostRepository implements PostRepository |
|
| 8 | { |
|
| 9 | ||
| 10 | /** @var Aura\Sql\ConnectionLocator */ |
|
| 11 | protected $connections; |
|
| 12 | ||
| 13 | /** |
|
| 14 | * @param Aura\Sql\ConnectionLocator $connections |
|
| 15 | */ |
|
| 16 | public function __construct(ConnectionLocator $connections) |
|
| 17 | { |
|
| 18 | $this->connections = $connections; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @param string $category |
|
| 23 | * @param string $path |
|
| 24 | * |
|
| 25 | * @return array|false |
|
| 26 | */ |
|
| 27 | public function findPostByPath($category, $path) |
|
| 28 | { |
|
| 29 | $query = " |
|
| 30 | SELECT `id`, `title`, `path`, `date`, `body`, `category` |
|
| 31 | FROM `jpemeric_blog`.`post` |
|
| 32 | WHERE `path` = :path AND `category` = :category AND `display` = :is_active |
|
| 33 | LIMIT 1"; |
|
| 34 | $bindings = array( |
|
| 35 | 'path' => $path, |
|
| 36 | 'category' => $category, |
|
| 37 | 'is_active' => 1, |
|
| 38 | ); |
|
| 39 | ||
| 40 | return $this |
|
| 41 | ->connections |
|
| 42 | ->getRead() |
|
| 43 | ->fetchOne($query, $bindings); |
|
| 44 | } |
|
| 45 | } |
|
| 46 | ||
| @@ 7-51 (lines=45) @@ | ||
| 4 | ||
| 5 | use Aura\Sql\ConnectionLocator; |
|
| 6 | ||
| 7 | class MysqlSeriesRepository implements IntroductionRepository |
|
| 8 | { |
|
| 9 | ||
| 10 | /** @var Aura\Sql\ConnectionLocator */ |
|
| 11 | protected $connections; |
|
| 12 | ||
| 13 | /** |
|
| 14 | * @param Aura\Sql\ConnectionLocator |
|
| 15 | */ |
|
| 16 | public function __construct(ConnectionLocator $connections) |
|
| 17 | { |
|
| 18 | $this->connections = $connections; |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @param integer $post |
|
| 23 | * |
|
| 24 | * @return array|false |
|
| 25 | */ |
|
| 26 | public function getSeriesForPost($post) |
|
| 27 | { |
|
| 28 | $query = " |
|
| 29 | SELECT `series`.`title` AS `series_title`, `series`.`description` AS `series_descriptions`, |
|
| 30 | `post.id` AS `post`, `post`.`title`, `post`.`category`, `post`.`path` |
|
| 31 | FROM `jpemeric_blog`.`series` |
|
| 32 | INNER JOIN `jpemeric_blog`.`series_post` ON `series_post`.`series` = `series.`id` |
|
| 33 | INNER JOIN `jpemeric_blog`.`post` ON `post`.`id` = `series_post`.`post` AND |
|
| 34 | `post`.`display` = :is_active |
|
| 35 | WHERE `series`.`id` = ( |
|
| 36 | SELECT `series` |
|
| 37 | FROM `jpemeric_blog`.`series_post` |
|
| 38 | WHERE `post` = :lookup_post |
|
| 39 | LIMIT 1) |
|
| 40 | ORDER BY `series_post`.`order`"; |
|
| 41 | $bindings = [ |
|
| 42 | 'is_active' => 1, |
|
| 43 | 'lookup_post' => $post, |
|
| 44 | ]; |
|
| 45 | ||
| 46 | return $this |
|
| 47 | ->connections() |
|
| 48 | ->getRead() |
|
| 49 | ->fetchAll($query, $bindings); |
|
| 50 | } |
|
| 51 | } |
|
| 52 | ||