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 include_once( "kernel/classes/ezcontentclassattribute.php" );
00041
00042 class eZMedia extends eZPersistentObject
00043 {
00044 function eZMedia( $row )
00045 {
00046 $this->eZPersistentObject( $row );
00047 }
00048
00049 function definition()
00050 {
00051 return array( "fields" => array( "contentobject_attribute_id" => array( 'name' => "ContentObjectAttributeID",
00052 'datatype' => 'integer',
00053 'default' => 0,
00054 'required' => true,
00055 'foreign_class' => 'eZContentObjectAttribute',
00056 'foreign_attribute' => 'id',
00057 'multiplicity' => '1..*' ),
00058 "version" => array( 'name' => "Version",
00059 'datatype' => 'integer',
00060 'default' => 0,
00061 'required' => true ),
00062 "filename" => array( 'name' => "Filename",
00063 'datatype' => 'string',
00064 'default' => '',
00065 'required' => true ),
00066 "original_filename" => array( 'name' => "OriginalFilename",
00067 'datatype' => 'string',
00068 'default' => '',
00069 'required' => true ),
00070 "mime_type" => array( 'name' => "MimeType",
00071 'datatype' => 'string',
00072 'default' => '',
00073 'required' => true ),
00074 "width" => array( 'name' => "Width",
00075 'datatype' => 'integer',
00076 'default' => 0,
00077 'required' => true ),
00078 "height" => array( 'name' => "Height",
00079 'datatype' => 'integer',
00080 'default' => 0,
00081 'required' => true ),
00082 "has_controller" => array( 'name' => "HasController",
00083 'datatype' => 'integer',
00084 'default' => 0,
00085 'required' => true ),
00086 "controls" => array( 'name' => "Controls",
00087 'datatype' => 'string',
00088 'default' => '',
00089 'required' => true ),
00090 "is_autoplay" => array( 'name' => "IsAutoplay",
00091 'datatype' => 'integer',
00092 'default' => 0,
00093 'required' => true ),
00094 "pluginspage" => array( 'name' => "Pluginspage",
00095 'datatype' => 'string',
00096 'default' => '',
00097 'required' => true ),
00098 "quality" => array( 'name' => 'Quality',
00099 'datatype' => 'string',
00100 'default' => '',
00101 'required' => true ),
00102 "is_loop" => array( 'name' => "IsLoop",
00103 'datatype' => 'integer',
00104 'default' => 0,
00105 'required' => true ) ),
00106 "keys" => array( "contentobject_attribute_id", "version" ),
00107 'function_attributes' => array( 'filesize' => 'filesize',
00108 'filepath' => 'filepath',
00109 'mime_type_category' => 'mimeTypeCategory',
00110 'mime_type_part' => 'mimeTypePart' ),
00111 "relations" => array( "contentobject_attribute_id" => array( "class" => "ezcontentobjectattribute",
00112 "field" => "id" ),
00113 "version" => array( "class" => "ezcontentobjectattribute",
00114 "field" => "version" )),
00115 "class_name" => "eZMedia",
00116 "name" => "ezmedia" );
00117 }
00118
00119 function &fileSize()
00120 {
00121 $fileInfo = $this->storedFileInfo();
00122
00123
00124 require_once( 'kernel/classes/ezclusterfilehandler.php' );
00125 $file = eZClusterFileHandler::instance( $fileInfo['filepath'] );
00126
00127 if ( $file->exists() )
00128 $fileSize = $file->size();
00129 else
00130 $fileSize = 0;
00131 return $fileSize;
00132 }
00133
00134 function &filePath()
00135 {
00136 $fileInfo = $this->storedFileInfo();
00137 return $fileInfo['filepath'];
00138 }
00139
00140 function &mimeTypeCategory()
00141 {
00142 $types = explode( "/", eZPersistentObject::attribute( "mime_type" ) );
00143 return $types[0];
00144 }
00145
00146 function &mimeTypePart()
00147 {
00148 $types = explode( "/", eZPersistentObject::attribute( "mime_type" ) );
00149 return $types[1];
00150 }
00151
00152 function create( $contentObjectAttributeID, $version )
00153 {
00154 $row = array( "contentobject_attribute_id" => $contentObjectAttributeID,
00155 "version" => $version,
00156 "filename" => "",
00157 "original_filename" => "",
00158 "mime_type" => "",
00159 "width" => "0",
00160 "height" => "0",
00161 "controller" => true,
00162 "autoplay" => true,
00163 "pluginspage" => "",
00164 "is_loop" => false,
00165 "quality" => "",
00166 "controls" => ""
00167 );
00168 return new eZMedia( $row );
00169 }
00170
00171 function fetch( $id, $version, $asObject = true )
00172 {
00173 if( $version == null )
00174 {
00175 return eZPersistentObject::fetchObjectList( eZMedia::definition(),
00176 null,
00177 array( "contentobject_attribute_id" => $id ),
00178 null,
00179 null,
00180 $asObject );
00181 }
00182 else
00183 {
00184 return eZPersistentObject::fetchObject( eZMedia::definition(),
00185 null,
00186 array( "contentobject_attribute_id" => $id,
00187 "version" => $version ),
00188 $asObject );
00189 }
00190 }
00191
00192 function remove( $id, $version )
00193 {
00194 if( $version == null )
00195 {
00196 eZPersistentObject::removeObject( eZMedia::definition(),
00197 array( "contentobject_attribute_id" => $id ) );
00198 }
00199 else
00200 {
00201 eZPersistentObject::removeObject( eZMedia::definition(),
00202 array( "contentobject_attribute_id" => $id,
00203 "version" => $version ) );
00204 }
00205 }
00206
00207 function storedFileInfo()
00208 {
00209 $fileName = $this->attribute( 'filename' );
00210 $mimeType = $this->attribute( 'mime_type' );
00211 $originalFileName = $this->attribute( 'original_filename' );
00212
00213 $storageDir = eZSys::storageDirectory();
00214
00215 $group = '';
00216 $type = '';
00217 if ( $mimeType )
00218 list( $group, $type ) = explode( '/', $mimeType );
00219
00220 $filePath = $storageDir . '/original/' . $group . '/' . $fileName;
00221
00222 return array( 'filename' => $fileName,
00223 'original_filename' => $originalFileName,
00224 'filepath' => $filePath,
00225 'mime_type' => $mimeType );
00226 }
00227
00228 var $ContentObjectAttributeID;
00229 var $Filename;
00230 var $OriginalFilename;
00231 var $MimeType;
00232 var $Width;
00233 var $Height;
00234 var $HasController;
00235 var $Controls;
00236 var $IsLoop;
00237 var $IsAutoplay;
00238 var $Pluginspage;
00239 var $Quality;
00240 }
00241
00242 ?>