1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
SectionCollection.php
См. документацию.
1<?php
2
3namespace Bitrix\Catalog\v2\Section;
4
5use Bitrix\Catalog\v2\BaseCollection;
6use Bitrix\Main\Result;
7use Bitrix\Main\Type;
8
18{
20 protected $factory;
22 protected $repository;
23
25 {
26 $this->factory = $factory;
27 $this->repository = $repository;
28 }
29
34 public function setValues(array $values): self
35 {
36 // ToDo recalculate already loaded properties on section modifications?
37 $currentValues = $this->getValues();
38 $filteredValues = $this->filterValues($values);
39
40 $oldValuesToRemove = array_diff($currentValues, $filteredValues);
41
42 if (!empty($oldValuesToRemove))
43 {
44 $oldSections = [];
45
47 foreach ($this->getIterator() as $item)
48 {
49 if (in_array($item->getValue(), $oldValuesToRemove, true))
50 {
51 $oldSections[] = $item;
52 }
53 }
54
55 $this->remove(...$oldSections);
56 }
57
58 $newValuesToAdd = array_diff($filteredValues, $currentValues);
59
60 if (!empty($newValuesToAdd))
61 {
62 $newSections = [];
63
64 foreach ($newValuesToAdd as $value)
65 {
66 $newSections[] = $this
67 ->factory
68 ->createEntity()
69 ->setValue($value)
70 ;
71 }
72
73 $this->add(...$newSections);
74 }
75
76 return $this;
77 }
78
79 public function getValues(): array
80 {
81 $values = [];
82
84 foreach ($this->getIterator() as $item)
85 {
86 $values[] = $item->getValue();
87 }
88
89 return $values;
90 }
91
92 private function filterValues(array $values): array
93 {
94 Type\Collection::normalizeArrayValuesByInt($values);
95
96 return $values;
97 }
98
99 public function saveInternal(): Result
100 {
101 $result = new Result();
102
103 if ($this->isChanged())
104 {
105 $res = $this->repository->save(...$this->getIterator());
106
107 if ($res->isSuccess())
108 {
109 $this->clearChanged();
110 }
111 else
112 {
113 $result->addErrors($res->getErrors());
114 }
115 }
116
117 return $result;
118 }
119}
add(BaseEntity ... $items)
Определения BaseCollection.php:50
__construct(SectionFactory $factory, SectionRepositoryContract $repository)
Определения SectionCollection.php:24
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$result
Определения get_property_values.php:14
if($request->isPost() && $currentAction !==null &&check_bitrix_sessid()) $currentValues
Определения options.php:198