Skip to content

Commit 306e354

Browse files
committed
Fix bug
1 parent 2307303 commit 306e354

File tree

2 files changed

+114
-76
lines changed

2 files changed

+114
-76
lines changed

Vuefront/Vuefront/ApiGraphql/resolver/blog/category.php

Lines changed: 50 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,25 @@
44

55
class ResolverBlogCategory extends Resolver
66
{
7+
private $blog = false;
8+
9+
public function __construct($registry) {
10+
parent::__construct($registry);
11+
$moduleManager = \Magento\Framework\App\ObjectManager::getInstance()->get('\Magento\Framework\Module\Manager');
12+
13+
$this->blog = $moduleManager->isOutputEnabled('Magefan_Blog');
14+
}
15+
716
public function get($data)
817
{
9-
$this->load->model('blog/category');
10-
$category = $this->model_blog_category->getCategory($data['id']);
18+
if ($this->blog) {
19+
$this->load->model('blog/category');
20+
$category = $this->model_blog_category->getCategory($data['id']);
1121

12-
$thumb = '';
13-
$thumbLazy = '';
22+
$thumb = '';
23+
$thumbLazy = '';
1424

15-
return array(
25+
return array(
1626
'id' => $category['category_id'],
1727
'name' => $category['title'],
1828
'description' => $category['content'],
@@ -33,42 +43,51 @@ public function get($data)
3343
));
3444
}
3545
);
46+
} else {
47+
return array();
48+
}
3649
}
3750

