@@ -68,17 +68,17 @@ |
||
68 | 68 | return $string; |
69 | 69 | } |
70 | 70 | |
71 | - public function getExcerpt($text, $count=Constant::EXCERPT_WORD_COUNT){ |
|
72 | - if($count < 1){ |
|
71 | + public function getExcerpt($text, $count = Constant::EXCERPT_WORD_COUNT) { |
|
72 | + if ($count < 1) { |
|
73 | 73 | throw new \ErrorException('excerpt length too low'); |
74 | 74 | } |
75 | 75 | |
76 | 76 | $text = str_replace(" ", " ", $text); |
77 | 77 | $string = explode(" ", $text); |
78 | 78 | $trimed = ''; |
79 | - for ( $wordCounter = 0; $wordCounter < $count; $wordCounter++ ){ |
|
79 | + for ($wordCounter = 0; $wordCounter < $count; $wordCounter++) { |
|
80 | 80 | $trimed .= $string[$wordCounter]; |
81 | - if ( $wordCounter < $count-1 ){ $trimed .= " "; } |
|
81 | + if ($wordCounter < $count - 1) { $trimed .= " "; } |
|
82 | 82 | else { $trimed .= "..."; } |
83 | 83 | } |
84 | 84 | $trimed = trim($trimed); |
@@ -78,8 +78,7 @@ |
||
78 | 78 | $trimed = ''; |
79 | 79 | for ( $wordCounter = 0; $wordCounter < $count; $wordCounter++ ){ |
80 | 80 | $trimed .= $string[$wordCounter]; |
81 | - if ( $wordCounter < $count-1 ){ $trimed .= " "; } |
|
82 | - else { $trimed .= "..."; } |
|
81 | + if ( $wordCounter < $count-1 ){ $trimed .= " "; } else { $trimed .= "..."; } |
|
83 | 82 | } |
84 | 83 | $trimed = trim($trimed); |
85 | 84 | return $trimed; |
@@ -22,5 +22,5 @@ |
||
22 | 22 | const FRONT_PAGE_POSTS = 3; |
23 | 23 | const POSTS_PER_PAGE = 10; |
24 | 24 | |
25 | - const EXCERPT_WORD_COUNT =20; |
|
25 | + const EXCERPT_WORD_COUNT = 20; |
|
26 | 26 | } |
27 | 27 | \ No newline at end of file |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | { |
11 | 11 | use StringFunctions; |
12 | 12 | |
13 | - private function getAllPosts(int $offset, int $limit, bool $isFrontPage = false){ |
|
13 | + private function getAllPosts(int $offset, int $limit, bool $isFrontPage = false) { |
|
14 | 14 | $postsTbl = $this->getTablePrefix('posts'); |
15 | 15 | $categoriesTbl = $this->getTablePrefix('categories'); |
16 | 16 | $usersTbl = $this->getTablePrefix('users'); |
@@ -18,16 +18,16 @@ discard block |
||
18 | 18 | $sql = "SELECT title, post_image,article,$postsTbl.last_update, posts_slug, category_name, categories_slug, pseudo as author, idusers |
19 | 19 | FROM $postsTbl INNER JOIN $categoriesTbl ON $postsTbl.categories_idcategories = $categoriesTbl.idcategories |
20 | 20 | INNER JOIN $usersTbl ON $postsTbl.author_iduser = $usersTbl.idusers"; |
21 | - if($isFrontPage){ |
|
21 | + if ($isFrontPage) { |
|
22 | 22 | $sql .= " WHERE on_front_page = 1"; |
23 | 23 | } |
24 | - $sql .=" LIMIT $limit OFFSET $offset"; |
|
24 | + $sql .= " LIMIT $limit OFFSET $offset"; |
|
25 | 25 | $this->query($sql); |
26 | 26 | $this->execute(); |
27 | 27 | $results = $this->fetchAll(); |
28 | - $sendResults= []; |
|
28 | + $sendResults = []; |
|
29 | 29 | //we create the excerpt for the text and add it to the object |
30 | - foreach ($results as $result){ |
|
30 | + foreach ($results as $result) { |
|
31 | 31 | $result->{'excerpt'} = $this->getExcerpt($result->article); |
32 | 32 | $sendResults[] = $result; |
33 | 33 | } |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | return $this->getAllPosts($offset, $limit, true); |
40 | 40 | } |
41 | 41 | |
42 | - public function getPosts(int $offset = 0, int $limit = Constant::POSTS_PER_PAGE){ |
|
42 | + public function getPosts(int $offset = 0, int $limit = Constant::POSTS_PER_PAGE) { |
|
43 | 43 | return $this->getAllPosts($offset, $limit, false); |
44 | 44 | } |
45 | 45 | } |
46 | 46 | \ No newline at end of file |