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