@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | return [ |
| 10 | 10 | 'templates' => [ |
| 11 | 11 | 'paths' => [ |
| 12 | - 'category' => [__DIR__ . '/../templates/category'], |
|
| 12 | + 'category' => [ __DIR__ . '/../templates/category' ], |
|
| 13 | 13 | ], |
| 14 | 14 | ], |
| 15 | 15 | |
@@ -30,13 +30,13 @@ discard block |
||
| 30 | 30 | 'name' => 'admin.categories', |
| 31 | 31 | 'path' => '/admin/categories', |
| 32 | 32 | 'middleware' => Controller\IndexController::class, |
| 33 | - 'allowed_methods' => ['GET'], |
|
| 33 | + 'allowed_methods' => [ 'GET' ], |
|
| 34 | 34 | ], |
| 35 | 35 | [ |
| 36 | 36 | 'name' => 'admin.categories.action', |
| 37 | 37 | 'path' => '/admin/categories/:action/:id', |
| 38 | 38 | 'middleware' => Controller\IndexController::class, |
| 39 | - 'allowed_methods' => ['GET', 'POST'] |
|
| 39 | + 'allowed_methods' => [ 'GET', 'POST' ] |
|
| 40 | 40 | ], |
| 41 | 41 | ], |
| 42 | 42 | |
@@ -47,12 +47,12 @@ discard block |
||
| 47 | 47 | public function index() : \Psr\Http\Message\ResponseInterface |
| 48 | 48 | { |
| 49 | 49 | $params = $this->request->getQueryParams(); |
| 50 | - $page = isset($params['page']) ? $params['page'] : 1; |
|
| 51 | - $limit = isset($params['limit']) ? $params['limit'] : 15; |
|
| 50 | + $page = isset($params[ 'page' ]) ? $params[ 'page' ] : 1; |
|
| 51 | + $limit = isset($params[ 'limit' ]) ? $params[ 'limit' ] : 15; |
|
| 52 | 52 | |
| 53 | 53 | $categories = $this->categoryService->getPagination($page, $limit); |
| 54 | 54 | |
| 55 | - return new HtmlResponse($this->template->render('category::index/index', ['list' => $categories, 'layout' => 'layout/admin'])); |
|
| 55 | + return new HtmlResponse($this->template->render('category::index/index', [ 'list' => $categories, 'layout' => 'layout/admin' ])); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
@@ -60,13 +60,13 @@ discard block |
||
| 60 | 60 | * |
| 61 | 61 | * @return \Psr\Http\Message\ResponseInterface |
| 62 | 62 | */ |
| 63 | - public function edit($errors = []): \Psr\Http\Message\ResponseInterface |
|
| 63 | + public function edit($errors = [ ]): \Psr\Http\Message\ResponseInterface |
|
| 64 | 64 | { |
| 65 | 65 | $id = $this->request->getAttribute('id'); |
| 66 | 66 | $category = $this->categoryService->getCategory($id); |
| 67 | 67 | |
| 68 | - if($this->request->getParsedBody()){ |
|
| 69 | - $category = (object)($this->request->getParsedBody() + (array)$category); |
|
| 68 | + if ($this->request->getParsedBody()) { |
|
| 69 | + $category = (object) ($this->request->getParsedBody() + (array) $category); |
|
| 70 | 70 | $category->category_id = $id; |
| 71 | 71 | } |
| 72 | 72 | |
@@ -79,36 +79,36 @@ discard block |
||
| 79 | 79 | |
| 80 | 80 | public function save() |
| 81 | 81 | { |
| 82 | - try{ |
|
| 82 | + try { |
|
| 83 | 83 | $id = $this->request->getAttribute('id'); |
| 84 | 84 | $data = $this->request->getParsedBody(); |
| 85 | 85 | |
| 86 | - if($id){ |
|
| 86 | + if ($id) { |
|
| 87 | 87 | $this->categoryService->updateCategory($data, $id); |
| 88 | 88 | } |
| 89 | - else{ |
|
| 89 | + else { |
|
| 90 | 90 | $this->categoryService->createCategory($data); |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | return $this->response->withStatus(302)->withHeader('Location', $this->router->generateUri('admin.categories')); |
| 94 | 94 | } |
| 95 | - catch(FilterException $fe){ |
|
| 95 | + catch (FilterException $fe) { |
|
| 96 | 96 | return $this->edit($fe->getArrayMessages()); |
| 97 | 97 | } |
| 98 | - catch(\Exception $e){ |
|
| 98 | + catch (\Exception $e) { |
|
| 99 | 99 | throw $e; |
| 100 | 100 | } |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | public function delete() |
| 104 | 104 | { |
| 105 | - try{ |
|
| 105 | + try { |
|
| 106 | 106 | $id = $this->request->getAttribute('id'); |
| 107 | 107 | $this->categoryService->delete($id); |
| 108 | 108 | |
| 109 | 109 | return $this->response->withStatus(302)->withHeader('Location', $this->router->generateUri('admin.categories')); |
| 110 | 110 | } |
| 111 | - catch(\Exception $e){ |
|
| 111 | + catch (\Exception $e) { |
|
| 112 | 112 | return $this->response->withStatus(302)->withHeader('Location', $this->router->generateUri('admin.categories')); |
| 113 | 113 | } |
| 114 | 114 | } |
@@ -85,17 +85,14 @@ discard block |
||
| 85 | 85 | |
| 86 | 86 | if($id){ |
| 87 | 87 | $this->categoryService->updateCategory($data, $id); |
| 88 | - } |
|
| 89 | - else{ |
|
| 88 | + } else{ |
|
| 90 | 89 | $this->categoryService->createCategory($data); |
| 91 | 90 | } |
| 92 | 91 | |
| 93 | 92 | return $this->response->withStatus(302)->withHeader('Location', $this->router->generateUri('admin.categories')); |
| 94 | - } |
|
| 95 | - catch(FilterException $fe){ |
|
| 93 | + } catch(FilterException $fe){ |
|
| 96 | 94 | return $this->edit($fe->getArrayMessages()); |
| 97 | - } |
|
| 98 | - catch(\Exception $e){ |
|
| 95 | + } catch(\Exception $e){ |
|
| 99 | 96 | throw $e; |
| 100 | 97 | } |
| 101 | 98 | } |
@@ -107,8 +104,7 @@ discard block |
||
| 107 | 104 | $this->categoryService->delete($id); |
| 108 | 105 | |
| 109 | 106 | return $this->response->withStatus(302)->withHeader('Location', $this->router->generateUri('admin.categories')); |
| 110 | - } |
|
| 111 | - catch(\Exception $e){ |
|
| 107 | + } catch(\Exception $e){ |
|
| 112 | 108 | return $this->response->withStatus(302)->withHeader('Location', $this->router->generateUri('admin.categories')); |
| 113 | 109 | } |
| 114 | 110 | } |
@@ -9,8 +9,8 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | public function up() |
| 11 | 11 | { |
| 12 | - $this->table('category', ['id' => false, 'primary_key' => 'category_uuid']) |
|
| 13 | - ->addColumn('category_uuid', 'binary', ['limit' => 16]) |
|
| 12 | + $this->table('category', [ 'id' => false, 'primary_key' => 'category_uuid' ]) |
|
| 13 | + ->addColumn('category_uuid', 'binary', [ 'limit' => 16 ]) |
|
| 14 | 14 | ->addColumn('category_id', 'text') |
| 15 | 15 | ->addColumn('name', 'text') |
| 16 | 16 | ->addColumn('slug', 'text') |
@@ -20,24 +20,24 @@ discard block |
||
| 20 | 20 | $count = rand(5, 15); |
| 21 | 21 | |
| 22 | 22 | $categories = [ |
| 23 | - ['name' => 'Video', 'slug' => 'super-videos'], |
|
| 24 | - ['name' => 'Blog Posts', 'slug' => 'experts-posts'], |
|
| 25 | - ['name' => 'Discusions', 'slug' => 'discusions'], |
|
| 26 | - ['name' => 'Events in region', 'slug' => 'all-events'], |
|
| 27 | - ['name' => '#meetup', 'slug' => 'region-meetups'], |
|
| 28 | - ['name' => 'conf2017', 'slug' => 'phpsrbija-conf2017'], |
|
| 29 | - ['name' => 'Beer', 'slug' => 'after-parties'], |
|
| 23 | + [ 'name' => 'Video', 'slug' => 'super-videos' ], |
|
| 24 | + [ 'name' => 'Blog Posts', 'slug' => 'experts-posts' ], |
|
| 25 | + [ 'name' => 'Discusions', 'slug' => 'discusions' ], |
|
| 26 | + [ 'name' => 'Events in region', 'slug' => 'all-events' ], |
|
| 27 | + [ 'name' => '#meetup', 'slug' => 'region-meetups' ], |
|
| 28 | + [ 'name' => 'conf2017', 'slug' => 'phpsrbija-conf2017' ], |
|
| 29 | + [ 'name' => 'Beer', 'slug' => 'after-parties' ], |
|
| 30 | 30 | ]; |
| 31 | 31 | |
| 32 | - foreach($categories as $cat){ |
|
| 32 | + foreach ($categories as $cat) { |
|
| 33 | 33 | $id = $faker->uuid; |
| 34 | 34 | $mysqluuid = (new Uuid($id))->toFormat(new Binary()); |
| 35 | 35 | |
| 36 | 36 | $data = [ |
| 37 | 37 | 'category_uuid' => $mysqluuid, |
| 38 | 38 | 'category_id' => $id, |
| 39 | - 'name' => $cat['name'], |
|
| 40 | - 'slug' => $cat['slug'], |
|
| 39 | + 'name' => $cat[ 'name' ], |
|
| 40 | + 'slug' => $cat[ 'slug' ], |
|
| 41 | 41 | ]; |
| 42 | 42 | |
| 43 | 43 | $this->insert('category', $data); |
@@ -12,11 +12,11 @@ |
||
| 12 | 12 | { |
| 13 | 13 | public function up() |
| 14 | 14 | { |
| 15 | - $this->table('article_categories', ['id' => true, 'primary_key' => 'id']) |
|
| 16 | - ->addColumn('category_uuid', 'binary', ['limit' => 16]) |
|
| 17 | - ->addColumn('article_uuid', 'binary', ['limit' => 16]) |
|
| 18 | - ->addForeignKey('article_uuid', 'articles', 'article_uuid', ['delete' => 'NO_ACTION', 'update' => 'NO_ACTION']) |
|
| 19 | - ->addForeignKey('category_uuid', 'category', 'category_uuid', ['delete' => 'NO_ACTION', 'update' => 'NO_ACTION']) |
|
| 15 | + $this->table('article_categories', [ 'id' => true, 'primary_key' => 'id' ]) |
|
| 16 | + ->addColumn('category_uuid', 'binary', [ 'limit' => 16 ]) |
|
| 17 | + ->addColumn('article_uuid', 'binary', [ 'limit' => 16 ]) |
|
| 18 | + ->addForeignKey('article_uuid', 'articles', 'article_uuid', [ 'delete' => 'NO_ACTION', 'update' => 'NO_ACTION' ]) |
|
| 19 | + ->addForeignKey('category_uuid', 'category', 'category_uuid', [ 'delete' => 'NO_ACTION', 'update' => 'NO_ACTION' ]) |
|
| 20 | 20 | ->create(); |
| 21 | 21 | |
| 22 | 22 | //$this->insertDummyData(); |
@@ -7,23 +7,23 @@ |
||
| 7 | 7 | |
| 8 | 8 | public function up() |
| 9 | 9 | { |
| 10 | - $this->table('menu', ['id' => false, 'primary_key' => 'menu_uuid']) |
|
| 11 | - ->addColumn('menu_uuid', 'binary', ['limit' => 16]) |
|
| 10 | + $this->table('menu', [ 'id' => false, 'primary_key' => 'menu_uuid' ]) |
|
| 11 | + ->addColumn('menu_uuid', 'binary', [ 'limit' => 16 ]) |
|
| 12 | 12 | ->addColumn('menu_id', 'text') |
| 13 | - ->addColumn('parent_id', 'text', ['null' => true]) |
|
| 13 | + ->addColumn('parent_id', 'text', [ 'null' => true ]) |
|
| 14 | 14 | ->addColumn('title', 'text') |
| 15 | - ->addColumn('href', 'text', ['null' => true]) |
|
| 16 | - ->addColumn('is_active', 'boolean', ['default' => false]) |
|
| 17 | - ->addColumn('is_in_header', 'boolean', ['default' => true]) |
|
| 18 | - ->addColumn('is_in_footer', 'boolean', ['default' => true]) |
|
| 19 | - ->addColumn('is_in_side', 'boolean', ['default' => true]) |
|
| 20 | - ->addColumn('order_no', 'integer', ['default' => 0]) |
|
| 21 | - ->addColumn('created_at', 'datetime', ['null' => true]) |
|
| 15 | + ->addColumn('href', 'text', [ 'null' => true ]) |
|
| 16 | + ->addColumn('is_active', 'boolean', [ 'default' => false ]) |
|
| 17 | + ->addColumn('is_in_header', 'boolean', [ 'default' => true ]) |
|
| 18 | + ->addColumn('is_in_footer', 'boolean', [ 'default' => true ]) |
|
| 19 | + ->addColumn('is_in_side', 'boolean', [ 'default' => true ]) |
|
| 20 | + ->addColumn('order_no', 'integer', [ 'default' => 0 ]) |
|
| 21 | + ->addColumn('created_at', 'datetime', [ 'null' => true ]) |
|
| 22 | 22 | //->addForeignKey('parent_id', 'menu', 'id', ['delete' => 'NO_ACTION', 'update' => 'NO_ACTION']) # we can not add constraints |
| 23 | - ->addColumn('article_uuid', 'binary', ['limit' => 16, 'null' => true]) |
|
| 24 | - ->addColumn('category_uuid', 'binary', ['limit' => 16, 'null' => true]) |
|
| 25 | - ->addForeignKey('article_uuid', 'articles', 'article_uuid', ['delete' => 'NO_ACTION', 'update' => 'NO_ACTION']) |
|
| 26 | - ->addForeignKey('category_uuid', 'category', 'category_uuid', ['delete' => 'NO_ACTION', 'update' => 'NO_ACTION']) |
|
| 23 | + ->addColumn('article_uuid', 'binary', [ 'limit' => 16, 'null' => true ]) |
|
| 24 | + ->addColumn('category_uuid', 'binary', [ 'limit' => 16, 'null' => true ]) |
|
| 25 | + ->addForeignKey('article_uuid', 'articles', 'article_uuid', [ 'delete' => 'NO_ACTION', 'update' => 'NO_ACTION' ]) |
|
| 26 | + ->addForeignKey('category_uuid', 'category', 'category_uuid', [ 'delete' => 'NO_ACTION', 'update' => 'NO_ACTION' ]) |
|
| 27 | 27 | ->create(); |
| 28 | 28 | } |
| 29 | 29 | |
@@ -37,13 +37,13 @@ discard block |
||
| 37 | 37 | ])); |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | - public function edit($errors = []) |
|
| 40 | + public function edit($errors = [ ]) |
|
| 41 | 41 | { |
| 42 | 42 | $id = $this->request->getAttribute('id'); |
| 43 | 43 | $item = $this->menuService->get($id); |
| 44 | 44 | |
| 45 | - if($this->request->getParsedBody()){ |
|
| 46 | - $item = (object)($this->request->getParsedBody() + (array)$item); |
|
| 45 | + if ($this->request->getParsedBody()) { |
|
| 46 | + $item = (object) ($this->request->getParsedBody() + (array) $item); |
|
| 47 | 47 | $item->menu_id = $id; |
| 48 | 48 | } |
| 49 | 49 | |
@@ -58,36 +58,36 @@ discard block |
||
| 58 | 58 | |
| 59 | 59 | public function save() |
| 60 | 60 | { |
| 61 | - try{ |
|
| 61 | + try { |
|
| 62 | 62 | $id = $this->request->getAttribute('id'); |
| 63 | 63 | $data = $this->request->getParsedBody(); |
| 64 | 64 | |
| 65 | - if($id){ |
|
| 65 | + if ($id) { |
|
| 66 | 66 | $this->menuService->updateMenuItem($data, $id); |
| 67 | 67 | } |
| 68 | - else{ |
|
| 68 | + else { |
|
| 69 | 69 | $this->menuService->addMenuItem($data); |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | return $this->response->withStatus(302)->withHeader('Location', $this->router->generateUri('admin.menu')); |
| 73 | 73 | } |
| 74 | - catch(FilterException $fe){ |
|
| 74 | + catch (FilterException $fe) { |
|
| 75 | 75 | return $this->edit($fe->getArrayMessages()); |
| 76 | 76 | } |
| 77 | - catch(\Exception $e){ |
|
| 77 | + catch (\Exception $e) { |
|
| 78 | 78 | throw $e; |
| 79 | 79 | } |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | public function delete() |
| 83 | 83 | { |
| 84 | - try{ |
|
| 84 | + try { |
|
| 85 | 85 | $id = $this->request->getAttribute('id'); |
| 86 | 86 | $this->menuService->delete($id); |
| 87 | 87 | |
| 88 | 88 | return $this->response->withStatus(302)->withHeader('Location', $this->router->generateUri('admin.menu')); |
| 89 | 89 | } |
| 90 | - catch(\Exception $e){ |
|
| 90 | + catch (\Exception $e) { |
|
| 91 | 91 | throw $e; |
| 92 | 92 | } |
| 93 | 93 | } |
@@ -95,9 +95,9 @@ discard block |
||
| 95 | 95 | public function updateOrder() |
| 96 | 96 | { |
| 97 | 97 | $data = $this->request->getParsedBody(); |
| 98 | - $menuOrder = isset($data['order']) ? json_decode($data['order']) : []; |
|
| 98 | + $menuOrder = isset($data[ 'order' ]) ? json_decode($data[ 'order' ]) : [ ]; |
|
| 99 | 99 | $status = $this->menuService->updateMenuOrder($menuOrder); |
| 100 | 100 | |
| 101 | - return new JsonResponse(['status' => $status]); |
|
| 101 | + return new JsonResponse([ 'status' => $status ]); |
|
| 102 | 102 | } |
| 103 | 103 | } |
| 104 | 104 | \ No newline at end of file |
@@ -64,17 +64,14 @@ discard block |
||
| 64 | 64 | |
| 65 | 65 | if($id){ |
| 66 | 66 | $this->menuService->updateMenuItem($data, $id); |
| 67 | - } |
|
| 68 | - else{ |
|
| 67 | + } else{ |
|
| 69 | 68 | $this->menuService->addMenuItem($data); |
| 70 | 69 | } |
| 71 | 70 | |
| 72 | 71 | return $this->response->withStatus(302)->withHeader('Location', $this->router->generateUri('admin.menu')); |
| 73 | - } |
|
| 74 | - catch(FilterException $fe){ |
|
| 72 | + } catch(FilterException $fe){ |
|
| 75 | 73 | return $this->edit($fe->getArrayMessages()); |
| 76 | - } |
|
| 77 | - catch(\Exception $e){ |
|
| 74 | + } catch(\Exception $e){ |
|
| 78 | 75 | throw $e; |
| 79 | 76 | } |
| 80 | 77 | } |
@@ -86,8 +83,7 @@ discard block |
||
| 86 | 83 | $this->menuService->delete($id); |
| 87 | 84 | |
| 88 | 85 | return $this->response->withStatus(302)->withHeader('Location', $this->router->generateUri('admin.menu')); |
| 89 | - } |
|
| 90 | - catch(\Exception $e){ |
|
| 86 | + } catch(\Exception $e){ |
|
| 91 | 87 | throw $e; |
| 92 | 88 | } |
| 93 | 89 | } |
@@ -20,65 +20,65 @@ |
||
| 20 | 20 | |
| 21 | 21 | public function getInputFilter() |
| 22 | 22 | { |
| 23 | - if(!$this->inputFilter){ |
|
| 23 | + if (!$this->inputFilter) { |
|
| 24 | 24 | $inputFilter = new InputFilter(); |
| 25 | 25 | |
| 26 | 26 | $inputFilter->add([ |
| 27 | 27 | 'name' => 'title', |
| 28 | 28 | 'required' => true, |
| 29 | - 'filters' => [['name' => 'StripTags'], ['name' => 'StringTrim']], |
|
| 29 | + 'filters' => [ [ 'name' => 'StripTags' ], [ 'name' => 'StringTrim' ] ], |
|
| 30 | 30 | 'validators' => [ |
| 31 | - ['name' => 'NotEmpty'], |
|
| 32 | - ['name' => 'StringLength', 'options' => ['max' => '255']], |
|
| 31 | + [ 'name' => 'NotEmpty' ], |
|
| 32 | + [ 'name' => 'StringLength', 'options' => [ 'max' => '255' ] ], |
|
| 33 | 33 | ], |
| 34 | 34 | ]); |
| 35 | 35 | |
| 36 | 36 | $inputFilter->add([ |
| 37 | 37 | 'name' => 'href', |
| 38 | 38 | 'required' => false, |
| 39 | - 'filters' => [['name' => 'StripTags'], ['name' => 'StringTrim']] |
|
| 39 | + 'filters' => [ [ 'name' => 'StripTags' ], [ 'name' => 'StringTrim' ] ] |
|
| 40 | 40 | ]); |
| 41 | 41 | |
| 42 | 42 | $inputFilter->add([ |
| 43 | 43 | 'name' => 'article_id', |
| 44 | 44 | 'required' => false, |
| 45 | - 'filters' => [['name' => 'Null']], |
|
| 45 | + 'filters' => [ [ 'name' => 'Null' ] ], |
|
| 46 | 46 | 'validators' => [ |
| 47 | - ['name' => RecordExists::class, 'options' => ['table' => 'articles', 'field' => 'article_id', 'adapter' => $this->db]] |
|
| 47 | + [ 'name' => RecordExists::class, 'options' => [ 'table' => 'articles', 'field' => 'article_id', 'adapter' => $this->db ] ] |
|
| 48 | 48 | ] |
| 49 | 49 | ]); |
| 50 | 50 | |
| 51 | 51 | $inputFilter->add([ |
| 52 | 52 | 'name' => 'category_id', |
| 53 | 53 | 'required' => false, |
| 54 | - 'filters' => [['name' => 'Null']], |
|
| 54 | + 'filters' => [ [ 'name' => 'Null' ] ], |
|
| 55 | 55 | 'validators' => [ |
| 56 | - ['name' => RecordExists::class, 'options' => ['table' => 'category', 'field' => 'category_id', 'adapter' => $this->db]] |
|
| 56 | + [ 'name' => RecordExists::class, 'options' => [ 'table' => 'category', 'field' => 'category_id', 'adapter' => $this->db ] ] |
|
| 57 | 57 | ] |
| 58 | 58 | ]); |
| 59 | 59 | |
| 60 | 60 | $inputFilter->add([ |
| 61 | 61 | 'name' => 'is_active', |
| 62 | 62 | 'required' => false, |
| 63 | - 'filters' => [['name' => 'Boolean']] |
|
| 63 | + 'filters' => [ [ 'name' => 'Boolean' ] ] |
|
| 64 | 64 | ]); |
| 65 | 65 | |
| 66 | 66 | $inputFilter->add([ |
| 67 | 67 | 'name' => 'is_in_header', |
| 68 | 68 | 'required' => false, |
| 69 | - 'filters' => [['name' => 'Boolean']] |
|
| 69 | + 'filters' => [ [ 'name' => 'Boolean' ] ] |
|
| 70 | 70 | ]); |
| 71 | 71 | |
| 72 | 72 | $inputFilter->add([ |
| 73 | 73 | 'name' => 'is_in_footer', |
| 74 | 74 | 'required' => false, |
| 75 | - 'filters' => [['name' => 'Boolean']] |
|
| 75 | + 'filters' => [ [ 'name' => 'Boolean' ] ] |
|
| 76 | 76 | ]); |
| 77 | 77 | |
| 78 | 78 | $inputFilter->add([ |
| 79 | 79 | 'name' => 'is_in_side', |
| 80 | 80 | 'required' => false, |
| 81 | - 'filters' => [['name' => 'Boolean']] |
|
| 81 | + 'filters' => [ [ 'name' => 'Boolean' ] ] |
|
| 82 | 82 | ]); |
| 83 | 83 | |
| 84 | 84 | $this->inputFilter = $inputFilter; |
@@ -12,7 +12,6 @@ |
||
| 12 | 12 | /** |
| 13 | 13 | * Fetches a list of ArticleEntity models. |
| 14 | 14 | * |
| 15 | - * @param array $params |
|
| 16 | 15 | * @return ArrayObject |
| 17 | 16 | */ |
| 18 | 17 | public function fetchAllArticles($page, $limit); |
@@ -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 | |
@@ -88,8 +88,8 @@ discard block |
||
| 88 | 88 | { |
| 89 | 89 | $article = $this->articleVideosMapper->get($articleId); |
| 90 | 90 | |
| 91 | - if($article) { |
|
| 92 | - $article['categories'] = $this->getCategoryIds($articleId); |
|
| 91 | + if ($article) { |
|
| 92 | + $article[ 'categories' ] = $this->getCategoryIds($articleId); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | return $article; |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | $articleFilter = $this->articleFilter->getInputFilter()->setData($data); |
| 101 | 101 | $videosFilter = $this->videosFilter->getInputFilter()->setData($data); |
| 102 | 102 | |
| 103 | - if(!$articleFilter->isValid() || !$videosFilter->isValid()) { |
|
| 103 | + if (!$articleFilter->isValid() || !$videosFilter->isValid()) { |
|
| 104 | 104 | throw new FilterException($articleFilter->getMessages() + $videosFilter->getMessages()); |
| 105 | 105 | } |
| 106 | 106 | |
@@ -123,9 +123,9 @@ discard block |
||
| 123 | 123 | $this->articleMapper->insert($article); |
| 124 | 124 | $this->articleVideosMapper->insert($videos); |
| 125 | 125 | |
| 126 | - if(isset($data['categories']) && $data['categories']) { |
|
| 127 | - $categories = $this->categoryMapper->select(['category_id' => $data['categories']]); |
|
| 128 | - $this->articleMapper->insertCategories($categories, $article['article_uuid']); |
|
| 126 | + if (isset($data[ 'categories' ]) && $data[ 'categories' ]) { |
|
| 127 | + $categories = $this->categoryMapper->select([ 'category_id' => $data[ 'categories' ] ]); |
|
| 128 | + $this->articleMapper->insertCategories($categories, $article[ 'article_uuid' ]); |
|
| 129 | 129 | } |
| 130 | 130 | } |
| 131 | 131 | |
@@ -135,32 +135,32 @@ discard block |
||
| 135 | 135 | $articleFilter = $this->articleFilter->getInputFilter()->setData($data); |
| 136 | 136 | $videosFilter = $this->videosFilter->getInputFilter()->setData($data); |
| 137 | 137 | |
| 138 | - if(!$articleFilter->isValid() || !$videosFilter->isValid()) { |
|
| 138 | + if (!$articleFilter->isValid() || !$videosFilter->isValid()) { |
|
| 139 | 139 | throw new FilterException($articleFilter->getMessages() + $videosFilter->getMessages()); |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | - $article = $articleFilter->getValues() + ['article_uuid' => $article->article_uuid]; |
|
| 142 | + $article = $articleFilter->getValues() + [ 'article_uuid' => $article->article_uuid ]; |
|
| 143 | 143 | $videos = $videosFilter->getValues() + [ |
| 144 | 144 | 'featured_img' => $this->upload->uploadImage($data, 'featured_img'), |
| 145 | 145 | 'main_img' => $this->upload->uploadImage($data, 'main_img') |
| 146 | 146 | ]; |
| 147 | 147 | |
| 148 | 148 | // We dont want to force user to re-upload image on edit |
| 149 | - if(!$videos['featured_img']) { |
|
| 150 | - unset($videos['featured_img']); |
|
| 149 | + if (!$videos[ 'featured_img' ]) { |
|
| 150 | + unset($videos[ 'featured_img' ]); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | - if(!$videos['main_img']) { |
|
| 154 | - unset($videos['main_img']); |
|
| 153 | + if (!$videos[ 'main_img' ]) { |
|
| 154 | + unset($videos[ 'main_img' ]); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | - $this->articleMapper->update($article, ['article_uuid' => $article['article_uuid']]); |
|
| 158 | - $this->articleVideosMapper->update($videos, ['article_uuid' => $article['article_uuid']]); |
|
| 159 | - $this->articleMapper->deleteCategories($article['article_uuid']); |
|
| 157 | + $this->articleMapper->update($article, [ 'article_uuid' => $article[ 'article_uuid' ] ]); |
|
| 158 | + $this->articleVideosMapper->update($videos, [ 'article_uuid' => $article[ 'article_uuid' ] ]); |
|
| 159 | + $this->articleMapper->deleteCategories($article[ 'article_uuid' ]); |
|
| 160 | 160 | |
| 161 | - if(isset($data['categories']) && $data['categories']) { |
|
| 162 | - $categories = $this->categoryMapper->select(['category_id' => $data['categories']]); |
|
| 163 | - $this->articleMapper->insertCategories($categories, $article['article_uuid']); |
|
| 161 | + if (isset($data[ 'categories' ]) && $data[ 'categories' ]) { |
|
| 162 | + $categories = $this->categoryMapper->select([ 'category_id' => $data[ 'categories' ] ]); |
|
| 163 | + $this->articleMapper->insertCategories($categories, $article[ 'article_uuid' ]); |
|
| 164 | 164 | } |
| 165 | 165 | } |
| 166 | 166 | |
@@ -168,11 +168,11 @@ discard block |
||
| 168 | 168 | { |
| 169 | 169 | $video = $this->articleVideosMapper->get($id); |
| 170 | 170 | |
| 171 | - if(!$video) { |
|
| 171 | + if (!$video) { |
|
| 172 | 172 | throw new \Exception('Article not found!'); |
| 173 | 173 | } |
| 174 | 174 | |
| 175 | - $this->articleVideosMapper->delete(['article_uuid' => $video->article_uuid]); |
|
| 175 | + $this->articleVideosMapper->delete([ 'article_uuid' => $video->article_uuid ]); |
|
| 176 | 176 | $this->delete($video->article_uuid); |
| 177 | 177 | } |
| 178 | 178 | |