Advertisement
Guest User

Untitled

a guest
Jan 17th, 2020
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.12 KB | None | 0 0
  1. <?php
  2. use Kalamov\Helpers\Element;
  3. use Kalamov\Helpers\Iblock;
  4. use Kalamov\Helpers\Common;
  5. use Kalamov\Helpers\Cache;
  6. use Kalamov\Helpers\Preg;
  7.  
  8. if (!defined('B_PROLOG_INCLUDED') || B_PROLOG_INCLUDED !== true) {
  9.     die();
  10. }
  11.  
  12. class PageContactsComponent extends CBitrixComponent
  13. {
  14.     /** @var $cacheManager Cache */
  15.     protected $cacheManager;
  16.  
  17.     public function executeComponent()
  18.     {
  19.         $this->setCacheManager();
  20.  
  21.         $this->arResult = $this->shapeResult();
  22.  
  23.         $this->includeComponentTemplate();
  24.     }
  25.  
  26.     protected function setCacheManager()
  27.     {
  28.         $this->cacheManager = new Cache();
  29.     }
  30.  
  31.     protected function shapeResult()
  32.     {
  33.         if ($this->cacheManager->exists(sprintf('page_contacts_%s', $this->getSiteId()))) {
  34.             $result = $this->cacheManager->get(sprintf('page_contacts_%s', $this->getSiteId()));
  35.         } else {
  36.             $row = Element::getOneBy(
  37.                 [
  38.                     'IBLOCK_ID' => Iblock::getOneByCode('pages'),
  39.                     'CODE' => 'contacts'
  40.                 ]
  41.             );
  42.  
  43.             $contactsBlock = Common::getSpecificCustomBlock(
  44.                 $row['PROPERTIES']['CUSTOM_BLOCKS']['VALUE_DECODED'],
  45.                 'block_contacts'
  46.             );
  47.  
  48.             $pageParams = Common::getSpecificCustomBlock(
  49.                 $row['PROPERTIES']['CUSTOM_BLOCKS']['VALUE_DECODED'],
  50.                 'page_contacts'
  51.             );
  52.  
  53.             $result = [
  54.                 'PHONE_UNFORMATTED_PREFIX' => substr($contactsBlock['phone'], 0, 2),
  55.                 'PHONE_UNFORMATTED_THE_REST_OF' => substr($contactsBlock['phone'],2),
  56.                 'PHONE_FORMATTED' => Preg::filterOnlyNumbers($contactsBlock['phone']),
  57.                 'EMAIL' => $contactsBlock['email'],
  58.                 'MAP_LINK' => $contactsBlock['map_link'],
  59.                 'MAP_LINK_DESCRIPTION' => $contactsBlock['map_link_description'],
  60.                 'NOTICE' => $pageParams['notice']
  61.             ];
  62.  
  63.             $this->cacheManager->set(sprintf('page_contacts_%s', $this->getSiteId()), $result);
  64.         }
  65.  
  66.         return $result;
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement