1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
save.php
См. документацию.
1<?php
2
3namespace Bitrix\Location\Repository\Location\Strategy;
4
5use Bitrix\Location\Entity\Location;
6use Bitrix\Location\Repository\Location\Capability\ISaveParents;
7use Bitrix\Location\Repository\Location\IRepository;
8use Bitrix\Location\Repository\Location\ICache;
9use Bitrix\Location\Repository\Location\IDatabase;
10use Bitrix\Location\Repository\Location\Capability\ISave;
11use Bitrix\Location\Repository\Location\Strategy\Save\NewItem;
12use Bitrix\Main\Result;
13
18class Save
19 extends Base
20 implements ISave, ISaveParents
21{
23 protected $locationRepositories = [];
24
27 {
28 $idx = 0;
29
30 foreach($locationRepositories as $repository)
31 {
32 if($repository instanceof ISave)
33 {
34 $key = (string)$this->getRepoPriority($repository) . (string)($idx++);
35 $this->locationRepositories[$key] = $repository;
36 }
37 }
38
39 ksort($this->locationRepositories);
40 return $this;
41 }
42
47 protected function getRepoPriority(IRepository $repository)
48 {
49 if($repository instanceof IDatabase)
50 {
51 $result = self::REPO_PRIORITY_A;
52 }
53 elseif($repository instanceof ICache)
54 {
55 $result = self::REPO_PRIORITY_B;
56 }
57 else
58 {
59 $result = self::REPO_PRIORITY_C;
60 }
61
62 return $result;
63 }
64
72 public function save(Location $location): Result
73 {
74 if($location->getId() <= 0)
75 {
76 return (new NewItem($this->locationRepositories))
77 ->save($location);
78 }
79
80 $result = new Result();
81
82 foreach($this->locationRepositories as $repository)
83 {
84 $res = $repository->save($location);
85
86 if(!$res->isSuccess())
87 {
88 $result->addErrors($res->getErrors());
89 }
90 }
91
92 if($parents = $location->getParents())
93 {
94 $res = $this->saveParents($parents);
95
96 if (!$res->isSuccess())
97 {
98 $result->addErrors($res->getErrors());
99 }
100 }
101
102 return $result;
103 }
104
105 public function saveParents(Location\Parents $parents): Result
106 {
107 $result = new Result();
108
109 foreach($this->locationRepositories as $repository)
110 {
111 if($repository instanceof ISaveParents)
112 {
113 $res = $repository->saveParents($parents);
114
115 if (!$res->isSuccess())
116 {
117 $result->addErrors($res->getErrors());
118 }
119 }
120 }
121
122 return $result;
123 }
124}
getRepoPriority(IRepository $repository)
Определения save.php:47
saveParents(Location\Parents $parents)
Определения save.php:105
setLocationRepositories(array $locationRepositories)
Определения save.php:26
save(Location $location)
Определения save.php:72
</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( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
if(empty($signedUserToken)) $key
Определения quickway.php:257
$location
Определения options.php:2729