/kernel/classes/datatypes/ezmedia/ezmedia.php
https://github.com/eeggenberger/ezpublish · PHP · 274 lines · 231 code · 22 blank · 21 comment · 10 complexity · b89020de57886fbd0704aab71a613e6c MD5 · raw file
- <?php
- /**
- * File containing the eZBinaryFile class.
- *
- * @copyright Copyright (C) 1999-2011 eZ Systems AS. All rights reserved.
- * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
- * @version //autogentag//
- * @package kernel
- */
- /*!
- \class eZMedia ezmedia.php
- \ingroup eZDatatype
- \brief The class eZMedia handles registered media files
- */
- class eZMedia extends eZPersistentObject
- {
- function eZMedia( $row )
- {
- $this->eZPersistentObject( $row );
- }
- static function definition()
- {
- static $definition = array( "fields" => array( "contentobject_attribute_id" => array( 'name' => "ContentObjectAttributeID",
- 'datatype' => 'integer',
- 'default' => 0,
- 'required' => true,
- 'foreign_class' => 'eZContentObjectAttribute',
- 'foreign_attribute' => 'id',
- 'multiplicity' => '1..*' ),
- "version" => array( 'name' => "Version",
- 'datatype' => 'integer',
- 'default' => 0,
- 'required' => true ),
- "filename" => array( 'name' => "Filename",
- 'datatype' => 'string',
- 'default' => '',
- 'required' => true ),
- "original_filename" => array( 'name' => "OriginalFilename",
- 'datatype' => 'string',
- 'default' => '',
- 'required' => true ),
- "mime_type" => array( 'name' => "MimeType",
- 'datatype' => 'string',
- 'default' => '',
- 'required' => true ),
- "width" => array( 'name' => "Width",
- 'datatype' => 'integer',
- 'default' => 0,
- 'required' => true ),
- "height" => array( 'name' => "Height",
- 'datatype' => 'integer',
- 'default' => 0,
- 'required' => true ),
- "has_controller" => array( 'name' => "HasController",
- 'datatype' => 'integer',
- 'default' => 0,
- 'required' => true ),
- "controls" => array( 'name' => "Controls",
- 'datatype' => 'string',
- 'default' => '',
- 'required' => true ),
- "is_autoplay" => array( 'name' => "IsAutoplay",
- 'datatype' => 'integer',
- 'default' => 0,
- 'required' => true ),
- "pluginspage" => array( 'name' => "Pluginspage",
- 'datatype' => 'string',
- 'default' => '',
- 'required' => true ),
- "quality" => array( 'name' => 'Quality',
- 'datatype' => 'string',
- 'default' => '',
- 'required' => true ),
- "is_loop" => array( 'name' => "IsLoop",
- 'datatype' => 'integer',
- 'default' => 0,
- 'required' => true ) ),
- "keys" => array( "contentobject_attribute_id", "version" ),
- 'function_attributes' => array( 'filesize' => 'filesize',
- 'filepath' => 'filepath',
- 'mime_type_category' => 'mimeTypeCategory',
- 'mime_type_part' => 'mimeTypePart' ),
- "relations" => array( "contentobject_attribute_id" => array( "class" => "ezcontentobjectattribute",
- "field" => "id" ),
- "version" => array( "class" => "ezcontentobjectattribute",
- "field" => "version" )),
- "class_name" => "eZMedia",
- "name" => "ezmedia" );
- return $definition;
- }
- function fileSize()
- {
- $fileInfo = $this->storedFileInfo();
- $file = eZClusterFileHandler::instance( $fileInfo['filepath'] );
- if ( $file->exists() )
- {
- return $file->size();
- }
- return 0;
- }
- function filePath()
- {
- $fileInfo = $this->storedFileInfo();
- return $fileInfo['filepath'];
- }
- function mimeTypeCategory()
- {
- $types = explode( "/", eZPersistentObject::attribute( "mime_type" ) );
- return $types[0];
- }
- function mimeTypePart()
- {
- $types = explode( "/", eZPersistentObject::attribute( "mime_type" ) );
- return $types[1];
- }
- static function create( $contentObjectAttributeID, $version )
- {
- $row = array( "contentobject_attribute_id" => $contentObjectAttributeID,
- "version" => $version,
- "filename" => "",
- "original_filename" => "",
- "mime_type" => "",
- "width" => "0",
- "height" => "0",
- "controller" => true,
- "autoplay" => true,
- "pluginspage" => "",
- "is_loop" => false,
- "quality" => "",
- "controls" => ""
- );
- return new eZMedia( $row );
- }
- static function fetch( $id, $version, $asObject = true )
- {
- if( $version == null )
- {
- return eZPersistentObject::fetchObjectList( eZMedia::definition(),
- null,
- array( "contentobject_attribute_id" => $id ),
- null,
- null,
- $asObject );
- }
- else
- {
- return eZPersistentObject::fetchObject( eZMedia::definition(),
- null,
- array( "contentobject_attribute_id" => $id,
- "version" => $version ),
- $asObject );
- }
- }
- static function fetchByFileName( $filename, $version = null, $asObject = true )
- {
- if ( $version == null )
- {
- return eZPersistentObject::fetchObjectList( eZMedia::definition(),
- null,
- array( 'filename' => $filename ),
- null,
- null,
- $asObject );
- }
- else
- {
- return eZPersistentObject::fetchObject( eZMedia::definition(),
- null,
- array( 'filename' => $filename,
- 'version' => $version ),
- $asObject );
- }
- }
- /**
- * Fetch media objects by content object id
- * @param int $contentObjectID contentobject id
- * @param string $languageCode language code
- * @param boolean $asObject if return object
- * @return array
- */
- static function fetchByContentObjectID( $contentObjectID, $languageCode = null, $asObject = true )
- {
- $condition = array();
- $condition['contentobject_id'] = $contentObjectID;
- $condition['data_type_string'] = 'ezmedia';
- if ( $languageCode != null )
- {
- $condition['language_code'] = $languageCode;
- }
- $custom = array( array( 'operation' => 'DISTINCT id',
- 'name' => 'id' ) );
- $ids = eZPersistentObject::fetchObjectList( eZContentObjectAttribute::definition(),
- array(),
- $condition,
- null,
- null,
- false,
- false,
- $custom );
- $mediaFiles = array();
- foreach ( $ids as $id )
- {
- $mediaFileObjectAttribute = eZMedia::fetch( $id['id'], null, $asObject );
- $mediaFiles = array_merge( $mediaFiles, $mediaFileObjectAttribute );
- }
- return $mediaFiles;
- }
- static function removeByID( $id, $version )
- {
- if( $version == null )
- {
- eZPersistentObject::removeObject( eZMedia::definition(),
- array( "contentobject_attribute_id" => $id ) );
- }
- else
- {
- eZPersistentObject::removeObject( eZMedia::definition(),
- array( "contentobject_attribute_id" => $id,
- "version" => $version ) );
- }
- }
- function storedFileInfo()
- {
- $fileName = $this->attribute( 'filename' );
- $mimeType = $this->attribute( 'mime_type' );
- $originalFileName = $this->attribute( 'original_filename' );
- $storageDir = eZSys::storageDirectory();
- $group = '';
- $type = '';
- if ( $mimeType )
- list( $group, $type ) = explode( '/', $mimeType );
- $filePath = $storageDir . '/original/' . $group . '/' . $fileName;
- return array( 'filename' => $fileName,
- 'original_filename' => $originalFileName,
- 'filepath' => $filePath,
- 'mime_type' => $mimeType );
- }
- public $ContentObjectAttributeID;
- public $Filename;
- public $OriginalFilename;
- public $MimeType;
- public $Width;
- public $Height;
- public $HasController;
- public $Controls;
- public $IsLoop;
- public $IsAutoplay;
- public $Pluginspage;
- public $Quality;
- }
- ?>