@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | */ |
| 50 | 50 | public function getPage($pageId) |
| 51 | 51 | { |
| 52 | - return $this->pageMapper->select(['page_id' => $pageId])->current(); |
|
| 52 | + return $this->pageMapper->select([ 'page_id' => $pageId ])->current(); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | /** |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | */ |
| 68 | 68 | public function getHomepage() |
| 69 | 69 | { |
| 70 | - return $this->pageMapper->select(['is_homepage' => true])->current(); |
|
| 70 | + return $this->pageMapper->select([ 'is_homepage' => true ])->current(); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /** |
@@ -85,13 +85,13 @@ discard block |
||
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | $data = $filter->getValues() |
| 88 | - + ['main_img' => $this->upload->uploadImage($data, 'main_img')]; |
|
| 89 | - $data['page_id'] = Uuid::uuid1()->toString(); |
|
| 90 | - $data['page_uuid'] |
|
| 91 | - = (new MysqlUuid($data['page_id']))->toFormat(new Binary); |
|
| 88 | + + [ 'main_img' => $this->upload->uploadImage($data, 'main_img') ]; |
|
| 89 | + $data[ 'page_id' ] = Uuid::uuid1()->toString(); |
|
| 90 | + $data[ 'page_uuid' ] |
|
| 91 | + = (new MysqlUuid($data[ 'page_id' ]))->toFormat(new Binary); |
|
| 92 | 92 | |
| 93 | - if ($data['is_homepage']) { |
|
| 94 | - $this->pageMapper->update(['is_homepage' => false]); |
|
| 93 | + if ($data[ 'is_homepage' ]) { |
|
| 94 | + $this->pageMapper->update([ 'is_homepage' => false ]); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | return $this->pageMapper->insert($data); |
@@ -110,21 +110,21 @@ discard block |
||
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | $data = $filter->getValues() |
| 113 | - + ['main_img' => $this->upload->uploadImage($data, 'main_img')]; |
|
| 113 | + + [ 'main_img' => $this->upload->uploadImage($data, 'main_img') ]; |
|
| 114 | 114 | |
| 115 | 115 | // We don't want to force user to re-upload image on edit |
| 116 | - if (!$data['main_img']) { |
|
| 117 | - unset($data['main_img']); |
|
| 116 | + if (!$data[ 'main_img' ]) { |
|
| 117 | + unset($data[ 'main_img' ]); |
|
| 118 | 118 | } |
| 119 | 119 | else { |
| 120 | 120 | $this->upload->deleteFile($page->getMainImg()); |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - if ($data['is_homepage']) { |
|
| 124 | - $this->pageMapper->update(['is_homepage' => false]); |
|
| 123 | + if ($data[ 'is_homepage' ]) { |
|
| 124 | + $this->pageMapper->update([ 'is_homepage' => false ]); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | - return $this->pageMapper->update($data, ['page_id' => $pageId]); |
|
| 127 | + return $this->pageMapper->update($data, [ 'page_id' => $pageId ]); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | public function delete($pageId) |
@@ -135,6 +135,6 @@ discard block |
||
| 135 | 135 | |
| 136 | 136 | $this->upload->deleteFile($page->getMainImg()); |
| 137 | 137 | |
| 138 | - return (bool)$this->pageMapper->delete(['page_id' => $pageId]); |
|
| 138 | + return (bool) $this->pageMapper->delete([ 'page_id' => $pageId ]); |
|
| 139 | 139 | } |
| 140 | 140 | } |
| 141 | 141 | \ No newline at end of file |
@@ -115,8 +115,7 @@ |
||
| 115 | 115 | // We don't want to force user to re-upload image on edit |
| 116 | 116 | if (!$data['main_img']) { |
| 117 | 117 | unset($data['main_img']); |
| 118 | - } |
|
| 119 | - else { |
|
| 118 | + } else { |
|
| 120 | 119 | $this->upload->deleteFile($page->getMainImg()); |
| 121 | 120 | } |
| 122 | 121 | |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types=1); |
|
| 3 | +declare(strict_types = 1); |
|
| 4 | 4 | |
| 5 | 5 | namespace Core\Service; |
| 6 | 6 | |
@@ -65,17 +65,17 @@ discard block |
||
| 65 | 65 | */ |
| 66 | 66 | public function loginUser($email, $password) |
| 67 | 67 | { |
| 68 | - if(!$email || !$password) { |
|
| 68 | + if (!$email || !$password) { |
|
| 69 | 69 | throw new \Exception('Both email and password are required.', 400); |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | $user = $this->adminUsersMapper->getByEmail($email); |
| 73 | 73 | |
| 74 | - if(!$user) { |
|
| 74 | + if (!$user) { |
|
| 75 | 75 | throw new \Exception('User does not exist.'); |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - if(!$this->crypt->verify($password, $user->password)) { |
|
| 78 | + if (!$this->crypt->verify($password, $user->password)) { |
|
| 79 | 79 | throw new \Exception('Password does not match.'); |
| 80 | 80 | } |
| 81 | 81 | |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | { |
| 120 | 120 | $filter = $this->adminUserFilter->getInputFilter()->setData($data); |
| 121 | 121 | |
| 122 | - if(!$filter->isValid()) { |
|
| 122 | + if (!$filter->isValid()) { |
|
| 123 | 123 | throw new FilterException($filter->getMessages()); |
| 124 | 124 | } |
| 125 | 125 | |
@@ -128,10 +128,10 @@ discard block |
||
| 128 | 128 | 'profile_img' => $this->upload->uploadImage($data, 'profile_img') |
| 129 | 129 | ]; |
| 130 | 130 | |
| 131 | - unset($data['confirm_password']); |
|
| 132 | - $data['password'] = $this->crypt->create($data['password']); |
|
| 133 | - $data['admin_user_id'] = Uuid::uuid1()->toString(); |
|
| 134 | - $data['admin_user_uuid'] = (new MysqlUuid($data['admin_user_id']))->toFormat(new Binary); |
|
| 131 | + unset($data[ 'confirm_password' ]); |
|
| 132 | + $data[ 'password' ] = $this->crypt->create($data[ 'password' ]); |
|
| 133 | + $data[ 'admin_user_id' ] = Uuid::uuid1()->toString(); |
|
| 134 | + $data[ 'admin_user_uuid' ] = (new MysqlUuid($data[ 'admin_user_id' ]))->toFormat(new Binary); |
|
| 135 | 135 | |
| 136 | 136 | return $this->adminUsersMapper->insert($data); |
| 137 | 137 | } |
@@ -145,17 +145,17 @@ discard block |
||
| 145 | 145 | $filter = $this->adminUserFilter->getInputFilter()->setData($data); |
| 146 | 146 | |
| 147 | 147 | // we dont want to force user to enter the password again |
| 148 | - if($data['password'] == '') { |
|
| 148 | + if ($data[ 'password' ] == '') { |
|
| 149 | 149 | $filter->remove('password'); |
| 150 | 150 | $filter->remove('confirm_password'); |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | // if we want to keep same email |
| 154 | - if($user->email == $data['email']) { |
|
| 154 | + if ($user->email == $data[ 'email' ]) { |
|
| 155 | 155 | $filter->remove('email'); |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | - if(!$filter->isValid()) { |
|
| 158 | + if (!$filter->isValid()) { |
|
| 159 | 159 | throw new FilterException($filter->getMessages()); |
| 160 | 160 | } |
| 161 | 161 | |
@@ -165,26 +165,26 @@ discard block |
||
| 165 | 165 | ]; |
| 166 | 166 | |
| 167 | 167 | // We don't want to force user to re-upload image on edit |
| 168 | - if(!$data['face_img']) { |
|
| 169 | - unset($data['face_img']); |
|
| 168 | + if (!$data[ 'face_img' ]) { |
|
| 169 | + unset($data[ 'face_img' ]); |
|
| 170 | 170 | } |
| 171 | - else{ |
|
| 171 | + else { |
|
| 172 | 172 | $this->upload->deleteFile($user->face_img); |
| 173 | 173 | } |
| 174 | 174 | |
| 175 | - if(!$data['profile_img']) { |
|
| 176 | - unset($data['profile_img']); |
|
| 175 | + if (!$data[ 'profile_img' ]) { |
|
| 176 | + unset($data[ 'profile_img' ]); |
|
| 177 | 177 | } |
| 178 | - else{ |
|
| 178 | + else { |
|
| 179 | 179 | $this->upload->deleteFile($user->profile_img); |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | - if(isset($data['password'])) { |
|
| 183 | - unset($data['confirm_password']); |
|
| 184 | - $data['password'] = $this->crypt->create($data['password']); |
|
| 182 | + if (isset($data[ 'password' ])) { |
|
| 183 | + unset($data[ 'confirm_password' ]); |
|
| 184 | + $data[ 'password' ] = $this->crypt->create($data[ 'password' ]); |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | - return $this->adminUsersMapper->update($data, ['admin_user_id' => $userId]); |
|
| 187 | + return $this->adminUsersMapper->update($data, [ 'admin_user_id' => $userId ]); |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | /** |
@@ -196,14 +196,14 @@ discard block |
||
| 196 | 196 | */ |
| 197 | 197 | public function delete($userId) |
| 198 | 198 | { |
| 199 | - if(!($adminUser = $this->getUser($userId))){ |
|
| 199 | + if (!($adminUser = $this->getUser($userId))) { |
|
| 200 | 200 | throw new \Exception('Admin user not found.'); |
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | $this->upload->deleteFile($adminUser->face_img); |
| 204 | 204 | $this->upload->deleteFile($adminUser->profile_img); |
| 205 | 205 | |
| 206 | - return (bool)$this->adminUsersMapper->delete(['admin_user_id' => $userId]); |
|
| 206 | + return (bool) $this->adminUsersMapper->delete([ 'admin_user_id' => $userId ]); |
|
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | /** |
@@ -167,15 +167,13 @@ |
||
| 167 | 167 | // We don't want to force user to re-upload image on edit |
| 168 | 168 | if(!$data['face_img']) { |
| 169 | 169 | unset($data['face_img']); |
| 170 | - } |
|
| 171 | - else{ |
|
| 170 | + } else{ |
|
| 172 | 171 | $this->upload->deleteFile($user->face_img); |
| 173 | 172 | } |
| 174 | 173 | |
| 175 | 174 | if(!$data['profile_img']) { |
| 176 | 175 | unset($data['profile_img']); |
| 177 | - } |
|
| 178 | - else{ |
|
| 176 | + } else{ |
|
| 179 | 177 | $this->upload->deleteFile($user->profile_img); |
| 180 | 178 | } |
| 181 | 179 | |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | |
| 4 | 4 | namespace Category\Service; |
| 5 | 5 | |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | */ |
| 77 | 77 | public function getCategoryBySlug($urlSlug) |
| 78 | 78 | { |
| 79 | - return $this->categoryMapper->select(['slug' => $urlSlug])->current(); |
|
| 79 | + return $this->categoryMapper->select([ 'slug' => $urlSlug ])->current(); |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | /** |
@@ -89,14 +89,14 @@ discard block |
||
| 89 | 89 | { |
| 90 | 90 | $filter = $this->categoryFilter->getInputFilter()->setData($data); |
| 91 | 91 | |
| 92 | - if(!$filter->isValid()) { |
|
| 92 | + if (!$filter->isValid()) { |
|
| 93 | 93 | throw new FilterException($filter->getMessages()); |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | $values = $filter->getValues(); |
| 97 | - $values['category_id'] = Uuid::uuid1()->toString(); |
|
| 98 | - $values['category_uuid'] = (new MysqlUuid($values['category_id']))->toFormat(new Binary); |
|
| 99 | - $values['main_img'] = $this->upload->uploadImage($data, 'main_img'); |
|
| 97 | + $values[ 'category_id' ] = Uuid::uuid1()->toString(); |
|
| 98 | + $values[ 'category_uuid' ] = (new MysqlUuid($values[ 'category_id' ]))->toFormat(new Binary); |
|
| 99 | + $values[ 'main_img' ] = $this->upload->uploadImage($data, 'main_img'); |
|
| 100 | 100 | |
| 101 | 101 | $this->categoryMapper->insert($values); |
| 102 | 102 | } |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | |
| 118 | 118 | $filter = $this->categoryFilter->getInputFilter()->setData($data); |
| 119 | 119 | |
| 120 | - if(!$filter->isValid()) { |
|
| 120 | + if (!$filter->isValid()) { |
|
| 121 | 121 | throw new FilterException($filter->getMessages()); |
| 122 | 122 | } |
| 123 | 123 | |
@@ -126,14 +126,14 @@ discard block |
||
| 126 | 126 | ]; |
| 127 | 127 | |
| 128 | 128 | // We don't want to force user to re-upload image on edit |
| 129 | - if(!$values['main_img']) { |
|
| 130 | - unset($values['main_img']); |
|
| 129 | + if (!$values[ 'main_img' ]) { |
|
| 130 | + unset($values[ 'main_img' ]); |
|
| 131 | 131 | } |
| 132 | - else{ |
|
| 132 | + else { |
|
| 133 | 133 | $this->upload->deleteFile($oldCategory->main_img); |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - $this->categoryMapper->update($values, ['category_id' => $categoryId]); |
|
| 136 | + $this->categoryMapper->update($values, [ 'category_id' => $categoryId ]); |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | /** |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | |
| 149 | 149 | $this->upload->deleteFile($category->main_img); |
| 150 | 150 | |
| 151 | - return (bool)$this->categoryMapper->delete(['category_id' => $categoryId]); |
|
| 151 | + return (bool) $this->categoryMapper->delete([ 'category_id' => $categoryId ]); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | /** |
@@ -172,10 +172,10 @@ discard block |
||
| 172 | 172 | { |
| 173 | 173 | $categories = $this->categoryMapper->getWeb(7, null, $inHomepage, $inCategoryList)->toArray(); |
| 174 | 174 | |
| 175 | - foreach($categories as $ctn => $category) { |
|
| 176 | - $select = $this->categoryMapper->getCategoryPostsSelect($category['category_id'], 4); |
|
| 175 | + foreach ($categories as $ctn => $category) { |
|
| 176 | + $select = $this->categoryMapper->getCategoryPostsSelect($category[ 'category_id' ], 4); |
|
| 177 | 177 | $posts = $this->categoryMapper->selectWith($select)->toArray(); |
| 178 | - $categories[$ctn]['posts'] = $posts; |
|
| 178 | + $categories[ $ctn ][ 'posts' ] = $posts; |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | return $categories; |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | */ |
| 190 | 190 | public function getCategories($inCategoryList = null) |
| 191 | 191 | { |
| 192 | - return $this->categoryMapper->getWeb(null, ['name' => 'asc'], null, $inCategoryList); |
|
| 192 | + return $this->categoryMapper->getWeb(null, [ 'name' => 'asc' ], null, $inCategoryList); |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | /** |
@@ -128,8 +128,7 @@ |
||
| 128 | 128 | // We don't want to force user to re-upload image on edit |
| 129 | 129 | if(!$values['main_img']) { |
| 130 | 130 | unset($values['main_img']); |
| 131 | - } |
|
| 132 | - else{ |
|
| 131 | + } else{ |
|
| 133 | 132 | $this->upload->deleteFile($oldCategory->main_img); |
| 134 | 133 | } |
| 135 | 134 | |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | $articleFilter = $this->articleFilter->getInputFilter()->setData($data); |
| 88 | 88 | $eventFilter = $this->eventFilter->getInputFilter()->setData($data); |
| 89 | 89 | |
| 90 | - if(!$articleFilter->isValid() || !$eventFilter->isValid()) { |
|
| 90 | + if (!$articleFilter->isValid() || !$eventFilter->isValid()) { |
|
| 91 | 91 | throw new FilterException($articleFilter->getMessages() + $eventFilter->getMessages()); |
| 92 | 92 | } |
| 93 | 93 | |
@@ -96,15 +96,15 @@ discard block |
||
| 96 | 96 | |
| 97 | 97 | $article = $articleFilter->getValues(); |
| 98 | 98 | $article += [ |
| 99 | - 'admin_user_uuid' => $this->adminUsersMapper->getUuid($article['admin_user_id']), |
|
| 99 | + 'admin_user_uuid' => $this->adminUsersMapper->getUuid($article[ 'admin_user_id' ]), |
|
| 100 | 100 | 'type' => ArticleType::EVENT, |
| 101 | 101 | 'article_id' => $id, |
| 102 | 102 | 'article_uuid' => $uuId |
| 103 | 103 | ]; |
| 104 | - unset($article['admin_user_id']); |
|
| 104 | + unset($article[ 'admin_user_id' ]); |
|
| 105 | 105 | |
| 106 | - $article['category_uuid'] = $this->categoryMapper->get($article['category_id'])->category_uuid; |
|
| 107 | - unset($article['category_id']); |
|
| 106 | + $article[ 'category_uuid' ] = $this->categoryMapper->get($article[ 'category_id' ])->category_uuid; |
|
| 107 | + unset($article[ 'category_id' ]); |
|
| 108 | 108 | |
| 109 | 109 | $event = $eventFilter->getValues() + [ |
| 110 | 110 | 'featured_img' => $this->upload->uploadImage($data, 'featured_img'), |
@@ -122,50 +122,50 @@ discard block |
||
| 122 | 122 | $articleFilter = $this->articleFilter->getInputFilter()->setData($data); |
| 123 | 123 | $eventFilter = $this->eventFilter->getInputFilter()->setData($data); |
| 124 | 124 | |
| 125 | - if(!$articleFilter->isValid() || !$eventFilter->isValid()) { |
|
| 125 | + if (!$articleFilter->isValid() || !$eventFilter->isValid()) { |
|
| 126 | 126 | throw new FilterException($articleFilter->getMessages() + $eventFilter->getMessages()); |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | - $article = $articleFilter->getValues() + ['article_uuid' => $oldArticle->article_uuid]; |
|
| 129 | + $article = $articleFilter->getValues() + [ 'article_uuid' => $oldArticle->article_uuid ]; |
|
| 130 | 130 | $event = $eventFilter->getValues() + [ |
| 131 | 131 | 'featured_img' => $this->upload->uploadImage($data, 'featured_img'), |
| 132 | 132 | 'main_img' => $this->upload->uploadImage($data, 'main_img') |
| 133 | 133 | ]; |
| 134 | 134 | |
| 135 | - $article['admin_user_uuid'] = $this->adminUsersMapper->getUuid($article['admin_user_id']); |
|
| 136 | - $article['category_uuid'] = $this->categoryMapper->get($article['category_id'])->category_uuid; |
|
| 137 | - unset($article['category_id'], $article['admin_user_id']); |
|
| 135 | + $article[ 'admin_user_uuid' ] = $this->adminUsersMapper->getUuid($article[ 'admin_user_id' ]); |
|
| 136 | + $article[ 'category_uuid' ] = $this->categoryMapper->get($article[ 'category_id' ])->category_uuid; |
|
| 137 | + unset($article[ 'category_id' ], $article[ 'admin_user_id' ]); |
|
| 138 | 138 | |
| 139 | 139 | // We don't want to force user to re-upload image on edit |
| 140 | - if (!$event['featured_img']) { |
|
| 141 | - unset($event['featured_img']); |
|
| 140 | + if (!$event[ 'featured_img' ]) { |
|
| 141 | + unset($event[ 'featured_img' ]); |
|
| 142 | 142 | } |
| 143 | 143 | else { |
| 144 | 144 | $this->upload->deleteFile($oldArticle->featured_img); |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | - if (!$event['main_img']) { |
|
| 148 | - unset($event['main_img']); |
|
| 147 | + if (!$event[ 'main_img' ]) { |
|
| 148 | + unset($event[ 'main_img' ]); |
|
| 149 | 149 | } |
| 150 | 150 | else { |
| 151 | 151 | $this->upload->deleteFile($oldArticle->main_img); |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | - $this->articleMapper->update($article, ['article_uuid' => $article['article_uuid']]); |
|
| 155 | - $this->articleEventsMapper->update($event, ['article_uuid' => $article['article_uuid']]); |
|
| 154 | + $this->articleMapper->update($article, [ 'article_uuid' => $article[ 'article_uuid' ] ]); |
|
| 155 | + $this->articleEventsMapper->update($event, [ 'article_uuid' => $article[ 'article_uuid' ] ]); |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | public function deleteArticle($id) |
| 159 | 159 | { |
| 160 | 160 | $event = $this->articleEventsMapper->get($id); |
| 161 | 161 | |
| 162 | - if(!$event) { |
|
| 162 | + if (!$event) { |
|
| 163 | 163 | throw new \Exception('Article not found!'); |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | $this->upload->deleteFile($event->main_img); |
| 167 | 167 | $this->upload->deleteFile($event->featured_img); |
| 168 | - $this->articleEventsMapper->delete(['article_uuid' => $event->article_uuid]); |
|
| 168 | + $this->articleEventsMapper->delete([ 'article_uuid' => $event->article_uuid ]); |
|
| 169 | 169 | $this->delete($event->article_uuid); |
| 170 | 170 | } |
| 171 | 171 | |
@@ -139,15 +139,13 @@ |
||
| 139 | 139 | // We don't want to force user to re-upload image on edit |
| 140 | 140 | if (!$event['featured_img']) { |
| 141 | 141 | unset($event['featured_img']); |
| 142 | - } |
|
| 143 | - else { |
|
| 142 | + } else { |
|
| 144 | 143 | $this->upload->deleteFile($oldArticle->featured_img); |
| 145 | 144 | } |
| 146 | 145 | |
| 147 | 146 | if (!$event['main_img']) { |
| 148 | 147 | unset($event['main_img']); |
| 149 | - } |
|
| 150 | - else { |
|
| 148 | + } else { |
|
| 151 | 149 | $this->upload->deleteFile($oldArticle->main_img); |
| 152 | 150 | } |
| 153 | 151 | |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types=1); |
|
| 3 | +declare(strict_types = 1); |
|
| 4 | 4 | |
| 5 | 5 | namespace Article\Service; |
| 6 | 6 | |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | $articleFilter = $this->articleFilter->getInputFilter()->setData($data); |
| 96 | 96 | $postFilter = $this->postFilter->getInputFilter()->setData($data); |
| 97 | 97 | |
| 98 | - if(!$articleFilter->isValid() || !$postFilter->isValid()) { |
|
| 98 | + if (!$articleFilter->isValid() || !$postFilter->isValid()) { |
|
| 99 | 99 | throw new FilterException($articleFilter->getMessages() + $postFilter->getMessages()); |
| 100 | 100 | } |
| 101 | 101 | |
@@ -104,19 +104,19 @@ discard block |
||
| 104 | 104 | |
| 105 | 105 | $article = $articleFilter->getValues(); |
| 106 | 106 | $article += [ |
| 107 | - 'admin_user_uuid' => $this->adminUsersMapper->getUuid($article['admin_user_id']), |
|
| 107 | + 'admin_user_uuid' => $this->adminUsersMapper->getUuid($article[ 'admin_user_id' ]), |
|
| 108 | 108 | 'type' => ArticleType::POST, |
| 109 | 109 | 'article_id' => $id, |
| 110 | 110 | 'article_uuid' => $uuId |
| 111 | 111 | ]; |
| 112 | 112 | |
| 113 | - $article['category_uuid'] = $this->categoryMapper->get($article['category_id'])->category_uuid; |
|
| 114 | - unset($article['category_id'], $article['admin_user_id']); |
|
| 113 | + $article[ 'category_uuid' ] = $this->categoryMapper->get($article[ 'category_id' ])->category_uuid; |
|
| 114 | + unset($article[ 'category_id' ], $article[ 'admin_user_id' ]); |
|
| 115 | 115 | |
| 116 | 116 | $post = $postFilter->getValues() + [ |
| 117 | 117 | 'featured_img' => $this->upload->uploadImage($data, 'featured_img'), |
| 118 | 118 | 'main_img' => $this->upload->uploadImage($data, 'main_img'), |
| 119 | - 'article_uuid' => $article['article_uuid'] |
|
| 119 | + 'article_uuid' => $article[ 'article_uuid' ] |
|
| 120 | 120 | ]; |
| 121 | 121 | |
| 122 | 122 | $this->articleMapper->insert($article); |
@@ -129,37 +129,37 @@ discard block |
||
| 129 | 129 | $articleFilter = $this->articleFilter->getInputFilter()->setData($data); |
| 130 | 130 | $postFilter = $this->postFilter->getInputFilter()->setData($data); |
| 131 | 131 | |
| 132 | - if(!$articleFilter->isValid() || !$postFilter->isValid()) { |
|
| 132 | + if (!$articleFilter->isValid() || !$postFilter->isValid()) { |
|
| 133 | 133 | throw new FilterException($articleFilter->getMessages() + $postFilter->getMessages()); |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - $article = $articleFilter->getValues() + ['article_uuid' => $oldArticle->article_uuid]; |
|
| 136 | + $article = $articleFilter->getValues() + [ 'article_uuid' => $oldArticle->article_uuid ]; |
|
| 137 | 137 | $post = $postFilter->getValues() + [ |
| 138 | 138 | 'featured_img' => $this->upload->uploadImage($data, 'featured_img'), |
| 139 | 139 | 'main_img' => $this->upload->uploadImage($data, 'main_img') |
| 140 | 140 | ]; |
| 141 | 141 | |
| 142 | - $article['admin_user_uuid'] = $this->adminUsersMapper->getUuid($article['admin_user_id']); |
|
| 143 | - $article['category_uuid'] = $this->categoryMapper->get($article['category_id'])->category_uuid; |
|
| 144 | - unset($article['category_id'], $article['admin_user_id']); |
|
| 142 | + $article[ 'admin_user_uuid' ] = $this->adminUsersMapper->getUuid($article[ 'admin_user_id' ]); |
|
| 143 | + $article[ 'category_uuid' ] = $this->categoryMapper->get($article[ 'category_id' ])->category_uuid; |
|
| 144 | + unset($article[ 'category_id' ], $article[ 'admin_user_id' ]); |
|
| 145 | 145 | |
| 146 | 146 | // We don't want to force user to re-upload image on edit |
| 147 | - if (!$post['featured_img']) { |
|
| 148 | - unset($post['featured_img']); |
|
| 147 | + if (!$post[ 'featured_img' ]) { |
|
| 148 | + unset($post[ 'featured_img' ]); |
|
| 149 | 149 | } |
| 150 | 150 | else { |
| 151 | 151 | $this->upload->deleteFile($oldArticle->featured_img); |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | - if (!$post['main_img']) { |
|
| 155 | - unset($post['main_img']); |
|
| 154 | + if (!$post[ 'main_img' ]) { |
|
| 155 | + unset($post[ 'main_img' ]); |
|
| 156 | 156 | } |
| 157 | 157 | else { |
| 158 | 158 | $this->upload->deleteFile($oldArticle->main_img); |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - $this->articleMapper->update($article, ['article_uuid' => $article['article_uuid']]); |
|
| 162 | - $this->articlePostsMapper->update($post, ['article_uuid' => $article['article_uuid']]); |
|
| 161 | + $this->articleMapper->update($article, [ 'article_uuid' => $article[ 'article_uuid' ] ]); |
|
| 162 | + $this->articlePostsMapper->update($post, [ 'article_uuid' => $article[ 'article_uuid' ] ]); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | public function deleteArticle($id) |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | |
| 173 | 173 | $this->upload->deleteFile($post->main_img); |
| 174 | 174 | $this->upload->deleteFile($post->featured_img); |
| 175 | - $this->articlePostsMapper->delete(['article_uuid' => $post->article_uuid]); |
|
| 175 | + $this->articlePostsMapper->delete([ 'article_uuid' => $post->article_uuid ]); |
|
| 176 | 176 | $this->delete($post->article_uuid); |
| 177 | 177 | } |
| 178 | 178 | |
@@ -146,15 +146,13 @@ |
||
| 146 | 146 | // We don't want to force user to re-upload image on edit |
| 147 | 147 | if (!$post['featured_img']) { |
| 148 | 148 | unset($post['featured_img']); |
| 149 | - } |
|
| 150 | - else { |
|
| 149 | + } else { |
|
| 151 | 150 | $this->upload->deleteFile($oldArticle->featured_img); |
| 152 | 151 | } |
| 153 | 152 | |
| 154 | 153 | if (!$post['main_img']) { |
| 155 | 154 | unset($post['main_img']); |
| 156 | - } |
|
| 157 | - else { |
|
| 155 | + } else { |
|
| 158 | 156 | $this->upload->deleteFile($oldArticle->main_img); |
| 159 | 157 | } |
| 160 | 158 | |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types=1); |
|
| 3 | +declare(strict_types = 1); |
|
| 4 | 4 | |
| 5 | 5 | namespace Article\Service; |
| 6 | 6 | |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | $articleFilter = $this->articleFilter->getInputFilter()->setData($data); |
| 107 | 107 | $videosFilter = $this->videosFilter->getInputFilter()->setData($data); |
| 108 | 108 | |
| 109 | - if(!$articleFilter->isValid() || !$videosFilter->isValid()) { |
|
| 109 | + if (!$articleFilter->isValid() || !$videosFilter->isValid()) { |
|
| 110 | 110 | throw new FilterException($articleFilter->getMessages() + $videosFilter->getMessages()); |
| 111 | 111 | } |
| 112 | 112 | |
@@ -115,14 +115,14 @@ discard block |
||
| 115 | 115 | |
| 116 | 116 | $article = $articleFilter->getValues(); |
| 117 | 117 | $article += [ |
| 118 | - 'admin_user_uuid' => $this->adminUsersMapper->getUuid($article['admin_user_id']), |
|
| 118 | + 'admin_user_uuid' => $this->adminUsersMapper->getUuid($article[ 'admin_user_id' ]), |
|
| 119 | 119 | 'type' => ArticleType::VIDEO, |
| 120 | 120 | 'article_id' => $id, |
| 121 | 121 | 'article_uuid' => $uuId |
| 122 | 122 | ]; |
| 123 | 123 | |
| 124 | - $article['category_uuid'] = $this->categoryMapper->get($article['category_id'])->category_uuid; |
|
| 125 | - unset($article['category_id'], $article['admin_user_id']); |
|
| 124 | + $article[ 'category_uuid' ] = $this->categoryMapper->get($article[ 'category_id' ])->category_uuid; |
|
| 125 | + unset($article[ 'category_id' ], $article[ 'admin_user_id' ]); |
|
| 126 | 126 | |
| 127 | 127 | $videos = $videosFilter->getValues() + [ |
| 128 | 128 | 'featured_img' => $this->upload->uploadImage($data, 'featured_img'), |
@@ -140,15 +140,15 @@ discard block |
||
| 140 | 140 | $articleFilter = $this->articleFilter->getInputFilter()->setData($data); |
| 141 | 141 | $videosFilter = $this->videosFilter->getInputFilter()->setData($data); |
| 142 | 142 | |
| 143 | - if(!$articleFilter->isValid() || !$videosFilter->isValid()) { |
|
| 143 | + if (!$articleFilter->isValid() || !$videosFilter->isValid()) { |
|
| 144 | 144 | throw new FilterException($articleFilter->getMessages() + $videosFilter->getMessages()); |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | - $article = $articleFilter->getValues() + ['article_uuid' => $oldArticle->article_uuid]; |
|
| 148 | - $article['category_uuid'] = $this->categoryMapper->get($article['category_id'])->category_uuid; |
|
| 149 | - $article['admin_user_uuid'] = $this->adminUsersMapper->getUuid($article['admin_user_id']); |
|
| 150 | - unset($article['category_id']); |
|
| 151 | - unset($article['admin_user_id']); |
|
| 147 | + $article = $articleFilter->getValues() + [ 'article_uuid' => $oldArticle->article_uuid ]; |
|
| 148 | + $article[ 'category_uuid' ] = $this->categoryMapper->get($article[ 'category_id' ])->category_uuid; |
|
| 149 | + $article[ 'admin_user_uuid' ] = $this->adminUsersMapper->getUuid($article[ 'admin_user_id' ]); |
|
| 150 | + unset($article[ 'category_id' ]); |
|
| 151 | + unset($article[ 'admin_user_id' ]); |
|
| 152 | 152 | |
| 153 | 153 | $videos = $videosFilter->getValues() + [ |
| 154 | 154 | 'featured_img' => $this->upload->uploadImage($data, 'featured_img'), |
@@ -156,35 +156,35 @@ discard block |
||
| 156 | 156 | ]; |
| 157 | 157 | |
| 158 | 158 | // We don't want to force user to re-upload image on edit |
| 159 | - if(!$videos['featured_img']) { |
|
| 160 | - unset($videos['featured_img']); |
|
| 159 | + if (!$videos[ 'featured_img' ]) { |
|
| 160 | + unset($videos[ 'featured_img' ]); |
|
| 161 | 161 | } |
| 162 | 162 | else { |
| 163 | 163 | $this->upload->deleteFile($oldArticle->featured_img); |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | - if(!$videos['main_img']) { |
|
| 167 | - unset($videos['main_img']); |
|
| 166 | + if (!$videos[ 'main_img' ]) { |
|
| 167 | + unset($videos[ 'main_img' ]); |
|
| 168 | 168 | } |
| 169 | 169 | else { |
| 170 | 170 | $this->upload->deleteFile($oldArticle->main_img); |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | - $this->articleMapper->update($article, ['article_uuid' => $article['article_uuid']]); |
|
| 174 | - $this->articleVideosMapper->update($videos, ['article_uuid' => $article['article_uuid']]); |
|
| 173 | + $this->articleMapper->update($article, [ 'article_uuid' => $article[ 'article_uuid' ] ]); |
|
| 174 | + $this->articleVideosMapper->update($videos, [ 'article_uuid' => $article[ 'article_uuid' ] ]); |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | public function deleteArticle($id) |
| 178 | 178 | { |
| 179 | 179 | $video = $this->articleVideosMapper->get($id); |
| 180 | 180 | |
| 181 | - if(!$video) { |
|
| 181 | + if (!$video) { |
|
| 182 | 182 | throw new \Exception('Article not found!'); |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | $this->upload->deleteFile($video->main_img); |
| 186 | 186 | $this->upload->deleteFile($video->featured_img); |
| 187 | - $this->articleVideosMapper->delete(['article_uuid' => $video->article_uuid]); |
|
| 187 | + $this->articleVideosMapper->delete([ 'article_uuid' => $video->article_uuid ]); |
|
| 188 | 188 | $this->delete($video->article_uuid); |
| 189 | 189 | } |
| 190 | 190 | |
@@ -158,15 +158,13 @@ |
||
| 158 | 158 | // We don't want to force user to re-upload image on edit |
| 159 | 159 | if(!$videos['featured_img']) { |
| 160 | 160 | unset($videos['featured_img']); |
| 161 | - } |
|
| 162 | - else { |
|
| 161 | + } else { |
|
| 163 | 162 | $this->upload->deleteFile($oldArticle->featured_img); |
| 164 | 163 | } |
| 165 | 164 | |
| 166 | 165 | if(!$videos['main_img']) { |
| 167 | 166 | unset($videos['main_img']); |
| 168 | - } |
|
| 169 | - else { |
|
| 167 | + } else { |
|
| 170 | 168 | $this->upload->deleteFile($oldArticle->main_img); |
| 171 | 169 | } |
| 172 | 170 | |