src/Sulu/Bundle/ContactBundle/Contact/AccountManager.php
public function setMedias(Account $account, $medias)
    {
        $mediaIds = array_map(
            function($media) {
                return $media['id'];
            },
            $medias
        );

        $foundMedias = $this->mediaRepository->findById($mediaIds);
        $foundMediaIds = array_map(
            function($mediaEntity) {
                return $mediaEntity->getId();
            },
            $foundMedias
        );

        if ($missingMediaIds = array_diff($mediaIds, $foundMediaIds)) {
            throw new EntityNotFoundException($this->mediaRepository->getClassName(), reset($missingMediaIds));
        }

        $account->getMedias()->clear();
        foreach ($foundMedias as $media) {
            $account->addMedia($media);
        }
    }
public function setMedias(Account $account, $medias)
    {
        $mediaIds = array_map(
            function($media) {
                return $media['id'];
            },
            $medias
        );

        $foundMedias = $this->mediaRepository->findById($mediaIds);
        $foundMediaIds = array_map(
            function($mediaEntity) {
                return $mediaEntity->getId();
            },
            $foundMedias
        );

        if ($missingMediaIds = array_diff($mediaIds, $foundMediaIds)) {
            throw new EntityNotFoundException($this->mediaRepository->getClassName(), reset($missingMediaIds));
        }

        $account->getMedias()->clear();
        foreach ($foundMedias as $media) {
            $account->addMedia($media);
        }
    }
public function setMedias ( Account $ account , $ medias ) { $ mediaIds = array_map ( function ( $ media ) { return $ media [ 'id' ] ; } , $ medias ) ; $ foundMedias = $ this -> mediaRepository -> findById ( $ mediaIds ) ; $ foundMediaIds = array_map ( function ( $ mediaEntity ) { return $ mediaEntity -> getId ( ) ; } , $ foundMedias ) ; if ( $ missingMediaIds = array_diff ( $ mediaIds , $ foundMediaIds ) ) { throw new EntityNotFoundException ( $ this -> mediaRepository -> getClassName ( ) , reset ( $ missingMediaIds ) ) ; } $ account -> getMedias ( ) -> clear ( ) ; foreach ( $ foundMedias as $ media ) { $ account -> addMedia ( $ media ) ; } }
Sets the medias of the given account to the given medias.
Currently associated medias are replaced.

@param Account $account
@param $medias

@throws EntityNotFoundException
Sets the medias of the given account to the given medias . Currently associated medias are replaced .