Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezmedia.php
Go to the documentation of this file.
1 <?php
18 class eZMedia extends eZPersistentObject
19 {
20 static function definition()
21 {
22 static $definition = array( "fields" => array( "contentobject_attribute_id" => array( 'name' => "ContentObjectAttributeID",
23 'datatype' => 'integer',
24 'default' => 0,
25 'required' => true,
26 'foreign_class' => 'eZContentObjectAttribute',
27 'foreign_attribute' => 'id',
28 'multiplicity' => '1..*' ),
29 "version" => array( 'name' => "Version",
30 'datatype' => 'integer',
31 'default' => 0,
32 'required' => true ),
33 "filename" => array( 'name' => "Filename",
34 'datatype' => 'string',
35 'default' => '',
36 'required' => true ),
37 "original_filename" => array( 'name' => "OriginalFilename",
38 'datatype' => 'string',
39 'default' => '',
40 'required' => true ),
41 "mime_type" => array( 'name' => "MimeType",
42 'datatype' => 'string',
43 'default' => '',
44 'required' => true ),
45 "width" => array( 'name' => "Width",
46 'datatype' => 'integer',
47 'default' => 0,
48 'required' => true ),
49 "height" => array( 'name' => "Height",
50 'datatype' => 'integer',
51 'default' => 0,
52 'required' => true ),
53 "has_controller" => array( 'name' => "HasController",
54 'datatype' => 'integer',
55 'default' => 0,
56 'required' => true ),
57 "controls" => array( 'name' => "Controls",
58 'datatype' => 'string',
59 'default' => '',
60 'required' => true ),
61 "is_autoplay" => array( 'name' => "IsAutoplay",
62 'datatype' => 'integer',
63 'default' => 0,
64 'required' => true ),
65 "pluginspage" => array( 'name' => "Pluginspage",
66 'datatype' => 'string',
67 'default' => '',
68 'required' => true ),
69 "quality" => array( 'name' => 'Quality',
70 'datatype' => 'string',
71 'default' => '',
72 'required' => true ),
73 "is_loop" => array( 'name' => "IsLoop",
74 'datatype' => 'integer',
75 'default' => 0,
76 'required' => true ) ),
77 "keys" => array( "contentobject_attribute_id", "version" ),
78 'function_attributes' => array( 'filesize' => 'filesize',
79 'filepath' => 'filepath',
80 'mime_type_category' => 'mimeTypeCategory',
81 'mime_type_part' => 'mimeTypePart' ),
82 "relations" => array( "contentobject_attribute_id" => array( "class" => "ezcontentobjectattribute",
83 "field" => "id" ),
84 "version" => array( "class" => "ezcontentobjectattribute",
85 "field" => "version" )),
86 "class_name" => "eZMedia",
87 "name" => "ezmedia" );
88 return $definition;
89 }
90
91 function fileSize()
92 {
93 $fileInfo = $this->storedFileInfo();
94
95 $file = eZClusterFileHandler::instance( $fileInfo['filepath'] );
96
97 if ( $file->exists() )
98 {
99 return $file->size();
100 }
101
102 return 0;
103 }
104
105 function filePath()
106 {
107 $fileInfo = $this->storedFileInfo();
108 return $fileInfo['filepath'];
109 }
110
111 function mimeTypeCategory()
112 {
113 $types = explode( "/", $this->attribute( "mime_type" ) );
114 return $types[0];
115 }
116
117 function mimeTypePart()
118 {
119 $types = explode( "/", $this->attribute( "mime_type" ) );
120 return $types[1];
121 }
122
123 static function create( $contentObjectAttributeID, $version )
124 {
125 $row = array( "contentobject_attribute_id" => $contentObjectAttributeID,
126 "version" => $version,
127 "filename" => "",
128 "original_filename" => "",
129 "mime_type" => "",
130 "width" => "0",
131 "height" => "0",
132 "controller" => true,
133 "autoplay" => true,
134 "pluginspage" => "",
135 "is_loop" => false,
136 "quality" => "",
137 "controls" => ""
138 );
139 return new eZMedia( $row );
140 }
141
142 static function fetch( $id, $version, $asObject = true )
143 {
144 if( $version == null )
145 {
146 return eZPersistentObject::fetchObjectList( eZMedia::definition(),
147 null,
148 array( "contentobject_attribute_id" => $id ),
149 null,
150 null,
151 $asObject );
152 }
153 else
154 {
155 return eZPersistentObject::fetchObject( eZMedia::definition(),
156 null,
157 array( "contentobject_attribute_id" => $id,
158 "version" => $version ),
159 $asObject );
160 }
161 }
162
163 static function fetchByFileName( $filename, $version = null, $asObject = true )
164 {
165 if ( $version == null )
166 {
167 return eZPersistentObject::fetchObjectList( eZMedia::definition(),
168 null,
169 array( 'filename' => $filename ),
170 null,
171 null,
172 $asObject );
173 }
174 else
175 {
176 return eZPersistentObject::fetchObject( eZMedia::definition(),
177 null,
178 array( 'filename' => $filename,
179 'version' => $version ),
180 $asObject );
181 }
182 }
183
191 static function fetchByContentObjectID( $contentObjectID, $languageCode = null, $asObject = true )
192 {
193 $condition = array();
194 $condition['contentobject_id'] = $contentObjectID;
195 $condition['data_type_string'] = 'ezmedia';
196 if ( $languageCode != null )
197 {
198 $condition['language_code'] = $languageCode;
199 }
200 $custom = array( array( 'operation' => 'DISTINCT id',
201 'name' => 'id' ) );
202 $ids = eZPersistentObject::fetchObjectList( eZContentObjectAttribute::definition(),
203 array(),
204 $condition,
205 null,
206 null,
207 false,
208 false,
209 $custom );
210 $mediaFiles = array();
211 foreach ( $ids as $id )
212 {
213 $mediaFileObjectAttribute = eZMedia::fetch( $id['id'], null, $asObject );
214 $mediaFiles = array_merge( $mediaFiles, $mediaFileObjectAttribute );
215 }
216 return $mediaFiles;
217 }
218
219 static function removeByID( $id, $version )
220 {
221 if( $version == null )
222 {
223 eZPersistentObject::removeObject( eZMedia::definition(),
224 array( "contentobject_attribute_id" => $id ) );
225 }
226 else
227 {
228 eZPersistentObject::removeObject( eZMedia::definition(),
229 array( "contentobject_attribute_id" => $id,
230 "version" => $version ) );
231 }
232 }
233
234 function storedFileInfo()
235 {
236 $fileName = $this->attribute( 'filename' );
237 $mimeType = $this->attribute( 'mime_type' );
238 $originalFileName = $this->attribute( 'original_filename' );
239
240 $storageDir = eZSys::storageDirectory();
241
242 $group = '';
243 $type = '';
244 if ( $mimeType )
245 list( $group, $type ) = explode( '/', $mimeType );
246
247 $filePath = $storageDir . '/original/' . $group . '/' . $fileName;
248
249 return array( 'filename' => $fileName,
250 'original_filename' => $originalFileName,
251 'filepath' => $filePath,
252 'mime_type' => $mimeType );
253 }
254
255 public $ContentObjectAttributeID;
256 public $Filename;
257 public $OriginalFilename;
258 public $MimeType;
259 public $Width;
260 public $Height;
261 public $HasController;
262 public $Controls;
263 public $IsLoop;
264 public $IsAutoplay;
265 public $Pluginspage;
266 public $Quality;
267 }
268
269 ?>
eZClusterFileHandler\instance
static instance( $filename=false)
Definition: ezclusterfilehandler.php:21
eZContentObjectAttribute\definition
static definition()
Definition: ezcontentobjectattribute.php:38
eZMedia
The class eZMedia handles registered media files.
Definition: ezmedia.php:19
eZMedia\$Controls
$Controls
Definition: ezmedia.php:262
eZMedia\$IsAutoplay
$IsAutoplay
Definition: ezmedia.php:264
eZMedia\$Height
$Height
Definition: ezmedia.php:260
eZMedia\$Width
$Width
Definition: ezmedia.php:259
eZMedia\$Quality
$Quality
Definition: ezmedia.php:266
eZMedia\$OriginalFilename
$OriginalFilename
Definition: ezmedia.php:257
eZMedia\fetchByFileName
static fetchByFileName( $filename, $version=null, $asObject=true)
Definition: ezmedia.php:163
eZMedia\create
static create( $contentObjectAttributeID, $version)
Definition: ezmedia.php:123
eZMedia\storedFileInfo
storedFileInfo()
Definition: ezmedia.php:234
eZMedia\fetch
static fetch( $id, $version, $asObject=true)
Definition: ezmedia.php:142
eZMedia\$MimeType
$MimeType
Definition: ezmedia.php:258
eZMedia\fileSize
fileSize()
Definition: ezmedia.php:91
eZMedia\definition
static definition()
Definition: ezmedia.php:20
eZMedia\filePath
filePath()
Definition: ezmedia.php:105
eZMedia\fetchByContentObjectID
static fetchByContentObjectID( $contentObjectID, $languageCode=null, $asObject=true)
Definition: ezmedia.php:191
eZMedia\$Filename
$Filename
Definition: ezmedia.php:256
eZMedia\$Pluginspage
$Pluginspage
Definition: ezmedia.php:265
eZMedia\$IsLoop
$IsLoop
Definition: ezmedia.php:263
eZMedia\$HasController
$HasController
Definition: ezmedia.php:261
eZMedia\mimeTypeCategory
mimeTypeCategory()
Definition: ezmedia.php:111
eZMedia\$ContentObjectAttributeID
$ContentObjectAttributeID
Definition: ezmedia.php:255
eZMedia\removeByID
static removeByID( $id, $version)
Definition: ezmedia.php:219
eZMedia\mimeTypePart
mimeTypePart()
Definition: ezmedia.php:117
eZPersistentObject
Definition: ezpersistentobject.php:33
eZPersistentObject\fetchObject
static fetchObject( $def, $field_filters, $conds, $asObject=true, $grouping=null, $custom_fields=null)
Definition: ezpersistentobject.php:213
eZPersistentObject\removeObject
static removeObject( $def, $conditions=null, $extraConditions=null)
Definition: ezpersistentobject.php:271
eZPersistentObject\attribute
attribute( $attr, $noFunction=false)
Definition: ezpersistentobject.php:1329
eZPersistentObject\fetchObjectList
static fetchObjectList( $def, $field_filters=null, $conds=null, $sorts=null, $limit=null, $asObject=true, $grouping=false, $custom_fields=null, $custom_tables=null, $custom_conds=null)
Definition: ezpersistentobject.php:806
eZSys\storageDirectory
static storageDirectory()
Definition: ezsys.php:514
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.