Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CanViewNotification.php
Go to the documentation of this file.
1 <?php
7 
13 
19 {
25  private static $conditionName = 'can_view_notification';
26 
32  private static $cachePrefix = 'release-notification-popup-';
33 
37  private $viewerLogger;
38 
42  private $session;
43 
47  private $productMetadata;
48 
52  private $cacheStorage;
53 
62  public function __construct(
63  Logger $viewerLogger,
64  Session $session,
65  ProductMetadataInterface $productMetadata,
66  CacheInterface $cacheStorage
67  ) {
68  $this->viewerLogger = $viewerLogger;
69  $this->session = $session;
70  $this->productMetadata = $productMetadata;
71  $this->cacheStorage = $cacheStorage;
72  }
73 
79  public function isVisible(array $arguments)
80  {
81  $userId = $this->session->getUser()->getId();
82  $cacheKey = self::$cachePrefix . $userId;
83  $value = $this->cacheStorage->load($cacheKey);
84  if ($value === false) {
85  $value = version_compare(
86  $this->viewerLogger->get($userId)->getLastViewVersion(),
87  $this->productMetadata->getVersion(),
88  '<'
89  );
90  $this->cacheStorage->save(false, $cacheKey);
91  }
92  return (bool)$value;
93  }
94 
100  public function getName()
101  {
102  return self::$conditionName;
103  }
104 }
$value
Definition: gender.phtml:16
__construct(Logger $viewerLogger, Session $session, ProductMetadataInterface $productMetadata, CacheInterface $cacheStorage)
$arguments