@@ -17,6 +17,9 @@ |
||
| 17 | 17 | return self::run_row_query($query); |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | + /** |
|
| 21 | + * @param string $date |
|
| 22 | + */ |
|
| 20 | 23 | public static function getTweetByFields($date, $text) |
| 21 | 24 | {
|
| 22 | 25 | $query = "SELECT * FROM `jpemeric_stream`.`twitter` WHERE `date` = '{$date}' && `text` = '{$text}' LIMIT 1";
|
@@ -17,6 +17,9 @@ |
||
| 17 | 17 | return self::run_row_query($query); |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | + /** |
|
| 21 | + * @param string $date |
|
| 22 | + */ |
|
| 20 | 23 | public static function getTweetByFields($date, $text) |
| 21 | 24 | {
|
| 22 | 25 | $query = "SELECT * FROM `jpemeric_stream`.`twitter` WHERE `date` = '{$date}' && `text` = '{$text}' LIMIT 1";
|
@@ -17,6 +17,9 @@ |
||
| 17 | 17 | return self::run_row_query($query); |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | + /** |
|
| 21 | + * @param string $date |
|
| 22 | + */ |
|
| 20 | 23 | public static function getTweetByFields($date, $text) |
| 21 | 24 | {
|
| 22 | 25 | $query = "SELECT * FROM `jpemeric_stream`.`twitter` WHERE `date` = '{$date}' && `text` = '{$text}' LIMIT 1";
|
@@ -55,11 +55,11 @@ |
||
| 55 | 55 | final private function get_list_posts() |
| 56 | 56 | {
|
| 57 | 57 | $post_array = array(); |
| 58 | - foreach($this->get_list_results() as $post) |
|
| 58 | + foreach ($this->get_list_results() as $post) |
|
| 59 | 59 | {
|
| 60 | 60 | $post_array[] = $this->expand_post($post, 'full'); |
| 61 | 61 | } |
| 62 | - if(count($post_array) < 1 && URLDecode::getPiece(1) !== 'search') |
|
| 62 | + if (count($post_array) < 1 && URLDecode::getPiece(1) !== 'search') |
|
| 63 | 63 | $this->eject(); |
| 64 | 64 | return $post_array; |
| 65 | 65 | } |
@@ -59,8 +59,9 @@ |
||
| 59 | 59 | {
|
| 60 | 60 | $post_array[] = $this->expand_post($post, 'full'); |
| 61 | 61 | } |
| 62 | - if(count($post_array) < 1 && URLDecode::getPiece(1) !== 'search') |
|
| 63 | - $this->eject(); |
|
| 62 | + if(count($post_array) < 1 && URLDecode::getPiece(1) !== 'search') {
|
|
| 63 | + $this->eject(); |
|
| 64 | + } |
|
| 64 | 65 | return $post_array; |
| 65 | 66 | } |
| 66 | 67 | |
@@ -12,7 +12,7 @@ |
||
| 12 | 12 | |
| 13 | 13 | public function __construct() |
| 14 | 14 | {
|
| 15 | - global $config; |
|
| 15 | + global $config; |
|
| 16 | 16 | $this->headers['From'] = self::$FROM; |
| 17 | 17 | $this->headers['Reply-To'] = "Jacob <{$config->admin_email}>";
|
| 18 | 18 | $this->headers['Bcc'] = "Jacob <{$config->admin_email}>";
|
@@ -33,16 +33,16 @@ discard block |
||
| 33 | 33 | |
| 34 | 34 | private function process_form() |
| 35 | 35 | {
|
| 36 | - if(!Request::hasPost() || Request::getPost('submit') != 'Send Message!')
|
|
| 36 | + if (!Request::hasPost() || Request::getPost('submit') != 'Send Message!')
|
|
| 37 | 37 | return (object) array('display' => 'normal');
|
| 38 | 38 | |
| 39 | 39 | Loader::load('utility', 'Validate');
|
| 40 | 40 | $error_result = array(); |
| 41 | - if(!Validate::checkRequest('post', 'name', 'string'))
|
|
| 41 | + if (!Validate::checkRequest('post', 'name', 'string'))
|
|
| 42 | 42 | $error_result['name'] = 'please enter your name'; |
| 43 | - if(!Validate::checkRequest('post', 'email', 'string'))
|
|
| 43 | + if (!Validate::checkRequest('post', 'email', 'string'))
|
|
| 44 | 44 | $error_result['email'] = 'please enter a valid email'; |
| 45 | - if(!Validate::checkRequest('post', 'message', 'string'))
|
|
| 45 | + if (!Validate::checkRequest('post', 'message', 'string'))
|
|
| 46 | 46 | $error_result['message'] = 'please write a message'; |
| 47 | 47 | |
| 48 | 48 | $values = (object) array( |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | 'email' => Request::getPost('email'),
|
| 51 | 51 | 'message' => Request::getPost('message'));
|
| 52 | 52 | |
| 53 | - if(count($error_result) > 0) |
|
| 53 | + if (count($error_result) > 0) |
|
| 54 | 54 | {
|
| 55 | 55 | return (object) array( |
| 56 | 56 | 'display' => 'error', |
@@ -33,17 +33,21 @@ |
||
| 33 | 33 | |
| 34 | 34 | private function process_form() |
| 35 | 35 | {
|
| 36 | - if(!Request::hasPost() || Request::getPost('submit') != 'Send Message!')
|
|
| 37 | - return (object) array('display' => 'normal');
|
|
| 36 | + if(!Request::hasPost() || Request::getPost('submit') != 'Send Message!') {
|
|
| 37 | + return (object) array('display' => 'normal');
|
|
| 38 | + } |
|
| 38 | 39 | |
| 39 | 40 | Loader::load('utility', 'Validate');
|
| 40 | 41 | $error_result = array(); |
| 41 | - if(!Validate::checkRequest('post', 'name', 'string'))
|
|
| 42 | - $error_result['name'] = 'please enter your name'; |
|
| 43 | - if(!Validate::checkRequest('post', 'email', 'string'))
|
|
| 44 | - $error_result['email'] = 'please enter a valid email'; |
|
| 45 | - if(!Validate::checkRequest('post', 'message', 'string'))
|
|
| 46 | - $error_result['message'] = 'please write a message'; |
|
| 42 | + if(!Validate::checkRequest('post', 'name', 'string')) {
|
|
| 43 | + $error_result['name'] = 'please enter your name'; |
|
| 44 | + } |
|
| 45 | + if(!Validate::checkRequest('post', 'email', 'string')) {
|
|
| 46 | + $error_result['email'] = 'please enter a valid email'; |
|
| 47 | + } |
|
| 48 | + if(!Validate::checkRequest('post', 'message', 'string')) {
|
|
| 49 | + $error_result['message'] = 'please write a message'; |
|
| 50 | + } |
|
| 47 | 51 | |
| 48 | 52 | $values = (object) array( |
| 49 | 53 | 'name' => Request::getPost('name'),
|
@@ -20,6 +20,6 @@ |
||
| 20 | 20 | ) |
| 21 | 21 | ); |
| 22 | 22 | |
| 23 | -Router::route($redirect,$direct); |
|
| 23 | +Router::route($redirect, $direct); |
|
| 24 | 24 | |
| 25 | 25 | ?> |
| 26 | 26 | \ No newline at end of file |
@@ -13,7 +13,7 @@ |
||
| 13 | 13 | public function __construct() |
| 14 | 14 | { |
| 15 | 15 | $extendedPdo = $this->newExtendedPdo(); |
| 16 | - $this->connections = new ConnectionLocator(function () use ($extendedPdo) { |
|
| 16 | + $this->connections = new ConnectionLocator(function() use ($extendedPdo) { |
|
| 17 | 17 | return $extendedPdo; |
| 18 | 18 | }); |
| 19 | 19 | } |
@@ -7,21 +7,21 @@ discard block |
||
| 7 | 7 | class MysqlPostRepositoryTest extends PHPUnit_Framework_TestCase |
| 8 | 8 | { |
| 9 | 9 | |
| 10 | - protected $connections; |
|
| 11 | - |
|
| 12 | - public function __construct() |
|
| 13 | - { |
|
| 14 | - $extendedPdo = $this->newExtendedPdo(); |
|
| 15 | - $this->connections = new ConnectionLocator(function () use ($extendedPdo) { |
|
| 16 | - return $extendedPdo; |
|
| 17 | - }); |
|
| 18 | - } |
|
| 19 | - |
|
| 20 | - protected function newExtendedPdo() |
|
| 21 | - { |
|
| 22 | - $extendedPdo = new ExtendedPdo('sqlite::memory:'); |
|
| 23 | - $extendedPdo->exec('ATTACH DATABASE `jpemeric_blog.db` AS `jpemeric_blog`'); |
|
| 24 | - $extendedPdo->exec(" |
|
| 10 | + protected $connections; |
|
| 11 | + |
|
| 12 | + public function __construct() |
|
| 13 | + { |
|
| 14 | + $extendedPdo = $this->newExtendedPdo(); |
|
| 15 | + $this->connections = new ConnectionLocator(function () use ($extendedPdo) { |
|
| 16 | + return $extendedPdo; |
|
| 17 | + }); |
|
| 18 | + } |
|
| 19 | + |
|
| 20 | + protected function newExtendedPdo() |
|
| 21 | + { |
|
| 22 | + $extendedPdo = new ExtendedPdo('sqlite::memory:'); |
|
| 23 | + $extendedPdo->exec('ATTACH DATABASE `jpemeric_blog.db` AS `jpemeric_blog`'); |
|
| 24 | + $extendedPdo->exec(" |
|
| 25 | 25 | CREATE TABLE IF NOT EXISTS `jpemeric_blog`.`post` ( |
| 26 | 26 | `id` integer PRIMARY KEY AUTOINCREMENT, |
| 27 | 27 | `title` varchar(60) NOT NULL, |
@@ -31,88 +31,88 @@ discard block |
||
| 31 | 31 | `body` text NOT NULL, |
| 32 | 32 | `display` integer NOT NULL |
| 33 | 33 | )" |
| 34 | - ); |
|
| 35 | - return $extendedPdo; |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - public function newMysqlPostRepository() |
|
| 39 | - { |
|
| 40 | - return new MysqlPostRepository($this->connections); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - public function testConstructSetsConnections() |
|
| 44 | - { |
|
| 45 | - $this->assertAttributeEquals( |
|
| 46 | - $this->connections, |
|
| 47 | - 'connections', |
|
| 48 | - $this->newMysqlPostRepository() |
|
| 49 | - ); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - public function testFindPostByPath() |
|
| 53 | - { |
|
| 54 | - $test_active_post = array( |
|
| 55 | - 'title' => 'test findByPath active', |
|
| 56 | - 'path' => 'test-findbypath-active', |
|
| 57 | - 'category' => 'test-category', |
|
| 58 | - 'date' => (new DateTime())->format('Y-m-d H:i:s'), |
|
| 59 | - 'body' => 'test content', |
|
| 60 | - 'display' => 1 |
|
| 61 | - ); |
|
| 62 | - |
|
| 63 | - $this->connections->getDefault()->perform(" |
|
| 34 | + ); |
|
| 35 | + return $extendedPdo; |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + public function newMysqlPostRepository() |
|
| 39 | + { |
|
| 40 | + return new MysqlPostRepository($this->connections); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + public function testConstructSetsConnections() |
|
| 44 | + { |
|
| 45 | + $this->assertAttributeEquals( |
|
| 46 | + $this->connections, |
|
| 47 | + 'connections', |
|
| 48 | + $this->newMysqlPostRepository() |
|
| 49 | + ); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + public function testFindPostByPath() |
|
| 53 | + { |
|
| 54 | + $test_active_post = array( |
|
| 55 | + 'title' => 'test findByPath active', |
|
| 56 | + 'path' => 'test-findbypath-active', |
|
| 57 | + 'category' => 'test-category', |
|
| 58 | + 'date' => (new DateTime())->format('Y-m-d H:i:s'), |
|
| 59 | + 'body' => 'test content', |
|
| 60 | + 'display' => 1 |
|
| 61 | + ); |
|
| 62 | + |
|
| 63 | + $this->connections->getDefault()->perform(" |
|
| 64 | 64 | INSERT INTO jpemeric_blog.post |
| 65 | 65 | (title, path, category, date, body, display) |
| 66 | 66 | VALUES |
| 67 | 67 | (:title, :path, :category, :date, :body, :display)", |
| 68 | - $test_active_post); |
|
| 69 | - |
|
| 70 | - $active_post = $this->newMysqlPostRepository()->findPostByPath( |
|
| 71 | - $test_active_post['category'], |
|
| 72 | - $test_active_post['path'] |
|
| 73 | - ); |
|
| 74 | - $this->assertSame($test_active_post['title'], $active_post['title']); |
|
| 75 | - |
|
| 76 | - $test_inactive_post = array( |
|
| 77 | - 'title' => 'test findByPath inactive', |
|
| 78 | - 'path' => 'test-findbypath-inactive', |
|
| 79 | - 'category' => 'test-category', |
|
| 80 | - 'date' => (new DateTime())->format('Y-m-d H:i:s'), |
|
| 81 | - 'body' => 'test content', |
|
| 82 | - 'display' => 0 |
|
| 83 | - ); |
|
| 84 | - |
|
| 85 | - $this->connections->getDefault()->perform(" |
|
| 68 | + $test_active_post); |
|
| 69 | + |
|
| 70 | + $active_post = $this->newMysqlPostRepository()->findPostByPath( |
|
| 71 | + $test_active_post['category'], |
|
| 72 | + $test_active_post['path'] |
|
| 73 | + ); |
|
| 74 | + $this->assertSame($test_active_post['title'], $active_post['title']); |
|
| 75 | + |
|
| 76 | + $test_inactive_post = array( |
|
| 77 | + 'title' => 'test findByPath inactive', |
|
| 78 | + 'path' => 'test-findbypath-inactive', |
|
| 79 | + 'category' => 'test-category', |
|
| 80 | + 'date' => (new DateTime())->format('Y-m-d H:i:s'), |
|
| 81 | + 'body' => 'test content', |
|
| 82 | + 'display' => 0 |
|
| 83 | + ); |
|
| 84 | + |
|
| 85 | + $this->connections->getDefault()->perform(" |
|
| 86 | 86 | INSERT INTO jpemeric_blog.post |
| 87 | 87 | (title, path, category, date, body, display) |
| 88 | 88 | VALUES |
| 89 | 89 | (:title, :path, :category, :date, :body, :display)", |
| 90 | - $test_inactive_post); |
|
| 91 | - |
|
| 92 | - $inactive_post = $this->newMysqlPostRepository()->findPostByPath( |
|
| 93 | - $test_inactive_post['category'], |
|
| 94 | - $test_inactive_post['path'] |
|
| 95 | - ); |
|
| 96 | - $this->assertFalse($inactive_post); |
|
| 97 | - |
|
| 98 | - $nonexistant_post = $this->newMysqlPostRepository()->findPostByPath( |
|
| 99 | - 'test-category', |
|
| 100 | - 'test-findbypath-nonexistant' |
|
| 101 | - ); |
|
| 102 | - $this->assertFalse($nonexistant_post); |
|
| 90 | + $test_inactive_post); |
|
| 91 | + |
|
| 92 | + $inactive_post = $this->newMysqlPostRepository()->findPostByPath( |
|
| 93 | + $test_inactive_post['category'], |
|
| 94 | + $test_inactive_post['path'] |
|
| 95 | + ); |
|
| 96 | + $this->assertFalse($inactive_post); |
|
| 97 | + |
|
| 98 | + $nonexistant_post = $this->newMysqlPostRepository()->findPostByPath( |
|
| 99 | + 'test-category', |
|
| 100 | + 'test-findbypath-nonexistant' |
|
| 101 | + ); |
|
| 102 | + $this->assertFalse($nonexistant_post); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - public function testIsInstanceOfPostRepository() |
|
| 106 | - { |
|
| 107 | - $this->assertInstanceOf( |
|
| 108 | - 'Jacobemerick\Web\Domain\Blog\Post\PostRepositoryInterface', |
|
| 109 | - $this->newMysqlPostRepository() |
|
| 110 | - ); |
|
| 111 | - } |
|
| 105 | + public function testIsInstanceOfPostRepository() |
|
| 106 | + { |
|
| 107 | + $this->assertInstanceOf( |
|
| 108 | + 'Jacobemerick\Web\Domain\Blog\Post\PostRepositoryInterface', |
|
| 109 | + $this->newMysqlPostRepository() |
|
| 110 | + ); |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | - public static function tearDownAfterClass() |
|
| 114 | - { |
|
| 113 | + public static function tearDownAfterClass() |
|
| 114 | + { |
|
| 115 | 115 | // $this->connections->getDefault()->disconnect(); |
| 116 | - unlink('jpemeric_blog.db'); |
|
| 117 | - } |
|
| 116 | + unlink('jpemeric_blog.db'); |
|
| 117 | + } |
|
| 118 | 118 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | protected $connections; |
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | - * @param Aura\Sql\ConnectionLocator $connections |
|
| 14 | + * @param ConnectionLocator $connections |
|
| 15 | 15 | */ |
| 16 | 16 | public function __construct(ConnectionLocator $connections) |
| 17 | 17 | { |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | * @param string $category |
| 23 | 23 | * @param string $path |
| 24 | 24 | * |
| 25 | - * @return array|false |
|
| 25 | + * @return boolean |
|
| 26 | 26 | */ |
| 27 | 27 | public function findByPath($category, $path) |
| 28 | 28 | { |
@@ -7,165 +7,165 @@ discard block |
||
| 7 | 7 | class MysqlPostRepository implements PostRepository |
| 8 | 8 | { |
| 9 | 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 = " |
|
| 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 | 30 | SELECT `id`, `title`, `path`, `date`, `body`, `category` |
| 31 | 31 | FROM `jpemeric_blog`.`post` |
| 32 | 32 | WHERE `path` = :path AND `category` = :category AND `display` = :is_active |
| 33 | 33 | LIMIT 1"; |
| 34 | - $bindings = [ |
|
| 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 | - public function getActivePosts($limit = null, $offset = 0) |
|
| 47 | - { |
|
| 48 | - $query = " |
|
| 34 | + $bindings = [ |
|
| 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 | + public function getActivePosts($limit = null, $offset = 0) |
|
| 47 | + { |
|
| 48 | + $query = " |
|
| 49 | 49 | SELECT `id`, `title`, `path`, `date`, `body`, `category` |
| 50 | 50 | FROM `jpemeric_blog`.`post` |
| 51 | 51 | WHERE `display` = :is_active |
| 52 | 52 | ORDER BY `date` DESC"; |
| 53 | - if ($limit != null) { |
|
| 54 | - $query .= " |
|
| 53 | + if ($limit != null) { |
|
| 54 | + $query .= " |
|
| 55 | 55 | LIMIT {$offset}, {$limit}"; |
| 56 | - } |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - $bindings = [ |
|
| 59 | - 'is_active' => 1, |
|
| 60 | - ]; |
|
| 58 | + $bindings = [ |
|
| 59 | + 'is_active' => 1, |
|
| 60 | + ]; |
|
| 61 | 61 | |
| 62 | - return $this |
|
| 63 | - ->connections |
|
| 64 | - ->getRead() |
|
| 65 | - ->fetchAll($query, $bindings); |
|
| 66 | - } |
|
| 62 | + return $this |
|
| 63 | + ->connections |
|
| 64 | + ->getRead() |
|
| 65 | + ->fetchAll($query, $bindings); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - public function getActivePostsCount() |
|
| 69 | - { |
|
| 70 | - $query = " |
|
| 68 | + public function getActivePostsCount() |
|
| 69 | + { |
|
| 70 | + $query = " |
|
| 71 | 71 | SELECT COUNT(1) AS `count` |
| 72 | 72 | FROM `jpemeric_blog`.`post` |
| 73 | 73 | WHERE `display` = :is_active"; |
| 74 | - $bindings = [ |
|
| 75 | - 'is_active' => 1, |
|
| 76 | - ]; |
|
| 77 | - |
|
| 78 | - return $this |
|
| 79 | - ->connections |
|
| 80 | - ->getRead() |
|
| 81 | - ->fetchValue($query, $bindings); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - public function getActivePostsByTag($tag, $limit = null, $offset = 0) |
|
| 85 | - { |
|
| 86 | - $query = " |
|
| 74 | + $bindings = [ |
|
| 75 | + 'is_active' => 1, |
|
| 76 | + ]; |
|
| 77 | + |
|
| 78 | + return $this |
|
| 79 | + ->connections |
|
| 80 | + ->getRead() |
|
| 81 | + ->fetchValue($query, $bindings); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + public function getActivePostsByTag($tag, $limit = null, $offset = 0) |
|
| 85 | + { |
|
| 86 | + $query = " |
|
| 87 | 87 | SELECT `id`, `title`, `path`, `date`, `body`, `category` |
| 88 | 88 | FROM `jpemeric_blog`.`post` |
| 89 | 89 | INNER JOIN `jpemeric_blog`.`ptlink` ON `ptlink`.`post_id` = `post`.`id` AND |
| 90 | 90 | `ptlink`.`tag_id` = :tag_id |
| 91 | 91 | WHERE `display` = :is_active"; |
| 92 | - if ($limit != null) { |
|
| 93 | - $query .= " |
|
| 92 | + if ($limit != null) { |
|
| 93 | + $query .= " |
|
| 94 | 94 | LIMIT {$offset}, {$limit}"; |
| 95 | - } |
|
| 96 | - |
|
| 97 | - $bindings = [ |
|
| 98 | - 'tag_id' => $tag, |
|
| 99 | - 'is_active' => 1, |
|
| 100 | - ]; |
|
| 101 | - |
|
| 102 | - return $this |
|
| 103 | - ->connections |
|
| 104 | - ->getRead() |
|
| 105 | - ->fetchAll($query, $bindings); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - public function getActivePostsCountByTag($tag) |
|
| 109 | - { |
|
| 110 | - $query = " |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + $bindings = [ |
|
| 98 | + 'tag_id' => $tag, |
|
| 99 | + 'is_active' => 1, |
|
| 100 | + ]; |
|
| 101 | + |
|
| 102 | + return $this |
|
| 103 | + ->connections |
|
| 104 | + ->getRead() |
|
| 105 | + ->fetchAll($query, $bindings); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + public function getActivePostsCountByTag($tag) |
|
| 109 | + { |
|
| 110 | + $query = " |
|
| 111 | 111 | SELECT COUNT(1) AS `count` |
| 112 | 112 | FROM `jpemeric_blog`.`post` |
| 113 | 113 | INNER JOIN `jpemeric_blog`.`ptlink` ON `ptlink`.`post_id` = `post`.`id` AND |
| 114 | 114 | `ptlink`.`tag_id` = :tag_id |
| 115 | 115 | WHERE `display` = :is_active"; |
| 116 | - $bindings = [ |
|
| 117 | - 'tag_id' => $tag, |
|
| 118 | - 'is_active' => 1, |
|
| 119 | - ]; |
|
| 120 | - |
|
| 121 | - return $this |
|
| 122 | - ->connections |
|
| 123 | - ->getRead() |
|
| 124 | - ->fetchValue($query, $bindings); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - public function getActivePostsByCategory($category, $limit = null, $offset = 0) |
|
| 128 | - { |
|
| 129 | - $query = " |
|
| 116 | + $bindings = [ |
|
| 117 | + 'tag_id' => $tag, |
|
| 118 | + 'is_active' => 1, |
|
| 119 | + ]; |
|
| 120 | + |
|
| 121 | + return $this |
|
| 122 | + ->connections |
|
| 123 | + ->getRead() |
|
| 124 | + ->fetchValue($query, $bindings); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + public function getActivePostsByCategory($category, $limit = null, $offset = 0) |
|
| 128 | + { |
|
| 129 | + $query = " |
|
| 130 | 130 | SELECT `id`, `title`, `path`, `date`, `body`, `category` |
| 131 | 131 | FROM `jpemeric_blog`.`post` |
| 132 | 132 | WHERE `category` = :category AND `display` = :is_active"; |
| 133 | - if ($limit != null) { |
|
| 134 | - $query .= " |
|
| 133 | + if ($limit != null) { |
|
| 134 | + $query .= " |
|
| 135 | 135 | LIMIT {$offset}, {$limit}"; |
| 136 | - } |
|
| 137 | - |
|
| 138 | - $bindings = [ |
|
| 139 | - 'category' => $category, |
|
| 140 | - 'is_active' => 1, |
|
| 141 | - ]; |
|
| 142 | - |
|
| 143 | - return $this |
|
| 144 | - ->connections |
|
| 145 | - ->getRead() |
|
| 146 | - ->fetchAll($query, $bindings); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - public function getActivePostsCountByCategory($category) |
|
| 150 | - { |
|
| 151 | - $query = " |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + $bindings = [ |
|
| 139 | + 'category' => $category, |
|
| 140 | + 'is_active' => 1, |
|
| 141 | + ]; |
|
| 142 | + |
|
| 143 | + return $this |
|
| 144 | + ->connections |
|
| 145 | + ->getRead() |
|
| 146 | + ->fetchAll($query, $bindings); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + public function getActivePostsCountByCategory($category) |
|
| 150 | + { |
|
| 151 | + $query = " |
|
| 152 | 152 | SELECT COUNT(1) AS `count` |
| 153 | 153 | FROM `jpemeric_blog`.`post` |
| 154 | 154 | WHERE `category` = :category AND `display` = :is_active"; |
| 155 | - $bindings = [ |
|
| 156 | - 'category' => $category, |
|
| 157 | - 'is_active' => 1, |
|
| 158 | - ]; |
|
| 159 | - |
|
| 160 | - return $this |
|
| 161 | - ->connections |
|
| 162 | - ->getRead() |
|
| 163 | - ->fetchValue($query, $bindings); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - public function getActivePostsByRelatedTags($post, $limit = 4) |
|
| 167 | - { |
|
| 168 | - $query = " |
|
| 155 | + $bindings = [ |
|
| 156 | + 'category' => $category, |
|
| 157 | + 'is_active' => 1, |
|
| 158 | + ]; |
|
| 159 | + |
|
| 160 | + return $this |
|
| 161 | + ->connections |
|
| 162 | + ->getRead() |
|
| 163 | + ->fetchValue($query, $bindings); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + public function getActivePostsByRelatedTags($post, $limit = 4) |
|
| 167 | + { |
|
| 168 | + $query = " |
|
| 169 | 169 | SELECT `id`, `title`, `path`, `date`, `body`, `category`, COUNT(1) AS `count` |
| 170 | 170 | FROM `jpemeric_blog`.`post` |
| 171 | 171 | INNER JOIN `jpemeric_blog`.`ptlink` ON `ptlink`.`post_id` = `post`.`id` AND |
@@ -185,14 +185,14 @@ discard block |
||
| 185 | 185 | GROUP BY `id` |
| 186 | 186 | ORDER BY `count` DESC |
| 187 | 187 | LIMIT {$limit}"; |
| 188 | - $bindings = [ |
|
| 189 | - 'post' => $post, |
|
| 190 | - 'is_active' => 1, |
|
| 191 | - ]; |
|
| 192 | - |
|
| 193 | - return $this |
|
| 194 | - ->connections |
|
| 195 | - ->getRead() |
|
| 196 | - ->fetchAll($query, $bindings); |
|
| 197 | - } |
|
| 188 | + $bindings = [ |
|
| 189 | + 'post' => $post, |
|
| 190 | + 'is_active' => 1, |
|
| 191 | + ]; |
|
| 192 | + |
|
| 193 | + return $this |
|
| 194 | + ->connections |
|
| 195 | + ->getRead() |
|
| 196 | + ->fetchAll($query, $bindings); |
|
| 197 | + } |
|
| 198 | 198 | } |
@@ -4,12 +4,12 @@ |
||
| 4 | 4 | |
| 5 | 5 | interface PostRepository |
| 6 | 6 | { |
| 7 | - public function findPostByPath($category, $path); |
|
| 8 | - public function getActivePosts($limit = null, $offset= 0); |
|
| 9 | - public function getActivePostsCount(); |
|
| 10 | - public function getActivePostsByTag($tag, $limit = null, $offset = 0); |
|
| 11 | - public function getActivePostsCountByTag($tag); |
|
| 12 | - public function getActivePostsByCategory($category, $limit = null, $offset = 0); |
|
| 13 | - public function getActivePostsCountByCategory($category); |
|
| 14 | - public function getActivePostsByRelatedTags($post, $limit = 4); |
|
| 7 | + public function findPostByPath($category, $path); |
|
| 8 | + public function getActivePosts($limit = null, $offset= 0); |
|
| 9 | + public function getActivePostsCount(); |
|
| 10 | + public function getActivePostsByTag($tag, $limit = null, $offset = 0); |
|
| 11 | + public function getActivePostsCountByTag($tag); |
|
| 12 | + public function getActivePostsByCategory($category, $limit = null, $offset = 0); |
|
| 13 | + public function getActivePostsCountByCategory($category); |
|
| 14 | + public function getActivePostsByRelatedTags($post, $limit = 4); |
|
| 15 | 15 | } |
@@ -5,7 +5,7 @@ |
||
| 5 | 5 | interface PostRepository |
| 6 | 6 | { |
| 7 | 7 | public function findPostByPath($category, $path); |
| 8 | - public function getActivePosts($limit = null, $offset= 0); |
|
| 8 | + public function getActivePosts($limit = null, $offset = 0); |
|
| 9 | 9 | public function getActivePostsCount(); |
| 10 | 10 | public function getActivePostsByTag($tag, $limit = null, $offset = 0); |
| 11 | 11 | public function getActivePostsCountByTag($tag); |