Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
datacounter.php
1<?php
9
11
17{
19 public $data;
20
26 public function __construct(array $data)
27 {
28 $this->data = array();
29 $types = Recipient\Type::getList();
30 foreach ($data as $typeId => $count)
31 {
32 if (is_numeric($typeId))
33 {
34 $typeId = (int) $typeId;
35 }
36 $typeId = $typeId ?: Recipient\Type::EMAIL;
37 $typeId = is_numeric($typeId) ? $typeId : Recipient\Type::getId($typeId);
38 if ($typeId && !in_array($typeId, $types))
39 {
40 continue;
41 }
42
43 $this->data[$typeId] = (int) $count;
44 }
45 }
46
52 public function getSummary()
53 {
54 $summary = 0;
55 foreach ($this->data as $typeId => $count)
56 {
57 $summary += $count;
58 }
59
60 return $summary;
61 }
62
69 public function getCount($typeId)
70 {
71 return isset($this->data[$typeId]) ? $this->data[$typeId] : 0;
72 }
73
80 public function leave($leaveTypeId = null)
81 {
82 if (!$leaveTypeId)
83 {
84 return $this;
85 }
86
87 foreach ($this->data as $typeId => $count)
88 {
89 if ($leaveTypeId == $typeId)
90 {
91 continue;
92 }
93
94 unset($this->data[$typeId]);
95 }
96
97 return $this;
98 }
99
105 public function getList()
106 {
107 return $this->data;
108 }
109
115 public function getArray()
116 {
117 $counters = array();
118 foreach ($this->data as $typeId => $count)
119 {
120 $counters[] = array(
121 'typeId' => $typeId,
122 'typeCode' => Recipient\Type::getCode($typeId),
123 'typeName' => Recipient\Type::getName($typeId),
124 'count' => $count
125 );
126 }
127
128 $result = self::getDefaultArray();
129 $result['summary'] = $this->getSummary();
130 $result['counters'] = $counters;
131
132 return $result;
133 }
134
140 public function getArrayCounters()
141 {
142 $counters = array();
143 foreach ($this->data as $typeId => $count)
144 {
145 $counters[$typeId] = $count;
146 }
147
148 return $counters;
149 }
150
156 public static function getDefaultArray()
157 {
158 return array(
159 'summary' => 0,
160 'counters' => array()
161 );
162 }
163}
getName()