1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
counter.php
См. документацию.
1<?php declare(strict_types=1);
2
4
5class Counter
6{
7 public function __construct(
8 public readonly bool $useAirDesign = false,
9 public readonly CounterStyle $style = CounterStyle::FILLED_ALERT,
10 public readonly int $value = 0,
11 public readonly int $maxValue = 99,
12 public readonly CounterColor $color = CounterColor::PRIMARY,
13 public readonly CounterColor $secondaryColor = CounterColor::PRIMARY,
14 public readonly bool $border = false,
15 public readonly CounterSize $size = CounterSize::MEDIUM,
16 public readonly bool $isDouble = false,
17 public readonly bool $usePercentSymbol = false,
18 public readonly string $id = '',
19 public readonly bool $hideIfZero = false,
20 ) {
21 }
22
23 public function render(): string
24 {
25 $classes = ['ui-counter', 'ui-counter__scope'];
26
27 if ($this->useAirDesign)
28 {
29 $classes[] = '--air';
30 }
31
32 if ($this->border)
33 {
34 $classes[] = 'ui-counter-border';
35 }
36
37 if ($this->value < 10 && !$this->usePercentSymbol)
38 {
39 $classes[] = '--one-digit';
40 }
41
42 if ($this->hideIfZero)
43 {
44 $classes[] = '--hide-zero';
45 }
46
47 $classes[] = $this->color->value;
48 $classes[] = $this->size->value;
49 $classes[] = $this->style->value;
50
51 $classString = implode(' ', $classes);
52 $id = $this->id ?? '';
53 $html = sprintf(
54 '<div id="%s" class="%s" data-value="%s">',
56 htmlspecialcharsbx($classString),
57 htmlspecialcharsbx($this->value)
58 );
59 $html .= $this->getInnerHtml();
60
61 if ($this->isDouble)
62 {
63 $html .= sprintf(
64 '<div class="ui-counter-secondary %s"></div>',
65 htmlspecialcharsbx($this->secondaryColor->value),
66 );
67 }
68
69 $html .= '</div>';
70
71 return $html;
72 }
73
74 private function getInnerHtml(): string
75 {
76 if ($this->useAirDesign)
77 {
78 $symbol = '';
79 $displayValue = $this->value;
80
81 if ($this->usePercentSymbol)
82 {
83 $symbol = '%';
84 }
85 elseif ($this->value > $this->maxValue)
86 {
87 $displayValue = $this->maxValue;
88 $symbol = '+';
89 }
90
91 return sprintf(
92 '<div class="ui-counter-inner"><span class="ui-counter__value">%s</span><span class="ui-counter__symbol">%s</span></div>',
93 htmlspecialcharsbx($displayValue),
94 htmlspecialcharsbx($symbol),
95 );
96 }
97
98 $percentSymbol = $this->usePercentSymbol ? '%' : '';
99
100 return sprintf(
101 '<div class="ui-counter-inner">%s%s</div>',
102 htmlspecialcharsbx((string)$this->getValue()),
103 htmlspecialcharsbx($percentSymbol),
104 );
105 }
106
107 private function getValue(): string|int
108 {
109 if ($this->usePercentSymbol)
110 {
111 return $this->value;
112 }
113
114 if ($this->value <= $this->maxValue)
115 {
116 return $this->value;
117 }
118
119 return $this->maxValue . '+';
120 }
121}
__construct(public readonly bool $useAirDesign=false, public readonly CounterStyle $style=CounterStyle::FILLED_ALERT, public readonly int $value=0, public readonly int $maxValue=99, public readonly CounterColor $color=CounterColor::PRIMARY, public readonly CounterColor $secondaryColor=CounterColor::PRIMARY, public readonly bool $border=false, public readonly CounterSize $size=CounterSize::MEDIUM, public readonly bool $isDouble=false, public readonly bool $usePercentSymbol=false, public readonly string $id='', public readonly bool $hideIfZero=false,)
Определения counter.php:7
render()
Определения counter.php:23
background color
Определения file_new.php:745
htmlspecialcharsbx($string, $flags=ENT_COMPAT, $doubleEncode=true)
Определения tools.php:2701
Определения counter.php:3
CounterSize
Определения countersize.php:6
@ MEDIUM
Определения countersize.php:9
CounterColor
Определения countercolor.php:6
CounterStyle
Определения counterstyle.php:6
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
font style
Определения invoice.php:442
font size
Определения invoice.php:442