1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
entitylink.php
См. документацию.
1<?php
2
4
5use Bitrix\Crm\Service\Container;
8use CCrmOwnerType;
9
10Loader::requireModule('crm');
11
16{
17 private int $entityTypeId;
18 private int $entityId;
19 private string $href;
20
26 public function __construct(int $entityTypeId, int $entityId, string $href)
27 {
28 $this->entityTypeId = $entityTypeId;
29 $this->entityId = $entityId;
30 $this->href = $href;
31 }
32
45 public static function createByOrder(int $orderId, string $link): self
46 {
47 $entityId = $orderId;
48 $entityTypeId = CCrmOwnerType::Undefined;
49
50 $order = \Bitrix\Crm\Order\Order::load($orderId);
51 if ($order)
52 {
53 $binding = $order->getEntityBinding();
54 if ($binding)
55 {
56 $entityId = $binding->getOwnerId();
57 $entityTypeId = $binding->getOwnerTypeId();
58 }
59 else
60 {
61 $entityId = $orderId;
62 $entityTypeId = CCrmOwnerType::Order;
63 }
64 }
65
66 return new static($entityTypeId, $entityId, $link);
67 }
68
74 private function getLabel(): string
75 {
76 // we process orders separately, because the factory does not know how to work with items.
77 if ($this->entityTypeId === CCrmOwnerType::Order)
78 {
79 $description = CCrmOwnerType::GetDescription($this->entityTypeId);
80
81 return "{$description} #{$this->entityId}";
82 }
83
84 $factory = Container::getInstance()->getFactory($this->entityTypeId);
85 if ($factory)
86 {
87 $item = $factory->getItem($this->entityId);
88 if ($item)
89 {
90 $title = $item->getHeading();
91 if ($title)
92 {
93 return $title;
94 }
95 }
96 }
97
98 return $this->entityId;
99 }
100
106 public function render(): string
107 {
108 $href = HtmlFilter::encode($this->href);
109
110 $sanitizer = new \CBXSanitizer();
111 $sanitizer->setLevel(\CBXSanitizer::SECURE_LEVEL_HIGH);
112 $sanitizer->ApplyDoubleEncode(false);
113
114 $label = $sanitizer->SanitizeHtml($this->getLabel());
115
116 unset($sanitizer);
117
118 if (!$href)
119 {
120 return $label;
121 }
122
123 return '<a href="' . $href . '">' . $label . '</a>';
124 }
125}
Определения loader.php:13
static encode($string, $flags=ENT_COMPAT, $doubleEncode=true)
Определения htmlfilter.php:12
const SECURE_LEVEL_HIGH
Определения sanitizer.php:28
$orderId
Определения payment.php:5
if(Loader::includeModule( 'bitrix24')) elseif(Loader::includeModule('intranet') &&CIntranetUtils::getPortalZone() !=='ru') $description
Определения .description.php:24
$order
Определения payment.php:8
$entityId
Определения payment.php:4
$title
Определения pdf.php:123