Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

Core/Persistence/Legacy/Content/Section/Handler.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\Persistence\Legacy\Content\Section;
8
9 use eZ\Publish\SPI\Persistence\Content\Section\Handler as BaseSectionHandler;
10 use eZ\Publish\SPI\Persistence\Content\Section;
11 use eZ\Publish\Core\Base\Exceptions\NotFoundException as NotFound;
12 use RuntimeException;
13
17 class Handler implements BaseSectionHandler
18 {
24 protected $sectionGateway;
25
31 public function __construct(Gateway $sectionGateway)
32 {
33 $this->sectionGateway = $sectionGateway;
34 }
35
44 public function create($name, $identifier)
45 {
46 $section = new Section();
47
48 $section->name = $name;
49 $section->identifier = $identifier;
50
51 $section->id = $this->sectionGateway->insertSection($name, $identifier);
52
53 return $section;
54 }
55
65 public function update($id, $name, $identifier)
66 {
67 $this->sectionGateway->updateSection($id, $name, $identifier);
68
69 $section = new Section();
70 $section->id = $id;
71 $section->name = $name;
72 $section->identifier = $identifier;
73
74 return $section;
75 }
76
86 public function load($id)
87 {
88 $rows = $this->sectionGateway->loadSectionData($id);
89
90 if (empty($rows)) {
91 throw new NotFound('Section', $id);
92 }
93
94 return $this->createSectionFromArray(reset($rows));
95 }
96
102 public function loadAll()
103 {
104 $rows = $this->sectionGateway->loadAllSectionData();
105
106 return $this->createSectionsFromArray($rows);
107 }
108
118 public function loadByIdentifier($identifier)
119 {
120 $rows = $this->sectionGateway->loadSectionDataByIdentifier($identifier);
121
122 if (empty($rows)) {
123 throw new NotFound('Section', $identifier);
124 }
125
126 return $this->createSectionFromArray(reset($rows));
127 }
128
136 protected function createSectionFromArray(array $data)
137 {
138 $section = new Section();
139
140 $section->id = (int)$data['id'];
141 $section->name = $data['name'];
142 $section->identifier = $data['identifier'];
143
144 return $section;
145 }
146
154 protected function createSectionsFromArray(array $data)
155 {
156 $sections = [];
157 foreach ($data as $sectionData) {
158 $sections[] = $this->createSectionFromArray($sectionData);
159 }
160
161 return $sections;
162 }
163
173 public function delete($id)
174 {
175 $contentCount = $this->sectionGateway->countContentObjectsInSection($id);
176
177 if ($contentCount > 0) {
178 throw new RuntimeException(
179 "Section with ID '{$id}' still has content assigned."
180 );
181 }
182 $this->sectionGateway->deleteSection($id);
183 }
184
191 public function assign($sectionId, $contentId)
192 {
193 $this->sectionGateway->assignSectionToContent($sectionId, $contentId);
194 }
195
203 public function assignmentsCount($sectionId)
204 {
205 return $this->sectionGateway->countContentObjectsInSection($sectionId);
206 }
207
215 public function policiesCount($sectionId)
216 {
217 return $this->sectionGateway->countPoliciesUsingSection($sectionId);
218 }
219
227 public function countRoleAssignmentsUsingSection($sectionId)
228 {
229 return $this->sectionGateway->countRoleAssignmentsUsingSection($sectionId);
230 }
231 }
eZ\Publish\Core\Base\Exceptions\NotFoundException
Not Found Exception implementation.
Definition: Core/Base/Exceptions/NotFoundException.php:21
eZ\Publish\Core\Persistence\Legacy\Content\Section\Gateway
Section Handler.
Definition: Persistence/Legacy/Content/Section/Gateway.php:13
eZ\Publish\Core\Persistence\Legacy\Content\Section\Handler
Section Handler.
Definition: Core/Persistence/Legacy/Content/Section/Handler.php:18
eZ\Publish\Core\Persistence\Legacy\Content\Section\Handler\assign
assign($sectionId, $contentId)
Assigns section to single content object.
Definition: Core/Persistence/Legacy/Content/Section/Handler.php:191
eZ\Publish\Core\Persistence\Legacy\Content\Section\Handler\createSectionFromArray
createSectionFromArray(array $data)
Creates a Section from the given $data.
Definition: Core/Persistence/Legacy/Content/Section/Handler.php:136
eZ\Publish\Core\Persistence\Legacy\Content\Section\Handler\countRoleAssignmentsUsingSection
countRoleAssignmentsUsingSection($sectionId)
Counts the number of role assignments using section with $sectionId in their limitations.
Definition: Core/Persistence/Legacy/Content/Section/Handler.php:227
eZ\Publish\Core\Persistence\Legacy\Content\Section\Handler\assignmentsCount
assignmentsCount($sectionId)
Number of content assignments a Section has.
Definition: Core/Persistence/Legacy/Content/Section/Handler.php:203
eZ\Publish\Core\Persistence\Legacy\Content\Section\Handler\load
load($id)
Get section data.
Definition: Core/Persistence/Legacy/Content/Section/Handler.php:86
eZ\Publish\Core\Persistence\Legacy\Content\Section\Handler\__construct
__construct(Gateway $sectionGateway)
Creates a new Section Handler.
Definition: Core/Persistence/Legacy/Content/Section/Handler.php:31
eZ\Publish\Core\Persistence\Legacy\Content\Section\Handler\policiesCount
policiesCount($sectionId)
Number of role policies using a Section in limitations.
Definition: Core/Persistence/Legacy/Content/Section/Handler.php:215
eZ\Publish\Core\Persistence\Legacy\Content\Section\Handler\loadByIdentifier
loadByIdentifier($identifier)
Get section data by identifier.
Definition: Core/Persistence/Legacy/Content/Section/Handler.php:118
eZ\Publish\Core\Persistence\Legacy\Content\Section\Handler\$sectionGateway
$sectionGateway
Definition: Core/Persistence/Legacy/Content/Section/Handler.php:24
eZ\Publish\Core\Persistence\Legacy\Content\Section\Handler\update
update($id, $name, $identifier)
Update name and identifier of a section.
Definition: Core/Persistence/Legacy/Content/Section/Handler.php:65
eZ\Publish\Core\Persistence\Legacy\Content\Section\Handler\loadAll
loadAll()
Get all section data.
Definition: Core/Persistence/Legacy/Content/Section/Handler.php:102
eZ\Publish\Core\Persistence\Legacy\Content\Section\Handler\create
create($name, $identifier)
Create a new section.
Definition: Core/Persistence/Legacy/Content/Section/Handler.php:44
eZ\Publish\Core\Persistence\Legacy\Content\Section\Handler\createSectionsFromArray
createSectionsFromArray(array $data)
Creates a Section from the given $data.
Definition: Core/Persistence/Legacy/Content/Section/Handler.php:154
eZ\Publish\SPI\Persistence\Content\Section
Definition: SPI/Persistence/Content/Section.php:12
eZ\Publish\SPI\Persistence\Content\Section\Handler
Definition: SPI/Persistence/Content/Section/Handler.php:10
eZ\Publish\SPI\Persistence\Content\Section
Definition: SPI/Persistence/Content/Section/Handler.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.