|
eZ Publish
[4.0]
|
00001 <?php 00002 // 00003 // Definition of eZURLObjectLink class 00004 // 00005 // Created on: <04-Jul-2003 13:14:41 wy> 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 /*! \file ezurlobjectlink.php 00032 */ 00033 00034 /*! 00035 \class eZURLObjectLink ezurlobjectlink.php 00036 \ingroup eZDatatype 00037 \brief The class eZURLObjectLink does 00038 00039 */ 00040 00041 //include_once( 'kernel/classes/ezpersistentobject.php' ); 00042 00043 class eZURLObjectLink extends eZPersistentObject 00044 { 00045 /*! 00046 Constructor 00047 */ 00048 function eZURLObjectLink( $row ) 00049 { 00050 $this->eZPersistentObject( $row ); 00051 } 00052 00053 static function definition() 00054 { 00055 return array( 'fields' => array( 'url_id' => array( 'name' => 'URLID', 00056 'datatype' => 'integer', 00057 'default' => 0, 00058 'required' => true, 00059 'foreign_class' => 'eZURL', 00060 'foreign_attribute' => 'id', 00061 'multiplicity' => '1..*' ), 00062 'contentobject_attribute_id' => array( 'name' => 'ContentObjectAttributeID', 00063 'datatype' => 'integer', 00064 'default' => 0, 00065 'required' => true, 00066 'foreign_class' => 'eZContentObjectAttribute', 00067 'foreign_attribute' => 'id', 00068 'multiplicity' => '1..*' ), 00069 'contentobject_attribute_version' => array( 'name' => 'ContentObjectAttributeVersion', 00070 'datatype' => 'integer', 00071 'default' => 0, 00072 'short_name' => 'contentobject_attr_version', 00073 'required' => true ) ), 00074 'keys' => array( 'url_id', 'contentobject_attribute_id', 'contentobject_attribute_version' ), 00075 'sort' => array( 'url_id' => 'asc' ), 00076 'class_name' => 'eZURLObjectLink', 00077 'name' => 'ezurl_object_link' ); 00078 } 00079 00080 /*! 00081 \static 00082 */ 00083 static function create( $urlID, $contentObjectAttributeID, $contentObjectAttributeVersion ) 00084 { 00085 $row = array( 00086 'url_id' => $urlID, 00087 'contentobject_attribute_id' => $contentObjectAttributeID, 00088 'contentobject_attribute_version' => $contentObjectAttributeVersion ); 00089 return new eZURLObjectLink( $row ); 00090 } 00091 00092 /*! 00093 \static 00094 \return the url object for id \a $id. 00095 */ 00096 static function fetch( $urlID, $contentObjectAttributeID, $contentObjectAttributeVersion, $asObject = true ) 00097 { 00098 return eZPersistentObject::fetchObject( eZURLObjectLink::definition(), 00099 null, 00100 array( 'url_id' => $urlID, 00101 'contentobject_attribute_id' => $contentObjectAttributeID, 00102 'contentobject_attribute_version' => $contentObjectAttributeVersion ), 00103 $asObject ); 00104 } 00105 00106 /*! 00107 \static 00108 \return \c true if the URL \a $urlID has any object links 00109 */ 00110 static function hasObjectLinkList( $urlID ) 00111 { 00112 return ( eZURLObjectLink::fetchObjectVersionCount( $urlID ) > 0 ); 00113 } 00114 00115 /*! 00116 \static 00117 \return all object versions which has the link. 00118 */ 00119 static function fetchObjectVersionList( $urlID, $parameters = false ) 00120 { 00121 $objectVersionList = array(); 00122 $urlObjectLinkList = eZPersistentObject::fetchObjectList( eZURLObjectLink::definition(), 00123 null, 00124 array( 'url_id' => $urlID ), 00125 null, 00126 $parameters, 00127 true ); 00128 $storedVersionList = array(); 00129 foreach ( $urlObjectLinkList as $urlObjectLink ) 00130 { 00131 $objectAttributeID = $urlObjectLink->attribute( 'contentobject_attribute_id' ); 00132 $objectAttributeVersion = $urlObjectLink->attribute( 'contentobject_attribute_version' ); 00133 $objectAttribute = eZContentObjectAttribute::fetch( $objectAttributeID, $objectAttributeVersion ); 00134 if ( $objectAttribute ) // Object and version has been deleted 00135 { 00136 $objectID = $objectAttribute->attribute( 'contentobject_id' ); 00137 $objectVersion = $objectAttribute->attribute( 'version' ); 00138 $object = eZContentObject::fetch( $objectID ); 00139 if ( $object ) 00140 { 00141 $versionObject = $object->version( $objectVersion ); 00142 if ( $versionObject and !in_array( $versionObject->attribute( 'id' ), $storedVersionList ) ) 00143 { 00144 $objectVersionList[] = $versionObject; 00145 $storedVersionList[] = $versionObject->attribute( 'id' ); 00146 } 00147 } 00148 } 00149 } 00150 return $objectVersionList; 00151 } 00152 00153 /*! 00154 Get url object count 00155 \param urld id 00156 */ 00157 static function fetchObjectVersionCount( $urlID ) 00158 { 00159 $result = eZPersistentObject::fetchObjectList( eZURLObjectLink::definition(), 00160 array(), 00161 array( 'url_id' => $urlID ), 00162 false, 00163 null, 00164 false, 00165 false, 00166 array( array( 'operation' => 'count( * )', 00167 'name' => 'count' ) ) ); 00168 return $result[0]['count']; 00169 } 00170 00171 /*! 00172 \static 00173 Removes all links for the object attribute \a $contentObjectAttributeID and version \a $contentObjectVersion. 00174 If \a $contentObjectVersion is \c false then all versions are removed as well. 00175 */ 00176 static function removeURLlinkList( $contentObjectAttributeID, $contentObjectAttributeVersion ) 00177 { 00178 $conditions = array( 'contentobject_attribute_id' => $contentObjectAttributeID ); 00179 if ( $contentObjectAttributeVersion !== false ) 00180 $conditions['contentobject_attribute_version'] = $contentObjectAttributeVersion; 00181 eZPersistentObject::removeObject( eZURLObjectLink::definition(), 00182 $conditions ); 00183 } 00184 00185 00186 /*! 00187 \static 00188 \return all links for the contenobject attribute ID \a $contenObjectAttributeID and version \a $contenObjectVersion. 00189 If \a $contentObjectVersion is \c false then all links for all versions are returned. 00190 */ 00191 static function fetchLinkList( $contentObjectAttributeID, $contentObjectAttributeVersion, $asObject = true ) 00192 { 00193 $linkList = array(); 00194 $conditions = array( 'contentobject_attribute_id' => $contentObjectAttributeID ); 00195 if ( $contentObjectAttributeVersion !== false ) 00196 $conditions['contentobject_attribute_version'] = $contentObjectAttributeVersion; 00197 $urlObjectLinkList = eZPersistentObject::fetchObjectList( eZURLObjectLink::definition(), 00198 null, 00199 $conditions, 00200 null, 00201 null, 00202 $asObject ); 00203 foreach ( $urlObjectLinkList as $urlObjectLink ) 00204 { 00205 if ( $asObject ) 00206 { 00207 $linkID = $urlObjectLink->attribute( 'url_id' ); 00208 $linkList[] = eZURL::fetch( $linkID ); 00209 } 00210 else 00211 { 00212 $linkID = $urlObjectLink['url_id']; 00213 $linkList[] = $linkID; 00214 } 00215 } 00216 return $linkList; 00217 } 00218 00219 /*! 00220 \static 00221 Clear view cache for every object which contains URL with given link ID \a $urlID. 00222 */ 00223 static function clearCacheForObjectLink( $urlID ) 00224 { 00225 //include_once( "kernel/classes/ezcontentcachemanager.php" ); 00226 $urlObjectLinkList = eZPersistentObject::fetchObjectList( eZURLObjectLink::definition(), 00227 null, 00228 array( 'url_id' => $urlID ), 00229 null, 00230 null, 00231 true ); 00232 foreach ( $urlObjectLinkList as $urlObjectLink ) 00233 { 00234 $objectAttributeID = $urlObjectLink->attribute( 'contentobject_attribute_id' ); 00235 $objectAttributeVersion = $urlObjectLink->attribute( 'contentobject_attribute_version' ); 00236 $objectAttribute = eZContentObjectAttribute::fetch( $objectAttributeID, $objectAttributeVersion ); 00237 if ( $objectAttribute ) 00238 { 00239 $objectID = $objectAttribute->attribute( 'contentobject_id' ); 00240 $objectVersion = $objectAttribute->attribute( 'version' ); 00241 eZContentCacheManager::clearContentCacheIfNeeded( $objectID, $objectVersion ); 00242 } 00243 } 00244 } 00245 00246 00247 /// \privatesection 00248 public $URLID; 00249 public $ContentObjectAttributeID; 00250 public $ContentObjectAttributeVersion; 00251 } 00252 ?>