Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezsection.php
Go to the documentation of this file.
1 <?php
17 class eZSection extends eZPersistentObject
18 {
19 public function __construct( $row )
20 {
21 if ( !isset( $row['id'] ) )
22 {
23 $row['id'] = null;
24 }
25 parent::__construct( $row );
26 }
27
31 static function definition()
32 {
33 static $definition = array( "fields" => array( "id" => array( 'name' => 'ID',
34 'datatype' => 'integer',
35 'default' => 0,
36 'required' => true ),
37 "name" => array( 'name' => "Name",
38 'datatype' => 'string',
39 'default' => 0,
40 'required' => true ),
41 "navigation_part_identifier" => array( 'name' => "NavigationPartIdentifier",
42 'datatype' => 'string',
43 'default' => 'ezcontentnavigationpart',
44 'required' => true ),
45 "locale" => array( 'name' => "Locale",
46 'datatype' => 'string',
47 'default' => '',
48 'required' => true ),
49 "identifier" => array( 'name' => "Identifier",
50 'datatype' => 'string',
51 'default' => '',
52 'required' => true ) ),
53 "keys" => array( "id" ),
54 "increment_key" => "id",
55 "class_name" => "eZSection",
56 "sort" => array( "name" => "asc" ),
57 "name" => "ezsection" );
58 return $definition;
59 }
60
64 static function fetch( $sectionID, $asObject = true )
65 {
66 global $eZContentSectionObjectCache;
67
68 // If the object given by its id is not cached or should be returned as array
69 // then we fetch it from the DB (objects are always cached as arrays).
70 if ( !isset( $eZContentSectionObjectCache[$sectionID] ) or $asObject === false )
71 {
72 $section = eZPersistentObject::fetchObject( eZSection::definition(),
73 null,
74 array( "id" => $sectionID ),
75 $asObject );
76 if ( $asObject )
77 {
78 $eZContentSectionObjectCache[$sectionID] = $section;
79 }
80 }
81 else
82 {
83 $section = $eZContentSectionObjectCache[$sectionID];
84 }
85 return $section;
86 }
87
94 static function fetchByIdentifier( $sectionIdentifier, $asObject = true )
95 {
96 global $eZContentSectionObjectCache;
97 if( !isset( $eZContentSectionObjectCache[$sectionIdentifier] ) || $asObject === false )
98 {
99 $sectionFetched = eZPersistentObject::fetchObject( eZSection::definition(),
100 null,
101 array( "identifier" => $sectionIdentifier ),
102 $asObject );
103 if( !$sectionFetched )
104 {
105 return null;
106 }
107
108 if( $asObject )
109 {
110 // the section identifier index refers to the id index object
111 $sectionID = $sectionFetched->attribute( 'id' );
112 if( !isset( $eZContentSectionObjectCache[$sectionID] ) )
113 {
114 $eZContentSectionObjectCache[$sectionID] = $sectionFetched;
115 }
116 $eZContentSectionObjectCache[$sectionIdentifier] = $eZContentSectionObjectCache[$sectionID];
117 }
118 else
119 {
120 return $sectionFetched;
121 }
122 }
123 $section = $eZContentSectionObjectCache[$sectionIdentifier];
124 return $section;
125 }
126
127 static function fetchFilteredList( $conditions = null, $offset = false, $limit = false, $asObject = true )
128 {
129 $limits = null;
130 if ( $offset or $limit )
131 $limits = array( 'offset' => $offset,
132 'length' => $limit );
133 return eZPersistentObject::fetchObjectList( eZSection::definition(),
134 null,
135 $conditions, null, $limits,
136 $asObject );
137 }
138
139 static function fetchList( $asObject = true )
140 {
141 return eZPersistentObject::fetchObjectList( eZSection::definition(),
142 null, null, null, null,
143 $asObject );
144 }
145
146 static function fetchByOffset( $offset, $limit, $asObject = true )
147 {
148 $sectionList = eZPersistentObject::fetchObjectList( eZSection::definition(),
149 null,
150 null,
151 array( 'name' => 'ASC' ),
152 array( 'offset' => $offset, 'length' => $limit ),
153 $asObject );
154 return $sectionList;
155 }
156
160 static function sectionCount()
161 {
162 $db = eZDB::instance();
163
164 $countArray = $db->arrayQuery( "SELECT count( * ) AS count FROM ezsection" );
165 return $countArray[0]['count'];
166 }
167
173 function removeThis( $conditions = null, $extraConditions = null )
174 {
175 $this->remove( array( "id" => $this->ID ), $extraConditions );
176 }
177
178 /*
179 Check if this section is allowed to remove from the system
180 */
181 function canBeRemoved( $sectionID = false )
182 {
183 if ( $sectionID === false )
184 {
185 $sectionID = $this->attribute( 'id' );
186 }
187
188 $objects = eZPersistentObject::fetchObjectList( eZContentObject::definition(), null,
189 array( 'section_id' => $sectionID ) );
190 $limitations = eZPolicyLimitation::findByType( 'Section', $sectionID, true, false );
191 $userRoles = eZRole::fetchRolesByLimitation( 'section', $sectionID );
192
193 if ( count( $objects ) > 0 or
194 count( $limitations ) > 0 or
195 count( $userRoles ) > 0 )
196 {
197 return false;
198 }
199 else
200 {
201 return true;
202 }
203 }
204
205 public function applyTo( eZContentObject $object )
206 {
207 $sectionID = $this->attribute( "id" );
208
209 $currentUser = eZUser::currentUser();
210 if ( !$currentUser->canAssignSectionToObject( $sectionID, $object ) )
211 {
212 eZDebug::writeError(
213 "You do not have permissions to assign the section <" . $this->attribute( "name" ) . "> to the object <" . $object->attribute( "name" ) . ">."
214 );
215 return false;
216 }
217
218 $db = eZDB::instance();
219 $db->begin();
220 $assignedNodes = $object->attribute( "assigned_nodes" );
221 if ( !empty( $assignedNodes ) )
222 {
223 if ( eZOperationHandler::operationIsAvailable( "content_updatesection" ) )
224 {
225 foreach ( $assignedNodes as $node )
226 {
227 eZOperationHandler::execute(
228 "content",
229 "updatesection",
230 array(
231 "node_id" => $node->attribute( "node_id" ),
232 "selected_section_id" => $sectionID
233 ),
234 null,
235 true
236 );
237 }
238 }
239 else
240 {
241 foreach ( $assignedNodes as $node )
242 {
243 eZContentOperationCollection::updateSection( $node->attribute( "node_id" ), $sectionID, false );
244 }
245 }
246 }
247 else
248 {
249 // If there are no assigned nodes we should update db for the current object.
250 $objectID = $object->attribute( "id" );
251 $db->query( "UPDATE ezcontentobject SET section_id='$sectionID' WHERE id = '$objectID'" );
252 $db->query( "UPDATE ezsearch_object_word_link SET section_id='$sectionID' WHERE contentobject_id = '$objectID'" );
253 }
254 eZContentCacheManager::clearContentCacheIfNeeded( $object->attribute( "id" ) );
255 $object->expireAllViewCache();
256 $commitResult = $db->commit();
257
258 // Update search indexes AFTER transaction is completed, so changes are actually available for Search Engine.
259 if ( $commitResult ) {
260 if ( !empty( $assignedNodes ) ) {
261 foreach ( $assignedNodes as $node ) {
262 $objectIDArray = eZContentObjectTreeNode::getObjectIdsInNodeSubTree( $node );
263
264 if ( is_array( $objectIDArray ) )
265 {
266 foreach (array_chunk($objectIDArray, 100) as $pagedObjectIDs) {
267 // Clear cache of affected objects in sub tree so they are up-to-date when indexed.
268 eZContentCacheManager::clearObjectViewCacheArray($pagedObjectIDs);
269 eZSearch::updateObjectsSection($pagedObjectIDs, $sectionID);
270 }
271 }
272 }
273 } else {
274 eZSearch::updateObjectsSection(array($object->attribute("id")), $sectionID);
275 }
276 }
277 }
278 }
279
280 ?>
eZContentCacheManager\clearContentCacheIfNeeded
static clearContentCacheIfNeeded( $objectID, $versionNum=true, $additionalNodeList=false)
Definition: ezcontentcachemanager.php:1062
eZContentCacheManager\clearObjectViewCacheArray
static clearObjectViewCacheArray(array $objectIDList)
Definition: ezcontentcachemanager.php:711
eZContentObjectTreeNode\getObjectIdsInNodeSubTree
static getObjectIdsInNodeSubTree($node)
Definition: ezcontentobjecttreenode.php:6446
eZContentObject
Definition: ezcontentobject.php:17
eZContentObject\definition
static definition()
Definition: ezcontentobject.php:100
eZContentObject\expireAllViewCache
static expireAllViewCache()
Definition: ezcontentobject.php:5932
eZDB\instance
static instance( $databaseImplementation=false, $databaseParameters=false, $forceNewInstance=false)
Definition: ezdb.php:117
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:545
eZOperationHandler\operationIsAvailable
static operationIsAvailable( $name)
Definition: ezoperationhandler.php:59
eZOperationHandler\execute
static execute( $moduleName, $operationName, $operationParameters, $lastTriggerName=null, $useTriggers=true)
Definition: ezoperationhandler.php:42
eZPersistentObject
Definition: ezpersistentobject.php:33
eZPersistentObject\fetchObject
static fetchObject( $def, $field_filters, $conds, $asObject=true, $grouping=null, $custom_fields=null)
Definition: ezpersistentobject.php:213
eZPersistentObject\count
static count( $def, $conds=null, $field=null)
Definition: ezpersistentobject.php:187
eZPersistentObject\attribute
attribute( $attr, $noFunction=false)
Definition: ezpersistentobject.php:1329
eZPersistentObject\fetchObjectList
static fetchObjectList( $def, $field_filters=null, $conds=null, $sorts=null, $limit=null, $asObject=true, $grouping=false, $custom_fields=null, $custom_tables=null, $custom_conds=null)
Definition: ezpersistentobject.php:806
eZPolicyLimitation\findByType
static findByType( $type, $value, $asObject=true, $useLike=true)
Definition: ezpolicylimitation.php:351
eZRole\fetchRolesByLimitation
static fetchRolesByLimitation( $limit_identifier, $limit_value)
Definition: ezrole.php:835
eZSearch\updateObjectsSection
static updateObjectsSection(array $objectIDs, $sectionID)
Definition: ezsearch.php:504
eZSection
eZSection handles grouping of content in eZ Publish
Definition: ezsection.php:18
eZSection\removeThis
removeThis( $conditions=null, $extraConditions=null)
Definition: ezsection.php:173
eZSection\fetchByOffset
static fetchByOffset( $offset, $limit, $asObject=true)
Definition: ezsection.php:146
eZSection\__construct
__construct( $row)
Definition: ezsection.php:19
eZSection\sectionCount
static sectionCount()
Definition: ezsection.php:160
eZSection\canBeRemoved
canBeRemoved( $sectionID=false)
Definition: ezsection.php:181
eZSection\fetchFilteredList
static fetchFilteredList( $conditions=null, $offset=false, $limit=false, $asObject=true)
Definition: ezsection.php:127
eZSection\fetchList
static fetchList( $asObject=true)
Definition: ezsection.php:139
eZSection\definition
static definition()
Definition: ezsection.php:31
eZSection\fetch
static fetch( $sectionID, $asObject=true)
Definition: ezsection.php:64
eZSection\applyTo
applyTo(eZContentObject $object)
Definition: ezsection.php:205
eZSection\fetchByIdentifier
static fetchByIdentifier( $sectionIdentifier, $asObject=true)
Definition: ezsection.php:94
eZUser\currentUser
static currentUser()
Definition: ezuser.php:1716
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.