|
4 | 4 |
|
5 | 5 | class ResolverBlogPost extends Resolver |
6 | 6 | { |
| 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 | + |
7 | 16 | public function get($args) |
8 | 17 | { |
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']); |
11 | 21 |
|
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 | + } |
19 | 29 |
|
20 | 30 |
|
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 | + } |
36 | 49 | } |
37 | 50 |
|
38 | 51 | public function getList($args) |
39 | 52 | { |
40 | | - $this->load->model('blog/post'); |
41 | | - $filter_data = array( |
| 53 | + if ($this->blog) { |
| 54 | + $this->load->model('blog/post'); |
| 55 | + $filter_data = array( |
42 | 56 | 'limit' => $args['size'], |
43 | 57 | 'start' => ($args['page'] - 1) * $args['size'], |
44 | 58 | 'sort' => $args['sort'], |
45 | 59 | 'order' => $args['order'] |
46 | 60 | ); |
47 | 61 |
|
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 | + } |
51 | 65 |
|
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); |
54 | 68 |
|
55 | | - $posts = array(); |
| 69 | + $posts = array(); |
56 | 70 |
|
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 | + } |
60 | 74 |
|
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 | + } |
71 | 90 | } |
72 | 91 | } |
0 commit comments