mageprince /
magento2-FAQ
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * MagePrince |
||
| 4 | * |
||
| 5 | * NOTICE OF LICENSE |
||
| 6 | * |
||
| 7 | * This source file is subject to the mageprince.com license that is |
||
| 8 | * available through the world-wide-web at this URL: |
||
| 9 | * https://mageprince.com/end-user-license-agreement |
||
| 10 | * |
||
| 11 | * DISCLAIMER |
||
| 12 | * |
||
| 13 | * Do not edit or add to this file if you wish to upgrade this extension to newer |
||
| 14 | * version in the future. |
||
| 15 | * |
||
| 16 | * @category MagePrince |
||
| 17 | * @package Mageprince_Faq |
||
| 18 | * @copyright Copyright (c) MagePrince (https://mageprince.com/) |
||
| 19 | * @license https://mageprince.com/end-user-license-agreement |
||
| 20 | */ |
||
| 21 | |||
| 22 | namespace Mageprince\Faq\Block\Index; |
||
| 23 | |||
| 24 | use Magento\Cms\Model\Template\FilterProvider; |
||
|
0 ignored issues
–
show
|
|||
| 25 | use Magento\Framework\Exception\LocalizedException; |
||
|
0 ignored issues
–
show
The type
Magento\Framework\Exception\LocalizedException was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 26 | use Magento\Framework\Exception\NoSuchEntityException; |
||
|
0 ignored issues
–
show
The type
Magento\Framework\Exception\NoSuchEntityException was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 27 | use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection; |
||
|
0 ignored issues
–
show
The type
Magento\Framework\Model\...tion\AbstractCollection was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 28 | use Magento\Framework\UrlInterface; |
||
|
0 ignored issues
–
show
The type
Magento\Framework\UrlInterface was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 29 | use Magento\Framework\View\Element\Template; |
||
|
0 ignored issues
–
show
The type
Magento\Framework\View\Element\Template was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 30 | use Magento\Store\Model\ScopeInterface; |
||
|
0 ignored issues
–
show
The type
Magento\Store\Model\ScopeInterface was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 31 | use Magento\Widget\Block\BlockInterface; |
||
|
0 ignored issues
–
show
The type
Magento\Widget\Block\BlockInterface was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 32 | use Mageprince\Faq\Api\Data\FaqGroupInterface; |
||
| 33 | use Mageprince\Faq\Api\FaqGroupRepositoryInterface; |
||
| 34 | use Mageprince\Faq\Helper\Data as HelperData; |
||
| 35 | use Mageprince\Faq\Model\Config\DefaultConfig; |
||
| 36 | use Mageprince\Faq\Model\ResourceModel\Faq\CollectionFactory; |
||
|
0 ignored issues
–
show
The type
Mageprince\Faq\Model\Res...l\Faq\CollectionFactory was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 37 | use Mageprince\Faq\Model\ResourceModel\FaqGroup\Collection as FaqGroupCollection; |
||
| 38 | use Mageprince\Faq\Model\ResourceModel\FaqGroup\CollectionFactory as FaqGroupCollectionFactory; |
||
|
0 ignored issues
–
show
The type
Mageprince\Faq\Model\Res...Group\CollectionFactory was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 39 | |||
| 40 | class Index extends Template implements BlockInterface |
||
| 41 | { |
||
| 42 | /** |
||
| 43 | * Default faq template |
||
| 44 | * |
||
| 45 | * @var string |
||
| 46 | */ |
||
| 47 | protected $_template = DefaultConfig::FAQ_MAIN_TEMPLATE_FILE; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @var CollectionFactory |
||
| 51 | */ |
||
| 52 | protected $faqCollectionFactory; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @var FaqGroupCollectionFactory |
||
| 56 | */ |
||
| 57 | protected $faqGroupCollectionFactory; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @var HelperData |
||
| 61 | */ |
||
| 62 | protected $customerSession; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @var HelperData |
||
| 66 | */ |
||
| 67 | protected $helper; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @var FaqGroupRepositoryInterface |
||
| 71 | */ |
||
| 72 | protected $faqGroupRepository; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @var FilterProvider |
||
| 76 | */ |
||
| 77 | protected $filterProvider; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Index constructor. |
||
| 81 | * @param Template\Context $context |
||
| 82 | * @param CollectionFactory $faqCollectionFactory |
||
| 83 | * @param FaqGroupRepositoryInterface $faqGroupRepository |
||
| 84 | * @param FaqGroupCollectionFactory $faqGroupCollectionFactory |
||
| 85 | * @param FilterProvider $filterProvider |
||
| 86 | * @param HelperData $helper |
||
| 87 | */ |
||
| 88 | public function __construct( |
||
| 89 | Template\Context $context, |
||
|
0 ignored issues
–
show
The type
Magento\Framework\View\Element\Template\Context was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 90 | CollectionFactory $faqCollectionFactory, |
||
| 91 | FaqGroupRepositoryInterface $faqGroupRepository, |
||
| 92 | FaqGroupCollectionFactory $faqGroupCollectionFactory, |
||
| 93 | FilterProvider $filterProvider, |
||
| 94 | HelperData $helper |
||
| 95 | ) { |
||
| 96 | $this->faqCollectionFactory = $faqCollectionFactory; |
||
| 97 | $this->faqGroupCollectionFactory = $faqGroupCollectionFactory; |
||
| 98 | $this->faqGroupRepository = $faqGroupRepository; |
||
| 99 | $this->helper = $helper; |
||
| 100 | $this->filterProvider = $filterProvider; |
||
| 101 | parent::__construct($context); |
||
| 102 | } |
||
| 103 | |||
| 104 | /** |
||
| 105 | * Get faq collection |
||
| 106 | * |
||
| 107 | * @param int $group |
||
| 108 | * @return \Mageprince\Faq\Model\ResourceModel\Faq\Collection |
||
| 109 | * @throws NoSuchEntityException |
||
| 110 | */ |
||
| 111 | public function getFaqCollection($group) |
||
| 112 | { |
||
| 113 | $faqCollection = $this->faqCollectionFactory->create(); |
||
| 114 | $faqCollection->addFieldToFilter( |
||
| 115 | 'group', |
||
| 116 | [ |
||
| 117 | ['null' => true], |
||
| 118 | ['finset' => $group] |
||
| 119 | ] |
||
| 120 | ); |
||
| 121 | $this->filterCollectionData($faqCollection); |
||
| 122 | return $faqCollection; |
||
| 123 | } |
||
| 124 | |||
| 125 | /** |
||
| 126 | * Get faq group collection |
||
| 127 | * |
||
| 128 | * @return FaqGroupCollection |
||
| 129 | * @throws NoSuchEntityException |
||
| 130 | */ |
||
| 131 | public function getFaqGroupCollection() |
||
| 132 | { |
||
| 133 | $faqGroupCollection = $this->faqGroupCollectionFactory->create(); |
||
| 134 | $this->filterCollectionData($faqGroupCollection); |
||
| 135 | if ($this->getGroupId()) { |
||
| 136 | $faqGroupCollection->addFieldToFilter('faqgroup_id', ['in' => $this->getGroupId()]); |
||
| 137 | } |
||
| 138 | return $faqGroupCollection; |
||
| 139 | } |
||
| 140 | |||
| 141 | /** |
||
| 142 | * Filter collection data |
||
| 143 | * |
||
| 144 | * @param AbstractCollection $collection |
||
| 145 | * @throws NoSuchEntityException |
||
| 146 | */ |
||
| 147 | private function filterCollectionData($collection) |
||
| 148 | { |
||
| 149 | $collection->addFieldToFilter('status', 1); |
||
| 150 | $collection->addFieldToFilter( |
||
| 151 | 'customer_group', |
||
| 152 | [ |
||
| 153 | ['null' => true], |
||
| 154 | ['finset' => $this->helper->getCustomerGroupId()] |
||
| 155 | ] |
||
| 156 | ); |
||
| 157 | $collection->addFieldToFilter( |
||
| 158 | 'storeview', |
||
| 159 | [ |
||
| 160 | ['eq' => 0], |
||
| 161 | ['finset' => $this->getCurrentStore()] |
||
| 162 | ] |
||
| 163 | ); |
||
| 164 | $collection->setOrder('sortorder', 'ASC'); |
||
| 165 | } |
||
| 166 | |||
| 167 | /** |
||
| 168 | * Get group by id |
||
| 169 | * |
||
| 170 | * @param int $groupId |
||
| 171 | * @return FaqGroupInterface |
||
| 172 | * @throws LocalizedException |
||
| 173 | */ |
||
| 174 | public function getGroupById($groupId) |
||
| 175 | { |
||
| 176 | return $this->faqGroupRepository->getById($groupId); |
||
| 177 | } |
||
| 178 | |||
| 179 | /** |
||
| 180 | * Filter faq content |
||
| 181 | * |
||
| 182 | * @param string $string |
||
| 183 | * @return string |
||
| 184 | */ |
||
| 185 | public function filterOutputHtml($string) |
||
| 186 | { |
||
| 187 | $output = ''; |
||
|
0 ignored issues
–
show
|
|||
| 188 | try { |
||
| 189 | $output = $this->filterProvider->getPageFilter()->filter($string); |
||
| 190 | } catch (\Exception $e) { |
||
| 191 | $this->_logger->error('Faq filter output error: ' . $e->getMessage()); |
||
| 192 | } |
||
| 193 | return $output; |
||
| 194 | } |
||
| 195 | |||
| 196 | /** |
||
| 197 | * Get icon image url |
||
| 198 | * |
||
| 199 | * @param string $icon |
||
| 200 | * @return string |
||
| 201 | */ |
||
| 202 | public function getImageUrl($icon) |
||
| 203 | { |
||
| 204 | $imageUrl = ''; |
||
| 205 | try { |
||
| 206 | $mediaUrl = $this->_storeManager |
||
| 207 | ->getStore() |
||
| 208 | ->getBaseUrl(UrlInterface::URL_TYPE_MEDIA); |
||
| 209 | $imageUrl = $mediaUrl . DefaultConfig::ICON_TMP_PATH . $icon; |
||
| 210 | } catch (\Exception $e) { |
||
| 211 | $this->_logger->error('Faq get image error:' . $e->getMessage()); |
||
| 212 | } |
||
| 213 | |||
| 214 | return $imageUrl; |
||
| 215 | } |
||
| 216 | |||
| 217 | /** |
||
| 218 | * Get config value |
||
| 219 | * |
||
| 220 | * @param string $config |
||
| 221 | * @return mixed |
||
| 222 | */ |
||
| 223 | public function getConfig($config) |
||
| 224 | { |
||
| 225 | return $this->_scopeConfig->getValue( |
||
| 226 | $config, |
||
| 227 | ScopeInterface::SCOPE_STORE |
||
| 228 | ); |
||
| 229 | } |
||
| 230 | |||
| 231 | /** |
||
| 232 | * Get current store id |
||
| 233 | * |
||
| 234 | * @return int |
||
| 235 | * @throws NoSuchEntityException |
||
| 236 | */ |
||
| 237 | public function getCurrentStore() |
||
| 238 | { |
||
| 239 | return $this->_storeManager->getStore()->getId(); |
||
| 240 | } |
||
| 241 | |||
| 242 | /** |
||
| 243 | * Check is module enabled |
||
| 244 | * |
||
| 245 | * @return bool |
||
| 246 | */ |
||
| 247 | public function isEnable() |
||
| 248 | { |
||
| 249 | return $this->getConfig(DefaultConfig::CONFIG_PATH_IS_ENABLE); |
||
| 250 | } |
||
| 251 | |||
| 252 | /** |
||
| 253 | * Check is group enabled |
||
| 254 | * |
||
| 255 | * @return bool |
||
| 256 | */ |
||
| 257 | public function isShowGroup() |
||
| 258 | { |
||
| 259 | if ($this->getShowGroup() != null) { |
||
| 260 | return $this->helper->checkBlockData($this->getShowGroup()); |
||
| 261 | } else { |
||
| 262 | return $this->getConfig(DefaultConfig::CONFIG_PATH_IS_SHOW_GROUP); |
||
| 263 | } |
||
| 264 | } |
||
| 265 | |||
| 266 | /** |
||
| 267 | * Check is group title enabled |
||
| 268 | * |
||
| 269 | * @return bool |
||
| 270 | */ |
||
| 271 | public function isShowGroupTitle() |
||
| 272 | { |
||
| 273 | if ($this->getShowGroupTitle() != null) { |
||
| 274 | return $this->helper->checkBlockData($this->getShowGroupTitle()); |
||
| 275 | } else { |
||
| 276 | return $this->getConfig(DefaultConfig::CONFIG_PATH_IS_SHOW_GROUP_TITLE); |
||
| 277 | } |
||
| 278 | } |
||
| 279 | |||
| 280 | /** |
||
| 281 | * Get faq page type action |
||
| 282 | * |
||
| 283 | * @return string |
||
| 284 | */ |
||
| 285 | public function getPageTypeAction() |
||
| 286 | { |
||
| 287 | if ($this->getPageType() == DefaultConfig::FAQ_PAGE_TYPE_AJAX) { |
||
| 288 | $pageType = DefaultConfig::FAQ_PAGE_TYPE_AJAX; |
||
| 289 | } elseif ($this->getPageType() == DefaultConfig::FAQ_PAGE_TYPE_SCROLL) { |
||
| 290 | $pageType = DefaultConfig::FAQ_PAGE_TYPE_SCROLL; |
||
| 291 | } else { |
||
| 292 | $pageType = $this->getConfig(DefaultConfig::CONFIG_PATH_PAGE_TYPE); |
||
| 293 | } |
||
| 294 | return $pageType; |
||
| 295 | } |
||
| 296 | |||
| 297 | /** |
||
| 298 | * Check is faqs collapse expand enabled |
||
| 299 | * |
||
| 300 | * @return bool |
||
| 301 | */ |
||
| 302 | public function isCollapseExpandEnabled() |
||
| 303 | { |
||
| 304 | if ($this->getEnableCollapseExpand() != null) { |
||
| 305 | $isEnable = $this->getEnableCollapseExpand(); |
||
| 306 | } else { |
||
| 307 | $isEnable = $this->getConfig(DefaultConfig::CONFIG_PATH_IS_ENABLED_COLLAPSE_EXPAND); |
||
| 308 | } |
||
| 309 | return $isEnable; |
||
| 310 | } |
||
| 311 | |||
| 312 | /** |
||
| 313 | * Get ajax url |
||
| 314 | * |
||
| 315 | * @return string |
||
| 316 | */ |
||
| 317 | public function getAjaxUrl() |
||
| 318 | { |
||
| 319 | return $this->getUrl(DefaultConfig::FAQ_PAGE_AJAX_URL); |
||
| 320 | } |
||
| 321 | } |
||
| 322 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths