Example #1
0
 /**
  * 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;
 }
 function downloadFileObject($contentObject, $contentObjectAttribute)
 {
     $contentObjectAttributeID = $contentObjectAttribute->attribute('id');
     $version = $contentObject->attribute('current_version');
     $fileObject = eZBinaryFile::fetch($contentObjectAttributeID, $version);
     if ($fileObject) {
         return $fileObject;
     }
     $fileObject = eZMedia::fetch($contentObjectAttributeID, $version);
     return $fileObject;
 }
    /**
     * Regression test for issue 16400
     * @link http://issues.ez.no/16400
     * @return unknown_type
     */
    public function testIssue16400()
    {
        $className = 'Media test class';
        $classIdentifier = 'media_test_class';
        $filePath = 'tests/tests/kernel/datatypes/ezmedia/ezmediatype_regression_issue16400.flv';
        eZFile::create( $filePath );
        $attributeName = 'Media';
        $attributeIdentifier = 'media';
        $attributeType = 'ezmedia';
        //1. test method fetchByContentObjectID

        $class = new ezpClass( $className, $classIdentifier, $className );
        $class->add( $attributeName, $attributeIdentifier, $attributeType );
        $attribute = $class->class->fetchAttributeByIdentifier( $attributeIdentifier );

        $attribute->setAttribute( 'can_translate', 0 );
        $class->store();

        $object = new ezpObject( $classIdentifier, 2 );
        $dataMap = $object->object->dataMap();
        $fileAttribute = $dataMap[$attributeIdentifier];
        $dataType = new eZMediaType();
        $dataType->fromString( $fileAttribute, $filePath );

        $fileAttribute->store();
        $object->publish();
        $object->refresh();

        //verify fetchByContentObjectID
        $mediaObject = eZMedia::fetch( $fileAttribute->attribute( 'id' ), 1 );
        $medias = eZMedia::fetchByContentObjectID( $object->object->attribute( 'id' ) );
        $this->assertEquals( $mediaObject->attribute( 'filename' ), $medias[0]->attribute( 'filename' ) );
        $medias = eZMedia::fetchByContentObjectID( $object->object->attribute( 'id' ),
                                                    $fileAttribute->attribute( 'language_code' ) );
        $this->assertEquals( $mediaObject->attribute( 'filename' ), $medias[0]->attribute( 'filename' ) );

        //2. test issue
        // create translation
        $contentObject = $object->object;
        $storedFileName = $mediaObject->attribute( 'filename' );
        $version = $contentObject->createNewVersionIn( 'nor-NO',
                                                        $fileAttribute->attribute( 'language_code' )  );
        $version->setAttribute( 'status', eZContentObjectVersion::STATUS_INTERNAL_DRAFT );
        $version->store();
        $version->removeThis();
        $sys = eZSys::instance();
        $dir = $sys->storageDirectory();
        //verify the file is deleted
        $storedFilePath = $dir . '/original/video/' . $storedFileName;
        $file = eZClusterFileHandler::instance( $storedFilePath );
        $this->assertTrue( $file->exists( $storedFilePath ) );
        if ( $file->exists( $storedFilePath ) )
            unlink( $storedFilePath );
    }
 function downloadType($contentObject, $contentObjectAttribute)
 {
     $contentObjectAttributeID = $contentObjectAttribute->attribute('id');
     $version = $contentObject->attribute('current_version');
     $fileObject = eZBinaryFile::fetch($contentObjectAttributeID, $version);
     if ($fileObject) {
         return self::TYPE_FILE;
     }
     $fileObject = eZMedia::fetch($contentObjectAttributeID, $version);
     if ($fileObject) {
         return self::TYPE_MEDIA;
     }
     return false;
 }
Example #5
0
 function objectAttributeContent($contentObjectAttribute)
 {
     $mediaFile = eZMedia::fetch($contentObjectAttribute->attribute("id"), $contentObjectAttribute->attribute("version"));
     if (!$mediaFile) {
         $retValue = false;
         return $retValue;
     }
     return $mediaFile;
 }