1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
Promotion.php
См. документацию.
1<?php
2
3declare(strict_types=1);
4
5namespace Bitrix\Im\V2\Promotion;
6
7use Bitrix\Im\V2\Promotion\Entity\PromotionList;
8use Bitrix\Im\V2\Promotion\Event\Update\PromotionUpdateData;
9use Bitrix\Im\V2\Promotion\Event\Update\PromotionUpdateEvent;
10use Bitrix\Im\V2\Promotion\Internals\DeviceType;
11use Bitrix\Im\V2\Promotion\Service\PromotionServiceInterface;
12use Bitrix\Main\Config\Option;
13use Bitrix\Main\DI\ServiceLocator;
14use Bitrix\Main\Result;
15use Bitrix\Main\Validation\ValidationService;
16
18{
20 private array $serviceList;
21 private ValidationService $vavidation;
22
23 public function __construct()
24 {
25 $this->serviceList = PromotionServiceFactory::getServiceList();
26 $this->vavidation = ServiceLocator::getInstance()->get('main.validation.service');
27 }
28
29 public function getActive(DeviceType $type = DeviceType::ALL): PromotionList
30 {
31 $promotionList = new PromotionList();
32
33 if (self::isUnavailable())
34 {
35 return $promotionList;
36 }
37
38 foreach ($this->serviceList as $service)
39 {
40 $promotionList->merge($service->getActive($type));
41 }
42
43 return $promotionList;
44 }
45
46 public function markAsViewed(Entity\Promotion $promotion): Result
47 {
48 $validationResult = $this->vavidation->validate($promotion);
49 if (!$validationResult->isSuccess())
50 {
51 return $validationResult;
52 }
53
54 return PromotionServiceFactory::create($promotion->getId())->markAsViewed($promotion);
55 }
56
58 public function handlePromotionUpdate(array $sortedByUserData): void
59 {
60 if (empty($sortedByUserData))
61 {
62 return;
63 }
64
65 $event = new PromotionUpdateEvent($sortedByUserData);
66 $event->send();
67 }
68
69 public static function isUnavailable(): bool
70 {
71 return Option::get('im', 'promo_disabled', 'N') === 'Y';
72 }
73}
$type
Определения options.php:106
getActive(DeviceType $type=DeviceType::ALL)
Определения Promotion.php:29
static isUnavailable()
Определения Promotion.php:69
markAsViewed(Entity\Promotion $promotion)
Определения Promotion.php:46
handlePromotionUpdate(array $sortedByUserData)
Определения Promotion.php:58
static create(string $promotionId)
Определения PromotionServiceFactory.php:22
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$service
Определения payment.php:18
$event
Определения prolog_after.php:141