/kernel/classes/ezsection.php

https://github.com/lserwatka/ezpublish · PHP · 259 lines · 158 code · 20 blank · 81 comment · 10 complexity · 4d52ca2d5e704b8ba019a43f93604c4d MD5 · raw file

  1. <?php
  2. //
  3. // Definition of eZSection class
  4. //
  5. // Created on: <27-Aug-2002 15:55:18 bf>
  6. //
  7. // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
  8. // SOFTWARE NAME: eZ Publish
  9. // SOFTWARE RELEASE: 4.1.x
  10. // COPYRIGHT NOTICE: Copyright (C) 1999-2010 eZ Systems AS
  11. // SOFTWARE LICENSE: GNU General Public License v2.0
  12. // NOTICE: >
  13. // This program is free software; you can redistribute it and/or
  14. // modify it under the terms of version 2.0 of the GNU General
  15. // Public License as published by the Free Software Foundation.
  16. //
  17. // This program is distributed in the hope that it will be useful,
  18. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. // GNU General Public License for more details.
  21. //
  22. // You should have received a copy of version 2.0 of the GNU General
  23. // Public License along with this program; if not, write to the Free
  24. // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  25. // MA 02110-1301, USA.
  26. //
  27. //
  28. // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
  29. //
  30. /*!
  31. \class eZSection ezsection.php
  32. \brief eZSection handles grouping of content in eZ Publish
  33. */
  34. class eZSection extends eZPersistentObject
  35. {
  36. function eZSection( $row )
  37. {
  38. if ( !isset( $row['id'] ) )
  39. {
  40. $row['id'] = null;
  41. }
  42. $this->eZPersistentObject( $row );
  43. }
  44. /*!
  45. \return the persistent object definition for the eZSection class.
  46. */
  47. static function definition()
  48. {
  49. static $definition = array( "fields" => array( "id" => array( 'name' => 'ID',
  50. 'datatype' => 'integer',
  51. 'default' => 0,
  52. 'required' => true ),
  53. "name" => array( 'name' => "Name",
  54. 'datatype' => 'string',
  55. 'default' => 0,
  56. 'required' => true ),
  57. "navigation_part_identifier" => array( 'name' => "NavigationPartIdentifier",
  58. 'datatype' => 'string',
  59. 'default' => 'ezcontentnavigationpart',
  60. 'required' => true ),
  61. "locale" => array( 'name' => "Locale",
  62. 'datatype' => 'string',
  63. 'default' => '',
  64. 'required' => true ),
  65. "identifier" => array( 'name' => "Identifier",
  66. 'datatype' => 'string',
  67. 'default' => '',
  68. 'required' => true ) ),
  69. "keys" => array( "id" ),
  70. "increment_key" => "id",
  71. "class_name" => "eZSection",
  72. "sort" => array( "name" => "asc" ),
  73. "name" => "ezsection" );
  74. return $definition;
  75. }
  76. /*!
  77. \return the section object with the given id.
  78. */
  79. static function fetch( $sectionID, $asObject = true )
  80. {
  81. global $eZContentSectionObjectCache;
  82. // If the object given by its id is not cached or should be returned as array
  83. // then we fetch it from the DB (objects are always cached as arrays).
  84. if ( !isset( $eZContentSectionObjectCache[$sectionID] ) or $asObject === false )
  85. {
  86. $section = eZPersistentObject::fetchObject( eZSection::definition(),
  87. null,
  88. array( "id" => $sectionID ),
  89. $asObject );
  90. if ( $asObject )
  91. {
  92. $eZContentSectionObjectCache[$sectionID] = $section;
  93. }
  94. }
  95. else
  96. {
  97. $section = $eZContentSectionObjectCache[$sectionID];
  98. }
  99. return $section;
  100. }
  101. /**
  102. * fetch object by section identifier
  103. * @param string $sectionIdentifier
  104. * @param boolean $asObject
  105. * @return object|null
  106. */
  107. static function fetchByIdentifier( $sectionIdentifier, $asObject = true )
  108. {
  109. global $eZContentSectionObjectCache;
  110. if( !isset( $eZContentSectionObjectCache[$sectionIdentifier] ) || $asObject === false )
  111. {
  112. $sectionFetched = eZPersistentObject::fetchObject( eZSection::definition(),
  113. null,
  114. array( "identifier" => $sectionIdentifier ),
  115. $asObject );
  116. if( $asObject )
  117. {
  118. // the section identifier index refers to the id index object
  119. $sectionID = $sectionFetched->attribute( 'id' );
  120. if( !isset( $eZContentSectionObjectCache[$sectionID] ) )
  121. {
  122. $eZContentSectionObjectCache[$sectionID] = $sectionFetched;
  123. }
  124. $eZContentSectionObjectCache[$sectionIdentifier] = $eZContentSectionObjectCache[$sectionID];
  125. }
  126. else
  127. {
  128. return $sectionFetched;
  129. }
  130. }
  131. $section = $eZContentSectionObjectCache[$sectionIdentifier];
  132. return $section;
  133. }
  134. static function fetchFilteredList( $conditions = null, $offset = false, $limit = false, $asObject = true )
  135. {
  136. $limits = null;
  137. if ( $offset or $limit )
  138. $limits = array( 'offset' => $offset,
  139. 'length' => $limit );
  140. return eZPersistentObject::fetchObjectList( eZSection::definition(),
  141. null,
  142. $conditions, null, $limits,
  143. $asObject );
  144. }
  145. static function fetchList( $asObject = true )
  146. {
  147. return eZPersistentObject::fetchObjectList( eZSection::definition(),
  148. null, null, null, null,
  149. $asObject );
  150. }
  151. static function fetchByOffset( $offset, $limit, $asObject = true )
  152. {
  153. $sectionList = eZPersistentObject::fetchObjectList( eZSection::definition(),
  154. null,
  155. null,
  156. array( 'name' => 'ASC' ),
  157. array( 'offset' => $offset, 'length' => $limit ),
  158. $asObject );
  159. return $sectionList;
  160. }
  161. /*!
  162. \return the number of active orders
  163. */
  164. static function sectionCount()
  165. {
  166. $db = eZDB::instance();
  167. $countArray = $db->arrayQuery( "SELECT count( * ) AS count FROM ezsection" );
  168. return $countArray[0]['count'];
  169. }
  170. /**
  171. * Makes sure the global section ID is propagated to the template override key.
  172. * @deprecated since 4.4, global section support has been removed
  173. *
  174. * @return false
  175. */
  176. static function initGlobalID()
  177. {
  178. return false;
  179. }
  180. /**
  181. * Sets the current global section ID to \a $sectionID in the session and
  182. * the template override key
  183. * @deprecated since 4.4, global section support has been removed this
  184. * function only sets value to override values for bc.
  185. *
  186. * @param int $sectionID
  187. */
  188. static function setGlobalID( $sectionID )
  189. {
  190. // eZTemplateDesignResource will read this global variable
  191. $GLOBALS['eZDesignKeys']['section'] = $sectionID;
  192. }
  193. /**
  194. * Return the global section ID or \c null if it is not set yet.
  195. * @deprecated since 4.4, global section support has been removed and
  196. * null is always returned.
  197. *
  198. * @return null
  199. */
  200. static function globalID()
  201. {
  202. return null;
  203. }
  204. /*!
  205. Will remove the current section from the database.
  206. \note Transaction unsafe. If you call several transaction unsafe methods you must enclose
  207. the calls within a db transaction; thus within db->begin and db->commit.
  208. */
  209. function removeThis( $conditions = null, $extraConditions = null )
  210. {
  211. eZPersistentObject::remove( array( "id" => $this->ID ), $extraConditions );
  212. }
  213. /*
  214. Check if this section is allowed to remove from the system
  215. */
  216. function canBeRemoved( $sectionID = false )
  217. {
  218. if ( $sectionID === false )
  219. {
  220. $sectionID = $this->attribute( 'id' );
  221. }
  222. $objects = eZPersistentObject::fetchObjectList( eZContentObject::definition(), null,
  223. array( 'section_id' => $sectionID ) );
  224. $limitations = eZPolicyLimitation::findByType( 'Section', $sectionID, true, false );
  225. $userRoles = eZRole::fetchRolesByLimitation( 'section', $sectionID );
  226. if ( count( $objects ) > 0 or
  227. count( $limitations ) > 0 or
  228. count( $userRoles ) > 0 )
  229. {
  230. return false;
  231. }
  232. else
  233. {
  234. return true;
  235. }
  236. }
  237. }
  238. ?>