@@ -75,21 +75,21 @@ |
||
75 | 75 | * @return string the shortend text |
76 | 76 | * @throws \ErrorException |
77 | 77 | */ |
78 | - public function getExcerpt(string $text, int $count=Constant::EXCERPT_WORD_COUNT){ |
|
79 | - if($count < 1){ |
|
78 | + public function getExcerpt(string $text, int $count = Constant::EXCERPT_WORD_COUNT) { |
|
79 | + if ($count < 1) { |
|
80 | 80 | throw new \ErrorException('excerpt length too low'); |
81 | 81 | } |
82 | 82 | |
83 | 83 | $text = str_replace(" ", " ", $text); |
84 | 84 | $string = explode(" ", $text); |
85 | - if(count($string) <= $count){ |
|
85 | + if (count($string) <= $count) { |
|
86 | 86 | return $text; |
87 | 87 | } |
88 | 88 | $trimed = ''; |
89 | - for ( $wordCounter = 0; $wordCounter < $count; $wordCounter++ ){ |
|
89 | + for ($wordCounter = 0; $wordCounter < $count; $wordCounter++) { |
|
90 | 90 | //TODO Take into account the "read more" tag |
91 | 91 | $trimed .= $string[$wordCounter]; |
92 | - if ( $wordCounter < $count-1 ){ $trimed .= " "; } |
|
92 | + if ($wordCounter < $count - 1) { $trimed .= " "; } |
|
93 | 93 | else { $trimed .= "..."; } |
94 | 94 | } |
95 | 95 | $trimed = trim($trimed); |
@@ -89,8 +89,7 @@ |
||
89 | 89 | for ( $wordCounter = 0; $wordCounter < $count; $wordCounter++ ){ |
90 | 90 | //TODO Take into account the "read more" tag |
91 | 91 | $trimed .= $string[$wordCounter]; |
92 | - if ( $wordCounter < $count-1 ){ $trimed .= " "; } |
|
93 | - else { $trimed .= "..."; } |
|
92 | + if ( $wordCounter < $count-1 ){ $trimed .= " "; } else { $trimed .= "..."; } |
|
94 | 93 | } |
95 | 94 | $trimed = trim($trimed); |
96 | 95 | return $trimed; |
@@ -85,10 +85,10 @@ |
||
85 | 85 | |
86 | 86 | $postId = $postModel->newPost($title, $postImage, $idCategory, $article, $idUser, $published, $onFrontpage, $postSlug); |
87 | 87 | |
88 | - echo "<p>new post ID : " . $postId . "</p>"; |
|
88 | + echo "<p>new post ID : ".$postId."</p>"; |
|
89 | 89 | |
90 | 90 | foreach ($posts["tags"] as $tag) { |
91 | - if(isset($tag["id"])){ |
|
91 | + if (isset($tag["id"])) { |
|
92 | 92 | $tagModel->addTagToPost($postId, $tag["id"]); |
93 | 93 | continue; |
94 | 94 | } |
@@ -81,7 +81,7 @@ |
||
81 | 81 | { |
82 | 82 | //if the post already has the tag, do nothing |
83 | 83 | if($this->postHasTag($postId, $tagId)){ |
84 | - return; |
|
84 | + return; |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | $sql = "INSERT INTO $this->tagAssoTbl (post_idposts, tag_idtags) VALUES (:postId, :tagId)"; |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | use Core\Container; |
5 | 5 | use Core\Model; |
6 | 6 | |
7 | -class TagsModel extends Model{ |
|
7 | +class TagsModel extends Model { |
|
8 | 8 | |
9 | 9 | private $tagAssoTbl; |
10 | 10 | private $tagTbl; |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | $this->bind(':tagName', $tagName); |
41 | 41 | $this->execute(); |
42 | 42 | //if no rows, return zero |
43 | - if(!$this->stmt->rowCount() > 0){ |
|
43 | + if (!$this->stmt->rowCount() > 0) { |
|
44 | 44 | return 0; |
45 | 45 | } |
46 | 46 | return $this->stmt->fetchColumn(); |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | public function addTagToPost(int $postId, int $tagId) |
81 | 81 | { |
82 | 82 | //if the post already has the tag, do nothing |
83 | - if($this->postHasTag($postId, $tagId)){ |
|
83 | + if ($this->postHasTag($postId, $tagId)) { |
|
84 | 84 | return; |
85 | 85 | } |
86 | 86 | |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | { |
102 | 102 | //check if tag doesn't already exist |
103 | 103 | $tagId = $this->getTagId($tag); |
104 | - if($tagId === 0){ |
|
104 | + if ($tagId === 0) { |
|
105 | 105 | $tagId = $this->createNewTag($tag); |
106 | 106 | } |
107 | 107 | $this->addTagToPost($postId, $tagId); |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | public function removeTagFromPost(int $postId, int $tagId) |
117 | 117 | { |
118 | 118 | //if the tag isn't present, do nothing |
119 | - if(!$this->postHasTag($postId, $tagId)){ |
|
119 | + if (!$this->postHasTag($postId, $tagId)) { |
|
120 | 120 | return; |
121 | 121 | } |
122 | 122 |