Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
BarcodeCollection.php
1<?php
2
4
9
19{
21 protected $container;
23 protected $factory;
24
26 {
27 $this->container = $container;
28 $this->factory = $factory;
29 }
30
31 public function create(): Barcode
32 {
33 $barcode = $this->factory->createEntity();
34 $this->add($barcode);
35
36 return $barcode;
37 }
38
39 public function getItemByBarcode(string $barcode): ?Barcode
40 {
42 foreach ($this->items as $item)
43 {
44 if ($barcode === $item->getBarcode())
45 {
46 return $item;
47 }
48 }
49
50 return null;
51 }
52
53 public function setSimpleBarcodeValue(string $value = ''): self
54 {
55 $barcodeItem = $this->getFirst();
56 if ($value !== '')
57 {
58 if (!$barcodeItem)
59 {
60 $barcodeItem = $this->create();
61 $this->add($barcodeItem);
62 }
63
64 $barcodeItem->setBarcode($value);
65
66 }
67 elseif ($barcodeItem)
68 {
69 $barcodeItem->remove();
70 }
71
72 return $this;
73 }
74}
__construct(ContainerContract $container, BarcodeFactory $factory)
getFirst(callable $callback=null)