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
00038 include_once( 'lib/ezdb/classes/ezdb.php' );
00039 include_once( 'kernel/classes/ezpersistentobject.php' );
00040
00041 class eZImageFile extends eZPersistentObject
00042 {
00043 function eZImageFile( $row )
00044 {
00045 $this->eZPersistentObject( $row );
00046 }
00047
00048 function definition()
00049 {
00050 return array( 'fields' => array( 'id' => array( 'name' => 'id',
00051 'datatype' => 'integer',
00052 'default' => 0,
00053 'required' => true ),
00054 'contentobject_attribute_id' => array( 'name' => 'ContentObjectAttributeID',
00055 'datatype' => 'integer',
00056 'default' => 0,
00057 'required' => true,
00058 'foreign_class' => 'eZContentObjectAttribute',
00059 'foreign_attribute' => 'id',
00060 'multiplicity' => '1..*' ),
00061 'filepath' => array( 'name' => 'Filepath',
00062 'datatype' => 'string',
00063 'default' => '',
00064 'required' => true ) ),
00065 'keys' => array( 'id' ),
00066 'class_name' => 'eZImageFile',
00067 'name' => 'ezimagefile' );
00068 }
00069
00070 function create( $contentObjectAttributeID, $filepath )
00071 {
00072 $row = array( "contentobject_attribute_id" => $contentObjectAttributeID,
00073 "filepath" => $filepath );
00074 return new eZImageFile( $row );
00075 }
00076
00077 function &fetchForContentObjectAttribute( $contentObjectAttributeID, $asObject = false )
00078 {
00079 $rows = eZPersistentObject::fetchObjectList( eZImageFile::definition(),
00080 null,
00081 array( "contentobject_attribute_id" => $contentObjectAttributeID ),
00082 null,
00083 null,
00084 $asObject );
00085 if ( !$asObject )
00086 {
00087 $files = array();
00088 foreach ( array_keys( $rows ) as $rowKey )
00089 {
00090 $row =& $rows[$rowKey];
00091 $files[] = $row['filepath'];
00092 }
00093 $files = array_unique( $files );
00094 return $files;
00095 }
00096 else
00097 return $rows;
00098 }
00099
00100
00101
00102 function fetchImageAttributesByFilepath( $filepath, $contentObjectAttributeID )
00103 {
00104 $db = eZDB::instance();
00105 $filepath = $db->escapeString( $filepath );
00106 $contentObjectAttributeID =(int) $contentObjectAttributeID;
00107 $query = "SELECT id, version
00108 FROM ezcontentobject_attribute
00109 WHERE id = $contentObjectAttributeID and
00110 data_text like '%url=\"$filepath\"%'";
00111
00112 $rows = $db->arrayQuery( $query );
00113 return $rows;
00114 }
00115
00116 function fetchByFilepath( $contentObjectAttributeID, $filepath, $asObject = true )
00117 {
00118
00119 if ( $contentObjectAttributeID === false )
00120 return eZPersistentObject::fetchObject( eZImageFile::definition(),
00121 null,
00122 array( 'filepath' => $filepath ),
00123 $asObject );
00124
00125 return eZPersistentObject::fetchObject( eZImageFile::definition(),
00126 null,
00127 array( 'contentobject_attribute_id' => $contentObjectAttributeID,
00128 'filepath' => $filepath ),
00129 $asObject );
00130 }
00131
00132 function moveFilepath( $contentObjectAttributeID, $oldFilepath, $newFilepath )
00133 {
00134 $db =& eZDB::instance();
00135 $db->begin();
00136
00137 eZImageFile::removeFilepath( $contentObjectAttributeID, $oldFilepath );
00138 $result = eZImageFile::appendFilepath( $contentObjectAttributeID, $newFilepath );
00139
00140 $db->commit();
00141 return $result;
00142 }
00143
00144 function appendFilepath( $contentObjectAttributeID, $filepath, $ignoreUnique = false )
00145 {
00146 if ( empty( $filepath ) )
00147 return false;
00148
00149 if ( !$ignoreUnique )
00150 {
00151
00152 $imageFiles = eZImageFile::fetchByFilePath( false, $filepath, false );
00153
00154 if ( isset( $imageFiles[ 'contentobject_attribute_id' ] ) )
00155 return false;
00156 }
00157 $fileObject = eZImageFile::fetchByFilePath( $contentObjectAttributeID, $filepath );
00158 if ( $fileObject )
00159 return false;
00160 $fileObject = eZImageFile::create( $contentObjectAttributeID, $filepath );
00161 $fileObject->store();
00162 return true;
00163 }
00164
00165 function removeFilepath( $contentObjectAttributeID, $filepath )
00166 {
00167 if ( empty( $filepath ) )
00168 return false;
00169 $fileObject = eZImageFile::fetchByFilePath( $contentObjectAttributeID, $filepath );
00170 if ( !$fileObject )
00171 return false;
00172 $fileObject->remove();
00173 return true;
00174 }
00175
00176 function removeForContentObjectAttribute( $contentObjectAttributeID )
00177 {
00178 if ( isset( $this ) and
00179 get_class( $this ) == 'ezimagefile' )
00180 $instance =& $this;
00181 else
00182 $instance =& eZImageFile::instance();
00183 $instance->remove( array( 'contentobject_attribute_id' => $contentObjectAttributeID ) );
00184 }
00185
00186 function &instance()
00187 {
00188 $instance =& $GLOBALS['eZImageFileInstance'];
00189 if ( !isset( $instance ) )
00190 {
00191 $instance = new eZImageFile( array() );
00192 }
00193 return $instance;
00194 }
00195
00196
00197
00198 var $ID;
00199 var $ContentObjectAttributeID;
00200 var $Filepath;
00201 }
00202
00203 ?>