protected function createRecord(File $file, $nosubdef=false)
    {
        $element = \record_adapter::createFromFile($file, $this->app);
        $date = new \DateTime();

        $file->addAttribute(
            new MetadataAttr(
                new Metadata(
                    new TfArchivedate(), new MonoValue($date->format('Y/m/d H:i:s'))
                )
            )
        );
        $file->addAttribute(
            new MetadataAttr(
                new Metadata(
                    new TfRecordid(), new MonoValue($element->getRecordId())
                )
            )
        );
        $file->addAttribute(
            new MetadataAttr(
                new Metadata(
                    new TfBasename(), new MonoValue(pathinfo($file->getOriginalName(), PATHINFO_BASENAME))
                )
            )
        );
        $file->addAttribute(
            new MetadataAttr(
                new Metadata(
                    new TfFilename(), new MonoValue(pathinfo($file->getOriginalName(), PATHINFO_FILENAME))
                )
            )
        );

        $newMetadata = $file->getMedia()->getMetadatas()->toArray();
        foreach ($file->getAttributes() as $attribute) {
            switch ($attribute->getName()) {
                case AttributeInterface::NAME_METAFIELD:
                    /** @var MetafieldAttr $attribute */
                    $values = $attribute->getValue();
                    $value = $attribute->getField()->is_multi() ? new Multi($values) : new MonoValue(array_pop($values));

                    $newMetadata[] = new Metadata($attribute->getField()->get_tag(), $value);
                    break;

                case AttributeInterface::NAME_METADATA:
                    /** @var MetadataAttr $attribute */
                    $newMetadata[] = $attribute->getValue();
                    break;
                case AttributeInterface::NAME_STATUS:
                    /** @var StatusAttr $attribute */
                    $element->setStatus(decbin(bindec($element->getStatus()) | bindec($attribute->getValue())));

                    break;
                case AttributeInterface::NAME_STORY:

                    /** @var StoryAttr $attribute */
                    $story = $attribute->getValue();

                    if ( ! $story->hasChild($element)) {
                        $story->appendChild($element);
                    }

                    break;
            }
        }

        $this->app['phraseanet.metadata-setter']->replaceMetadata($newMetadata, $element);

        if(!$nosubdef) {
            $element->rebuild_subdefs();
        }

        return $element;
    }
protected function createRecord(File $file, $nosubdef=false)
    {
        $element = \record_adapter::createFromFile($file, $this->app);
        $date = new \DateTime();

        $file->addAttribute(
            new MetadataAttr(
                new Metadata(
                    new TfArchivedate(), new MonoValue($date->format('Y/m/d H:i:s'))
                )
            )
        );
        $file->addAttribute(
            new MetadataAttr(
                new Metadata(
                    new TfRecordid(), new MonoValue($element->getRecordId())
                )
            )
        );
        $file->addAttribute(
            new MetadataAttr(
                new Metadata(
                    new TfBasename(), new MonoValue(pathinfo($file->getOriginalName(), PATHINFO_BASENAME))
                )
            )
        );
        $file->addAttribute(
            new MetadataAttr(
                new Metadata(
                    new TfFilename(), new MonoValue(pathinfo($file->getOriginalName(), PATHINFO_FILENAME))
                )
            )
        );

        $newMetadata = $file->getMedia()->getMetadatas()->toArray();
        foreach ($file->getAttributes() as $attribute) {
            switch ($attribute->getName()) {
                case AttributeInterface::NAME_METAFIELD:
                    /** @var MetafieldAttr $attribute */
                    $values = $attribute->getValue();
                    $value = $attribute->getField()->is_multi() ? new Multi($values) : new MonoValue(array_pop($values));

                    $newMetadata[] = new Metadata($attribute->getField()->get_tag(), $value);
                    break;

                case AttributeInterface::NAME_METADATA:
                    /** @var MetadataAttr $attribute */
                    $newMetadata[] = $attribute->getValue();
                    break;
                case AttributeInterface::NAME_STATUS:
                    /** @var StatusAttr $attribute */
                    $element->setStatus(decbin(bindec($element->getStatus()) | bindec($attribute->getValue())));

                    break;
                case AttributeInterface::NAME_STORY:

                    /** @var StoryAttr $attribute */
                    $story = $attribute->getValue();

                    if ( ! $story->hasChild($element)) {
                        $story->appendChild($element);
                    }

                    break;
            }
        }

        $this->app['phraseanet.metadata-setter']->replaceMetadata($newMetadata, $element);

        if(!$nosubdef) {
            $element->rebuild_subdefs();
        }

        return $element;
    }
protected function createRecord ( File $ file , $ nosubdef = false ) { $ element = \ record_adapter :: createFromFile ( $ file , $ this -> app ) ; $ date = new \ DateTime ( ) ; $ file -> addAttribute ( new MetadataAttr ( new Metadata ( new TfArchivedate ( ) , new MonoValue ( $ date -> format ( 'Y/m/d H:i:s' ) ) ) ) ) ; $ file -> addAttribute ( new MetadataAttr ( new Metadata ( new TfRecordid ( ) , new MonoValue ( $ element -> getRecordId ( ) ) ) ) ) ; $ file -> addAttribute ( new MetadataAttr ( new Metadata ( new TfBasename ( ) , new MonoValue ( pathinfo ( $ file -> getOriginalName ( ) , PATHINFO_BASENAME ) ) ) ) ) ; $ file -> addAttribute ( new MetadataAttr ( new Metadata ( new TfFilename ( ) , new MonoValue ( pathinfo ( $ file -> getOriginalName ( ) , PATHINFO_FILENAME ) ) ) ) ) ; $ newMetadata = $ file -> getMedia ( ) -> getMetadatas ( ) -> toArray ( ) ; foreach ( $ file -> getAttributes ( ) as $ attribute ) { switch ( $ attribute -> getName ( ) ) { case AttributeInterface :: NAME_METAFIELD : /** @var MetafieldAttr $attribute */ $ values = $ attribute -> getValue ( ) ; $ value = $ attribute -> getField ( ) -> is_multi ( ) ? new Multi ( $ values ) : new MonoValue ( array_pop ( $ values ) ) ; $ newMetadata [ ] = new Metadata ( $ attribute -> getField ( ) -> get_tag ( ) , $ value ) ; break ; case AttributeInterface :: NAME_METADATA : /** @var MetadataAttr $attribute */ $ newMetadata [ ] = $ attribute -> getValue ( ) ; break ; case AttributeInterface :: NAME_STATUS : /** @var StatusAttr $attribute */ $ element -> setStatus ( decbin ( bindec ( $ element -> getStatus ( ) ) | bindec ( $ attribute -> getValue ( ) ) ) ) ; break ; case AttributeInterface :: NAME_STORY : /** @var StoryAttr $attribute */ $ story = $ attribute -> getValue ( ) ; if ( ! $ story -> hasChild ( $ element ) ) { $ story -> appendChild ( $ element ) ; } break ; } } $ this -> app [ 'phraseanet.metadata-setter' ] -> replaceMetadata ( $ newMetadata , $ element ) ; if ( ! $ nosubdef ) { $ element -> rebuild_subdefs ( ) ; } return $ element ; }
Adds a record to Phraseanet

@param  File           $file The package file
@return \record_adapter
Adds a record to Phraseanet