3851
public function getList($args)
3952
{
40-
$this->load->model('blog/category');
41-
$filter_data = array(
42-
'limit' => $args['size'],
43-
'start' => ($args['page'] - 1) * $args['size'],
44-
'sort' => $args['sort'],
45-
'order' => $args['order']
46-
);
53+
if ($this->blog) {
54+
$this->load->model('blog/category');
55+
$filter_data = array(
56+
'limit' => $args['size'],
57+
'start' => ($args['page'] - 1) * $args['size'],
58+
'sort' => $args['sort'],
59+
'order' => $args['order']
60+
);
61+
62+
if ($args['parent'] !== -1) {
63+
$filter_data['filter_parent_id'] = $args['parent'];
64+
}
4765

48-
if ($args['parent'] !== -1) {
49-
$filter_data['filter_parent_id'] = $args['parent'];
50-
}
66+
$product_categories = $this->model_blog_category->getCategories($filter_data);
5167

52-
$product_categories = $this->model_blog_category->getCategories($filter_data);
68+
$category_total = $this->model_blog_category->getTotalCategories($filter_data);
5369

54-
$category_total = $this->model_blog_category->getTotalCategories($filter_data);
70+
$categories = array();
5571

56-
$categories = array();
72+
foreach ($product_categories as $category) {
73+
$categories[] = $this->get(array( 'id' => $category['ID'] ));
74+
}
5775

58-
foreach ($product_categories as $category) {
59-
$categories[] = $this->get(array( 'id' => $category['ID'] ));
76+
return array(
77+
'content' => $categories,
78+
'first' => $args['page'] === 1,
79+
'last' => $args['page'] === ceil($category_total / $args['size']),
80+
'number' => (int) $args['page'],
81+
'numberOfElements' => count($categories),
82+
'size' => (int) $args['size'],
83+
'totalPages' => (int) ceil($category_total / $args['size']),
84+
'totalElements' => (int) $category_total,
85+
);
86+
} else {
87+
return array(
88+
'content' => array()
89+
);
6090
}
61-
62-
return array(
63-
'content' => $categories,
64-
'first' => $args['page'] === 1,
65-
'last' => $args['page'] === ceil($category_total / $args['size']),
66-
'number' => (int) $args['page'],
67-
'numberOfElements' => count($categories),
68-
'size' => (int) $args['size'],
69-
'totalPages' => (int) ceil($category_total / $args['size']),
70-
'totalElements' => (int) $category_total,
71-
);
7291
}
7392

7493
public function child($data)

Vuefront/Vuefront/ApiGraphql/resolver/blog/post.php

Lines changed: 64 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,69 +4,88 @@
44

55
class ResolverBlogPost extends Resolver
66
{
7+
private $blog = false;
8+
9+
public function __construct($registry) {
10+
parent::__construct($registry);
11+
$moduleManager = \Magento\Framework\App\ObjectManager::getInstance()->get('\Magento\Framework\Module\Manager');
12+
13+
$this->blog = $moduleManager->isOutputEnabled('Magefan_Blog');
14+
}
15+
716
public function get($args)
817
{
9-
$this->load->model('blog/post');
10-
$post = $this->model_blog_post->getPost($args['id']);
18+
if ($this->blog) {
19+
$this->load->model('blog/post');
20+
$post = $this->model_blog_post->getPost($args['id']);
1121

12-
if ($post['featured_img']) {
13-
$thumb = $this->image->getUrl($post['featured_img'], '');
14-
$thumbLazy = $this->image->resize($post['featured_img'], 10, 10, '');
15-
} else {
16-
$thumb = '';
17-
$thumbLazy = '';
18-
}
22+
if ($post['featured_img']) {
23+
$thumb = $this->image->getUrl($post['featured_img'], '');
24+
$thumbLazy = $this->image->resize($post['featured_img'], 10, 10, '');
25+
} else {
26+
$thumb = '';
27+
$thumbLazy = '';
28+
}
1929

2030

21-
return array(
22-
'id' => $post['post_id'],
23-
'title' => $post['title'],
24-
'shortDescription' => $post['short_content'],
25-
'description' => $post['content'],
26-
'keyword' => $post['identifier'],
27-
'image' => $thumb,
28-
'imageLazy' => $thumbLazy,
29-
'reviews' => function ($root, $args) {
30-
return $this->load->resolver('blog/review/get', array(
31-
'parent' => $root,
32-
'args' => $args
33-
));
34-
}
35-
);
31+
return array(
32+
'id' => $post['post_id'],
33+
'title' => $post['title'],
34+
'shortDescription' => $post['short_content'],
35+
'description' => $post['content'],
36+
'keyword' => $post['identifier'],
37+
'image' => $thumb,
38+
'imageLazy' => $thumbLazy,
39+
'reviews' => function ($root, $args) {
40+
return $this->load->resolver('blog/review/get', array(
41+
'parent' => $root,
42+
'args' => $args
43+
));
44+
}
45+
);
46+
} else {
47+
return array();
48+
}
3649
}
3750

3851
public function getList($args)
3952
{
40-
$this->load->model('blog/post');
41-
$filter_data = array(
53+
if ($this->blog) {
54+
$this->load->model('blog/post');
55+
$filter_data = array(
4256
'limit' => $args['size'],
4357
'start' => ($args['page'] - 1) * $args['size'],
4458
'sort' => $args['sort'],
4559
'order' => $args['order']
4660
);
4761

48-
if ($args['category_id'] !== 0) {
49-
$filter_data['filter_category_id'] = $args['category_id'];
50-
}
62+
if ($args['category_id'] !== 0) {
63+
$filter_data['filter_category_id'] = $args['category_id'];
64+
}
5165

52-
$results = $this->model_blog_post->getPosts($filter_data);
53-
$product_total = $this->model_blog_post->getTotalPosts($filter_data);
66+
$results = $this->model_blog_post->getPosts($filter_data);
67+
$product_total = $this->model_blog_post->getTotalPosts($filter_data);
5468

55-
$posts = array();
69+
$posts = array();
5670

57-
foreach ($results as $post) {
58-
$posts[] = $this->get(array( 'id' => $post['ID'] ));
59-
}
71+
foreach ($results as $post) {
72+
$posts[] = $this->get(array( 'id' => $post['ID'] ));
73+
}
6074

61-
return array(
62-
'content' => $posts,
63-
'first' => $args['page'] === 1,
64-
'last' => $args['page'] === ceil($product_total / $args['size']),
65-
'number' => (int) $args['page'],
66-
'numberOfElements' => count($posts),
67-
'size' => (int) $args['size'],
68-
'totalPages' => (int) ceil($product_total / $args['size']),
69-
'totalElements' => (int) $product_total,
70-
);
75+
return array(
76+
'content' => $posts,
77+
'first' => $args['page'] === 1,
78+
'last' => $args['page'] === ceil($product_total / $args['size']),
79+
'number' => (int) $args['page'],
80+
'numberOfElements' => count($posts),
81+
'size' => (int) $args['size'],
82+
'totalPages' => (int) ceil($product_total / $args['size']),
83+
'totalElements' => (int) $product_total,
84+
);
85+
} else {
86+
return array(
87+
'content' => array()
88+
);
89+
}
7190
}
7291
}

0 commit comments

Comments
 (0)