Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- use Kalamov\Helpers\Element;
- use Kalamov\Helpers\Iblock;
- use Kalamov\Helpers\Common;
- use Kalamov\Helpers\Cache;
- use Kalamov\Helpers\Preg;
- if (!defined('B_PROLOG_INCLUDED') || B_PROLOG_INCLUDED !== true) {
- die();
- }
- class PageContactsComponent extends CBitrixComponent
- {
- /** @var $cacheManager Cache */
- protected $cacheManager;
- public function executeComponent()
- {
- $this->setCacheManager();
- $this->arResult = $this->shapeResult();
- $this->includeComponentTemplate();
- }
- protected function setCacheManager()
- {
- $this->cacheManager = new Cache();
- }
- protected function shapeResult()
- {
- if ($this->cacheManager->exists(sprintf('page_contacts_%s', $this->getSiteId()))) {
- $result = $this->cacheManager->get(sprintf('page_contacts_%s', $this->getSiteId()));
- } else {
- $row = Element::getOneBy(
- [
- 'IBLOCK_ID' => Iblock::getOneByCode('pages'),
- 'CODE' => 'contacts'
- ]
- );
- $contactsBlock = Common::getSpecificCustomBlock(
- $row['PROPERTIES']['CUSTOM_BLOCKS']['VALUE_DECODED'],
- 'block_contacts'
- );
- $pageParams = Common::getSpecificCustomBlock(
- $row['PROPERTIES']['CUSTOM_BLOCKS']['VALUE_DECODED'],
- 'page_contacts'
- );
- $result = [
- 'PHONE_UNFORMATTED_PREFIX' => substr($contactsBlock['phone'], 0, 2),
- 'PHONE_UNFORMATTED_THE_REST_OF' => substr($contactsBlock['phone'],2),
- 'PHONE_FORMATTED' => Preg::filterOnlyNumbers($contactsBlock['phone']),
- 'EMAIL' => $contactsBlock['email'],
- 'MAP_LINK' => $contactsBlock['map_link'],
- 'MAP_LINK_DESCRIPTION' => $contactsBlock['map_link_description'],
- 'NOTICE' => $pageParams['notice']
- ];
- $this->cacheManager->set(sprintf('page_contacts_%s', $this->getSiteId()), $result);
- }
- return $result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement