eZ Publish  [4.0]
ezsection.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Definition of eZSection class
00004 //
00005 // Created on: <27-Aug-2002 15:55:18 bf>
00006 //
00007 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00008 // SOFTWARE NAME: eZ Publish
00009 // SOFTWARE RELEASE: 4.0.x
00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS
00011 // SOFTWARE LICENSE: GNU General Public License v2.0
00012 // NOTICE: >
00013 //   This program is free software; you can redistribute it and/or
00014 //   modify it under the terms of version 2.0  of the GNU General
00015 //   Public License as published by the Free Software Foundation.
00016 //
00017 //   This program is distributed in the hope that it will be useful,
00018 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 //   GNU General Public License for more details.
00021 //
00022 //   You should have received a copy of version 2.0 of the GNU General
00023 //   Public License along with this program; if not, write to the Free
00024 //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00025 //   MA 02110-1301, USA.
00026 //
00027 //
00028 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00029 //
00030 
00031 /*!
00032   \class eZSection ezsection.php
00033   \brief eZSection handles grouping of content in eZ Publish
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         if ( !isset( $row['id'] ) )
00046         {
00047             $row['id'] = null;
00048         }
00049         $this->eZPersistentObject( $row );
00050     }
00051 
00052     /*!
00053      \return the persistent object definition for the eZSection class.
00054     */
00055     static function definition()
00056     {
00057         return array( "fields" => array( "id" => array( 'name' => 'ID',
00058                                                         'datatype' => 'integer',
00059                                                         'default' => 0,
00060                                                         'required' => true ),
00061                                          "name" => array( 'name' => "Name",
00062                                                           'datatype' => 'string',
00063                                                           'default' => 0,
00064                                                           'required' => true ),
00065                                          "navigation_part_identifier" => array( 'name' => "NavigationPartIdentifier",
00066                                                                                 'datatype' => 'string',
00067                                                                                 'default' => 'ezcontentnavigationpart',
00068                                                                                 'required' => true ),
00069                                          "locale" => array( 'name' => "Locale",
00070                                                             'datatype' => 'string',
00071                                                             'default' => '',
00072                                                             'required' => true ) ),
00073                       "keys" => array( "id" ),
00074                       "increment_key" => "id",
00075                       "class_name" => "eZSection",
00076                       "sort" => array( "name" => "asc" ),
00077                       "name" => "ezsection" );
00078     }
00079 
00080     /*!
00081      \return the section object with the given id.
00082     */
00083     static function fetch( $sectionID, $asObject = true )
00084     {
00085         global $eZContentSectionObjectCache;
00086 
00087         // If the object given by its id is not cached or should be returned as array
00088         // then we fetch it from the DB (objects are always cached as arrays).
00089         if ( !isset( $eZContentSectionObjectCache[$sectionID] ) or $asObject === false )
00090         {
00091             $section = eZPersistentObject::fetchObject( eZSection::definition(),
00092                                                 null,
00093                                                 array( "id" => $sectionID ),
00094                                                 $asObject );
00095             if ( $asObject )
00096             {
00097                 $eZContentSectionObjectCache[$sectionID] = $section;
00098             }
00099         }
00100         else
00101         {
00102             $section = $eZContentSectionObjectCache[$sectionID];
00103         }
00104         return $section;
00105     }
00106 
00107     static function fetchFilteredList( $conditions = null, $offset = false, $limit = false, $asObject = true )
00108     {
00109         $limits = null;
00110         if ( $offset or $limit )
00111             $limits = array( 'offset' => $offset,
00112                              'length' => $limit );
00113         return eZPersistentObject::fetchObjectList( eZSection::definition(),
00114                                                     null,
00115                                                     $conditions, null, $limits,
00116                                                     $asObject );
00117     }
00118 
00119     static function fetchList( $asObject = true )
00120     {
00121         return eZPersistentObject::fetchObjectList( eZSection::definition(),
00122                                                     null, null, null, null,
00123                                                     $asObject );
00124     }
00125 
00126     static function fetchByOffset( $offset, $limit, $asObject = true )
00127     {
00128         $sectionList = eZPersistentObject::fetchObjectList( eZSection::definition(),
00129                                                              null,
00130                                                              null,
00131                                                              array( 'name' => 'ASC' ),
00132                                                              array( 'offset' => $offset, 'length' => $limit ),
00133                                                              $asObject );
00134         return $sectionList;
00135     }
00136 
00137      /*!
00138      \return the number of active orders
00139     */
00140     static function sectionCount()
00141     {
00142         $db = eZDB::instance();
00143 
00144         $countArray = $db->arrayQuery(  "SELECT count( * ) AS count FROM ezsection" );
00145         return $countArray[0]['count'];
00146     }
00147 
00148     /*!
00149      Makes sure the global section ID is propagated to the template override key.
00150     */
00151     static function initGlobalID()
00152     {
00153         global $eZSiteBasics;
00154         $sessionRequired = $eZSiteBasics['session-required'];
00155         $sectionID = false;
00156         if ( $sessionRequired )
00157         {
00158             //include_once( 'lib/ezutils/classes/ezhttptool.php' );
00159             $http = eZHTTPTool::instance();
00160             $sectionArray = array();
00161             if ( $http->hasSessionVariable( 'eZGlobalSection' ) )
00162                 $sectionArray = $http->sessionVariable( 'eZGlobalSection' );
00163             if ( !isset( $sectionArray['id'] ) )
00164             {
00165                 return false;
00166             }
00167             $sectionID = $sectionArray['id'];
00168         }
00169 
00170         if ( $sectionID )
00171         {
00172             // eZTemplateDesignResource will read this global variable
00173             $GLOBALS['eZDesignKeys']['section'] = $sectionID;
00174             return true;
00175         }
00176         return false;
00177     }
00178 
00179     /*!
00180      Sets the current global section ID to \a $sectionID in the session and
00181      the template override key.
00182     */
00183     static function setGlobalID( $sectionID )
00184     {
00185         //include_once( 'lib/ezutils/classes/ezhttptool.php' );
00186         $http = eZHTTPTool::instance();
00187         $sectionArray = array();
00188         if ( $http->hasSessionVariable( 'eZGlobalSection' ) )
00189             $sectionArray = $http->sessionVariable( 'eZGlobalSection' );
00190         $sectionArray['id'] = $sectionID;
00191         $http->setSessionVariable( 'eZGlobalSection', $sectionArray );
00192 
00193         // eZTemplateDesignResource will read this global variable
00194         $GLOBALS['eZDesignKeys']['section'] = $sectionID;
00195     }
00196 
00197     /*!
00198      \return the global section ID or \c null if it is not set yet.
00199     */
00200     static function globalID()
00201     {
00202         //include_once( 'lib/ezutils/classes/ezhttptool.php' );
00203         $http = eZHTTPTool::instance();
00204         if ( $http->hasSessionVariable( 'eZGlobalSection' ) )
00205         {
00206             $sectionArray = $http->sessionVariable( 'eZGlobalSection' );
00207             if ( isset( $sectionArray['id'] ) )
00208                 return $sectionArray['id'];
00209         }
00210         return null;
00211     }
00212 
00213     /*!
00214      Will remove the current section from the database.
00215      \note Transaction unsafe. If you call several transaction unsafe methods you must enclose
00216      the calls within a db transaction; thus within db->begin and db->commit.
00217     */
00218     function removeThis( $conditions = null, $extraConditions = null )
00219     {
00220         eZPersistentObject::remove( array( "id" => $this->ID ), $extraConditions );
00221     }
00222 
00223     /*
00224      Check if this section is allowed to remove from the system
00225     */
00226     function canBeRemoved( $sectionID = false )
00227     {
00228         if ( $sectionID === false )
00229         {
00230             $sectionID = $this->attribute( 'id' );
00231         }
00232 
00233         $objects = eZPersistentObject::fetchObjectList( eZContentObject::definition(), null,
00234                                                         array( 'section_id' => $sectionID ) );
00235         include_once( 'kernel/classes/ezpolicylimitation.php' );
00236         $limitations = eZPolicyLimitation::findByType( 'Section', $sectionID, true, false );
00237         include_once( 'kernel/classes/ezrole.php' );
00238         $userRoles = eZRole::fetchRolesByLimitation( 'section', $sectionID );
00239 
00240         if ( count( $objects ) > 0 or
00241              count( $limitations ) > 0 or
00242              count( $userRoles ) > 0 )
00243         {
00244             return false;
00245         }
00246         else
00247         {
00248             return true;
00249         }
00250     }
00251 
00252 }
00253 
00254 ?>