00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 include_once( "kernel/classes/ezpersistentobject.php" );
00038
00039 class eZSection extends eZPersistentObject
00040 {
00041
00042
00043 function eZSection( $row )
00044 {
00045 $this->eZPersistentObject( $row );
00046 }
00047
00048
00049
00050
00051 function definition()
00052 {
00053 return array( "fields" => array( "id" => array( 'name' => 'ID',
00054 'datatype' => 'integer',
00055 'default' => 0,
00056 'required' => true ),
00057 "name" => array( 'name' => "Name",
00058 'datatype' => 'string',
00059 'default' => 0,
00060 'required' => true ),
00061 "navigation_part_identifier" => array( 'name' => "NavigationPartIdentifier",
00062 'datatype' => 'string',
00063 'default' => 'ezcontentnavigationpart',
00064 'required' => true ),
00065 "locale" => array( 'name' => "Locale",
00066 'datatype' => 'string',
00067 'default' => '',
00068 'required' => true ) ),
00069 "keys" => array( "id" ),
00070 "increment_key" => "id",
00071 "class_name" => "eZSection",
00072 "name" => "ezsection" );
00073 }
00074
00075
00076
00077
00078 function fetch( $sectionID, $asObject = true )
00079 {
00080 global $eZContentSectionObjectCache;
00081
00082
00083
00084 if ( !isset( $eZContentSectionObjectCache[$sectionID] ) or $asObject === false )
00085 {
00086 $section = eZPersistentObject::fetchObject( eZSection::definition(),
00087 null,
00088 array( "id" => $sectionID ),
00089 $asObject );
00090 if ( $asObject )
00091 {
00092 $eZContentSectionObjectCache[$sectionID] = $section;
00093 }
00094 }
00095 else
00096 {
00097 $section = $eZContentSectionObjectCache[$sectionID];
00098 }
00099 return $section;
00100 }
00101
00102 function fetchFilteredList( $conditions = null, $offset = false, $limit = false, $asObject = true )
00103 {
00104 $limits = null;
00105 if ( $offset or $limit )
00106 $limits = array( 'offset' => $offset,
00107 'length' => $limit );
00108 return eZPersistentObject::fetchObjectList( eZSection::definition(),
00109 null,
00110 $conditions, null, $limits,
00111 $asObject );
00112 }
00113
00114 function fetchList( $asObject = true )
00115 {
00116 return eZPersistentObject::fetchObjectList( eZSection::definition(),
00117 null, null, null, null,
00118 $asObject );
00119 }
00120
00121 function &fetchByOffset( $offset, $limit, $asObject = true )
00122 {
00123 $sectionList = eZPersistentObject::fetchObjectList( eZSection::definition(),
00124 null,
00125 null,
00126 array( 'name' => 'ASC' ),
00127 array( 'offset' => $offset, 'length' => $limit ),
00128 $asObject );
00129 return $sectionList;
00130 }
00131
00132
00133
00134
00135 function sectionCount()
00136 {
00137 $db =& eZDB::instance();
00138
00139 $countArray = $db->arrayQuery( "SELECT count( * ) AS count FROM ezsection" );
00140 return $countArray[0]['count'];
00141 }
00142
00143
00144
00145
00146 function initGlobalID()
00147 {
00148 global $eZSiteBasics;
00149 $sessionRequired = $eZSiteBasics['session-required'];
00150 $sectionID = false;
00151 if ( $sessionRequired )
00152 {
00153 include_once( 'lib/ezutils/classes/ezhttptool.php' );
00154 $sectionArray = array();
00155 if ( eZHTTPTool::hasSessionVariable( 'eZGlobalSection' ) )
00156 $sectionArray = eZHTTPTool::sessionVariable( 'eZGlobalSection' );
00157 if ( !isset( $sectionArray['id'] ) )
00158 {
00159 return false;
00160 }
00161 $sectionID = $sectionArray['id'];
00162 }
00163
00164 if ( $sectionID )
00165 {
00166
00167 $GLOBALS['eZDesignKeys']['section'] = $sectionID;
00168 return true;
00169 }
00170 return false;
00171 }
00172
00173
00174
00175
00176
00177 function setGlobalID( $sectionID )
00178 {
00179 include_once( 'lib/ezutils/classes/ezhttptool.php' );
00180 $sectionArray = array();
00181 if ( eZHTTPTool::hasSessionVariable( 'eZGlobalSection' ) )
00182 $sectionArray = eZHTTPTool::sessionVariable( 'eZGlobalSection' );
00183 $sectionArray['id'] = $sectionID;
00184 eZHTTPTool::setSessionVariable( 'eZGlobalSection', $sectionArray );
00185
00186
00187 $GLOBALS['eZDesignKeys']['section'] = $sectionID;
00188 }
00189
00190
00191
00192
00193 function globalID()
00194 {
00195 include_once( 'lib/ezutils/classes/ezhttptool.php' );
00196 if ( eZHTTPTool::hasSessionVariable( 'eZGlobalSection' ) )
00197 {
00198 $sectionArray = eZHTTPTool::sessionVariable( 'eZGlobalSection' );
00199 if ( isset( $sectionArray['id'] ) )
00200 return $sectionArray['id'];
00201 }
00202 return null;
00203 }
00204
00205
00206
00207
00208
00209
00210 function remove( )
00211 {
00212 $def = $this->definition();
00213 eZPersistentObject::removeObject( $def, array( "id" => $this->ID ) );
00214 }
00215
00216
00217
00218
00219 function canBeRemoved( $sectionID = false )
00220 {
00221 if ( $sectionID === false )
00222 {
00223 $sectionID = $this->attribute( 'id' );
00224 }
00225
00226 $objects = eZPersistentObject::fetchObjectList( eZContentObject::definition(), null,
00227 array( 'section_id' => $sectionID ) );
00228 include_once( 'kernel/classes/ezpolicylimitation.php' );
00229 $limitations = eZPolicyLimitation::findByType( 'Section', $sectionID, true, false );
00230 include_once( 'kernel/classes/ezrole.php' );
00231 $userRoles = eZRole::fetchRolesByLimitation( 'section', $sectionID );
00232
00233 if ( count( $objects ) > 0 or
00234 count( $limitations ) > 0 or
00235 count( $userRoles ) > 0 )
00236 {
00237 return false;
00238 }
00239 else
00240 {
00241 return true;
00242 }
00243 }
00244
00245 }
00246
00247 ?>